summaryrefslogtreecommitdiff
path: root/thunar/thunar-shortcuts-pane.c
diff options
context:
space:
mode:
Diffstat (limited to 'thunar/thunar-shortcuts-pane.c')
-rw-r--r--thunar/thunar-shortcuts-pane.c181
1 files changed, 17 insertions, 164 deletions
diff --git a/thunar/thunar-shortcuts-pane.c b/thunar/thunar-shortcuts-pane.c
index 2cc26a20..7e4f8fb1 100644
--- a/thunar/thunar-shortcuts-pane.c
+++ b/thunar/thunar-shortcuts-pane.c
@@ -25,7 +25,6 @@
#include <thunar/thunar-private.h>
#include <thunar/thunar-shortcuts-model.h>
#include <thunar/thunar-shortcuts-pane.h>
-#include <thunar/thunar-shortcuts-pane-ui.h>
#include <thunar/thunar-shortcuts-view.h>
#include <thunar/thunar-side-pane.h>
@@ -37,7 +36,6 @@ enum
PROP_CURRENT_DIRECTORY,
PROP_SELECTED_FILES,
PROP_SHOW_HIDDEN,
- PROP_UI_MANAGER,
};
@@ -61,11 +59,6 @@ static void thunar_shortcuts_pane_set_current_directory (ThunarNavigato
static GList *thunar_shortcuts_pane_get_selected_files (ThunarComponent *component);
static void thunar_shortcuts_pane_set_selected_files (ThunarComponent *component,
GList *selected_files);
-static GtkUIManager *thunar_shortcuts_pane_get_ui_manager (ThunarComponent *component);
-static void thunar_shortcuts_pane_set_ui_manager (ThunarComponent *component,
- GtkUIManager *ui_manager);
-static void thunar_shortcuts_pane_action_shortcuts_add (GtkAction *action,
- ThunarShortcutsPane *shortcuts_pane);
static void thunar_shortcuts_pane_show_shortcuts_view_padding (GtkWidget *widget);
static void thunar_shortcuts_pane_hide_shortcuts_view_padding (GtkWidget *widget);
@@ -83,10 +76,6 @@ struct _ThunarShortcutsPane
ThunarFile *current_directory;
GList *selected_files;
- GtkActionGroup *action_group;
- GtkUIManager *ui_manager;
- guint ui_merge_id;
-
GtkWidget *view;
guint idle_select_directory;
@@ -94,13 +83,6 @@ struct _ThunarShortcutsPane
-static const GtkActionEntry action_entries[] =
-{
- { "sendto-shortcuts", "bookmark-new", "", NULL, NULL, G_CALLBACK (thunar_shortcuts_pane_action_shortcuts_add), },
-};
-
-
-
G_DEFINE_TYPE_WITH_CODE (ThunarShortcutsPane, thunar_shortcuts_pane, GTK_TYPE_SCROLLED_WINDOW,
G_IMPLEMENT_INTERFACE (THUNAR_TYPE_NAVIGATOR, thunar_shortcuts_pane_navigator_init)
G_IMPLEMENT_INTERFACE (THUNAR_TYPE_COMPONENT, thunar_shortcuts_pane_component_init)
@@ -124,7 +106,6 @@ thunar_shortcuts_pane_class_init (ThunarShortcutsPaneClass *klass)
/* override ThunarComponent's properties */
g_object_class_override_property (gobject_class, PROP_SELECTED_FILES, "selected-files");
- g_object_class_override_property (gobject_class, PROP_UI_MANAGER, "ui-manager");
/* override ThunarSidePane's properties */
g_object_class_override_property (gobject_class, PROP_SHOW_HIDDEN, "show-hidden");
@@ -137,8 +118,6 @@ thunar_shortcuts_pane_component_init (ThunarComponentIface *iface)
{
iface->get_selected_files = thunar_shortcuts_pane_get_selected_files;
iface->set_selected_files = thunar_shortcuts_pane_set_selected_files;
- iface->get_ui_manager = thunar_shortcuts_pane_get_ui_manager;
- iface->set_ui_manager = thunar_shortcuts_pane_set_ui_manager;
}
@@ -166,13 +145,6 @@ thunar_shortcuts_pane_init (ThunarShortcutsPane *shortcuts_pane)
{
GtkWidget *vscrollbar;
- /* setup the action group for the shortcuts actions */
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- shortcuts_pane->action_group = gtk_action_group_new ("ThunarShortcutsPane");
- gtk_action_group_set_translation_domain (shortcuts_pane->action_group, GETTEXT_PACKAGE);
- gtk_action_group_add_actions (shortcuts_pane->action_group, action_entries, G_N_ELEMENTS (action_entries), shortcuts_pane);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
/* configure the GtkScrolledWindow */
gtk_scrolled_window_set_hadjustment (GTK_SCROLLED_WINDOW (shortcuts_pane), NULL);
gtk_scrolled_window_set_vadjustment (GTK_SCROLLED_WINDOW (shortcuts_pane), NULL);
@@ -209,7 +181,6 @@ thunar_shortcuts_pane_dispose (GObject *object)
thunar_navigator_set_current_directory (THUNAR_NAVIGATOR (shortcuts_pane), NULL);
thunar_component_set_selected_files (THUNAR_COMPONENT (shortcuts_pane), NULL);
- thunar_component_set_ui_manager (THUNAR_COMPONENT (shortcuts_pane), NULL);
(*G_OBJECT_CLASS (thunar_shortcuts_pane_parent_class)->dispose) (object);
}
@@ -219,11 +190,6 @@ thunar_shortcuts_pane_dispose (GObject *object)
static void
thunar_shortcuts_pane_finalize (GObject *object)
{
- ThunarShortcutsPane *shortcuts_pane = THUNAR_SHORTCUTS_PANE (object);
-
- /* release our action group */
- g_object_unref (G_OBJECT (shortcuts_pane->action_group));
-
(*G_OBJECT_CLASS (thunar_shortcuts_pane_parent_class)->finalize) (object);
}
@@ -249,10 +215,6 @@ thunar_shortcuts_pane_get_property (GObject *object,
g_value_set_boolean (value, thunar_side_pane_get_show_hidden (THUNAR_SIDE_PANE (object)));
break;
- case PROP_UI_MANAGER:
- g_value_set_object (value, thunar_component_get_ui_manager (THUNAR_COMPONENT (object)));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -281,10 +243,6 @@ thunar_shortcuts_pane_set_property (GObject *object,
thunar_side_pane_set_show_hidden (THUNAR_SIDE_PANE (object), g_value_get_boolean (value));
break;
- case PROP_UI_MANAGER:
- thunar_component_set_ui_manager (THUNAR_COMPONENT (object), g_value_get_object (value));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -372,11 +330,6 @@ thunar_shortcuts_pane_set_selected_files (ThunarComponent *component,
GList *selected_files)
{
ThunarShortcutsPane *shortcuts_pane = THUNAR_SHORTCUTS_PANE (component);
- GtkTreeModel *model;
- GtkTreeModel *child_model;
- GtkAction *action;
- GList *lp;
- gint n;
/* disconnect from the previously selected files... */
thunar_g_file_list_free (shortcuts_pane->selected_files);
@@ -384,140 +337,40 @@ thunar_shortcuts_pane_set_selected_files (ThunarComponent *component,
/* ...and take a copy of the newly selected files */
shortcuts_pane->selected_files = thunar_g_file_list_copy (selected_files);
- /* check if the selection contains only folders */
- for (lp = selected_files, n = 0; lp != NULL; lp = lp->next, ++n)
- if (!thunar_file_is_directory (lp->data))
- break;
-
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- /* change the visibility of the "shortcuts-add" action appropriately */
- action = gtk_action_group_get_action (shortcuts_pane->action_group, "sendto-shortcuts");
-G_GNUC_END_IGNORE_DEPRECATIONS
- if (lp == NULL && selected_files != NULL)
- {
- /* check if atleast one of the selected folders is not already present in the model */
- model = gtk_tree_view_get_model (GTK_TREE_VIEW (shortcuts_pane->view));
- if (G_LIKELY (model != NULL))
- {
- /* check all selected folders */
- child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
- for (lp = selected_files; lp != NULL; lp = lp->next)
- if (!thunar_shortcuts_model_has_bookmark (THUNAR_SHORTCUTS_MODEL (child_model), thunar_file_get_file (lp->data)))
- break;
- }
-
- /* display the action and change the label appropriately */
- g_object_set (G_OBJECT (action),
- "label", ngettext ("Side Pane (Create Shortcut)", "Side Pane (Create Shortcuts)", n),
- "sensitive", (lp != NULL),
- "tooltip", ngettext ("Add the selected folder to the shortcuts side pane",
- "Add the selected folders to the shortcuts side pane", n),
- "visible", TRUE,
- NULL);
- }
- else
- {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- /* hide the action */
- gtk_action_set_visible (action, FALSE);
-G_GNUC_END_IGNORE_DEPRECATIONS
- }
-
/* notify listeners */
g_object_notify (G_OBJECT (shortcuts_pane), "selected-files");
}
-static GtkUIManager*
-thunar_shortcuts_pane_get_ui_manager (ThunarComponent *component)
-{
- return THUNAR_SHORTCUTS_PANE (component)->ui_manager;
-}
-
-
-
-static void
-thunar_shortcuts_pane_set_ui_manager (ThunarComponent *component,
- GtkUIManager *ui_manager)
-{
- ThunarShortcutsPane *shortcuts_pane = THUNAR_SHORTCUTS_PANE (component);
- GError *error = NULL;
-
- /* disconnect from the previous UI manager */
- if (G_UNLIKELY (shortcuts_pane->ui_manager != NULL))
- {
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- /* drop our action group from the previous UI manager */
- gtk_ui_manager_remove_action_group (shortcuts_pane->ui_manager, shortcuts_pane->action_group);
-
- /* unmerge our ui controls from the previous UI manager */
- gtk_ui_manager_remove_ui (shortcuts_pane->ui_manager, shortcuts_pane->ui_merge_id);
-G_GNUC_END_IGNORE_DEPRECATIONS
-
- /* drop our reference on the previous UI manager */
- g_object_unref (G_OBJECT (shortcuts_pane->ui_manager));
- }
-
- /* activate the new UI manager */
- shortcuts_pane->ui_manager = ui_manager;
-
- /* connect to the new UI manager */
- if (G_LIKELY (ui_manager != NULL))
- {
- /* we keep a reference on the new manager */
- g_object_ref (G_OBJECT (ui_manager));
-
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- /* add our action group to the new manager */
- gtk_ui_manager_insert_action_group (ui_manager, shortcuts_pane->action_group, -1);
-
- /* merge our UI control items with the new manager */
- shortcuts_pane->ui_merge_id = gtk_ui_manager_add_ui_from_string (ui_manager, thunar_shortcuts_pane_ui, thunar_shortcuts_pane_ui_length, &error);
-G_GNUC_END_IGNORE_DEPRECATIONS
- if (G_UNLIKELY (shortcuts_pane->ui_merge_id == 0))
- {
- g_error ("Failed to merge ThunarShortcutsPane menus: %s", error->message);
- g_error_free (error);
- }
- }
-
- /* notify listeners */
- g_object_notify (G_OBJECT (shortcuts_pane), "ui-manager");
-}
-
-
-
-static void
-thunar_shortcuts_pane_action_shortcuts_add (GtkAction *action,
- ThunarShortcutsPane *shortcuts_pane)
+/**
+ * thunar_shortcuts_pane_add_shortcut:
+ * @shortcuts_pane : Instance of a #ThunarShortcutsPane
+ * @file : #ThunarFile for which a shortcut should be added
+ *
+ * Adds a shortcut for the passed #ThunarFile to the shortcuts_pane.
+ * Only folders will be considered.
+ **/
+void
+thunar_shortcuts_pane_add_shortcut (ThunarShortcutsPane *shortcuts_pane,
+ ThunarFile *file)
{
GtkTreeModel *model;
GtkTreeModel *child_model;
- GList *lp;
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
- _thunar_return_if_fail (GTK_IS_ACTION (action));
-G_GNUC_END_IGNORE_DEPRECATIONS
_thunar_return_if_fail (THUNAR_IS_SHORTCUTS_PANE (shortcuts_pane));
+ _thunar_return_if_fail (THUNAR_IS_FILE (file));
/* determine the shortcuts model for the view */
model = gtk_tree_view_get_model (GTK_TREE_VIEW (shortcuts_pane->view));
if (G_LIKELY (model != NULL))
{
- /* add all selected folders to the model */
child_model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER (model));
- for (lp = shortcuts_pane->selected_files; lp != NULL; lp = lp->next)
- if (G_LIKELY (thunar_file_is_directory (lp->data)))
- {
- /* append the folder to the shortcuts model */
- thunar_shortcuts_model_add (THUNAR_SHORTCUTS_MODEL (child_model), NULL, lp->data);
- }
-
- /* update the user interface to reflect the new action state */
- lp = thunar_g_file_list_copy (shortcuts_pane->selected_files);
- thunar_component_set_selected_files (THUNAR_COMPONENT (shortcuts_pane), lp);
- thunar_g_file_list_free (lp);
+ if (G_LIKELY (thunar_file_is_directory (file)))
+ {
+ /* append the folder to the shortcuts model */
+ thunar_shortcuts_model_add (THUNAR_SHORTCUTS_MODEL (child_model), NULL, file);
+ }
}
}