src/mess/filemngr.c
| r2957 | r2958 | |
| 25 | 25 | CONSTANTS |
| 26 | 26 | ***************************************************************************/ |
| 27 | 27 | |
| 28 | | #define SLOT_EMPTY "[empty slot]" |
| 29 | | #define SLOT_CREATE "[create]" |
| 30 | | |
| 31 | 28 | #define ITEMREF_NEW_IMAGE_NAME ((void *) 0x0001) |
| 29 | #define ITEMREF_EMPTY_SLOT ((void *) 0x0002) |
| 30 | #define ITEMREF_CREATE ((void *) 0x0003) |
| 32 | 31 | |
| 33 | 32 | |
| 34 | 33 | |
| r2957 | r2958 | |
| 491 | 490 | goto done; |
| 492 | 491 | |
| 493 | 492 | /* 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); |
| 495 | 494 | |
| 496 | 495 | info = image_device_getinfo(device->machine->config, device); |
| 497 | 496 | if (info.creatable && !zippath_is_zip(directory)) |
| 498 | 497 | { |
| 499 | 498 | /* 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); |
| 501 | 500 | } |
| 502 | 501 | |
| 503 | 502 | /* add the drives */ |
| r2957 | r2958 | |
| 603 | 602 | /* handle selections */ |
| 604 | 603 | if (event->iptkey == IPT_UI_SELECT) |
| 605 | 604 | { |
| 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) |
| 610 | 606 | { |
| 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); |
| 616 | 623 | |
| 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; |
| 625 | 644 | break; |
| 626 | | } |
| 627 | | astring_free(menustate->manager_menustate->current_directory); |
| 628 | | menustate->manager_menustate->current_directory = new_path; |
| 629 | | break; |
| 630 | 645 | |
| 631 | | case ENTTYPE_FILE: |
| 632 | | if (dirent->name != NULL) |
| 633 | | { |
| 646 | case ENTTYPE_FILE: |
| 634 | 647 | /* specified a file */ |
| 635 | 648 | new_path = zippath_combine(astring_alloc(), astring_c(menustate->manager_menustate->current_directory), dirent->name); |
| 636 | 649 | image_load(menustate->manager_menustate->selected_device, astring_c(new_path)); |
| 637 | 650 | 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; |
| 658 | 653 | |
| 659 | | default: |
| 660 | | /* do nothing */ |
| 661 | | break; |
| 654 | default: |
| 655 | /* do nothing */ |
| 656 | break; |
| 657 | } |
| 662 | 658 | } |
| 663 | 659 | } |
| 664 | 660 | } |