always alpha sort and cleaner hotkeys in file menu

This commit is contained in:
Dagen Brock 2018-08-28 10:51:54 -05:00
parent 6ec560ca49
commit 710e2cd067
2 changed files with 72 additions and 100 deletions

View File

@ -1645,7 +1645,7 @@ void adb_physical_key_update(int a2code, int is_up) {
break; break;
case 0x04: /* F4 - emulator config panel */ case 0x04: /* F4 - emulator config panel */
if (CMD_DOWN) { if (CMD_DOWN) {
glog("Quit!"); glog("Alt-F4 Quit!");
iwm_shut(); iwm_shut();
my_exit(1); my_exit(1);
} }

View File

@ -2576,50 +2576,18 @@ void cfg_file_add_dirent(Cfg_listhdr *listhdrptr, const char *nameptr, int is_di
listhdrptr->last++; listhdrptr->last++;
} }
/* Called by qsort to sort directory listings */
int cfg_dirent_sortfn(const void *obj1, const void *obj2) { int cfg_dirent_sortfn(const void *obj1, const void *obj2) {
const Cfg_dirent *direntptr1, *direntptr2; const Cfg_dirent *direntptr1, *direntptr2;
int ret; int ret;
/* Called by qsort to sort directory listings */ // all systems sort the file list case-insensitively
direntptr1 = (const Cfg_dirent *)obj1; direntptr1 = (const Cfg_dirent *)obj1;
direntptr2 = (const Cfg_dirent *)obj2; direntptr2 = (const Cfg_dirent *)obj2;
#if defined(MAC) || defined(_WIN32) ret = strcasecmp(direntptr1->name, direntptr2->name);
// OG
ret = 0;
// ret = strcasecmp(direntptr1->name, direntptr2->name);
#else
ret = strcmp(direntptr1->name, direntptr2->name);
#endif
return ret; return ret;
} }
int cfg_str_match(const char *str1, const char *str2, int len) {
const byte *bptr1, *bptr2;
int c, c2;
int i;
/* basically, work like strcmp, except if str1 ends first, return 0 */
bptr1 = (const byte *)str1;
bptr2 = (const byte *)str2;
for(i = 0; i < len; i++) {
c = *bptr1++;
c2 = *bptr2++;
if(c == 0) {
if(i > 0) {
return 0;
} else {
return c - c2;
}
}
if(c != c2) {
return c - c2;
}
}
return 0;
}
void cfg_file_readdir(const char *pathptr) { void cfg_file_readdir(const char *pathptr) {
struct dirent *direntptr; struct dirent *direntptr;
@ -2696,7 +2664,7 @@ void cfg_file_readdir(const char *pathptr) {
if(!strcmp("..", direntptr->d_name)) { if(!strcmp("..", direntptr->d_name)) {
continue; continue;
} }
/* Else, see if it is a directory or a file */ // Else, see if it is a directory or a file
snprintf(&g_cfg_tmp_path[0], CFG_PATH_MAX, "%s%s", snprintf(&g_cfg_tmp_path[0], CFG_PATH_MAX, "%s%s",
&g_cfg_file_cachedreal[0], direntptr->d_name); &g_cfg_file_cachedreal[0], direntptr->d_name);
ret = cfg_stat(&g_cfg_tmp_path[0], &stat_buf); ret = cfg_stat(&g_cfg_tmp_path[0], &stat_buf);
@ -2715,7 +2683,7 @@ void cfg_file_readdir(const char *pathptr) {
fmt = stat_buf.st_mode & S_IFMT; fmt = stat_buf.st_mode & S_IFMT;
size = stat_buf.st_size; size = stat_buf.st_size;
if(fmt == S_IFDIR) { if(fmt == S_IFDIR) {
/* it's a directory */ // it's a directory
is_dir = 1; is_dir = 1;
} else if((fmt == S_IFREG) && (is_gz == 0)) { } else if((fmt == S_IFREG) && (is_gz == 0)) {
if(g_cfg_slotdrive < 0xfff) { if(g_cfg_slotdrive < 0xfff) {
@ -2723,7 +2691,7 @@ void cfg_file_readdir(const char *pathptr) {
continue; /* skip it */ continue; /* skip it */
} }
} else { } else {
/* see if there are size limits */ // see if there are size limits
if((size < g_cfg_file_min_size) || if((size < g_cfg_file_min_size) ||
(size > g_cfg_file_max_size)) { (size > g_cfg_file_max_size)) {
continue; /* skip it */ continue; /* skip it */
@ -2736,15 +2704,13 @@ void cfg_file_readdir(const char *pathptr) {
cfg_file_add_dirent(&g_cfg_dirlist, direntptr->d_name, is_dir, cfg_file_add_dirent(&g_cfg_dirlist, direntptr->d_name, is_dir,
stat_buf.st_size, -1, -1); stat_buf.st_size, -1, -1);
} }
/* then sort the results (Mac's HFS+ is sorted, but other FS won't be)*/ // always sort the results, all systems
qsort(&(g_cfg_dirlist.direntptr[0]), g_cfg_dirlist.last, qsort(&(g_cfg_dirlist.direntptr[0]), g_cfg_dirlist.last, sizeof(Cfg_dirent), cfg_dirent_sortfn);
sizeof(Cfg_dirent), cfg_dirent_sortfn);
g_cfg_dirlist.curent = g_cfg_dirlist.last - 1; g_cfg_dirlist.curent = g_cfg_dirlist.last - 1;
for(i = g_cfg_dirlist.last - 1; i >= 0; i--) { for(i = g_cfg_dirlist.last - 1; i >= 0; i--) {
ret = cfg_str_match(&g_cfg_file_match[0], ret = strcasecmp(&g_cfg_file_match[0], g_cfg_dirlist.direntptr[i].name);
g_cfg_dirlist.direntptr[i].name, CFG_PATH_MAX);
if(ret <= 0) { if(ret <= 0) {
/* set cur ent to closest filename to the match name */ // set curent to closest filename to the match name
g_cfg_dirlist.curent = i; g_cfg_dirlist.curent = i;
} }
} }
@ -2974,6 +2940,7 @@ void cfg_file_draw() {
} }
cfg_putchar('\t'); cfg_putchar('\t');
} }
void cfg_partition_selected() { void cfg_partition_selected() {
char *str; char *str;
const char *part_str; const char *part_str;
@ -3092,18 +3059,19 @@ void cfg_file_handle_key(int key) {
if(g_cfg_select_partition > 0) { if(g_cfg_select_partition > 0) {
listhdrptr = &g_cfg_partitionlist; listhdrptr = &g_cfg_partitionlist;
} }
// can't hotkey numbers because it falsely matches PGUP/PGDN
if( (g_cfg_file_pathfield == 0) && if( (g_cfg_file_pathfield == 0) &&
((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) ) { ((key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z')) ) {
/* jump to file starting with this letter */ /* jump to file starting with this letter */
g_cfg_file_match[0] = key; g_cfg_file_match[0] = key;
g_cfg_file_match[1] = 0; g_cfg_file_match[1] = 0;
g_cfg_dirlist.invalid = 1; /* re-read directory */ g_cfg_dirlist.invalid = 1; /* re-read directory */
} } else {
switch(key) { switch(key) {
case 0x1b: case 0x1b:
if(g_cfg_slotdrive < 0xfff) { if(g_cfg_slotdrive < 0xfff) {
eject_disk_by_num(g_cfg_slotdrive >> 8, eject_disk_by_num(g_cfg_slotdrive >> 8, g_cfg_slotdrive & 0xff);
g_cfg_slotdrive & 0xff);
} }
g_cfg_slotdrive = -1; g_cfg_slotdrive = -1;
g_cfg_select_partition = -1; g_cfg_select_partition = -1;
@ -3139,6 +3107,9 @@ void cfg_file_handle_key(int key) {
case 0x09: /* tab */ case 0x09: /* tab */
g_cfg_file_pathfield = !g_cfg_file_pathfield; g_cfg_file_pathfield = !g_cfg_file_pathfield;
break; break;
case 0x15:
glogf("You can't go right!"); /* eggs - DB */
break;
case 0x08: /* left arrow */ case 0x08: /* left arrow */
case 0x7f: /* delete key */ case 0x7f: /* delete key */
if(g_cfg_file_pathfield) { if(g_cfg_file_pathfield) {
@ -3152,7 +3123,8 @@ void cfg_file_handle_key(int key) {
cfg_file_selected(g_cfg_file_dir_only); cfg_file_selected(g_cfg_file_dir_only);
break; break;
default: default:
glogf("Unhandled config key: 0x%02x", key); glogf("Unhandled file config key: 0x%02x", key);
}
} }
} }