[frogr] Use GtkActionGroup to group actions and set sensitiveness



commit af358de22e3b8bbe03aa29e5f6741d4109f556db
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Thu Apr 12 10:23:08 2012 +0200

    Use GtkActionGroup to group actions and set sensitiveness

 data/gtkbuilder/frogr-main-view.xml |  210 +++++++++++++++++++++--------------
 src/frogr-main-view.c               |   41 ++++----
 2 files changed, 149 insertions(+), 102 deletions(-)
---
diff --git a/data/gtkbuilder/frogr-main-view.xml b/data/gtkbuilder/frogr-main-view.xml
index 5cfc8d5..bdcfb06 100644
--- a/data/gtkbuilder/frogr-main-view.xml
+++ b/data/gtkbuilder/frogr-main-view.xml
@@ -1,91 +1,137 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
-  <object class="GtkAction" id="about_action">
-    <property name="label" translatable="yes">_About</property>
-    <property name="stock_id">gtk-about</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="load_pictures_action">
-    <property name="label" translatable="yes">_Load Picturesâ</property>
-    <property name="stock_id">gtk-add</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="add_tags_action">
-    <property name="label" translatable="yes">Add _Tagsâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="add_to_group_action">
-    <property name="label" translatable="yes">Add to _Groupâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="add_to_new_set_action">
-    <property name="label" translatable="yes">_Create New Setâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="add_to_set_action">
-    <property name="label" translatable="yes">Add to _Existing Setâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="auth_action">
-    <property name="label" translatable="yes">Aut_horize accountâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkToggleAction" id="enable_tooltips_action">
-    <property name="label" translatable="yes">Enable _Tooltips</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="edit_details_action">
-    <property name="label" translatable="yes">Edit _Detailsâ</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="help_action">
-    <property name="label" translatable="yes">_Help</property>
-    <property name="stock_id">gtk-help</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="open_in_external_viewer_action">
-    <property name="label" translatable="yes">Open in E_xternal Viewer</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="preferences_action">
-    <property name="label" translatable="yes">_Preferencesâ</property>
-    <property name="stock_id">gtk-preferences</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="quit_action">
-    <property name="label" translatable="yes">_Quit</property>
-    <property name="stock_id">gtk-quit</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkAction" id="remove_pictures_action">
-    <property name="label" translatable="yes">_Remove Pictures</property>
-    <property name="stock_id">gtk-remove</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
-  </object>
-  <object class="GtkToggleAction" id="reversed_order_action">
-    <property name="label" translatable="yes">_Reversed Order</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
-  </object>
-  <object class="GtkRadioAction" id="sort_as_loaded_action">
-    <property name="label" translatable="yes">As _Loaded</property>
-    <property name="draw_as_radio">True</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+  <object class="GtkActionGroup" id="global_action_group">
+    <child>
+      <object class="GtkAction" id="about_action">
+        <property name="label" translatable="yes">_About</property>
+        <property name="stock_id">gtk-about</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="help_action">
+        <property name="label" translatable="yes">_Help</property>
+        <property name="stock_id">gtk-help</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="preferences_action">
+        <property name="label" translatable="yes">_Preferencesâ</property>
+        <property name="stock_id">gtk-preferences</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="quit_action">
+        <property name="label" translatable="yes">_Quit</property>
+        <property name="stock_id">gtk-quit</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkToggleAction" id="enable_tooltips_action">
+        <property name="label" translatable="yes">Enable _Tooltips</property>
+        <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkToggleAction" id="reversed_order_action">
+        <property name="label" translatable="yes">_Reversed Order</property>
+        <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioAction" id="sort_as_loaded_action">
+        <property name="label" translatable="yes">As _Loaded</property>
+        <property name="draw_as_radio">True</property>
+        <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioAction" id="sort_by_date_taken_action">
+        <property name="label" translatable="yes">By _Date Taken</property>
+        <property name="draw_as_radio">True</property>
+        <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioAction" id="sort_by_title_action">
+        <property name="label" translatable="yes">By _Title</property>
+        <property name="draw_as_radio">True</property>
+        <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+      </object>
+    </child>
   </object>
-  <object class="GtkRadioAction" id="sort_by_date_taken_action">
-    <property name="label" translatable="yes">By _Date Taken</property>
-    <property name="draw_as_radio">True</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+  <object class="GtkActionGroup" id="on_idle_action_group">
+    <child>
+      <object class="GtkAction" id="auth_action">
+        <property name="label" translatable="yes">Aut_horize accountâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="load_pictures_action">
+        <property name="label" translatable="yes">_Load Picturesâ</property>
+        <property name="stock_id">gtk-add</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
   </object>
-  <object class="GtkRadioAction" id="sort_by_title_action">
-    <property name="label" translatable="yes">By _Title</property>
-    <property name="draw_as_radio">True</property>
-    <signal name="toggled" handler="_on_toggle_action_changed" swapped="no"/>
+  <object class="GtkActionGroup" id="upload_action_group">
+    <child>
+      <object class="GtkAction" id="upload_pictures_action">
+        <property name="label" translatable="yes">_Upload All</property>
+        <property name="stock_id">gtk-go-up</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
   </object>
-  <object class="GtkAction" id="upload_pictures_action">
-    <property name="label" translatable="yes">_Upload All</property>
-    <property name="stock_id">gtk-go-up</property>
-    <signal name="activate" handler="_on_action_activated" swapped="no"/>
+  <object class="GtkActionGroup" id="edition_action_group">
+    <child>
+      <object class="GtkAction" id="add_tags_action">
+        <property name="label" translatable="yes">Add _Tagsâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="add_to_group_action">
+        <property name="label" translatable="yes">Add to _Groupâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="add_to_new_set_action">
+        <property name="label" translatable="yes">_Create New Setâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="add_to_set_action">
+        <property name="label" translatable="yes">Add to _Existing Setâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="edit_details_action">
+        <property name="label" translatable="yes">Edit _Detailsâ</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="remove_pictures_action">
+        <property name="label" translatable="yes">_Remove Pictures</property>
+        <property name="stock_id">gtk-remove</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkAction" id="open_in_external_viewer_action">
+        <property name="label" translatable="yes">Open in E_xternal Viewer</property>
+        <signal name="activate" handler="_on_action_activated" swapped="no"/>
+      </object>
+    </child>
   </object>
   <object class="GtkMenu" id="ctxt_menu">
     <property name="visible">True</property>
diff --git a/src/frogr-main-view.c b/src/frogr-main-view.c
index 7f765b7..008116e 100644
--- a/src/frogr-main-view.c
+++ b/src/frogr-main-view.c
@@ -91,6 +91,11 @@ typedef struct _FrogrMainViewPrivate {
 
   GtkBuilder *builder;
 
+  GtkActionGroup *global_action_group;
+  GtkActionGroup *on_idle_action_group;
+  GtkActionGroup *upload_action_group;
+  GtkActionGroup *edition_action_group;
+
   GtkAction *load_pictures_action;
   GtkAction *remove_pictures_action;
   GtkAction *upload_pictures_action;
@@ -1424,16 +1429,9 @@ _update_sensitiveness (FrogrMainView *self)
     {
     case FROGR_STATE_LOADING_PICTURES:
     case FROGR_STATE_UPLOADING_PICTURES:
-      gtk_action_set_sensitive (priv->load_pictures_action, FALSE);
-      gtk_action_set_sensitive (priv->remove_pictures_action, FALSE);
-      gtk_action_set_sensitive (priv->upload_pictures_action, FALSE);
-      gtk_action_set_sensitive (priv->open_in_external_viewer_action, FALSE);
-      gtk_action_set_sensitive (priv->auth_action, FALSE);
-      gtk_action_set_sensitive (priv->add_tags_action, FALSE);
-      gtk_action_set_sensitive (priv->edit_details_action, FALSE);
-      gtk_action_set_sensitive (priv->add_to_group_action, FALSE);
-      gtk_action_set_sensitive (priv->add_to_set_action, FALSE);
-      gtk_action_set_sensitive (priv->add_to_new_set_action, FALSE);
+      gtk_action_group_set_sensitive (priv->on_idle_action_group, FALSE);
+      gtk_action_group_set_sensitive (priv->upload_action_group, FALSE);
+      gtk_action_group_set_sensitive (priv->edition_action_group, FALSE);
       gtk_widget_set_sensitive (priv->accounts_menu_item, FALSE);
       gtk_widget_set_sensitive (priv->add_to_set_menu_item, FALSE);
       break;
@@ -1443,17 +1441,10 @@ _update_sensitiveness (FrogrMainView *self)
       has_accounts = (priv->accounts_menu != NULL);
       n_selected_pics = priv->n_selected_pictures;
 
-      gtk_action_set_sensitive (priv->load_pictures_action, TRUE);
-      gtk_action_set_sensitive (priv->auth_action, TRUE);
+      gtk_action_group_set_sensitive (priv->on_idle_action_group, TRUE);
+      gtk_action_group_set_sensitive (priv->upload_action_group, has_pics);
+      gtk_action_group_set_sensitive (priv->edition_action_group, n_selected_pics > 0);
       gtk_widget_set_sensitive (priv->accounts_menu_item, has_accounts);
-      gtk_action_set_sensitive (priv->upload_pictures_action, has_pics);
-      gtk_action_set_sensitive (priv->remove_pictures_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->open_in_external_viewer_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->add_tags_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->edit_details_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->add_to_group_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->add_to_set_action, n_selected_pics > 0);
-      gtk_action_set_sensitive (priv->add_to_new_set_action, n_selected_pics > 0);
       gtk_widget_set_sensitive (priv->add_to_set_menu_item, n_selected_pics > 0);
       break;
 
@@ -1634,6 +1625,16 @@ frogr_main_view_init (FrogrMainView *self)
   status_bar = GTK_WIDGET (gtk_builder_get_object (builder, "status_bar"));
   priv->status_bar = status_bar;
 
+  /* Get action groups from GtkBuilder */
+  priv->global_action_group =
+    GTK_ACTION_GROUP (gtk_builder_get_object (builder, "global_action_group"));
+  priv->on_idle_action_group =
+    GTK_ACTION_GROUP (gtk_builder_get_object (builder, "on_idle_action_group"));
+  priv->upload_action_group =
+    GTK_ACTION_GROUP (gtk_builder_get_object (builder, "upload_action_group"));
+  priv->edition_action_group =
+    GTK_ACTION_GROUP (gtk_builder_get_object (builder, "edition_action_group"));
+
   /* Get actions from GtkBuilder */
   priv->load_pictures_action =
     GTK_ACTION (gtk_builder_get_object (builder, "load_pictures_action"));



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