From b38e246fbc642f5c18fc85edeef190a9fbbe9866 Mon Sep 17 00:00:00 2001 From: Alexander Schwinn <alexxcons@xfce.org> Date: Sun, 17 May 2020 01:29:03 +0200 Subject: [PATCH] Re-introduce view-specific menu items (Issue #293) - Propagate "append-item" methods down into concrete view widgets --- thunar/thunar-abstract-icon-view.c | 222 ++++++++++++++++++++++++----- thunar/thunar-abstract-icon-view.h | 12 ++ thunar/thunar-details-view.c | 93 +++++++++--- thunar/thunar-details-view.h | 6 + thunar/thunar-standard-view.c | 26 +++- thunar/thunar-standard-view.h | 3 + thunar/thunar-window.c | 13 ++ 7 files changed, 323 insertions(+), 52 deletions(-) diff --git a/thunar/thunar-abstract-icon-view.c b/thunar/thunar-abstract-icon-view.c index 5da9c5ca1..47d02a1e6 100644 --- a/thunar/thunar-abstract-icon-view.c +++ b/thunar/thunar-abstract-icon-view.c @@ -63,9 +63,13 @@ static gboolean thunar_abstract_icon_view_get_visible_range (ThunarStand static void thunar_abstract_icon_view_highlight_path (ThunarStandardView *standard_view, GtkTreePath *path); static GtkAction *thunar_abstract_icon_view_gesture_action (ThunarAbstractIconView *abstract_icon_view); -static void thunar_abstract_icon_view_action_sort (GtkAction *action, - GtkAction *current, - ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_connect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group); +static void thunar_abstract_icon_view_disconnect_accelerators(ThunarStandardView *standard_view, + GtkAccelGroup *accel_group); +static void thunar_abstract_icon_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group); static void thunar_abstract_icon_view_notify_model (ExoIconView *view, GParamSpec *pspec, ThunarAbstractIconView *abstract_icon_view); @@ -90,14 +94,21 @@ static void thunar_abstract_icon_view_item_activated (ExoIconView static void thunar_abstract_icon_view_sort_column_changed (GtkTreeSortable *sortable, ThunarAbstractIconView *abstract_icon_view); static void thunar_abstract_icon_view_zoom_level_changed (ThunarAbstractIconView *abstract_icon_view); - - +static void thunar_abstract_icon_view_action_sort_by_name (ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_action_sort_by_size (ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_action_sort_by_type (ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_action_sort_by_date (ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_action_sort_ascending (ThunarStandardView *standard_view); +static void thunar_abstract_icon_view_action_sort_descending(ThunarStandardView *standard_view); struct _ThunarAbstractIconViewPrivate { /* the UI manager merge id for the abstract icon view */ gint ui_merge_id; + GtkSortType sort_order; + gint sort_column; + /* mouse gesture support */ gint gesture_start_x; gint gesture_start_y; @@ -133,6 +144,21 @@ static const GtkRadioActionEntry order_action_entries[] = +static XfceGtkActionEntry thunar_abstract_icon_view_action_entries[] = +{ + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_ARRANGE_ITEMS_MENU, "<Actions>/ThunarStandardView/arrange-items-menu", "", XFCE_GTK_MENU_ITEM, N_ ("Arran_ge Items"), NULL, NULL, G_CALLBACK (NULL), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_NAME, "<Actions>/ThunarStandardView/sort-by-name", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("Sort By _Name"), N_ ("Keep items sorted by their name"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_by_name), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_SIZE, "<Actions>/ThunarStandardView/sort-by-size", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("Sort By _Size"), N_ ("Keep items sorted by their size"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_by_size), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_TYPE, "<Actions>/ThunarStandardView/sort-by-type", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("Sort By _Type"), N_ ("Keep items sorted by their type"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_by_type), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_MTIME, "<Actions>/ThunarStandardView/sort-by-mtime", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("Sort By Modification _Date"), N_ ("Keep items sorted by their modification date"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_by_date), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_ASCENDING, "<Actions>/ThunarStandardView/sort-ascending", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("_Ascending"), N_ ("Sort items in ascending order"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_ascending), }, + { THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_DESCENDING, "<Actions>/ThunarStandardView/sort-descending", "", XFCE_GTK_RADIO_MENU_ITEM, N_ ("_Descending"), N_ ("Sort items in descending order"), NULL, G_CALLBACK (thunar_abstract_icon_view_action_sort_descending), }, +}; + +#define get_action_entry(id) xfce_gtk_get_action_entry_by_id(thunar_abstract_icon_view_action_entries,G_N_ELEMENTS(thunar_abstract_icon_view_action_entries),id) + + + G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (ThunarAbstractIconView, thunar_abstract_icon_view, THUNAR_TYPE_STANDARD_VIEW) @@ -159,6 +185,11 @@ thunar_abstract_icon_view_class_init (ThunarAbstractIconViewClass *klass) thunarstandard_view_class->get_path_at_pos = thunar_abstract_icon_view_get_path_at_pos; thunarstandard_view_class->get_visible_range = thunar_abstract_icon_view_get_visible_range; thunarstandard_view_class->highlight_path = thunar_abstract_icon_view_highlight_path; + thunarstandard_view_class->append_menu_items = thunar_abstract_icon_view_append_menu_items; + thunarstandard_view_class->connect_accelerators = thunar_abstract_icon_view_connect_accelerators; + thunarstandard_view_class->disconnect_accelerators = thunar_abstract_icon_view_disconnect_accelerators; + + xfce_gtk_translate_action_entries (thunar_abstract_icon_view_action_entries, G_N_ELEMENTS (thunar_abstract_icon_view_action_entries)); /** * ThunarAbstractIconView:column-spacing: @@ -234,10 +265,10 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS GTK_WIDGET (abstract_icon_view)); gtk_action_group_add_radio_actions (THUNAR_STANDARD_VIEW (abstract_icon_view)->action_group, column_action_entries, G_N_ELEMENTS (column_action_entries), THUNAR_COLUMN_NAME, - G_CALLBACK (thunar_abstract_icon_view_action_sort), abstract_icon_view); + G_CALLBACK (NULL), abstract_icon_view); gtk_action_group_add_radio_actions (THUNAR_STANDARD_VIEW (abstract_icon_view)->action_group, order_action_entries, G_N_ELEMENTS (order_action_entries), GTK_SORT_ASCENDING, - G_CALLBACK (thunar_abstract_icon_view_action_sort), abstract_icon_view); + G_CALLBACK (NULL), abstract_icon_view); G_GNUC_END_IGNORE_DEPRECATIONS /* we need to listen to sort column changes to sync the menu items */ @@ -417,6 +448,93 @@ thunar_abstract_icon_view_highlight_path (ThunarStandardView *standard_view, +/** + * thunar_abstract_icon_view_connect_accelerators: + * @standard_view : a #ThunarStandardView + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Connects all accelerators and corresponding default keys of this widget to the global accelerator list + * The concrete implementation depends on the concrete widget which is implementing this view + **/ +static void +thunar_abstract_icon_view_connect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + xfce_gtk_accel_map_add_entries (thunar_abstract_icon_view_action_entries, + G_N_ELEMENTS (thunar_abstract_icon_view_action_entries)); + xfce_gtk_accel_group_connect_action_entries (accel_group, + thunar_abstract_icon_view_action_entries, + G_N_ELEMENTS (thunar_abstract_icon_view_action_entries), + standard_view); +} + + + +/** + * thunar_abstract_icon_view_disconnect_accelerators: + * @standard_view : a #ThunarStandardView + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Disconnects all accelerators from the passed #GtkAccelGroup + **/ +static void +thunar_abstract_icon_view_disconnect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group) +{ + /* Dont listen to the accel keys defined by the action entries any more */ + xfce_gtk_accel_group_disconnect_action_entries (accel_group, + thunar_abstract_icon_view_action_entries, + G_N_ELEMENTS (thunar_abstract_icon_view_action_entries)); +} + + + +/** + * thunar_abstract_icon_view_append_menu_items: + * @standard_view : a #ThunarStandardView + * @menu : the #GtkMenu to add the menu items + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Appends widget-specific menu items to a #GtkMenu and connects them to the passed #GtkAccelGroup + * Implements method 'append_menu_items' of #ThunarStandardView + **/ +static void +thunar_abstract_icon_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + GtkWidget *submenu; + GtkWidget *item; + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + item = xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_ARRANGE_ITEMS_MENU), NULL, GTK_MENU_SHELL (menu)); + submenu = gtk_menu_new(); + if (accel_group != NULL) + gtk_menu_set_accel_group (GTK_MENU (submenu), accel_group); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_NAME), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_column == THUNAR_COLUMN_NAME, GTK_MENU_SHELL (submenu)); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_SIZE), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_column == THUNAR_COLUMN_SIZE, GTK_MENU_SHELL (submenu)); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_TYPE), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_column == THUNAR_COLUMN_TYPE, GTK_MENU_SHELL (submenu)); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_MTIME), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_column == THUNAR_COLUMN_DATE_MODIFIED, GTK_MENU_SHELL (submenu)); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_ASCENDING), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_order == GTK_SORT_ASCENDING, GTK_MENU_SHELL (submenu)); + xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_DESCENDING), G_OBJECT (standard_view), + abstract_icon_view->priv->sort_order == GTK_SORT_DESCENDING, GTK_MENU_SHELL (submenu)); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (item), GTK_WIDGET (submenu)); + gtk_widget_show (item); +} + + + static GtkAction* thunar_abstract_icon_view_gesture_action (ThunarAbstractIconView *abstract_icon_view) { @@ -449,25 +567,73 @@ G_GNUC_END_IGNORE_DEPRECATIONS static void -thunar_abstract_icon_view_action_sort (GtkAction *action, - GtkAction *current, - ThunarStandardView *standard_view) +thunar_abstract_icon_view_action_sort_by_name (ThunarStandardView *standard_view) { - GtkSortType order; - gint column; + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* query the new sort column id */ - action = gtk_action_group_get_action (standard_view->action_group, "sort-by-name"); - column = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); - /* query the new sort order */ - action = gtk_action_group_get_action (standard_view->action_group, "sort-ascending"); - order = gtk_radio_action_get_current_value (GTK_RADIO_ACTION (action)); -G_GNUC_END_IGNORE_DEPRECATIONS + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), THUNAR_COLUMN_NAME, abstract_icon_view->priv->sort_order); +} - /* apply the new settings */ - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), column, order); + + +static void +thunar_abstract_icon_view_action_sort_by_size (ThunarStandardView *standard_view) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), THUNAR_COLUMN_SIZE, abstract_icon_view->priv->sort_order); +} + + + +static void +thunar_abstract_icon_view_action_sort_by_type (ThunarStandardView *standard_view) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), THUNAR_COLUMN_TYPE, abstract_icon_view->priv->sort_order); +} + + + +static void +thunar_abstract_icon_view_action_sort_by_date (ThunarStandardView *standard_view) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), THUNAR_COLUMN_DATE_MODIFIED, abstract_icon_view->priv->sort_order); +} + + + +static void +thunar_abstract_icon_view_action_sort_ascending (ThunarStandardView *standard_view) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), abstract_icon_view->priv->sort_column, GTK_SORT_ASCENDING); +} + + + +static void +thunar_abstract_icon_view_action_sort_descending (ThunarStandardView *standard_view) +{ + ThunarAbstractIconView *abstract_icon_view = THUNAR_ABSTRACT_ICON_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_ABSTRACT_ICON_VIEW (abstract_icon_view)); + + gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (standard_view->model), abstract_icon_view->priv->sort_column, GTK_SORT_DESCENDING); } @@ -776,20 +942,12 @@ thunar_abstract_icon_view_sort_column_changed (GtkTreeSortable *sortable, ThunarAbstractIconView *abstract_icon_view) { GtkSortType order; - GtkAction *action; gint column; if (gtk_tree_sortable_get_sort_column_id (sortable, &column, &order)) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* apply the new sort column */ - action = gtk_action_group_get_action (THUNAR_STANDARD_VIEW (abstract_icon_view)->action_group, "sort-by-name"); - gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), column); - - /* apply the new sort order */ - action = gtk_action_group_get_action (THUNAR_STANDARD_VIEW (abstract_icon_view)->action_group, "sort-ascending"); - gtk_radio_action_set_current_value (GTK_RADIO_ACTION (action), order); -G_GNUC_END_IGNORE_DEPRECATIONS + abstract_icon_view->priv->sort_column = column; + abstract_icon_view->priv->sort_order = order; } } diff --git a/thunar/thunar-abstract-icon-view.h b/thunar/thunar-abstract-icon-view.h index 84a3d045d..15d5a3758 100644 --- a/thunar/thunar-abstract-icon-view.h +++ b/thunar/thunar-abstract-icon-view.h @@ -35,6 +35,18 @@ typedef struct _ThunarAbstractIconView ThunarAbstractIconView; #define THUNAR_IS_ABSTRACT_ICON_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), THUNAR_TYPE_ABSTRACT_ICON_VIEW)) #define THUNAR_ABSTRACT_ICON_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_ABSTRACT_ICON_VIEW, ThunarAbstractIconViewClass)) +/* #XfceGtkActionEntrys provided by this widget */ +typedef enum +{ + THUNAR_ABSTRACT_ICON_VIEW_ACTION_ARRANGE_ITEMS_MENU, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_NAME, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_SIZE, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_TYPE, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_BY_MTIME, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_ASCENDING, + THUNAR_ABSTRACT_ICON_VIEW_ACTION_SORT_DESCENDING, +} ThunarAbstractIconViewAction; + struct _ThunarAbstractIconViewClass { ThunarStandardViewClass __parent__; diff --git a/thunar/thunar-details-view.c b/thunar/thunar-details-view.c index bc2fc3727..66a4fba1d 100644 --- a/thunar/thunar-details-view.c +++ b/thunar/thunar-details-view.c @@ -105,11 +105,16 @@ static void thunar_details_view_row_changed (GtkTreeView static void thunar_details_view_columns_changed (ThunarColumnModel *column_model, ThunarDetailsView *details_view); static void thunar_details_view_zoom_level_changed (ThunarDetailsView *details_view); -static void thunar_details_view_action_setup_columns (GtkAction *action, - ThunarDetailsView *details_view); static gboolean thunar_details_view_get_fixed_columns (ThunarDetailsView *details_view); static void thunar_details_view_set_fixed_columns (ThunarDetailsView *details_view, gboolean fixed_columns); +static void thunar_details_view_connect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group); +static void thunar_details_view_disconnect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group); +static void thunar_details_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group); @@ -140,11 +145,13 @@ struct _ThunarDetailsView -static const GtkActionEntry action_entries[] = +static XfceGtkActionEntry thunar_details_view_action_entries[] = { - { "setup-columns", NULL, N_ ("Configure _Columns..."), NULL, N_ ("Configure the columns in the detailed list view"), G_CALLBACK (thunar_details_view_action_setup_columns), }, + { THUNAR_DETAILS_VIEW_ACTION_CONFIGURE_COLUMNS, "<Actions>/ThunarStandardView/configure-columns", "", XFCE_GTK_MENU_ITEM , N_ ("Configure _Columns..."), N_("Configure the columns in the detailed list view"), NULL, G_CALLBACK (thunar_show_column_editor), }, }; +#define get_action_entry(id) xfce_gtk_get_action_entry_by_id(thunar_details_view_action_entries,G_N_ELEMENTS(thunar_details_view_action_entries),id) + G_DEFINE_TYPE (ThunarDetailsView, thunar_details_view, THUNAR_TYPE_STANDARD_VIEW) @@ -179,8 +186,13 @@ thunar_details_view_class_init (ThunarDetailsViewClass *klass) thunarstandard_view_class->get_path_at_pos = thunar_details_view_get_path_at_pos; thunarstandard_view_class->get_visible_range = thunar_details_view_get_visible_range; thunarstandard_view_class->highlight_path = thunar_details_view_highlight_path; + thunarstandard_view_class->append_menu_items = thunar_details_view_append_menu_items; + thunarstandard_view_class->connect_accelerators = thunar_details_view_connect_accelerators; + thunarstandard_view_class->disconnect_accelerators = thunar_details_view_disconnect_accelerators; thunarstandard_view_class->zoom_level_property_name = "last-details-view-zoom-level"; + xfce_gtk_translate_action_entries (thunar_details_view_action_entries, G_N_ELEMENTS (thunar_details_view_action_entries)); + /** * ThunarDetailsView:fixed-columns: * @@ -212,13 +224,6 @@ thunar_details_view_init (ThunarDetailsView *details_view) */ g_signal_connect (G_OBJECT (details_view), "notify::zoom-level", G_CALLBACK (thunar_details_view_zoom_level_changed), NULL); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* setup the details view actions */ - gtk_action_group_add_actions (THUNAR_STANDARD_VIEW (details_view)->action_group, - action_entries, G_N_ELEMENTS (action_entries), - GTK_WIDGET (details_view)); -G_GNUC_END_IGNORE_DEPRECATIONS - /* create the tree view to embed */ tree_view = exo_tree_view_new (); g_signal_connect (G_OBJECT (tree_view), "notify::model", @@ -980,17 +985,69 @@ thunar_details_view_zoom_level_changed (ThunarDetailsView *details_view) +/** + * thunar_details_view_connect_accelerators: + * @standard_view : a #ThunarStandardView. + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Connects all accelerators and corresponding default keys of this widget to the global accelerator list + * The concrete implementation depends on the concrete widget which is implementing this view + **/ static void -thunar_details_view_action_setup_columns (GtkAction *action, - ThunarDetailsView *details_view) +thunar_details_view_connect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group) { + ThunarDetailsView *details_view = THUNAR_DETAILS_VIEW (standard_view); + + _thunar_return_if_fail (THUNAR_IS_DETAILS_VIEW (details_view)); + + xfce_gtk_accel_map_add_entries (thunar_details_view_action_entries, G_N_ELEMENTS (thunar_details_view_action_entries)); + xfce_gtk_accel_group_connect_action_entries (accel_group, + thunar_details_view_action_entries, + G_N_ELEMENTS (thunar_details_view_action_entries), + standard_view); +} + + + +/** + * thunar_details_view_disconnect_accelerators: + * @standard_view : a #ThunarStandardView. + * @accel_group : a #GtkAccelGroup to be disconnected + * + * Dont listen to the accel keys defined by the action entries any more + **/ +static void +thunar_details_view_disconnect_accelerators (ThunarStandardView *standard_view, + GtkAccelGroup *accel_group) +{ + /* Dont listen to the accel keys defined by the action entries any more */ + xfce_gtk_accel_group_disconnect_action_entries (accel_group, + thunar_details_view_action_entries, + G_N_ELEMENTS (thunar_details_view_action_entries)); +} + + + +/** + * thunar_details_view_append_menu_items: + * @standard_view : a #ThunarStandardView. + * @menu : the #GtkMenu to add the menu items. + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Appends widget-specific menu items to a #GtkMenu and connects them to the passed #GtkAccelGroup + * Implements method 'append_menu_items' of #ThunarStandardView + **/ +static void +thunar_details_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group) +{ + ThunarDetailsView *details_view = THUNAR_DETAILS_VIEW (standard_view); + _thunar_return_if_fail (THUNAR_IS_DETAILS_VIEW (details_view)); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_if_fail (GTK_IS_ACTION (action)); -G_GNUC_END_IGNORE_DEPRECATIONS - /* popup the column editor dialog */ - thunar_show_column_editor (details_view); + xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_DETAILS_VIEW_ACTION_CONFIGURE_COLUMNS), G_OBJECT (details_view), GTK_MENU_SHELL (menu)); } diff --git a/thunar/thunar-details-view.h b/thunar/thunar-details-view.h index bd83df535..240440db3 100644 --- a/thunar/thunar-details-view.h +++ b/thunar/thunar-details-view.h @@ -34,6 +34,12 @@ typedef struct _ThunarDetailsView ThunarDetailsView; #define THUNAR_IS_DETAILS_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_DETAILS_VIEW)) #define THUNAR_DETAILS_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_DETAILS_VIEW, ThunarDetailsViewClass)) +/* #XfceGtkActionEntrys provided by this widget */ +typedef enum +{ + THUNAR_DETAILS_VIEW_ACTION_CONFIGURE_COLUMNS, +} ThunarDetailsViewAction; + GType thunar_details_view_get_type (void) G_GNUC_CONST; G_END_DECLS; diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index e603a2ee9..c002fcbaf 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -855,7 +855,7 @@ thunar_standard_view_finalize (GObject *object) G_N_ELEMENTS (thunar_standard_view_action_entries)); /* as well disconnect accelerators of derived widgets */ - //(*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->disconnect_accelerators) (standard_view, standard_view->accel_group); + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->disconnect_accelerators) (standard_view, standard_view->accel_group); /* and release the accel group */ if (G_LIKELY (standard_view->accel_group != NULL)) @@ -3662,6 +3662,7 @@ thunar_standard_view_context_menu (ThunarStandardView *standard_view) | THUNAR_MENU_SECTION_COPY_PASTE | THUNAR_MENU_SECTION_EMPTY_TRASH | THUNAR_MENU_SECTION_CUSTOM_ACTIONS); + thunar_standard_view_append_menu_items (standard_view, GTK_MENU (context_menu), NULL); xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (context_menu)); thunar_menu_add_sections (context_menu, THUNAR_MENU_SECTION_ZOOM | THUNAR_MENU_SECTION_PROPERTIES); @@ -3828,6 +3829,27 @@ thunar_standard_view_copy_history (ThunarStandardView *standard_view) +/** + * thunar_standard_view_append_menu_items: + * @standard_view : a #ThunarStandardView. + * @menu : the #GtkMenu to add the menu items. + * @accel_group : a #GtkAccelGroup to be used used for new menu items + * + * Appends widget-specific menu items to a #GtkMenu and connects them to the passed #GtkAccelGroup + * The concrete implementation depends on the concrete widget which is implementing this view + **/ +void +thunar_standard_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group) +{ + _thunar_return_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view)); + + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->append_menu_items) (standard_view, menu, accel_group); +} + + + /** * thunar_standard_view_append_menu_item: * @standard_view : Instance of a #ThunarStandardView @@ -3869,5 +3891,5 @@ thunar_standard_view_connect_accelerators (ThunarStandardView *standard_view) standard_view); /* as well append accelerators of derived widgets */ - //(*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->connect_accelerators) (standard_view, standard_view->accel_group); + (*THUNAR_STANDARD_VIEW_GET_CLASS (standard_view)->connect_accelerators) (standard_view, standard_view->accel_group); } diff --git a/thunar/thunar-standard-view.h b/thunar/thunar-standard-view.h index 11ea4b03c..a05f52671 100644 --- a/thunar/thunar-standard-view.h +++ b/thunar/thunar-standard-view.h @@ -169,6 +169,9 @@ void thunar_standard_view_selection_changed (ThunarStandardView void thunar_standard_view_set_history (ThunarStandardView *standard_view, ThunarHistory *history); ThunarHistory *thunar_standard_view_copy_history (ThunarStandardView *standard_view); +void thunar_standard_view_append_menu_items (ThunarStandardView *standard_view, + GtkMenu *menu, + GtkAccelGroup *accel_group); void thunar_standard_view_append_menu_item (ThunarStandardView *standard_view, GtkMenu *menu, ThunarStandardViewAction action); diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index a47fd4745..60781f492 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -1158,6 +1158,16 @@ thunar_window_create_edit_menu (ThunarWindow *window, thunar_menu_add_sections (submenu, THUNAR_MENU_SECTION_CUT | THUNAR_MENU_SECTION_COPY_PASTE | THUNAR_MENU_SECTION_TRASH_DELETE); + if (window->view != NULL) + { + thunar_standard_view_append_menu_item (THUNAR_STANDARD_VIEW (window->view), + GTK_MENU (submenu), THUNAR_STANDARD_VIEW_ACTION_SELECT_ALL_FILES); + thunar_standard_view_append_menu_item (THUNAR_STANDARD_VIEW (window->view), + GTK_MENU (submenu), THUNAR_STANDARD_VIEW_ACTION_SELECT_BY_PATTERN); + thunar_standard_view_append_menu_item (THUNAR_STANDARD_VIEW (window->view), + GTK_MENU (submenu), THUNAR_STANDARD_VIEW_ACTION_INVERT_SELECTION); + } + xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu)); thunar_menu_add_sections (submenu, THUNAR_MENU_SECTION_DUPLICATE | THUNAR_MENU_SECTION_MAKELINK | THUNAR_MENU_SECTION_RENAME @@ -1218,6 +1228,9 @@ thunar_window_create_view_menu (ThunarWindow *window, xfce_gtk_toggle_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_SHOW_HIDDEN), G_OBJECT (window), window->show_hidden, GTK_MENU_SHELL (submenu)); xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu)); + if (window->view != NULL) + thunar_standard_view_append_menu_items (THUNAR_STANDARD_VIEW (window->view), GTK_MENU (submenu), window->accel_group); + xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu)); thunar_window_append_menu_item (window, GTK_MENU_SHELL (submenu), THUNAR_WINDOW_ACTION_ZOOM_IN); thunar_window_append_menu_item (window, GTK_MENU_SHELL (submenu), THUNAR_WINDOW_ACTION_ZOOM_OUT); thunar_window_append_menu_item (window, GTK_MENU_SHELL (submenu), THUNAR_WINDOW_ACTION_ZOOM_RESET); -- GitLab