comparison gui/ui/gtk/fileselect.c @ 33787:42feff0f8a7b

Start all file dialogs always in last active directory. This starts the "add subtitle" and "add external audio" dialogs in the directory of the chosen or started movie. Don't change the directory just to retrieve its name and prepend the active directory instead of appending it. This closes Bugzilla #977.
author ib
date Mon, 11 Jul 2011 14:54:25 +0000
parents 4fae8b19fbbd
children b2e63fe7fe17
comparison
equal deleted inserted replaced
33786:0d3d8db05a59 33787:42feff0f8a7b
51 #endif 51 #endif
52 52
53 gchar * fsSelectedFile = NULL; 53 gchar * fsSelectedFile = NULL;
54 gchar * fsSelectedFileUtf8 = NULL; 54 gchar * fsSelectedFileUtf8 = NULL;
55 gchar * fsSelectedDirectory = NULL; 55 gchar * fsSelectedDirectory = NULL;
56 gchar * fsSelectedDirectoryUtf8 = NULL;
56 unsigned char * fsThatDir = "."; 57 unsigned char * fsThatDir = ".";
57 const gchar * fsFilter = "*"; 58 const gchar * fsFilter = "*";
58 59
59 int fsType = 0; 60 int fsType = 0;
60 61
246 gtk_widget_show( list ); 247 gtk_widget_show( list );
247 } 248 }
248 249
249 void ShowFileSelect( int type,int modal ) 250 void ShowFileSelect( int type,int modal )
250 { 251 {
251 int i, k; 252 int i, k, fsMedium;
252 char * tmp = NULL; 253 char * tmp = NULL, * dir = NULL;
253 254
254 if ( fsFileSelect ) gtkActive( fsFileSelect ); 255 if ( fsFileSelect ) gtkActive( fsFileSelect );
255 else fsFileSelect=create_FileSelect(); 256 else fsFileSelect=create_FileSelect();
256 257
257 fsType=type; 258 fsType=type;
311 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsFontFileNames[k >= 0 ? k : i-2][0] ); 312 gtk_entry_set_text( GTK_ENTRY( fsFilterCombo ),fsFontFileNames[k >= 0 ? k : i-2][0] );
312 tmp=font_name; 313 tmp=font_name;
313 break; 314 break;
314 } 315 }
315 316
317 fsMedium=(fsType == fsVideoSelector || fsType == fsSubtitleSelector || fsType == fsAudioSelector);
318
319 if ( !tmp && fsMedium ) tmp=guiInfo.Filename;
320
316 if ( tmp && tmp[0] ) 321 if ( tmp && tmp[0] )
317 { 322 {
318 struct stat f; 323 struct stat f;
319 char * dir = strdup( tmp ); 324 dir = strdup( tmp );
320 325
321 do 326 do
322 { 327 {
323 char * c = strrchr( dir,'/' ); 328 char * c = strrchr( dir,'/' );
324 stat( dir,&f ); 329 stat( dir,&f );
325 if ( S_ISDIR( f.st_mode ) ) break; 330 if ( S_ISDIR( f.st_mode ) ) break;
326 if ( c ) *c=0; 331 if ( c ) *c=0;
327 } while ( strrchr( dir,'/' ) ); 332 } while ( strrchr( dir,'/' ) );
328 333
329 if ( dir[0] ) chdir( dir ); 334 if ( !dir[0] ) nfree( dir );
330
331 free( dir );
332 } 335 }
333 336
334 if ( fsTopList_items ) g_list_free( fsTopList_items ); fsTopList_items=NULL; 337 if ( fsTopList_items ) g_list_free( fsTopList_items ); fsTopList_items=NULL;
335 { 338 {
336 unsigned int i, c = 1; 339 unsigned int i, c = 1;
337 340
338 if ( fsType == fsVideoSelector ) 341
342 if ( fsMedium )
339 { 343 {
340 for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ ) 344 for ( i=0;i < FF_ARRAY_ELEMS(fsHistory);i++ )
341 if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,fsHistory[i] ); c=0; } 345 if ( fsHistory[i] ) { fsTopList_items=g_list_append( fsTopList_items,fsHistory[i] ); if ( c ) c=gstrcmp( dir,fsHistory[i] ); }
342 } 346 }
343 if ( c ) fsTopList_items=g_list_append( fsTopList_items,(gchar *)get_current_dir_name_utf8() ); 347 if ( c && dir )
348 {
349 g_free( fsSelectedDirectoryUtf8 );
350 fsSelectedDirectoryUtf8=g_filename_to_utf8( dir, -1, NULL, NULL, NULL );
351 fsTopList_items=g_list_prepend( fsTopList_items,fsSelectedDirectoryUtf8 );
352 }
344 } 353 }
354 free( dir );
345 if ( getenv( "HOME" ) ) fsTopList_items=g_list_append( fsTopList_items,getenv( "HOME" ) ); 355 if ( getenv( "HOME" ) ) fsTopList_items=g_list_append( fsTopList_items,getenv( "HOME" ) );
346 fsTopList_items=g_list_append( fsTopList_items,"/home" ); 356 fsTopList_items=g_list_append( fsTopList_items,"/home" );
347 fsTopList_items=g_list_append( fsTopList_items,"/mnt" ); 357 fsTopList_items=g_list_append( fsTopList_items,"/mnt" );
348 fsTopList_items=g_list_append( fsTopList_items,"/" ); 358 fsTopList_items=g_list_append( fsTopList_items,"/" );
349 gtk_combo_set_popdown_strings( GTK_COMBO( fsCombo4 ),fsTopList_items ); 359 gtk_combo_set_popdown_strings( GTK_COMBO( fsCombo4 ),fsTopList_items );
580 590
581 static void fs_Destroy( void ) 591 static void fs_Destroy( void )
582 { 592 {
583 g_free( fsSelectedFileUtf8 ); 593 g_free( fsSelectedFileUtf8 );
584 fsSelectedFileUtf8 = NULL; 594 fsSelectedFileUtf8 = NULL;
595 g_free( fsSelectedDirectoryUtf8 );
596 fsSelectedDirectoryUtf8 = NULL;
585 WidgetDestroy( fsFileSelect, &fsFileSelect ); 597 WidgetDestroy( fsFileSelect, &fsFileSelect );
586 } 598 }
587 599
588 GtkWidget * create_FileSelect( void ) 600 GtkWidget * create_FileSelect( void )
589 { 601 {