Previous 15994 Revisions Next

r3095 Saturday 23rd August, 2008 at 19:51:01 UTC by Nathan Woods
File Manager will now prompt user when saving over existing images, and allow
the user to do so if they say "yes"
[docs]messnew.txt
[src/mess]filemngr.c

src/mess/filemngr.c
r3094r3095
3737#define ITEMREF_NEW_IMAGE_NAME   ((void *) 0x0001)
3838#define ITEMREF_CREATE         ((void *) 0x0002)
3939#define ITEMREF_FORMAT         ((void *) 0x0003)
40#define ITEMREF_NO            ((void *) 0x0004)
41#define ITEMREF_YES            ((void *) 0x0005)
4042
4143
4244
r3094r3095
9799{
98100   file_manager_menu_state *manager_menustate;
99101   const image_device_format *current_format;
102   int confirm_save_as_yes;
100103   char filename_buffer[1024];
101104};
102105
103106
107/* state of the confirm save as menu */
108typedef struct _confirm_save_as_menu_state confirm_save_as_menu_state;
109struct _confirm_save_as_menu_state
110{
111   int *yes;
112};
104113
114
115
105116/***************************************************************************
106117    MENU HELPERS
107118***************************************************************************/
r3094r3095
195206
196207
197208/***************************************************************************
209    CONFIRM SAVE AS MENU
210***************************************************************************/
211
212/*-------------------------------------------------
213    menu_confirm_save_as_populate - populates the
214   confirm save as menu
215-------------------------------------------------*/
216
217static void menu_confirm_save_as_populate(running_machine *machine, ui_menu *menu, void *state)
218{
219   ui_menu_item_append(menu, "File Already Exists - Overide?", NULL, MENU_FLAG_DISABLE, NULL);
220   ui_menu_item_append(menu, MENU_SEPARATOR_ITEM, NULL, MENU_FLAG_DISABLE, NULL);
221   ui_menu_item_append(menu, "No", NULL, 0, ITEMREF_NO);
222   ui_menu_item_append(menu, "Yes", NULL, 0, ITEMREF_YES);
223}
224
225
226
227/*-------------------------------------------------
228    menu_confirm_save_as - confirm save as menu
229-------------------------------------------------*/
230
231static void menu_confirm_save_as(running_machine *machine, ui_menu *menu, void *parameter, void *state)
232{
233   const ui_menu_event *event;
234   confirm_save_as_menu_state *menustate = (confirm_save_as_menu_state *) state;
235
236   /* if the menu isn't built, populate now */
237   if (!ui_menu_populated(menu))
238      menu_confirm_save_as_populate(machine, menu, state);
239
240   /* process the menu */
241   event = ui_menu_process(menu, 0);
242
243   /* process the event */
244   if ((event != NULL) && (event->iptkey == IPT_UI_SELECT))
245   {
246      if (event->itemref == ITEMREF_YES)
247         *menustate->yes = TRUE;
248
249      /* no matter what, pop out */
250      ui_menu_stack_pop(machine);
251   }
252}
253
254
255
256/***************************************************************************
198257    FILE CREATE MENU
199258***************************************************************************/
200259
r3094r3095
288347    create_new_image - creates a new disk image
289348-------------------------------------------------*/
290349
291static int create_new_image(const device_config *device, const char *directory, const char *filename)
350static int create_new_image(const device_config *device, const char *directory, const char *filename, int *yes)
292351{
293352   astring *path;
294353   osd_directory_entry *entry;
295354   osd_dir_entry_type file_type;
296355   int do_create, err;
297356   int result = FALSE;
357   ui_menu *child_menu;
358   confirm_save_as_menu_state *child_menustate;
298359
299360   /* assemble the full path */
300361   path = zippath_combine(astring_alloc(), directory, filename);
r3094r3095
305366   if (entry != NULL)
306367      free(entry);
307368
369   /* special case */
370   if ((file_type == ENTTYPE_FILE) && *yes)
371      file_type = ENTTYPE_NONE;
372
308373   switch(file_type)
309374   {
310375      case ENTTYPE_NONE:
r3094r3095
313378         break;
314379
315380      case ENTTYPE_FILE:
316         /* TODO - we should be raising a warning here, not an error */
317         ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over file");
381         /* a file exists here - ask for permission from the user */
382         child_menu = ui_menu_alloc(device->machine, menu_confirm_save_as, NULL);
383         child_menustate = ui_menu_alloc_state(child_menu, sizeof(*child_menustate), NULL);
384         child_menustate->yes = yes;
385         ui_menu_stack_push(child_menu);
318386         do_create = FALSE;
319387         break;
320388
321389      case ENTTYPE_DIR:
390         /* a directory exists here - we can't save over it */
322391         ui_popup_time(ERROR_MESSAGE_TIME, "Cannot save over directory");
323392         do_create = FALSE;
324393         break;
r3094r3095
355424{
356425   void *selection;
357426   const ui_menu_event *event;
427   ui_menu_event fake_event;
358428   file_create_menu_state *menustate = (file_create_menu_state *) state;
359429
360430   /* identify the selection */
r3094r3095
364434   ui_menu_reset(menu, UI_MENU_RESET_REMEMBER_POSITION);
365435   menu_file_create_populate(machine, menu, state, selection);
366436
367   /* process the menu */
368   event = ui_menu_process(menu, 0);
437   if (menustate->confirm_save_as_yes)
438   {
439      /* we just returned from a "confirm save as" dialog and the user said "yes" - fake an event */
440      memset(&fake_event, 0, sizeof(fake_event));
441      fake_event.iptkey = IPT_UI_SELECT;
442      fake_event.itemref = ITEMREF_CREATE;
443      event = &fake_event;
444   }
445   else
446   {
447      /* process the menu */
448      event = ui_menu_process(menu, 0);
449   }
369450
370451   /* process the event */
371452   if (event != NULL)
r3094r3095
379460               if (create_new_image(
380461                  menustate->manager_menustate->selected_device,
381462                  astring_c(menustate->manager_menustate->current_directory),
382                  menustate->filename_buffer))
463                  menustate->filename_buffer,
464                  &menustate->confirm_save_as_yes))
383465               {
384466                  /* success - pop out twice to device view */
385467                  ui_menu_stack_pop(machine);
docs/messnew.txt
r3094r3095
3333
3434User Interface Changes:
3535-----------------------
36- Major file manager improvements; much better experience for creating new
37  images.  (bugs #1653, #1654) [Nate Woods]
38
3639- Fixed bug that caused "categorized" inputs (used on Atari 2600, NES, SMS)
3740  to not be remappable.  (bug #1614) [Nate Woods]
3841

Previous 15994 Revisions Next


© 1998-2018 The MESS Team