Previous 15994 Revisions Next

r2958 Thursday 17th July, 2008 at 11:24:30 UTC by Nathan Woods
A file manager fix... still more work to do
[src/mess]filemngr.c

src/mess/filemngr.c
r2957r2958
2525    CONSTANTS
2626***************************************************************************/
2727
28#define SLOT_EMPTY            "[empty slot]"
29#define SLOT_CREATE            "[create]"
30
3128#define ITEMREF_NEW_IMAGE_NAME   ((void *) 0x0001)
29#define ITEMREF_EMPTY_SLOT      ((void *) 0x0002)
30#define ITEMREF_CREATE         ((void *) 0x0003)
3231
3332
3433
r2957r2958
491490      goto done;
492491
493492   /* add the "[empty slot]" entry */
494   append_menu_item(menu, menustate, SLOT_EMPTY, NULL, NULL, ENTTYPE_FILE, 0, FALSE);
493   ui_menu_item_append(menu, "[empty slot]", NULL, 0, ITEMREF_EMPTY_SLOT);
495494
496495   info = image_device_getinfo(device->machine->config, device);
497496   if (info.creatable && !zippath_is_zip(directory))
498497   {
499498      /* add the "[create]" entry */
500      append_menu_item(menu, menustate, SLOT_CREATE, NULL, NULL, ENTTYPE_FILE, 0, FALSE);
499      ui_menu_item_append(menu, "[create]", NULL, 0, ITEMREF_CREATE);
501500   }
502501
503502   /* add the drives */
r2957r2958
603602      /* handle selections */
604603      if (event->iptkey == IPT_UI_SELECT)
605604      {
606         dirent = (const osd_directory_entry *) event->itemref;
607         ui_menu_reset(menu, 0);
608
609         switch(dirent->type)
605         if (event->itemref == ITEMREF_EMPTY_SLOT)
610606         {
611            case ENTTYPE_DIR:
612               /* prepare the selection in the new directory */
613               selected = 1;
614               if (!strcmp(dirent->name, ".."))
615                  zippath_parent_basename(menustate->manager_menustate->current_file, astring_c(menustate->manager_menustate->current_directory));
607            /* empty slot - unload */
608            image_unload(menustate->manager_menustate->selected_device);
609            ui_menu_stack_pop(machine);
610         }
611         else if (event->itemref == ITEMREF_CREATE)
612         {
613            /* create */
614            child_menu = ui_menu_alloc(machine, menu_file_create, NULL);
615            child_menustate = ui_menu_alloc_state(child_menu, sizeof(*child_menustate));
616            child_menustate->manager_menustate = menustate->manager_menustate;
617            ui_menu_stack_push(child_menu);
618         }
619         else
620         {
621            dirent = (const osd_directory_entry *) event->itemref;
622            ui_menu_reset(menu, 0);
616623
617               /* change the directory */
618               new_path = zippath_combine(astring_alloc(), astring_c(menustate->manager_menustate->current_directory), dirent->name);
619               err = check_path(astring_c(new_path));
620               if (err != FILERR_NONE)
621               {
622                  /* this path is problematic; present the user with an error and bail */
623                  ui_popup_time(1, "Error accessing %s", astring_c(new_path));
624                  astring_free(new_path);
624            switch(dirent->type)
625            {
626               case ENTTYPE_DIR:
627                  /* prepare the selection in the new directory */
628                  selected = 1;
629                  if (!strcmp(dirent->name, ".."))
630                     zippath_parent_basename(menustate->manager_menustate->current_file, astring_c(menustate->manager_menustate->current_directory));
631
632                  /* change the directory */
633                  new_path = zippath_combine(astring_alloc(), astring_c(menustate->manager_menustate->current_directory), dirent->name);
634                  err = check_path(astring_c(new_path));
635                  if (err != FILERR_NONE)
636                  {
637                     /* this path is problematic; present the user with an error and bail */
638                     ui_popup_time(1, "Error accessing %s", astring_c(new_path));
639                     astring_free(new_path);
640                     break;
641                  }
642                  astring_free(menustate->manager_menustate->current_directory);
643                  menustate->manager_menustate->current_directory = new_path;
625644                  break;
626               }
627               astring_free(menustate->manager_menustate->current_directory);
628               menustate->manager_menustate->current_directory = new_path;
629               break;
630645
631            case ENTTYPE_FILE:
632               if (dirent->name != NULL)
633               {
646               case ENTTYPE_FILE:
634647                  /* specified a file */
635648                  new_path = zippath_combine(astring_alloc(), astring_c(menustate->manager_menustate->current_directory), dirent->name);
636649                  image_load(menustate->manager_menustate->selected_device, astring_c(new_path));
637650                  astring_free(new_path);
638               }
639               else if (!strcmp(dirent->name, SLOT_EMPTY))
640               {
641                  /* empty slot - unload */
642                  image_unload(menustate->manager_menustate->selected_device);
643               }
644               else if (!strcmp(dirent->name, SLOT_CREATE))
645               {
646                  /* create */
647                  child_menu = ui_menu_alloc(machine, menu_file_create, NULL);
648                  child_menustate = ui_menu_alloc_state(child_menu, sizeof(*child_menustate));
649                  child_menustate->manager_menustate = menustate->manager_menustate;
650                  ui_menu_stack_push(child_menu);
651               }
652               else
653               {
654                  fatalerror("Should not reach here");
655               }
656               ui_menu_stack_pop(machine);
657               break;
651                  ui_menu_stack_pop(machine);
652                  break;
658653
659            default:
660               /* do nothing */
661               break;
654               default:
655                  /* do nothing */
656                  break;
657            }
662658         }
663659      }
664660   }

Previous 15994 Revisions Next


© 1998-2018 The MESS Team