Commit 88af16bd authored by Alexander Schwinn's avatar Alexander Schwinn
Browse files

Add preference to open new thunar instances as tabs, if there is an existing thunar window

(Bug #13314)
parent 130870f0
......@@ -1235,14 +1235,15 @@ thunar_application_take_window (ThunarApplication *application,
/**
* thunar_application_open_window:
* @application : a #ThunarApplication.
* @directory : the directory to open.
* @screen : the #GdkScreen on which to open the window or %NULL
* to open on the default screen.
* @startup_id : startup id from startup notification passed along
* with dbus to make focus stealing work properly.
* @application : a #ThunarApplication.
* @directory : the directory to open.
* @screen : the #GdkScreen on which to open the window or %NULL
* to open on the default screen.
* @startup_id : startup id from startup notification passed along
* with dbus to make focus stealing work properly.
* @force_new_window : 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 force_new_window)
{
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 (!force_new_window && 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 ());
......
......@@ -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 force_new_window);
gboolean thunar_application_bulk_rename (ThunarApplication *application,
const gchar *working_directory,
......
......@@ -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 */
......
......@@ -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;
}
......
......@@ -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));
......
......@@ -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));
}
}
......
......@@ -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));
}
}
......
......@@ -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 (_("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
*/
......
......@@ -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,
......@@ -586,6 +587,19 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass)
FALSE,
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:
*
......
......@@ -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)
......
......@@ -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);
}
......
......@@ -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 */
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment