[gedit/wip/browser-menu] Handle toggles correctly



commit a4ab62388e18ce30d5249be8e35e947d4edba585
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Thu Apr 18 18:43:16 2013 +0200

    Handle toggles correctly

 plugins/filebrowser/gedit-file-browser-widget.c | 46 +++++++++++++++++--------
 1 file changed, 31 insertions(+), 15 deletions(-)
---
diff --git a/plugins/filebrowser/gedit-file-browser-widget.c b/plugins/filebrowser/gedit-file-browser-widget.c
index b6ff32f..34355b1 100644
--- a/plugins/filebrowser/gedit-file-browser-widget.c
+++ b/plugins/filebrowser/gedit-file-browser-widget.c
@@ -227,11 +227,11 @@ static void refresh_view_activated             (GSimpleAction          *action,
 static void view_folder_activated              (GSimpleAction          *action,
                                                 GVariant               *parameter,
                                                 gpointer                user_data);
-static void show_hidden_activated              (GSimpleAction          *action,
-                                                GVariant               *parameter,
+static void change_show_hidden_state           (GSimpleAction          *action,
+                                                GVariant               *state,
                                                 gpointer                user_data);
-static void show_binary_activated              (GSimpleAction          *action,
-                                                GVariant               *parameter,
+static void change_show_binary_state           (GSimpleAction          *action,
+                                                GVariant               *state,
                                                 gpointer                user_data);
 static void bookmark_open_activated            (GSimpleAction          *action,
                                                 GVariant               *parameter,
@@ -901,6 +901,19 @@ on_end_loading (GeditFileBrowserStore  *model,
        gdk_window_set_cursor (gtk_widget_get_window (GTK_WIDGET (obj)), NULL);
 }
 
+static void
+activate_toggle (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       user_data)
+{
+       GVariant *state;
+
+       state = g_action_get_state (G_ACTION (action));
+       g_action_change_state (G_ACTION (action),
+                              g_variant_new_boolean (!g_variant_get_boolean (state)));
+       g_variant_unref (state);
+}
+
 static GActionEntry browser_entries[] = {
        { "open", open_activated },
        //{ "set_active_root", set_active_root_activated },
@@ -912,8 +925,8 @@ static GActionEntry browser_entries[] = {
        { "refresh_view", refresh_view_activated },
        { "view_folder", view_folder_activated },
        //{ "open_in_terminal", open_in_terminal_activated },
-       { "show_hidden", show_hidden_activated, NULL, "true", NULL },
-       { "show_binary", show_binary_activated, NULL, "true", NULL },
+       { "show_hidden", activate_toggle, NULL, "false", change_show_hidden_state },
+       { "show_binary", activate_toggle, NULL, "false", change_show_binary_state },
        { "bookmark_open", bookmark_open_activated },
        { "previous_location", previous_location_activated },
        { "next_location", next_location_activated },
@@ -1416,13 +1429,13 @@ clear_next_locations (GeditFileBrowserWidget *obj)
 static void
 update_filter_mode (GeditFileBrowserWidget          *obj,
                     GSimpleAction                   *action,
+                    GVariant                        *state,
                     GeditFileBrowserStoreFilterMode  mode)
 {
        GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (obj->priv->treeview));
 
        if (GEDIT_IS_FILE_BROWSER_STORE (model))
        {
-               GVariant *state = g_action_get_state (G_ACTION (action));
                gint now = gedit_file_browser_store_get_filter_mode (GEDIT_FILE_BROWSER_STORE (model));
 
                if (g_variant_get_boolean(state))
@@ -1430,11 +1443,12 @@ update_filter_mode (GeditFileBrowserWidget          *obj,
                else
                        now |= mode;
 
-               g_variant_unref (state);
-
                gedit_file_browser_store_set_filter_mode (GEDIT_FILE_BROWSER_STORE (model),
                                                          now);
+
        }
+
+       g_simple_action_set_state (action, state);
 }
 
 static void
@@ -2860,26 +2874,28 @@ view_folder_activated (GSimpleAction *action,
 }
 
 static void
-show_hidden_activated (GSimpleAction *action,
-                       GVariant      *parameter,
-                       gpointer       user_data)
+change_show_hidden_state (GSimpleAction *action,
+                          GVariant      *state,
+                          gpointer       user_data)
 {
        GeditFileBrowserWidget *widget = GEDIT_FILE_BROWSER_WIDGET (user_data);
 
        update_filter_mode (widget,
                            action,
+                           state,
                            GEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_HIDDEN);
 }
 
 static void
-show_binary_activated (GSimpleAction *action,
-                       GVariant      *parameter,
-                       gpointer       user_data)
+change_show_binary_state (GSimpleAction *action,
+                          GVariant      *state,
+                          gpointer       user_data)
 {
        GeditFileBrowserWidget *widget = GEDIT_FILE_BROWSER_WIDGET (user_data);
 
        update_filter_mode (widget,
                            action,
+                           state,
                            GEDIT_FILE_BROWSER_STORE_FILTER_MODE_HIDE_BINARY);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]