@@ -267,26 +267,90 @@ open_window (CajaApplication *application,
267267 g_free (uri );
268268}
269269
270+ static void
271+ open_tabs (CajaApplication * application ,
272+ GFile * * locations , guint n_files , GdkScreen * screen , const char * geometry , gboolean browser_window )
273+ {
274+ CajaApplication * self = CAJA_APPLICATION (application );
275+ CajaWindow * window ;
276+ gchar * uri = NULL ;
277+
278+ /*monitor the preference to use browser or spatial windows */
279+ /*connect before trying to read or this preference won't be read by root or after change*/
280+ g_signal_connect_swapped (caja_preferences , "changed::" CAJA_PREFERENCES_ALWAYS_USE_BROWSER ,
281+ G_CALLBACK (caja_empty_callback_to_ensure_read ),
282+ self );
283+
284+ if (browser_window || g_settings_get_boolean (caja_preferences , CAJA_PREFERENCES_ALWAYS_USE_BROWSER )) {
285+ window = caja_application_create_navigation_window (application ,
286+ screen );
287+ } else {
288+ window = caja_application_get_spatial_window (application ,
289+ NULL ,
290+ NULL ,
291+ locations [0 ],
292+ screen ,
293+ NULL );
294+ }
295+
296+ /* open all locations */
297+ uri = g_file_get_uri (locations [0 ]);
298+ g_debug ("Opening new tab at uri %s\n" , uri );
299+ caja_window_go_to (window , locations [0 ]);
300+ for (int i = 1 ; i < n_files ;i ++ ){
301+ /* open tabs in reverse order because each
302+ * tab is opened before the previous one */
303+ guint tab = n_files - i ;
304+ uri = g_file_get_uri (locations [tab ]);
305+ g_debug ("Opening new tab at uri %s\n" , uri );
306+ if (i == 0 ){
307+ caja_window_go_to (window , locations [tab ]);
308+ }else {
309+ caja_window_go_to_tab (window , locations [tab ]);
310+ }
311+ }
312+
313+ if (geometry != NULL && !gtk_widget_get_visible (GTK_WIDGET (window ))) {
314+ /* never maximize windows opened from shell if a
315+ * custom geometry has been requested.
316+ */
317+ gtk_window_unmaximize (GTK_WINDOW (window ));
318+ eel_gtk_window_set_initial_geometry_from_string (GTK_WINDOW (window ),
319+ geometry ,
320+ APPLICATION_WINDOW_MIN_WIDTH ,
321+ APPLICATION_WINDOW_MIN_HEIGHT ,
322+ FALSE);
323+ }
324+
325+ g_free (uri );
326+ }
327+
270328static void
271329open_windows (CajaApplication * application ,
272330 GFile * * files ,
273331 GdkScreen * screen ,
274332 const char * geometry ,
275- guint len ,
276- gboolean browser_window )
333+ guint n_files ,
334+ gboolean browser_window ,
335+ gboolean open_in_tabs )
277336{
278337 guint i ;
279338
280339 if (files == NULL || files [0 ] == NULL ) {
281340 /* Open a window pointing at the default location. */
282- open_window (application , NULL , screen , geometry , browser_window );
341+ open_window (application , NULL , screen , geometry , browser_window );
283342 } else {
284- /* Open windows at each requested location. */
285- i = 0 ;
286- while (i < len ){
287- open_window (application , files [i ], screen , geometry , browser_window );
288- i ++ ;
289- }
343+ if (open_in_tabs ){
344+ /* Open one window with one tab at each requested location */
345+ open_tabs (application , files , n_files , screen , geometry , browser_window );
346+ }else {
347+ /* Open windows at each requested location. */
348+ i = 0 ;
349+ while (i < n_files ){
350+ open_window (application , files [i ], screen , geometry , browser_window );
351+ i ++ ;
352+ }
353+ }
290354 }
291355}
292356
@@ -298,40 +362,41 @@ caja_application_open (GApplication *app,
298362{
299363 CajaApplication * self = CAJA_APPLICATION (app );
300364 gboolean browser_window = FALSE;
365+ gboolean open_in_tabs = FALSE;
301366 const gchar * geometry = NULL ;
302367 const char splitter = '=' ;
303368
304369 g_debug ("Open called on the GApplication instance; %d files" , n_files );
305370
306- /*Check if local command line passed --browser or --geometry */
307- if (strcmp (options ,"" ) != 0 ){
308- if (g_str_match_string ("browser" ,
309- options ,
310- FALSE) == TRUE){
311- browser_window = TRUE;
312- geometry = strchr (options , splitter );
313- }
314- else {
315- geometry = options ;
371+ /*Check if local command line passed --browser, --geometry or --tabs*/
372+ if (strlen (options ) > 0 ){
373+ gchar * * splitedOptions = g_strsplit (options , & splitter , 3 );
374+ sscanf (splitedOptions [0 ], "%d" , & browser_window );
375+ if (strcmp (splitedOptions [1 ], "NULL" )!= 0 ){
376+ geometry = splitedOptions [1 ];
316377 }
378+ sscanf (splitedOptions [2 ], "%d" , & open_in_tabs );
379+
317380 /*Reset this or 3ed and later invocations will use same
318381 *geometry even if the user has resized open window
319382 */
320383 self -> priv -> geometry = NULL ;
321384 }
322385
323- open_windows (self , files ,
386+ open_windows (self , files ,
324387 gdk_screen_get_default (),
325388 geometry ,
326389 n_files ,
327- browser_window );
390+ browser_window ,
391+ open_in_tabs );
328392}
329393
330394void
331395caja_application_open_location (CajaApplication * application ,
332396 GFile * location ,
333397 GFile * selection ,
334- const char * startup_id )
398+ const char * startup_id ,
399+ const gboolean open_in_tabs )
335400{
336401 CajaWindow * window ;
337402 GList * sel_list = NULL ;
@@ -343,7 +408,8 @@ caja_application_open_location (CajaApplication *application,
343408 }
344409
345410 caja_window_slot_open_location_full (caja_window_get_active_slot (window ), location ,
346- 0 , CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW , sel_list , NULL , NULL );
411+ open_in_tabs , CAJA_WINDOW_OPEN_FLAG_NEW_WINDOW ,
412+ sel_list , NULL , NULL );
347413
348414 if (sel_list != NULL ) {
349415 caja_file_list_free (sel_list );
@@ -1997,6 +2063,7 @@ caja_application_local_command_line (GApplication *application,
19972063 gboolean perform_self_check = FALSE;
19982064 gboolean version = FALSE;
19992065 gboolean browser_window = FALSE;
2066+ gboolean open_in_tabs = FALSE;
20002067 gboolean kill_shell = FALSE;
20012068 const gchar * autostart_id ;
20022069 gboolean no_default_window = FALSE;
@@ -2022,6 +2089,8 @@ caja_application_local_command_line (GApplication *application,
20222089 N_ ("Do not manage the desktop (ignore the preference set in the preferences dialog)." ), NULL },
20232090 { "force-desktop" , '\0' , 0 , G_OPTION_ARG_NONE , & self -> priv -> force_desktop ,
20242091 N_ ("Manage the desktop regardless of set preferences or environment (on new startup only)" ), NULL },
2092+ { "tabs" , 't' , 0 , G_OPTION_ARG_NONE , & open_in_tabs ,
2093+ N_ ("Open URI in tabs." ), NULL },
20252094 { "browser" , '\0' , 0 , G_OPTION_ARG_NONE , & browser_window ,
20262095 N_ ("Open a browser window." ), NULL },
20272096 { "quit" , 'q' , 0 , G_OPTION_ARG_NONE , & kill_shell ,
@@ -2051,7 +2120,7 @@ caja_application_local_command_line (GApplication *application,
20512120 if (autostart_id != NULL && * autostart_id != '\0' ) {
20522121 no_default_window = TRUE;
20532122 self -> priv -> autostart = TRUE;
2054- }
2123+ }
20552124
20562125
20572126 argv = * arguments ;
@@ -2109,7 +2178,6 @@ caja_application_local_command_line (GApplication *application,
21092178 caja_application_load_session (self );
21102179 }
21112180
2112-
21132181 GFile * * files ;
21142182 gint idx , len ;
21152183
@@ -2143,30 +2211,19 @@ caja_application_local_command_line (GApplication *application,
21432211 files [1 ] = NULL ;
21442212 }
21452213
2146- /*Set up geometry and --browser options */
2214+ /*Set up -- geometry, --browser and --tabs options */
21472215 /*Invoke "Open" to create new windows */
2148-
2149- if (browser_window == TRUE && self -> priv -> geometry == NULL ){
2150-
2151- if (len > 0 ) {
2152- g_application_open (application , files , len , "browser" );
2153- }
2154- }
2155-
2156- else if (browser_window == FALSE && self -> priv -> geometry != NULL ){
2157- if (len > 0 ) {
2158- g_application_open (application , files , len , self -> priv -> geometry );
2216+ if (len > 0 ) {
2217+ gchar * concatOptions = g_malloc0 (64 );
2218+ if (self -> priv -> geometry == NULL ){
2219+ g_snprintf (concatOptions , 64 , "%d=NULL=%d" , browser_window , open_in_tabs );
2220+ }else {
2221+ g_snprintf (concatOptions , 64 , "%d=%s=%d" , browser_window , self -> priv -> geometry , open_in_tabs );
21592222 }
2160- }
2161-
2162- else if (browser_window == TRUE && self -> priv -> geometry != NULL ){
2163- if (len > 0 ) {
2164- g_application_open (application , files , len , (g_strconcat ("browser" ,"=" ,
2165- self -> priv -> geometry , NULL )));
2166- }
2167- }
2168-
2169- else {
2223+ g_application_open (application , files , len , concatOptions );
2224+ g_free (concatOptions );
2225+ } else {
2226+ g_print ("non\n" );
21702227 if (len > 0 ) {
21712228 g_application_open (application , files , len , "" );
21722229 }
@@ -2420,11 +2477,11 @@ caja_application_quit_mainloop (GApplication *app)
24202477static void
24212478caja_application_class_init (CajaApplicationClass * class )
24222479{
2423- GObjectClass * object_class ;
2480+ GObjectClass * object_class ;
24242481 GApplicationClass * application_class ;
24252482
2426- object_class = G_OBJECT_CLASS (class );
2427- object_class -> finalize = caja_application_finalize ;
2483+ object_class = G_OBJECT_CLASS (class );
2484+ object_class -> finalize = caja_application_finalize ;
24282485
24292486 application_class = G_APPLICATION_CLASS (class );
24302487 application_class -> startup = caja_application_startup ;
0 commit comments