mirror of
https://github.com/holub/mame
synced 2025-04-21 16:01:56 +03:00
ui: Made file manager software list menu search behave better (based on file selection menu code).
This commit is contained in:
parent
eae75824d3
commit
1638f5f8a1
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user