summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
author Vas Crabb <vas@vastheman.com>2021-10-06 05:28:14 +1100
committer Vas Crabb <vas@vastheman.com>2021-10-06 05:28:14 +1100
commit1638f5f8a1f16b20303da659613cdb795e6aef43 (patch)
treeeecfc4a2947379d2d1561f6625f61dde2f272f98
parenteae75824d3c8d697216a9782b9f7ca6494ef431d (diff)
ui: Made file manager software list menu search behave better (based on file selection menu code).
-rw-r--r--src/frontend/mame/ui/swlist.cpp45
-rw-r--r--src/frontend/mame/ui/swlist.h2
2 files changed, 24 insertions, 23 deletions
diff --git a/src/frontend/mame/ui/swlist.cpp b/src/frontend/mame/ui/swlist.cpp
index 11d2c7e00db..0ead9a66814 100644
--- a/src/frontend/mame/ui/swlist.cpp
+++ b/src/frontend/mame/ui/swlist.cpp
@@ -247,9 +247,6 @@ void menu_software_list::populate(float &customtop, float &custombottom)
void menu_software_list::handle()
{
- const entry_info *selected_entry = nullptr;
- int bestmatch = 0;
-
// process the menu
const event *event = process(0);
@@ -260,7 +257,7 @@ void menu_software_list::handle()
m_ordered_by_shortname = !m_ordered_by_shortname;
// reset the char buffer if we change ordering criterion
- m_filename_buffer.clear();
+ m_search.clear();
// reload the menu with the new order
reset(reset_options::REMEMBER_REF);
@@ -275,29 +272,33 @@ void menu_software_list::handle()
}
else if (event->iptkey == IPT_SPECIAL)
{
- if (input_character(m_filename_buffer, event->unichar, &is_valid_softlist_part_char))
+ if (input_character(m_search, event->unichar, m_ordered_by_shortname ? is_valid_softlist_part_char : [] (char32_t ch) { return true; }))
{
// display the popup
- ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_filename_buffer);
+ ui().popup_time(ERROR_MESSAGE_TIME, "%s", m_search);
// identify the selected entry
entry_info const *const cur_selected = (uintptr_t(event->itemref) != 1)
? reinterpret_cast<entry_info const *>(get_selection_ref())
: nullptr;
- // loop through all entries
- for (auto &entry : m_entrylist)
+ // if it's a perfect match for the current selection, don't move it
+ auto const &cur_name = m_ordered_by_shortname ? cur_selected->short_name : cur_selected->long_name;
+ if (!cur_selected || core_strnicmp(cur_name.c_str(), m_search.c_str(), m_search.size()))
{
- // is this entry the selected entry?
- if (cur_selected != &entry)
+ std::string::size_type bestmatch(0);
+ entry_info const *selected_entry(cur_selected);
+ for (auto &entry : m_entrylist)
{
- auto &compare_name = m_ordered_by_shortname ? entry.short_name : entry.long_name;
-
- int match = 0;
- for (int i = 0; i < m_filename_buffer.size() + 1; i++)
+ // TODO: more efficient "common prefix" code
+ auto const &compare_name = m_ordered_by_shortname ? entry.short_name : entry.long_name;
+ std::string::size_type match(0);
+ for (std::string::size_type i = 1; m_search.size() >= i; ++i)
{
- if (core_strnicmp(compare_name.c_str(), m_filename_buffer.c_str(), i) == 0)
+ if (!core_strnicmp(compare_name.c_str(), m_search.c_str(), i))
match = i;
+ else
+ break;
}
if (match > bestmatch)
@@ -306,20 +307,20 @@ void menu_software_list::handle()
selected_entry = &entry;
}
}
- }
- if (selected_entry != nullptr && selected_entry != cur_selected)
- {
- set_selection((void *)selected_entry);
- centre_selection();
+ if (selected_entry && (selected_entry != cur_selected))
+ {
+ set_selection((void *)selected_entry);
+ centre_selection();
+ }
}
}
}
else if (event->iptkey == IPT_UI_CANCEL)
{
// reset the char buffer also in this case
- m_filename_buffer.clear();
- m_result = m_filename_buffer;
+ m_search.clear();
+ m_result = m_search;
stack_pop();
}
}
diff --git a/src/frontend/mame/ui/swlist.h b/src/frontend/mame/ui/swlist.h
index a9947cd8daf..3c4bd5b91b7 100644
--- a/src/frontend/mame/ui/swlist.h
+++ b/src/frontend/mame/ui/swlist.h
@@ -84,7 +84,7 @@ private:
const char * m_interface;
std::string & m_result;
std::list<entry_info> m_entrylist;
- std::string m_filename_buffer;
+ std::string m_search;
bool m_ordered_by_shortname;
// functions