From b33be1a9c5f3d0912d11455655f8ef3b1c8d13ed Mon Sep 17 00:00:00 2001 From: Pratyaksh Gautam <pratyakshgautam11@gmail.com> Date: Thu, 3 Mar 2022 19:53:15 +0000 Subject: [PATCH] Option to show full path in tabs (Issue #627) - Added a checkbox in the settings to toggle the feature on/off - Change property "tooltip-text" to "full-parsed-path" since the property is being used for more than just the tooltip text - Split PROP_MISC_FULL_PATH_IN_TITLE to PROP_MISC_FULL_PATH_IN_TAB_TITLE and PROP_MISC_FULL_PATH_IN_WINDOW_TITLE to distinguish between both --- thunar/thunar-preferences-dialog.c | 13 ++++++++ thunar/thunar-preferences.c | 24 +++++++++++--- thunar/thunar-standard-view.c | 20 +++++------ thunar/thunar-window.c | 53 +++++++++++++++++++++++++++--- 4 files changed, 91 insertions(+), 19 deletions(-) diff --git a/thunar/thunar-preferences-dialog.c b/thunar/thunar-preferences-dialog.c index d8b7079a8..7266ff591 100644 --- a/thunar/thunar-preferences-dialog.c +++ b/thunar/thunar-preferences-dialog.c @@ -905,6 +905,19 @@ thunar_preferences_dialog_init (ThunarPreferencesDialog *dialog) /* next row */ row++; + button = gtk_check_button_new_with_mnemonic (_("Show full directory paths in tab titles")); + g_object_bind_property (G_OBJECT (dialog->preferences), + "misc-full-path-in-tab-title", + G_OBJECT (button), + "active", + G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); + gtk_widget_set_tooltip_text (button, _("Select this option to show the full directory path in the tab title instead of only the directory name")); + gtk_grid_attach (GTK_GRID (grid), button, 0, row, 1, 1); + gtk_widget_show (button); + + /* next row */ + row++; + button = gtk_check_button_new_with_mnemonic (_("Open new thunar instances as tabs")); g_object_bind_property (G_OBJECT (dialog->preferences), "misc-open-new-window-as-tab", diff --git a/thunar/thunar-preferences.c b/thunar/thunar-preferences.c index 364353e07..3d97d22d3 100644 --- a/thunar/thunar-preferences.c +++ b/thunar/thunar-preferences.c @@ -86,7 +86,8 @@ enum PROP_MISC_DATE_CUSTOM_STYLE, PROP_EXEC_SHELL_SCRIPTS_BY_DEFAULT, PROP_MISC_FOLDERS_FIRST, - PROP_MISC_FULL_PATH_IN_TITLE, + PROP_MISC_FULL_PATH_IN_TAB_TITLE, + PROP_MISC_FULL_PATH_IN_WINDOW_TITLE, PROP_MISC_HORIZONTAL_WHEEL_NAVIGATES, PROP_MISC_IMAGE_SIZE_IN_STATUSBAR, PROP_MISC_MIDDLE_CLICK_IN_TAB, @@ -640,14 +641,27 @@ thunar_preferences_class_init (ThunarPreferencesClass *klass) EXO_PARAM_READWRITE); /** - * ThunarPreferences:misc-full-path-in-title: + * ThunarPreferences:misc-full-path-in-tab-title: + * + * Show the full directory path in the tab title, instead of + * only the directory name. + **/ + preferences_props[PROP_MISC_FULL_PATH_IN_TAB_TITLE] = + g_param_spec_boolean ("misc-full-path-in-tab-title", + "MiscFullPathInTabTitle", + NULL, + FALSE, + EXO_PARAM_READWRITE); + + /** + * ThunarPreferences:misc-full-path-in-window-title: * * Show the full directory path in the window title, instead of * only the directory name. **/ - preferences_props[PROP_MISC_FULL_PATH_IN_TITLE] = - g_param_spec_boolean ("misc-full-path-in-title", - "MiscFullPathInTitle", + preferences_props[PROP_MISC_FULL_PATH_IN_WINDOW_TITLE] = + g_param_spec_boolean ("misc-full-path-in-window-title", + "MiscFullPathInWindowTitle", NULL, FALSE, EXO_PARAM_READWRITE); diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index 29c77ee13..5d072257d 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -69,7 +69,7 @@ enum PROP_CURRENT_DIRECTORY, PROP_LOADING, PROP_DISPLAY_NAME, - PROP_TOOLTIP_TEXT, + PROP_FULL_PARSED_PATH, PROP_SELECTED_FILES, PROP_SHOW_HIDDEN, PROP_STATUSBAR_TEXT, @@ -565,14 +565,14 @@ thunar_standard_view_class_init (ThunarStandardViewClass *klass) EXO_PARAM_READABLE); /** - * ThunarStandardView:parse-name: + * ThunarStandardView:full-parsed-path * - * Full parsed name of the current directory, for label tooltip + * Full parsed path of the current directory, for label tooltip **/ - standard_view_props[PROP_TOOLTIP_TEXT] = - g_param_spec_string ("tooltip-text", - "tooltip-text", - "tooltip-text", + standard_view_props[PROP_FULL_PARSED_PATH] = + g_param_spec_string ("full-parsed-path", + "full-parsed-path", + "full-parsed-path", NULL, EXO_PARAM_READABLE); @@ -1056,7 +1056,7 @@ thunar_standard_view_get_property (GObject *object, } break; - case PROP_TOOLTIP_TEXT: + case PROP_FULL_PARSED_PATH: current_directory = thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (object)); if (current_directory != NULL) g_value_take_string (value, g_file_get_parse_name (thunar_file_get_file (current_directory))); @@ -1528,7 +1528,7 @@ thunar_standard_view_set_current_directory (ThunarNavigator *navigator, /* update tab label and tooltip */ g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_DISPLAY_NAME]); - g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_TOOLTIP_TEXT]); + g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_FULL_PARSED_PATH]); /* restore the selection from the history */ thunar_standard_view_restore_selection_from_history (standard_view); @@ -2263,7 +2263,7 @@ thunar_standard_view_current_directory_changed (ThunarFile *current_dire /* update tab label and tooltip */ g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_DISPLAY_NAME]); - g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_TOOLTIP_TEXT]); + g_object_notify_by_pspec (G_OBJECT (standard_view), standard_view_props[PROP_FULL_PARSED_PATH]); /* directory is possibly moved, schedule a thumbnail update */ thunar_standard_view_schedule_thumbnail_timeout (standard_view); diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 8cb578a37..cc827a9e0 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -154,6 +154,7 @@ static gpointer thunar_window_notebook_create_window (GtkWidget gint x, gint y, ThunarWindow *window); +static gboolean thunar_window_notebook_update_title (GtkWidget *label); static GtkWidget*thunar_window_notebook_insert_page (ThunarWindow *window, ThunarFile *directory, GType view_type, @@ -1464,6 +1465,8 @@ thunar_window_finalize (GObject *object) /* release our reference on the provider factory */ g_object_unref (window->provider_factory); + g_signal_handlers_disconnect_matched (window->preferences, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, thunar_window_notebook_update_title, NULL); + /* release the preferences reference */ g_object_unref (window->preferences); @@ -2300,6 +2303,42 @@ thunar_window_notebook_create_window (GtkWidget *notebook, +static gboolean +thunar_window_notebook_update_title (GtkWidget *label) +{ + ThunarWindow *window; + GtkWidget *view; + GBinding *binding; + gboolean show_full_path; + + window = g_object_get_data (G_OBJECT (label), "window"); + view = g_object_get_data (G_OBJECT (label), "view"); + binding = g_object_get_data (G_OBJECT (label), "binding"); + + _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE); + + /* set tab title according to window preferences */ + g_object_get (G_OBJECT (window->preferences), "misc-full-path-in-tab-title", &show_full_path, NULL); + + if (binding != NULL) + g_binding_unbind (binding); + + if (show_full_path) + { + binding = g_object_bind_property (G_OBJECT (view), "full-parsed-path", G_OBJECT (label), "label", G_BINDING_SYNC_CREATE); + gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_START); + } + else + { + binding = g_object_bind_property (G_OBJECT (view), "display-name", G_OBJECT (label), "label", G_BINDING_SYNC_CREATE); + gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); + } + + g_object_set_data (G_OBJECT (label), "binding", binding); + + return TRUE; +} + static GtkWidget* thunar_window_notebook_insert_page (ThunarWindow *window, ThunarFile *directory, @@ -2346,15 +2385,21 @@ thunar_window_notebook_insert_page (ThunarWindow *window, label_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); label = gtk_label_new (NULL); - g_object_bind_property (G_OBJECT (view), "display-name", G_OBJECT (label), "label", G_BINDING_SYNC_CREATE); - g_object_bind_property (G_OBJECT (view), "tooltip-text", G_OBJECT (label), "tooltip-text", G_BINDING_SYNC_CREATE); + + g_object_set_data (G_OBJECT (label), "window", window); + g_object_set_data (G_OBJECT (label), "view", view); + g_object_set_data (G_OBJECT (label), "binding", NULL); + thunar_window_notebook_update_title (label); + + g_signal_connect_swapped (window->preferences, "notify::misc-full-path-in-tab-title", G_CALLBACK (thunar_window_notebook_update_title), label); + + g_object_bind_property (G_OBJECT (view), "full-parsed-path", G_OBJECT (label), "tooltip-text", G_BINDING_SYNC_CREATE); gtk_widget_set_has_tooltip (label, TRUE); gtk_label_set_xalign (GTK_LABEL (label), 0.0f); gtk_widget_set_margin_start (GTK_WIDGET(label), 3); gtk_widget_set_margin_end (GTK_WIDGET(label), 3); gtk_widget_set_margin_top (GTK_WIDGET(label), 3); gtk_widget_set_margin_bottom (GTK_WIDGET(label), 3); - gtk_label_set_ellipsize (GTK_LABEL (label), PANGO_ELLIPSIZE_END); gtk_label_set_single_line_mode (GTK_LABEL (label), TRUE); gtk_box_pack_start (GTK_BOX (label_box), label, TRUE, TRUE, 0); gtk_widget_show (label); @@ -4310,7 +4355,7 @@ thunar_window_current_directory_changed (ThunarFile *current_directory, _thunar_return_if_fail (window->current_directory == current_directory); /* get name of directory or full path */ - g_object_get (G_OBJECT (window->preferences), "misc-full-path-in-title", &show_full_path, NULL); + g_object_get (G_OBJECT (window->preferences), "misc-full-path-in-window-title", &show_full_path, NULL); if (G_UNLIKELY (show_full_path)) name = parse_name = g_file_get_parse_name (thunar_file_get_file (current_directory)); else -- GitLab