From de2b4b79fc78670d4ad9ea092c8bcf0edde41372 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Tue, 14 Aug 2018 23:03:08 +0200 Subject: [PATCH] Add preference to open new thunar instances as tabs, if there is an existing thunar window (Bug #13314) --- thunar/thunar-application.c | 27 +++++++++++++++++++++++++-- thunar/thunar-application.h | 3 ++- thunar/thunar-dbus-service.c | 6 +++--- thunar/thunar-file.c | 2 +- thunar/thunar-launcher.c | 2 +- thunar/thunar-location-button.c | 2 +- thunar/thunar-location-buttons.c | 2 +- thunar/thunar-preferences-dialog.c | 29 ++++++++++++++++------------- thunar/thunar-preferences.c | 14 ++++++++++++++ thunar/thunar-shortcuts-view.c | 2 +- thunar/thunar-tree-view.c | 2 +- thunar/thunar-window.c | 8 +++----- thunar/thunar-window.h | 2 ++ 13 files changed, 71 insertions(+), 30 deletions(-) diff --git a/thunar/thunar-application.c b/thunar/thunar-application.c index d26364c2..c7647565 100644 --- a/thunar/thunar-application.c +++ b/thunar/thunar-application.c @@ -1241,8 +1241,9 @@ thunar_application_take_window (ThunarApplication *application, * to open on the default screen. * @startup_id : startup id from startup notification passed along * with dbus to make focus stealing work properly. + * @forceNewWindow : set this flag to force a new window, even if misc-open-new-window-as-tab is set * - * Opens a new #ThunarWindow for @application, displaying the + * Opens a new #ThunarWindow (or tab if preferred) for @application, displaying the * given @directory. * * Return value: the newly allocated #ThunarWindow. @@ -1251,10 +1252,13 @@ GtkWidget* thunar_application_open_window (ThunarApplication *application, ThunarFile *directory, GdkScreen *screen, - const gchar *startup_id) + const gchar *startup_id, + gboolean forceNewWindow) { + GList* list; GtkWidget *window; gchar *role; + gboolean open_new_window_as_tab; _thunar_return_val_if_fail (THUNAR_IS_APPLICATION (application), NULL); _thunar_return_val_if_fail (directory == NULL || THUNAR_IS_FILE (directory), NULL); @@ -1263,6 +1267,25 @@ thunar_application_open_window (ThunarApplication *application, if (G_UNLIKELY (screen == NULL)) screen = gdk_screen_get_default (); + /* open as tab instead, if preferred */ + g_object_get (G_OBJECT (application->preferences), "misc-open-new-window-as-tab", &open_new_window_as_tab, NULL); + if (G_UNLIKELY (!forceNewWindow && open_new_window_as_tab)) + { + list = thunar_application_get_windows (application); + if (list != NULL) + { + /* this will be the topmost Window */ + list = g_list_last (list); + + if (directory != NULL) + thunar_window_notebook_insert (THUNAR_WINDOW (list->data), directory); + + /* bring the window to front */ + gtk_window_present (list->data); + return list->data; + } + } + /* generate a unique role for the new window (for session management) */ role = g_strdup_printf ("Thunar-%u-%u", (guint) time (NULL), (guint) g_random_int ()); diff --git a/thunar/thunar-application.h b/thunar/thunar-application.h index 6e4d6739..c86eeb15 100644 --- a/thunar/thunar-application.h +++ b/thunar/thunar-application.h @@ -58,7 +58,8 @@ void thunar_application_take_window (ThunarAppli GtkWidget *thunar_application_open_window (ThunarApplication *application, ThunarFile *directory, GdkScreen *screen, - const gchar *startup_id); + const gchar *startup_id, + gboolean forceNewWindow); gboolean thunar_application_bulk_rename (ThunarApplication *application, const gchar *working_directory, diff --git a/thunar/thunar-dbus-service.c b/thunar/thunar-dbus-service.c index 258acb9a..66c104b7 100644 --- a/thunar/thunar-dbus-service.c +++ b/thunar/thunar-dbus-service.c @@ -462,7 +462,7 @@ thunar_dbus_service_display_folder (ThunarDBusFileManager *object, /* popup a new window for the folder */ application = thunar_application_get (); - thunar_application_open_window (application, file, screen, startup_id); + thunar_application_open_window (application, file, screen, startup_id, FALSE); g_object_unref (G_OBJECT (application)); /* cleanup */ @@ -509,7 +509,7 @@ thunar_dbus_service_display_folder_and_select (ThunarDBusFileManager *object, /* popup a new window for the folder */ application = thunar_application_get (); - window = thunar_application_open_window (application, folder, screen, startup_id); + window = thunar_application_open_window (application, folder, screen, startup_id, FALSE); g_object_unref (application); /* determine the path for the filename relative to the folder */ @@ -745,7 +745,7 @@ thunar_dbus_service_display_trash (ThunarDBusTrash *object, { /* tell the application to display the trash bin */ application = thunar_application_get (); - thunar_application_open_window (application, dbus_service->trash_bin, screen, startup_id); + thunar_application_open_window (application, dbus_service->trash_bin, screen, startup_id, FALSE); g_object_unref (G_OBJECT (application)); /* release the screen */ diff --git a/thunar/thunar-file.c b/thunar/thunar-file.c index 6758a760..5194b664 100644 --- a/thunar/thunar-file.c +++ b/thunar/thunar-file.c @@ -1798,7 +1798,7 @@ thunar_file_launch (ThunarFile *file, if (thunar_file_is_directory (file)) { application = thunar_application_get (); - thunar_application_open_window (application, file, screen, startup_id); + thunar_application_open_window (application, file, screen, startup_id, FALSE); g_object_unref (G_OBJECT (application)); return TRUE; } diff --git a/thunar/thunar-launcher.c b/thunar/thunar-launcher.c index 6f9d4302..b34b491b 100644 --- a/thunar/thunar-launcher.c +++ b/thunar/thunar-launcher.c @@ -741,7 +741,7 @@ thunar_launcher_open_windows (ThunarLauncher *launcher, /* open all requested windows */ for (lp = directories; lp != NULL; lp = lp->next) - thunar_application_open_window (application, lp->data, screen, NULL); + thunar_application_open_window (application, lp->data, screen, NULL, TRUE); /* release the application object */ g_object_unref (G_OBJECT (application)); diff --git a/thunar/thunar-location-button.c b/thunar/thunar-location-button.c index be161616..30ea56e4 100644 --- a/thunar/thunar-location-button.c +++ b/thunar/thunar-location-button.c @@ -565,7 +565,7 @@ thunar_location_button_button_release_event (GtkWidget *button, { /* open a new window for the folder */ application = thunar_application_get (); - thunar_application_open_window (application, THUNAR_LOCATION_BUTTON (button)->file, gtk_widget_get_screen (button), NULL); + thunar_application_open_window (application, THUNAR_LOCATION_BUTTON (button)->file, gtk_widget_get_screen (button), NULL, TRUE); g_object_unref (G_OBJECT (application)); } } diff --git a/thunar/thunar-location-buttons.c b/thunar/thunar-location-buttons.c index a13bcbed..872e4568 100644 --- a/thunar/thunar-location-buttons.c +++ b/thunar/thunar-location-buttons.c @@ -1476,7 +1476,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS { /* open a new window for the directory */ application = thunar_application_get (); - thunar_application_open_window (application, directory, gtk_widget_get_screen (GTK_WIDGET (buttons)), NULL); + thunar_application_open_window (application, directory, gtk_widget_get_screen (GTK_WIDGET (buttons)), NULL, TRUE); g_object_unref (G_OBJECT (application)); } } diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index 3d54bfbd..43cccde0 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -623,27 +623,30 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, TRUE, 0); gtk_widget_show (frame); - label = gtk_label_new (_("Middle Click")); + label = gtk_label_new (_("Open Tabs instead of new Windows")); gtk_label_set_attributes (GTK_LABEL (label), thunar_pango_attr_list_bold ()); gtk_frame_set_label_widget (GTK_FRAME (frame), label); gtk_widget_show (label); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6); - gtk_container_add (GTK_CONTAINER (frame), vbox); - gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); - gtk_widget_show (vbox); - - button = gtk_radio_button_new_with_mnemonic_from_widget (NULL, _("Open folder in new _window")); - g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, TRUE, 0); - gtk_widget_show (button); + grid = gtk_grid_new (); + gtk_grid_set_column_spacing (GTK_GRID (grid), 12); + gtk_grid_set_row_spacing (GTK_GRID (grid), 2); + gtk_container_set_border_width (GTK_CONTAINER (grid), 12); + gtk_container_add (GTK_CONTAINER (frame), grid); + gtk_widget_show (grid); - button = gtk_radio_button_new_with_mnemonic_from_widget (GTK_RADIO_BUTTON (button), _("Open folder in new _tab")); + button = gtk_check_button_new_with_mnemonic (_("Open folders in new tabs on middle click")); exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-middle-click-in-tab", G_OBJECT (button), "active"); - g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (g_object_notify), "active"); - gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, TRUE, 0); + gtk_widget_set_tooltip_text (button, _("Select this option to open a new tab on middle click instead of a new window")); + gtk_grid_attach (GTK_GRID (grid), button, 0, 0, 1, 1); gtk_widget_show (button); + button = gtk_check_button_new_with_mnemonic (_("Open new thunar instances as tabs")); + exo_mutual_binding_new (G_OBJECT (dialog->preferences), "misc-open-new-window-as-tab", G_OBJECT (button), "active"); + gtk_widget_set_tooltip_text (button, _("Select this option to open new thunar instances as tabs in an existing thunar window")); + gtk_widget_set_hexpand (button, TRUE); + gtk_grid_attach (GTK_GRID (grid), button, 0, 1, 1, 1); + gtk_widget_show (button); /* Advanced */ diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 217ec7cf..8a5df7c9 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -82,6 +82,7 @@ enum PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES, PROP_MISC_IMAGE_SIZE_IN_STATUSBAR, PROP_MISC_MIDDLE_CLICK_IN_TAB, + PROP_MISC_OPEN_NEW_WINDOW_AS_TAB, PROP_MISC_RECURSIVE_PERMISSIONS, PROP_MISC_REMEMBER_GEOMETRY, PROP_MISC_SHOW_ABOUT_TEMPLATES, @@ -587,6 +588,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** + * ThunarPreferences:misc-open-new-window-as_tab: + * + * %TRUE to open a new tab in an existing thunar instance. instead of a new window + * if a thunar windows already is present + **/ + preferences_props[PROP_MISC_OPEN_NEW_WINDOW_AS_TAB] = + g_param_spec_boolean ("misc-open-new-window-as-tab", + "MiscOpenNewWindowAsTab", + NULL, + FALSE, + EXO_PARAM_READWRITE); + + /** * ThunarPreferences:misc-recursive-permissions: * * Whether to apply permissions recursively every time the diff --git a/thunar/thunar-shortcuts-view.c b/thunar/thunar-shortcuts-view.c index 97d63a03..10bb95e0 100644 --- a/thunar/thunar-shortcuts-view.c +++ b/thunar/thunar-shortcuts-view.c @@ -1661,7 +1661,7 @@ thunar_shortcuts_view_poke_file_finish (ThunarBrowser *browser, /* open a new window for the target folder */ application = thunar_application_get (); thunar_application_open_window (application, target_file, - gtk_widget_get_screen (GTK_WIDGET (browser)), NULL); + gtk_widget_get_screen (GTK_WIDGET (browser)), NULL, TRUE); g_object_unref (application); } else if (open_in == OPEN_IN_TAB) diff --git a/thunar/thunar-tree-view.c b/thunar/thunar-tree-view.c index 4c238ca5..0d2d2cef 100644 --- a/thunar/thunar-tree-view.c +++ b/thunar/thunar-tree-view.c @@ -2355,7 +2355,7 @@ thunar_tree_view_open_selection_in_new_window (ThunarTreeView *view) /* open a new window for the selected folder */ application = thunar_application_get (); thunar_application_open_window (application, file, - gtk_widget_get_screen (GTK_WIDGET (view)), NULL); + gtk_widget_get_screen (GTK_WIDGET (view)), NULL, TRUE); g_object_unref (application); g_object_unref (file); } diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index a5e718dd..016d383a 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -140,8 +140,6 @@ static gpointer thunar_window_notebook_create_window (GtkWidget gint x, gint y, ThunarWindow *window); -static void thunar_window_notebook_insert (ThunarWindow *window, - ThunarFile *directory); static void thunar_window_merge_custom_preferences (ThunarWindow *window); static gboolean thunar_window_bookmark_merge (gpointer user_data); static void thunar_window_merge_go_actions (ThunarWindow *window); @@ -1743,7 +1741,7 @@ thunar_window_notebook_create_window (GtkWidget *notebook, /* create new window */ application = thunar_application_get (); screen = gtk_window_get_screen (GTK_WINDOW (window)); - new_window = thunar_application_open_window (application, NULL, screen, NULL); + new_window = thunar_application_open_window (application, NULL, screen, NULL, TRUE); g_object_unref (application); /* make sure the new window has the same size */ @@ -1771,7 +1769,7 @@ thunar_window_notebook_create_window (GtkWidget *notebook, -static void +void thunar_window_notebook_insert (ThunarWindow *window, ThunarFile *directory) { @@ -2357,7 +2355,7 @@ thunar_window_action_open_new_window (GtkAction *action, /* popup a new window */ application = thunar_application_get (); new_window = THUNAR_WINDOW (thunar_application_open_window (application, window->current_directory, - gtk_widget_get_screen (GTK_WIDGET (window)), NULL)); + gtk_widget_get_screen (GTK_WIDGET (window)), NULL, TRUE)); g_object_unref (G_OBJECT (application)); /* if we have no origin view we are done */ diff --git a/thunar/thunar-window.h b/thunar/thunar-window.h index 8906fcb7..015525d1 100644 --- a/thunar/thunar-window.h +++ b/thunar/thunar-window.h @@ -56,6 +56,8 @@ gboolean thunar_window_set_directories (ThunarWindow *window, void thunar_window_update_directories (ThunarWindow *window, ThunarFile *old_directory, ThunarFile *new_directory); +void thunar_window_notebook_insert (ThunarWindow *window, + ThunarFile *directory); G_END_DECLS; -- 2.11.0