summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2022-01-07 07:13:24 +1100
committer Vas Crabb <vas@vastheman.com>2022-01-07 07:13:24 +1100
commite14fec69d8e461b2c768dd7867a83dbc1ec45e69 (patch)
tree83e303db46ac31c740d6cfc741498b99df4e0546 /src/frontend/mame
parent933c2341f5a1961627a03495b726b750b25b41d0 (diff)
frontend: Sort directory selection menu items (MT08167).
Also fixed selecting .. not moving up more than one level. Removed a vestigial member function from the file selection menu and reduced redundancy in a few more slot machine layouts while I was at it.
Diffstat (limited to 'src/frontend/mame')
-rw-r--r--src/frontend/mame/ui/dirmenu.cpp59
-rw-r--r--src/frontend/mame/ui/filesel.cpp47
-rw-r--r--src/frontend/mame/ui/filesel.h1
3 files changed, 40 insertions, 67 deletions
diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp
index 3b92204ae3e..d37217afd9d 100644
--- a/src/frontend/mame/ui/dirmenu.cpp
+++ b/src/frontend/mame/ui/dirmenu.cpp
@@ -18,11 +18,16 @@
#include "emuopts.h"
#include "mame.h"
-#include "corestr.h"
+#include "util/corestr.h"
+#include "util/path.h"
+
+#include <locale>
namespace ui {
+namespace {
+
static int ADDING = 1;
static int CHANGE = 2;
@@ -68,6 +73,8 @@ static const folders_entry s_folders[] =
{ N_p("path-option", "Covers"), OPTION_COVER_PATH, ADDING }
};
+} // anonymous namespace
+
/**************************************************
MENU DIRECTORY
@@ -249,27 +256,21 @@ void menu_add_change_folder::handle(event const *ev)
{
if (ev->iptkey == IPT_UI_SELECT)
{
- int index = (uintptr_t)ev->itemref - 1;
- const menu_item &pitem = item(index);
+ assert(ev->item);
+ menu_item const &pitem = *ev->item;
// go up to the parent path
if (pitem.text() == "..")
{
- size_t first_sep = m_current_path.find_first_of(PATH_SEPARATOR[0]);
- size_t last_sep = m_current_path.find_last_of(PATH_SEPARATOR[0]);
- if (first_sep != last_sep)
- m_current_path.erase(++last_sep);
+ size_t const first_sep = m_current_path.find_first_of(PATH_SEPARATOR[0]);
+ size_t const last_sep = m_current_path.find_last_of(PATH_SEPARATOR[0]);
+ m_current_path.erase(last_sep + ((first_sep == last_sep) ? 1 : 0));
}
else
{
// if isn't a drive, appends the directory
if (pitem.subtext() != "[DRIVE]")
- {
- if (m_current_path[m_current_path.length() - 1] == PATH_SEPARATOR[0])
- m_current_path.append(pitem.text());
- else
- m_current_path.append(PATH_SEPARATOR).append(pitem.text());
- }
+ util::path_append(m_current_path, pitem.text());
else
m_current_path = pitem.text();
}
@@ -291,9 +292,7 @@ void menu_add_change_folder::handle(event const *ev)
if (ui().options().exists(s_folders[m_ref].option))
ui().options().set_value(s_folders[m_ref].option, m_current_path, OPTION_PRIORITY_CMDLINE);
else if (machine().options().value(s_folders[m_ref].option) != m_current_path)
- {
machine().options().set_value(s_folders[m_ref].option, m_current_path, OPTION_PRIORITY_CMDLINE);
- }
}
else
{
@@ -309,9 +308,7 @@ void menu_add_change_folder::handle(event const *ev)
if (ui().options().exists(s_folders[m_ref].option))
ui().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
else if (machine().options().value(s_folders[m_ref].option) != tmppath)
- {
machine().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
- }
}
reset_parent(reset_options::SELECT_FIRST);
@@ -383,22 +380,38 @@ void menu_add_change_folder::handle(event const *ev)
void menu_add_change_folder::populate(float &customtop, float &custombottom)
{
- // open a path
- file_enumerator path(m_current_path.c_str());
- const osd::directory::entry *dirent;
int folders_count = 0;
// add the drives
for (std::string const &volume_name : osd_get_volume_names())
item_append(volume_name, "[DRIVE]", 0, (void *)(uintptr_t)++folders_count);
- // add the directories
+ // get subdirectories
+ std::vector<std::string> dirnames;
+ file_enumerator path(m_current_path);
+ const osd::directory::entry *dirent;
while ((dirent = path.next()) != nullptr)
{
- if (dirent->type == osd::directory::entry::entry_type::DIR && strcmp(dirent->name, ".") != 0)
- item_append(dirent->name, "[DIR]", 0, (void *)(uintptr_t)++folders_count);
+ if ((osd::directory::entry::entry_type::DIR == dirent->type) && strcmp(dirent->name, "."))
+ dirnames.emplace_back(dirent->name);
}
+ // sort
+ std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t> >(std::locale());
+ std::sort(
+ dirnames.begin(),
+ dirnames.end(),
+ [&coll] (std::string const &x, std::string const &y)
+ {
+ std::wstring const xw = wstring_from_utf8(x);
+ std::wstring const yw = wstring_from_utf8(y);
+ return coll.compare(xw.data(), xw.data() + xw.size(), yw.data(), yw.data() + yw.size()) < 0;
+ });
+
+ // add to menu
+ for (std::string const &name : dirnames)
+ item_append(name, "[DIR]", 0, (void *)(uintptr_t)++folders_count);
+
item_append(menu_item_type::SEPARATOR);
// configure the custom rendering
diff --git a/src/frontend/mame/ui/filesel.cpp b/src/frontend/mame/ui/filesel.cpp
index 3da27ae7a36..36f18005409 100644
--- a/src/frontend/mame/ui/filesel.cpp
+++ b/src/frontend/mame/ui/filesel.cpp
@@ -19,8 +19,8 @@
#include "imagedev/floppy.h"
-#include "corestr.h"
-#include "zippath.h"
+#include "util/corestr.h"
+#include "util/zippath.h"
#include <cstring>
#include <locale>
@@ -137,45 +137,6 @@ bool menu_file_selector::custom_mouse_down()
//-------------------------------------------------
-// compare_file_selector_entries - sorting proc
-// for file selector entries
-//-------------------------------------------------
-
-int menu_file_selector::compare_entries(const file_selector_entry *e1, const file_selector_entry *e2)
-{
- int result;
- const char *e1_basename = e1->basename.c_str();
- const char *e2_basename = e2->basename.c_str();
-
- if (e1->type < e2->type)
- {
- result = -1;
- }
- else if (e1->type > e2->type)
- {
- result = 1;
- }
- else
- {
- result = core_stricmp(e1_basename, e2_basename);
- if (result == 0)
- {
- result = strcmp(e1_basename, e2_basename);
- if (result == 0)
- {
- if (e1 < e2)
- result = -1;
- else if (e1 > e2)
- result = 1;
- }
- }
- }
-
- return result;
-}
-
-
-//-------------------------------------------------
// append_entry - appends a new
// file selector entry to an entry list
//-------------------------------------------------
@@ -450,7 +411,7 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
if (m_entrylist.size() > first)
{
// sort the menu entries
- const std::collate<wchar_t> &coll = std::use_facet<std::collate<wchar_t>>(std::locale());
+ std::collate<wchar_t> const &coll = std::use_facet<std::collate<wchar_t> >(std::locale());
std::sort(
m_entrylist.begin() + first,
m_entrylist.end(),
@@ -458,7 +419,7 @@ void menu_file_selector::populate(float &customtop, float &custombottom)
{
std::wstring const xstr = wstring_from_utf8(x.basename);
std::wstring const ystr = wstring_from_utf8(y.basename);
- return coll.compare(xstr.data(), xstr.data()+xstr.size(), ystr.data(), ystr.data()+ystr.size()) < 0;
+ return coll.compare(xstr.data(), xstr.data() + xstr.size(), ystr.data(), ystr.data() + ystr.size()) < 0;
});
}
diff --git a/src/frontend/mame/ui/filesel.h b/src/frontend/mame/ui/filesel.h
index 11e5643c2de..3b09244ca20 100644
--- a/src/frontend/mame/ui/filesel.h
+++ b/src/frontend/mame/ui/filesel.h
@@ -86,7 +86,6 @@ private:
virtual void handle(event const *ev) override;
// methods
- int compare_entries(const file_selector_entry *e1, const file_selector_entry *e2);
file_selector_entry &append_entry(file_selector_entry_type entry_type, const std::string &entry_basename, const std::string &entry_fullpath);
file_selector_entry &append_entry(file_selector_entry_type entry_type, std::string &&entry_basename, std::string &&entry_fullpath);
file_selector_entry *append_dirent_entry(const osd::directory::entry *dirent);