update Find_file_in_fileselector() to return -1 when not found
This commit is contained in:
		
							parent
							
								
									16799113fc
								
							
						
					
					
						commit
						12050cd068
					
				@ -1314,7 +1314,8 @@ void Button_Skins(int btn)
 | 
				
			|||||||
  Sort_list_of_files(&Font_files_list);
 | 
					  Sort_list_of_files(&Font_files_list);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  selected_font = Find_file_in_fileselector(&Font_files_list, Config.Font_file);
 | 
					  selected_font = Find_file_in_fileselector(&Font_files_list, Config.Font_file);
 | 
				
			||||||
 | 
					  if (selected_font < 0)
 | 
				
			||||||
 | 
					    selected_font = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // --------------------------------------------------------------
 | 
					  // --------------------------------------------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1340,6 +1341,8 @@ void Button_Skins(int btn)
 | 
				
			|||||||
    Draw_one_skin_name, 2); // 4
 | 
					    Draw_one_skin_name, 2); // 4
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  skin_list->Cursor_position = Find_file_in_fileselector(&Skin_files_list, Config.Skin_file);
 | 
					  skin_list->Cursor_position = Find_file_in_fileselector(&Skin_files_list, Config.Skin_file);
 | 
				
			||||||
 | 
					  if (skin_list->Cursor_position < 0)
 | 
				
			||||||
 | 
					    skin_list->Cursor_position = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Buttons to choose a font
 | 
					  // Buttons to choose a font
 | 
				
			||||||
  font_dropdown = Window_set_dropdown_button(172, 43, 104, 11, 0, Get_item_by_index(&Font_files_list,selected_font)->Short_name,1,0,1,RIGHT_SIDE|LEFT_SIDE,0); // 5
 | 
					  font_dropdown = Window_set_dropdown_button(172, 43, 104, 11, 0, Get_item_by_index(&Font_files_list,selected_font)->Short_name,1,0,1,RIGHT_SIDE|LEFT_SIDE,0); // 5
 | 
				
			||||||
 | 
				
			|||||||
@ -2309,6 +2309,8 @@ void Highlight_script(T_Fileselector *selector, T_List_button *list, const char
 | 
				
			|||||||
  short index;
 | 
					  short index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  index=Find_file_in_fileselector(selector, selected_file);
 | 
					  index=Find_file_in_fileselector(selector, selected_file);
 | 
				
			||||||
 | 
					  if (index < 0)
 | 
				
			||||||
 | 
					    index = 0;  // 1st item if selected_file is not found
 | 
				
			||||||
  Locate_list_item(list, index);
 | 
					  Locate_list_item(list, index);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -1386,13 +1386,13 @@ short Find_file_in_fileselector(T_Fileselector *list, const char * fname)
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  T_Fileselector_item * item;
 | 
					  T_Fileselector_item * item;
 | 
				
			||||||
  short  index;
 | 
					  short  index;
 | 
				
			||||||
  short  close_match=0;
 | 
					  short  close_match = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  index=0;
 | 
					  index=0;
 | 
				
			||||||
  for (item=list->First; item!=NULL; item=item->Next)
 | 
					  for (item=list->First; item!=NULL; item=item->Next)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    if (strcmp(item->Full_name,fname)==0)
 | 
					    if (strcmp(item->Full_name,fname)==0)
 | 
				
			||||||
      return index;
 | 
					      return index; // exact match
 | 
				
			||||||
    if (strcasecmp(item->Full_name,fname)==0)
 | 
					    if (strcasecmp(item->Full_name,fname)==0)
 | 
				
			||||||
      close_match=index;
 | 
					      close_match=index;
 | 
				
			||||||
      
 | 
					      
 | 
				
			||||||
@ -1402,7 +1402,10 @@ short Find_file_in_fileselector(T_Fileselector *list, const char * fname)
 | 
				
			|||||||
  return close_match;
 | 
					  return close_match;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Highlight_file(short index)
 | 
					/// Set the position and index of the file list according
 | 
				
			||||||
 | 
					/// to the selected index
 | 
				
			||||||
 | 
					/// @param index index of selected file
 | 
				
			||||||
 | 
					static void Highlight_file(short index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if ((Filelist.Nb_elements<=10) || (index<5))
 | 
					  if ((Filelist.Nb_elements<=10) || (index<5))
 | 
				
			||||||
@ -1685,7 +1688,8 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  if (!load)
 | 
					  if (!load)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    Highlight_file(Find_file_in_fileselector(&Filelist, context->File_name));
 | 
					    short pos = Find_file_in_fileselector(&Filelist, context->File_name);
 | 
				
			||||||
 | 
					    Highlight_file((pos >= 0) ? pos : 0);
 | 
				
			||||||
    Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
					    Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // On initialise le nom de fichier à celui en cours et non pas celui sous
 | 
					    // On initialise le nom de fichier à celui en cours et non pas celui sous
 | 
				
			||||||
@ -1885,15 +1889,15 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
 | 
				
			|||||||
          if (savename != NULL)
 | 
					          if (savename != NULL)
 | 
				
			||||||
          {
 | 
					          {
 | 
				
			||||||
            // attempt to find the file name in new list
 | 
					            // attempt to find the file name in new list
 | 
				
			||||||
            int pos=Find_file_in_fileselector(&Filelist, savename);
 | 
					            short pos=Find_file_in_fileselector(&Filelist, savename);
 | 
				
			||||||
            if (pos!=0)
 | 
					            if (pos >= 0)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              Highlight_file(pos);
 | 
					              Highlight_file(pos);
 | 
				
			||||||
              Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
					              Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            // If the file is (still present) or it's a name with new
 | 
					            // If the file is (still present) or it's a name with new
 | 
				
			||||||
            // extension, set it as the proposed file name.
 | 
					            // extension, set it as the proposed file name.
 | 
				
			||||||
            if (pos!=0 || !load)
 | 
					            if (pos >= 0 || !load)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
              strcpy(Selector_filename, savename);
 | 
					              strcpy(Selector_filename, savename);
 | 
				
			||||||
              memcpy(Selector_filename_unicode, Selector_filename_unicode_save, sizeof(Selector_filename_unicode_save));
 | 
					              memcpy(Selector_filename_unicode, Selector_filename_unicode_save, sizeof(Selector_filename_unicode_save));
 | 
				
			||||||
@ -2265,7 +2269,8 @@ byte Button_Load_or_Save(T_Selector_settings *settings, byte load, T_IO_Context
 | 
				
			|||||||
          Read_list_of_files(&Filelist, Selector->Format_filter);
 | 
					          Read_list_of_files(&Filelist, Selector->Format_filter);
 | 
				
			||||||
          Sort_list_of_files(&Filelist);
 | 
					          Sort_list_of_files(&Filelist);
 | 
				
			||||||
          // Set the fileselector bar on the directory we're coming from
 | 
					          // Set the fileselector bar on the directory we're coming from
 | 
				
			||||||
          Highlight_file(Find_file_in_fileselector(&Filelist, previous_directory));
 | 
					          pos = Find_file_in_fileselector(&Filelist, previous_directory);
 | 
				
			||||||
 | 
					          Highlight_file((pos >= 0) ? pos : 0);
 | 
				
			||||||
          // display the 1st visible files
 | 
					          // display the 1st visible files
 | 
				
			||||||
          Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
					          Prepare_and_display_filelist(Selector->Position,Selector->Offset,file_scroller);
 | 
				
			||||||
          Display_cursor();
 | 
					          Display_cursor();
 | 
				
			||||||
 | 
				
			|||||||
@ -72,6 +72,11 @@ T_Fileselector_item * Get_item_by_index(T_Fileselector *list, unsigned short ind
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void Read_list_of_drives(T_Fileselector *list, byte name_length);
 | 
					void Read_list_of_drives(T_Fileselector *list, byte name_length);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Look for a file name in a file selector list
 | 
				
			||||||
 | 
					/// @param list  The file selector list
 | 
				
			||||||
 | 
					/// @param fname The file name to search for
 | 
				
			||||||
 | 
					/// @return the index of the file
 | 
				
			||||||
 | 
					/// @return -1 if the file name was not found
 | 
				
			||||||
short Find_file_in_fileselector(T_Fileselector *list, const char * fname);
 | 
					short Find_file_in_fileselector(T_Fileselector *list, const char * fname);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void Locate_list_item(T_List_button * list, short selected_item);
 | 
					void Locate_list_item(T_List_button * list, short selected_item);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user