mirror of
https://github.com/holub/mame
synced 2025-04-23 00:39:36 +03:00
Changed filesel entrylist to be a vector
This commit is contained in:
parent
7dd79891e9
commit
dd57d5c00e
@ -293,7 +293,6 @@ menu_file_selector::menu_file_selector(mame_ui_manager &mui, render_container *c
|
||||
: menu(mui, container)
|
||||
, m_current_directory(current_directory)
|
||||
, m_current_file(current_file)
|
||||
, m_entrylist(nullptr)
|
||||
{
|
||||
m_image = image;
|
||||
m_has_empty = has_empty;
|
||||
@ -384,8 +383,8 @@ bool menu_file_selector::custom_mouse_down()
|
||||
int menu_file_selector::compare_entries(const file_selector_entry *e1, const file_selector_entry *e2)
|
||||
{
|
||||
int result;
|
||||
const char *e1_basename = (e1->basename != nullptr) ? e1->basename : "";
|
||||
const char *e2_basename = (e2->basename != nullptr) ? e2->basename : "";
|
||||
const char *e1_basename = e1->basename.c_str();
|
||||
const char *e2_basename = e2->basename.c_str();
|
||||
|
||||
if (e1->type < e2->type)
|
||||
{
|
||||
@ -423,25 +422,15 @@ int menu_file_selector::compare_entries(const file_selector_entry *e1, const fil
|
||||
menu_file_selector::file_selector_entry *menu_file_selector::append_entry(
|
||||
file_selector_entry_type entry_type, const char *entry_basename, const char *entry_fullpath)
|
||||
{
|
||||
file_selector_entry *entry;
|
||||
file_selector_entry **entryptr;
|
||||
|
||||
// allocate a new entry
|
||||
entry = (file_selector_entry *) m_pool_alloc(sizeof(*entry));
|
||||
memset(entry, 0, sizeof(*entry));
|
||||
entry->type = entry_type;
|
||||
entry->basename = (entry_basename != nullptr) ? pool_strdup(entry_basename) : entry_basename;
|
||||
entry->fullpath = (entry_fullpath != nullptr) ? pool_strdup(entry_fullpath) : entry_fullpath;
|
||||
file_selector_entry entry;
|
||||
entry.type = entry_type;
|
||||
entry.basename.assign(entry_basename ? entry_basename : "");
|
||||
entry.fullpath.assign(entry_fullpath ? entry_fullpath : "");
|
||||
|
||||
// find the end of the list
|
||||
entryptr = &m_entrylist;
|
||||
while ((*entryptr != nullptr) && (compare_entries(entry, *entryptr) >= 0))
|
||||
entryptr = &(*entryptr)->next;
|
||||
|
||||
// insert the entry
|
||||
entry->next = *entryptr;
|
||||
*entryptr = entry;
|
||||
return entry;
|
||||
m_entrylist.push_back(entry);
|
||||
return &m_entrylist[m_entrylist.size() - 1];
|
||||
}
|
||||
|
||||
|
||||
@ -546,7 +535,7 @@ void menu_file_selector::populate()
|
||||
err = util::zippath_opendir(path, &directory);
|
||||
|
||||
// clear out the menu entries
|
||||
m_entrylist = nullptr;
|
||||
m_entrylist.clear();
|
||||
|
||||
if (m_has_empty)
|
||||
{
|
||||
@ -598,8 +587,8 @@ void menu_file_selector::populate()
|
||||
}
|
||||
|
||||
// append all of the menu entries
|
||||
for (entry = m_entrylist; entry != nullptr; entry = entry->next)
|
||||
append_entry_menu_item(entry);
|
||||
for (auto &entry : m_entrylist)
|
||||
append_entry_menu_item(&entry);
|
||||
|
||||
// set the selection (if we have one)
|
||||
if (selected_entry != nullptr)
|
||||
@ -620,7 +609,6 @@ void menu_file_selector::populate()
|
||||
void menu_file_selector::handle()
|
||||
{
|
||||
osd_file::error err;
|
||||
const file_selector_entry *entry;
|
||||
const file_selector_entry *selected_entry = nullptr;
|
||||
int bestmatch = 0;
|
||||
|
||||
@ -631,7 +619,7 @@ void menu_file_selector::handle()
|
||||
// handle selections
|
||||
if (event->iptkey == IPT_UI_SELECT)
|
||||
{
|
||||
entry = (const file_selector_entry *) event->itemref;
|
||||
auto entry = (const file_selector_entry *) event->itemref;
|
||||
switch (entry->type)
|
||||
{
|
||||
case SELECTOR_ENTRY_TYPE_EMPTY:
|
||||
@ -654,7 +642,7 @@ void menu_file_selector::handle()
|
||||
case SELECTOR_ENTRY_TYPE_DRIVE:
|
||||
case SELECTOR_ENTRY_TYPE_DIRECTORY:
|
||||
// drive/directory - first check the path
|
||||
err = util::zippath_opendir(entry->fullpath, nullptr);
|
||||
err = util::zippath_opendir(entry->fullpath.c_str(), nullptr);
|
||||
if (err != osd_file::error::NONE)
|
||||
{
|
||||
// this path is problematic; present the user with an error and bail
|
||||
@ -709,41 +697,21 @@ void menu_file_selector::handle()
|
||||
const file_selector_entry *cur_selected = (const file_selector_entry *)get_selection();
|
||||
|
||||
// check for entries which matches our m_filename_buffer:
|
||||
// from current entry to the end
|
||||
for (entry = cur_selected; entry != nullptr; entry = entry->next)
|
||||
for (auto &entry : m_entrylist)
|
||||
{
|
||||
if (entry->basename != nullptr && m_filename_buffer[0] != '\0')
|
||||
if (cur_selected != &entry)
|
||||
{
|
||||
int match = 0;
|
||||
for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++)
|
||||
{
|
||||
if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0)
|
||||
if (core_strnicmp(entry.basename.c_str(), m_filename_buffer, i) == 0)
|
||||
match = i;
|
||||
}
|
||||
|
||||
if (match > bestmatch)
|
||||
{
|
||||
bestmatch = match;
|
||||
selected_entry = entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
// and from the first entry to current one
|
||||
for (entry = m_entrylist; entry != cur_selected; entry = entry->next)
|
||||
{
|
||||
if (entry->basename != nullptr && m_filename_buffer[0] != '\0')
|
||||
{
|
||||
int match = 0;
|
||||
for (int i = 0; i < ARRAY_LENGTH(m_filename_buffer); i++)
|
||||
{
|
||||
if (core_strnicmp(entry->basename, m_filename_buffer, i) == 0)
|
||||
match = i;
|
||||
}
|
||||
|
||||
if (match > bestmatch)
|
||||
{
|
||||
bestmatch = match;
|
||||
selected_entry = entry;
|
||||
selected_entry = &entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -84,11 +84,9 @@ private:
|
||||
|
||||
struct file_selector_entry
|
||||
{
|
||||
file_selector_entry *next;
|
||||
|
||||
file_selector_entry_type type;
|
||||
const char *basename;
|
||||
const char *fullpath;
|
||||
std::string basename;
|
||||
std::string fullpath;
|
||||
};
|
||||
|
||||
// internal state
|
||||
@ -99,7 +97,7 @@ private:
|
||||
bool m_has_softlist;
|
||||
bool m_has_create;
|
||||
int * m_result;
|
||||
file_selector_entry * m_entrylist;
|
||||
std::vector<file_selector_entry> m_entrylist;
|
||||
std::string m_hover_directory;
|
||||
char m_filename_buffer[1024];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user