summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend
diff options
context:
space:
mode:
author npwoods <npwoods@mess.org>2022-04-11 06:54:35 -0400
committer GitHub <noreply@github.com>2022-04-11 06:54:35 -0400
commitb8758ed358e38adc40294ba39a410fe06f1b0c7c (patch)
tree329acfa0b3dc212383e243edd1aa621b823d86a0 /src/frontend
parent9ef4774f2ee83df5ea6def9342450fad5061db23 (diff)
Consolidated floppy_image_device::m_create_fs and floppy_image_device::m_io_fs vectors (#9542)
* Consolidated floppy_image_device::m_create_fs and floppy_image_device::m_io_fs vectors We had two separate members in floppy_image_device (m_create_fs and m_io_fs) that contained the same data. Whether the file systems can be formatted or read can be identified by querying fs::manager_t. For this reason, it seems bad to have these separate members, the seemingly only reason to make the UI code slightly less complicated. For this reason I consolidated these two members and moved the burden of selecting which ones are creatable to the UI code.
Diffstat (limited to 'src/frontend')
-rw-r--r--src/frontend/mame/ui/filecreate.cpp6
-rw-r--r--src/frontend/mame/ui/filecreate.h6
-rw-r--r--src/frontend/mame/ui/floppycntrl.cpp35
-rw-r--r--src/frontend/mame/ui/floppycntrl.h1
4 files changed, 37 insertions, 11 deletions
diff --git a/src/frontend/mame/ui/filecreate.cpp b/src/frontend/mame/ui/filecreate.cpp
index 8e036f4ae3b..3ecb44f9b62 100644
--- a/src/frontend/mame/ui/filecreate.cpp
+++ b/src/frontend/mame/ui/filecreate.cpp
@@ -290,9 +290,9 @@ SELECT FORMAT MENU
// ctor
//-------------------------------------------------
-menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, const std::vector<floppy_image_device::fs_info> &fs, int *result)
+menu_select_floppy_init::menu_select_floppy_init(mame_ui_manager &mui, render_container &container, std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> &&fs, int *result)
: menu(mui, container),
- m_fs(fs),
+ m_fs(std::move(fs)),
m_result(result)
{
@@ -316,7 +316,7 @@ void menu_select_floppy_init::populate(float &customtop, float &custombottom)
{
item_append(_("Select initial contents"), FLAG_DISABLE, nullptr);
int id = 0;
- for (const auto &fmt : m_fs)
+ for (const floppy_image_device::fs_info &fmt : m_fs)
item_append(fmt.m_description, fmt.m_name, 0, (void *)(uintptr_t)(id++));
}
diff --git a/src/frontend/mame/ui/filecreate.h b/src/frontend/mame/ui/filecreate.h
index bc08ef66974..bf8d7accbf6 100644
--- a/src/frontend/mame/ui/filecreate.h
+++ b/src/frontend/mame/ui/filecreate.h
@@ -86,7 +86,7 @@ class menu_select_floppy_init : public menu
{
public:
menu_select_floppy_init(mame_ui_manager &mui, render_container &container,
- const std::vector<floppy_image_device::fs_info> &fs, int *result);
+ std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> &&fs, int *result);
virtual ~menu_select_floppy_init() override;
private:
@@ -94,8 +94,8 @@ private:
virtual void handle(event const *ev) override;
// internal state
- const std::vector<floppy_image_device::fs_info> &m_fs;
- int * m_result;
+ std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> m_fs;
+ int * m_result;
};
diff --git a/src/frontend/mame/ui/floppycntrl.cpp b/src/frontend/mame/ui/floppycntrl.cpp
index 0e658b52199..9b85992a923 100644
--- a/src/frontend/mame/ui/floppycntrl.cpp
+++ b/src/frontend/mame/ui/floppycntrl.cpp
@@ -94,6 +94,11 @@ void menu_control_floppy_image::hook_load(const std::string &filename)
}
}
+bool menu_control_floppy_image::can_format(const floppy_image_device::fs_info &fs)
+{
+ return !fs.m_manager || fs.m_manager->can_format();
+}
+
void menu_control_floppy_image::menu_activated()
{
switch (m_state) {
@@ -124,26 +129,46 @@ void menu_control_floppy_image::menu_activated()
m_state = START_FILE;
menu_activated();
} else {
- const auto &fs = fd.get_create_fs();
+ // get all formatable file systems
+ std::vector<std::reference_wrapper<const floppy_image_device::fs_info>> fs;
+ for (const auto &this_fs : fd.get_fs()) {
+ if (can_format(this_fs))
+ fs.emplace_back(std::ref(this_fs));
+ }
+
output_filename = util::zippath_combine(m_current_directory, m_current_file);
if(fs.size() == 1) {
- create_fs = &fs[0];
+ create_fs = &(fs[0].get());
do_load_create();
stack_pop();
} else {
m_submenu_result.i = -1;
- menu::stack_push<menu_select_floppy_init>(ui(), container(), fs, &m_submenu_result.i);
+ menu::stack_push<menu_select_floppy_init>(ui(), container(), std::move(fs), &m_submenu_result.i);
m_state = SELECT_INIT;
}
}
break;
case SELECT_INIT:
- if(m_submenu_result.i == -1) {
+ // figure out which (if any) create file system was selected
+ create_fs = nullptr;
+ if(m_submenu_result.i >= 0) {
+ int i = 0;
+ for (const auto &this_fs : fd.get_fs()) {
+ if (can_format(this_fs)) {
+ if (i == m_submenu_result.i) {
+ create_fs = &this_fs;
+ break;
+ }
+ i++;
+ }
+ }
+ }
+
+ if(!create_fs) {
m_state = START_FILE;
menu_activated();
} else {
- create_fs = &fd.get_create_fs()[m_submenu_result.i];
do_load_create();
stack_pop();
}
diff --git a/src/frontend/mame/ui/floppycntrl.h b/src/frontend/mame/ui/floppycntrl.h
index 5923a9f8914..fd7e17cf7ce 100644
--- a/src/frontend/mame/ui/floppycntrl.h
+++ b/src/frontend/mame/ui/floppycntrl.h
@@ -39,6 +39,7 @@ private:
void do_load_create();
virtual void hook_load(const std::string &filename) override;
+ static bool can_format(const floppy_image_device::fs_info &fs);
};
} // namespace ui