From 4542272e8fb47ab9aff6b22fcb4540faff9c275a Mon Sep 17 00:00:00 2001 From: Alexander Schwinn Date: Sat, 16 May 2020 23:46:58 +0200 Subject: use XfceGtkActionEntry for toolbar - re-introduce history (Bug #16654) support - remove now obsolete thunar-history-action --- thunar/Makefile.am | 2 - thunar/thunar-gtk-extensions.c | 68 +------- thunar/thunar-gtk-extensions.h | 9 - thunar/thunar-history-action.c | 364 ----------------------------------------- thunar/thunar-history-action.h | 46 ------ thunar/thunar-history.c | 304 ++++++++++------------------------ thunar/thunar-history.h | 32 +++- thunar/thunar-standard-view.c | 82 +++++----- thunar/thunar-standard-view.h | 1 + thunar/thunar-window.c | 238 +++++++++++++++++++-------- 10 files changed, 319 insertions(+), 827 deletions(-) delete mode 100644 thunar/thunar-history-action.c delete mode 100644 thunar/thunar-history-action.h (limited to 'thunar') diff --git a/thunar/Makefile.am b/thunar/Makefile.am index 1c0b5a2e..e61a2c9e 100644 --- a/thunar/Makefile.am +++ b/thunar/Makefile.am @@ -108,8 +108,6 @@ thunar_SOURCES = \ thunar-gobject-extensions.h \ thunar-gtk-extensions.c \ thunar-gtk-extensions.h \ - thunar-history-action.c \ - thunar-history-action.h \ thunar-history.c \ thunar-history.h \ thunar-ice.c \ diff --git a/thunar/thunar-gtk-extensions.c b/thunar/thunar-gtk-extensions.c index f2a0c226..541c1e67 100644 --- a/thunar/thunar-gtk-extensions.c +++ b/thunar/thunar-gtk-extensions.c @@ -32,6 +32,7 @@ #include +#include /** * thunar_gtk_action_set_tooltip: @@ -68,36 +69,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS -/** - * thunar_gtk_action_group_set_action_sensitive: - * @action_group : a #GtkActionGroup. - * @action_name : the name of a #GtkAction in @action_group. - * @sensitive : the new sensitivity. - * - * Convenience function to change the sensitivity of an action - * in @action_group (whose name is @action_name) to @sensitive. - **/ -void -thunar_gtk_action_group_set_action_sensitive (GtkActionGroup *action_group, - const gchar *action_name, - gboolean sensitive) -{ -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - GtkAction *action; - - _thunar_return_if_fail (GTK_IS_ACTION_GROUP (action_group)); - _thunar_return_if_fail (action_name != NULL && *action_name != '\0'); - - /* query the action from the group */ - action = gtk_action_group_get_action (action_group, action_name); - - /* apply the sensitivity to the action */ - gtk_action_set_sensitive (action, sensitive); -G_GNUC_END_IGNORE_DEPRECATIONS -} - - - /** * thunar_gtk_label_set_a11y_relation: * @label : a #GtkLabel. @@ -220,43 +191,6 @@ thunar_gtk_menu_run_at_event (GtkMenu *menu, -/** - * thunar_gtk_ui_manager_get_action_by_name: - * @ui_manager : a #GtkUIManager. - * @action_name : the name of a #GtkAction in @ui_manager. - * - * Looks up the #GtkAction with the given @action_name in all - * #GtkActionGroups associated with @ui_manager. Returns - * %NULL if no such #GtkAction exists in @ui_manager. - * - * Return value: the #GtkAction of the given @action_name in - * @ui_manager or %NULL. - **/ -GtkAction* -thunar_gtk_ui_manager_get_action_by_name (GtkUIManager *ui_manager, - const gchar *action_name) -{ - GtkAction *action; - GList *lp; - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_val_if_fail (GTK_IS_UI_MANAGER (ui_manager), NULL); - _thunar_return_val_if_fail (action_name != NULL, NULL); - - /* check all action groups associated with the ui manager */ - for (lp = gtk_ui_manager_get_action_groups (ui_manager); lp != NULL; lp = lp->next) - { - action = gtk_action_group_get_action (lp->data, action_name); - if (G_LIKELY (action != NULL)) - return action; - } -G_GNUC_END_IGNORE_DEPRECATIONS - - return NULL; -} - - - /** * thunar_gtk_widget_set_tooltip: * @widget : a #GtkWidget for which to set the tooltip. diff --git a/thunar/thunar-gtk-extensions.h b/thunar/thunar-gtk-extensions.h index 98e0c30f..b92e5361 100644 --- a/thunar/thunar-gtk-extensions.h +++ b/thunar/thunar-gtk-extensions.h @@ -28,21 +28,12 @@ void thunar_gtk_action_set_tooltip (GtkAction const gchar *format, ...) G_GNUC_PRINTF (2, 3); -void thunar_gtk_action_group_set_action_sensitive (GtkActionGroup *action_group, - const gchar *action_name, - gboolean sensitive); - void thunar_gtk_label_set_a11y_relation (GtkLabel *label, GtkWidget *widget); - void thunar_gtk_menu_run (GtkMenu *menu); void thunar_gtk_menu_run_at_event (GtkMenu *menu, GdkEvent *event); - -GtkAction *thunar_gtk_ui_manager_get_action_by_name (GtkUIManager *ui_manager, - const gchar *action_name); - void thunar_gtk_widget_set_tooltip (GtkWidget *widget, const gchar *format, ...) G_GNUC_PRINTF (2, 3); diff --git a/thunar/thunar-history-action.c b/thunar/thunar-history-action.c deleted file mode 100644 index 5f2baab5..00000000 --- a/thunar/thunar-history-action.c +++ /dev/null @@ -1,364 +0,0 @@ -/* vi:set et ai sw=2 sts=2 ts=2: */ -/*- - * Copyright (c) 2006 Benedikt Meurer - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include - - - -static GtkWidget *thunar_history_action_create_tool_item (GtkAction *action); -static void thunar_history_action_show_menu (GtkWidget *tool_item, - ThunarHistoryAction *history_action); - - - -struct _ThunarHistoryActionClass -{ - GtkActionClass __parent__; -}; - -struct _ThunarHistoryAction -{ - GtkAction __parent__; - - guint popup_delay; -}; - - - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS -G_DEFINE_TYPE (ThunarHistoryAction, thunar_history_action, GTK_TYPE_ACTION) -G_GNUC_END_IGNORE_DEPRECATIONS - - - -static void -thunar_history_action_class_init (ThunarHistoryActionClass *klass) -{ - GtkActionClass *gtkaction_class; - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtkaction_class = GTK_ACTION_CLASS (klass); -G_GNUC_END_IGNORE_DEPRECATIONS - gtkaction_class->create_tool_item = thunar_history_action_create_tool_item; - - /** - * ThunarHistoryAction::show-menu: - * @history_action : a #ThunarHistoryAction. - * @menu : the #GtkMenu to which to add the items to display. - * - * Emitted by the @history_action right before the @menu is shown. - **/ - g_signal_new (I_("show-menu"), - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, GTK_TYPE_MENU); -} - - - -static void -thunar_history_action_init (ThunarHistoryAction *actions_changed) -{ -} - - - -static gboolean -thunar_history_action_popup_delayed (gpointer data) -{ - GtkWidget *button = GTK_WIDGET (data); - ThunarHistoryAction *history_action; - - history_action = g_object_get_data (G_OBJECT (button), I_("thunar-history-action")); - thunar_history_action_show_menu (button, history_action); - history_action->popup_delay = 0; - - return FALSE; -} - - - -static gboolean -thunar_history_action_button_press_event (GtkWidget *toggle_button, - GdkEventButton *event, - GtkWidget *tool_item) -{ - ThunarHistoryAction *history_action; - - _thunar_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE); - _thunar_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE); - - history_action = g_object_get_data (G_OBJECT (toggle_button), I_("thunar-history-action")); - - if (event->button == 1) - { - /* shouldn't happen, but stop pending timeout */ - if (history_action->popup_delay != 0) - g_source_remove (history_action->popup_delay); - - /* schedule a popup for button press */ - history_action->popup_delay = g_timeout_add (500, thunar_history_action_popup_delayed, toggle_button); - } - else if (event->button == 3) - { - /* directy show the menu */ - thunar_history_action_show_menu (toggle_button, history_action); - } - - return FALSE; -} - - - -static gboolean -thunar_history_action_button_release_event (GtkWidget *toggle_button, - GdkEventButton *event, - GtkWidget *tool_item) -{ - ThunarHistoryAction *history_action; - - _thunar_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE); - _thunar_return_val_if_fail (GTK_IS_TOOL_ITEM (tool_item), FALSE); - - if (event->button == 1) - { - history_action = g_object_get_data (G_OBJECT (toggle_button), I_("thunar-history-action")); - if (history_action->popup_delay != 0) - { - /* stop timeout */ - g_source_remove (history_action->popup_delay); - history_action->popup_delay = 0; - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* activate event */ - gtk_action_activate (GTK_ACTION (history_action)); -G_GNUC_END_IGNORE_DEPRECATIONS - } - } - else - { - return TRUE; - } - - /* bit of a strange trick to get the button untoggeled */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_button), - gtk_widget_is_sensitive (toggle_button)); - - return FALSE; -} - - - -static gboolean -thunar_history_action_leave_notify_event (GtkWidget *toggle_button, - GdkEventCrossing *event, - ThunarHistoryAction *history_action) -{ - - GtkAllocation alloc; - - _thunar_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button), FALSE); - _thunar_return_val_if_fail (THUNAR_IS_HISTORY_ACTION (history_action), FALSE); - - if (history_action->popup_delay != 0) - { - /* stop the timeout */ - g_source_remove (history_action->popup_delay); - history_action->popup_delay = 0; - - /* if the user dragged to the bottom, directly popup the menu */ - gtk_widget_get_allocation (toggle_button, &alloc); - if (event->x >= 0 - && event->x < alloc.width - && event->y >= alloc.height) - { - thunar_history_action_show_menu (toggle_button, history_action); - } - } - - return FALSE; -} - - - -static void -thunar_history_action_activate (GtkWidget *toggle_button, - ThunarHistoryAction *history_action) -{ - _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button)); - _thunar_return_if_fail (THUNAR_IS_HISTORY_ACTION (history_action)); - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* activate event (only key events trigger this function) */ - gtk_action_activate (GTK_ACTION (history_action)); -G_GNUC_END_IGNORE_DEPRECATIONS - - /* activate, so the code deactivates a bit later... */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_button), TRUE); -} - - - -static void -thunar_history_action_toolbar_configured (GtkWidget *tool_item, - GtkWidget *toggle_button) -{ - GtkWidget *icon; - GtkAction *action; - - gtk_button_set_relief (GTK_BUTTON (toggle_button), - gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (tool_item))); - - icon = gtk_bin_get_child (GTK_BIN (toggle_button)); - action = g_object_get_data (G_OBJECT (toggle_button), I_("thunar-history-action")); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_image_set_from_icon_name (GTK_IMAGE (icon), - gtk_action_get_icon_name (action), - gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (tool_item))); -G_GNUC_END_IGNORE_DEPRECATIONS -} - - - -static GtkWidget* -thunar_history_action_create_tool_item (GtkAction *action) -{ - GtkWidget *tool_item; - GtkWidget *button; - GtkWidget *icon; - - _thunar_return_val_if_fail (THUNAR_IS_HISTORY_ACTION (action), NULL); - - /* allocate the tool item with an empty menu */ - tool_item = g_object_new (GTK_TYPE_TOOL_ITEM, NULL); - gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (tool_item), TRUE); - - button = gtk_toggle_button_new (); - gtk_container_add (GTK_CONTAINER (tool_item), button); - gtk_button_set_relief (GTK_BUTTON (button), - gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (tool_item))); - gtk_widget_set_focus_on_click (button, FALSE); - gtk_widget_show (button); - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - icon = gtk_image_new_from_icon_name (gtk_action_get_icon_name (action), - gtk_tool_item_get_icon_size (GTK_TOOL_ITEM (tool_item))); -G_GNUC_END_IGNORE_DEPRECATIONS - gtk_container_add (GTK_CONTAINER (button), icon); - gtk_widget_show (icon); - - g_object_set_data (G_OBJECT (button), I_("thunar-history-action"), action); - - g_signal_connect (G_OBJECT (tool_item), "toolbar-reconfigured", - G_CALLBACK (thunar_history_action_toolbar_configured), button); - g_signal_connect (G_OBJECT (button), "button-press-event", - G_CALLBACK (thunar_history_action_button_press_event), tool_item); - g_signal_connect (G_OBJECT (button), "button-release-event", - G_CALLBACK (thunar_history_action_button_release_event), tool_item); - g_signal_connect (G_OBJECT (button), "leave-notify-event", - G_CALLBACK (thunar_history_action_leave_notify_event), action); - g_signal_connect (G_OBJECT (button), "activate", - G_CALLBACK (thunar_history_action_activate), action); - - return tool_item; -} - - - -static void -thunar_history_action_menu_deactivate (GtkWidget *toggle_button) -{ - /* untoggle the button */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_button), FALSE); -} - - - -static void -thunar_history_action_show_menu (GtkWidget *toggle_button, - ThunarHistoryAction *history_action) -{ - GtkWidget *menu; - - _thunar_return_if_fail (GTK_IS_TOGGLE_BUTTON (toggle_button)); - _thunar_return_if_fail (THUNAR_IS_HISTORY_ACTION (history_action)); - - /* allocate a new menu for the action */ - menu = gtk_menu_new (); - gtk_menu_attach_to_widget (GTK_MENU (menu), toggle_button, NULL); - g_signal_connect_swapped (G_OBJECT (menu), "deactivate", - G_CALLBACK (thunar_history_action_menu_deactivate), toggle_button); - - /* generate the menu items */ - g_signal_emit_by_name (G_OBJECT (history_action), "show-menu", menu); - - /* toggle the button */ - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle_button), TRUE); - - /* run the menu (takes over the floating of menu) */ - thunar_gtk_menu_run (GTK_MENU (menu)); -} - - - -/** - * thunar_history_action_new: - * @name : the name for the action. - * @label : the label for the action. - * @tooltip : the tooltip for the action. - * @iconname : the icon name for the action. - * - * Allocates a new #ThunarHistoryAction with the specified - * parameters. - * - * Return value: the newly allocated #ThunarHistoryAction. - **/ -GtkAction* -thunar_history_action_new (const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *iconname) -{ - gchar *fulltip; - GtkAction *action; - - _thunar_return_val_if_fail (name != NULL, NULL); - - /* extend history tooltip with function of the button */ - fulltip = g_strconcat (tooltip, "\n", _("Right-click or pull down to show history"), NULL); - - action = g_object_new (THUNAR_TYPE_HISTORY_ACTION, - "name", name, - "label", label, - "tooltip", fulltip, - "icon-name", iconname, - NULL); - - g_free (fulltip); - - return action; -} - diff --git a/thunar/thunar-history-action.h b/thunar/thunar-history-action.h deleted file mode 100644 index dc069e03..00000000 --- a/thunar/thunar-history-action.h +++ /dev/null @@ -1,46 +0,0 @@ -/* vi:set et ai sw=2 sts=2 ts=2: */ -/*- - * Copyright (c) 2006 Benedikt Meurer - * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the Free - * Software Foundation; either version 2 of the License, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - * more details. - * - * You should have received a copy of the GNU General Public License along with - * this program; if not, write to the Free Software Foundation, Inc., 59 Temple - * Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef __THUNAR_HISTORY_ACTION_H__ -#define __THUNAR_HISTORY_ACTION_H__ - -#include - -G_BEGIN_DECLS; - -typedef struct _ThunarHistoryActionClass ThunarHistoryActionClass; -typedef struct _ThunarHistoryAction ThunarHistoryAction; - -#define THUNAR_TYPE_HISTORY_ACTION (thunar_history_action_get_type ()) -#define THUNAR_HISTORY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), THUNAR_TYPE_HISTORY_ACTION, ThunarHistoryAction)) -#define THUNAR_HISTORY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), THUNAR_TYPE_HISTORY_ACTION, ThunarHistoryActionClass)) -#define THUNAR_IS_HISTORY_ACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), THUNAR_TYPE_HISTORY_ACTION)) -#define THUNAR_IS_HISTORY_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_HISTORY_ACTION)) -#define THUNAR_HISTORY_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_HISTORY_ACTION, ThunarHistoryActionClass)) - -GType thunar_history_action_get_type (void) G_GNUC_CONST; - -GtkAction *thunar_history_action_new (const gchar *name, - const gchar *label, - const gchar *tooltip, - const gchar *icon_name) G_GNUC_MALLOC; - -G_END_DECLS; - -#endif /* !__THUNAR_HISTORY_ACTION_H__ */ diff --git a/thunar/thunar-history.c b/thunar/thunar-history.c index 8e21047a..2c068190 100644 --- a/thunar/thunar-history.c +++ b/thunar/thunar-history.c @@ -22,23 +22,31 @@ #endif #include -#include +#include #include #include #include #include #include +#include + /* Property identifiers */ enum { PROP_0, - PROP_ACTION_GROUP, PROP_CURRENT_DIRECTORY, }; +/* Signal identifiers */ +enum +{ + HISTORY_CHANGED, + LAST_SIGNAL, +}; + static void thunar_history_navigator_init (ThunarNavigatorIface *iface); @@ -59,26 +67,12 @@ static void thunar_history_go_back (ThunarHistory GFile *goto_file); static void thunar_history_go_forward (ThunarHistory *history, GFile *goto_file); -static void thunar_history_action_back (GtkAction *action, - ThunarHistory *history); static void thunar_history_action_back_nth (GtkWidget *item, ThunarHistory *history); -static void thunar_history_action_forward (GtkAction *action, - ThunarHistory *history); static void thunar_history_action_forward_nth (GtkWidget *item, ThunarHistory *history); -static void thunar_history_show_menu (GtkAction *action, - GtkWidget *menu, - ThunarHistory *history); -static GtkActionGroup *thunar_history_get_action_group (const ThunarHistory *history); -static void thunar_history_set_action_group (ThunarHistory *history, - GtkActionGroup *action_group); -struct _ThunarHistoryClass -{ - GObjectClass __parent__; -}; struct _ThunarHistory { @@ -86,16 +80,11 @@ struct _ThunarHistory ThunarFile *current_directory; - GtkActionGroup *action_group; - - GtkAction *action_back; - GtkAction *action_forward; - GSList *back_list; GSList *forward_list; }; - +static guint history_signals[LAST_SIGNAL]; G_DEFINE_TYPE_WITH_CODE (ThunarHistory, thunar_history, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (THUNAR_TYPE_NAVIGATOR, thunar_history_navigator_init)) @@ -121,22 +110,6 @@ thunar_history_class_init (ThunarHistoryClass *klass) thunar_history_display_name_quark = g_quark_from_static_string ("thunar-history-display-name"); thunar_history_gfile_quark = g_quark_from_static_string ("thunar-history-gfile"); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /** - * ThunarHistory::action-group: - * - * The #GtkActionGroup to which the #ThunarHistorys - * actions "back" and "forward" should be connected. - **/ - g_object_class_install_property (gobject_class, - PROP_ACTION_GROUP, - g_param_spec_object ("action-group", - "action-group", - "action-group", - GTK_TYPE_ACTION_GROUP, - EXO_PARAM_READWRITE)); -G_GNUC_END_IGNORE_DEPRECATIONS - /** * ThunarHistory::current-directory: * @@ -145,6 +118,15 @@ G_GNUC_END_IGNORE_DEPRECATIONS g_object_class_override_property (gobject_class, PROP_CURRENT_DIRECTORY, "current-directory"); + + history_signals[HISTORY_CHANGED] = + g_signal_new (I_("history-changed"), + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ThunarHistoryClass, history_changed), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); } @@ -161,21 +143,7 @@ thunar_history_navigator_init (ThunarNavigatorIface *iface) static void thunar_history_init (ThunarHistory *history) { - /* create the "back" action */ - history->action_back = thunar_history_action_new ("back", _("Back"), _("Go to the previous visited folder"), "go-previous-symbolic"); - g_signal_connect (G_OBJECT (history->action_back), "activate", G_CALLBACK (thunar_history_action_back), history); - g_signal_connect (G_OBJECT (history->action_back), "show-menu", G_CALLBACK (thunar_history_show_menu), history); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_action_set_sensitive (history->action_back, FALSE); -G_GNUC_END_IGNORE_DEPRECATIONS - - /* create the "forward" action */ - history->action_forward = thunar_history_action_new ("forward", _("Forward"), _("Go to the next visited folder"), "go-next-symbolic"); - g_signal_connect (G_OBJECT (history->action_forward), "activate", G_CALLBACK (thunar_history_action_forward), history); - g_signal_connect (G_OBJECT (history->action_forward), "show-menu", G_CALLBACK (thunar_history_show_menu), history); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_action_set_sensitive (history->action_forward, FALSE); -G_GNUC_END_IGNORE_DEPRECATIONS + } @@ -188,9 +156,6 @@ thunar_history_dispose (GObject *object) /* disconnect from the current directory */ thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (history), NULL); - /* disconnect from the action group */ - thunar_history_set_action_group (history, NULL); - (*G_OBJECT_CLASS (thunar_history_parent_class)->dispose) (object); } @@ -201,14 +166,6 @@ thunar_history_finalize (GObject *object) { ThunarHistory *history = THUNAR_HISTORY (object); - /* disconnect from the "forward" action */ - g_signal_handlers_disconnect_matched (G_OBJECT (history->action_forward), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, history); - g_object_unref (G_OBJECT (history->action_forward)); - - /* disconnect from the "back" action */ - g_signal_handlers_disconnect_matched (G_OBJECT (history->action_back), G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, history); - g_object_unref (G_OBJECT (history->action_back)); - /* release the "forward" and "back" lists */ g_slist_free_full (history->forward_list, g_object_unref); g_slist_free_full (history->back_list, g_object_unref); @@ -228,10 +185,6 @@ thunar_history_get_property (GObject *object, switch (prop_id) { - case PROP_ACTION_GROUP: - g_value_set_object (value, thunar_history_get_action_group (history)); - break; - case PROP_CURRENT_DIRECTORY: g_value_set_object (value, thunar_navigator_get_current_directory (THUNAR_NAVIGATOR (history))); break; @@ -254,10 +207,6 @@ thunar_history_set_property (GObject *object, switch (prop_id) { - case PROP_ACTION_GROUP: - thunar_history_set_action_group (history, g_value_get_object (value)); - break; - case PROP_CURRENT_DIRECTORY: thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (history), g_value_get_object (value)); break; @@ -320,9 +269,6 @@ thunar_history_set_current_directory (ThunarNavigator *navigator, else { /* clear the "forward" list */ -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_action_set_sensitive (history->action_forward, FALSE); -G_GNUC_END_IGNORE_DEPRECATIONS g_slist_free_full (history->forward_list, g_object_unref); history->forward_list = NULL; @@ -331,9 +277,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS { gfile = thunar_history_get_gfile (history->current_directory); history->back_list = g_slist_prepend (history->back_list, gfile); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_action_set_sensitive (history->action_back, TRUE); -G_GNUC_END_IGNORE_DEPRECATIONS g_object_unref (history->current_directory); } @@ -348,6 +291,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* notify listeners */ g_object_notify (G_OBJECT (history), "current-directory"); + g_signal_emit (G_OBJECT (history), history_signals[HISTORY_CHANGED], 0, history); } @@ -406,8 +350,7 @@ thunar_history_go_back (ThunarHistory *history, g_object_unref (lp->data); history->back_list = g_slist_delete_link (history->back_list, lp); } - - goto update_actions; + return; } /* prepend the previous current directory to the "forward" list */ @@ -452,14 +395,6 @@ thunar_history_go_back (ThunarHistory *history, /* tell the other modules to change the current directory */ if (G_LIKELY (history->current_directory != NULL)) thunar_navigator_change_directory (THUNAR_NAVIGATOR (history), history->current_directory); - - update_actions: - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* update the sensitivity of the actions */ - gtk_action_set_sensitive (history->action_back, (history->back_list != NULL)); - gtk_action_set_sensitive (history->action_forward, (history->forward_list != NULL)); -G_GNUC_END_IGNORE_DEPRECATIONS } @@ -489,8 +424,7 @@ thunar_history_go_forward (ThunarHistory *history, g_object_unref (lp->data); history->forward_list = g_slist_delete_link (history->forward_list, lp); } - - goto update_actions; + return; } /* prepend the previous current directory to the "back" list */ @@ -533,25 +467,13 @@ thunar_history_go_forward (ThunarHistory *history, /* tell the other modules to change the current directory */ if (G_LIKELY (history->current_directory != NULL)) thunar_navigator_change_directory (THUNAR_NAVIGATOR (history), history->current_directory); - - update_actions: - -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* update the sensitivity of the actions */ - gtk_action_set_sensitive (history->action_back, (history->back_list != NULL)); - gtk_action_set_sensitive (history->action_forward, (history->forward_list != NULL)); -G_GNUC_END_IGNORE_DEPRECATIONS } -static void -thunar_history_action_back (GtkAction *action, - ThunarHistory *history) +void +thunar_history_action_back (ThunarHistory *history) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_if_fail (GTK_IS_ACTION (action)); -G_GNUC_END_IGNORE_DEPRECATIONS _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); /* go back one step */ @@ -577,13 +499,9 @@ thunar_history_action_back_nth (GtkWidget *item, -static void -thunar_history_action_forward (GtkAction *action, - ThunarHistory *history) +void +thunar_history_action_forward (ThunarHistory *history) { -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_if_fail (GTK_IS_ACTION (action)); -G_GNUC_END_IGNORE_DEPRECATIONS _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); /* go forward one step */ @@ -609,15 +527,16 @@ thunar_history_action_forward_nth (GtkWidget *item, -static void -thunar_history_show_menu (GtkAction *action, - GtkWidget *menu, - ThunarHistory *history) +void +thunar_history_show_menu (ThunarHistory *history, + ThunarHistoryMenuType type, + GtkWidget *parent) { ThunarIconFactory *icon_factory; GtkIconTheme *icon_theme; GCallback handler; GtkWidget *image; + GtkWidget *menu; GtkWidget *item; GdkPixbuf *icon; GSList *lp; @@ -626,18 +545,17 @@ thunar_history_show_menu (GtkAction *action, const gchar *icon_name; gchar *parse_name; -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_if_fail (GTK_IS_ACTION (action)); -G_GNUC_END_IGNORE_DEPRECATIONS - _thunar_return_if_fail (GTK_IS_MENU_SHELL (menu)); + _thunar_return_if_fail (GTK_IS_WIDGET (parent)); _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); + menu = gtk_menu_new (); + /* determine the icon factory to use to load the icons */ - icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (menu)); + icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (parent)); icon_factory = thunar_icon_factory_get_for_icon_theme (icon_theme); /* check if we have "Back" or "Forward" here */ - if (action == history->action_back) + if (type == THUNAR_HISTORY_MENU_BACK) { /* display the "back" list */ lp = history->back_list; @@ -653,20 +571,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* add menu items for all list items */ for (;lp != NULL; lp = lp->next) { - /* add an item for this file */ - display_name = g_object_get_qdata (G_OBJECT (lp->data), thunar_history_display_name_quark); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - item = gtk_image_menu_item_new_with_label (display_name); -G_GNUC_END_IGNORE_DEPRECATIONS - g_object_set_qdata (G_OBJECT (item), thunar_history_gfile_quark, lp->data); - g_signal_connect (G_OBJECT (item), "activate", handler, history); - gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); - gtk_widget_show (item); - parse_name = g_file_get_parse_name (lp->data); - gtk_widget_set_tooltip_text (item, parse_name); - g_free (parse_name); - file = thunar_file_cache_lookup (lp->data); image = NULL; if (file != NULL) @@ -697,96 +602,37 @@ G_GNUC_END_IGNORE_DEPRECATIONS image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); } -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), image); -G_GNUC_END_IGNORE_DEPRECATIONS - } - - /* release the icon factory */ - g_object_unref (G_OBJECT (icon_factory)); -} - - - -/** - * thunar_history_get_action_group: - * @history : a #ThunarHistory. - * - * Returns the #GtkActionGroup to which @history - * is currently attached, or %NULL if @history is - * not attached to any #GtkActionGroup right now. - * - * Return value: the #GtkActionGroup to which - * @history is currently attached. - **/ -static GtkActionGroup* -thunar_history_get_action_group (const ThunarHistory *history) -{ - _thunar_return_val_if_fail (THUNAR_IS_HISTORY (history), NULL); - return history->action_group; -} - - - -/** - * thunar_history_set_action_group: - * @history : a #ThunarHistory. - * @action_group : a #GtkActionGroup or %NULL. - * - * Attaches @history to the specified @action_group, - * and thereby registers the actions "back" and - * "forward" provided by @history on the given - * @action_group. - **/ -static void -thunar_history_set_action_group (ThunarHistory *history, - GtkActionGroup *action_group) -{ -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_if_fail (THUNAR_IS_HISTORY (history)); - _thunar_return_if_fail (action_group == NULL || GTK_IS_ACTION_GROUP (action_group)); - /* verify that we don't already use that action group */ - if (G_UNLIKELY (history->action_group == action_group)) - return; + /* add an item for this file */ + display_name = g_object_get_qdata (G_OBJECT (lp->data), thunar_history_display_name_quark); + item = xfce_gtk_image_menu_item_new (display_name, parse_name, NULL, + NULL, NULL, image, GTK_MENU_SHELL (menu)); + g_object_set_qdata (G_OBJECT (item), thunar_history_gfile_quark, lp->data); + g_signal_connect (G_OBJECT (item), "activate", handler, history); - /* disconnect from the previous action group */ - if (G_UNLIKELY (history->action_group != NULL)) - { - gtk_action_group_remove_action (history->action_group, history->action_back); - gtk_action_group_remove_action (history->action_group, history->action_forward); - g_object_unref (G_OBJECT (history->action_group)); + g_free (parse_name); } - /* activate the new action group */ - history->action_group = action_group; - - /* connect to the new action group */ - if (G_LIKELY (action_group != NULL)) - { - g_object_ref (G_OBJECT (action_group)); - gtk_action_group_add_action_with_accel (action_group, history->action_back, "Left"); - gtk_action_group_add_action_with_accel (action_group, history->action_forward, "Right"); - } + gtk_widget_show_all (menu); + /* release the icon factory */ + g_object_unref (G_OBJECT (icon_factory)); - /* notify listeners */ - g_object_notify (G_OBJECT (history), "action-group"); -G_GNUC_END_IGNORE_DEPRECATIONS + /* run the menu (takes over the floating of menu) */ + gtk_menu_popup_at_widget (GTK_MENU (menu), parent, + GDK_GRAVITY_SOUTH_WEST, + GDK_GRAVITY_NORTH_WEST, + NULL); } ThunarHistory * -thunar_history_copy (ThunarHistory *history, - GtkActionGroup *action_group) +thunar_history_copy (ThunarHistory *history) { ThunarHistory *copy; GSList *lp; _thunar_return_val_if_fail (history == NULL || THUNAR_IS_HISTORY (history), NULL); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - _thunar_return_val_if_fail (action_group == NULL || GTK_IS_ACTION_GROUP (action_group), NULL); -G_GNUC_END_IGNORE_DEPRECATIONS if (G_UNLIKELY (history == NULL)) return NULL; @@ -796,9 +642,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS /* take a ref on the current directory */ copy->current_directory = g_object_ref (history->current_directory); - /* set the action group */ - thunar_history_set_action_group (copy, action_group); - /* copy the back list */ for (lp = history->back_list; lp != NULL; lp = lp->next) copy->back_list = g_slist_append (copy->back_list, g_object_ref (G_OBJECT (lp->data))); @@ -807,17 +650,44 @@ G_GNUC_END_IGNORE_DEPRECATIONS for (lp = history->forward_list; lp != NULL; lp = lp->next) copy->forward_list = g_slist_append (copy->forward_list, g_object_ref (G_OBJECT (lp->data))); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - /* update the sensitivity of the actions */ - gtk_action_set_sensitive (copy->action_back, (copy->back_list != NULL)); - gtk_action_set_sensitive (copy->action_forward, (copy->forward_list != NULL)); -G_GNUC_END_IGNORE_DEPRECATIONS - return copy; } +/** + * thunar_history_has_back: + * @history : a #ThunarHistory. + * + * Return value: TRUE if there is a backward history + **/ +gboolean +thunar_history_has_back (ThunarHistory *history) +{ + _thunar_return_val_if_fail (THUNAR_IS_HISTORY (history), FALSE); + + return history->back_list != NULL; +} + + + + +/** + * thunar_history_has_forward: + * @history : a #ThunarHistory. + * + * Return value: TRUE if there is a forward history + **/ +gboolean +thunar_history_has_forward (ThunarHistory *history) +{ + _thunar_return_val_if_fail (THUNAR_IS_HISTORY (history), FALSE); + + return history->forward_list != NULL; +} + + + /** * thunar_file_history_peek_back: * @history : a #ThunarHistory. diff --git a/thunar/thunar-history.h b/thunar/thunar-history.h index efef8ec1..ffae36e0 100644 --- a/thunar/thunar-history.h +++ b/thunar/thunar-history.h @@ -34,13 +34,35 @@ typedef struct _ThunarHistory ThunarHistory; #define THUNAR_IS_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), THUNAR_TYPE_HISTORY)) #define THUNAR_HISTORY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), THUNAR_TYPE_HISTORY, ThunarHistoryClass)) -GType thunar_history_get_type (void) G_GNUC_CONST; +typedef enum +{ + THUNAR_HISTORY_MENU_BACK, + THUNAR_HISTORY_MENU_FORWARD, + + +} ThunarHistoryMenuType; -ThunarHistory *thunar_history_copy (ThunarHistory *history, - GtkActionGroup *action_group); +struct _ThunarHistoryClass +{ + GObjectClass __parent__; + + /* external signals */ + void (*history_changed) (ThunarHistory *history, + const gchar *initial_text); +}; + +GType thunar_history_get_type (void) G_GNUC_CONST; -ThunarFile *thunar_history_peek_back (ThunarHistory *history); -ThunarFile *thunar_history_peek_forward (ThunarHistory *history); +ThunarHistory *thunar_history_copy (ThunarHistory *history); +gboolean thunar_history_has_back (ThunarHistory *history); +gboolean thunar_history_has_forward (ThunarHistory *history); +ThunarFile *thunar_history_peek_back (ThunarHistory *history); +ThunarFile *thunar_history_peek_forward (ThunarHistory *history); +void thunar_history_action_back (ThunarHistory *history); +void thunar_history_action_forward (ThunarHistory *history); +void thunar_history_show_menu (ThunarHistory *history, + ThunarHistoryMenuType type, + GtkWidget *parent); G_END_DECLS; diff --git a/thunar/thunar-standard-view.c b/thunar/thunar-standard-view.c index a577956a..82e1b72b 100644 --- a/thunar/thunar-standard-view.c +++ b/thunar/thunar-standard-view.c @@ -185,9 +185,6 @@ static gboolean thunar_standard_view_key_press_event (Gtk static gboolean thunar_standard_view_scroll_event (GtkWidget *view, GdkEventScroll *event, ThunarStandardView *standard_view); -static gboolean thunar_standard_view_button_press_event (GtkWidget *view, - GdkEventButton *event, - ThunarStandardView *standard_view); static gboolean thunar_standard_view_drag_drop (GtkWidget *view, GdkDragContext *context, gint x, @@ -658,7 +655,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS g_object_unref (G_OBJECT (standard_view->priv->action_create_document)); /* setup the history support */ - standard_view->priv->history = g_object_new (THUNAR_TYPE_HISTORY, "action-group", standard_view->action_group, NULL); + standard_view->priv->history = g_object_new (THUNAR_TYPE_HISTORY, NULL); g_signal_connect_swapped (G_OBJECT (standard_view->priv->history), "change-directory", G_CALLBACK (thunar_navigator_change_directory), standard_view); /* setup the list model */ @@ -763,7 +760,6 @@ thunar_standard_view_constructor (GType type, /* setup support to navigate using a horizontal mouse wheel and the back and forward buttons */ g_signal_connect (G_OBJECT (view), "scroll-event", G_CALLBACK (thunar_standard_view_scroll_event), object); - g_signal_connect (G_OBJECT (view), "button-press-event", G_CALLBACK (thunar_standard_view_button_press_event), object); /* need to catch certain keys for the internal view widget */ g_signal_connect (G_OBJECT (view), "key-press-event", G_CALLBACK (thunar_standard_view_key_press_event), object); @@ -2390,7 +2386,6 @@ thunar_standard_view_scroll_event (GtkWidget *view, GdkEventScroll *event, ThunarStandardView *standard_view) { - GdkEventButton fake_event; GdkScrollDirection scrolling_direction; gboolean misc_horizontal_wheel_navigates; @@ -2418,12 +2413,10 @@ thunar_standard_view_scroll_event (GtkWidget *view, g_object_get (G_OBJECT (standard_view->preferences), "misc-horizontal-wheel-navigates", &misc_horizontal_wheel_navigates, NULL); if (G_UNLIKELY (misc_horizontal_wheel_navigates)) { - /* create a fake event (8 == back, 9 forward) */ - fake_event.type = GDK_BUTTON_PRESS; - fake_event.button = scrolling_direction == GDK_SCROLL_LEFT ? 8 : 9; - - /* trigger a fake button press event */ - return thunar_standard_view_button_press_event (view, &fake_event, standard_view); + if (scrolling_direction == GDK_SCROLL_LEFT) + thunar_history_action_back (standard_view->priv->history); + else + thunar_history_action_forward (standard_view->priv->history); } } @@ -2443,36 +2436,6 @@ thunar_standard_view_scroll_event (GtkWidget *view, -static gboolean -thunar_standard_view_button_press_event (GtkWidget *view, - GdkEventButton *event, - ThunarStandardView *standard_view) -{ -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - GtkAction *action = NULL; - - if (G_LIKELY (event->type == GDK_BUTTON_PRESS)) - { - /* determine the appropriate action ("back" for button 8, "forward" for button 9) */ - if (G_UNLIKELY (event->button == 8)) - action = gtk_ui_manager_get_action (standard_view->ui_manager, "/main-menu/go-menu/placeholder-go-history-actions/back"); - else if (G_UNLIKELY (event->button == 9)) - action = gtk_ui_manager_get_action (standard_view->ui_manager, "/main-menu/go-menu/placeholder-go-history-actions/forward"); - - /* perform the action (if any) */ - if (G_UNLIKELY (action != NULL)) - { - gtk_action_activate (action); - return TRUE; - } - } -G_GNUC_END_IGNORE_DEPRECATIONS - /* next please... */ - return FALSE; -} - - - static gboolean thunar_standard_view_key_press_event (GtkWidget *view, GdkEventKey *event, @@ -3797,6 +3760,13 @@ thunar_standard_view_selection_changed (ThunarStandardView *standard_view) +/** + * thunar_standard_view_set_history: + * @standard_view : a #ThunarStandardView instance. + * @history : the #ThunarHistory to set. + * + * replaces the history of this #ThunarStandardView with the passed history + **/ void thunar_standard_view_set_history (ThunarStandardView *standard_view, ThunarHistory *history) @@ -3810,19 +3780,41 @@ thunar_standard_view_set_history (ThunarStandardView *standard_view, /* connect callback */ g_signal_connect_swapped (G_OBJECT (history), "change-directory", G_CALLBACK (thunar_navigator_change_directory), standard_view); +} + + - /* make the history use the action group of this view */ - g_object_set (G_OBJECT (history), "action-group", standard_view->action_group, NULL); +/** + * thunar_standard_view_get_history: + * @standard_view : a #ThunarStandardView instance. + * + * returns the #ThunarHistory of this #ThunarStandardView + * + * Return value: (transfer none): The #ThunarHistory of this #ThunarStandardView + **/ +ThunarHistory* +thunar_standard_view_get_history (ThunarStandardView *standard_view) +{ + return standard_view->priv->history; } +/** + * thunar_standard_view_copy_history: + * @standard_view : a #ThunarStandardView instance. + * + * returns a copy of the #ThunarHistory of this #ThunarStandardView + * The caller has to release the passed history with g_object_unref() after use. + * + * Return value: (transfer full): A copy of the #ThunarHistory of this #ThunarStandardView + **/ ThunarHistory * thunar_standard_view_copy_history (ThunarStandardView *standard_view) { _thunar_return_val_if_fail (THUNAR_IS_STANDARD_VIEW (standard_view), NULL); - return thunar_history_copy (standard_view->priv->history, NULL); + return thunar_history_copy (standard_view->priv->history); } diff --git a/thunar/thunar-standard-view.h b/thunar/thunar-standard-view.h index a05f5267..93eaf05a 100644 --- a/thunar/thunar-standard-view.h +++ b/thunar/thunar-standard-view.h @@ -168,6 +168,7 @@ void thunar_standard_view_queue_popup (ThunarStandardView void thunar_standard_view_selection_changed (ThunarStandardView *standard_view); void thunar_standard_view_set_history (ThunarStandardView *standard_view, ThunarHistory *history); +ThunarHistory *thunar_standard_view_get_history (ThunarStandardView *standard_view); ThunarHistory *thunar_standard_view_copy_history (ThunarStandardView *standard_view); void thunar_standard_view_append_menu_items (ThunarStandardView *standard_view, GtkMenu *menu, diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index f73507f9..a004398b 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -104,8 +104,7 @@ static void thunar_window_set_property (GObject guint prop_id, const GValue *value, GParamSpec *pspec); -static gboolean thunar_window_back (ThunarWindow *window); -static gboolean thunar_window_reload (ThunarWindow *window, +static gboolean thunar_window_reload (ThunarWindow *window, gboolean reload_info); static gboolean thunar_window_toggle_sidepane (ThunarWindow *window); static gboolean thunar_window_zoom_in (ThunarWindow *window); @@ -177,6 +176,8 @@ static void thunar_window_action_compact_view (ThunarWindow static void thunar_window_action_view_changed (ThunarWindow *window, GType view_type); static void thunar_window_action_go_up (ThunarWindow *window); +static void thunar_window_action_back (ThunarWindow *window); +static void thunar_window_action_forward (ThunarWindow *window); static void thunar_window_action_open_home (ThunarWindow *window); static void thunar_window_action_open_desktop (ThunarWindow *window); static void thunar_window_action_open_computer (ThunarWindow *window); @@ -251,6 +252,10 @@ static void thunar_window_binding_create (ThunarWindow gpointer dst_object, const gchar *dst_prop, GBindingFlags flags); +static gboolean thunar_window_history_clicked (GtkWidget *button, + GdkEventButton *event, + GtkWidget *window); +static void thunar_window_history_changed (ThunarWindow *window); static gboolean thunar_window_menu_item_hovered (ThunarWindow *window, GdkEventCrossing *event, GtkWidget *menu); @@ -327,8 +332,15 @@ struct _ThunarWindow GtkWidget *location_bar; GtkWidget *location_toolbar; + /* we need to maintain pointers to be able to toggle sensitivity */ + GtkWidget *location_toolbar_item_back; + GtkWidget *location_toolbar_item_forward; + GtkWidget *location_toolbar_item_parent; + ThunarLauncher *launcher; + gulong signal_handler_id_history_changed; + ThunarFile *current_directory; GtkAccelGroup *accel_group; @@ -453,6 +465,9 @@ static XfceGtkActionEntry thunar_window_action_entries[] = { THUNAR_WINDOW_ACTION_HELP_MENU, "/ThunarWindow/contents/help-menu", "", XFCE_GTK_MENU_ITEM , N_ ("_Help"), NULL, NULL, NULL}, { THUNAR_WINDOW_ACTION_CONTENTS, "/ThunarWindow/contents", "F1", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Contents"), N_ ("Display Thunar user manual"), "help-browser", G_CALLBACK (thunar_window_action_contents), }, { THUNAR_WINDOW_ACTION_ABOUT, "/ThunarWindow/about", "", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_About"), N_ ("Display information about Thunar"), "help-about", G_CALLBACK (thunar_window_action_about), }, + { THUNAR_WINDOW_ACTION_BACK, "/ThunarStandardView/back", "Left", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Back"), N_ ("Go to the previous visited folder"), "go-previous-symbolic", G_CALLBACK (thunar_window_action_back), }, + { THUNAR_WINDOW_ACTION_BACK_ALT, "/ThunarStandardView/back-alt", "BackSpace", XFCE_GTK_IMAGE_MENU_ITEM, NULL, NULL, NULL, G_CALLBACK (thunar_window_action_back), }, + { THUNAR_WINDOW_ACTION_FORWARD, "/ThunarStandardView/forward", "Right", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("Forward"), N_ ("Go to the next visited folder"), "go-next-symbolic", G_CALLBACK (thunar_window_action_forward), }, { THUNAR_WINDOW_ACTION_SWITCH_PREV_TAB, "/ThunarWindow/switch-previous-tab", "Page_Up", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Previous Tab"), N_ ("Switch to Previous Tab"), "go-previous", G_CALLBACK (thunar_window_action_switch_previous_tab), }, { THUNAR_WINDOW_ACTION_SWITCH_NEXT_TAB, "/ThunarWindow/switch-next-tab", "Page_Down", XFCE_GTK_IMAGE_MENU_ITEM, N_ ("_Next Tab"), N_ ("Switch to Next Tab"), "go-next", G_CALLBACK (thunar_window_action_switch_next_tab), }, { 0, "/ThunarWindow/open-file-menu", "F10", 0, NULL, NULL, NULL, G_CALLBACK (thunar_window_action_open_file_menu), }, @@ -490,7 +505,6 @@ thunar_window_class_init (ThunarWindowClass *klass) gtkwidget_class->unrealize = thunar_window_unrealize; gtkwidget_class->configure_event = thunar_window_configure_event; - klass->back = thunar_window_back; klass->reload = thunar_window_reload; klass->zoom_in = thunar_window_zoom_in; klass->zoom_out = thunar_window_zoom_out; @@ -966,29 +980,34 @@ G_GNUC_END_IGNORE_DEPRECATIONS g_signal_connect_swapped (G_OBJECT (window->location_bar), "reload-requested", G_CALLBACK (thunar_window_handle_reload_request), window); g_signal_connect_swapped (G_OBJECT (window->location_bar), "entry-done", G_CALLBACK (thunar_window_update_location_bar_visible), window); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* setup the toolbar for the location bar */ - window->location_toolbar = gtk_ui_manager_get_widget (window->ui_manager, "/location-toolbar"); -G_GNUC_END_IGNORE_DEPRECATIONS - + window->location_toolbar = gtk_toolbar_new (); gtk_toolbar_set_style (GTK_TOOLBAR (window->location_toolbar), GTK_TOOLBAR_ICONS); gtk_toolbar_set_icon_size (GTK_TOOLBAR (window->location_toolbar), small_icons ? GTK_ICON_SIZE_SMALL_TOOLBAR : GTK_ICON_SIZE_LARGE_TOOLBAR); gtk_widget_set_hexpand (window->location_toolbar, TRUE); gtk_grid_attach (GTK_GRID (window->grid), window->location_toolbar, 0, 1, 1, 1); - /* add the location bar tool item */ + window->location_toolbar_item_back = xfce_gtk_tool_button_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_BACK), G_OBJECT (window), GTK_TOOLBAR (window->location_toolbar)); + window->location_toolbar_item_forward = xfce_gtk_tool_button_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_FORWARD), G_OBJECT (window), GTK_TOOLBAR (window->location_toolbar)); + window->location_toolbar_item_parent = xfce_gtk_tool_button_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_OPEN_PARENT), G_OBJECT (window), GTK_TOOLBAR (window->location_toolbar)); + xfce_gtk_tool_button_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_OPEN_HOME), G_OBJECT (window), GTK_TOOLBAR (window->location_toolbar)); + + g_signal_connect (G_OBJECT (window->location_toolbar_item_back), "button-press-event", G_CALLBACK (thunar_window_history_clicked), G_OBJECT (window)); + g_signal_connect (G_OBJECT (window->location_toolbar_item_forward), "button-press-event", G_CALLBACK (thunar_window_history_clicked), G_OBJECT (window)); + window->signal_handler_id_history_changed = 0; + + /* add the location bar to the toolbar */ tool_item = gtk_tool_item_new (); gtk_tool_item_set_expand (tool_item, TRUE); gtk_toolbar_insert (GTK_TOOLBAR (window->location_toolbar), tool_item, -1); gtk_toolbar_set_show_arrow (GTK_TOOLBAR (window->location_toolbar), FALSE); - gtk_widget_show (GTK_WIDGET (tool_item)); /* add the location bar itself */ gtk_container_add (GTK_CONTAINER (tool_item), window->location_bar); - /* display the new location bar widget */ - gtk_widget_show (window->location_bar); + /* display the toolbar */ + gtk_widget_show_all (window->location_toolbar); G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* activate the selected location selector */ @@ -1259,17 +1278,26 @@ thunar_window_create_go_menu (ThunarWindow *window, ThunarMenu *submenu; gchar *icon_name; const XfceGtkActionEntry *action_entry; + ThunarHistory *history = NULL; GtkWidget *item; _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE); _thunar_return_val_if_fail (GTK_IS_MENU_ITEM (menu), FALSE); + if (window->view != NULL) + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + submenu = g_object_new (THUNAR_TYPE_MENU, "launcher", window->launcher, NULL); gtk_menu_set_accel_group (GTK_MENU (submenu), window->accel_group); gtk_menu_item_set_submenu (GTK_MENU_ITEM (menu), GTK_WIDGET (submenu)); item = xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_OPEN_PARENT), G_OBJECT (window), GTK_MENU_SHELL (submenu)); gtk_widget_set_sensitive (item, !thunar_g_file_is_root (thunar_file_get_file (window->current_directory))); - + item = xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_BACK), G_OBJECT (window), GTK_MENU_SHELL (submenu)); + if (history != NULL) + gtk_widget_set_sensitive (item, thunar_history_has_back (history)); + item = xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_FORWARD), G_OBJECT (window), GTK_MENU_SHELL (submenu)); + if (history != NULL) + gtk_widget_set_sensitive (item, thunar_history_has_forward (history)); xfce_gtk_menu_append_seperator (GTK_MENU_SHELL (submenu)); xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_OPEN_COMPUTER), G_OBJECT (window), GTK_MENU_SHELL (submenu)); xfce_gtk_menu_item_new_from_action_entry (get_action_entry (THUNAR_WINDOW_ACTION_OPEN_HOME), G_OBJECT (window), GTK_MENU_SHELL (submenu)); @@ -1341,7 +1369,11 @@ thunar_window_create_help_menu (ThunarWindow *window, static void thunar_window_dispose (GObject *object) { - ThunarWindow *window = THUNAR_WINDOW (object); + ThunarWindow *window = THUNAR_WINDOW (object); + + /* indicate that history items are out of use */ + window->location_toolbar_item_back = NULL; + window->location_toolbar_item_forward = NULL; /* destroy the save geometry timer source */ if (G_UNLIKELY (window->save_geometry_timer_id != 0)) @@ -1544,52 +1576,6 @@ thunar_window_set_property (GObject *object, -static gboolean -thunar_window_back (ThunarWindow *window) -{ - GtkAction *action; - GdkEvent *event; - const gchar *accel_path; - GtkAccelKey key; - - _thunar_return_val_if_fail (THUNAR_IS_WINDOW (window), FALSE); - - /* check source event */ - event = gtk_get_current_event (); -G_GNUC_BEGIN_IGNORE_DEPRECATIONS - if (event != NULL - && event->type == GDK_KEY_PRESS) - { - action = thunar_gtk_ui_manager_get_action_by_name (window->ui_manager, "open-parent"); - if (G_LIKELY (action != NULL)) - { - /* check if the current event (back) is different then the open-parent - * accelerator. this way a user can override the default backspace action - * of back in open-parent, without backspace resulting in a back action - * if open-parent is insensitive in the menu */ - accel_path = gtk_action_get_accel_path (action); - if (accel_path != NULL - && gtk_accel_map_lookup_entry (accel_path, &key) - && key.accel_key == ((GdkEventKey *) event)->keyval - && key.accel_mods == 0) - return FALSE; - } - } - - /* activate the "back" action */ - action = thunar_gtk_ui_manager_get_action_by_name (window->ui_manager, "back"); - if (G_LIKELY (action != NULL)) - { - gtk_action_activate (action); - return TRUE; - } -G_GNUC_END_IGNORE_DEPRECATIONS - - return FALSE; -} - - - static gboolean thunar_window_reload (ThunarWindow *window, gboolean reload_info) @@ -1879,6 +1865,7 @@ thunar_window_notebook_switch_page (GtkWidget *notebook, { GSList *view_bindings; ThunarFile *current_directory; + ThunarHistory *history; _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); _thunar_return_if_fail (GTK_IS_NOTEBOOK (notebook)); @@ -1891,8 +1878,13 @@ thunar_window_notebook_switch_page (GtkWidget *notebook, if (G_LIKELY (window->view != NULL)) { - /* unregisters the actions from the ui */ - thunar_component_set_ui_manager (THUNAR_COMPONENT (window->view), NULL); + /* disconnect from previous history */ + if (window->signal_handler_id_history_changed != 0) + { + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + g_signal_handler_disconnect (history, window->signal_handler_id_history_changed); + window->signal_handler_id_history_changed = 0; + } /* unset view during switch */ window->view = NULL; @@ -1939,6 +1931,14 @@ thunar_window_notebook_switch_page (GtkWidget *notebook, /* integrate the standard view action in the ui */ thunar_component_set_ui_manager (THUNAR_COMPONENT (page), window->ui_manager); + /* connect to the new history */ + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + if (history != NULL) + { + window->signal_handler_id_history_changed = g_signal_connect_swapped (G_OBJECT (history), "history-changed", G_CALLBACK (thunar_window_history_changed), window); + thunar_window_history_changed (window); + } + /* update the actions */ thunar_standard_view_selection_changed (THUNAR_STANDARD_VIEW (page)); @@ -1967,6 +1967,29 @@ thunar_window_notebook_show_tabs (ThunarWindow *window) +static void +thunar_window_history_changed (ThunarWindow *window) +{ + ThunarHistory *history; + + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); + + if (window->view == NULL) + return; + + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + if (history == NULL) + return; + + if (window->location_toolbar_item_back != NULL) + gtk_widget_set_sensitive (window->location_toolbar_item_back, thunar_history_has_back (history)); + + if (window->location_toolbar_item_forward != NULL) + gtk_widget_set_sensitive (window->location_toolbar_item_forward, thunar_history_has_forward (history)); +} + + + static void thunar_window_notebook_page_added (GtkWidget *notebook, GtkWidget *page, @@ -2185,18 +2208,18 @@ thunar_window_notebook_insert (ThunarWindow *window, if (directory == NULL) return; - /* save the history of the origin view */ - if (THUNAR_IS_STANDARD_VIEW (window->view)) - history = thunar_standard_view_copy_history (THUNAR_STANDARD_VIEW (window->view)); - /* allocate and setup a new view */ view = g_object_new (window->view_type, "current-directory", directory, "accel-group", window->accel_group, NULL); thunar_view_set_show_hidden (THUNAR_VIEW (view), window->show_hidden); gtk_widget_show (view); - /* use the history of the origin view if available */ - if (history != NULL) - thunar_standard_view_set_history (THUNAR_STANDARD_VIEW (view), history); + /* save the history of the origin view */ + if (THUNAR_IS_STANDARD_VIEW (window->view)) + { + history = thunar_standard_view_copy_history (THUNAR_STANDARD_VIEW (window->view)); + if (history != NULL) + thunar_standard_view_set_history (THUNAR_STANDARD_VIEW (view), history); + } label_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); @@ -2741,7 +2764,13 @@ thunar_window_action_open_new_window (ThunarWindow *window, /* let the view of the new window inherit the history of the origin view */ history = thunar_standard_view_copy_history (THUNAR_STANDARD_VIEW (window->view)); if (history != NULL) - thunar_standard_view_set_history (THUNAR_STANDARD_VIEW (new_window->view), history); + { + thunar_standard_view_set_history (THUNAR_STANDARD_VIEW (new_window->view), history); + thunar_window_history_changed (new_window); + + /* connect to the new history */ + window->signal_handler_id_history_changed = g_signal_connect_swapped (G_OBJECT (history), "history-changed", G_CALLBACK (thunar_window_history_changed), new_window); + } /* determine the first visible file in the current window */ if (thunar_view_get_visible_range (THUNAR_VIEW (window->view), &start_file, NULL)) @@ -3041,12 +3070,20 @@ thunar_window_action_view_changed (ThunarWindow *window, ThunarFile *file = NULL; ThunarFile *current_directory = NULL; GtkWidget *old_view; + ThunarHistory *history; GList *selected_files = NULL; /* drop the previous view (if any) */ old_view = window->view; if (G_LIKELY (window->view != NULL)) { + if (window->signal_handler_id_history_changed != 0) + { + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + g_signal_handler_disconnect (history, window->signal_handler_id_history_changed); + window->signal_handler_id_history_changed = 0; + } + /* get first visible file in the previous view */ if (!thunar_view_get_visible_range (THUNAR_VIEW (window->view), &file, NULL)) file = NULL; @@ -3099,6 +3136,9 @@ thunar_window_action_view_changed (ThunarWindow *window, g_object_unref (G_OBJECT (file)); if (G_UNLIKELY (current_directory != NULL)) g_object_unref (G_OBJECT (current_directory)); + + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + window->signal_handler_id_history_changed = g_signal_connect_swapped (G_OBJECT (history), "history-changed", G_CALLBACK (thunar_window_history_changed), window); } @@ -3124,6 +3164,32 @@ thunar_window_action_go_up (ThunarWindow *window) +static void +thunar_window_action_back (ThunarWindow *window) +{ + ThunarHistory *history; + + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); + + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + thunar_history_action_back (history); +} + + + +static void +thunar_window_action_forward (ThunarWindow *window) +{ + ThunarHistory *history; + + _thunar_return_if_fail (THUNAR_IS_WINDOW (window)); + + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + thunar_history_action_forward (history); +} + + + static void thunar_window_action_open_home (ThunarWindow *window) { @@ -4120,9 +4186,8 @@ thunar_window_set_current_directory (ThunarWindow *window, gtk_widget_grab_focus (window->view); } - /* enable the 'Up' action if possible for the new directory */ - thunar_gtk_action_group_set_action_sensitive (window->action_group, "open-parent", (current_directory != NULL - && thunar_file_has_parent (current_directory))); + thunar_window_history_changed (window); + gtk_widget_set_sensitive (window->location_toolbar_item_parent, !thunar_g_file_is_root (thunar_file_get_file (current_directory))); } /* tell everybody that we have a new "current-directory", @@ -4308,3 +4373,32 @@ thunar_window_get_launcher (ThunarWindow *window) return window->launcher; } + + + +static gboolean +thunar_window_history_clicked (GtkWidget *button, + GdkEventButton *event, + GtkWidget *data) +{ + ThunarHistory *history; + ThunarWindow *window; + + _thunar_return_val_if_fail (THUNAR_IS_WINDOW (data), FALSE); + + window = THUNAR_WINDOW (data); + + if (event->button == 3) + { + history = thunar_standard_view_get_history (THUNAR_STANDARD_VIEW (window->view)); + + if (button == window->location_toolbar_item_back) + thunar_history_show_menu (history, THUNAR_HISTORY_MENU_BACK, button); + else if (button == window->location_toolbar_item_forward) + thunar_history_show_menu (history, THUNAR_HISTORY_MENU_FORWARD, button); + else + g_warning ("This button is not able to spawn a history menu"); + } + + return FALSE; +} -- cgit v1.2.1