[gnome-applets] stickynotes: don't use deprecated gtkactiongroup



commit 4342fbc9eb7666f93c8532b40d507ce88dcb4d28
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Thu Mar 26 13:23:32 2015 +0200

    stickynotes: don't use deprecated gtkactiongroup

 po/POTFILES.in                        |    1 +
 stickynotes/Makefile.am               |    3 +-
 stickynotes/stickynotes-note-menu.xml |   26 +++++++++++++
 stickynotes/stickynotes.c             |   64 ++++++++++++++++++++------------
 stickynotes/stickynotes.h             |    2 -
 stickynotes/stickynotes.ui            |   41 ---------------------
 stickynotes/stickynotes_callbacks.c   |   38 +++++++++++++++-----
 stickynotes/stickynotes_callbacks.h   |   19 ++++++++--
 8 files changed, 113 insertions(+), 81 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 1854366..dd1505f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -92,6 +92,7 @@ stickynotes/stickynotes_applet.c
 stickynotes/stickynotes_applet_callbacks.c
 stickynotes/stickynotes_callbacks.c
 [type: gettext/glade]stickynotes/stickynotes-applet-menu.xml
+[type: gettext/glade]stickynotes/stickynotes-note-menu.xml
 [type: gettext/ini]trashapplet/org.gnome.applets.TrashApplet.panel-applet.in.in
 stickynotes/org.gnome.gnome-applets.stickynotes.gschema.xml.in.in
 trashapplet/src/trashapplet.c
diff --git a/stickynotes/Makefile.am b/stickynotes/Makefile.am
index f243a2c..c173e07 100644
--- a/stickynotes/Makefile.am
+++ b/stickynotes/Makefile.am
@@ -2,7 +2,8 @@
 
 SUBDIRS = help pixmaps
 
-ui_files = stickynotes-applet-menu.xml
+ui_files = stickynotes-applet-menu.xml \
+       stickynotes-note-menu.xml
 builder_files = stickynotes.ui \
        stickynotes-preferences.ui
 applet_in_files = org.gnome.applets.StickyNotesApplet.panel-applet.in
diff --git a/stickynotes/stickynotes-note-menu.xml b/stickynotes/stickynotes-note-menu.xml
new file mode 100644
index 0000000..62f8b38
--- /dev/null
+++ b/stickynotes/stickynotes-note-menu.xml
@@ -0,0 +1,26 @@
+<interface>
+  <menu id="note-popup">
+    <section>
+           <item>
+                   <attribute name="label" translatable="yes">_New Note</attribute>
+                   <attribute name="action">stickynote.create</attribute>
+           </item>
+           <item>
+                   <attribute name="label" translatable="yes">_Delete Note...</attribute>
+                   <attribute name="action">stickynote.destroy</attribute>
+           </item>
+    </section>
+    <section>
+           <item>
+                   <attribute name="label" translatable="yes">_Lock Note</attribute>
+                   <attribute name="action">stickynote.lock</attribute>
+           </item>
+    </section>
+    <section>
+           <item>
+                   <attribute name="label" translatable="yes">_Properties</attribute>
+                   <attribute name="action">stickynote.properties</attribute>
+           </item>
+    </section>
+  </menu>
+</interface>
diff --git a/stickynotes/stickynotes.c b/stickynotes/stickynotes.c
index d4c267d..c8f80ed 100644
--- a/stickynotes/stickynotes.c
+++ b/stickynotes/stickynotes.c
@@ -36,6 +36,45 @@ static gboolean save_scheduled = FALSE;
 
 static void response_cb (GtkWidget *dialog, gint id, gpointer data);
 
+/* Popup menu on the sticky note */
+static const GActionEntry stickynotes_note_menu_actions [] = {
+       { "create",     popup_create_cb,      NULL, NULL,    NULL },
+       { "lock",       popup_toggle_lock_cb, NULL, "false", popup_toggle_lock_state },
+       { "destroy",    popup_destroy_cb,     NULL, NULL,    NULL },
+       { "properties", popup_properties_cb,  NULL, NULL,    NULL }
+};
+
+static void
+setup_note_menu (StickyNote *note)
+{
+       GSimpleActionGroup *action_group;
+       gchar *ui_file;
+       GtkBuilder *builder;
+       GMenu *gmenu;
+
+       action_group = g_simple_action_group_new ();
+       g_action_map_add_action_entries (G_ACTION_MAP (action_group),
+                                        stickynotes_note_menu_actions,
+                                        G_N_ELEMENTS (stickynotes_note_menu_actions),
+                                        note);
+
+       ui_file = g_build_filename (STICKYNOTES_MENU_UI_DIR, "stickynotes-note-menu.xml", NULL);
+       builder = gtk_builder_new_from_file (ui_file);
+       g_free (ui_file);
+
+       gtk_builder_set_translation_domain (builder, GETTEXT_PACKAGE);
+
+       gmenu = G_MENU (gtk_builder_get_object (builder, "note-popup"));
+       note->w_menu = gtk_menu_new_from_model (G_MENU_MODEL (gmenu));
+       g_object_unref (builder);
+
+       gtk_menu_attach_to_widget (GTK_MENU (note->w_menu), GTK_WIDGET (note->w_window), NULL);
+
+       gtk_widget_insert_action_group (GTK_WIDGET (note->w_window), "stickynote",
+                                       G_ACTION_GROUP (action_group));
+       g_object_unref (action_group);
+}
+
 /* Based on a function found in wnck */
 static void
 set_icon_geometry  (GdkWindow *window,
@@ -135,9 +174,7 @@ stickynote_new_aux (GdkScreen *screen, gint x, gint y, gint w, gint h)
        gtk_widget_set_direction (GTK_WIDGET (gtk_builder_get_object (builder, "resize_bar")),
                        GTK_TEXT_DIR_LTR);
 
-       note->w_menu = GTK_WIDGET (gtk_builder_get_object (builder, "stickynote_menu"));
-       note->ta_lock_toggle_item = GTK_TOGGLE_ACTION (gtk_builder_get_object (builder,
-               "popup_toggle_lock"));
+       setup_note_menu (note);
 
        note->w_properties = GTK_WIDGET (gtk_builder_get_object (builder,
                        "stickynote_properties"));
@@ -205,12 +242,6 @@ stickynote_new_aux (GdkScreen *screen, gint x, gint y, gint w, gint h)
 
        gtk_widget_realize (note->w_window);
 
-       /* Connect a popup menu to all buttons and title */
-       /* GtkBuilder holds and drops the references to all the widgets it
-        * creates for as long as it exist (GtkBuilder). Hence in our callback
-        * we would have an invalid GtkMenu. We need to ref it.
-        */
-       g_object_ref (note->w_menu);
        g_signal_connect (G_OBJECT (note->w_window), "button-press-event",
                        G_CALLBACK (stickynote_show_popup_menu), note->w_menu);
 
@@ -251,19 +282,6 @@ stickynote_new_aux (GdkScreen *screen, gint x, gint y, gint w, gint h)
        g_signal_connect (G_OBJECT (note->w_window), "delete-event",
                        G_CALLBACK (stickynote_delete_cb), note);
 
-       g_signal_connect (gtk_builder_get_object (builder,
-                                       "popup_create"), "activate",
-                       G_CALLBACK (popup_create_cb), note);
-       g_signal_connect (gtk_builder_get_object (builder,
-                                       "popup_destroy"), "activate",
-                       G_CALLBACK (popup_destroy_cb), note);
-       g_signal_connect (gtk_builder_get_object (builder,
-                                       "popup_toggle_lock"), "toggled",
-                       G_CALLBACK (popup_toggle_lock_cb), note);
-       g_signal_connect (gtk_builder_get_object (builder,
-                                       "popup_properties"), "activate",
-                       G_CALLBACK (popup_properties_cb), note);
-
        g_signal_connect_swapped (G_OBJECT (note->w_entry), "changed",
                        G_CALLBACK (properties_apply_title_cb), note);
        g_signal_connect (G_OBJECT (note->w_color), "color-set",
@@ -621,8 +639,6 @@ void stickynote_set_locked(StickyNote *note, gboolean locked)
                gtk_widget_set_tooltip_text(note->w_lock, _("This note is unlocked."));
        }
 
-       gtk_toggle_action_set_active(note->ta_lock_toggle_item, locked);
-
        stickynotes_applet_update_menus();
 }
 
diff --git a/stickynotes/stickynotes.h b/stickynotes/stickynotes.h
index 25285d1..950225f 100644
--- a/stickynotes/stickynotes.h
+++ b/stickynotes/stickynotes.h
@@ -46,8 +46,6 @@ typedef struct
        GtkWidget *w_resize_se;         /* Sticky Note resize button (south east) */
        GtkWidget *w_resize_sw;         /* Sticky Note resize button (south west) */
 
-       GtkToggleAction *ta_lock_toggle_item; /* Lock item in the popup menu */
-
        GtkImage *img_lock;             /* Lock image */
        GtkImage *img_close;            /* Close image */
        GtkImage *img_resize_se;        /* SE resize image */
diff --git a/stickynotes/stickynotes.ui b/stickynotes/stickynotes.ui
index a6bba94..025b388 100644
--- a/stickynotes/stickynotes.ui
+++ b/stickynotes/stickynotes.ui
@@ -3,46 +3,6 @@
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy toplevel-contextual -->
-  <object class="GtkUIManager" id="uimanager1">
-    <child>
-      <object class="GtkActionGroup" id="actiongroup1">
-        <child>
-          <object class="GtkAction" id="popup_create">
-            <property name="name">popup_create</property>
-            <property name="label" translatable="yes">_New Note</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkAction" id="popup_destroy">
-            <property name="name">popup_destroy</property>
-            <property name="label" translatable="yes">_Delete Note...</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkToggleAction" id="popup_toggle_lock">
-            <property name="name">popup_toggle_lock</property>
-            <property name="label" translatable="yes">_Lock Note</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkAction" id="popup_properties">
-            <property name="name">popup_properties</property>
-            <property name="label" translatable="yes">_Properties</property>
-          </object>
-        </child>
-      </object>
-    </child>
-    <ui>
-      <popup name="stickynote_menu">
-        <menuitem action="popup_create"/>
-        <menuitem action="popup_destroy"/>
-        <separator/>
-        <menuitem action="popup_toggle_lock"/>
-        <separator/>
-        <menuitem action="popup_properties"/>
-      </popup>
-    </ui>
-  </object>
   <object class="GtkDialog" id="delete_dialog">
     <property name="border_width">5</property>
     <property name="resizable">False</property>
@@ -449,7 +409,6 @@
       </object>
     </child>
   </object>
-  <object class="GtkMenu" constructor="uimanager1" id="stickynote_menu"/>
   <object class="GtkDialog" id="stickynote_properties">
     <property name="border_width">5</property>
     <property name="title" translatable="yes">Sticky Note Properties</property>
diff --git a/stickynotes/stickynotes_callbacks.c b/stickynotes/stickynotes_callbacks.c
index cb3ddad..8c425e3 100644
--- a/stickynotes/stickynotes_callbacks.c
+++ b/stickynotes/stickynotes_callbacks.c
@@ -121,33 +121,53 @@ stickynote_show_popup_menu (GtkWidget      *widget,
 
 /* Popup Menu Callback : Create a new sticky note */
 void
-popup_create_cb (GtkWidget  *widget,
-                 StickyNote *note)
+popup_create_cb (GSimpleAction *action,
+                 GVariant      *parameter,
+                 gpointer       user_data)
 {
+       StickyNote *note = (StickyNote *) user_data;
        stickynotes_add (gtk_widget_get_screen (note->w_window));
 }
 
 /* Popup Menu Callback : Destroy selected sticky note */
 void
-popup_destroy_cb (GtkWidget  *widget,
-                  StickyNote *note)
+popup_destroy_cb (GSimpleAction *action,
+                  GVariant      *parameter,
+                  gpointer       user_data)
 {
+       StickyNote *note = (StickyNote *) user_data;
        stickynotes_remove (note);
 }
 
 /* Popup Menu Callback : Lock/Unlock selected sticky note */
 void
-popup_toggle_lock_cb (GtkToggleAction *action,
-                      StickyNote      *note)
+popup_toggle_lock_cb (GSimpleAction *action,
+                      GVariant      *parameter,
+                      gpointer       user_data)
 {
-       stickynote_set_locked (note, gtk_toggle_action_get_active (action));
+       GVariant *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);
+}
+
+void
+popup_toggle_lock_state (GSimpleAction *action,
+                         GVariant      *value,
+                         gpointer       user_data)
+{
+       StickyNote *note = (StickyNote *) user_data;
+       gboolean locked = g_variant_get_boolean (value);
+
+       stickynote_set_locked (note, locked);
 }
 
 /* Popup Menu Callback : Change sticky note properties */
 void
-popup_properties_cb (GtkWidget  *widget,
-                     StickyNote *note)
+popup_properties_cb (GSimpleAction *action,
+                     GVariant      *parameter,
+                     gpointer       user_data)
 {
+       StickyNote *note = (StickyNote *) user_data;
        stickynote_change_properties (note);
 }
 
diff --git a/stickynotes/stickynotes_callbacks.h b/stickynotes/stickynotes_callbacks.h
index 70d87b8..ff69f5a 100644
--- a/stickynotes/stickynotes_callbacks.h
+++ b/stickynotes/stickynotes_callbacks.h
@@ -30,10 +30,21 @@ gboolean stickynote_delete_cb(GtkWidget *widget, GdkEvent *event, StickyNote *no
 gboolean stickynote_show_popup_menu(GtkWidget *widget, GdkEventButton *event, GtkWidget *popup_menu);
 
 /* Callbacks for the sticky notes popup menu */
-void popup_create_cb(GtkWidget *widget, StickyNote *note);
-void popup_destroy_cb(GtkWidget *widget, StickyNote *note);
-void popup_toggle_lock_cb(GtkToggleAction *action, StickyNote *note);
-void popup_properties_cb(GtkWidget *widget, StickyNote *note);
+void popup_create_cb         (GSimpleAction *action,
+                              GVariant      *parameter,
+                              gpointer       user_data);
+void popup_destroy_cb        (GSimpleAction *action,
+                              GVariant      *parameter,
+                              gpointer       user_data);
+void popup_toggle_lock_cb    (GSimpleAction *action,
+                              GVariant      *parameter,
+                              gpointer       user_data);
+void popup_toggle_lock_state (GSimpleAction *action,
+                              GVariant      *value,
+                              gpointer       user_data);
+void popup_properties_cb     (GSimpleAction *action,
+                              GVariant      *parameter,
+                              gpointer       user_data);
 
 /* Callbacks for sticky notes properties dialog */
 void properties_apply_title_cb(StickyNote *note);


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