mirror of
https://github.com/holub/mame
synced 2025-07-04 17:38:08 +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 "emuopts.h"
|
||||||
#include "mame.h"
|
#include "mame.h"
|
||||||
|
|
||||||
#include "corestr.h"
|
#include "util/corestr.h"
|
||||||
|
#include "util/path.h"
|
||||||
|
|
||||||
|
#include <locale>
|
||||||
|
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
static int ADDING = 1;
|
static int ADDING = 1;
|
||||||
static int CHANGE = 2;
|
static int CHANGE = 2;
|
||||||
|
|
||||||
@ -68,6 +73,8 @@ static const folders_entry s_folders[] =
|
|||||||
{ N_p("path-option", "Covers"), OPTION_COVER_PATH, ADDING }
|
{ N_p("path-option", "Covers"), OPTION_COVER_PATH, ADDING }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
/**************************************************
|
/**************************************************
|
||||||
MENU DIRECTORY
|
MENU DIRECTORY
|
||||||
@ -249,27 +256,21 @@ void menu_add_change_folder::handle(event const *ev)
|
|||||||
{
|
{
|
||||||
if (ev->iptkey == IPT_UI_SELECT)
|
if (ev->iptkey == IPT_UI_SELECT)
|
||||||
{
|
{
|
||||||
int index = (uintptr_t)ev->itemref - 1;
|
assert(ev->item);
|
||||||
const menu_item &pitem = item(index);
|
menu_item const &pitem = *ev->item;
|
||||||
|
|
||||||
// go up to the parent path
|
// go up to the parent path
|
||||||
if (pitem.text() == "..")
|
if (pitem.text() == "..")
|
||||||
{
|
{
|
||||||
size_t first_sep = m_current_path.find_first_of(PATH_SEPARATOR[0]);
|
size_t const first_sep = m_current_path.find_first_of(PATH_SEPARATOR[0]);
|
||||||
size_t last_sep = m_current_path.find_last_of(PATH_SEPARATOR[0]);
|
size_t const last_sep = m_current_path.find_last_of(PATH_SEPARATOR[0]);
|
||||||
if (first_sep != last_sep)
|
m_current_path.erase(last_sep + ((first_sep == last_sep) ? 1 : 0));
|
||||||
m_current_path.erase(++last_sep);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// if isn't a drive, appends the directory
|
// if isn't a drive, appends the directory
|
||||||
if (pitem.subtext() != "[DRIVE]")
|
if (pitem.subtext() != "[DRIVE]")
|
||||||
{
|
util::path_append(m_current_path, pitem.text());
|
||||||
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());
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
m_current_path = pitem.text();
|
m_current_path = pitem.text();
|
||||||
}
|
}
|
||||||
@ -291,10 +292,8 @@ void menu_add_change_folder::handle(event const *ev)
|
|||||||
if (ui().options().exists(s_folders[m_ref].option))
|
if (ui().options().exists(s_folders[m_ref].option))
|
||||||
ui().options().set_value(s_folders[m_ref].option, m_current_path, OPTION_PRIORITY_CMDLINE);
|
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)
|
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);
|
machine().options().set_value(s_folders[m_ref].option, m_current_path, OPTION_PRIORITY_CMDLINE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_folders.push_back(m_current_path);
|
m_folders.push_back(m_current_path);
|
||||||
@ -309,10 +308,8 @@ void menu_add_change_folder::handle(event const *ev)
|
|||||||
if (ui().options().exists(s_folders[m_ref].option))
|
if (ui().options().exists(s_folders[m_ref].option))
|
||||||
ui().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
|
ui().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
|
||||||
else if (machine().options().value(s_folders[m_ref].option) != tmppath)
|
else if (machine().options().value(s_folders[m_ref].option) != tmppath)
|
||||||
{
|
|
||||||
machine().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
|
machine().options().set_value(s_folders[m_ref].option, tmppath, OPTION_PRIORITY_CMDLINE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
reset_parent(reset_options::SELECT_FIRST);
|
reset_parent(reset_options::SELECT_FIRST);
|
||||||
stack_pop();
|
stack_pop();
|
||||||
@ -383,22 +380,38 @@ void menu_add_change_folder::handle(event const *ev)
|
|||||||
|
|
||||||
void menu_add_change_folder::populate(float &customtop, float &custombottom)
|
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;
|
int folders_count = 0;
|
||||||
|
|
||||||
// add the drives
|
// add the drives
|
||||||
for (std::string const &volume_name : osd_get_volume_names())
|
for (std::string const &volume_name : osd_get_volume_names())
|
||||||
item_append(volume_name, "[DRIVE]", 0, (void *)(uintptr_t)++folders_count);
|
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)
|
while ((dirent = path.next()) != nullptr)
|
||||||
{
|
{
|
||||||
if (dirent->type == osd::directory::entry::entry_type::DIR && strcmp(dirent->name, ".") != 0)
|
if ((osd::directory::entry::entry_type::DIR == dirent->type) && strcmp(dirent->name, "."))
|
||||||
item_append(dirent->name, "[DIR]", 0, (void *)(uintptr_t)++folders_count);
|
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);
|
item_append(menu_item_type::SEPARATOR);
|
||||||
|
|
||||||
// configure the custom rendering
|
// configure the custom rendering
|
||||||
|
@ -19,8 +19,8 @@
|
|||||||
|
|
||||||
#include "imagedev/floppy.h"
|
#include "imagedev/floppy.h"
|
||||||
|
|
||||||
#include "corestr.h"
|
#include "util/corestr.h"
|
||||||
#include "zippath.h"
|
#include "util/zippath.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <locale>
|
#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
|
// append_entry - appends a new
|
||||||
// file selector entry to an entry list
|
// 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)
|
if (m_entrylist.size() > first)
|
||||||
{
|
{
|
||||||
// sort the menu entries
|
// 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(
|
std::sort(
|
||||||
m_entrylist.begin() + first,
|
m_entrylist.begin() + first,
|
||||||
m_entrylist.end(),
|
m_entrylist.end(),
|
||||||
|
@ -86,7 +86,6 @@ private:
|
|||||||
virtual void handle(event const *ev) override;
|
virtual void handle(event const *ev) override;
|
||||||
|
|
||||||
// methods
|
// 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, 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_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_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