[Xfce4-commits] [xfce/xfdesktop] 02/03: Remove code duplication

noreply at xfce.org noreply at xfce.org
Thu Apr 20 17:38:21 CEST 2017


This is an automated email from the git hooks/post-receive script.

eric pushed a commit to branch master
in repository xfce/xfdesktop.

commit a424bbc1653df0142fe3fb6d264d29496805f7c1
Author: Eric Koegel <eric.koegel at gmail.com>
Date:   Thu Apr 20 09:17:31 2017 +0300

    Remove code duplication
---
 common/xfdesktop-common.c | 53 ++++++++++++++++-------------------------------
 1 file changed, 18 insertions(+), 35 deletions(-)

diff --git a/common/xfdesktop-common.c b/common/xfdesktop-common.c
index a821100..af6198d 100644
--- a/common/xfdesktop-common.c
+++ b/common/xfdesktop-common.c
@@ -202,22 +202,15 @@ xfdesktop_remove_whitspaces(gchar* str)
 }
 
 
-
-/* Adapted from garcon_gtk_menu_create_menu_item because I don't want
- * to write it over and over.
- */
-GtkWidget*
-xfdesktop_menu_create_menu_item_with_markup(const gchar *name,
-                                            GtkWidget   *image)
+static GtkWidget*
+create_menu_item(GtkWidget* label, GtkWidget* image)
 {
     GtkWidget *mi;
     GtkWidget *box;
-    GtkWidget *label;
 
     /* create item */
     mi = gtk_menu_item_new ();
-    label = gtk_label_new (NULL);
-    gtk_label_set_markup (GTK_LABEL (label), name);
+
     gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
     gtk_label_set_xalign (GTK_LABEL (label), 0.0);
 
@@ -239,38 +232,28 @@ xfdesktop_menu_create_menu_item_with_markup(const gchar *name,
     return mi;
 }
 
-
-
+/* Adapted from garcon_gtk_menu_create_menu_item because I don't want
+ * to write it over and over.
+ */
 GtkWidget*
-xfdesktop_menu_create_menu_item_with_mnemonic(const gchar *name,
-                                              GtkWidget   *image)
+xfdesktop_menu_create_menu_item_with_markup(const gchar *name,
+                                            GtkWidget   *image)
 {
-    GtkWidget *mi;
-    GtkWidget *box;
-    GtkWidget *label;
+    GtkWidget *label = gtk_label_new (NULL);
 
-    /* create item */
-    mi = gtk_menu_item_new ();
-    label = gtk_label_new_with_mnemonic (name);
-    gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
-    gtk_label_set_xalign (GTK_LABEL (label), 0.0);
-
-    box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
-    gtk_widget_set_halign (label, GTK_ALIGN_START);
+    gtk_label_set_markup(GTK_LABEL(label), name);
+    return create_menu_item(label, image);
+}
 
-    /* Add the image and label to the box, add the box to the menu item */
-    if(image && GTK_IS_WIDGET(image)) {
-        /* only add the widget if it exists */
-        gtk_widget_show (image);
 
-        gtk_box_pack_start (GTK_BOX (box), image, FALSE, FALSE, 0);
-    }
 
-    gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 6);
-    gtk_widget_show_all (box);
-    gtk_container_add (GTK_CONTAINER (mi), box);
+GtkWidget*
+xfdesktop_menu_create_menu_item_with_mnemonic(const gchar *name,
+                                              GtkWidget   *image)
+{
+    GtkWidget *label = label = gtk_label_new_with_mnemonic(name);
 
-    return mi;
+    return create_menu_item(label, image);
 }
 
 

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list