summaryrefslogtreecommitdiffstatshomepage
path: root/src/emu/uiimage.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/emu/uiimage.c')
-rw-r--r--src/emu/uiimage.c208
1 files changed, 45 insertions, 163 deletions
diff --git a/src/emu/uiimage.c b/src/emu/uiimage.c
index c36c6c98071..56449a43f72 100644
--- a/src/emu/uiimage.c
+++ b/src/emu/uiimage.c
@@ -149,9 +149,10 @@ static void extra_text_render(render_container *container, float top, float bott
confirm save as menu
-------------------------------------------------*/
-ui_menu_confirm_save_as::ui_menu_confirm_save_as(running_machine &machine, render_container *container, int *_yes) : ui_menu(machine, container)
+ui_menu_confirm_save_as::ui_menu_confirm_save_as(running_machine &machine, render_container *container, bool *_yes) : ui_menu(machine, container)
{
yes = _yes;
+ *yes = false;
}
ui_menu_confirm_save_as::~ui_menu_confirm_save_as()
@@ -160,7 +161,7 @@ ui_menu_confirm_save_as::~ui_menu_confirm_save_as()
void ui_menu_confirm_save_as::populate()
{
- item_append("File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL);
+ item_append("File Already Exists - Override?", NULL, MENU_FLAG_DISABLE, NULL);
item_append(MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL);
item_append("No", NULL, 0, ITEMREF_NO);
item_append("Yes", NULL, 0, ITEMREF_YES);
@@ -179,7 +180,7 @@ void ui_menu_confirm_save_as::handle()
if ((event != NULL) && (event->iptkey == IPT_UI_SELECT))
{
if (event->itemref == ITEMREF_YES)
- *yes = TRUE;
+ *yes = true;
/* no matter what, pop out */
ui_menu::stack_pop(machine());
@@ -224,7 +225,7 @@ static int is_valid_filename_char(unicode_char unichar)
void ui_menu_file_create::custom_render(void *selectedref, float top, float bottom, float origx1, float origy1, float origx2, float origy2)
{
extra_text_render(container, top, bottom, origx1, origy1, origx2, origy2,
- manager->current_directory,
+ current_directory,
NULL);
}
@@ -235,9 +236,9 @@ void ui_menu_file_create::custom_render(void *selectedref, float top, float bott
creator menu
-------------------------------------------------*/
-ui_menu_file_create::ui_menu_file_create(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container)
+ui_menu_file_create::ui_menu_file_create(running_machine &machine, render_container *container, device_image_interface *_image, astring &_current_directory, astring &_current_file) : ui_menu(machine, container), current_directory(_current_directory), current_file(_current_file)
{
- manager = parent;
+ image = _image;
}
ui_menu_file_create::~ui_menu_file_create()
@@ -247,7 +248,6 @@ ui_menu_file_create::~ui_menu_file_create()
void ui_menu_file_create::populate()
{
astring buffer;
- device_image_interface *device = manager->selected_device;
const image_device_format *format;
const char *new_image_name;
@@ -264,7 +264,7 @@ void ui_menu_file_create::populate()
item_append("New Image Name:", new_image_name, 0, ITEMREF_NEW_IMAGE_NAME);
/* do we support multiple formats? */
- format = device->device_get_creatable_formats();
+ format = image->device_get_creatable_formats();
if (ENABLE_FORMATS && (format != NULL))
{
item_append("Image Format:", current_format->m_description, 0, ITEMREF_FORMAT);
@@ -279,94 +279,14 @@ void ui_menu_file_create::populate()
}
-
-/*-------------------------------------------------
- create_new_image - creates a new disk image
--------------------------------------------------*/
-
-int ui_menu_file_create::create_new_image(device_image_interface *image, const char *directory, const char *filename, int *yes)
-{
- astring path;
- osd_directory_entry *entry;
- osd_dir_entry_type file_type;
- int do_create, err;
- int result = FALSE;
-
- /* assemble the full path */
- zippath_combine(path, directory, filename);
-
- /* does a file or a directory exist at the path */
- entry = osd_stat(path);
- file_type = (entry != NULL) ? entry->type : ENTTYPE_NONE;
- if (entry != NULL)
- free(entry);
-
- /* special case */
- if ((file_type == ENTTYPE_FILE) && *yes)
- file_type = ENTTYPE_NONE;
-
- switch(file_type)
- {
- case ENTTYPE_NONE:
- /* no file/dir here - always create */
- do_create = TRUE;
- break;
-
- case ENTTYPE_FILE:
- /* a file exists here - ask for permission from the user */
- ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_confirm_save_as(machine(), container, yes)));
- do_create = FALSE;
- break;
-
- case ENTTYPE_DIR:
- /* a directory exists here - we can't save over it */
- ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over directory");
- do_create = FALSE;
- break;
-
- default:
- fatalerror("Unexpected");
- do_create = FALSE;
- break;
- }
-
- /* create the image, if appropriate */
- if (do_create)
- {
- err = image->create(path, 0, NULL);
- if (err != 0)
- popmessage("Error: %s", image->error());
- else
- result = TRUE;
- }
-
- return result;
-}
-
-
-
/*-------------------------------------------------
menu_file_create - file creator menu
-------------------------------------------------*/
void ui_menu_file_create::handle()
{
- const ui_menu_event *event;
- ui_menu_event fake_event;
-
- if (confirm_save_as_yes)
- {
- /* we just returned from a "confirm save as" dialog and the user said "yes" - fake an event */
- memset(&fake_event, 0, sizeof(fake_event));
- fake_event.iptkey = IPT_UI_SELECT;
- fake_event.itemref = ITEMREF_CREATE;
- event = &fake_event;
- }
- else
- {
- /* process the menu */
- event = process(0);
- }
+ /* process the menu */
+ const ui_menu_event *event = process(0);
/* process the event */
if (event != NULL)
@@ -377,16 +297,8 @@ void ui_menu_file_create::handle()
case IPT_UI_SELECT:
if ((event->itemref == ITEMREF_CREATE) || (event->itemref == ITEMREF_NEW_IMAGE_NAME))
{
- if (create_new_image(
- manager->selected_device,
- manager->current_directory,
- filename_buffer,
- &confirm_save_as_yes))
- {
- /* success - pop out twice to device view */
- ui_menu::stack_pop(machine());
- ui_menu::stack_pop(machine());
- }
+ current_file.cpy(filename_buffer);
+ ui_menu::stack_pop(machine());
}
break;
@@ -398,6 +310,7 @@ void ui_menu_file_create::handle()
ARRAY_LENGTH(filename_buffer),
event->unichar,
is_valid_filename_char);
+ reset(UI_MENU_RESET_REMEMBER_POSITION);
}
break;
}
@@ -419,7 +332,7 @@ void ui_menu_file_selector::custom_render(void *selectedref, float top, float bo
{
extra_text_render(container, top, bottom,
origx1, origy1, origx2, origy2,
- manager->current_directory,
+ current_directory,
NULL);
}
@@ -523,10 +436,7 @@ ui_menu_file_selector::file_selector_entry *ui_menu_file_selector::append_dirent
}
/* determine the full path */
- zippath_combine(
- buffer,
- manager->current_directory,
- dirent->name);
+ zippath_combine(buffer, current_directory, dirent->name);
/* create the file selector entry */
entry = append_entry(
@@ -587,9 +497,13 @@ void ui_menu_file_selector::append_entry_menu_item(const file_selector_entry *en
allocates all menu items for a directory
-------------------------------------------------*/
-ui_menu_file_selector::ui_menu_file_selector(running_machine &machine, render_container *container, ui_menu_file_manager *parent) : ui_menu(machine, container)
+ui_menu_file_selector::ui_menu_file_selector(running_machine &machine, render_container *container, device_image_interface *_image, astring &_current_directory, astring &_current_file, bool _has_empty, bool _has_softlist, bool _has_create, int *_result) : ui_menu(machine, container), current_directory(_current_directory), current_file(_current_file)
{
- manager = parent;
+ image = _image;
+ has_empty = _has_empty;
+ has_softlist = _has_softlist;
+ has_create = _has_create;
+ result = _result;
}
ui_menu_file_selector::~ui_menu_file_selector()
@@ -605,8 +519,10 @@ void ui_menu_file_selector::populate()
const file_selector_entry *selected_entry = NULL;
int i;
const char *volume_name;
- device_image_interface *device = manager->selected_device;
- const char *path = manager->current_directory;
+ const char *path = current_directory;
+
+ if(path[0])
+ fprintf(stderr, "curdir=%s\n", path);
/* open the directory */
err = zippath_opendir(path, &directory);
@@ -616,17 +532,21 @@ void ui_menu_file_selector::populate()
/* clear out the menu entries */
entrylist = NULL;
- /* add the "[empty slot]" entry */
- append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL);
+ if (has_empty)
+ {
+ /* add the "[empty slot]" entry */
+ append_entry(SELECTOR_ENTRY_TYPE_EMPTY, NULL, NULL);
+ }
- if (device->is_creatable() && !zippath_is_zip(directory))
+ if (has_create)
{
/* add the "[create]" entry */
append_entry(SELECTOR_ENTRY_TYPE_CREATE, NULL, NULL);
}
- /* add the "[software list]" entry */
- append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL);
+ if (has_softlist)
+ /* add the "[software list]" entry */
+ append_entry(SELECTOR_ENTRY_TYPE_SOFTWARE_LIST, NULL, NULL);
/* add the drives */
i = 0;
@@ -650,7 +570,7 @@ void ui_menu_file_selector::populate()
selected_entry = entry;
/* do we have to select this file? */
- if (!mame_stricmp(manager->current_file, dirent->name))
+ if (!mame_stricmp(current_file, dirent->name))
selected_entry = entry;
}
}
@@ -671,17 +591,6 @@ done:
zippath_closedir(directory);
}
-/*-------------------------------------------------
- check_path - performs a quick check to see if
- a path exists
--------------------------------------------------*/
-
-static file_error check_path(const char *path)
-{
- return zippath_opendir(path, NULL);
-}
-
-
/*-------------------------------------------------
menu_file_selector - file selector menu
@@ -706,34 +615,37 @@ void ui_menu_file_selector::handle()
{
case SELECTOR_ENTRY_TYPE_EMPTY:
/* empty slot - unload */
- manager->selected_device->unload();
+ *result = R_EMPTY;
ui_menu::stack_pop(machine());
break;
case SELECTOR_ENTRY_TYPE_CREATE:
/* create */
- ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_create(machine(), container, manager)));
+ *result = R_CREATE;
+ ui_menu::stack_pop(machine());
break;
case SELECTOR_ENTRY_TYPE_SOFTWARE_LIST:
- ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_software(machine(), container, manager->selected_device)));
+ *result = R_SOFTLIST;
+ ui_menu::stack_pop(machine());
break;
case SELECTOR_ENTRY_TYPE_DRIVE:
case SELECTOR_ENTRY_TYPE_DIRECTORY:
/* drive/directory - first check the path */
- err = check_path(entry->fullpath);
+ err = zippath_opendir(entry->fullpath, NULL);
if (err != FILERR_NONE)
{
/* this path is problematic; present the user with an error and bail */
ui_popup_time(1, "Error accessing %s", entry->fullpath);
break;
}
- manager->current_directory.cpy(entry->fullpath);
+ current_directory.cpy(entry->fullpath);
reset((ui_menu_reset_options)0);
break;
case SELECTOR_ENTRY_TYPE_FILE:
/* file */
- manager->selected_device->load(entry->fullpath);
+ current_file.cpy(entry->fullpath);
+ *result = R_FILE;
ui_menu::stack_pop(machine());
break;
}
@@ -830,28 +742,6 @@ void ui_menu_file_selector::handle()
FILE MANAGER
***************************************************************************/
-/*-------------------------------------------------
- fix_working_directory - checks the working
- directory for this device to ensure that it
- "makes sense"
--------------------------------------------------*/
-
-void ui_menu_file_manager::fix_working_directory(device_image_interface *image)
-{
- /* if the image exists, set the working directory to the parent directory */
- if (image->exists())
- {
- astring astr;
- zippath_parent(astr, image->filename());
- image->set_working_directory(astr);
- }
-
- /* check to see if the path exists; if not clear it */
- if (check_path(image->working_directory()) != FILERR_NONE)
- image->set_working_directory("");
-}
-
-
/*-------------------------------------------------
file_manager_render_extra - perform our
@@ -954,18 +844,10 @@ void ui_menu_file_manager::handle()
selected_device = (device_image_interface *) event->itemref;
if (selected_device != NULL)
{
- /* ensure that the working directory for this device exists */
- fix_working_directory(selected_device);
-
- /* set up current_directory and current_file - depends on whether we have an image */
- current_directory.cpy(selected_device->working_directory());
- current_file.cpy(selected_device->exists() ? selected_device->basename() : "");
+ ui_menu::stack_push(selected_device->get_selection_menu(machine(), container));
/* reset the existing menu */
reset(UI_MENU_RESET_REMEMBER_POSITION);
-
- /* push the menu */
- ui_menu::stack_push(auto_alloc_clear(machine(), ui_menu_file_selector(machine(), container, this)));
}
}
}