Fixed side effect of issue 498 in fileselector. Also fixed possible crash when you change format filter while highlighted filename has less than 3 characters, and made the display 'follow' selected file/dir when you change filter if it's still in list.
git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1995 416bcca6-2ee7-4201-b75f-2eb2f807beb1
This commit is contained in:
parent
95b537e5f0
commit
48bb895147
@ -208,6 +208,17 @@ void Free_fileselector_list(T_Fileselector *list)
|
|||||||
Recount_files(list);
|
Recount_files(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Position_last_dot(const char * fname)
|
||||||
|
{
|
||||||
|
int pos_last_dot = -1;
|
||||||
|
int c = 0;
|
||||||
|
|
||||||
|
for (c = 0; fname[c]!='\0'; c++)
|
||||||
|
if (fname[c]=='.')
|
||||||
|
pos_last_dot = c;
|
||||||
|
return pos_last_dot;
|
||||||
|
}
|
||||||
|
|
||||||
char * Format_filename(const char * fname, word max_length, int type)
|
char * Format_filename(const char * fname, word max_length, int type)
|
||||||
{
|
{
|
||||||
static char result[40];
|
static char result[40];
|
||||||
@ -251,10 +262,7 @@ char * Format_filename(const char * fname, word max_length, int type)
|
|||||||
result[max_length-5]='.';
|
result[max_length-5]='.';
|
||||||
|
|
||||||
// Look for the last dot in filename
|
// Look for the last dot in filename
|
||||||
pos_last_dot = -1;
|
pos_last_dot = Position_last_dot(fname);
|
||||||
for (c = 0; fname[c]!='\0'; c++)
|
|
||||||
if (fname[c]=='.')
|
|
||||||
pos_last_dot = c;
|
|
||||||
|
|
||||||
// Copy the part before the dot
|
// Copy the part before the dot
|
||||||
for (c=0; c!=pos_last_dot && fname[c]!='\0'; c++)
|
for (c=0; c!=pos_last_dot && fname[c]!='\0'; c++)
|
||||||
@ -311,15 +319,14 @@ void Add_element_to_list(T_Fileselector *list, const char * full_name, const cha
|
|||||||
/// This function allows wildcard '?', and '*' if it's the only character.
|
/// This function allows wildcard '?', and '*' if it's the only character.
|
||||||
int Check_extension(const char *filename, const char * filter)
|
int Check_extension(const char *filename, const char * filter)
|
||||||
{
|
{
|
||||||
int pos_last_dot = -1;
|
int pos_last_dot;
|
||||||
int c = 0;
|
int c = 0;
|
||||||
|
|
||||||
if (filter[0] == '*')
|
if (filter[0] == '*')
|
||||||
return 1;
|
return 1;
|
||||||
// On recherche la position du dernier . dans le nom
|
// On recherche la position du dernier . dans le nom
|
||||||
for (c = 0; filename[c]!='\0'; c++)
|
pos_last_dot = Position_last_dot(filename);
|
||||||
if (filename[c]=='.')
|
|
||||||
pos_last_dot = c;
|
|
||||||
// Fichier sans extension (ca arrive)
|
// Fichier sans extension (ca arrive)
|
||||||
if (pos_last_dot == -1)
|
if (pos_last_dot == -1)
|
||||||
return (filter[0] == '\0' || filter[0] == ';');
|
return (filter[0] == '\0' || filter[0] == ';');
|
||||||
@ -1642,28 +1649,54 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
|
|||||||
Reset_quicksearch();
|
Reset_quicksearch();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6 : // Scroller des formats
|
case 6 : // File Format dropdown
|
||||||
// On met à jour le format de browsing du fileselect:
|
// Refresh fileselector according to new filter
|
||||||
if (Main_format != Window_attribute2) {
|
if (Main_format != Window_attribute2)
|
||||||
char* savename = (char *)strdup(Selector_filename);
|
{
|
||||||
int nameLength = strlen(savename);
|
int pos_last_dot;
|
||||||
|
char* savename = NULL;
|
||||||
|
|
||||||
Main_format = Window_attribute2;
|
Main_format = Window_attribute2;
|
||||||
// Comme on change de liste, on se place en début de liste:
|
if (Filelist.Nb_elements>0)
|
||||||
|
{
|
||||||
|
T_Fileselector_item * current_item;
|
||||||
|
current_item = Get_item_by_index(&Filelist, Main_fileselector_position + Main_fileselector_offset);
|
||||||
|
// In "save" box, if current name is a (possible) filename
|
||||||
|
// with extension, set it to new format's extension
|
||||||
|
if (!load &&
|
||||||
|
current_item->Type == 0 &&
|
||||||
|
Get_fileformat(Main_format)->Default_extension[0] != '\0' &&
|
||||||
|
(pos_last_dot=Position_last_dot(Selector_filename))!=-1 &&
|
||||||
|
Selector_filename[pos_last_dot+1]!='\0')
|
||||||
|
{
|
||||||
|
strcpy(Selector_filename + pos_last_dot + 1,
|
||||||
|
Get_fileformat(Main_format)->Default_extension);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
savename = (char *)strdup(Selector_filename);
|
||||||
|
// By default, position list at the beginning
|
||||||
Main_fileselector_position = 0;
|
Main_fileselector_position = 0;
|
||||||
Main_fileselector_offset = 0;
|
Main_fileselector_offset = 0;
|
||||||
// Affichage des premiers fichiers visibles:
|
// Print the first visible files
|
||||||
Hide_cursor();
|
Hide_cursor();
|
||||||
Reload_list_of_files(Main_format, file_scroller);
|
Reload_list_of_files(Main_format, file_scroller);
|
||||||
New_preview_is_needed = 1;
|
New_preview_is_needed = 1;
|
||||||
Reset_quicksearch();
|
Reset_quicksearch();
|
||||||
strcpy(Selector_filename, savename);
|
if (savename != NULL)
|
||||||
if (Get_fileformat(Main_format)->Default_extension[0] != '\0' &&
|
|
||||||
Selector_filename[nameLength - 4] == '.')
|
|
||||||
{
|
{
|
||||||
strcpy(Selector_filename + nameLength - 3,
|
// attempt to find the file name in new list
|
||||||
Get_fileformat(Main_format)->Default_extension);
|
int pos=Find_file_in_fileselector(&Filelist, savename);
|
||||||
|
if (pos!=0)
|
||||||
|
{
|
||||||
|
Highlight_file(pos);
|
||||||
|
Prepare_and_display_filelist(Main_fileselector_position,Main_fileselector_offset,file_scroller);
|
||||||
}
|
}
|
||||||
|
// If the file is (still present) or it's a name with new
|
||||||
|
// extension, set it as the proposed file name.
|
||||||
|
if (pos!=0 || !load)
|
||||||
|
strcpy(Selector_filename, savename);
|
||||||
free(savename);
|
free(savename);
|
||||||
|
}
|
||||||
Print_filename_in_fileselector();
|
Print_filename_in_fileselector();
|
||||||
Display_cursor();
|
Display_cursor();
|
||||||
}
|
}
|
||||||
@ -1685,8 +1718,8 @@ byte Button_Load_or_Save(byte load, T_IO_Context *context)
|
|||||||
{
|
{
|
||||||
T_Fileselector_item * current_item;
|
T_Fileselector_item * current_item;
|
||||||
current_item = Get_item_by_index(&Filelist, Main_fileselector_position + Main_fileselector_offset);
|
current_item = Get_item_by_index(&Filelist, Main_fileselector_position + Main_fileselector_offset);
|
||||||
if (current_item->Type != 0)
|
if (current_item->Type != 0 && !FILENAME_COMPARE(current_item->Full_name,Selector_filename))
|
||||||
// selected entry is note a filename
|
// current name is a highlighted directory
|
||||||
Selector_filename[0]='\0';
|
Selector_filename[0]='\0';
|
||||||
}
|
}
|
||||||
if (Readline(82,48,Selector_filename,27,INPUT_TYPE_FILENAME))
|
if (Readline(82,48,Selector_filename,27,INPUT_TYPE_FILENAME))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user