Changeset 1423 for trunk


Ignore:
Timestamp:
11/23/11 02:27:57 (18 months ago)
Author:
philmoz
Message:

Improvements to the file selector system, inspired by tsvstars text reader suggestions.

  • File selector can be passed in an existing file name rather than just a directory to start in. If it exists the file is automatically selected in the file list.
  • Updated calls to the file selector to pass in the previous file for the text reader, script selector, curve selector, grid selector, language selector and font selectors. These will now open in the previous directory with the previous file pre-selected.
  • Changed the default text reader file to A/CHDK/BOOKS/README.TXT (was A/README.TXT which does not exist).

Also includes change to enable the MENU key to work for the file selector popup menu (exits popup menu).

Location:
trunk/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/core/conf.c

    r1416 r1423  
    184184    CONF_INFO( 36, conf.raw_prefix,             CONF_DEF_VALUE, i:RAW_PREFIX_CRW, NULL), 
    185185    CONF_INFO( 37, conf.raw_ext,                CONF_DEF_VALUE, i:DEFAULT_RAW_EXT, NULL), 
    186     CONF_INFO( 38, conf.reader_file,            CONF_DEF_PTR,   ptr:"A/README.TXT", NULL), 
     186    CONF_INFO( 38, conf.reader_file,            CONF_DEF_PTR,   ptr:"A/CHDK/BOOKS/README.TXT", NULL), 
    187187    CONF_INFO( 39, conf.reader_pos,             CONF_DEF_VALUE, i:0, NULL), 
    188188    CONF_INFO( 40, conf.sokoban_level,          CONF_DEF_VALUE, i:0, NULL), 
  • trunk/core/gui.c

    r1414 r1423  
    11431143 
    11441144void gui_load_script(int arg) { 
    1145     DIR   *d; 
    1146     char  *path="A/CHDK/SCRIPTS"; 
    1147  
    1148     // if exists "A/CHDK/SCRIPTS" go into 
    1149     d=opendir(path); 
    1150     if (d) { 
    1151         closedir(d); 
    1152     } else { 
    1153         path="A"; 
    1154     } 
    1155  
    1156     gui_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, path, gui_load_script_selected); 
     1145    gui_fselect_init(LANG_STR_SELECT_SCRIPT_FILE, conf.script_file, "A/CHDK/SCRIPTS", gui_load_script_selected); 
    11571146} 
    11581147 
     
    13401329                "64","50.8", "40.3", "32", "25.4","20","16", "12.7", "10","8", "6.3","5","4","3.2", "2.5","2", "1.6", "1.3", "1", "0.8", "0.6", "0.5", "0.4", "0.3", "1/4", "1/5", "1/6", "1/8", "1/10", "1/13", "1/15", "1/20", "1/25", "1/30", "1/40", "1/50", "1/60", "1/80", "1/100", "1/125", "1/160", "1/200", "1/250", "1/320", "1/400", "1/500", "1/640","1/800", "1/1000", "1/1250", "1/1600","1/2000","1/2500","1/3200","1/4000", "1/5000", "1/6400", "1/8000", "1/10000", "1/12500", "1/16000", "1/20000", "1/25000", "1/32000", "1/40000", "1/50000", "1/64000","1/80000", "1/100k"}; 
    13411330                */ 
    1342     static char *buf; 
     1331    static char buf[4]; 
    13431332 
    13441333        // XXX This array above is redundant with platform/generic/shooting.c, this should be avoided! 
     
    13581347        } 
    13591348       else if (conf.tv_override_value>100)  conf.tv_override_value=0; 
    1360        if(!buf) buf=malloc(4); 
    1361        if(!buf) return ""; 
    13621349       sprintf(buf, "%d",  conf.tv_override_value); 
    13631350       return buf; 
     
    15321519void gui_raw_develop(int arg){ 
    15331520 int m=mode_get(); 
    1534  gui_fselect_init(LANG_RAW_DEVELOP_SELECT_FILE, "A/DCIM", raw_fselect_cb); 
     1521 gui_fselect_init(LANG_RAW_DEVELOP_SELECT_FILE, "A/DCIM", "A", raw_fselect_cb); 
    15351522} 
    15361523 
     
    16961683//------------------------------------------------------------------- 
    16971684void gui_load_curve(int arg) { 
    1698     DIR   *d; 
    1699     char  *path = CURVE_DIR; 
    1700  
    1701     // if exists CURVE_DIR go into 
    1702     d=opendir(path); 
    1703     if (d) { 
    1704         closedir(d); 
    1705     } else { 
    1706         path="A"; 
    1707     } 
    1708  
    1709     gui_fselect_init(LANG_STR_SELECT_CURVE_FILE, path, gui_load_curve_selected); 
     1685    gui_fselect_init(LANG_STR_SELECT_CURVE_FILE, conf.curve_file, CURVE_DIR, gui_load_curve_selected); 
    17101686} 
    17111687 
     
    20622038                                { 0, 0, 0 }, 
    20632039#endif 
    2064     /*GUI_MODE_MPOPUP*/         { gui_mpopup_draw,      gui_mpopup_kbd_process,     0 }, 
     2040    /*GUI_MODE_MPOPUP*/         { gui_mpopup_draw,      gui_mpopup_kbd_process,     gui_mpopup_kbd_process }, 
    20652041#ifdef OPT_GAME_CONNECT4 
    20662042    /*GUI_MODE_4WINS*/          { gui_4wins_draw,       gui_4wins_kbd_process,      gui_default_kbd_process_menu_btn }, 
     
    27422718//------------------------------------------------------------------- 
    27432719void gui_draw_fselect(int arg) { 
    2744     gui_fselect_init(LANG_STR_FILE_BROWSER, "A", NULL); 
     2720    gui_fselect_init(LANG_STR_FILE_BROWSER, "A", "A", NULL); 
    27452721} 
    27462722 
     
    27512727} 
    27522728void gui_grid_lines_load(int arg) { 
    2753     DIR   *d; 
    2754     char  *path="A/CHDK/GRIDS"; 
    2755  
    2756     // if exists "A/CHDK/GRIDS" go into 
    2757     d=opendir(path); 
    2758     if (d) { 
    2759         closedir(d); 
    2760     } else { 
    2761         path="A"; 
    2762     } 
    2763  
    2764     gui_fselect_init(LANG_STR_SELECT_GRID_FILE, path, gui_grid_lines_load_selected); 
     2729    gui_fselect_init(LANG_STR_SELECT_GRID_FILE, conf.grid_lines_file, "A/CHDK/GRIDS", gui_grid_lines_load_selected); 
    27652730} 
    27662731 
     
    27822747    } 
    27832748} 
     2749 
    27842750void gui_draw_read(int arg) { 
    2785     DIR   *d; 
    2786     char  *path="A/CHDK/BOOKS"; 
    2787  
    2788     // if exists "A/CHDK/BOOKS" go into 
    2789     d=opendir(path); 
    2790     if (d) { 
    2791         closedir(d); 
    2792     } else { 
    2793         path="A"; 
    2794     } 
    2795     gui_fselect_init(LANG_STR_SELECT_TEXT_FILE, path, gui_draw_read_selected); 
     2751    gui_fselect_init(LANG_STR_SELECT_TEXT_FILE, conf.reader_file, "A/CHDK/BOOKS", gui_draw_read_selected); 
    27962752    void gui_fselect_set_key_redraw(int n); 
    27972753    gui_fselect_set_key_redraw(1); 
    27982754} 
    27992755 
    2800 //------------------------------------------------------------------- 
    28012756void gui_draw_read_last(int arg) { 
    2802     int fd; 
    2803  
    2804     fd = open(conf.reader_file, O_RDONLY, 0777); 
    2805     if (fd >= 0) { 
    2806         close(fd); 
     2757    struct stat st; 
     2758    if (stat(conf.reader_file,&st) == 0) { 
    28072759        gui_draw_read_selected(conf.reader_file); 
    28082760    } else { 
     
    28292781 
    28302782void gui_menuproc_edge_load(int arg) { 
    2831     DIR   *d; 
    2832     char  *path = EDGE_SAVE_DIR; 
    2833     const char* fn; 
    2834  
    2835     // if exists, go into 
    2836     d=opendir(path); 
    2837     if (d) { 
    2838         closedir(d); 
    2839     } else { 
    2840         path="A"; 
    2841     } 
    2842  
    2843     gui_fselect_init(LANG_MENU_EDGE_LOAD, path, gui_load_edge_selected); 
     2783    gui_fselect_init(LANG_MENU_EDGE_LOAD, EDGE_SAVE_DIR, EDGE_SAVE_DIR, gui_load_edge_selected); 
    28442784} 
    28452785#endif 
     
    28602800} 
    28612801void gui_draw_load_rbf(int arg) { 
    2862     DIR   *d; 
    2863     char  *path="A/CHDK/FONTS"; 
    2864  
    2865     // if exists "A/CHDK/FONTS" go into 
    2866     d=opendir(path); 
    2867     if (d) { 
    2868         closedir(d); 
    2869     } else { 
    2870         path="A"; 
    2871     } 
    2872  
    2873     gui_fselect_init(LANG_STR_SELECT_FONT_FILE, path, gui_draw_rbf_selected); 
     2802    gui_fselect_init(LANG_STR_SELECT_FONT_FILE, conf.reader_rbf_file, "A/CHDK/FONTS", gui_draw_rbf_selected); 
    28742803} 
    28752804#endif 
     
    28852814} 
    28862815void gui_draw_load_menu_rbf(int arg) { 
    2887     DIR   *d; 
    2888     char  *path="A/CHDK/FONTS"; 
    2889  
    2890     // if exists "A/CHDK/FONTS" go into 
    2891     d=opendir(path); 
    2892     if (d) { 
    2893         closedir(d); 
    2894     } else { 
    2895         path="A"; 
    2896     } 
    2897  
    2898     gui_fselect_init(LANG_STR_SELECT_FONT_FILE, path, gui_draw_menu_rbf_selected); 
     2816    gui_fselect_init(LANG_STR_SELECT_FONT_FILE, conf.menu_rbf_file, "A/CHDK/FONTS", gui_draw_menu_rbf_selected); 
    28992817} 
    29002818 
     
    29082826} 
    29092827void gui_draw_load_symbol_rbf(int arg) { 
    2910     DIR   *d; 
    2911     char  *path="A/CHDK/SYMBOLS"; 
    2912  
    2913     // if exists "A/CHDK/FONTS" go into 
    2914     d=opendir(path); 
    2915     if (d) { 
    2916         closedir(d); 
    2917     } else { 
    2918         path="A"; 
    2919     } 
    2920  
    2921     gui_fselect_init(LANG_STR_SELECT_SYMBOL_FILE, path, gui_draw_symbol_rbf_selected); 
     2828    gui_fselect_init(LANG_STR_SELECT_SYMBOL_FILE, conf.menu_symbol_rbf_file, "A/CHDK/SYMBOLS", gui_draw_symbol_rbf_selected); 
    29222829} 
    29232830 
     
    29312838} 
    29322839void gui_draw_load_lang(int arg) { 
    2933     DIR   *d; 
    2934     char  *path="A/CHDK/LANG"; 
    2935  
    2936     // if exists "A/CHDK/LANG" go into 
    2937     d=opendir(path); 
    2938     if (d) { 
    2939         closedir(d); 
    2940     } else { 
    2941         path="A"; 
    2942     } 
    2943  
    2944     gui_fselect_init(LANG_STR_SELECT_LANG_FILE, path, gui_draw_lang_selected); 
     2840    gui_fselect_init(LANG_STR_SELECT_LANG_FILE, conf.lang_file, "A/CHDK/LANG", gui_draw_lang_selected); 
    29452841} 
    29462842 
  • trunk/core/gui_fselect.c

    r1407 r1423  
    8181static char raw_operation;      // info for process_raw_files() RAW_OPERATION_AVERAGE, RAW_OPERATION_SUM,  
    8282static int set_key_redraw_mode; // dirty hack: screen erase & mode restore done after(0) or before(1) call to fselect_on_select 
     83 
     84//------------------------------------------------------------------- 
     85static void fselect_goto_prev(int step) { 
     86    register int j, i; 
     87 
     88    for (j=0; j<step; ++j) { 
     89        if (selected->prev==top && top->prev)  
     90            top=top->prev; 
     91        if (selected->prev)  
     92            selected=selected->prev; 
     93        else 
     94        if (step == 1) 
     95        { 
     96            for(; selected->next; selected=selected->next); 
     97            for (i=0, top=selected; i<BODY_LINES-1 && top->prev; ++i, top=top->prev); 
     98        } 
     99    } 
     100} 
     101 
     102//------------------------------------------------------------------- 
     103static void fselect_goto_next(int step) { 
     104    register int j, i; 
     105    struct fitem  *ptr; 
     106 
     107    for (j=0; j<step; ++j) { 
     108        for (i=0, ptr=top; i<BODY_LINES-1 && ptr; ++i, ptr=ptr->next); 
     109        if (i==BODY_LINES-1 && ptr && ptr->prev==selected && ptr->next) 
     110            top=top->next; 
     111        if (selected->next)  
     112            selected=selected->next; 
     113        else 
     114        if (step == 1) 
     115        { 
     116            for(; top->prev; top = top->prev); 
     117            selected = top; 
     118        } 
     119    } 
     120} 
    83121 
    84122//------------------------------------------------------------------- 
     
    223261} 
    224262 
    225 void gui_fselect_init(int title, const char* dir, void (*on_select)(const char *fn)) { 
     263//------------------------------------------------------------------- 
     264// Attempt to set startup directory (and file) based on input 'dir' 
     265// Note: 'dir' may be a directory name or a file name (including path) 
     266// Returns 1 if valid directory/file found, 0 otherwise 
     267int gui_fselect_find_start_dir(const char* dir) 
     268{ 
     269    selected_file[0] = 0; 
     270    strcpy(current_dir, dir); 
     271 
     272    // Make sure there is something left to check 
     273    while (strlen(current_dir) > 0) 
     274    { 
     275        struct stat st; 
     276        // check if input 'dir' exists 
     277        if (stat(current_dir,&st) == 0)      
     278        { 
     279            // exists - check if it is a directory or file 
     280            if (st.st_attrib & DOS_ATTR_DIRECTORY) 
     281            { 
     282                // Directory and exists so all good 
     283                return 1; 
     284            } 
     285            else 
     286            { 
     287                // 'dir' is a file, extract filename to 'selected_file' and remove from 'current_dir' 
     288                char *p = strrchr(current_dir,'/'); 
     289                strcpy(selected_file, p+1); 
     290                *p = 0; 
     291                return 1; 
     292            } 
     293        } 
     294        else 
     295        { 
     296            // could not find 'dir' - try one level up 
     297            char *p = strrchr(current_dir,'/'); 
     298            if (p) *p = 0; 
     299            else return 0; 
     300        } 
     301    } 
     302 
     303    return 0; 
     304} 
     305 
     306//------------------------------------------------------------------- 
     307void gui_fselect_init(int title, const char* prev_dir, const char* default_dir, void (*on_select)(const char *fn)) { 
    226308    int i; 
    227309     
     
    242324     
    243325    fselect_title = lang_str(title); 
    244     strcpy(current_dir, dir); 
     326 
     327    // Try and set start directory, and optionally selected file, from inputs 
     328    if (!gui_fselect_find_start_dir(prev_dir))  
     329        if (!gui_fselect_find_start_dir(default_dir)) 
     330            gui_fselect_find_start_dir("A"); 
     331 
    245332    max_dir_len = NAME_SIZE + SIZE_SIZE + SPACING; 
    246333    gui_fselect_read_dir(current_dir); 
    247334    top = selected = head; 
    248     selected_file[0] = 0; 
     335 
     336    // Find selected file if it exists in list 
     337    if (selected_file[0]) 
     338    { 
     339        struct fitem *p = head; 
     340        while (p) 
     341        { 
     342            if (strcmp(p->name,selected_file) == 0) 
     343            { 
     344                break; 
     345            } 
     346            p = p->next; 
     347            fselect_goto_next(1); 
     348        } 
     349        if (!p) selected_file[0] = 0; 
     350    } 
     351 
    249352    fselect_on_select = on_select; 
    250353    marked_operation = MARKED_OP_NONE; 
     
    582685 
    583686//------------------------------------------------------------------- 
    584 static void fselect_goto_prev(int step) { 
    585     register int j, i; 
    586  
    587     for (j=0; j<step; ++j) { 
    588         if (selected->prev==top && top->prev)  
    589             top=top->prev; 
    590         if (selected->prev)  
    591             selected=selected->prev; 
    592         else 
    593         if (step == 1) 
    594         { 
    595             for(; selected->next; selected=selected->next); 
    596             for (i=0, top=selected; i<BODY_LINES-1 && top->prev; ++i, top=top->prev); 
    597         } 
    598     } 
    599 } 
    600  
    601 //------------------------------------------------------------------- 
    602 static void fselect_goto_next(int step) { 
    603     register int j, i; 
    604     struct fitem  *ptr; 
    605  
    606     for (j=0; j<step; ++j) { 
    607         for (i=0, ptr=top; i<BODY_LINES-1 && ptr; ++i, ptr=ptr->next); 
    608         if (i==BODY_LINES-1 && ptr && ptr->prev==selected && ptr->next) 
    609             top=top->next; 
    610         if (selected->next)  
    611             selected=selected->next; 
    612         else 
    613         if (step == 1) 
    614             { 
    615             for(; top->prev; top = top->prev); 
    616             selected = top; 
    617         } 
    618     } 
    619 } 
    620  
    621 //------------------------------------------------------------------- 
    622687static void fselect_marked_toggle() { 
    623688    if (selected && selected->attr != 0xFF && !(selected->attr & DOS_ATTR_DIRECTORY)) { 
  • trunk/core/gui_fselect.h

    r1302 r1423  
    33 
    44//------------------------------------------------------------------- 
    5 extern void gui_fselect_init(int title, const char* dir, void (*on_select)(const char *fn)); 
     5extern void gui_fselect_init(int title, const char* prev_dir, const char* default_dir, void (*on_select)(const char *fn)); 
    66extern char* gui_fselect_result(); 
    77extern void gui_fselect_kbd_process(); 
  • trunk/core/luascript.c

    r1360 r1423  
    778778    action_push(AS_FILE_BROWSER); 
    779779    // Switch to file browser gui mode. Path can be supplied in call or defaults to "A" (root directory). 
    780     gui_fselect_init(LANG_STR_FILE_BROWSER, luaL_optstring( L, 1, "A" ), file_browser_selected); 
     780    gui_fselect_init(LANG_STR_FILE_BROWSER, luaL_optstring( L, 1, "A" ), "A", file_browser_selected); 
    781781    // Yield the script so that the action stack will process the AS_FILE_BROWSER action 
    782782    return lua_yield(L, 0); 
Note: See TracChangeset for help on using the changeset viewer.