From ca9321f5991eecc2b7e5ff7412d0da1d54fc9f73 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 02:01:16 -0800 Subject: [PATCH 01/21] Fix g_free which should be g_object_unref in file browser https://github.com/GNOME/gedit/commit/331af4bdda8c200f19ed8ef8a05cb548084ba83f --- plugins/filebrowser/xed-file-browser-store.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index dbd083c..7942b42 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -3013,7 +3013,11 @@ mount_cb (GFile *file, g_object_unref (mount_info->operation); g_object_unref (mount_info->cancellable); - g_free (mount_info->virtual_root); + + if (mount_info->virtual_root) + { + g_object_unref (mount_info->virtual_root); + } g_free (mount_info); } From a1e94f2777fc5750b2a837871853dc81d628cdaa Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 02:14:07 -0800 Subject: [PATCH 02/21] Use slice allocator instead of g_new when appropriate https://github.com/GNOME/gedit/commit/a0b15be6fd680afba64bb09b16b1a7b8e6f31dc5 --- plugins/filebrowser/xed-file-browser-store.c | 12 ++++---- plugins/filebrowser/xed-file-browser-widget.c | 28 +++++++++++-------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index 7942b42..eae3e1e 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -2451,7 +2451,7 @@ async_node_free (AsyncNode *async) { g_object_unref (async->cancellable); g_slist_free (async->original_children); - g_free (async); + g_slice_free (AsyncNode, async); } static void @@ -2606,7 +2606,7 @@ model_load_directory (XedFileBrowserStore *model, dir->cancellable = g_cancellable_new (); - async = g_new (AsyncNode, 1); + async = g_slice_new (AsyncNode); async->dir = dir; async->cancellable = g_object_ref (dir->cancellable); async->original_children = g_slist_copy (dir->children); @@ -3019,7 +3019,7 @@ mount_cb (GFile *file, g_object_unref (mount_info->virtual_root); } - g_free (mount_info); + g_slice_free (MountInfo, mount_info); } static XedFileBrowserStoreResult @@ -3043,7 +3043,7 @@ model_mount_root (XedFileBrowserStore *model, /* Try to mount it */ FILE_BROWSER_NODE_DIR (model->priv->root)->cancellable = g_cancellable_new (); - mount_info = g_new(MountInfo, 1); + mount_info = g_slice_new (MountInfo); mount_info->model = model; mount_info->virtual_root = g_file_dup (virtual_root); @@ -3637,7 +3637,7 @@ async_data_free (AsyncData *data) data->model->priv->async_handles = g_slist_remove (data->model->priv->async_handles, data); } - g_free (data); + g_slice_free (AsyncData, data); } static gboolean @@ -3785,7 +3785,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model, files = g_list_prepend (files, g_object_ref (node->file)); } - data = g_new (AsyncData, 1); + data = g_slice_new (AsyncData); data->model = model; data->cancellable = g_cancellable_new (); diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 6d21fbd..8bfbf36 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -253,7 +253,7 @@ free_name_icon (gpointer data) if (item->icon) g_object_unref (item->icon); - g_free (item); + g_slice_free (NameIcon, item); } static FilterFunc * @@ -264,7 +264,7 @@ filter_func_new (XedFileBrowserWidget * obj, { FilterFunc *result; - result = g_new (FilterFunc, 1); + result = g_slice_new (FilterFunc); result->id = ++obj->priv->filter_id; result->func = func; @@ -282,7 +282,7 @@ location_free (Location * loc) if (loc->virtual_root) g_object_unref (loc->virtual_root); - g_free (loc); + g_slice_free (Location, loc); } static gboolean @@ -329,6 +329,12 @@ cancel_async_operation (XedFileBrowserWidget *widget) widget->priv->cancellable = NULL; } + static void +filter_func_free (FilterFunc *func) +{ + g_slice_free (FilterFunc, func); +} + static void xed_file_browser_widget_finalize (GObject * object) { @@ -344,7 +350,7 @@ xed_file_browser_widget_finalize (GObject * object) g_object_unref (obj->priv->bookmarks_store); g_object_unref (obj->priv->combo_model); - g_slist_foreach (obj->priv->filter_funcs, (GFunc) g_free, NULL); + g_slist_foreach (obj->priv->filter_funcs, (GFunc)filter_func_free, NULL); g_slist_free (obj->priv->filter_funcs); for (loc = obj->priv->locations; loc; loc = loc->next) @@ -487,7 +493,7 @@ xed_file_browser_widget_class_finalize (XedFileBrowserWidgetClass *klass) static void add_signal (XedFileBrowserWidget * obj, gpointer object, gulong id) { - SignalNode *node = g_new (SignalNode, 1); + SignalNode *node = g_slice_new (SignalNode); node->object = G_OBJECT (object); node->id = id; @@ -506,7 +512,7 @@ clear_signals (XedFileBrowserWidget * obj) node = (SignalNode *) (item->data); g_signal_handler_disconnect (node->object, node->id); - g_free (item->data); + g_slice_free (SignalNode, node); } g_slist_free (obj->priv->signal_pool); @@ -1078,7 +1084,7 @@ add_bookmark_hash (XedFileBrowserWidget * obj, XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, &name, -1); - item = g_new (NameIcon, 1); + item = g_slice_new (NameIcon); item->name = name; item->icon = pixbuf; @@ -1941,7 +1947,7 @@ xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, obj->priv->filter_funcs = g_slist_remove_link (obj->priv->filter_funcs, item); - g_free (func); + filter_func_free (func); break; } } @@ -2044,7 +2050,7 @@ async_data_new (XedFileBrowserWidget *widget) { AsyncData *ret; - ret = g_new (AsyncData, 1); + ret = g_slice_new (AsyncData); ret->widget = widget; cancel_async_operation (widget); @@ -2059,7 +2065,7 @@ static void async_free (AsyncData *async) { g_object_unref (async->cancellable); - g_free (async); + g_slice_free (AsyncData, async); } static void @@ -2516,7 +2522,7 @@ on_virtual_root_changed (XedFileBrowserStore * model, if (obj->priv->current_location) clear_next_locations (obj); - loc = g_new (Location, 1); + loc = g_slice_new (Location); loc->root = xed_file_browser_store_get_root (model); loc->virtual_root = g_object_ref (location); From 61bca3cc0f4da6cc18fd4ae74c1588835a97b774 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 04:04:08 -0800 Subject: [PATCH 03/21] xed-file-browser-widget: Clean up code styling --- plugins/filebrowser/xed-file-browser-widget.c | 1843 +++++++++-------- 1 file changed, 970 insertions(+), 873 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 8bfbf36..7d8a88a 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -160,83 +160,82 @@ struct _XedFileBrowserWidgetPrivate GdkCursor *busy_cursor; }; -static void set_enable_delete (XedFileBrowserWidget *obj, - gboolean enable); -static void on_model_set (GObject * gobject, - GParamSpec * arg1, - XedFileBrowserWidget * obj); -static void on_treeview_error (XedFileBrowserView * tree_view, - guint code, - gchar * message, - XedFileBrowserWidget * obj); -static void on_file_store_error (XedFileBrowserStore * store, - guint code, - gchar * message, - XedFileBrowserWidget * obj); -static gboolean on_file_store_no_trash (XedFileBrowserStore * store, - GList * files, - XedFileBrowserWidget * obj); -static void on_combo_changed (GtkComboBox * combo, - XedFileBrowserWidget * obj); -static gboolean on_treeview_popup_menu (XedFileBrowserView * treeview, - XedFileBrowserWidget * obj); -static gboolean on_treeview_button_press_event (XedFileBrowserView * treeview, - GdkEventButton * event, - XedFileBrowserWidget * obj); -static gboolean on_treeview_key_press_event (XedFileBrowserView * treeview, - GdkEventKey * event, - XedFileBrowserWidget * obj); -static void on_selection_changed (GtkTreeSelection * selection, - XedFileBrowserWidget * obj); +static void set_enable_delete (XedFileBrowserWidget *obj, + gboolean enable); +static void on_model_set (GObject *gobject, + GParamSpec *arg1, + XedFileBrowserWidget *obj); +static void on_treeview_error (XedFileBrowserView *tree_view, + guint code, + gchar *message, + XedFileBrowserWidget *obj); +static void on_file_store_error (XedFileBrowserStore *store, + guint code, + gchar *message, + XedFileBrowserWidget *obj); +static gboolean on_file_store_no_trash (XedFileBrowserStore *store, + GList *files, + XedFileBrowserWidget *obj); +static void on_combo_changed (GtkComboBox *combo, + XedFileBrowserWidget *obj); +static gboolean on_treeview_popup_menu (XedFileBrowserView *treeview, + XedFileBrowserWidget *obj); +static gboolean on_treeview_button_press_event (XedFileBrowserView *treeview, + GdkEventButton *event, + XedFileBrowserWidget *obj); +static gboolean on_treeview_key_press_event (XedFileBrowserView *treeview, + GdkEventKey *event, + XedFileBrowserWidget *obj); +static void on_selection_changed (GtkTreeSelection *selection, + XedFileBrowserWidget *obj); -static void on_virtual_root_changed (XedFileBrowserStore * model, - GParamSpec *param, - XedFileBrowserWidget * obj); +static void on_virtual_root_changed (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserWidget *obj); -static gboolean on_entry_filter_activate (XedFileBrowserWidget * obj); -static void on_location_jump_activate (GtkMenuItem * item, - XedFileBrowserWidget * obj); -static void on_bookmarks_row_changed (GtkTreeModel * model, - GtkTreePath * path, - GtkTreeIter * iter, - XedFileBrowserWidget * obj); -static void on_bookmarks_row_deleted (GtkTreeModel * model, - GtkTreePath * path, - XedFileBrowserWidget * obj); -static void on_filter_mode_changed (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserWidget * obj); -static void on_action_directory_previous (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_directory_next (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_directory_up (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_directory_new (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_file_open (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_file_new (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_file_rename (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_file_delete (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_file_move_to_trash (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_directory_refresh (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_directory_open (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_filter_hidden (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_filter_binary (GtkAction * action, - XedFileBrowserWidget * obj); -static void on_action_bookmark_open (GtkAction * action, - XedFileBrowserWidget * obj); +static gboolean on_entry_filter_activate (XedFileBrowserWidget *obj); +static void on_location_jump_activate (GtkMenuItem *item, + XedFileBrowserWidget *obj); +static void on_bookmarks_row_changed (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + XedFileBrowserWidget *obj); +static void on_bookmarks_row_deleted (GtkTreeModel *model, + GtkTreePath *path, + XedFileBrowserWidget *obj); +static void on_filter_mode_changed (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserWidget *obj); +static void on_action_directory_previous (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_directory_next (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_directory_up (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_directory_new (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_file_open (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_file_new (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_file_rename (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_file_delete (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_file_move_to_trash (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_directory_refresh (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_directory_open (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_filter_hidden (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_filter_binary (GtkAction *action, + XedFileBrowserWidget *obj); +static void on_action_bookmark_open (GtkAction *action, + XedFileBrowserWidget *obj); -G_DEFINE_DYNAMIC_TYPE (XedFileBrowserWidget, xed_file_browser_widget, - GTK_TYPE_BOX) +G_DEFINE_DYNAMIC_TYPE (XedFileBrowserWidget, xed_file_browser_widget, GTK_TYPE_BOX) static void free_name_icon (gpointer data) @@ -244,23 +243,27 @@ free_name_icon (gpointer data) NameIcon * item; if (data == NULL) + { return; + } item = (NameIcon *)(data); g_free (item->name); if (item->icon) + { g_object_unref (item->icon); + } g_slice_free (NameIcon, item); } static FilterFunc * -filter_func_new (XedFileBrowserWidget * obj, - XedFileBrowserWidgetFilterFunc func, - gpointer user_data, - GDestroyNotify notify) +filter_func_new (XedFileBrowserWidget *obj, + XedFileBrowserWidgetFilterFunc func, + gpointer user_data, + GDestroyNotify notify) { FilterFunc *result; @@ -274,34 +277,43 @@ filter_func_new (XedFileBrowserWidget * obj, } static void -location_free (Location * loc) +location_free (Location *loc) { if (loc->root) + { g_object_unref (loc->root); + } if (loc->virtual_root) + { g_object_unref (loc->virtual_root); + } g_slice_free (Location, loc); } static gboolean -combo_find_by_id (XedFileBrowserWidget * obj, guint id, - GtkTreeIter * iter) +combo_find_by_id (XedFileBrowserWidget *obj, + guint id, + GtkTreeIter *iter) { guint checkid; GtkTreeModel *model = GTK_TREE_MODEL (obj->priv->combo_model); if (iter == NULL) + { return FALSE; + } - if (gtk_tree_model_get_iter_first (model, iter)) { + if (gtk_tree_model_get_iter_first (model, iter)) + { do { - gtk_tree_model_get (model, iter, COLUMN_ID, - &checkid, -1); + gtk_tree_model_get (model, iter, COLUMN_ID, &checkid, -1); if (checkid == id) + { return TRUE; + } } while (gtk_tree_model_iter_next (model, iter)); } @@ -309,19 +321,23 @@ combo_find_by_id (XedFileBrowserWidget * obj, guint id, } static void -remove_path_items (XedFileBrowserWidget * obj) +remove_path_items (XedFileBrowserWidget *obj) { GtkTreeIter iter; while (combo_find_by_id (obj, PATH_ID, &iter)) + { gtk_tree_store_remove (obj->priv->combo_model, &iter); + } } static void cancel_async_operation (XedFileBrowserWidget *widget) { if (!widget->priv->cancellable) + { return; + } g_cancellable_cancel (widget->priv->cancellable); g_object_unref (widget->priv->cancellable); @@ -336,14 +352,13 @@ filter_func_free (FilterFunc *func) } static void -xed_file_browser_widget_finalize (GObject * object) +xed_file_browser_widget_finalize (GObject *object) { XedFileBrowserWidget *obj = XED_FILE_BROWSER_WIDGET (object); GList *loc; remove_path_items (obj); - xed_file_browser_store_set_filter_func (obj->priv->file_store, - NULL, NULL); + xed_file_browser_store_set_filter_func (obj->priv->file_store, NULL, NULL); g_object_unref (obj->priv->manager); g_object_unref (obj->priv->file_store); @@ -354,10 +369,14 @@ xed_file_browser_widget_finalize (GObject * object) g_slist_free (obj->priv->filter_funcs); for (loc = obj->priv->locations; loc; loc = loc->next) + { location_free ((Location *) (loc->data)); + } if (obj->priv->current_location_menu_item) + { g_object_unref (obj->priv->current_location_menu_item); + } g_list_free (obj->priv->locations); @@ -372,9 +391,9 @@ xed_file_browser_widget_finalize (GObject * object) static void xed_file_browser_widget_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) + guint prop_id, + GValue *value, + GParamSpec *pspec) { XedFileBrowserWidget *obj = XED_FILE_BROWSER_WIDGET (object); @@ -394,17 +413,16 @@ xed_file_browser_widget_get_property (GObject *object, static void xed_file_browser_widget_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) + guint prop_id, + const GValue *value, + GParamSpec *pspec) { XedFileBrowserWidget *obj = XED_FILE_BROWSER_WIDGET (object); switch (prop_id) { case PROP_FILTER_PATTERN: - xed_file_browser_widget_set_filter_pattern (obj, - g_value_get_string (value)); + xed_file_browser_widget_set_filter_pattern (obj, g_value_get_string (value)); break; case PROP_ENABLE_DELETE: set_enable_delete (obj, g_value_get_boolean (value)); @@ -416,7 +434,7 @@ xed_file_browser_widget_set_property (GObject *object, } static void -xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass) +xed_file_browser_widget_class_init (XedFileBrowserWidgetClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); @@ -426,34 +444,35 @@ xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass) object_class->set_property = xed_file_browser_widget_set_property; g_object_class_install_property (object_class, PROP_FILTER_PATTERN, - g_param_spec_string ("filter-pattern", - "Filter Pattern", - "The filter pattern", - NULL, - G_PARAM_READWRITE)); + g_param_spec_string ("filter-pattern", + "Filter Pattern", + "The filter pattern", + NULL, + G_PARAM_READWRITE)); g_object_class_install_property (object_class, PROP_ENABLE_DELETE, - g_param_spec_boolean ("enable-delete", - "Enable delete", - "Enable permanently deleting items", - TRUE, - G_PARAM_READWRITE | - G_PARAM_CONSTRUCT)); + g_param_spec_boolean ("enable-delete", + "Enable delete", + "Enable permanently deleting items", + TRUE, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT)); signals[LOCATION_ACTIVATED] = g_signal_new ("location-activated", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserWidgetClass, - location_activated), NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, - G_TYPE_FILE); + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserWidgetClass, + location_activated), NULL, NULL, + g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, + G_TYPE_FILE); + signals[ERROR] = g_signal_new ("error", G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (XedFileBrowserWidgetClass, - error), NULL, NULL, - xed_file_browser_marshal_VOID__UINT_STRING, - G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (XedFileBrowserWidgetClass, + error), NULL, NULL, + xed_file_browser_marshal_VOID__UINT_STRING, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_STRING); signals[CONFIRM_DELETE] = g_signal_new ("confirm-delete", G_OBJECT_CLASS_TYPE (object_class), @@ -480,8 +499,7 @@ xed_file_browser_widget_class_init (XedFileBrowserWidgetClass * klass) 1, G_TYPE_POINTER); - g_type_class_add_private (object_class, - sizeof (XedFileBrowserWidgetPrivate)); + g_type_class_add_private (object_class, sizeof (XedFileBrowserWidgetPrivate)); } static void @@ -491,24 +509,26 @@ xed_file_browser_widget_class_finalize (XedFileBrowserWidgetClass *klass) } static void -add_signal (XedFileBrowserWidget * obj, gpointer object, gulong id) +add_signal (XedFileBrowserWidget *obj, + gpointer object, + gulong id) { SignalNode *node = g_slice_new (SignalNode); node->object = G_OBJECT (object); node->id = id; - obj->priv->signal_pool = - g_slist_prepend (obj->priv->signal_pool, node); + obj->priv->signal_pool = g_slist_prepend (obj->priv->signal_pool, node); } static void -clear_signals (XedFileBrowserWidget * obj) +clear_signals (XedFileBrowserWidget *obj) { GSList *item; SignalNode *node; - for (item = obj->priv->signal_pool; item; item = item->next) { + for (item = obj->priv->signal_pool; item; item = item->next) + { node = (SignalNode *) (item->data); g_signal_handler_disconnect (node->object, node->id); @@ -520,7 +540,9 @@ clear_signals (XedFileBrowserWidget * obj) } static gboolean -separator_func (GtkTreeModel * model, GtkTreeIter * iter, gpointer data) +separator_func (GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) { guint id; @@ -530,16 +552,20 @@ separator_func (GtkTreeModel * model, GtkTreeIter * iter, gpointer data) } static gboolean -get_from_bookmark_file (XedFileBrowserWidget * obj, GFile * file, - gchar ** name, GdkPixbuf ** icon) +get_from_bookmark_file (XedFileBrowserWidget *obj, + GFile *file, + gchar **name, + GdkPixbuf **icon) { gpointer data; - NameIcon * item; + NameIcon *item; data = g_hash_table_lookup (obj->priv->bookmarks_hash, file); if (data == NULL) + { return FALSE; + } item = (NameIcon *)data; @@ -555,17 +581,18 @@ get_from_bookmark_file (XedFileBrowserWidget * obj, GFile * file, } static void -insert_path_item (XedFileBrowserWidget * obj, - GFile * file, - GtkTreeIter * after, - GtkTreeIter * iter, - guint indent) +insert_path_item (XedFileBrowserWidget *obj, + GFile *file, + GtkTreeIter *after, + GtkTreeIter *iter, + guint indent) { - gchar * unescape; - GdkPixbuf * icon = NULL; + gchar *unescape; + GdkPixbuf *icon = NULL; /* Try to get the icon and name from the bookmarks hash */ - if (!get_from_bookmark_file (obj, file, &unescape, &icon)) { + if (!get_from_bookmark_file (obj, file, &unescape, &icon)) + { /* It's not a bookmark, fetch the name and the icon ourselves */ unescape = xed_file_browser_utils_file_basename (file); @@ -573,8 +600,7 @@ insert_path_item (XedFileBrowserWidget * obj, icon = xed_file_browser_utils_pixbuf_from_file (file, GTK_ICON_SIZE_MENU); } - gtk_tree_store_insert_after (obj->priv->combo_model, iter, NULL, - after); + gtk_tree_store_insert_after (obj->priv->combo_model, iter, NULL, after); gtk_tree_store_set (obj->priv->combo_model, iter, @@ -582,50 +608,58 @@ insert_path_item (XedFileBrowserWidget * obj, COLUMN_ICON, icon, COLUMN_NAME, unescape, COLUMN_FILE, file, - COLUMN_ID, PATH_ID, - -1); + COLUMN_ID, PATH_ID, + -1); if (icon) + { g_object_unref (icon); + } g_free (unescape); } static void -insert_separator_item (XedFileBrowserWidget * obj) +insert_separator_item (XedFileBrowserWidget *obj) { GtkTreeIter iter; gtk_tree_store_insert (obj->priv->combo_model, &iter, NULL, 1); gtk_tree_store_set (obj->priv->combo_model, &iter, - COLUMN_ICON, NULL, - COLUMN_NAME, NULL, - COLUMN_ID, SEPARATOR_ID, -1); + COLUMN_ICON, NULL, + COLUMN_NAME, NULL, + COLUMN_ID, SEPARATOR_ID, -1); } static void -combo_set_active_by_id (XedFileBrowserWidget * obj, guint id) +combo_set_active_by_id (XedFileBrowserWidget *obj, + guint id) { GtkTreeIter iter; if (combo_find_by_id (obj, id, &iter)) - gtk_combo_box_set_active_iter (GTK_COMBO_BOX - (obj->priv->combo), &iter); + { + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (obj->priv->combo), &iter); + } } static guint -uri_num_parents (GFile * from, GFile * to) +uri_num_parents (GFile *from, + GFile *to) { /* Determine the number of 'levels' to get from #from to #to. */ guint parents = 0; - GFile * parent; + GFile *parent; if (from == NULL) + { return 0; + } g_object_ref (from); - while ((parent = g_file_get_parent (from)) && !(to && g_file_equal (from, to))) { + while ((parent = g_file_get_parent (from)) && !(to && g_file_equal (from, to))) + { g_object_unref (from); from = parent; @@ -637,16 +671,17 @@ uri_num_parents (GFile * from, GFile * to) } static void -insert_location_path (XedFileBrowserWidget * obj) +insert_location_path (XedFileBrowserWidget *obj) { Location *loc; GFile *current = NULL; - GFile * tmp; + GFile *tmp; GtkTreeIter separator; GtkTreeIter iter; guint indent; - if (!obj->priv->current_location) { + if (!obj->priv->current_location) + { g_message ("insert_location_path: no current location"); return; } @@ -658,39 +693,40 @@ insert_location_path (XedFileBrowserWidget * obj) indent = uri_num_parents (loc->virtual_root, loc->root); - while (current != NULL) { + while (current != NULL) + { insert_path_item (obj, current, &separator, &iter, indent--); - if (current == loc->virtual_root) { - g_signal_handlers_block_by_func (obj->priv->combo, - on_combo_changed, - obj); - gtk_combo_box_set_active_iter (GTK_COMBO_BOX - (obj->priv->combo), - &iter); - g_signal_handlers_unblock_by_func (obj->priv-> - combo, - on_combo_changed, - obj); + if (current == loc->virtual_root) + { + g_signal_handlers_block_by_func (obj->priv->combo, on_combo_changed, obj); + gtk_combo_box_set_active_iter (GTK_COMBO_BOX (obj->priv->combo), &iter); + g_signal_handlers_unblock_by_func (obj->priv->combo, on_combo_changed, obj); } - if (g_file_equal (current, loc->root) || !xed_utils_file_has_parent (current)) { + if (g_file_equal (current, loc->root) || !xed_utils_file_has_parent (current)) + { if (current != loc->virtual_root) + { g_object_unref (current); + } break; } tmp = g_file_get_parent (current); if (current != loc->virtual_root) + { g_object_unref (current); + } current = tmp; } } static void -check_current_item (XedFileBrowserWidget * obj, gboolean show_path) +check_current_item (XedFileBrowserWidget *obj, + gboolean show_path) { GtkTreeIter separator; gboolean has_sep; @@ -698,17 +734,23 @@ check_current_item (XedFileBrowserWidget * obj, gboolean show_path) remove_path_items (obj); has_sep = combo_find_by_id (obj, SEPARATOR_ID, &separator); - if (show_path) { + if (show_path) + { if (!has_sep) + { insert_separator_item (obj); + } insert_location_path (obj); - } else if (has_sep) + } + else if (has_sep) + { gtk_tree_store_remove (obj->priv->combo_model, &separator); + } } static void -fill_combo_model (XedFileBrowserWidget * obj) +fill_combo_model (XedFileBrowserWidget *obj) { GtkTreeStore *store = obj->priv->combo_model; GtkTreeIter iter; @@ -718,31 +760,33 @@ fill_combo_model (XedFileBrowserWidget * obj) gtk_tree_store_append (store, &iter, NULL); gtk_tree_store_set (store, &iter, - COLUMN_ICON, icon, - COLUMN_NAME, _("Bookmarks"), - COLUMN_ID, BOOKMARKS_ID, -1); + COLUMN_ICON, icon, + COLUMN_NAME, _("Bookmarks"), + COLUMN_ID, BOOKMARKS_ID, -1); g_object_unref (icon); - gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (obj->priv->combo), - separator_func, obj, NULL); + gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (obj->priv->combo), separator_func, obj, NULL); gtk_combo_box_set_active (GTK_COMBO_BOX (obj->priv->combo), 0); } static void -indent_cell_data_func (GtkCellLayout * cell_layout, - GtkCellRenderer * cell, - GtkTreeModel * model, - GtkTreeIter * iter, - gpointer data) +indent_cell_data_func (GtkCellLayout *cell_layout, + GtkCellRenderer *cell, + GtkTreeModel *model, + GtkTreeIter *iter, + gpointer data) { - gchar * indent; + gchar *indent; guint num; gtk_tree_model_get (model, iter, COLUMN_INDENT, &num, -1); if (num == 0) + { g_object_set (cell, "text", "", NULL); - else { + } + else + { indent = g_strnfill (num * 2, ' '); g_object_set (cell, "text", indent, NULL); @@ -751,49 +795,38 @@ indent_cell_data_func (GtkCellLayout * cell_layout, } static void -create_combo (XedFileBrowserWidget * obj) +create_combo (XedFileBrowserWidget *obj) { GtkCellRenderer *renderer; obj->priv->combo_model = gtk_tree_store_new (N_COLUMNS, - G_TYPE_UINT, - GDK_TYPE_PIXBUF, - G_TYPE_STRING, - G_TYPE_FILE, - G_TYPE_UINT); - obj->priv->combo = - gtk_combo_box_new_with_model (GTK_TREE_MODEL - (obj->priv->combo_model)); + G_TYPE_UINT, + GDK_TYPE_PIXBUF, + G_TYPE_STRING, + G_TYPE_FILE, + G_TYPE_UINT); + obj->priv->combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (obj->priv->combo_model)); renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, FALSE); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT - (obj->priv->combo), renderer, - indent_cell_data_func, obj, NULL); - + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), renderer, FALSE); + gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (obj->priv->combo), + renderer, indent_cell_data_func, obj, NULL); renderer = gtk_cell_renderer_pixbuf_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, FALSE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, "pixbuf", COLUMN_ICON); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), renderer, FALSE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (obj->priv->combo), renderer, "pixbuf", COLUMN_ICON); renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, TRUE); - gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, "text", COLUMN_NAME); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), renderer, TRUE); + gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (obj->priv->combo), renderer, "text", COLUMN_NAME); - g_object_set (renderer, "ellipsize-set", TRUE, - "ellipsize", PANGO_ELLIPSIZE_END, NULL); + g_object_set (renderer, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - gtk_box_pack_start (GTK_BOX (obj), GTK_WIDGET (obj->priv->combo), - FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (obj), GTK_WIDGET (obj->priv->combo), FALSE, FALSE, 0); fill_combo_model (obj); g_signal_connect (obj->priv->combo, "changed", - G_CALLBACK (on_combo_changed), obj); + G_CALLBACK (on_combo_changed), obj); gtk_widget_show (obj->priv->combo); } @@ -864,8 +897,8 @@ static const GtkActionEntry bookmark_actions[] = }; static void -create_toolbar (XedFileBrowserWidget * obj, - const gchar *data_dir) +create_toolbar (XedFileBrowserWidget *obj, + const gchar *data_dir) { GtkUIManager *manager; GError *error = NULL; @@ -883,9 +916,9 @@ create_toolbar (XedFileBrowserWidget * obj, g_free (ui_file); - if (error != NULL) { - g_warning ("Error in adding ui from file %s: %s", - XML_UI_FILE, error->message); + if (error != NULL) + { + g_warning ("Error in adding ui from file %s: %s", XML_UI_FILE, error->message); g_error_free (error); return; } @@ -893,84 +926,82 @@ create_toolbar (XedFileBrowserWidget * obj, action_group = gtk_action_group_new ("FileBrowserWidgetActionGroupToplevel"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - toplevel_actions, - G_N_ELEMENTS (toplevel_actions), - obj); + toplevel_actions, + G_N_ELEMENTS (toplevel_actions), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); action_group = gtk_action_group_new ("FileBrowserWidgetActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions, - G_N_ELEMENTS (tree_actions), - obj); + tree_actions, + G_N_ELEMENTS (tree_actions), + obj); gtk_action_group_add_toggle_actions (action_group, - tree_actions_toggle, - G_N_ELEMENTS (tree_actions_toggle), - obj); + tree_actions_toggle, + G_N_ELEMENTS (tree_actions_toggle), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetSelectionActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions_selection, - G_N_ELEMENTS (tree_actions_selection), - obj); + tree_actions_selection, + G_N_ELEMENTS (tree_actions_selection), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group_selection = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetFileSelectionActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions_file_selection, - G_N_ELEMENTS (tree_actions_file_selection), - obj); + tree_actions_file_selection, + G_N_ELEMENTS (tree_actions_file_selection), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group_file_selection = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetSingleSelectionActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions_single_selection, - G_N_ELEMENTS (tree_actions_single_selection), - obj); + tree_actions_single_selection, + G_N_ELEMENTS (tree_actions_single_selection), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group_single_selection = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetSingleMostSelectionActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions_single_most_selection, - G_N_ELEMENTS (tree_actions_single_most_selection), - obj); + tree_actions_single_most_selection, + G_N_ELEMENTS (tree_actions_single_most_selection), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group_single_most_selection = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetSensitiveActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - tree_actions_sensitive, - G_N_ELEMENTS (tree_actions_sensitive), - obj); + tree_actions_sensitive, + G_N_ELEMENTS (tree_actions_sensitive), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->action_group_sensitive = action_group; action_group = gtk_action_group_new ("FileBrowserWidgetBookmarkActionGroup"); gtk_action_group_set_translation_domain (action_group, NULL); gtk_action_group_add_actions (action_group, - bookmark_actions, - G_N_ELEMENTS (bookmark_actions), - obj); + bookmark_actions, + G_N_ELEMENTS (bookmark_actions), + obj); gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->bookmark_action_group = action_group; - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, - "DirectoryPrevious"); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); gtk_action_set_sensitive (action, FALSE); - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, - "DirectoryNext"); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); gtk_action_set_sensitive (action, FALSE); toolbar = gtk_ui_manager_get_widget (manager, "/ToolBar"); @@ -982,19 +1013,17 @@ create_toolbar (XedFileBrowserWidget * obj, gtk_widget_show (obj->priv->location_previous_menu); widget = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK)); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), - obj->priv->location_previous_menu); + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), obj->priv->location_previous_menu); g_object_set (widget, "label", _("Previous location"), NULL); - gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), - _("Go to previous location")); - gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), - _("Go to a previously opened location")); + gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), _("Go to previous location")); + gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), _("Go to a previously opened location")); - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, - "DirectoryPrevious"); - g_object_set (action, "is_important", TRUE, "short_label", - _("Previous location"), NULL); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); + g_object_set (action, + "is_important", TRUE, + "short_label", _("Previous location"), + NULL); gtk_activatable_set_related_action (GTK_ACTIVATABLE (widget), action); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (widget), 0); @@ -1003,19 +1032,17 @@ create_toolbar (XedFileBrowserWidget * obj, gtk_widget_show (obj->priv->location_next_menu); widget = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD)); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), - obj->priv->location_next_menu); + gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), obj->priv->location_next_menu); g_object_set (widget, "label", _("Next location"), NULL); - gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), - _("Go to next location")); - gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), - _("Go to a previously opened location")); + gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), _("Go to next location")); + gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), _("Go to a previously opened location")); - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, - "DirectoryNext"); - g_object_set (action, "is_important", TRUE, "short_label", - _("Previous location"), NULL); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); + g_object_set (action, + "is_important", TRUE, + "short_label", _("Previous location"), + NULL); gtk_activatable_set_related_action (GTK_ACTIVATABLE (widget), action); gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (widget), 1); @@ -1027,74 +1054,76 @@ create_toolbar (XedFileBrowserWidget * obj, static void set_enable_delete (XedFileBrowserWidget *obj, - gboolean enable) + gboolean enable) { GtkAction *action; obj->priv->enable_delete = enable; if (obj->priv->action_group_selection == NULL) + { return; + } - action = - gtk_action_group_get_action (obj->priv->action_group_selection, - "FileDelete"); + action = gtk_action_group_get_action (obj->priv->action_group_selection, "FileDelete"); g_object_set (action, "visible", enable, "sensitive", enable, NULL); } static gboolean -filter_real (XedFileBrowserStore * model, GtkTreeIter * iter, - XedFileBrowserWidget * obj) +filter_real (XedFileBrowserStore *model, + GtkTreeIter *iter, + XedFileBrowserWidget *obj) { GSList *item; FilterFunc *func; - for (item = obj->priv->filter_funcs; item; item = item->next) { + for (item = obj->priv->filter_funcs; item; item = item->next) + { func = (FilterFunc *) (item->data); if (!func->func (obj, model, iter, func->user_data)) + { return FALSE; + } } return TRUE; } static void -add_bookmark_hash (XedFileBrowserWidget * obj, - GtkTreeIter * iter) +add_bookmark_hash (XedFileBrowserWidget *obj, + GtkTreeIter *iter) { GtkTreeModel *model; - GdkPixbuf * pixbuf; - gchar * name; - GFile * location; - NameIcon * item; + GdkPixbuf *pixbuf; + gchar *name; + GFile *location; + NameIcon *item; model = GTK_TREE_MODEL (obj->priv->bookmarks_store); - location = xed_file_bookmarks_store_get_location (obj->priv-> - bookmarks_store, - iter); + location = xed_file_bookmarks_store_get_location (obj->priv->bookmarks_store, iter); if (location == NULL) + { return; + } gtk_tree_model_get (model, iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_ICON, - &pixbuf, - XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, - &name, -1); + XED_FILE_BOOKMARKS_STORE_COLUMN_ICON, + &pixbuf, + XED_FILE_BOOKMARKS_STORE_COLUMN_NAME, + &name, -1); item = g_slice_new (NameIcon); item->name = name; item->icon = pixbuf; - g_hash_table_insert (obj->priv->bookmarks_hash, - location, - item); + g_hash_table_insert (obj->priv->bookmarks_hash, location, item); } static void -init_bookmarks_hash (XedFileBrowserWidget * obj) +init_bookmarks_hash (XedFileBrowserWidget *obj) { GtkTreeIter iter; GtkTreeModel *model; @@ -1102,42 +1131,44 @@ init_bookmarks_hash (XedFileBrowserWidget * obj) model = GTK_TREE_MODEL (obj->priv->bookmarks_store); if (!gtk_tree_model_get_iter_first (model, &iter)) + { return; + } - do { + do + { add_bookmark_hash (obj, &iter); } while (gtk_tree_model_iter_next (model, &iter)); - g_signal_connect (obj->priv->bookmarks_store, - "row-changed", - G_CALLBACK (on_bookmarks_row_changed), - obj); + g_signal_connect (obj->priv->bookmarks_store, "row-changed", + G_CALLBACK (on_bookmarks_row_changed), obj); - g_signal_connect (obj->priv->bookmarks_store, - "row-deleted", - G_CALLBACK (on_bookmarks_row_deleted), - obj); + g_signal_connect (obj->priv->bookmarks_store, "row-deleted", + G_CALLBACK (on_bookmarks_row_deleted), obj); } static void on_begin_loading (XedFileBrowserStore *model, - GtkTreeIter *iter, - XedFileBrowserWidget *obj) + GtkTreeIter *iter, + XedFileBrowserWidget *obj) { if (!GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (obj->priv->treeview)))) + { return; + } - gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (obj)), - obj->priv->busy_cursor); + gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (obj)), obj->priv->busy_cursor); } static void on_end_loading (XedFileBrowserStore *model, - GtkTreeIter *iter, - XedFileBrowserWidget *obj) + GtkTreeIter *iter, + XedFileBrowserWidget *obj) { if (!GDK_IS_WINDOW (gtk_widget_get_window (GTK_WIDGET (obj->priv->treeview)))) + { return; + } gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (obj)), NULL); } @@ -1149,59 +1180,51 @@ create_tree (XedFileBrowserWidget * obj) obj->priv->file_store = xed_file_browser_store_new (NULL); obj->priv->bookmarks_store = xed_file_bookmarks_store_new (); - obj->priv->treeview = - XED_FILE_BROWSER_VIEW (xed_file_browser_view_new ()); + obj->priv->treeview = XED_FILE_BROWSER_VIEW (xed_file_browser_view_new ()); xed_file_browser_view_set_restore_expand_state (obj->priv->treeview, TRUE); xed_file_browser_store_set_filter_mode (obj->priv->file_store, - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN - | - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY); + XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN | + XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY); xed_file_browser_store_set_filter_func (obj->priv->file_store, - (XedFileBrowserStoreFilterFunc) - filter_real, obj); + (XedFileBrowserStoreFilterFunc) + filter_real, obj); sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), - GTK_SHADOW_ETCHED_IN); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_container_add (GTK_CONTAINER (sw), - GTK_WIDGET (obj->priv->treeview)); + gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (obj->priv->treeview)); gtk_box_pack_start (GTK_BOX (obj), sw, TRUE, TRUE, 0); g_signal_connect (obj->priv->treeview, "notify::model", - G_CALLBACK (on_model_set), obj); + G_CALLBACK (on_model_set), obj); g_signal_connect (obj->priv->treeview, "error", - G_CALLBACK (on_treeview_error), obj); + G_CALLBACK (on_treeview_error), obj); g_signal_connect (obj->priv->treeview, "popup-menu", - G_CALLBACK (on_treeview_popup_menu), obj); + G_CALLBACK (on_treeview_popup_menu), obj); g_signal_connect (obj->priv->treeview, "button-press-event", - G_CALLBACK (on_treeview_button_press_event), - obj); + G_CALLBACK (on_treeview_button_press_event), obj); g_signal_connect (obj->priv->treeview, "key-press-event", - G_CALLBACK (on_treeview_key_press_event), obj); + G_CALLBACK (on_treeview_key_press_event), obj); - g_signal_connect (gtk_tree_view_get_selection - (GTK_TREE_VIEW (obj->priv->treeview)), "changed", - G_CALLBACK (on_selection_changed), obj); + g_signal_connect (gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)), "changed", + G_CALLBACK (on_selection_changed), obj); g_signal_connect (obj->priv->file_store, "notify::filter-mode", - G_CALLBACK (on_filter_mode_changed), obj); + G_CALLBACK (on_filter_mode_changed), obj); g_signal_connect (obj->priv->file_store, "notify::virtual-root", - G_CALLBACK (on_virtual_root_changed), obj); + G_CALLBACK (on_virtual_root_changed), obj); g_signal_connect (obj->priv->file_store, "begin-loading", - G_CALLBACK (on_begin_loading), obj); + G_CALLBACK (on_begin_loading), obj); g_signal_connect (obj->priv->file_store, "end-loading", - G_CALLBACK (on_end_loading), obj); + G_CALLBACK (on_end_loading), obj); g_signal_connect (obj->priv->file_store, "error", - G_CALLBACK (on_file_store_error), obj); + G_CALLBACK (on_file_store_error), obj); init_bookmarks_hash (obj); @@ -1210,7 +1233,7 @@ create_tree (XedFileBrowserWidget * obj) } static void -create_filter (XedFileBrowserWidget * obj) +create_filter (XedFileBrowserWidget *obj) { GtkWidget *expander; GtkWidget *vbox; @@ -1231,29 +1254,26 @@ create_filter (XedFileBrowserWidget * obj) obj->priv->filter_entry = entry; g_signal_connect_swapped (entry, "activate", - G_CALLBACK (on_entry_filter_activate), - obj); + G_CALLBACK (on_entry_filter_activate), obj); g_signal_connect_swapped (entry, "focus_out_event", - G_CALLBACK (on_entry_filter_activate), - obj); + G_CALLBACK (on_entry_filter_activate), obj); gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, FALSE, 0); gtk_container_add (GTK_CONTAINER (expander), vbox); } static void -xed_file_browser_widget_init (XedFileBrowserWidget * obj) +xed_file_browser_widget_init (XedFileBrowserWidget *obj) { obj->priv = XED_FILE_BROWSER_WIDGET_GET_PRIVATE (obj); obj->priv->bookmarks_hash = g_hash_table_new_full (g_file_hash, - (GEqualFunc)g_file_equal, - g_object_unref, - free_name_icon); + (GEqualFunc)g_file_equal, + g_object_unref, + free_name_icon); gtk_box_set_spacing (GTK_BOX (obj), 3); - gtk_orientable_set_orientation (GTK_ORIENTABLE (obj), - GTK_ORIENTATION_VERTICAL); + gtk_orientable_set_orientation (GTK_ORIENTABLE (obj), GTK_ORIENTATION_VERTICAL); obj->priv->busy_cursor = gdk_cursor_new (GDK_WATCH); } @@ -1261,50 +1281,39 @@ xed_file_browser_widget_init (XedFileBrowserWidget * obj) /* Private */ static void -update_sensitivity (XedFileBrowserWidget * obj) +update_sensitivity (XedFileBrowserWidget *obj) { - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); GtkAction *action; gint mode; - if (XED_IS_FILE_BROWSER_STORE (model)) { - gtk_action_group_set_sensitive (obj->priv->action_group, - TRUE); - gtk_action_group_set_sensitive (obj->priv->bookmark_action_group, - FALSE); + if (XED_IS_FILE_BROWSER_STORE (model)) + { + gtk_action_group_set_sensitive (obj->priv->action_group, TRUE); + gtk_action_group_set_sensitive (obj->priv->bookmark_action_group, FALSE); - mode = - xed_file_browser_store_get_filter_mode - (XED_FILE_BROWSER_STORE (model)); + mode = xed_file_browser_store_get_filter_mode (XED_FILE_BROWSER_STORE (model)); - action = - gtk_action_group_get_action (obj->priv->action_group, - "FilterHidden"); + action = gtk_action_group_get_action (obj->priv->action_group, "FilterHidden"); gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), - !(mode & - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN)); - } else if (XED_IS_FILE_BOOKMARKS_STORE (model)) { - gtk_action_group_set_sensitive (obj->priv->action_group, - FALSE); - gtk_action_group_set_sensitive (obj->priv->bookmark_action_group, - TRUE); + !(mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN)); + } + else if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { + gtk_action_group_set_sensitive (obj->priv->action_group, FALSE); + gtk_action_group_set_sensitive (obj->priv->bookmark_action_group, TRUE); /* Set the filter toggle to normal up state, just for visual pleasure */ - action = - gtk_action_group_get_action (obj->priv->action_group, - "FilterHidden"); - gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), - FALSE); + action = gtk_action_group_get_action (obj->priv->action_group, "FilterHidden"); + gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), FALSE); } - on_selection_changed (gtk_tree_view_get_selection - (GTK_TREE_VIEW (obj->priv->treeview)), obj); + on_selection_changed (gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)), obj); } static gboolean xed_file_browser_widget_get_first_selected (XedFileBrowserWidget *obj, - GtkTreeIter *iter) + GtkTreeIter *iter) { GtkTreeSelection *selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); GtkTreeModel *model; @@ -1312,7 +1321,9 @@ xed_file_browser_widget_get_first_selected (XedFileBrowserWidget *obj, gboolean result; if (!rows) + { return FALSE; + } result = gtk_tree_model_get_iter(model, iter, (GtkTreePath *)(rows->data)); @@ -1323,24 +1334,34 @@ xed_file_browser_widget_get_first_selected (XedFileBrowserWidget *obj, } static gboolean -popup_menu (XedFileBrowserWidget * obj, GdkEventButton * event, GtkTreeModel * model) +popup_menu (XedFileBrowserWidget *obj, + GdkEventButton *event, + GtkTreeModel *model) { GtkWidget *menu; if (XED_IS_FILE_BROWSER_STORE (model)) + { menu = gtk_ui_manager_get_widget (obj->priv->manager, "/FilePopup"); + } else if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { menu = gtk_ui_manager_get_widget (obj->priv->manager, "/BookmarkPopup"); + } else + { return FALSE; + } g_return_val_if_fail (menu != NULL, FALSE); - if (event != NULL) { + if (event != NULL) + { GtkTreeSelection *selection; selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); - if (gtk_tree_selection_count_selected_rows (selection) <= 1) { + if (gtk_tree_selection_count_selected_rows (selection) <= 1) + { GtkTreePath *path; if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (obj->priv->treeview), @@ -1353,13 +1374,14 @@ popup_menu (XedFileBrowserWidget * obj, GdkEventButton * event, GtkTreeModel * m } } - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, - event->button, event->time); - } else { + gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); + } + else + { gtk_menu_popup (GTK_MENU (menu), NULL, NULL, - xed_utils_menu_position_under_tree_view, - obj->priv->treeview, 0, - gtk_get_current_event_time ()); + xed_utils_menu_position_under_tree_view, + obj->priv->treeview, 0, + gtk_get_current_event_time ()); gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE); } @@ -1367,27 +1389,33 @@ popup_menu (XedFileBrowserWidget * obj, GdkEventButton * event, GtkTreeModel * m } static gboolean -filter_glob (XedFileBrowserWidget * obj, XedFileBrowserStore * store, - GtkTreeIter * iter, gpointer user_data) +filter_glob (XedFileBrowserWidget *obj, + XedFileBrowserStore *store, + GtkTreeIter *iter, + gpointer user_data) { gchar *name; gboolean result; guint flags; if (obj->priv->filter_pattern == NULL) + { return TRUE; + } gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_NAME, &name, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + XED_FILE_BROWSER_STORE_COLUMN_NAME, &name, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); if (FILE_IS_DIR (flags) || FILE_IS_DUMMY (flags)) + { result = TRUE; + } else - result = - g_pattern_match_string (obj->priv->filter_pattern, - name); + { + result = g_pattern_match_string (obj->priv->filter_pattern, name); + } g_free (name); @@ -1395,7 +1423,7 @@ filter_glob (XedFileBrowserWidget * obj, XedFileBrowserStore * store, } static void -rename_selected_file (XedFileBrowserWidget * obj) +rename_selected_file (XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeIter iter; @@ -1403,15 +1431,19 @@ rename_selected_file (XedFileBrowserWidget * obj) model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } if (xed_file_browser_widget_get_first_selected (obj, &iter)) - xed_file_browser_view_start_rename (obj->priv->treeview, - &iter); + { + xed_file_browser_view_start_rename (obj->priv->treeview, &iter); + } } static GList * -get_deletable_files (XedFileBrowserWidget *obj) { +get_deletable_files (XedFileBrowserWidget *obj) +{ GtkTreeSelection *selection; GtkTreeModel *model; GList *rows; @@ -1427,18 +1459,21 @@ get_deletable_files (XedFileBrowserWidget *obj) { selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (row = rows; row; row = row->next) { + for (row = rows; row; row = row->next) + { path = (GtkTreePath *)(row->data); if (!gtk_tree_model_get_iter (model, &iter, path)) + { continue; + } - gtk_tree_model_get (model, &iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, - &flags, -1); + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); if (FILE_IS_DUMMY (flags)) + { continue; + } paths = g_list_append (paths, gtk_tree_path_copy (path)); } @@ -1450,7 +1485,8 @@ get_deletable_files (XedFileBrowserWidget *obj) { } static gboolean -delete_selected_files (XedFileBrowserWidget * obj, gboolean trash) +delete_selected_files (XedFileBrowserWidget *obj, + gboolean trash) { GtkTreeModel *model; gboolean confirm; @@ -1460,22 +1496,28 @@ delete_selected_files (XedFileBrowserWidget * obj, gboolean trash) model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return FALSE; + } rows = get_deletable_files (obj); if (!rows) + { return FALSE; + } - if (!trash) { + if (!trash) + { g_signal_emit (obj, signals[CONFIRM_DELETE], 0, model, rows, &confirm); if (!confirm) + { return FALSE; + } } - result = xed_file_browser_store_delete_all (XED_FILE_BROWSER_STORE (model), - rows, trash); + result = xed_file_browser_store_delete_all (XED_FILE_BROWSER_STORE (model), rows, trash); g_list_foreach (rows, (GFunc)gtk_tree_path_free, NULL); g_list_free (rows); @@ -1484,9 +1526,9 @@ delete_selected_files (XedFileBrowserWidget * obj, gboolean trash) } static gboolean -on_file_store_no_trash (XedFileBrowserStore * store, - GList * files, - XedFileBrowserWidget * obj) +on_file_store_no_trash (XedFileBrowserStore *store, + GList *files, + XedFileBrowserWidget *obj) { gboolean confirm = FALSE; @@ -1496,14 +1538,15 @@ on_file_store_no_trash (XedFileBrowserStore * store, } static GFile * -get_topmost_file (GFile * file) +get_topmost_file (GFile *file) { - GFile * tmp; - GFile * current; + GFile *tmp; + GFile *current; current = g_object_ref (file); - while ((tmp = g_file_get_parent (current)) != NULL) { + while ((tmp = g_file_get_parent (current)) != NULL) + { g_object_unref (current); current = tmp; } @@ -1512,8 +1555,9 @@ get_topmost_file (GFile * file) } static GtkWidget * -create_goto_menu_item (XedFileBrowserWidget * obj, GList * item, - GdkPixbuf * icon) +create_goto_menu_item (XedFileBrowserWidget *obj, + GList *item, + GdkPixbuf *icon) { GtkWidget *result; GtkWidget *image; @@ -1523,29 +1567,34 @@ create_goto_menu_item (XedFileBrowserWidget * obj, GList * item, loc = (Location *) (item->data); - if (!get_from_bookmark_file (obj, loc->virtual_root, &unescape, &pixbuf)) { + if (!get_from_bookmark_file (obj, loc->virtual_root, &unescape, &pixbuf)) + { unescape = xed_file_browser_utils_file_basename (loc->virtual_root); if (icon) + { pixbuf = g_object_ref (icon); + } } - if (pixbuf) { + if (pixbuf) + { image = gtk_image_new_from_pixbuf (pixbuf); g_object_unref (pixbuf); gtk_widget_show (image); result = gtk_image_menu_item_new_with_label (unescape); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (result), - image); - } else { + gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (result), image); + } + else + { result = gtk_menu_item_new_with_label (unescape); } g_object_set_data (G_OBJECT (result), LOCATION_DATA_KEY, item); g_signal_connect (result, "activate", - G_CALLBACK (on_location_jump_activate), obj); + G_CALLBACK (on_location_jump_activate), obj); gtk_widget_show (result); @@ -1555,26 +1604,31 @@ create_goto_menu_item (XedFileBrowserWidget * obj, GList * item, } static GList * -list_next_iterator (GList * list) +list_next_iterator (GList *list) { if (!list) + { return NULL; + } return list->next; } static GList * -list_prev_iterator (GList * list) +list_prev_iterator (GList *list) { if (!list) + { return NULL; + } return list->prev; } static void -jump_to_location (XedFileBrowserWidget * obj, GList * item, - gboolean previous) +jump_to_location (XedFileBrowserWidget *obj, + GList *item, + gboolean previous) { Location *loc; GtkWidget *widget; @@ -1585,13 +1639,18 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, GtkWidget *menu_to; if (!obj->priv->locations) + { return; + } - if (previous) { + if (previous) + { iter_func = list_next_iterator; menu_from = obj->priv->location_previous_menu; menu_to = obj->priv->location_next_menu; - } else { + } + else + { iter_func = list_prev_iterator; menu_from = obj->priv->location_next_menu; menu_to = obj->priv->location_previous_menu; @@ -1604,11 +1663,12 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, to be added to the menu */ widget = obj->priv->current_location_menu_item; - while (obj->priv->current_location != item) { - if (widget) { + while (obj->priv->current_location != item) + { + if (widget) + { /* Prepend the menu item to the menu */ - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu_to), - widget); + gtk_menu_shell_prepend (GTK_MENU_SHELL (menu_to), widget); g_object_unref (widget); } @@ -1621,14 +1681,18 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, obj->priv->current_location_menu_item = widget; - if (obj->priv->current_location == NULL) { + if (obj->priv->current_location == NULL) + { obj->priv->current_location = obj->priv->locations; if (obj->priv->current_location == item) + { break; - } else { - obj->priv->current_location = - iter_func (obj->priv->current_location); + } + } + else + { + obj->priv->current_location = iter_func (obj->priv->current_location); } child = child->next; @@ -1643,137 +1707,138 @@ jump_to_location (XedFileBrowserWidget * obj, GList * item, loc = (Location *) (obj->priv->current_location->data); /* Set the new root + virtual root */ - xed_file_browser_widget_set_root_and_virtual_root (obj, - loc->root, - loc->virtual_root); + xed_file_browser_widget_set_root_and_virtual_root (obj, loc->root, loc->virtual_root); obj->priv->changing_location = FALSE; } static void -clear_next_locations (XedFileBrowserWidget * obj) +clear_next_locations (XedFileBrowserWidget *obj) { GList *children; GList *item; if (obj->priv->current_location == NULL) + { return; - - while (obj->priv->current_location->prev) { - location_free ((Location *) (obj->priv->current_location-> - prev->data)); - obj->priv->locations = - g_list_remove_link (obj->priv->locations, - obj->priv->current_location->prev); } - children = - gtk_container_get_children (GTK_CONTAINER - (obj->priv->location_next_menu)); + while (obj->priv->current_location->prev) + { + location_free ((Location *) (obj->priv->current_location->prev->data)); + obj->priv->locations = g_list_remove_link (obj->priv->locations, obj->priv->current_location->prev); + } - for (item = children; item; item = item->next) { - gtk_container_remove (GTK_CONTAINER - (obj->priv->location_next_menu), - GTK_WIDGET (item->data)); + children = gtk_container_get_children (GTK_CONTAINER (obj->priv->location_next_menu)); + + for (item = children; item; item = item->next) + { + gtk_container_remove (GTK_CONTAINER (obj->priv->location_next_menu), GTK_WIDGET (item->data)); } g_list_free (children); - gtk_action_set_sensitive (gtk_action_group_get_action - (obj->priv->action_group_sensitive, - "DirectoryNext"), FALSE); + gtk_action_set_sensitive (gtk_action_group_get_action (obj->priv->action_group_sensitive, + "DirectoryNext"), FALSE); } static void -update_filter_mode (XedFileBrowserWidget * obj, - GtkAction * action, - XedFileBrowserStoreFilterMode mode) +update_filter_mode (XedFileBrowserWidget *obj, + GtkAction *action, + XedFileBrowserStoreFilterMode mode) { - gboolean active = - gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + gboolean active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); gint now; - if (XED_IS_FILE_BROWSER_STORE (model)) { - now = - xed_file_browser_store_get_filter_mode - (XED_FILE_BROWSER_STORE (model)); + if (XED_IS_FILE_BROWSER_STORE (model)) + { + now = xed_file_browser_store_get_filter_mode (XED_FILE_BROWSER_STORE (model)); if (active) + { now &= ~mode; + } else + { now |= mode; + } - xed_file_browser_store_set_filter_mode - (XED_FILE_BROWSER_STORE (model), now); + xed_file_browser_store_set_filter_mode (XED_FILE_BROWSER_STORE (model), now); } } static void -set_filter_pattern_real (XedFileBrowserWidget * obj, - gchar const * pattern, - gboolean update_entry) +set_filter_pattern_real (XedFileBrowserWidget *obj, + gchar const *pattern, + gboolean update_entry) { GtkTreeModel *model; - model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (pattern != NULL && *pattern == '\0') + { pattern = NULL; + } if (pattern == NULL && obj->priv->filter_pattern_str == NULL) + { return; + } if (pattern != NULL && obj->priv->filter_pattern_str != NULL && strcmp (pattern, obj->priv->filter_pattern_str) == 0) + { return; + } /* Free the old pattern */ g_free (obj->priv->filter_pattern_str); obj->priv->filter_pattern_str = g_strdup (pattern); - if (obj->priv->filter_pattern) { + if (obj->priv->filter_pattern) + { g_pattern_spec_free (obj->priv->filter_pattern); obj->priv->filter_pattern = NULL; } - if (pattern == NULL) { - if (obj->priv->glob_filter_id != 0) { - xed_file_browser_widget_remove_filter (obj, - obj-> - priv-> - glob_filter_id); + if (pattern == NULL) + { + if (obj->priv->glob_filter_id != 0) + { + xed_file_browser_widget_remove_filter (obj, obj->priv->glob_filter_id); obj->priv->glob_filter_id = 0; } - } else { + } + else + { obj->priv->filter_pattern = g_pattern_spec_new (pattern); if (obj->priv->glob_filter_id == 0) - obj->priv->glob_filter_id = - xed_file_browser_widget_add_filter (obj, - filter_glob, - NULL, - NULL); + { + obj->priv->glob_filter_id = xed_file_browser_widget_add_filter (obj, filter_glob, NULL, NULL); + } } - if (update_entry) { + if (update_entry) + { if (obj->priv->filter_pattern_str == NULL) - gtk_entry_set_text (GTK_ENTRY (obj->priv->filter_entry), - ""); - else { - gtk_entry_set_text (GTK_ENTRY (obj->priv->filter_entry), - obj->priv->filter_pattern_str); + { + gtk_entry_set_text (GTK_ENTRY (obj->priv->filter_entry), ""); + } + else + { + gtk_entry_set_text (GTK_ENTRY (obj->priv->filter_entry), obj->priv->filter_pattern_str); - gtk_expander_set_expanded (GTK_EXPANDER (obj->priv->filter_expander), - TRUE); + gtk_expander_set_expanded (GTK_EXPANDER (obj->priv->filter_expander), TRUE); } } if (XED_IS_FILE_BROWSER_STORE (model)) - xed_file_browser_store_refilter (XED_FILE_BROWSER_STORE - (model)); + { + xed_file_browser_store_refilter (XED_FILE_BROWSER_STORE (model)); + } g_object_notify (G_OBJECT (obj), "filter-pattern"); } @@ -1784,8 +1849,7 @@ set_filter_pattern_real (XedFileBrowserWidget * obj, GtkWidget * xed_file_browser_widget_new (const gchar *data_dir) { - XedFileBrowserWidget *obj = - g_object_new (XED_TYPE_FILE_BROWSER_WIDGET, NULL); + XedFileBrowserWidget *obj = g_object_new (XED_TYPE_FILE_BROWSER_WIDGET, NULL); create_toolbar (obj, data_dir); create_combo (obj); @@ -1798,139 +1862,136 @@ xed_file_browser_widget_new (const gchar *data_dir) } void -xed_file_browser_widget_show_bookmarks (XedFileBrowserWidget * obj) +xed_file_browser_widget_show_bookmarks (XedFileBrowserWidget *obj) { /* Select bookmarks in the combo box */ - g_signal_handlers_block_by_func (obj->priv->combo, - on_combo_changed, obj); + g_signal_handlers_block_by_func (obj->priv->combo, on_combo_changed, obj); combo_set_active_by_id (obj, BOOKMARKS_ID); - g_signal_handlers_unblock_by_func (obj->priv->combo, - on_combo_changed, obj); + g_signal_handlers_unblock_by_func (obj->priv->combo, on_combo_changed, obj); check_current_item (obj, FALSE); - xed_file_browser_view_set_model (obj->priv->treeview, - GTK_TREE_MODEL (obj->priv-> - bookmarks_store)); + xed_file_browser_view_set_model (obj->priv->treeview, GTK_TREE_MODEL (obj->priv->bookmarks_store)); } static void show_files_real (XedFileBrowserWidget *obj, - gboolean do_root_changed) + gboolean do_root_changed) { - xed_file_browser_view_set_model (obj->priv->treeview, - GTK_TREE_MODEL (obj->priv-> - file_store)); + xed_file_browser_view_set_model (obj->priv->treeview, GTK_TREE_MODEL (obj->priv->file_store)); if (do_root_changed) + { on_virtual_root_changed (obj->priv->file_store, NULL, obj); + } } void -xed_file_browser_widget_show_files (XedFileBrowserWidget * obj) +xed_file_browser_widget_show_files (XedFileBrowserWidget *obj) { show_files_real (obj, TRUE); } void xed_file_browser_widget_set_root_and_virtual_root (XedFileBrowserWidget *obj, - GFile *root, - GFile *virtual_root) + GFile *root, + GFile *virtual_root) { XedFileBrowserStoreResult result; if (!virtual_root) - result = - xed_file_browser_store_set_root_and_virtual_root - (obj->priv->file_store, root, root); + { + result = xed_file_browser_store_set_root_and_virtual_root (obj->priv->file_store, root, root); + } else - result = - xed_file_browser_store_set_root_and_virtual_root - (obj->priv->file_store, root, virtual_root); + { + result = xed_file_browser_store_set_root_and_virtual_root (obj->priv->file_store, root, virtual_root); + } if (result == XED_FILE_BROWSER_STORE_RESULT_NO_CHANGE) + { show_files_real (obj, TRUE); + } } void -xed_file_browser_widget_set_root (XedFileBrowserWidget * obj, - GFile *root, - gboolean virtual_root) +xed_file_browser_widget_set_root (XedFileBrowserWidget *obj, + GFile *root, + gboolean virtual_root) { GFile *parent; - if (!virtual_root) { - xed_file_browser_widget_set_root_and_virtual_root (obj, - root, - NULL); + if (!virtual_root) + { + xed_file_browser_widget_set_root_and_virtual_root (obj, root, NULL); return; } if (!root) + { return; + } parent = get_topmost_file (root); - xed_file_browser_widget_set_root_and_virtual_root - (obj, parent, root); + xed_file_browser_widget_set_root_and_virtual_root (obj, parent, root); g_object_unref (parent); } XedFileBrowserStore * -xed_file_browser_widget_get_browser_store (XedFileBrowserWidget * obj) +xed_file_browser_widget_get_browser_store (XedFileBrowserWidget *obj) { return obj->priv->file_store; } XedFileBookmarksStore * -xed_file_browser_widget_get_bookmarks_store (XedFileBrowserWidget * obj) +xed_file_browser_widget_get_bookmarks_store (XedFileBrowserWidget *obj) { return obj->priv->bookmarks_store; } XedFileBrowserView * -xed_file_browser_widget_get_browser_view (XedFileBrowserWidget * obj) +xed_file_browser_widget_get_browser_view (XedFileBrowserWidget *obj) { return obj->priv->treeview; } GtkUIManager * -xed_file_browser_widget_get_ui_manager (XedFileBrowserWidget * obj) +xed_file_browser_widget_get_ui_manager (XedFileBrowserWidget *obj) { return obj->priv->manager; } GtkWidget * -xed_file_browser_widget_get_filter_entry (XedFileBrowserWidget * obj) +xed_file_browser_widget_get_filter_entry (XedFileBrowserWidget *obj) { return obj->priv->filter_entry; } gulong -xed_file_browser_widget_add_filter (XedFileBrowserWidget * obj, - XedFileBrowserWidgetFilterFunc func, - gpointer user_data, - GDestroyNotify notify) +xed_file_browser_widget_add_filter (XedFileBrowserWidget *obj, + XedFileBrowserWidgetFilterFunc func, + gpointer user_data, + GDestroyNotify notify) { FilterFunc *f; - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); f = filter_func_new (obj, func, user_data, notify); - obj->priv->filter_funcs = - g_slist_append (obj->priv->filter_funcs, f); + obj->priv->filter_funcs = g_slist_append (obj->priv->filter_funcs, f); if (XED_IS_FILE_BROWSER_STORE (model)) - xed_file_browser_store_refilter (XED_FILE_BROWSER_STORE - (model)); + { + xed_file_browser_store_refilter (XED_FILE_BROWSER_STORE (model)); + } return f->id; } void -xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, - gulong id) +xed_file_browser_widget_remove_filter (XedFileBrowserWidget *obj, + gulong id) { GSList *item; FilterFunc *func; @@ -1942,11 +2003,11 @@ xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, if (func->id == id) { if (func->destroy_notify) + { func->destroy_notify (func->user_data); + } - obj->priv->filter_funcs = - g_slist_remove_link (obj->priv->filter_funcs, - item); + obj->priv->filter_funcs = g_slist_remove_link (obj->priv->filter_funcs, item); filter_func_free (func); break; } @@ -1954,35 +2015,37 @@ xed_file_browser_widget_remove_filter (XedFileBrowserWidget * obj, } void -xed_file_browser_widget_set_filter_pattern (XedFileBrowserWidget * obj, - gchar const *pattern) +xed_file_browser_widget_set_filter_pattern (XedFileBrowserWidget *obj, + gchar const *pattern) { set_filter_pattern_real (obj, pattern, TRUE); } gboolean -xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj, - GtkTreeIter * iter) +xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget *obj, + GtkTreeIter *iter) { - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); GtkTreeIter parent; guint flags; if (!XED_IS_FILE_BROWSER_STORE (model)) + { return FALSE; - - if (!xed_file_browser_widget_get_first_selected (obj, iter)) { - if (!xed_file_browser_store_get_iter_virtual_root - (XED_FILE_BROWSER_STORE (model), iter)) - return FALSE; } - gtk_tree_model_get (model, iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + if (!xed_file_browser_widget_get_first_selected (obj, iter)) + { + if (!xed_file_browser_store_get_iter_virtual_root (XED_FILE_BROWSER_STORE (model), iter)) + { + return FALSE; + } + } - if (!FILE_IS_DIR (flags)) { + gtk_tree_model_get (model, iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); + + if (!FILE_IS_DIR (flags)) + { /* Get the parent, because the selection is a file */ gtk_tree_model_iter_parent (model, &parent, iter); *iter = parent; @@ -1993,8 +2056,8 @@ xed_file_browser_widget_get_selected_directory (XedFileBrowserWidget * obj, static guint xed_file_browser_widget_get_num_selected_files_or_directories (XedFileBrowserWidget *obj, - guint *files, - guint *dirs) + guint *files, + guint *dirs) { GList *rows, *row; GtkTreePath *path; @@ -2008,26 +2071,34 @@ xed_file_browser_widget_get_num_selected_files_or_directories (XedFileBrowserWid model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { return 0; + } rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (row = rows; row; row = row->next) { + for (row = rows; row; row = row->next) + { path = (GtkTreePath *)(row->data); /* Get iter from path */ if (!gtk_tree_model_get_iter (model, &iter, path)) + { continue; + } - gtk_tree_model_get (model, &iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); - if (!FILE_IS_DUMMY (flags)) { + if (!FILE_IS_DUMMY (flags)) + { if (!FILE_IS_DIR (flags)) + { ++(*files); + } else + { ++(*dirs); + } ++result; } @@ -2069,14 +2140,17 @@ async_free (AsyncData *async) } static void -set_busy (XedFileBrowserWidget *obj, gboolean busy) +set_busy (XedFileBrowserWidget *obj, + gboolean busy) { GdkWindow *window; window = gtk_widget_get_window (GTK_WIDGET (obj->priv->treeview)); if (!GDK_IS_WINDOW (window)) + { return; + } if (busy) { @@ -2096,8 +2170,8 @@ static void try_mount_volume (XedFileBrowserWidget *widget, GVolume *volume); static void activate_mount (XedFileBrowserWidget *widget, - GVolume *volume, - GMount *mount) + GVolume *volume, + GMount *mount) { GFile *root; @@ -2110,10 +2184,10 @@ activate_mount (XedFileBrowserWidget *widget, message = g_strdup_printf (_("No mount object for mounted volume: %s"), name); g_signal_emit (widget, - signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_SET_ROOT, - message); + signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_SET_ROOT, + message); g_free (name); g_free (message); @@ -2129,7 +2203,7 @@ activate_mount (XedFileBrowserWidget *widget, static void try_activate_drive (XedFileBrowserWidget *widget, - GDrive *drive) + GDrive *drive) { GList *volumes; GVolume *volume; @@ -2158,8 +2232,8 @@ try_activate_drive (XedFileBrowserWidget *widget, static void poll_for_media_cb (GDrive *drive, - GAsyncResult *res, - AsyncData *async) + GAsyncResult *res, + AsyncData *async) { GError *error = NULL; @@ -2188,10 +2262,10 @@ poll_for_media_cb (GDrive *drive, message = g_strdup_printf (_("Could not open media: %s"), name); g_signal_emit (async->widget, - signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_SET_ROOT, - message); + signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_SET_ROOT, + message); g_free (name); g_free (message); @@ -2204,8 +2278,8 @@ poll_for_media_cb (GDrive *drive, static void mount_volume_cb (GVolume *volume, - GAsyncResult *res, - AsyncData *async) + GAsyncResult *res, + AsyncData *async) { GError *error = NULL; @@ -2224,7 +2298,9 @@ mount_volume_cb (GVolume *volume, activate_mount (async->widget, volume, mount); if (mount) + { g_object_unref (mount); + } } else { @@ -2235,10 +2311,10 @@ mount_volume_cb (GVolume *volume, message = g_strdup_printf (_("Could not mount volume: %s"), name); g_signal_emit (async->widget, - signals[ERROR], - 0, - XED_FILE_BROWSER_ERROR_SET_ROOT, - message); + signals[ERROR], + 0, + XED_FILE_BROWSER_ERROR_SET_ROOT, + message); g_free (name); g_free (message); @@ -2252,22 +2328,18 @@ mount_volume_cb (GVolume *volume, static void activate_drive (XedFileBrowserWidget *obj, - GtkTreeIter *iter) + GtkTreeIter *iter) { GDrive *drive; AsyncData *async; gtk_tree_model_get (GTK_TREE_MODEL (obj->priv->bookmarks_store), iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, - &drive, -1); + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, &drive, -1); /* most common use case is a floppy drive, we'll poll for media and go from there */ async = async_data_new (obj); - g_drive_poll_for_media (drive, - async->cancellable, - (GAsyncReadyCallback)poll_for_media_cb, - async); + g_drive_poll_for_media (drive, async->cancellable, (GAsyncReadyCallback)poll_for_media_cb, async); g_object_unref (drive); set_busy (obj, TRUE); @@ -2275,7 +2347,7 @@ activate_drive (XedFileBrowserWidget *obj, static void try_mount_volume (XedFileBrowserWidget *widget, - GVolume *volume) + GVolume *volume) { GMountOperation *operation; AsyncData *async; @@ -2284,11 +2356,11 @@ try_mount_volume (XedFileBrowserWidget *widget, async = async_data_new (widget); g_volume_mount (volume, - G_MOUNT_MOUNT_NONE, - operation, - async->cancellable, - (GAsyncReadyCallback)mount_volume_cb, - async); + G_MOUNT_MOUNT_NONE, + operation, + async->cancellable, + (GAsyncReadyCallback)mount_volume_cb, + async); g_object_unref (operation); set_busy (widget, TRUE); @@ -2296,13 +2368,13 @@ try_mount_volume (XedFileBrowserWidget *widget, static void activate_volume (XedFileBrowserWidget *obj, - GtkTreeIter *iter) + GtkTreeIter *iter) { GVolume *volume; gtk_tree_model_get (GTK_TREE_MODEL (obj->priv->bookmarks_store), iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, - &volume, -1); + XED_FILE_BOOKMARKS_STORE_COLUMN_OBJECT, + &volume, -1); /* see if we can mount the volume */ try_mount_volume (obj, volume); @@ -2312,30 +2384,32 @@ activate_volume (XedFileBrowserWidget *obj, void xed_file_browser_widget_refresh (XedFileBrowserWidget *obj) { - GtkTreeModel *model = - gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); + GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (XED_IS_FILE_BROWSER_STORE (model)) - xed_file_browser_store_refresh (XED_FILE_BROWSER_STORE - (model)); - else if (XED_IS_FILE_BOOKMARKS_STORE (model)) { + { + xed_file_browser_store_refresh (XED_FILE_BROWSER_STORE (model)); + } + else if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { g_hash_table_ref (obj->priv->bookmarks_hash); g_hash_table_destroy (obj->priv->bookmarks_hash); - xed_file_bookmarks_store_refresh - (XED_FILE_BOOKMARKS_STORE (model)); + xed_file_bookmarks_store_refresh (XED_FILE_BOOKMARKS_STORE (model)); } } void xed_file_browser_widget_history_back (XedFileBrowserWidget *obj) { - if (obj->priv->locations) { + if (obj->priv->locations) + { if (obj->priv->current_location) - jump_to_location (obj, - obj->priv->current_location-> - next, TRUE); - else { + { + jump_to_location (obj, obj->priv->current_location->next, TRUE); + } + else + { jump_to_location (obj, obj->priv->locations, TRUE); } } @@ -2345,21 +2419,20 @@ void xed_file_browser_widget_history_forward (XedFileBrowserWidget *obj) { if (obj->priv->locations) - jump_to_location (obj, obj->priv->current_location->prev, - FALSE); + { + jump_to_location (obj, obj->priv->current_location->prev, FALSE); + } } static void bookmark_open (XedFileBrowserWidget *obj, - GtkTreeModel *model, - GtkTreeIter *iter) + GtkTreeModel *model, + GtkTreeIter *iter) { GFile *location; gint flags; - gtk_tree_model_get (model, iter, - XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, - &flags, -1); + gtk_tree_model_get (model, iter, XED_FILE_BOOKMARKS_STORE_COLUMN_FLAGS, &flags, -1); if (flags & XED_FILE_BOOKMARKS_STORE_IS_DRIVE) { @@ -2376,55 +2449,56 @@ bookmark_open (XedFileBrowserWidget *obj, return; } - location = - xed_file_bookmarks_store_get_location - (XED_FILE_BOOKMARKS_STORE (model), iter); + location = xed_file_bookmarks_store_get_location (XED_FILE_BOOKMARKS_STORE (model), iter); - if (location) { + if (location) + { /* here we check if the bookmark is a mount point, or if it is a remote bookmark. If that's the case, we will set the root to the uri of the bookmark and not try to set the topmost parent as root (since that may as well not be the mount point anymore) */ if ((flags & XED_FILE_BOOKMARKS_STORE_IS_MOUNT) || - (flags & XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK)) { - xed_file_browser_widget_set_root (obj, - location, - FALSE); - } else { - xed_file_browser_widget_set_root (obj, - location, - TRUE); + (flags & XED_FILE_BOOKMARKS_STORE_IS_REMOTE_BOOKMARK)) + { + xed_file_browser_widget_set_root (obj, location, FALSE); + } + else + { + xed_file_browser_widget_set_root (obj, location, TRUE); } g_object_unref (location); - } else { + } + else + { g_warning ("No uri!"); } } static void file_open (XedFileBrowserWidget *obj, - GtkTreeModel *model, - GtkTreeIter *iter) + GtkTreeModel *model, + GtkTreeIter *iter) { GFile *location; gint flags; gtk_tree_model_get (model, iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, - -1); + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + -1); - if (!FILE_IS_DIR (flags) && !FILE_IS_DUMMY (flags)) { + if (!FILE_IS_DIR (flags) && !FILE_IS_DUMMY (flags)) + { g_signal_emit (obj, signals[LOCATION_ACTIVATED], 0, location); } } static gboolean directory_open (XedFileBrowserWidget *obj, - GtkTreeModel *model, - GtkTreeIter *iter) + GtkTreeModel *model, + GtkTreeIter *iter) { gboolean result = FALSE; GError *error = NULL; @@ -2432,20 +2506,20 @@ directory_open (XedFileBrowserWidget *obj, XedFileBrowserStoreFlag flags; gtk_tree_model_get (model, iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, - -1); + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + -1); - if (FILE_IS_DIR (flags) && location) { + if (FILE_IS_DIR (flags) && location) + { gchar *uri; result = TRUE; uri = g_file_get_uri (location); - if (!gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (obj)), uri, GDK_CURRENT_TIME, &error)) { - g_signal_emit (obj, signals[ERROR], 0, - XED_FILE_BROWSER_ERROR_OPEN_DIRECTORY, - error->message); + if (!gtk_show_uri (gtk_widget_get_screen (GTK_WIDGET (obj)), uri, GDK_CURRENT_TIME, &error)) + { + g_signal_emit (obj, signals[ERROR], 0, XED_FILE_BROWSER_ERROR_OPEN_DIRECTORY, error->message); g_error_free (error); error = NULL; @@ -2459,8 +2533,8 @@ directory_open (XedFileBrowserWidget *obj, static void on_bookmark_activated (XedFileBrowserView *tree_view, - GtkTreeIter *iter, - XedFileBrowserWidget *obj) + GtkTreeIter *iter, + XedFileBrowserWidget *obj) { GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); @@ -2469,8 +2543,8 @@ on_bookmark_activated (XedFileBrowserView *tree_view, static void on_file_activated (XedFileBrowserView *tree_view, - GtkTreeIter *iter, - XedFileBrowserWidget *obj) + GtkTreeIter *iter, + XedFileBrowserWidget *obj) { GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (tree_view)); @@ -2478,25 +2552,29 @@ on_file_activated (XedFileBrowserView *tree_view, } static gboolean -virtual_root_is_root (XedFileBrowserWidget * obj, - XedFileBrowserStore * model) +virtual_root_is_root (XedFileBrowserWidget *obj, + XedFileBrowserStore *model) { GtkTreeIter root; GtkTreeIter virtual_root; if (!xed_file_browser_store_get_iter_root (model, &root)) + { return TRUE; + } if (!xed_file_browser_store_get_iter_virtual_root (model, &virtual_root)) + { return TRUE; + } return xed_file_browser_store_iter_equal (model, &root, &virtual_root); } static void -on_virtual_root_changed (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserWidget * obj) +on_virtual_root_changed (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserWidget *obj) { GtkTreeIter iter; GFile *location; @@ -2505,102 +2583,84 @@ on_virtual_root_changed (XedFileBrowserStore * model, Location *loc; GdkPixbuf *pixbuf; - if (gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)) != - GTK_TREE_MODEL (obj->priv->file_store)) + if (gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)) != GTK_TREE_MODEL (obj->priv->file_store)) { show_files_real (obj, FALSE); } - if (xed_file_browser_store_get_iter_virtual_root (model, &iter)) { - gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, - XED_FILE_BROWSER_STORE_COLUMN_LOCATION, - &location, -1); + if (xed_file_browser_store_get_iter_virtual_root (model, &iter)) + { + gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - if (xed_file_browser_store_get_iter_root (model, &root)) { - if (!obj->priv->changing_location) { + if (xed_file_browser_store_get_iter_root (model, &root)) + { + if (!obj->priv->changing_location) + { /* Remove all items from obj->priv->current_location on */ if (obj->priv->current_location) + { clear_next_locations (obj); + } loc = g_slice_new (Location); loc->root = xed_file_browser_store_get_root (model); loc->virtual_root = g_object_ref (location); - if (obj->priv->current_location) { + if (obj->priv->current_location) + { /* Add current location to the menu so we can go back to it later */ - gtk_menu_shell_prepend - (GTK_MENU_SHELL - (obj->priv-> - location_previous_menu), - obj->priv-> - current_location_menu_item); + gtk_menu_shell_prepend (GTK_MENU_SHELL (obj->priv->location_previous_menu), + obj->priv->current_location_menu_item); } - obj->priv->locations = - g_list_prepend (obj->priv->locations, - loc); + obj->priv->locations = g_list_prepend (obj->priv->locations, loc); gtk_tree_model_get (GTK_TREE_MODEL (model), - &iter, - XED_FILE_BROWSER_STORE_COLUMN_ICON, - &pixbuf, -1); + &iter, + XED_FILE_BROWSER_STORE_COLUMN_ICON, + &pixbuf, -1); - obj->priv->current_location = - obj->priv->locations; - obj->priv->current_location_menu_item = - create_goto_menu_item (obj, - obj->priv-> - current_location, - pixbuf); + obj->priv->current_location = obj->priv->locations; + obj->priv->current_location_menu_item = create_goto_menu_item (obj, + obj->priv->current_location, + pixbuf); - g_object_ref_sink (obj->priv-> - current_location_menu_item); + g_object_ref_sink (obj->priv->current_location_menu_item); if (pixbuf) + { g_object_unref (pixbuf); + } } - action = - gtk_action_group_get_action (obj->priv-> - action_group, - "DirectoryUp"); - gtk_action_set_sensitive (action, - !virtual_root_is_root (obj, model)); + action = gtk_action_group_get_action (obj->priv->action_group, "DirectoryUp"); + gtk_action_set_sensitive (action, !virtual_root_is_root (obj, model)); - action = - gtk_action_group_get_action (obj->priv-> - action_group_sensitive, - "DirectoryPrevious"); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); gtk_action_set_sensitive (action, - obj->priv-> - current_location != NULL - && obj->priv-> - current_location->next != - NULL); + obj->priv->current_location != NULL && + obj->priv->current_location->next != NULL); - action = - gtk_action_group_get_action (obj->priv-> - action_group_sensitive, - "DirectoryNext"); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); gtk_action_set_sensitive (action, - obj->priv-> - current_location != NULL - && obj->priv-> - current_location->prev != - NULL); + obj->priv->current_location != NULL && + obj->priv->current_location->prev != NULL); } check_current_item (obj, TRUE); - } else { + } + else + { g_message ("NO!"); } } static void -on_model_set (GObject * gobject, GParamSpec * arg1, - XedFileBrowserWidget * obj) +on_model_set (GObject *gobject, + GParamSpec *arg1, + XedFileBrowserWidget *obj) { GtkTreeModel *model; @@ -2608,44 +2668,41 @@ on_model_set (GObject * gobject, GParamSpec * arg1, clear_signals (obj); - if (XED_IS_FILE_BOOKMARKS_STORE (model)) { + if (XED_IS_FILE_BOOKMARKS_STORE (model)) + { clear_next_locations (obj); /* Add the current location to the back menu */ - if (obj->priv->current_location) { + if (obj->priv->current_location) + { GtkAction *action; gtk_menu_shell_prepend (GTK_MENU_SHELL (obj->priv->location_previous_menu), - obj->priv->current_location_menu_item); + obj->priv->current_location_menu_item); g_object_unref (obj->priv->current_location_menu_item); obj->priv->current_location = NULL; obj->priv->current_location_menu_item = NULL; - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, - "DirectoryPrevious"); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); gtk_action_set_sensitive (action, TRUE); } gtk_widget_set_sensitive (obj->priv->filter_expander, FALSE); - add_signal (obj, gobject, - g_signal_connect (gobject, "bookmark-activated", - G_CALLBACK - (on_bookmark_activated), obj)); - } else if (XED_IS_FILE_BROWSER_STORE (model)) { + add_signal (obj, gobject, g_signal_connect (gobject, "bookmark-activated", + G_CALLBACK (on_bookmark_activated), obj)); + } + else if (XED_IS_FILE_BROWSER_STORE (model)) + { /* make sure any async operation is cancelled */ cancel_async_operation (obj); - add_signal (obj, gobject, - g_signal_connect (gobject, "file-activated", - G_CALLBACK - (on_file_activated), obj)); + add_signal (obj, gobject, g_signal_connect (gobject, "file-activated", + G_CALLBACK (on_file_activated), obj)); - add_signal (obj, model, - g_signal_connect (model, "no-trash", - G_CALLBACK - (on_file_store_no_trash), obj)); + add_signal (obj, model, g_signal_connect (model, "no-trash", + G_CALLBACK (on_file_store_no_trash), obj)); gtk_widget_set_sensitive (obj->priv->filter_expander, TRUE); } @@ -2654,106 +2711,109 @@ on_model_set (GObject * gobject, GParamSpec * arg1, } static void -on_file_store_error (XedFileBrowserStore * store, guint code, - gchar * message, XedFileBrowserWidget * obj) +on_file_store_error (XedFileBrowserStore *store, + guint code, + gchar *message, + XedFileBrowserWidget *obj) { g_signal_emit (obj, signals[ERROR], 0, code, message); } static void -on_treeview_error (XedFileBrowserView * tree_view, guint code, - gchar * message, XedFileBrowserWidget * obj) +on_treeview_error (XedFileBrowserView *tree_view, + guint code, + gchar *message, + XedFileBrowserWidget *obj) { g_signal_emit (obj, signals[ERROR], 0, code, message); } static void -on_combo_changed (GtkComboBox * combo, XedFileBrowserWidget * obj) +on_combo_changed (GtkComboBox *combo, + XedFileBrowserWidget *obj) { GtkTreeIter iter; guint id; GFile * file; if (!gtk_combo_box_get_active_iter (combo, &iter)) + { return; + } - gtk_tree_model_get (GTK_TREE_MODEL (obj->priv->combo_model), &iter, - COLUMN_ID, &id, -1); + gtk_tree_model_get (GTK_TREE_MODEL (obj->priv->combo_model), &iter, COLUMN_ID, &id, -1); - switch (id) { - case BOOKMARKS_ID: - xed_file_browser_widget_show_bookmarks (obj); - break; + switch (id) + { + case BOOKMARKS_ID: + xed_file_browser_widget_show_bookmarks (obj); + break; - case PATH_ID: - gtk_tree_model_get (GTK_TREE_MODEL - (obj->priv->combo_model), &iter, - COLUMN_FILE, &file, -1); + case PATH_ID: + gtk_tree_model_get (GTK_TREE_MODEL (obj->priv->combo_model), &iter, COLUMN_FILE, &file, -1); - xed_file_browser_store_set_virtual_root_from_location (obj->priv->file_store, file); + xed_file_browser_store_set_virtual_root_from_location (obj->priv->file_store, file); - g_object_unref (file); - break; + g_object_unref (file); + break; } } static gboolean -on_treeview_popup_menu (XedFileBrowserView * treeview, - XedFileBrowserWidget * obj) +on_treeview_popup_menu (XedFileBrowserView *treeview, + XedFileBrowserWidget *obj) { return popup_menu (obj, NULL, gtk_tree_view_get_model (GTK_TREE_VIEW (treeview))); } static gboolean -on_treeview_button_press_event (XedFileBrowserView * treeview, - GdkEventButton * event, - XedFileBrowserWidget * obj) +on_treeview_button_press_event (XedFileBrowserView *treeview, + GdkEventButton *event, + XedFileBrowserWidget *obj) { - if (event->type == GDK_BUTTON_PRESS && event->button == 3) { - return popup_menu (obj, event, - gtk_tree_view_get_model (GTK_TREE_VIEW (treeview))); + if (event->type == GDK_BUTTON_PRESS && event->button == 3) + { + return popup_menu (obj, event, gtk_tree_view_get_model (GTK_TREE_VIEW (treeview))); } return FALSE; } static gboolean -do_change_directory (XedFileBrowserWidget * obj, - GdkEventKey * event) +do_change_directory (XedFileBrowserWidget *obj, + GdkEventKey *event) { GtkAction * action = NULL; if ((event->state & (~GDK_CONTROL_MASK & ~GDK_SHIFT_MASK & ~GDK_MOD1_MASK)) == event->state && event->keyval == GDK_KEY_BackSpace) - action = gtk_action_group_get_action (obj->priv-> - action_group_sensitive, - "DirectoryPrevious"); + { + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); + } else if (!((event->state & GDK_MOD1_MASK) && - (event->state & (~GDK_CONTROL_MASK & ~GDK_SHIFT_MASK)) == event->state)) + (event->state & (~GDK_CONTROL_MASK & ~GDK_SHIFT_MASK)) == event->state)) + { return FALSE; - - switch (event->keyval) { - case GDK_KEY_Left: - action = gtk_action_group_get_action (obj->priv-> - action_group_sensitive, - "DirectoryPrevious"); - break; - case GDK_KEY_Right: - action = gtk_action_group_get_action (obj->priv-> - action_group_sensitive, - "DirectoryNext"); - break; - case GDK_KEY_Up: - action = gtk_action_group_get_action (obj->priv-> - action_group, - "DirectoryUp"); - break; - default: - break; } - if (action != NULL) { + switch (event->keyval) + { + case GDK_KEY_Left: + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); + break; + case GDK_KEY_Right: + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); + break; + case GDK_KEY_Up: + action = gtk_action_group_get_action (obj->priv->action_group, "DirectoryUp"); + break; + default: + break; + } + + if (action != NULL) + { gtk_action_activate (action); return TRUE; } @@ -2762,37 +2822,44 @@ do_change_directory (XedFileBrowserWidget * obj, } static gboolean -on_treeview_key_press_event (XedFileBrowserView * treeview, - GdkEventKey * event, - XedFileBrowserWidget * obj) +on_treeview_key_press_event (XedFileBrowserView *treeview, + GdkEventKey *event, + XedFileBrowserWidget *obj) { guint modifiers; if (do_change_directory (obj, event)) + { return TRUE; + } - if (!XED_IS_FILE_BROWSER_STORE - (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)))) + if (!XED_IS_FILE_BROWSER_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (treeview)))) + { return FALSE; + } modifiers = gtk_accelerator_get_default_mod_mask (); - if (event->keyval == GDK_KEY_Delete - || event->keyval == GDK_KEY_KP_Delete) { + if (event->keyval == GDK_KEY_Delete || event->keyval == GDK_KEY_KP_Delete) + { - if ((event->state & modifiers) == GDK_SHIFT_MASK) { - if (obj->priv->enable_delete) { + if ((event->state & modifiers) == GDK_SHIFT_MASK) + { + if (obj->priv->enable_delete) + { delete_selected_files (obj, FALSE); return TRUE; } - } else if ((event->state & modifiers) == 0) { + } + else if ((event->state & modifiers) == 0) + { delete_selected_files (obj, TRUE); return TRUE; } } - if ((event->keyval == GDK_KEY_F2) - && (event->state & modifiers) == 0) { + if ((event->keyval == GDK_KEY_F2) && (event->state & modifiers) == 0) + { rename_selected_file (obj); return TRUE; @@ -2802,8 +2869,8 @@ on_treeview_key_press_event (XedFileBrowserView * treeview, } static void -on_selection_changed (GtkTreeSelection * selection, - XedFileBrowserWidget * obj) +on_selection_changed (GtkTreeSelection *selection, + XedFileBrowserWidget *obj) { GtkTreeModel *model; guint selected = 0; @@ -2814,23 +2881,17 @@ on_selection_changed (GtkTreeSelection * selection, if (XED_IS_FILE_BROWSER_STORE (model)) { - selected = xed_file_browser_widget_get_num_selected_files_or_directories (obj, - &files, - &dirs); + selected = xed_file_browser_widget_get_num_selected_files_or_directories (obj, &files, &dirs); } - gtk_action_group_set_sensitive (obj->priv->action_group_selection, - selected > 0); - gtk_action_group_set_sensitive (obj->priv->action_group_file_selection, - (selected > 0) && (selected == files)); - gtk_action_group_set_sensitive (obj->priv->action_group_single_selection, - selected == 1); - gtk_action_group_set_sensitive (obj->priv->action_group_single_most_selection, - selected <= 1); + gtk_action_group_set_sensitive (obj->priv->action_group_selection, selected > 0); + gtk_action_group_set_sensitive (obj->priv->action_group_file_selection, (selected > 0) && (selected == files)); + gtk_action_group_set_sensitive (obj->priv->action_group_single_selection, selected == 1); + gtk_action_group_set_sensitive (obj->priv->action_group_single_most_selection, selected <= 1); } static gboolean -on_entry_filter_activate (XedFileBrowserWidget * obj) +on_entry_filter_activate (XedFileBrowserWidget *obj) { gchar const *text; @@ -2841,50 +2902,54 @@ on_entry_filter_activate (XedFileBrowserWidget * obj) } static void -on_location_jump_activate (GtkMenuItem * item, - XedFileBrowserWidget * obj) +on_location_jump_activate (GtkMenuItem *item, + XedFileBrowserWidget *obj) { GList *location; location = g_object_get_data (G_OBJECT (item), LOCATION_DATA_KEY); - if (obj->priv->current_location) { + if (obj->priv->current_location) + { jump_to_location (obj, location, - g_list_position (obj->priv->locations, - location) > - g_list_position (obj->priv->locations, - obj->priv-> - current_location)); - } else { + g_list_position (obj->priv->locations, location) > + g_list_position (obj->priv->locations, obj->priv->current_location)); + } + else + { jump_to_location (obj, location, TRUE); } } static void -on_bookmarks_row_changed (GtkTreeModel * model, - GtkTreePath * path, - GtkTreeIter * iter, +on_bookmarks_row_changed (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, XedFileBrowserWidget *obj) { add_bookmark_hash (obj, iter); } static void -on_bookmarks_row_deleted (GtkTreeModel * model, - GtkTreePath * path, +on_bookmarks_row_deleted (GtkTreeModel *model, + GtkTreePath *path, XedFileBrowserWidget *obj) { GtkTreeIter iter; GFile *location; if (!gtk_tree_model_get_iter (model, &iter, path)) + { return; + } location = xed_file_bookmarks_store_get_location (obj->priv->bookmarks_store, &iter); if (!location) + { return; + } g_hash_table_remove (obj->priv->bookmarks_hash, location); @@ -2892,60 +2957,66 @@ on_bookmarks_row_deleted (GtkTreeModel * model, } static void -on_filter_mode_changed (XedFileBrowserStore * model, - GParamSpec * param, - XedFileBrowserWidget * obj) +on_filter_mode_changed (XedFileBrowserStore *model, + GParamSpec *param, + XedFileBrowserWidget *obj) { gint mode; - GtkToggleAction * action; + GtkToggleAction *action; gboolean active; mode = xed_file_browser_store_get_filter_mode (model); - action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (obj->priv->action_group, - "FilterHidden")); + action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (obj->priv->action_group, "FilterHidden")); active = !(mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN); if (active != gtk_toggle_action_get_active (action)) + { gtk_toggle_action_set_active (action, active); + } - action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (obj->priv->action_group, - "FilterBinary")); + action = GTK_TOGGLE_ACTION (gtk_action_group_get_action (obj->priv->action_group, "FilterBinary")); active = !(mode & XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY); if (active != gtk_toggle_action_get_active (action)) + { gtk_toggle_action_set_active (action, active); + } } static void -on_action_directory_next (GtkAction * action, XedFileBrowserWidget * obj) +on_action_directory_next (GtkAction *action, + XedFileBrowserWidget *obj) { xed_file_browser_widget_history_forward (obj); } static void -on_action_directory_previous (GtkAction * action, - XedFileBrowserWidget * obj) +on_action_directory_previous (GtkAction *action, + XedFileBrowserWidget *obj) { xed_file_browser_widget_history_back (obj); } static void -on_action_directory_up (GtkAction * action, - XedFileBrowserWidget * obj) +on_action_directory_up (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } xed_file_browser_store_set_virtual_root_up (XED_FILE_BROWSER_STORE (model)); } static void -on_action_directory_new (GtkAction * action, XedFileBrowserWidget * obj) +on_action_directory_new (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeIter parent; @@ -2954,20 +3025,24 @@ on_action_directory_new (GtkAction * action, XedFileBrowserWidget * obj) model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } if (!xed_file_browser_widget_get_selected_directory (obj, &parent)) + { return; + } - if (xed_file_browser_store_new_directory - (XED_FILE_BROWSER_STORE (model), &parent, &iter)) { - xed_file_browser_view_start_rename (obj->priv->treeview, - &iter); + if (xed_file_browser_store_new_directory (XED_FILE_BROWSER_STORE (model), &parent, &iter)) + { + xed_file_browser_view_start_rename (obj->priv->treeview, &iter); } } static void -on_action_file_open (GtkAction * action, XedFileBrowserWidget * obj) +on_action_file_open (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeSelection *selection; @@ -2980,15 +3055,20 @@ on_action_file_open (GtkAction * action, XedFileBrowserWidget * obj) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (row = rows; row; row = row->next) { + for (row = rows; row; row = row->next) + { path = (GtkTreePath *)(row->data); if (gtk_tree_model_get_iter (model, &iter, path)) + { file_open (obj, model, &iter); + } gtk_tree_path_free (path); } @@ -2997,7 +3077,8 @@ on_action_file_open (GtkAction * action, XedFileBrowserWidget * obj) } static void -on_action_file_new (GtkAction * action, XedFileBrowserWidget * obj) +on_action_file_new (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeIter parent; @@ -3006,45 +3087,52 @@ on_action_file_new (GtkAction * action, XedFileBrowserWidget * obj) model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } if (!xed_file_browser_widget_get_selected_directory (obj, &parent)) + { return; + } - if (xed_file_browser_store_new_file - (XED_FILE_BROWSER_STORE (model), &parent, &iter)) { - xed_file_browser_view_start_rename (obj->priv->treeview, - &iter); + if (xed_file_browser_store_new_file (XED_FILE_BROWSER_STORE (model), &parent, &iter)) + { + xed_file_browser_view_start_rename (obj->priv->treeview, &iter); } } static void -on_action_file_rename (GtkAction * action, XedFileBrowserWidget * obj) +on_action_file_rename (GtkAction *action, + XedFileBrowserWidget *obj) { rename_selected_file (obj); } static void -on_action_file_delete (GtkAction * action, XedFileBrowserWidget * obj) +on_action_file_delete (GtkAction *action, + XedFileBrowserWidget *obj) { delete_selected_files (obj, FALSE); } static void -on_action_file_move_to_trash (GtkAction * action, XedFileBrowserWidget * obj) +on_action_file_move_to_trash (GtkAction *action, + XedFileBrowserWidget *obj) { delete_selected_files (obj, TRUE); } static void -on_action_directory_refresh (GtkAction * action, - XedFileBrowserWidget * obj) +on_action_directory_refresh (GtkAction *action, + XedFileBrowserWidget *obj) { xed_file_browser_widget_refresh (obj); } static void -on_action_directory_open (GtkAction * action, XedFileBrowserWidget * obj) +on_action_directory_open (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeSelection *selection; @@ -3058,45 +3146,52 @@ on_action_directory_open (GtkAction * action, XedFileBrowserWidget * obj) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BROWSER_STORE (model)) + { return; + } rows = gtk_tree_selection_get_selected_rows (selection, &model); - for (row = rows; row; row = row->next) { + for (row = rows; row; row = row->next) + { path = (GtkTreePath *)(row->data); if (gtk_tree_model_get_iter (model, &iter, path)) + { directory_opened |= directory_open (obj, model, &iter); + } gtk_tree_path_free (path); } - if (!directory_opened) { + if (!directory_opened) + { if (xed_file_browser_widget_get_selected_directory (obj, &iter)) + { directory_open (obj, model, &iter); + } } g_list_free (rows); } static void -on_action_filter_hidden (GtkAction * action, XedFileBrowserWidget * obj) +on_action_filter_hidden (GtkAction *action, + XedFileBrowserWidget *obj) { - update_filter_mode (obj, - action, - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN); + update_filter_mode (obj, action, XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN); } static void -on_action_filter_binary (GtkAction * action, XedFileBrowserWidget * obj) +on_action_filter_binary (GtkAction *action, + XedFileBrowserWidget *obj) { - update_filter_mode (obj, - action, - XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY); + update_filter_mode (obj, action, XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY); } static void -on_action_bookmark_open (GtkAction * action, XedFileBrowserWidget * obj) +on_action_bookmark_open (GtkAction *action, + XedFileBrowserWidget *obj) { GtkTreeModel *model; GtkTreeSelection *selection; @@ -3106,10 +3201,14 @@ on_action_bookmark_open (GtkAction * action, XedFileBrowserWidget * obj) selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (obj->priv->treeview)); if (!XED_IS_FILE_BOOKMARKS_STORE (model)) + { return; + } if (gtk_tree_selection_get_selected (selection, NULL, &iter)) + { bookmark_open (obj, model, &iter); + } } void @@ -3117,5 +3216,3 @@ _xed_file_browser_widget_register_type (GTypeModule *type_module) { xed_file_browser_widget_register_type (type_module); } - -// ex:ts=8:noet: From f20b3bdcf546a103e9c643c31b8cc3246a45c26a Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 14:17:35 -0800 Subject: [PATCH 04/21] filebrowser-view: Removed the unused "busy" cursor --- plugins/filebrowser/xed-file-browser-view.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index ff07ef3..e2051e7 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -44,8 +44,6 @@ struct _XedFileBrowserViewPrivate GtkTreeModel *model; GtkTreeRowReference *editable; - GdkCursor *busy_cursor; - /* CLick policy */ XedFileBrowserViewClickPolicy click_policy; GtkTreePath *double_click_path[2]; /* Both clicks in a double click need to be on the same row */ @@ -128,8 +126,6 @@ xed_file_browser_view_finalize (GObject *object) obj->priv->expand_state = NULL; } - g_object_unref (obj->priv->busy_cursor); - G_OBJECT_CLASS (xed_file_browser_view_parent_class)->finalize (object); } @@ -1038,8 +1034,6 @@ xed_file_browser_view_init (XedFileBrowserView *obj) drag_source_targets, G_N_ELEMENTS (drag_source_targets), GDK_ACTION_COPY); - - obj->priv->busy_cursor = gdk_cursor_new (GDK_WATCH); } static gboolean From 4c45b083e13fc9d960bb6f2c7168698c638c38e3 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 14:24:32 -0800 Subject: [PATCH 05/21] Do not leak file info for . and .. dirs https://github.com/GNOME/gedit/commit/fa5fa82ce0e093383437621a53df2605999da1d1 --- plugins/filebrowser/xed-file-browser-store.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index eae3e1e..1032ec0 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -2276,15 +2276,17 @@ model_add_nodes_from_files (XedFileBrowserStore *model, (strcmp (name, ".") == 0 || strcmp (name, "..") == 0)) { + g_object_unref (info); continue; } file = g_file_get_child (parent->file, name); - if ((node = node_list_contains_file (original_children, file)) == NULL) + node = node_list_contains_file (original_children, file); + if (node == NULL) { - if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) + if (type == G_FILE_TYPE_DIRECTORY) { node = file_browser_node_dir_new (model, file, parent); } From 372399891de8dcd37436051b3e951b1525ffcdad Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 14:27:43 -0800 Subject: [PATCH 06/21] filebrowser: Unref the enumerator in the filebrowser plugin https://github.com/GNOME/gedit/commit/8bb1b9555f5682cc585f37c21ea032c0e57801f2 --- plugins/filebrowser/xed-file-browser-store.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index 1032ec0..85fba73 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -2471,6 +2471,7 @@ model_iterate_next_files_cb (GFileEnumerator *enumerator, if (files == NULL) { g_file_enumerator_close (enumerator, NULL, NULL); + g_object_unref (enumerator); async_node_free (async); if (!error) @@ -2522,6 +2523,7 @@ model_iterate_next_files_cb (GFileEnumerator *enumerator, { /* Check cancel state manually */ g_file_enumerator_close (enumerator, NULL, NULL); + g_object_unref (enumerator); async_node_free (async); } else From fe9e6ac91c0b5f2a9cf8a97868f2a9f527e393c8 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 15:02:25 -0800 Subject: [PATCH 07/21] file-browser-messages: Clean up formatting --- .../filebrowser/xed-file-browser-messages.c | 512 +++++++++--------- 1 file changed, 263 insertions(+), 249 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-messages.c b/plugins/filebrowser/xed-file-browser-messages.c index 102027d..1d7d462 100644 --- a/plugins/filebrowser/xed-file-browser-messages.c +++ b/plugins/filebrowser/xed-file-browser-messages.c @@ -2,8 +2,8 @@ #include "xed-file-browser-store.h" #include -#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" -#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" +#define MESSAGE_OBJECT_PATH "/plugins/filebrowser" +#define WINDOW_DATA_KEY "XedFileBrowserMessagesWindowData" #define BUS_CONNECT(bus, name, data) xed_message_bus_connect(bus, MESSAGE_OBJECT_PATH, #name, (XedMessageCallback) message_##name##_cb, data, NULL) @@ -41,7 +41,7 @@ typedef struct static WindowData * window_data_new (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { WindowData *data = g_slice_new (WindowData); GtkUIManager *manager; @@ -50,14 +50,14 @@ window_data_new (XedWindow *window, data->bus = xed_window_get_message_bus (window); data->widget = widget; data->row_tracking = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - (GDestroyNotify)gtk_tree_row_reference_free); + g_str_equal, + (GDestroyNotify)g_free, + (GDestroyNotify)gtk_tree_row_reference_free); data->filters = g_hash_table_new_full (g_str_hash, - g_str_equal, - (GDestroyNotify)g_free, - NULL); + g_str_equal, + (GDestroyNotify)g_free, + NULL); manager = xed_file_browser_widget_get_ui_manager (widget); @@ -92,7 +92,9 @@ window_data_free (XedWindow *window) gtk_ui_manager_remove_action_group (manager, data->merged_actions); for (item = data->merge_ids; item; item = item->next) + { gtk_ui_manager_remove_ui (manager, GPOINTER_TO_INT (item->data)); + } g_list_free (data->merge_ids); g_object_unref (data->merged_actions); @@ -104,7 +106,7 @@ window_data_free (XedWindow *window) static FilterData * filter_data_new (XedWindow *window, - XedMessage *message) + XedMessage *message) { FilterData *data = g_slice_new (FilterData); WindowData *wdata; @@ -115,10 +117,8 @@ filter_data_new (XedWindow *window, wdata = get_window_data (window); - g_hash_table_insert (wdata->filters, - xed_message_type_identifier (xed_message_get_object_path (message), - xed_message_get_method (message)), - data); + g_hash_table_insert (wdata->filters, xed_message_type_identifier (xed_message_get_object_path (message), + xed_message_get_method (message)), data); return data; } @@ -130,7 +130,7 @@ filter_data_free (FilterData *data) gchar *identifier; identifier = xed_message_type_identifier (xed_message_get_object_path (data->message), - xed_message_get_method (data->message)); + xed_message_get_method (data->message)); g_hash_table_remove (wdata->filters, identifier); g_free (identifier); @@ -141,14 +141,16 @@ filter_data_free (FilterData *data) static GtkTreePath * track_row_lookup (WindowData *data, - const gchar *id) + const gchar *id) { GtkTreeRowReference *ref; ref = (GtkTreeRowReference *)g_hash_table_lookup (data->row_tracking, id); if (!ref) + { return NULL; + } return gtk_tree_row_reference_get_path (ref); } @@ -161,8 +163,8 @@ message_cache_data_free (MessageCacheData *data) } static MessageCacheData * -message_cache_data_new (XedWindow *window, - XedMessage *message) +message_cache_data_new (XedWindow *window, + XedMessage *message) { MessageCacheData *data = g_slice_new (MessageCacheData); @@ -174,8 +176,8 @@ message_cache_data_new (XedWindow *window, static void message_get_root_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { XedFileBrowserStore *store; GFile *location; @@ -192,8 +194,8 @@ message_get_root_cb (XedMessageBus *bus, static void message_set_root_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { GFile *root; GFile *virtual = NULL; @@ -201,21 +203,29 @@ message_set_root_cb (XedMessageBus *bus, xed_message_get (message, "location", &root, NULL); if (!root) + { return; + } if (xed_message_has_key (message, "virtual")) + { xed_message_get (message, "virtual", &virtual, NULL); + } if (virtual) + { xed_file_browser_widget_set_root_and_virtual_root (data->widget, root, virtual); + } else + { xed_file_browser_widget_set_root (data->widget, root, TRUE); + } } static void message_set_emblem_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { gchar *id = NULL; gchar *emblem = NULL; @@ -239,11 +249,7 @@ message_set_emblem_cb (XedMessageBus *bus, GError *error = NULL; GdkPixbuf *pixbuf; - pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - emblem, - 10, - 0, - &error); + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), emblem, 10, 0, &error); if (pixbuf) { @@ -257,10 +263,7 @@ message_set_emblem_cb (XedMessageBus *bus, g_value_init (&value, GDK_TYPE_PIXBUF); g_value_set_object (&value, pixbuf); - xed_file_browser_store_set_value (store, - &iter, - XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, - &value); + xed_file_browser_store_set_value (store, &iter, XED_FILE_BROWSER_STORE_COLUMN_EMBLEM, &value); g_value_unset (&value); } @@ -278,7 +281,7 @@ message_set_emblem_cb (XedMessageBus *bus, static gchar * item_id (const gchar *path, - GFile *location) + GFile *location) { gchar *uri; gchar *id; @@ -291,10 +294,10 @@ item_id (const gchar *path, } static gchar * -track_row (WindowData *data, - XedFileBrowserStore *store, - GtkTreePath *path, - GFile *location) +track_row (WindowData *data, + XedFileBrowserStore *store, + GtkTreePath *path, + GFile *location) { GtkTreeRowReference *ref; gchar *id; @@ -312,10 +315,10 @@ track_row (WindowData *data, } static void -set_item_message (WindowData *data, - GtkTreeIter *iter, - GtkTreePath *path, - XedMessage *message) +set_item_message (WindowData *data, + GtkTreeIter *iter, + GtkTreePath *path, + XedMessage *message) { XedFileBrowserStore *store; GFile *location; @@ -325,28 +328,29 @@ set_item_message (WindowData *data, store = xed_file_browser_widget_get_browser_store (data->widget); gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); if (!location) + { return; + } if (path && gtk_tree_path_get_depth (path) != 0) + { track_id = track_row (data, store, path, location); + } else + { track_id = NULL; + } - xed_message_set (message, - "id", track_id, - "location", location, - NULL); + xed_message_set (message, "id", track_id, "location", location, NULL); if (xed_message_has_key (message, "is_directory")) { - xed_message_set (message, - "is_directory", FILE_IS_DIR (flags), - NULL); + xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL); } g_free (track_id); @@ -354,9 +358,9 @@ set_item_message (WindowData *data, static gboolean custom_message_filter_func (XedFileBrowserWidget *widget, - XedFileBrowserStore *store, - GtkTreeIter *iter, - FilterData *data) + XedFileBrowserStore *store, + GtkTreeIter *iter, + FilterData *data) { WindowData *wdata = get_window_data (data->window); GFile *location; @@ -365,9 +369,9 @@ custom_message_filter_func (XedFileBrowserWidget *widget, GtkTreePath *path; gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); if (!location || FILE_IS_DUMMY (flags)) { @@ -388,8 +392,8 @@ custom_message_filter_func (XedFileBrowserWidget *widget, static void message_add_filter_cb (XedMessageBus *bus, - XedMessage *message, - XedWindow *window) + XedMessage *message, + XedWindow *window) { gchar *object_path = NULL; gchar *method = NULL; @@ -399,10 +403,7 @@ message_add_filter_cb (XedMessageBus *bus, FilterData *filter_data; WindowData *data = get_window_data (window); - xed_message_get (message, - "object_path", &object_path, - "method", &method, - NULL); + xed_message_get (message, "object_path", &object_path, "method", &method, NULL); // Check if there exists such a 'callback' message if (!object_path || !method) @@ -433,41 +434,43 @@ message_add_filter_cb (XedMessageBus *bus, } cbmessage = xed_message_type_instantiate (message_type, - "id", NULL, - "location", NULL, - "is_directory", FALSE, - "filter", FALSE, - NULL); + "id", NULL, + "location", NULL, + "is_directory", FALSE, + "filter", FALSE, + NULL); // Register the custom filter on the widget filter_data = filter_data_new (window, cbmessage); id = xed_file_browser_widget_add_filter (data->widget, - (XedFileBrowserWidgetFilterFunc)custom_message_filter_func, - filter_data, - (GDestroyNotify)filter_data_free); + (XedFileBrowserWidgetFilterFunc)custom_message_filter_func, + filter_data, + (GDestroyNotify)filter_data_free); filter_data->id = id; } static void message_remove_filter_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { gulong id = 0; xed_message_get (message, "id", &id, NULL); if (!id) + { return; + } xed_file_browser_widget_remove_filter (data->widget, id); } static void message_up_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { XedFileBrowserStore *store = xed_file_browser_widget_get_browser_store (data->widget); @@ -476,32 +479,32 @@ message_up_cb (XedMessageBus *bus, static void message_history_back_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { xed_file_browser_widget_history_back (data->widget); } static void message_history_forward_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { xed_file_browser_widget_history_forward (data->widget); } static void message_refresh_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { xed_file_browser_widget_refresh (data->widget); } static void message_set_show_hidden_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { gboolean active = FALSE; XedFileBrowserStore *store; @@ -513,17 +516,21 @@ message_set_show_hidden_cb (XedMessageBus *bus, mode = xed_file_browser_store_get_filter_mode (store); if (active) + { mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + } else + { mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN; + } xed_file_browser_store_set_filter_mode (store, mode); } static void message_set_show_binary_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { gboolean active = FALSE; XedFileBrowserStore *store; @@ -535,33 +542,37 @@ message_set_show_binary_cb (XedMessageBus *bus, mode = xed_file_browser_store_get_filter_mode (store); if (active) + { mode &= ~XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + } else + { mode |= XED_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY; + } xed_file_browser_store_set_filter_mode (store, mode); } static void message_show_bookmarks_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { xed_file_browser_widget_show_bookmarks (data->widget); } static void message_show_files_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { xed_file_browser_widget_show_files (data->widget); } static void message_add_context_item_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { GtkAction *action = NULL; gchar *path = NULL; @@ -569,15 +580,14 @@ message_add_context_item_cb (XedMessageBus *bus, GtkUIManager *manager; guint merge_id; - xed_message_get (message, - "action", &action, - "path", &path, - NULL); + xed_message_get (message, "action", &action, "path", &path, NULL); if (!action || !path) { if (action) + { g_object_unref (action); + } g_free (path); return; @@ -589,12 +599,12 @@ message_add_context_item_cb (XedMessageBus *bus, merge_id = gtk_ui_manager_new_merge_id (manager); gtk_ui_manager_add_ui (manager, - merge_id, - path, - name, - gtk_action_get_name (action), - GTK_UI_MANAGER_AUTO, - FALSE); + merge_id, + path, + name, + gtk_action_get_name (action), + GTK_UI_MANAGER_AUTO, + FALSE); if (gtk_ui_manager_get_widget (manager, path)) { @@ -613,8 +623,8 @@ message_add_context_item_cb (XedMessageBus *bus, static void message_remove_context_item_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { guint merge_id = 0; GtkUIManager *manager; @@ -622,7 +632,9 @@ message_remove_context_item_cb (XedMessageBus *bus, xed_message_get (message, "id", &merge_id, NULL); if (merge_id == 0) + { return; + } manager = xed_file_browser_widget_get_ui_manager (data->widget); @@ -632,8 +644,8 @@ message_remove_context_item_cb (XedMessageBus *bus, static void message_get_view_cb (XedMessageBus *bus, - XedMessage *message, - WindowData *data) + XedMessage *message, + WindowData *data) { XedFileBrowserView *view; view = xed_file_browser_widget_get_browser_view (data->widget); @@ -643,59 +655,59 @@ message_get_view_cb (XedMessageBus *bus, static void register_methods (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { XedMessageBus *bus = xed_window_get_message_bus (window); WindowData *data = get_window_data (window); /* Register method calls */ xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "get_root", - 1, - "location", G_TYPE_FILE, - NULL); + MESSAGE_OBJECT_PATH, "get_root", + 1, + "location", G_TYPE_FILE, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_root", - 1, - "location", G_TYPE_FILE, - "virtual", G_TYPE_STRING, - NULL); + MESSAGE_OBJECT_PATH, "set_root", + 1, + "location", G_TYPE_FILE, + "virtual", G_TYPE_STRING, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_emblem", - 0, - "id", G_TYPE_STRING, - "emblem", G_TYPE_STRING, - NULL); + MESSAGE_OBJECT_PATH, "set_emblem", + 0, + "id", G_TYPE_STRING, + "emblem", G_TYPE_STRING, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "add_filter", - 1, - "object_path", G_TYPE_STRING, - "method", G_TYPE_STRING, - "id", G_TYPE_ULONG, - NULL); + MESSAGE_OBJECT_PATH, "add_filter", + 1, + "object_path", G_TYPE_STRING, + "method", G_TYPE_STRING, + "id", G_TYPE_ULONG, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "remove_filter", - 0, - "id", G_TYPE_ULONG, - NULL); + MESSAGE_OBJECT_PATH, "remove_filter", + 0, + "id", G_TYPE_ULONG, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "add_context_item", - 1, - "action", GTK_TYPE_ACTION, - "path", G_TYPE_STRING, - "id", G_TYPE_UINT, - NULL); + MESSAGE_OBJECT_PATH, "add_context_item", + 1, + "action", GTK_TYPE_ACTION, + "path", G_TYPE_STRING, + "id", G_TYPE_UINT, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "remove_context_item", - 0, - "id", G_TYPE_UINT, - NULL); + MESSAGE_OBJECT_PATH, "remove_context_item", + 0, + "id", G_TYPE_UINT, + NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "up", 0, NULL); @@ -705,24 +717,24 @@ register_methods (XedWindow *window, xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "refresh", 0, NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_show_hidden", - 0, - "active", G_TYPE_BOOLEAN, - NULL); + MESSAGE_OBJECT_PATH, "set_show_hidden", + 0, + "active", G_TYPE_BOOLEAN, + NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "set_show_binary", - 0, - "active", G_TYPE_BOOLEAN, - NULL); + MESSAGE_OBJECT_PATH, "set_show_binary", + 0, + "active", G_TYPE_BOOLEAN, + NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_bookmarks", 0, NULL); xed_message_bus_register (bus, MESSAGE_OBJECT_PATH, "show_files", 0, NULL); xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "get_view", - 1, - "view", XED_TYPE_FILE_BROWSER_VIEW, - NULL); + MESSAGE_OBJECT_PATH, "get_view", + 1, + "view", XED_TYPE_FILE_BROWSER_VIEW, + NULL); BUS_CONNECT (bus, get_root, data); BUS_CONNECT (bus, set_root, data); @@ -750,15 +762,15 @@ register_methods (XedWindow *window, static void store_row_inserted (XedFileBrowserStore *store, - GtkTreePath *path, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreePath *path, + GtkTreeIter *iter, + MessageCacheData *data) { guint flags = 0; gtk_tree_model_get (GTK_TREE_MODEL (store), iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) { @@ -771,18 +783,20 @@ store_row_inserted (XedFileBrowserStore *store, static void store_row_deleted (XedFileBrowserStore *store, - GtkTreePath *path, - MessageCacheData *data) + GtkTreePath *path, + MessageCacheData *data) { GtkTreeIter iter; guint flags = 0; if (!gtk_tree_model_get_iter (GTK_TREE_MODEL (store), &iter, path)) + { return; + } gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, - XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, - -1); + XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, + -1); if (!FILE_IS_DUMMY (flags) && !FILE_IS_FILTERED (flags)) { @@ -795,8 +809,8 @@ store_row_deleted (XedFileBrowserStore *store, static void store_virtual_root_changed (XedFileBrowserStore *store, - GParamSpec *spec, - MessageCacheData *data) + GParamSpec *spec, + MessageCacheData *data) { WindowData *wdata = get_window_data (data->window); GFile *vroot; @@ -804,11 +818,11 @@ store_virtual_root_changed (XedFileBrowserStore *store, vroot = xed_file_browser_store_get_virtual_root (store); if (!vroot) + { return; + } - xed_message_set (data->message, - "location", vroot, - NULL); + xed_message_set (data->message, "location", vroot, NULL); xed_message_bus_send_message_sync (wdata->bus, data->message); @@ -817,8 +831,8 @@ store_virtual_root_changed (XedFileBrowserStore *store, static void store_begin_loading (XedFileBrowserStore *store, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreeIter *iter, + MessageCacheData *data) { GtkTreePath *path; WindowData *wdata = get_window_data (data->window); @@ -833,8 +847,8 @@ store_begin_loading (XedFileBrowserStore *store, static void store_end_loading (XedFileBrowserStore *store, - GtkTreeIter *iter, - MessageCacheData *data) + GtkTreeIter *iter, + MessageCacheData *data) { GtkTreePath *path; WindowData *wdata = get_window_data (data->window); @@ -849,7 +863,7 @@ store_end_loading (XedFileBrowserStore *store, static void register_signals (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { XedMessageBus *bus = xed_window_get_message_bus (window); XedFileBrowserStore *store; @@ -864,141 +878,141 @@ register_signals (XedWindow *window, /* Register signals */ root_changed_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "root_changed", - 0, - "id", G_TYPE_STRING, - "location", G_TYPE_FILE, - NULL); + MESSAGE_OBJECT_PATH, "root_changed", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); begin_loading_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "begin_loading", - 0, - "id", G_TYPE_STRING, - "location", G_TYPE_FILE, - NULL); + MESSAGE_OBJECT_PATH, "begin_loading", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); end_loading_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "end_loading", - 0, - "id", G_TYPE_STRING, - "location", G_TYPE_FILE, - NULL); + MESSAGE_OBJECT_PATH, "end_loading", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + NULL); inserted_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "inserted", - 0, - "id", G_TYPE_STRING, - "location", G_TYPE_FILE, - "is_directory", G_TYPE_BOOLEAN, - NULL); + MESSAGE_OBJECT_PATH, "inserted", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + "is_directory", G_TYPE_BOOLEAN, + NULL); deleted_type = xed_message_bus_register (bus, - MESSAGE_OBJECT_PATH, "deleted", - 0, - "id", G_TYPE_STRING, - "location", G_TYPE_FILE, - "is_directory", G_TYPE_BOOLEAN, - NULL); + MESSAGE_OBJECT_PATH, "deleted", + 0, + "id", G_TYPE_STRING, + "location", G_TYPE_FILE, + "is_directory", G_TYPE_BOOLEAN, + NULL); store = xed_file_browser_widget_get_browser_store (widget); message = xed_message_type_instantiate (inserted_type, - "id", NULL, - "location", NULL, - "is_directory", FALSE, - NULL); + "id", NULL, + "location", NULL, + "is_directory", FALSE, + NULL); data = get_window_data (window); data->row_inserted_id = g_signal_connect_data (store, - "row-inserted", - G_CALLBACK (store_row_inserted), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + "row-inserted", + G_CALLBACK (store_row_inserted), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); message = xed_message_type_instantiate (deleted_type, - "id", NULL, - "location", NULL, - "is_directory", FALSE, - NULL); + "id", NULL, + "location", NULL, + "is_directory", FALSE, + NULL); data->row_deleted_id = g_signal_connect_data (store, - "row-deleted", - G_CALLBACK (store_row_deleted), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + "row-deleted", + G_CALLBACK (store_row_deleted), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); message = xed_message_type_instantiate (root_changed_type, - "id", NULL, - "location", NULL, - NULL); + "id", NULL, + "location", NULL, + NULL); data->root_changed_id = g_signal_connect_data (store, - "notify::virtual-root", - G_CALLBACK (store_virtual_root_changed), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + "notify::virtual-root", + G_CALLBACK (store_virtual_root_changed), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); message = xed_message_type_instantiate (begin_loading_type, - "id", NULL, - "location", NULL, - NULL); + "id", NULL, + "location", NULL, + NULL); data->begin_loading_id = g_signal_connect_data (store, - "begin_loading", - G_CALLBACK (store_begin_loading), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + "begin_loading", + G_CALLBACK (store_begin_loading), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); message = xed_message_type_instantiate (end_loading_type, - "id", NULL, - "location", NULL, - NULL); + "id", NULL, + "location", NULL, + NULL); data->end_loading_id = g_signal_connect_data (store, - "end_loading", - G_CALLBACK (store_end_loading), - message_cache_data_new (window, message), - (GClosureNotify)message_cache_data_free, - 0); + "end_loading", + G_CALLBACK (store_end_loading), + message_cache_data_new (window, message), + (GClosureNotify)message_cache_data_free, + 0); } static void message_unregistered (XedMessageBus *bus, - XedMessageType *message_type, - XedWindow *window) + XedMessageType *message_type, + XedWindow *window) { gchar *identifier = xed_message_type_identifier (xed_message_type_get_object_path (message_type), - xed_message_type_get_method (message_type)); + xed_message_type_get_method (message_type)); FilterData *data; WindowData *wdata = get_window_data (window); data = g_hash_table_lookup (wdata->filters, identifier); if (data) + { xed_file_browser_widget_remove_filter (wdata->widget, data->id); + } g_free (identifier); } void xed_file_browser_messages_register (XedWindow *window, - XedFileBrowserWidget *widget) + XedFileBrowserWidget *widget) { window_data_new (window, widget); register_methods (window, widget); register_signals (window, widget); - g_signal_connect (xed_window_get_message_bus (window), - "unregistered", - G_CALLBACK (message_unregistered), - window); + g_signal_connect (xed_window_get_message_bus (window), "unregistered", + G_CALLBACK (message_unregistered), window); } static void From fa31c65c2f8fe86c61636e7e54cf0d6cf6b8f449 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 15:57:16 -0800 Subject: [PATCH 08/21] filebrowser: Don't leak GFiles https://github.com/GNOME/gedit/commit/e2f792359a53db544824b4a113427374841f228a --- .../filebrowser/xed-file-browser-messages.c | 39 ++++++----- plugins/filebrowser/xed-file-browser-plugin.c | 70 ++++++++++++------- plugins/filebrowser/xed-file-browser-store.c | 1 + plugins/filebrowser/xed-file-browser-view.c | 48 +++++++++---- plugins/filebrowser/xed-file-browser-widget.c | 25 +++++-- 5 files changed, 116 insertions(+), 67 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-messages.c b/plugins/filebrowser/xed-file-browser-messages.c index 1d7d462..fc40712 100644 --- a/plugins/filebrowser/xed-file-browser-messages.c +++ b/plugins/filebrowser/xed-file-browser-messages.c @@ -323,37 +323,36 @@ set_item_message (WindowData *data, XedFileBrowserStore *store; GFile *location; guint flags = 0; - gchar *track_id; store = xed_file_browser_widget_get_browser_store (data->widget); - gtk_tree_model_get (GTK_TREE_MODEL (store), iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, XED_FILE_BROWSER_STORE_COLUMN_FLAGS, &flags, -1); - if (!location) + if (location) { - return; - } + gchar *track_id; - if (path && gtk_tree_path_get_depth (path) != 0) - { - track_id = track_row (data, store, path, location); - } - else - { - track_id = NULL; - } + if (path && gtk_tree_path_get_depth (path) != 0) + { + track_id = track_row (data, store, path, location); + } + else + { + track_id = NULL; + } - xed_message_set (message, "id", track_id, "location", location, NULL); + xed_message_set (message, "id", track_id, "location", location, NULL); - if (xed_message_has_key (message, "is_directory")) - { - xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL); + if (xed_message_has_key (message, "is_directory")) + { + xed_message_set (message, "is_directory", FILE_IS_DIR (flags), NULL); + } + + g_free (track_id); + g_object_unref (location); } - - g_free (track_id); } static gboolean @@ -387,6 +386,8 @@ custom_message_filter_func (XedFileBrowserWidget *widget, xed_message_bus_send_message_sync (wdata->bus, data->message); xed_message_get (data->message, "filter", &filter, NULL); + g_object_unref (location); + return !filter; } diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 2556ed4..c1af45f 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -349,9 +349,6 @@ on_action_open_terminal (GtkAction *action, XedFileBrowserPlugin *plugin) { XedFileBrowserPluginPrivate *priv = plugin->priv; - gchar *terminal; - gchar *local; - gchar *argv[2]; GFile *file; GtkTreeIter iter; @@ -366,29 +363,32 @@ on_action_open_terminal (GtkAction *action, store = xed_file_browser_widget_get_browser_store (priv->tree_widget); gtk_tree_model_get (GTK_TREE_MODEL (store), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &file, -1); - if (file == NULL) + if (file) { - return; + gchar *terminal; + gchar *local; + gchar *argv[2]; + + terminal = get_terminal (plugin); + + local = g_file_get_path (file); + + argv[0] = terminal; + argv[1] = NULL; + + g_spawn_async (local, + argv, + NULL, + G_SPAWN_SEARCH_PATH, + NULL, + NULL, + NULL, + NULL); + + g_free (terminal); + g_free (local); + g_object_unref (file); } - - terminal = get_terminal (plugin); - - local = g_file_get_path (file); - - argv[0] = terminal; - argv[1] = NULL; - - g_spawn_async (local, - argv, - NULL, - G_SPAWN_SEARCH_PATH, - NULL, - NULL, - NULL, - NULL); - - g_free (terminal); - g_free (local); } static void @@ -400,7 +400,6 @@ on_selection_changed_cb (GtkTreeSelection *selection, GtkTreeModel *model; GtkTreeIter iter; gboolean sensitive; - GFile *location; tree_view = GTK_TREE_VIEW (xed_file_browser_widget_get_browser_view (priv->tree_widget)); model = gtk_tree_view_get_model (tree_view); @@ -414,9 +413,19 @@ on_selection_changed_cb (GtkTreeSelection *selection, if (sensitive) { + GFile *location; + gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - sensitive = g_file_has_uri_scheme (location, "file"); + if (location) + { + sensitive = g_file_has_uri_scheme (location, "file"); + g_object_unref (location); + } + else + { + sensitive = FALSE; + } } gtk_action_set_sensitive (gtk_action_group_get_action (priv->single_selection_action_group, "OpenTerminal"), sensitive); @@ -927,11 +936,18 @@ get_filename_from_path (GtkTreeModel *model, { GtkTreeIter iter; GFile *location; + gchar *ret = NULL; gtk_tree_model_get_iter (model, &iter, path); gtk_tree_model_get (model, &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); - return xed_file_browser_utils_file_basename (location); + if (location) + { + ret = xed_file_browser_utils_file_basename (location); + g_object_unref (location); + } + + return ret; } static gboolean diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index 85fba73..e0f0e5b 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -1027,6 +1027,7 @@ xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source, ret = gtk_selection_data_set_uris (selection_data, uris); g_free (uris[0]); + g_object_unref (location); return ret; } diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index e2051e7..bfb9621 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -165,7 +165,6 @@ row_expanded (GtkTreeView *tree_view, GtkTreePath *path) { XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - GFile *location; if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_expanded) { @@ -179,9 +178,16 @@ row_expanded (GtkTreeView *tree_view, if (view->priv->restore_expand_state) { + GFile *location; + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); add_expand_state (view, location); + + if (location) + { + g_object_unref (location); + } } _xed_file_browser_store_iter_expanded (XED_FILE_BROWSER_STORE (view->priv->model), iter); @@ -193,7 +199,6 @@ row_collapsed (GtkTreeView *tree_view, GtkTreePath *path) { XedFileBrowserView *view = XED_FILE_BROWSER_VIEW (tree_view); - GFile *location; if (GTK_TREE_VIEW_CLASS (xed_file_browser_view_parent_class)->row_collapsed) { @@ -207,9 +212,16 @@ row_collapsed (GtkTreeView *tree_view, if (view->priv->restore_expand_state) { + GFile *location; + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); remove_expand_state (view, location); + + if (location) + { + g_object_unref (location); + } } _xed_file_browser_store_iter_collapsed (XED_FILE_BROWSER_STORE (view->priv->model), iter); @@ -747,7 +759,6 @@ fill_expand_state (XedFileBrowserView *view, { GtkTreePath * path; GtkTreeIter child; - GFile *location; if (!gtk_tree_model_iter_has_child (view->priv->model, iter)) { @@ -758,6 +769,8 @@ fill_expand_state (XedFileBrowserView *view, if (gtk_tree_view_row_expanded (GTK_TREE_VIEW (view), path)) { + GFile *location; + gtk_tree_model_get (view->priv->model, iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, @@ -765,6 +778,11 @@ fill_expand_state (XedFileBrowserView *view, -1); add_expand_state (view, location); + + if (location) + { + g_object_unref (location); + } } if (gtk_tree_model_iter_children (view->priv->model, &child, iter)) @@ -1269,7 +1287,6 @@ restore_expand_state (XedFileBrowserView *view, GtkTreeIter *iter) { GFile *location; - GtkTreePath *path; gtk_tree_model_get (GTK_TREE_MODEL (model), iter, @@ -1277,19 +1294,20 @@ restore_expand_state (XedFileBrowserView *view, &location, -1); - if (!location) + if (location) { - return; + GtkTreePath *path; + + path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); + + if (g_hash_table_lookup (view->priv->expand_state, location)) + { + gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE); + } + + gtk_tree_path_free (path); + g_object_unref (location); } - - path = gtk_tree_model_get_path (GTK_TREE_MODEL (model), iter); - - if (g_hash_table_lookup (view->priv->expand_state, location)) - { - gtk_tree_view_expand_row (GTK_TREE_VIEW (view), path, FALSE); - } - - gtk_tree_path_free (path); } static void diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 7d8a88a..ba6c8d0 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -2493,6 +2493,11 @@ file_open (XedFileBrowserWidget *obj, { g_signal_emit (obj, signals[LOCATION_ACTIVATED], 0, location); } + + if (location) + { + g_object_unref (location); + } } static gboolean @@ -2526,6 +2531,7 @@ directory_open (XedFileBrowserWidget *obj, } g_free (uri); + g_object_unref (location); } return result; @@ -2577,11 +2583,6 @@ on_virtual_root_changed (XedFileBrowserStore *model, XedFileBrowserWidget *obj) { GtkTreeIter iter; - GFile *location; - GtkTreeIter root; - GtkAction *action; - Location *loc; - GdkPixbuf *pixbuf; if (gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview)) != GTK_TREE_MODEL (obj->priv->file_store)) { @@ -2590,12 +2591,20 @@ on_virtual_root_changed (XedFileBrowserStore *model, if (xed_file_browser_store_get_iter_virtual_root (model, &iter)) { + GFile *location; + GtkTreeIter root; + gtk_tree_model_get (GTK_TREE_MODEL (model), &iter, XED_FILE_BROWSER_STORE_COLUMN_LOCATION, &location, -1); if (xed_file_browser_store_get_iter_root (model, &root)) { + GtkAction *action; + if (!obj->priv->changing_location) { + Location *loc; + GdkPixbuf *pixbuf; + /* Remove all items from obj->priv->current_location on */ if (obj->priv->current_location) { @@ -2632,7 +2641,6 @@ on_virtual_root_changed (XedFileBrowserStore *model, { g_object_unref (pixbuf); } - } action = gtk_action_group_get_action (obj->priv->action_group, "DirectoryUp"); @@ -2650,6 +2658,11 @@ on_virtual_root_changed (XedFileBrowserStore *model, } check_current_item (obj, TRUE); + + if (location) + { + g_object_unref (location); + } } else { From c27e7811328c7b43eb995fee88aabe2a0328c42e Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 16:35:38 -0800 Subject: [PATCH 09/21] filebrowser: Fix crash on open_terminal action https://github.com/GNOME/gedit/commit/0836fd05ac7887d9d437696b4162b536e8134778 --- plugins/filebrowser/xed-file-browser-plugin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index c1af45f..b292df8 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -487,7 +487,7 @@ add_popup_ui (XedFileBrowserPlugin *plugin) gtk_action_group_add_actions (action_group, extra_single_selection_actions, G_N_ELEMENTS (extra_single_selection_actions), - priv->window); + plugin); gtk_ui_manager_insert_action_group (manager, action_group, 0); priv->single_selection_action_group = action_group; From 1e2e106d70f27f92602cbbfb571c6ecd6a8b370c Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 17:31:58 -0800 Subject: [PATCH 10/21] filebrowser: Remove the back and forward toolbar dropdowns --- .../xed-file-browser-widget-ui.xml | 3 +- plugins/filebrowser/xed-file-browser-widget.c | 199 +----------------- 2 files changed, 5 insertions(+), 197 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-widget-ui.xml b/plugins/filebrowser/xed-file-browser-widget-ui.xml index 472fd18..cbbad99 100644 --- a/plugins/filebrowser/xed-file-browser-widget-ui.xml +++ b/plugins/filebrowser/xed-file-browser-widget-ui.xml @@ -1,6 +1,7 @@ - + + diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index ba6c8d0..994474c 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -149,9 +149,6 @@ struct _XedFileBrowserWidgetPrivate GList *locations; GList *current_location; gboolean changing_location; - GtkWidget *location_previous_menu; - GtkWidget *location_next_menu; - GtkWidget *current_location_menu_item; gboolean enable_delete; @@ -194,8 +191,6 @@ static void on_virtual_root_changed (XedFileBrowserStore *model, XedFileBrowserWidget *obj); static gboolean on_entry_filter_activate (XedFileBrowserWidget *obj); -static void on_location_jump_activate (GtkMenuItem *item, - XedFileBrowserWidget *obj); static void on_bookmarks_row_changed (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, @@ -373,11 +368,6 @@ xed_file_browser_widget_finalize (GObject *object) location_free ((Location *) (loc->data)); } - if (obj->priv->current_location_menu_item) - { - g_object_unref (obj->priv->current_location_menu_item); - } - g_list_free (obj->priv->locations); g_hash_table_destroy (obj->priv->bookmarks_hash); @@ -904,7 +894,6 @@ create_toolbar (XedFileBrowserWidget *obj, GError *error = NULL; GtkActionGroup *action_group; GtkWidget *toolbar; - GtkWidget *widget; GtkAction *action; gchar *ui_file; @@ -1008,44 +997,6 @@ create_toolbar (XedFileBrowserWidget *obj, gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU); - /* Previous directory menu tool item */ - obj->priv->location_previous_menu = gtk_menu_new (); - gtk_widget_show (obj->priv->location_previous_menu); - - widget = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_BACK)); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), obj->priv->location_previous_menu); - - g_object_set (widget, "label", _("Previous location"), NULL); - gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), _("Go to previous location")); - gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), _("Go to a previously opened location")); - - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); - g_object_set (action, - "is_important", TRUE, - "short_label", _("Previous location"), - NULL); - gtk_activatable_set_related_action (GTK_ACTIVATABLE (widget), action); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (widget), 0); - - /* Next directory menu tool item */ - obj->priv->location_next_menu = gtk_menu_new (); - gtk_widget_show (obj->priv->location_next_menu); - - widget = GTK_WIDGET (gtk_menu_tool_button_new_from_stock (GTK_STOCK_GO_FORWARD)); - gtk_menu_tool_button_set_menu (GTK_MENU_TOOL_BUTTON (widget), obj->priv->location_next_menu); - - g_object_set (widget, "label", _("Next location"), NULL); - gtk_tool_item_set_tooltip_text (GTK_TOOL_ITEM (widget), _("Go to next location")); - gtk_menu_tool_button_set_arrow_tooltip_text (GTK_MENU_TOOL_BUTTON (widget), _("Go to a previously opened location")); - - action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); - g_object_set (action, - "is_important", TRUE, - "short_label", _("Previous location"), - NULL); - gtk_activatable_set_related_action (GTK_ACTIVATABLE (widget), action); - gtk_toolbar_insert (GTK_TOOLBAR (toolbar), GTK_TOOL_ITEM (widget), 1); - gtk_box_pack_start (GTK_BOX (obj), toolbar, FALSE, FALSE, 0); gtk_widget_show (toolbar); @@ -1554,55 +1505,6 @@ get_topmost_file (GFile *file) return current; } -static GtkWidget * -create_goto_menu_item (XedFileBrowserWidget *obj, - GList *item, - GdkPixbuf *icon) -{ - GtkWidget *result; - GtkWidget *image; - gchar *unescape; - GdkPixbuf *pixbuf = NULL; - Location *loc; - - loc = (Location *) (item->data); - - if (!get_from_bookmark_file (obj, loc->virtual_root, &unescape, &pixbuf)) - { - unescape = xed_file_browser_utils_file_basename (loc->virtual_root); - - if (icon) - { - pixbuf = g_object_ref (icon); - } - } - - if (pixbuf) - { - image = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); - - gtk_widget_show (image); - - result = gtk_image_menu_item_new_with_label (unescape); - gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (result), image); - } - else - { - result = gtk_menu_item_new_with_label (unescape); - } - - g_object_set_data (G_OBJECT (result), LOCATION_DATA_KEY, item); - g_signal_connect (result, "activate", - G_CALLBACK (on_location_jump_activate), obj); - - gtk_widget_show (result); - - g_free (unescape); - - return result; -} - static GList * list_next_iterator (GList *list) { @@ -1631,12 +1533,7 @@ jump_to_location (XedFileBrowserWidget *obj, gboolean previous) { Location *loc; - GtkWidget *widget; - GList *children; - GList *child; GList *(*iter_func) (GList *); - GtkWidget *menu_from; - GtkWidget *menu_to; if (!obj->priv->locations) { @@ -1646,62 +1543,24 @@ jump_to_location (XedFileBrowserWidget *obj, if (previous) { iter_func = list_next_iterator; - menu_from = obj->priv->location_previous_menu; - menu_to = obj->priv->location_next_menu; } else { iter_func = list_prev_iterator; - menu_from = obj->priv->location_next_menu; - menu_to = obj->priv->location_previous_menu; } - children = gtk_container_get_children (GTK_CONTAINER (menu_from)); - child = children; + obj->priv->changing_location = TRUE; - /* This is the menuitem for the current location, which is the first - to be added to the menu */ - widget = obj->priv->current_location_menu_item; - - while (obj->priv->current_location != item) + if (obj->priv->current_location != item) { - if (widget) - { - /* Prepend the menu item to the menu */ - gtk_menu_shell_prepend (GTK_MENU_SHELL (menu_to), widget); - - g_object_unref (widget); - } - - widget = GTK_WIDGET (child->data); - - /* Make sure the widget isn't destroyed when removed */ - g_object_ref (widget); - gtk_container_remove (GTK_CONTAINER (menu_from), widget); - - obj->priv->current_location_menu_item = widget; + obj->priv->current_location = iter_func (obj->priv->current_location); if (obj->priv->current_location == NULL) { obj->priv->current_location = obj->priv->locations; - - if (obj->priv->current_location == item) - { - break; - } } - else - { - obj->priv->current_location = iter_func (obj->priv->current_location); - } - - child = child->next; } - g_list_free (children); - - obj->priv->changing_location = TRUE; - g_assert (obj->priv->current_location != NULL); loc = (Location *) (obj->priv->current_location->data); @@ -1715,9 +1574,6 @@ jump_to_location (XedFileBrowserWidget *obj, static void clear_next_locations (XedFileBrowserWidget *obj) { - GList *children; - GList *item; - if (obj->priv->current_location == NULL) { return; @@ -1729,15 +1585,6 @@ clear_next_locations (XedFileBrowserWidget *obj) obj->priv->locations = g_list_remove_link (obj->priv->locations, obj->priv->current_location->prev); } - children = gtk_container_get_children (GTK_CONTAINER (obj->priv->location_next_menu)); - - for (item = children; item; item = item->next) - { - gtk_container_remove (GTK_CONTAINER (obj->priv->location_next_menu), GTK_WIDGET (item->data)); - } - - g_list_free (children); - gtk_action_set_sensitive (gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"), FALSE); } @@ -2614,15 +2461,6 @@ on_virtual_root_changed (XedFileBrowserStore *model, loc = g_slice_new (Location); loc->root = xed_file_browser_store_get_root (model); loc->virtual_root = g_object_ref (location); - - if (obj->priv->current_location) - { - /* Add current location to the menu so we can go back - to it later */ - gtk_menu_shell_prepend (GTK_MENU_SHELL (obj->priv->location_previous_menu), - obj->priv->current_location_menu_item); - } - obj->priv->locations = g_list_prepend (obj->priv->locations, loc); gtk_tree_model_get (GTK_TREE_MODEL (model), @@ -2631,11 +2469,6 @@ on_virtual_root_changed (XedFileBrowserStore *model, &pixbuf, -1); obj->priv->current_location = obj->priv->locations; - obj->priv->current_location_menu_item = create_goto_menu_item (obj, - obj->priv->current_location, - pixbuf); - - g_object_ref_sink (obj->priv->current_location_menu_item); if (pixbuf) { @@ -2690,12 +2523,7 @@ on_model_set (GObject *gobject, { GtkAction *action; - gtk_menu_shell_prepend (GTK_MENU_SHELL (obj->priv->location_previous_menu), - obj->priv->current_location_menu_item); - - g_object_unref (obj->priv->current_location_menu_item); obj->priv->current_location = NULL; - obj->priv->current_location_menu_item = NULL; action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); gtk_action_set_sensitive (action, TRUE); @@ -2914,27 +2742,6 @@ on_entry_filter_activate (XedFileBrowserWidget *obj) return FALSE; } -static void -on_location_jump_activate (GtkMenuItem *item, - XedFileBrowserWidget *obj) -{ - GList *location; - - location = g_object_get_data (G_OBJECT (item), LOCATION_DATA_KEY); - - if (obj->priv->current_location) - { - jump_to_location (obj, location, - g_list_position (obj->priv->locations, location) > - g_list_position (obj->priv->locations, obj->priv->current_location)); - } - else - { - jump_to_location (obj, location, TRUE); - } - -} - static void on_bookmarks_row_changed (GtkTreeModel *model, GtkTreePath *path, From 44f60af7a785eae17480cc3a70c42080e80e79ea Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 19:47:43 -0800 Subject: [PATCH 11/21] filebrowser: Support new location of gtk bookmarks file Also remove an old bit of code that was left over when some of the ifdef's for windows and mac specific code was removed. https://github.com/GNOME/gedit/commit/54d69eb93c36bf71dc2f3d611a48122dde754237 --- .../filebrowser/xed-file-bookmarks-store.c | 183 ++++++++++-------- 1 file changed, 107 insertions(+), 76 deletions(-) diff --git a/plugins/filebrowser/xed-file-bookmarks-store.c b/plugins/filebrowser/xed-file-bookmarks-store.c index 6074b5d..320c8e6 100644 --- a/plugins/filebrowser/xed-file-bookmarks-store.c +++ b/plugins/filebrowser/xed-file-bookmarks-store.c @@ -234,23 +234,23 @@ init_special_directories (XedFileBookmarksStore * model) g_object_unref (file); } - path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); - if (path != NULL) - { - file = g_file_new_for_path (path); - add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP | - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); - g_object_unref (file); - } + // path = g_get_user_special_dir (G_USER_DIRECTORY_DESKTOP); + // if (path != NULL) + // { + // file = g_file_new_for_path (path); + // add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DESKTOP | + // XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); + // g_object_unref (file); + // } - path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); - if (path != NULL) - { - file = g_file_new_for_path (path); - add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS | - XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); - g_object_unref (file); - } + // path = g_get_user_special_dir (G_USER_DIRECTORY_DOCUMENTS); + // if (path != NULL) + // { + // file = g_file_new_for_path (path); + // add_file (model, file, NULL, XED_FILE_BOOKMARKS_STORE_IS_DOCUMENTS | + // XED_FILE_BOOKMARKS_STORE_IS_SPECIAL_DIR, NULL); + // g_object_unref (file); + // } file = g_file_new_for_uri ("file:///"); add_file (model, file, _("File System"), XED_FILE_BOOKMARKS_STORE_IS_ROOT, NULL); @@ -514,75 +514,106 @@ add_bookmark (XedFileBookmarksStore * model, return ret; } -static void -init_bookmarks (XedFileBookmarksStore * model) +static gchar * +get_bookmarks_file (void) +{ + return g_build_filename (g_get_user_config_dir (), "gtk-3.0", "bookmarks", NULL); +} + +static gchar * +get_legacy_bookmarks_file (void) +{ + return g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL); +} + +static gboolean +parse_bookmarks_file (XedFileBookmarksStore *model, + const gchar *bookmarks, + gboolean *added) + { - gchar *bookmarks; GError *error = NULL; gchar *contents; gchar **lines; gchar **line; - gboolean added = FALSE; - /* Read the bookmarks file */ - bookmarks = g_build_filename (g_get_home_dir (), ".gtk-bookmarks", NULL); - - if (g_file_get_contents (bookmarks, &contents, NULL, &error)) - { - lines = g_strsplit (contents, "\n", 0); - - for (line = lines; *line; ++line) - { - if (**line) - { - GFile *location; - gchar *pos; - gchar *name; - - /* CHECK: is this really utf8? */ - pos = g_utf8_strchr (*line, -1, ' '); - - if (pos != NULL) - { - *pos = '\0'; - name = pos + 1; - } - else - { - name = NULL; - } - - /* the bookmarks file should contain valid - * URIs, but paranoia is good */ - location = g_file_new_for_uri (*line); - if (xed_utils_is_valid_location (location)) - { - added |= add_bookmark (model, name, *line); - } - g_object_unref (location); - } - } - - g_strfreev (lines); - g_free (contents); - - /* Add a watch */ - if (model->priv->bookmarks_monitor == NULL) - { - GFile * file; - - file = g_file_new_for_path (bookmarks); - model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); - g_object_unref (file); - - g_signal_connect (model->priv->bookmarks_monitor, "changed", - (GCallback)on_bookmarks_file_changed, model); - } - } - else + if (!g_file_get_contents (bookmarks, &contents, NULL, &error)) { /* The bookmarks file doesn't exist (which is perfectly fine) */ g_error_free (error); + + return FALSE; + } + + lines = g_strsplit (contents, "\n", 0); + + for (line = lines; *line; ++line) + { + if (**line) + { + GFile *location; + + gchar *pos; + gchar *name; + + /* CHECK: is this really utf8? */ + pos = g_utf8_strchr (*line, -1, ' '); + + if (pos != NULL) + { + *pos = '\0'; + name = pos + 1; + } + else + { + name = NULL; + } + + /* the bookmarks file should contain valid + * URIs, but paranoia is good */ + location = g_file_new_for_uri (*line); + if (xed_utils_is_valid_location (location)) + { + *added |= add_bookmark (model, name, *line); + } + g_object_unref (location); + } + } + + g_strfreev (lines); + g_free (contents); + + /* Add a watch */ + if (model->priv->bookmarks_monitor == NULL) + { + GFile * file; + + file = g_file_new_for_path (bookmarks); + model->priv->bookmarks_monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); + g_object_unref (file); + + g_signal_connect (model->priv->bookmarks_monitor, "changed", + G_CALLBACK (on_bookmarks_file_changed), model); + } + + return TRUE; +} + +static void +init_bookmarks (XedFileBookmarksStore *model) +{ + gchar *bookmarks; + gboolean added = FALSE; + + bookmarks = get_bookmarks_file (); + + if (!parse_bookmarks_file (model, bookmarks, &added)) + { + g_free (bookmarks); + + /* try the old location (gtk <= 3.4) */ + bookmarks = get_legacy_bookmarks_file (); + parse_bookmarks_file (model, bookmarks, &added); } if (added) From 14cc61975125684e631be6f0a39eea895f925f07 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 19:57:36 -0800 Subject: [PATCH 12/21] xed-file-browser-utils.c: Clean up code style --- plugins/filebrowser/xed-file-browser-utils.c | 214 +++++++++---------- 1 file changed, 102 insertions(+), 112 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-utils.c b/plugins/filebrowser/xed-file-browser-utils.c index 2c3fbb7..aae2fd9 100644 --- a/plugins/filebrowser/xed-file-browser-utils.c +++ b/plugins/filebrowser/xed-file-browser-utils.c @@ -1,5 +1,5 @@ /* - * xed-file-bookmarks-store.c - Xed plugin providing easy file access + * xed-file-browser-utils.c - Xed plugin providing easy file access * from the sidepanel * * Copyright (C) 2006 - Jesse van den Kieboom @@ -23,163 +23,153 @@ #include static GdkPixbuf * -process_icon_pixbuf (GdkPixbuf * pixbuf, - gchar const * name, - gint size, - GError * error) +process_icon_pixbuf (GdkPixbuf *pixbuf, + gchar const *name, + gint size, + GError *error) { - GdkPixbuf * scale; + GdkPixbuf *scale; - if (error != NULL) { - g_warning ("Could not load theme icon %s: %s", - name, - error->message); - g_error_free (error); - } + if (error != NULL) + { + g_warning ("Could not load theme icon %s: %s", name, error->message); + g_error_free (error); + } - if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size) { - scale = gdk_pixbuf_scale_simple (pixbuf, - size, - size, - GDK_INTERP_BILINEAR); - g_object_unref (pixbuf); - pixbuf = scale; - } + if (pixbuf && gdk_pixbuf_get_width (pixbuf) > size) + { + scale = gdk_pixbuf_scale_simple (pixbuf, size, size, GDK_INTERP_BILINEAR); + g_object_unref (pixbuf); + pixbuf = scale; + } - return pixbuf; + return pixbuf; } GdkPixbuf * -xed_file_browser_utils_pixbuf_from_theme (gchar const * name, - GtkIconSize size) +xed_file_browser_utils_pixbuf_from_theme (gchar const *name, + GtkIconSize size) { - gint width; - GError *error = NULL; - GdkPixbuf *pixbuf; + gint width; + GError *error = NULL; + GdkPixbuf *pixbuf; - gtk_icon_size_lookup (size, &width, NULL); + gtk_icon_size_lookup (size, &width, NULL); - pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), - name, - width, - 0, - &error); + pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), name, width, 0, &error); - pixbuf = process_icon_pixbuf (pixbuf, name, width, error); + pixbuf = process_icon_pixbuf (pixbuf, name, width, error); - return pixbuf; + return pixbuf; } GdkPixbuf * -xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, - GtkIconSize size) +xed_file_browser_utils_pixbuf_from_icon (GIcon *icon, + GtkIconSize size) { - GdkPixbuf * ret = NULL; - GtkIconTheme *theme; - GtkIconInfo *info; - gint width; + GdkPixbuf *ret = NULL; + GtkIconTheme *theme; + GtkIconInfo *info; + gint width; - if (!icon) - return NULL; + if (!icon) + { + return NULL; + } - theme = gtk_icon_theme_get_default (); - gtk_icon_size_lookup (size, &width, NULL); + theme = gtk_icon_theme_get_default (); + gtk_icon_size_lookup (size, &width, NULL); - info = gtk_icon_theme_lookup_by_gicon (theme, - icon, - width, - GTK_ICON_LOOKUP_USE_BUILTIN); + info = gtk_icon_theme_lookup_by_gicon (theme, icon, width, GTK_ICON_LOOKUP_USE_BUILTIN); - if (!info) - return NULL; + if (!info) + { + return NULL; + } - ret = gtk_icon_info_load_icon (info, NULL); - gtk_icon_info_free (info); + ret = gtk_icon_info_load_icon (info, NULL); + gtk_icon_info_free (info); - return ret; + return ret; } GdkPixbuf * -xed_file_browser_utils_pixbuf_from_file (GFile * file, - GtkIconSize size) +xed_file_browser_utils_pixbuf_from_file (GFile *file, + GtkIconSize size) { - GIcon * icon; - GFileInfo * info; - GdkPixbuf * ret = NULL; + GIcon *icon; + GFileInfo *info; + GdkPixbuf *ret = NULL; - info = g_file_query_info (file, - G_FILE_ATTRIBUTE_STANDARD_ICON, - G_FILE_QUERY_INFO_NONE, - NULL, - NULL); + info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_ICON, G_FILE_QUERY_INFO_NONE, NULL, NULL); - if (!info) - return NULL; + if (!info) + { + return NULL; + } - icon = g_file_info_get_icon (info); - if (icon != NULL) - ret = xed_file_browser_utils_pixbuf_from_icon (icon, size); + icon = g_file_info_get_icon (info); + if (icon != NULL) + { + ret = xed_file_browser_utils_pixbuf_from_icon (icon, size); + } - g_object_unref (info); + g_object_unref (info); - return ret; + return ret; } gchar * -xed_file_browser_utils_file_basename (GFile * file) +xed_file_browser_utils_file_basename (GFile *file) { - return xed_utils_basename_for_display (file); + return xed_utils_basename_for_display (file); } gboolean -xed_file_browser_utils_confirmation_dialog (XedWindow * window, - GtkMessageType type, - gchar const *message, - gchar const *secondary, - gchar const * button_stock, - gchar const * button_label) +xed_file_browser_utils_confirmation_dialog (XedWindow *window, + GtkMessageType type, + gchar const *message, + gchar const *secondary, + gchar const *button_stock, + gchar const *button_label) { - GtkWidget *dlg; - gint ret; - GtkWidget *button; + GtkWidget *dlg; + gint ret; + GtkWidget *button; - dlg = gtk_message_dialog_new (GTK_WINDOW (window), - GTK_DIALOG_MODAL | - GTK_DIALOG_DESTROY_WITH_PARENT, - type, - GTK_BUTTONS_NONE, "%s", message); + dlg = gtk_message_dialog_new (GTK_WINDOW (window), + GTK_DIALOG_MODAL | + GTK_DIALOG_DESTROY_WITH_PARENT, + type, + GTK_BUTTONS_NONE, "%s", message); - if (secondary) - gtk_message_dialog_format_secondary_text - (GTK_MESSAGE_DIALOG (dlg), "%s", secondary); + if (secondary) + { + gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), "%s", secondary); + } - /* Add a cancel button */ - button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); - gtk_widget_show (button); + /* Add a cancel button */ + button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); + gtk_widget_show (button); - gtk_widget_set_can_default (button, TRUE); - gtk_dialog_add_action_widget (GTK_DIALOG (dlg), - button, - GTK_RESPONSE_CANCEL); + gtk_widget_set_can_default (button, TRUE); + gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, GTK_RESPONSE_CANCEL); - /* Add custom button */ - button = gtk_button_new_from_stock (button_stock); + /* Add custom button */ + button = gtk_button_new_from_stock (button_stock); - if (button_label) { - gtk_button_set_use_stock (GTK_BUTTON (button), FALSE); - gtk_button_set_label (GTK_BUTTON (button), button_label); - } + if (button_label) + { + gtk_button_set_use_stock (GTK_BUTTON (button), FALSE); + gtk_button_set_label (GTK_BUTTON (button), button_label); + } - gtk_widget_show (button); - gtk_widget_set_can_default (button, TRUE); - gtk_dialog_add_action_widget (GTK_DIALOG (dlg), - button, - GTK_RESPONSE_OK); + gtk_widget_show (button); + gtk_widget_set_can_default (button, TRUE); + gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, GTK_RESPONSE_OK); - ret = gtk_dialog_run (GTK_DIALOG (dlg)); - gtk_widget_destroy (dlg); + ret = gtk_dialog_run (GTK_DIALOG (dlg)); + gtk_widget_destroy (dlg); - return (ret == GTK_RESPONSE_OK); + return (ret == GTK_RESPONSE_OK); } - -// ex:ts=8:noet: From 80509d36a33d875d83090ff366cadf2831f97fec Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 20:00:13 -0800 Subject: [PATCH 13/21] filebrowser: "Rename" menu entry should have an ellipsis --- plugins/filebrowser/xed-file-browser-widget.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 994474c..e251c49 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -856,7 +856,7 @@ static const GtkActionEntry tree_actions_single_most_selection[] = static const GtkActionEntry tree_actions_single_selection[] = { - {"FileRename", NULL, N_("_Rename"), NULL, + {"FileRename", NULL, N_("_Rename..."), NULL, N_("Rename selected file or folder"), G_CALLBACK (on_action_file_rename)} }; From 96378408867f1a5df98d3d99e4f4115e86728e57 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 20:07:16 -0800 Subject: [PATCH 14/21] filebrowser: use Untitled File/Folder for new file/folders https://github.com/GNOME/gedit/commit/e7e404a32a62a1e19d8f86aaa4ddfc9e7b172bb0 --- plugins/filebrowser/xed-file-browser-store.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index e0f0e5b..c91b1b2 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -3860,7 +3860,7 @@ xed_file_browser_store_new_file (XedFileBrowserStore *model, parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); /* Translators: This is the default name of new files created by the file browser pane. */ - file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("file")); + file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("Untitled File")); stream = g_file_create (file, G_FILE_CREATE_NONE, NULL, &error); @@ -3915,7 +3915,7 @@ xed_file_browser_store_new_directory (XedFileBrowserStore *model, parent_node = FILE_BROWSER_NODE_DIR (parent->user_data); /* Translators: This is the default name of new directories created by the file browser pane. */ - file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("directory")); + file = unique_new_name (((FileBrowserNode *) parent_node)->file, _("Untitled Folder")); if (!g_file_make_directory (file, NULL, &error)) { From 87238194c31e9ac75553b0ac8b2d65e375b75555 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Mon, 13 Feb 2017 20:24:42 -0800 Subject: [PATCH 15/21] filebrowser: don't use deprecated GIOScheduler https://github.com/GNOME/gedit/commit/2d1eb80d3d670d1420635e25042de248b6ce8fbb --- plugins/filebrowser/xed-file-browser-store.c | 206 ++++++++++--------- 1 file changed, 106 insertions(+), 100 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index c91b1b2..c812774 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -131,12 +131,12 @@ static FileBrowserNode *model_find_node (XedFileBrowserStore *model, FileBrowserNode *node, GFile *uri); static void model_remove_node (XedFileBrowserStore *model, - FileBrowserNode *node, - GtkTreePath *path, - gboolean free_nodes); + FileBrowserNode *node, + GtkTreePath *path, + gboolean free_nodes); static void set_virtual_root_from_node (XedFileBrowserStore *model, - FileBrowserNode *node); + FileBrowserNode *node); static void xed_file_browser_store_iface_init (GtkTreeModelIface *iface); static GtkTreeModelFlags xed_file_browser_store_get_flags (GtkTreeModel *tree_model); @@ -158,42 +158,44 @@ static gboolean xed_file_browser_store_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent); static gboolean xed_file_browser_store_iter_has_child (GtkTreeModel *tree_model, - GtkTreeIter *iter); + GtkTreeIter *iter); static gint xed_file_browser_store_iter_n_children (GtkTreeModel *tree_model, - GtkTreeIter * iter); -static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent, - gint n); -static gboolean xed_file_browser_store_iter_parent (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * child); -static void xed_file_browser_store_row_inserted (GtkTreeModel * tree_model, - GtkTreePath * path, - GtkTreeIter * iter); + GtkTreeIter *iter); +static gboolean xed_file_browser_store_iter_nth_child (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *parent, + gint n); +static gboolean xed_file_browser_store_iter_parent (GtkTreeModel *tree_model, + GtkTreeIter *iter, + GtkTreeIter *child); +static void xed_file_browser_store_row_inserted (GtkTreeModel *tree_model, + GtkTreePath *path, + GtkTreeIter *iter); -static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface * iface); -static gboolean xed_file_browser_store_row_draggable (GtkTreeDragSource * drag_source, - GtkTreePath * path); -static gboolean xed_file_browser_store_drag_data_delete (GtkTreeDragSource * drag_source, - GtkTreePath * path); -static gboolean xed_file_browser_store_drag_data_get (GtkTreeDragSource * drag_source, - GtkTreePath * path, - GtkSelectionData * selection_data); +static void xed_file_browser_store_drag_source_init (GtkTreeDragSourceIface *iface); +static gboolean xed_file_browser_store_row_draggable (GtkTreeDragSource *drag_source, + GtkTreePath *path); +static gboolean xed_file_browser_store_drag_data_delete (GtkTreeDragSource *drag_source, + GtkTreePath *path); +static gboolean xed_file_browser_store_drag_data_get (GtkTreeDragSource *drag_source, + GtkTreePath *path, + GtkSelectionData *selection_data); -static void file_browser_node_free (XedFileBrowserStore * model, - FileBrowserNode * node); -static void model_add_node (XedFileBrowserStore * model, - FileBrowserNode * child, - FileBrowserNode * parent); -static void model_clear (XedFileBrowserStore * model, - gboolean free_nodes); -static gint model_sort_default (FileBrowserNode * node1, - FileBrowserNode * node2); -static void model_check_dummy (XedFileBrowserStore * model, - FileBrowserNode * node); -static void next_files_async (GFileEnumerator * enumerator, - AsyncNode * async); +static void file_browser_node_free (XedFileBrowserStore *model, + FileBrowserNode *node); +static void model_add_node (XedFileBrowserStore *model, + FileBrowserNode *child, + FileBrowserNode *parent); +static void model_clear (XedFileBrowserStore *model, + gboolean free_nodes); +static gint model_sort_default (FileBrowserNode *node1, + FileBrowserNode *node2); +static void model_check_dummy (XedFileBrowserStore *model, + FileBrowserNode *node); +static void next_files_async (GFileEnumerator *enumerator, + AsyncNode *async); + +static void delete_files (AsyncData *data); G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedFileBrowserStore, xed_file_browser_store, G_TYPE_OBJECT, @@ -3655,93 +3657,101 @@ emit_no_trash (AsyncData *data) return ret; } -typedef struct +static void +delete_file_finished (GFile *file, + GAsyncResult *res, + AsyncData *data) { - XedFileBrowserStore *model; - GFile *file; -} IdleDelete; - -static gboolean -file_deleted (IdleDelete *data) -{ - FileBrowserNode *node; - node = model_find_node (data->model, NULL, data->file); - - if (node != NULL) - { - model_remove_node (data->model, node, NULL, TRUE); - } - - return FALSE; -} - -static gboolean -delete_files (GIOSchedulerJob *job, - GCancellable *cancellable, - AsyncData *data) -{ - GFile *file; GError *error = NULL; - gboolean ret; - gint code; - IdleDelete delete; - - /* Check if our job is done */ - if (!data->iter) - { - return FALSE; - } - - /* Move a file to the trash */ - file = G_FILE (data->iter->data); + gboolean ok; if (data->trash) { - ret = g_file_trash (file, cancellable, &error); + ok = g_file_trash_finish (file, res, &error); } else { - ret = g_file_delete (file, cancellable, &error); + ok = g_file_delete_finish (file, res, &error); } - if (ret) + if (ok) { - delete.model = data->model; - delete.file = file; + /* Remove the file from the model */ + FileBrowserNode *node = model_find_node (data->model, NULL, file); - /* Remove the file from the model in the main loop */ - g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)file_deleted, &delete, NULL); + if (node != NULL) + { + model_remove_node (data->model, node, NULL, TRUE); + } + + /* Process the next file */ + data->iter = data->iter->next; } - else if (!ret && error) + else if (!ok && error != NULL) { - code = error->code; + gint code = error->code; g_error_free (error); if (data->trash && code == G_IO_ERROR_NOT_SUPPORTED) { - /* Trash is not supported on this system ... */ - if (g_io_scheduler_job_send_to_mainloop (job, (GSourceFunc)emit_no_trash, data, NULL)) + /* Trash is not supported on this system. Ask the user + * if he wants to delete completely the files instead. + */ + if (emit_no_trash (data)) { /* Changes this into a delete job */ data->trash = FALSE; data->iter = data->files; - - return TRUE; } - - /* End the job */ - return FALSE; + else + { + /* End the job */ + async_data_free (data); + return; + } } else if (code == G_IO_ERROR_CANCELLED) { - /* Job has been cancelled, just let the job end */ - return FALSE; + /* Job has been cancelled, end the job */ + async_data_free (data); + return; } } - /* Process the next item */ - data->iter = data->iter->next; - return TRUE; + /* Continue the job */ + delete_files (data); +} + +static void +delete_files (AsyncData *data) +{ + GFile *file; + + /* Check if our job is done */ + if (data->iter == NULL) + { + async_data_free (data); + return; + } + + file = G_FILE (data->iter->data); + + if (data->trash) + { + g_file_trash_async (file, + G_PRIORITY_DEFAULT, + data->cancellable, + (GAsyncReadyCallback)delete_file_finished, + data); + } + else + { + g_file_delete_async (file, + G_PRIORITY_DEFAULT, + data->cancellable, + (GAsyncReadyCallback)delete_file_finished, + data); + } } XedFileBrowserStoreResult @@ -3801,11 +3811,7 @@ xed_file_browser_store_delete_all (XedFileBrowserStore *model, model->priv->async_handles = g_slist_prepend (model->priv->async_handles, data); - g_io_scheduler_push_job ((GIOSchedulerJobFunc)delete_files, - data, - (GDestroyNotify)async_data_free, - G_PRIORITY_DEFAULT, - data->cancellable); + delete_files (data); g_list_free (rows); return XED_FILE_BROWSER_STORE_RESULT_OK; From bf1133231bacaee3abd2950ac4081f27f01b4e17 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 03:25:42 -0800 Subject: [PATCH 16/21] filebrowser: Redesign the toolbar in filebrowser --- .../xed-file-browser-widget-ui.xml | 6 - plugins/filebrowser/xed-file-browser-widget.c | 114 ++++++------------ 2 files changed, 38 insertions(+), 82 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-widget-ui.xml b/plugins/filebrowser/xed-file-browser-widget-ui.xml index cbbad99..a313c86 100644 --- a/plugins/filebrowser/xed-file-browser-widget-ui.xml +++ b/plugins/filebrowser/xed-file-browser-widget-ui.xml @@ -3,13 +3,7 @@ - - - - - - diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index e251c49..745a950 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -60,7 +60,6 @@ enum enum { - COLUMN_INDENT, COLUMN_ICON, COLUMN_NAME, COLUMN_FILE, @@ -574,8 +573,7 @@ static void insert_path_item (XedFileBrowserWidget *obj, GFile *file, GtkTreeIter *after, - GtkTreeIter *iter, - guint indent) + GtkTreeIter *iter) { gchar *unescape; GdkPixbuf *icon = NULL; @@ -594,7 +592,6 @@ insert_path_item (XedFileBrowserWidget *obj, gtk_tree_store_set (obj->priv->combo_model, iter, - COLUMN_INDENT, indent, COLUMN_ICON, icon, COLUMN_NAME, unescape, COLUMN_FILE, file, @@ -633,33 +630,6 @@ combo_set_active_by_id (XedFileBrowserWidget *obj, } } -static guint -uri_num_parents (GFile *from, - GFile *to) -{ - /* Determine the number of 'levels' to get from #from to #to. */ - guint parents = 0; - GFile *parent; - - if (from == NULL) - { - return 0; - } - - g_object_ref (from); - - while ((parent = g_file_get_parent (from)) && !(to && g_file_equal (from, to))) - { - g_object_unref (from); - from = parent; - - ++parents; - } - - g_object_unref (from); - return parents; -} - static void insert_location_path (XedFileBrowserWidget *obj) { @@ -668,7 +638,6 @@ insert_location_path (XedFileBrowserWidget *obj) GFile *tmp; GtkTreeIter separator; GtkTreeIter iter; - guint indent; if (!obj->priv->current_location) { @@ -681,11 +650,9 @@ insert_location_path (XedFileBrowserWidget *obj) current = loc->virtual_root; combo_find_by_id (obj, SEPARATOR_ID, &separator); - indent = uri_num_parents (loc->virtual_root, loc->root); - while (current != NULL) { - insert_path_item (obj, current, &separator, &iter, indent--); + insert_path_item (obj, current, &separator, &iter); if (current == loc->virtual_root) { @@ -759,49 +726,18 @@ fill_combo_model (XedFileBrowserWidget *obj) gtk_combo_box_set_active (GTK_COMBO_BOX (obj->priv->combo), 0); } -static void -indent_cell_data_func (GtkCellLayout *cell_layout, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - gchar *indent; - guint num; - - gtk_tree_model_get (model, iter, COLUMN_INDENT, &num, -1); - - if (num == 0) - { - g_object_set (cell, "text", "", NULL); - } - else - { - indent = g_strnfill (num * 2, ' '); - - g_object_set (cell, "text", indent, NULL); - g_free (indent); - } -} - static void create_combo (XedFileBrowserWidget *obj) { GtkCellRenderer *renderer; obj->priv->combo_model = gtk_tree_store_new (N_COLUMNS, - G_TYPE_UINT, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_FILE, G_TYPE_UINT); obj->priv->combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (obj->priv->combo_model)); - renderer = gtk_cell_renderer_text_new (); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), renderer, FALSE); - gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (obj->priv->combo), - renderer, indent_cell_data_func, obj, NULL); - renderer = gtk_cell_renderer_pixbuf_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (obj->priv->combo), renderer, FALSE); gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (obj->priv->combo), renderer, "pixbuf", COLUMN_ICON); @@ -812,13 +748,9 @@ create_combo (XedFileBrowserWidget *obj) g_object_set (renderer, "ellipsize-set", TRUE, "ellipsize", PANGO_ELLIPSIZE_END, NULL); - gtk_box_pack_start (GTK_BOX (obj), GTK_WIDGET (obj->priv->combo), FALSE, FALSE, 0); - fill_combo_model (obj); g_signal_connect (obj->priv->combo, "changed", G_CALLBACK (on_combo_changed), obj); - - gtk_widget_show (obj->priv->combo); } static GtkActionEntry toplevel_actions[] = @@ -894,6 +826,9 @@ create_toolbar (XedFileBrowserWidget *obj, GError *error = NULL; GtkActionGroup *action_group; GtkWidget *toolbar; + GtkWidget *button; + GtkWidget *image; + GtkWidget *button_box; GtkAction *action; gchar *ui_file; @@ -987,18 +922,45 @@ create_toolbar (XedFileBrowserWidget *obj, gtk_ui_manager_insert_action_group (manager, action_group, 0); obj->priv->bookmark_action_group = action_group; + toolbar = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3); + gtk_container_set_border_width (GTK_CONTAINER (toolbar), 3); + button_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); + gtk_style_context_add_class (gtk_widget_get_style_context (button_box), "linked"); + gtk_box_pack_start (GTK_BOX (toolbar), button_box, FALSE, FALSE, 0); + action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryPrevious"); gtk_action_set_sensitive (action, FALSE); + button = gtk_button_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "small-button"); + image = gtk_image_new (); + gtk_button_set_image (GTK_BUTTON (button), image); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action); + gtk_button_set_label (GTK_BUTTON (button), NULL); + gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0); action = gtk_action_group_get_action (obj->priv->action_group_sensitive, "DirectoryNext"); gtk_action_set_sensitive (action, FALSE); + button = gtk_button_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "small-button"); + image = gtk_image_new (); + gtk_button_set_image (GTK_BUTTON (button), image); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action); + gtk_button_set_label (GTK_BUTTON (button), NULL); + gtk_box_pack_start (GTK_BOX (button_box), button, FALSE, FALSE, 0); - toolbar = gtk_ui_manager_get_widget (manager, "/ToolBar"); - gtk_toolbar_set_style (GTK_TOOLBAR (toolbar), GTK_TOOLBAR_ICONS); - gtk_toolbar_set_icon_size (GTK_TOOLBAR (toolbar), GTK_ICON_SIZE_MENU); + action = gtk_action_group_get_action (obj->priv->action_group, "DirectoryUp"); + button = gtk_button_new (); + gtk_style_context_add_class (gtk_widget_get_style_context (button), "small-button"); + image = gtk_image_new (); + gtk_button_set_image (GTK_BUTTON (button), image); + gtk_activatable_set_related_action (GTK_ACTIVATABLE (button), action); + gtk_button_set_label (GTK_BUTTON (button), NULL); + gtk_box_pack_start (GTK_BOX (toolbar), button, FALSE, FALSE, 0); + create_combo (obj); + gtk_box_pack_start (GTK_BOX (toolbar), obj->priv->combo, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (obj), toolbar, FALSE, FALSE, 0); - gtk_widget_show (toolbar); + gtk_widget_show_all (toolbar); set_enable_delete (obj, obj->priv->enable_delete); } @@ -1143,7 +1105,7 @@ create_tree (XedFileBrowserWidget * obj) filter_real, obj); sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_ETCHED_IN); + gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw), GTK_SHADOW_NONE); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER (sw), GTK_WIDGET (obj->priv->treeview)); @@ -1699,7 +1661,7 @@ xed_file_browser_widget_new (const gchar *data_dir) XedFileBrowserWidget *obj = g_object_new (XED_TYPE_FILE_BROWSER_WIDGET, NULL); create_toolbar (obj, data_dir); - create_combo (obj); + // create_combo (obj); create_tree (obj); create_filter (obj); From ee1448d73fe940ad412cd1ea8fe06aa2b02a2b27 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 03:38:48 -0800 Subject: [PATCH 17/21] filebrowser: Activate selected item when search is complete https://github.com/GNOME/gedit/commit/0701c9c4639c93e6f7b3840d0adff46b88ea6569 --- plugins/filebrowser/xed-file-browser-view.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/plugins/filebrowser/xed-file-browser-view.c b/plugins/filebrowser/xed-file-browser-view.c index bfb9621..20dac58 100644 --- a/plugins/filebrowser/xed-file-browser-view.c +++ b/plugins/filebrowser/xed-file-browser-view.c @@ -444,6 +444,20 @@ activate_selected_items (XedFileBrowserView *view) } } +static void +row_activated (GtkTreeView *tree_view, + GtkTreePath *path, + GtkTreeViewColumn *column) +{ + GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view); + + /* Make sure the activated row is the only one selected */ + gtk_tree_selection_unselect_all (selection); + gtk_tree_selection_select_path (selection, path); + + activate_selected_items (XED_FILE_BROWSER_VIEW (tree_view)); +} + static void toggle_hidden_filter (XedFileBrowserView *view) { @@ -922,6 +936,7 @@ xed_file_browser_view_class_init (XedFileBrowserViewClass *klass) widget_class->key_press_event = key_press_event; /* Tree view handlers */ + tree_view_class->row_activated = row_activated; tree_view_class->row_expanded = row_expanded; tree_view_class->row_collapsed = row_collapsed; From 5c08882ba676d822e4d829fd7be6fc065884e136 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 18:15:41 -0800 Subject: [PATCH 18/21] filebrowser: Don't use deprecated GtkStock --- plugins/filebrowser/xed-file-browser-plugin.c | 6 ++-- plugins/filebrowser/xed-file-browser-utils.c | 33 +++++++------------ plugins/filebrowser/xed-file-browser-utils.h | 25 +++++++------- plugins/filebrowser/xed-file-browser-widget.c | 5 ++- 4 files changed, 28 insertions(+), 41 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index b292df8..6124c6b 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -977,8 +977,7 @@ on_confirm_no_trash_cb (XedFileBrowserWidget *widget, GTK_MESSAGE_QUESTION, message, secondary, - GTK_STOCK_DELETE, - NULL); + _("_Delete")); g_free (secondary); return result; @@ -1013,8 +1012,7 @@ on_confirm_delete_cb (XedFileBrowserWidget *widget, GTK_MESSAGE_QUESTION, message, secondary, - GTK_STOCK_DELETE, - NULL); + _("_Delete")); g_free (message); diff --git a/plugins/filebrowser/xed-file-browser-utils.c b/plugins/filebrowser/xed-file-browser-utils.c index aae2fd9..9c55f6b 100644 --- a/plugins/filebrowser/xed-file-browser-utils.c +++ b/plugins/filebrowser/xed-file-browser-utils.c @@ -19,9 +19,15 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include "xed-file-browser-utils.h" +#ifdef HAVE_CONFIG_H +#include +#endif + +#include #include +#include "xed-file-browser-utils.h" + static GdkPixbuf * process_icon_pixbuf (GdkPixbuf *pixbuf, gchar const *name, @@ -130,12 +136,10 @@ xed_file_browser_utils_confirmation_dialog (XedWindow *window, GtkMessageType type, gchar const *message, gchar const *secondary, - gchar const *button_stock, gchar const *button_label) { GtkWidget *dlg; gint ret; - GtkWidget *button; dlg = gtk_message_dialog_new (GTK_WINDOW (window), GTK_DIALOG_MODAL | @@ -148,25 +152,12 @@ xed_file_browser_utils_confirmation_dialog (XedWindow *window, gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg), "%s", secondary); } - /* Add a cancel button */ - button = gtk_button_new_from_stock (GTK_STOCK_CANCEL); - gtk_widget_show (button); + gtk_dialog_add_buttons (GTK_DIALOG (dlg), + _("_Cancel"), GTK_RESPONSE_CANCEL, + button_label, GTK_RESPONSE_OK, + NULL); - gtk_widget_set_can_default (button, TRUE); - gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, GTK_RESPONSE_CANCEL); - - /* Add custom button */ - button = gtk_button_new_from_stock (button_stock); - - if (button_label) - { - gtk_button_set_use_stock (GTK_BUTTON (button), FALSE); - gtk_button_set_label (GTK_BUTTON (button), button_label); - } - - gtk_widget_show (button); - gtk_widget_set_can_default (button, TRUE); - gtk_dialog_add_action_widget (GTK_DIALOG (dlg), button, GTK_RESPONSE_OK); + gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_CANCEL); ret = gtk_dialog_run (GTK_DIALOG (dlg)); gtk_widget_destroy (dlg); diff --git a/plugins/filebrowser/xed-file-browser-utils.h b/plugins/filebrowser/xed-file-browser-utils.h index bd17b84..abbadd5 100644 --- a/plugins/filebrowser/xed-file-browser-utils.h +++ b/plugins/filebrowser/xed-file-browser-utils.h @@ -4,22 +4,21 @@ #include #include -GdkPixbuf *xed_file_browser_utils_pixbuf_from_theme (gchar const *name, - GtkIconSize size); +GdkPixbuf *xed_file_browser_utils_pixbuf_from_theme (gchar const *name, + GtkIconSize size); -GdkPixbuf *xed_file_browser_utils_pixbuf_from_icon (GIcon * icon, - GtkIconSize size); -GdkPixbuf *xed_file_browser_utils_pixbuf_from_file (GFile * file, - GtkIconSize size); +GdkPixbuf *xed_file_browser_utils_pixbuf_from_icon (GIcon *icon, + GtkIconSize size); +GdkPixbuf *xed_file_browser_utils_pixbuf_from_file (GFile *file, + GtkIconSize size); -gchar * xed_file_browser_utils_file_basename (GFile * file); +gchar * xed_file_browser_utils_file_basename (GFile *file); -gboolean xed_file_browser_utils_confirmation_dialog (XedWindow * window, - GtkMessageType type, - gchar const *message, - gchar const *secondary, - gchar const * button_stock, - gchar const * button_label); +gboolean xed_file_browser_utils_confirmation_dialog (XedWindow *window, + GtkMessageType type, + gchar const *message, + gchar const *secondary, + gchar const *button_label); #endif /* __XED_FILE_BROWSER_UTILS_H__ */ diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index 745a950..bed7544 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -559,11 +559,10 @@ get_from_bookmark_file (XedFileBrowserWidget *obj, item = (NameIcon *)data; *name = g_strdup (item->name); - *icon = item->icon; - if (item->icon != NULL) + if (icon != NULL && item->icon != NULL) { - g_object_ref (item->icon); + *icon = g_object_ref (item->icon); } return TRUE; From 6801233bd84bfb728ad974c265808bd2650bddbe Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 18:23:45 -0800 Subject: [PATCH 19/21] filebrowser: Do not parse .hidden in the file browser https://github.com/GNOME/gedit/commit/f0454abbec92f34431bd59fd1e3da6ad346a000e --- plugins/filebrowser/xed-file-browser-store.c | 95 -------------------- 1 file changed, 95 deletions(-) diff --git a/plugins/filebrowser/xed-file-browser-store.c b/plugins/filebrowser/xed-file-browser-store.c index c812774..48d1afc 100644 --- a/plugins/filebrowser/xed-file-browser-store.c +++ b/plugins/filebrowser/xed-file-browser-store.c @@ -104,7 +104,6 @@ struct _FileBrowserNodeDir { FileBrowserNode node; GSList *children; - GHashTable *hidden_file_hash; GCancellable *cancellable; GFileMonitor *monitor; @@ -1474,11 +1473,6 @@ file_browser_node_free (XedFileBrowserStore *model, g_file_monitor_cancel (dir->monitor); g_object_unref (dir->monitor); } - - if (dir->hidden_file_hash) - { - g_hash_table_destroy (dir->hidden_file_hash); - } } if (node->file) @@ -2085,9 +2079,7 @@ file_browser_node_set_from_info (XedFileBrowserStore *model, GFileInfo *info, gboolean isadded) { - FileBrowserNodeDir *dir; gchar const *content; - gchar const *name; gboolean free_info = FALSE; GtkTreePath *path; gchar *uri; @@ -2117,17 +2109,10 @@ file_browser_node_set_from_info (XedFileBrowserStore *model, free_info = TRUE; } - dir = FILE_BROWSER_NODE_DIR (node->parent); - name = g_file_info_get_name (info); - if (g_file_info_get_is_hidden (info) || g_file_info_get_is_backup (info)) { node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; } - else if (dir != NULL && dir->hidden_file_hash != NULL && g_hash_table_lookup (dir->hidden_file_hash, name) != NULL) - { - node->flags |= XED_FILE_BROWSER_STORE_FLAG_IS_HIDDEN; - } if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) { @@ -2342,83 +2327,6 @@ model_add_node_from_dir (XedFileBrowserStore *model, return node; } -/* Read is sync, but we only do it for local files */ -static void -parse_dot_hidden_file (FileBrowserNode *directory) -{ - gsize file_size; - char *file_contents; - GFile *child; - GFileInfo *info; - GFileType type; - int i; - FileBrowserNodeDir * dir = FILE_BROWSER_NODE_DIR (directory); - - /* FIXME: We only support .hidden on file: uri's for the moment. - * Need to figure out if we should do this async or sync to extend - * it to all types of uris. - */ - if (directory->file == NULL || !g_file_is_native (directory->file)) - { - return; - } - - child = g_file_get_child (directory->file, ".hidden"); - info = g_file_query_info (child, G_FILE_ATTRIBUTE_STANDARD_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); - - type = info ? g_file_info_get_file_type (info) : G_FILE_TYPE_UNKNOWN; - - if (info) - { - g_object_unref (info); - } - - if (type != G_FILE_TYPE_REGULAR) - { - g_object_unref (child); - return; - } - - if (!g_file_load_contents (child, NULL, &file_contents, &file_size, NULL, NULL)) - { - g_object_unref (child); - return; - } - - g_object_unref (child); - - if (dir->hidden_file_hash == NULL) - { - dir->hidden_file_hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - } - - /* Now parse the data */ - i = 0; - while (i < file_size) - { - int start; - - start = i; - while (i < file_size && file_contents[i] != '\n') - { - i++; - } - - if (i > start) - { - char *hidden_filename; - - hidden_filename = g_strndup (file_contents + start, i - start); - g_hash_table_insert (dir->hidden_file_hash, hidden_filename, hidden_filename); - } - - i++; - - } - - g_free (file_contents); -} - static void on_directory_monitor_event (GFileMonitor *monitor, GFile *file, @@ -2608,9 +2516,6 @@ model_load_directory (XedFileBrowserStore *model, node->flags |= XED_FILE_BROWSER_STORE_FLAG_LOADED; model_begin_loading (model, node); - /* Read the '.hidden' file first (if any) */ - parse_dot_hidden_file (node); - dir->cancellable = g_cancellable_new (); async = g_slice_new (AsyncNode); From 245991c22c84ca487c578db1c296d0b36ac64323 Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 19:27:30 -0800 Subject: [PATCH 20/21] filebrowser: Make the "Open terminal here" command work again Add a gsettings key to set the terminal used for the command in the menu. By default this is set to 'x-terminal-emulator' but it can be easily overridden by packagers or changed by users who choose to. --- .../org.x.editor.plugins.filebrowser.gschema.xml.in | 5 +++++ plugins/filebrowser/xed-file-browser-plugin.c | 10 +--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/filebrowser/org.x.editor.plugins.filebrowser.gschema.xml.in b/plugins/filebrowser/org.x.editor.plugins.filebrowser.gschema.xml.in index 6a708ca..46c3923 100644 --- a/plugins/filebrowser/org.x.editor.plugins.filebrowser.gschema.xml.in +++ b/plugins/filebrowser/org.x.editor.plugins.filebrowser.gschema.xml.in @@ -16,6 +16,11 @@ File Browser Filter Pattern The filter pattern to filter the file browser with. This filter works on top of the filter_mode. + + 'x-terminal-emulator' + Terminal Command + The terminal command when using the "Open terminal here" command. + diff --git a/plugins/filebrowser/xed-file-browser-plugin.c b/plugins/filebrowser/xed-file-browser-plugin.c index 6124c6b..cc88326 100644 --- a/plugins/filebrowser/xed-file-browser-plugin.c +++ b/plugins/filebrowser/xed-file-browser-plugin.c @@ -337,13 +337,6 @@ on_action_set_active_root (GtkAction *action, set_root_from_doc (plugin, xed_window_get_active_document (XED_WINDOW (plugin->priv->window))); } -static gchar * -get_terminal (XedFileBrowserPlugin *plugin) -{ - // TODO : Identify the DE, find the preferred terminal application (xterminal shouldn't be hardcoded here, it should be set as default in the DE prefs) - return g_strdup ("xterminal"); -} - static void on_action_open_terminal (GtkAction *action, XedFileBrowserPlugin *plugin) @@ -369,8 +362,7 @@ on_action_open_terminal (GtkAction *action, gchar *local; gchar *argv[2]; - terminal = get_terminal (plugin); - + terminal = g_settings_get_string (priv->settings, "terminal-command"); local = g_file_get_path (file); argv[0] = terminal; From ebb32ff1146cc21da2db6119590ebd11a428b11b Mon Sep 17 00:00:00 2001 From: JosephMcc Date: Wed, 15 Feb 2017 19:51:29 -0800 Subject: [PATCH 21/21] filebrowser: Set the combobox insensitive when the bookmarks are showing The combo doesn't show anything useful when treeview is showing the bookmarks so just set it insensitive. --- plugins/filebrowser/xed-file-browser-widget.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/filebrowser/xed-file-browser-widget.c b/plugins/filebrowser/xed-file-browser-widget.c index bed7544..f9376c2 100644 --- a/plugins/filebrowser/xed-file-browser-widget.c +++ b/plugins/filebrowser/xed-file-browser-widget.c @@ -1660,7 +1660,6 @@ xed_file_browser_widget_new (const gchar *data_dir) XedFileBrowserWidget *obj = g_object_new (XED_TYPE_FILE_BROWSER_WIDGET, NULL); create_toolbar (obj, data_dir); - // create_combo (obj); create_tree (obj); create_filter (obj); @@ -1677,6 +1676,8 @@ xed_file_browser_widget_show_bookmarks (XedFileBrowserWidget *obj) combo_set_active_by_id (obj, BOOKMARKS_ID); g_signal_handlers_unblock_by_func (obj->priv->combo, on_combo_changed, obj); + gtk_widget_set_sensitive (GTK_WIDGET (obj->priv->combo), FALSE); + check_current_item (obj, FALSE); xed_file_browser_view_set_model (obj->priv->treeview, GTK_TREE_MODEL (obj->priv->bookmarks_store)); @@ -1688,6 +1689,8 @@ show_files_real (XedFileBrowserWidget *obj, { xed_file_browser_view_set_model (obj->priv->treeview, GTK_TREE_MODEL (obj->priv->file_store)); + gtk_widget_set_sensitive (GTK_WIDGET (obj->priv->combo), TRUE); + if (do_root_changed) { on_virtual_root_changed (obj->priv->file_store, NULL, obj);