[gedit/wip/statusbar-buttons: 2/2] Use a Menu Button for the language popover.



commit 7d162a96245ec88034a56ef0563bcf9756a56e1d
Author: Steve Frécinaux <code istique net>
Date:   Tue Feb 11 12:50:59 2014 +0100

    Use a Menu Button for the language popover.
    
    The graphical effect is nicer, but it implies keeping the language
    selector widget around.

 gedit/gedit-window-private.h |    1 +
 gedit/gedit-window.c         |   73 +++++++++++++++---------------------------
 2 files changed, 27 insertions(+), 47 deletions(-)
---
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index abac703..fb56d24 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -67,6 +67,7 @@ struct _GeditWindowPrivate
        GtkWidget      *tab_width_combo;
        GtkWidget      *language_button;
        GtkWidget      *language_button_label;
+       GtkWidget      *language_popover;
        guint           generic_message_cid;
        guint           tip_message_cid;
        guint           bracket_match_message_cid;
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 5d8cb0a..983b45f 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -816,56 +816,43 @@ setup_headerbar_open_button (GeditWindow *window)
 }
 
 static void
-on_language_selected (GeditHighlightModeWidget *dlg,
-                      GtkSourceLanguage        *language,
-                      GeditWindow              *window)
+on_language_widget_shown (GeditHighlightModeWidget *hmwidget,
+                          GeditWindow              *window)
 {
        GeditDocument *doc;
 
        doc = gedit_window_get_active_document (window);
-
-       if (!doc)
-               return;
-
-       gedit_document_set_language (doc, language);
+       if (doc)
+       {
+               gedit_highlight_mode_widget_select_language (hmwidget,
+                                                            gedit_document_get_language (doc));
+       }
 }
 
 static void
-on_language_button_clicked (GtkButton   *button,
-                            GeditWindow *window)
+on_language_selected (GeditHighlightModeWidget *dlg,
+                      GtkSourceLanguage        *language,
+                      GeditWindow              *window)
 {
-       GtkWidget *widget;
        GeditDocument *doc;
-       GtkWidget *popover;
-
-       widget = gedit_highlight_mode_widget_new ();
 
        doc = gedit_window_get_active_document (window);
-       if (doc)
-       {
-               gedit_highlight_mode_widget_select_language (GEDIT_HIGHLIGHT_MODE_WIDGET (widget),
-                                                            gedit_document_get_language (doc));
-       }
 
-       g_signal_connect (widget, "language-selected",
-                         G_CALLBACK (on_language_selected), window);
-
-       popover = gtk_popover_new (GTK_WIDGET (button));
-       gtk_popover_set_modal (GTK_POPOVER (popover), TRUE);
-       gtk_popover_set_position (GTK_POPOVER (popover), GTK_POS_TOP);
-       g_signal_connect (G_OBJECT (popover), "closed", G_CALLBACK (gtk_widget_destroy), NULL);
+       if (!doc)
+               return;
 
-       gtk_container_add (GTK_CONTAINER (popover), widget);
-       gtk_widget_show_all (popover);
+       gedit_document_set_language (doc, language);
 }
 
 static void
 create_language_button (GeditWindow *window)
 {
-       GtkWidget *box;
-       GtkWidget *arrow;
+       GtkWidget *widget;
 
-       window->priv->language_button = gedit_small_button_new ();
+       window->priv->language_button = gedit_status_menu_button_new ();
+       window->priv->language_popover = gtk_popover_new (window->priv->language_button);
+       gtk_menu_button_set_popover (GTK_MENU_BUTTON (window->priv->language_button),
+                                    window->priv->language_popover);
        gtk_widget_show (window->priv->language_button);
        gtk_box_pack_end (GTK_BOX (window->priv->statusbar),
                          window->priv->language_button,
@@ -873,21 +860,13 @@ create_language_button (GeditWindow *window)
                          TRUE,
                          0);
 
-       box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 3);
-       gtk_widget_show (box);
-       gtk_container_add (GTK_CONTAINER (window->priv->language_button), box);
-
-       window->priv->language_button_label = gtk_label_new (NULL);
-       gtk_widget_show (window->priv->language_button_label);
-       gtk_box_pack_start (GTK_BOX (box), window->priv->language_button_label,
-                           FALSE, TRUE, 0);
-
-       arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
-       gtk_widget_show (arrow);
-       gtk_box_pack_start (GTK_BOX (box), arrow, FALSE, FALSE, 0);
-
-       g_signal_connect (window->priv->language_button, "clicked",
-                         G_CALLBACK (on_language_button_clicked), window);
+       widget = gedit_highlight_mode_widget_new ();
+       g_signal_connect (widget, "show",
+                         G_CALLBACK (on_language_widget_shown), window);
+       g_signal_connect (widget, "language-selected",
+                         G_CALLBACK (on_language_selected), window);
+       gtk_container_add (GTK_CONTAINER (window->priv->language_popover), widget);
+       gtk_widget_show (widget);
 }
 
 static void
@@ -1216,7 +1195,7 @@ language_changed (GObject     *object,
        else
                label = _("Plain Text");
 
-       gtk_label_set_text (GTK_LABEL (window->priv->language_button_label), label);
+       gedit_status_menu_button_set_label (GEDIT_STATUS_MENU_BUTTON (window->priv->language_button), label);
 
        peas_extension_set_foreach (window->priv->extensions,
                                    (PeasExtensionSetForeachFunc) extension_update_state,


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