mirror of
https://github.com/holub/mame
synced 2025-04-21 16:01:56 +03:00
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.
This commit is contained in:
parent
933c2341f5
commit
e14fec69d8
@ -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
|
||||
|
@ -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>
|
||||
@ -136,45 +136,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;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user