[gedit/wip/statusbar-buttons: 1/2] Embed the language switcher into a popover.



commit 8a7dcfb8113fe64ea450d66c76af4597bf90ac98
Author: Steve Frécinaux <code istique net>
Date:   Tue Feb 11 09:56:11 2014 +0100

    Embed the language switcher into a popover.

 gedit/Makefile.am                                  |    4 +-
 gedit/gedit-commands-view.c                        |   34 +----
 gedit/gedit-highlight-mode-dialog.h                |   69 --------
 gedit/gedit-highlight-mode-dialog.ui               |  161 ------------------
 ...mode-dialog.c => gedit-highlight-mode-widget.c} |  170 ++++++++------------
 gedit/gedit-highlight-mode-widget.h                |   69 ++++++++
 gedit/gedit-highlight-mode-widget.ui               |   83 ++++++++++
 gedit/gedit-window.c                               |   40 +++++-
 gedit/gedit.gresource.xml                          |    2 +-
 9 files changed, 266 insertions(+), 366 deletions(-)
---
diff --git a/gedit/Makefile.am b/gedit/Makefile.am
index d3f46db..ed1fb34 100644
--- a/gedit/Makefile.am
+++ b/gedit/Makefile.am
@@ -117,7 +117,7 @@ gedit_NOINST_H_FILES =                              \
        gedit/gedit-documents-panel.h           \
        gedit/gedit-encodings-dialog.h          \
        gedit/gedit-file-chooser-dialog.h       \
-       gedit/gedit-highlight-mode-dialog.h     \
+       gedit/gedit-highlight-mode-widget.h     \
        gedit/gedit-history-entry.h             \
        gedit/gedit-io-error-info-bar.h         \
        gedit/gedit-menu-stack-switcher.h       \
@@ -193,7 +193,7 @@ gedit_libgedit_c_files =                    \
        gedit/gedit-encodings-combo-box.c       \
        gedit/gedit-encodings-dialog.c          \
        gedit/gedit-file-chooser-dialog.c       \
-       gedit/gedit-highlight-mode-dialog.c     \
+       gedit/gedit-highlight-mode-widget.c     \
        gedit/gedit-history-entry.c             \
        gedit/gedit-io-error-info-bar.c         \
        gedit/gedit-menu-stack-switcher.c       \
diff --git a/gedit/gedit-commands-view.c b/gedit/gedit-commands-view.c
index 10fd849..29cd9fd 100644
--- a/gedit/gedit-commands-view.c
+++ b/gedit/gedit-commands-view.c
@@ -30,7 +30,6 @@
 #include "gedit-debug.h"
 #include "gedit-window.h"
 #include "gedit-window-private.h"
-#include "gedit-highlight-mode-dialog.h"
 
 void
 _gedit_cmd_view_toggle_side_panel (GSimpleAction *action,
@@ -118,43 +117,14 @@ _gedit_cmd_view_leave_fullscreen_mode (GSimpleAction *action,
                                   g_variant_new_boolean (FALSE));
 }
 
-static void
-on_language_selected (GeditHighlightModeDialog *dlg,
-                      GtkSourceLanguage        *language,
-                      GeditWindow              *window)
-{
-       GeditDocument *doc;
-
-       doc = gedit_window_get_active_document (window);
-
-       if (!doc)
-               return;
-
-       gedit_document_set_language (doc, language);
-}
-
 void
 _gedit_cmd_view_highlight_mode (GSimpleAction *action,
                                 GVariant      *parameter,
                                 gpointer       user_data)
 {
-       GtkWindow *window = GTK_WINDOW (user_data);
-       GtkWidget *dlg;
-       GeditDocument *doc;
-
-       dlg = gedit_highlight_mode_dialog_new (window);
-
-       doc = gedit_window_get_active_document (GEDIT_WINDOW (window));
-       if (doc)
-       {
-               gedit_highlight_mode_dialog_select_language (GEDIT_HIGHLIGHT_MODE_DIALOG (dlg),
-                                                            gedit_document_get_language (doc));
-       }
-
-       g_signal_connect (dlg, "language-selected",
-                         G_CALLBACK (on_language_selected), window);
+       GeditWindow *window = GEDIT_WINDOW (user_data);
 
-       gtk_widget_show (GTK_WIDGET (dlg));
+       gtk_button_clicked (GTK_BUTTON (window->priv->language_button));
 }
 
 /* ex:set ts=8 noet: */
diff --git a/gedit/gedit-highlight-mode-dialog.c b/gedit/gedit-highlight-mode-widget.c
similarity index 55%
rename from gedit/gedit-highlight-mode-dialog.c
rename to gedit/gedit-highlight-mode-widget.c
index d0bd533..669f28c 100644
--- a/gedit/gedit-highlight-mode-dialog.c
+++ b/gedit/gedit-highlight-mode-widget.c
@@ -1,5 +1,5 @@
 /*
- * gedit-highlight-mode-dialog.c
+ * gedit-highlight-mode-widget.c
  * This file is part of gedit
  *
  * Copyright (C) 2013 - Ignacio Casal Quinteiro
@@ -19,7 +19,7 @@
  */
 
 
-#include "gedit-highlight-mode-dialog.h"
+#include "gedit-highlight-mode-widget.h"
 
 #include <gdk/gdkkeysyms.h>
 #include <glib/gi18n.h>
@@ -32,7 +32,7 @@ enum
        N_COLUMNS
 };
 
-struct _GeditHighlightModeDialogPrivate
+struct _GeditHighlightModeWidgetPrivate
 {
        GtkWidget *treeview;
        GtkWidget *entry;
@@ -50,51 +50,19 @@ enum
 
 static guint signals[LAST_SIGNAL] = { 0 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GeditHighlightModeDialog, gedit_highlight_mode_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE_WITH_PRIVATE (GeditHighlightModeWidget, gedit_highlight_mode_widget, GTK_TYPE_GRID)
 
-static void
-gedit_highlight_mode_dialog_response (GtkDialog *dialog,
-                                      gint       response_id)
-{
-       GeditHighlightModeDialogPrivate *priv = GEDIT_HIGHLIGHT_MODE_DIALOG (dialog)->priv;
-
-       if (response_id == GTK_RESPONSE_OK)
-       {
-               GtkSourceLanguage *lang;
-               GtkTreeIter iter;
-
-               if (gtk_tree_selection_get_selected (priv->treeview_selection, NULL, &iter))
-               {
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->treemodelfilter), &iter,
-                                           COLUMN_LANG, &lang,
-                                           -1);
-               }
-
-               g_signal_emit (G_OBJECT (dialog), signals[LANGUAGE_SELECTED], 0, lang);
-
-               if (lang)
-               {
-                       g_object_unref (lang);
-               }
-       }
-
-       gtk_widget_destroy (GTK_WIDGET (dialog));
-}
 
 static void
-gedit_highlight_mode_dialog_class_init (GeditHighlightModeDialogClass *klass)
+gedit_highlight_mode_widget_class_init (GeditHighlightModeWidgetClass *klass)
 {
-       GObjectClass *object_class = G_OBJECT_CLASS (klass);
        GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
-       GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
-
-       dialog_class->response = gedit_highlight_mode_dialog_response;
 
        signals[LANGUAGE_SELECTED] =
                g_signal_new ("language-selected",
-                             G_TYPE_FROM_CLASS (object_class),
+                             G_TYPE_FROM_CLASS (klass),
                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GeditHighlightModeDialogClass, language_selected),
+                             G_STRUCT_OFFSET (GeditHighlightModeWidgetClass, language_selected),
                              NULL, NULL,
                              g_cclosure_marshal_VOID__OBJECT,
                              G_TYPE_NONE,
@@ -103,18 +71,18 @@ gedit_highlight_mode_dialog_class_init (GeditHighlightModeDialogClass *klass)
 
        /* Bind class to template */
        gtk_widget_class_set_template_from_resource (widget_class,
-                                                    "/org/gnome/gedit/ui/gedit-highlight-mode-dialog.ui");
-       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeDialog, treeview);
-       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeDialog, entry);
-       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeDialog, liststore);
-       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeDialog, 
treemodelfilter);
-       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeDialog, 
treeview_selection);
+                                                    "/org/gnome/gedit/ui/gedit-highlight-mode-widget.ui");
+       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeWidget, treeview);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeWidget, entry);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeWidget, liststore);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeWidget, 
treemodelfilter);
+       gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeWidget, 
treeview_selection);
 }
 
 static gboolean
 visible_func (GtkTreeModel             *model,
               GtkTreeIter              *iter,
-              GeditHighlightModeDialog *dlg)
+              GeditHighlightModeWidget *hmwidget)
 {
        const gchar *entry_text;
        gchar *name;
@@ -122,7 +90,7 @@ visible_func (GtkTreeModel             *model,
        gchar *text_lower;
        gboolean visible = FALSE;
 
-       entry_text = gtk_entry_get_text (GTK_ENTRY (dlg->priv->entry));
+       entry_text = gtk_entry_get_text (GTK_ENTRY (hmwidget->priv->entry));
 
        if (*entry_text == '\0')
        {
@@ -149,20 +117,20 @@ visible_func (GtkTreeModel             *model,
 
 static void
 on_entry_changed (GtkEntry                 *entry,
-                  GeditHighlightModeDialog *dlg)
+                  GeditHighlightModeWidget *hmwidget)
 {
        GtkTreeIter iter;
 
-       gtk_tree_model_filter_refilter (dlg->priv->treemodelfilter);
+       gtk_tree_model_filter_refilter (hmwidget->priv->treemodelfilter);
 
-       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter))
        {
-               gtk_tree_selection_select_iter (dlg->priv->treeview_selection, &iter);
+               gtk_tree_selection_select_iter (hmwidget->priv->treeview_selection, &iter);
        }
 }
 
 static gboolean
-move_selection (GeditHighlightModeDialog *dlg,
+move_selection (GeditHighlightModeWidget *hmwidget,
                 gint                      howmany)
 {
        GtkTreeIter iter;
@@ -170,13 +138,13 @@ move_selection (GeditHighlightModeDialog *dlg,
        gint *indices;
        gint ret = FALSE;
 
-       if (!gtk_tree_selection_get_selected (dlg->priv->treeview_selection, NULL, &iter) &&
-           !gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+       if (!gtk_tree_selection_get_selected (hmwidget->priv->treeview_selection, NULL, &iter) &&
+           !gtk_tree_model_get_iter_first (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter))
        {
                return FALSE;
        }
 
-       path = gtk_tree_model_get_path (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter);
+       path = gtk_tree_model_get_path (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter);
        indices = gtk_tree_path_get_indices (path);
 
        if (indices)
@@ -186,7 +154,7 @@ move_selection (GeditHighlightModeDialog *dlg,
                GtkTreePath *new_path;
 
                idx = indices[0];
-               num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (dlg->priv->treemodelfilter), NULL);
+               num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), NULL);
 
                if ((idx + howmany) < 0)
                {
@@ -202,8 +170,8 @@ move_selection (GeditHighlightModeDialog *dlg,
                }
 
                new_path = gtk_tree_path_new_from_indices (idx, -1);
-               gtk_tree_selection_select_path (dlg->priv->treeview_selection, new_path);
-               gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (dlg->priv->treeview),
+               gtk_tree_selection_select_path (hmwidget->priv->treeview_selection, new_path);
+               gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (hmwidget->priv->treeview),
                                              new_path, NULL, TRUE, 0.5, 0);
                gtk_tree_path_free (new_path);
 
@@ -218,76 +186,79 @@ move_selection (GeditHighlightModeDialog *dlg,
 static gboolean
 on_entry_key_press_event (GtkWidget                *entry,
                           GdkEventKey              *event,
-                          GeditHighlightModeDialog *dlg)
+                          GeditHighlightModeWidget *hmwidget)
 {
        if (event->keyval == GDK_KEY_Down)
        {
-               return move_selection (dlg, 1);
+               return move_selection (hmwidget, 1);
        }
        else if (event->keyval == GDK_KEY_Up)
        {
-               return move_selection (dlg, -1);
+               return move_selection (hmwidget, -1);
        }
        else if (event->keyval == GDK_KEY_Page_Down)
        {
-               return move_selection (dlg, 5);
+               return move_selection (hmwidget, 5);
        }
        else if (event->keyval == GDK_KEY_Page_Up)
        {
-               return move_selection (dlg, -5);
+               return move_selection (hmwidget, -5);
        }
 
        return FALSE;
 }
 
 static void
-on_selection_changed (GtkTreeSelection         *selection,
-                      GeditHighlightModeDialog *dlg)
-{
-       gtk_dialog_set_response_sensitive (GTK_DIALOG (dlg),
-                                          GTK_RESPONSE_OK,
-                                          gtk_tree_selection_get_selected (selection, NULL, NULL));
-}
-
-static void
 on_row_activated (GtkTreeView              *tree_view,
                   GtkTreePath              *path,
                   GtkTreeViewColumn        *column,
-                  GeditHighlightModeDialog *dlg)
+                  GeditHighlightModeWidget *hmwidget)
 {
-       gtk_window_activate_default (GTK_WINDOW (dlg));
+       GeditHighlightModeWidgetPrivate *priv = hmwidget->priv;
+       GtkSourceLanguage *lang;
+       GtkTreeIter iter;
+
+       if (gtk_tree_selection_get_selected (priv->treeview_selection, NULL, &iter))
+       {
+               gtk_tree_model_get (GTK_TREE_MODEL (priv->treemodelfilter), &iter,
+                                   COLUMN_LANG, &lang,
+                                   -1);
+       }
+
+       g_signal_emit (G_OBJECT (hmwidget), signals[LANGUAGE_SELECTED], 0, lang);
+
+       if (lang)
+       {
+               g_object_unref (lang);
+       }
 }
 
 static void
-gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
+gedit_highlight_mode_widget_init (GeditHighlightModeWidget *hmwidget)
 {
-       GeditHighlightModeDialogPrivate *priv;
+       GeditHighlightModeWidgetPrivate *priv;
        GtkSourceLanguageManager *lm;
        const gchar * const *ids;
        gint i;
        GtkTreeIter iter;
 
-       dlg->priv = gedit_highlight_mode_dialog_get_instance_private (dlg);
-       priv = dlg->priv;
+       hmwidget->priv = gedit_highlight_mode_widget_get_instance_private (hmwidget);
+       priv = hmwidget->priv;
 
-       gtk_widget_init_template (GTK_WIDGET (dlg));
-       gtk_dialog_set_default_response(GTK_DIALOG (dlg), GTK_RESPONSE_OK);
+       gtk_widget_init_template (GTK_WIDGET (hmwidget));
 
        gtk_tree_model_filter_set_visible_func (priv->treemodelfilter,
                                                (GtkTreeModelFilterVisibleFunc)visible_func,
-                                               dlg,
+                                               hmwidget,
                                                NULL);
 
        g_signal_connect (priv->entry, "changed",
-                         G_CALLBACK (on_entry_changed), dlg);
+                         G_CALLBACK (on_entry_changed), hmwidget);
        g_signal_connect (priv->entry, "key-press-event",
-                         G_CALLBACK (on_entry_key_press_event), dlg);
-
-       g_signal_connect (priv->treeview_selection, "changed",
-                         G_CALLBACK (on_selection_changed), dlg);
+                         G_CALLBACK (on_entry_key_press_event), hmwidget);
 
        g_signal_connect (priv->treeview, "row-activated",
-                         G_CALLBACK (on_row_activated), dlg);
+                         G_CALLBACK (on_row_activated), hmwidget);
 
        /* Populate tree model */
        gtk_list_store_append (priv->liststore, &iter);
@@ -316,40 +287,39 @@ gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
        }
 
        /* select first item */
-       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter))
        {
-               gtk_tree_selection_select_iter (dlg->priv->treeview_selection, &iter);
+               gtk_tree_selection_select_iter (hmwidget->priv->treeview_selection, &iter);
        }
 }
 
 GtkWidget *
-gedit_highlight_mode_dialog_new (GtkWindow *parent)
+gedit_highlight_mode_widget_new ()
 {
-       return GTK_WIDGET (g_object_new (GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG,
-                                        "transient-for", parent,
+       return GTK_WIDGET (g_object_new (GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET,
                                         NULL));
 }
 
 void
-gedit_highlight_mode_dialog_select_language (GeditHighlightModeDialog *dlg,
+gedit_highlight_mode_widget_select_language (GeditHighlightModeWidget *hmwidget,
                                              GtkSourceLanguage        *language)
 {
        GtkTreeIter iter;
 
-       g_return_if_fail (GEDIT_IS_HIGHLIGHT_MODE_DIALOG (dlg));
+       g_return_if_fail (GEDIT_IS_HIGHLIGHT_MODE_WIDGET (hmwidget));
 
        if (language == NULL)
        {
                return;
        }
 
-       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+       if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter))
        {
                do
                {
                        GtkSourceLanguage *lang;
 
-                       gtk_tree_model_get (GTK_TREE_MODEL (dlg->priv->treemodelfilter),
+                       gtk_tree_model_get (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter),
                                            &iter,
                                            COLUMN_LANG, &lang,
                                            -1);
@@ -364,17 +334,17 @@ gedit_highlight_mode_dialog_select_language (GeditHighlightModeDialog *dlg,
                                {
                                        GtkTreePath *path;
 
-                                       path = gtk_tree_model_get_path (GTK_TREE_MODEL 
(dlg->priv->treemodelfilter), &iter);
+                                       path = gtk_tree_model_get_path (GTK_TREE_MODEL 
(hmwidget->priv->treemodelfilter), &iter);
 
-                                       gtk_tree_selection_select_iter (dlg->priv->treeview_selection, &iter);
-                                       gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (dlg->priv->treeview),
+                                       gtk_tree_selection_select_iter (hmwidget->priv->treeview_selection, 
&iter);
+                                       gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW 
(hmwidget->priv->treeview),
                                                                      path, NULL, TRUE, 0.5, 0);
                                        gtk_tree_path_free (path);
                                        break;
                                }
                        }
                }
-               while (gtk_tree_model_iter_next (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter));
+               while (gtk_tree_model_iter_next (GTK_TREE_MODEL (hmwidget->priv->treemodelfilter), &iter));
        }
 }
 
diff --git a/gedit/gedit-highlight-mode-widget.h b/gedit/gedit-highlight-mode-widget.h
new file mode 100644
index 0000000..dc6bd96
--- /dev/null
+++ b/gedit/gedit-highlight-mode-widget.h
@@ -0,0 +1,69 @@
+/*
+ * gedit-highlight-mode-widget.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2013 - Ignacio Casal Quinteiro
+ *
+ * gedit is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with gedit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GEDIT_HIGHLIGHT_MODE_WIDGET_H__
+#define __GEDIT_HIGHLIGHT_MODE_WIDGET_H__
+
+#include <glib-object.h>
+#include <gtksourceview/gtksource.h>
+#include "gedit-window.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET               (gedit_highlight_mode_widget_get_type ())
+#define GEDIT_HIGHLIGHT_MODE_WIDGET(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET, GeditHighlightModeWidget))
+#define GEDIT_HIGHLIGHT_MODE_WIDGET_CONST(obj)         (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET, GeditHighlightModeWidget const))
+#define GEDIT_HIGHLIGHT_MODE_WIDGET_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET, GeditHighlightModeWidgetClass))
+#define GEDIT_IS_HIGHLIGHT_MODE_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET))
+#define GEDIT_IS_HIGHLIGHT_MODE_WIDGET_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET))
+#define GEDIT_HIGHLIGHT_MODE_WIDGET_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GEDIT_TYPE_HIGHLIGHT_MODE_WIDGET, GeditHighlightModeWidgetClass))
+
+typedef struct _GeditHighlightModeWidget       GeditHighlightModeWidget;
+typedef struct _GeditHighlightModeWidgetClass  GeditHighlightModeWidgetClass;
+typedef struct _GeditHighlightModeWidgetPrivate        GeditHighlightModeWidgetPrivate;
+
+struct _GeditHighlightModeWidget
+{
+       GtkGrid parent;
+
+       GeditHighlightModeWidgetPrivate *priv;
+};
+
+struct _GeditHighlightModeWidgetClass
+{
+       GtkGridClass parent_class;
+
+       void (* language_selected) (GeditHighlightModeWidget *widget,
+                                   GtkSourceLanguage        *language);
+};
+
+GType                    gedit_highlight_mode_widget_get_type        (void) G_GNUC_CONST;
+
+GtkWidget               *gedit_highlight_mode_widget_new             (void);
+
+void                     gedit_highlight_mode_widget_select_language (GeditHighlightModeWidget *hmwidget,
+                                                                      GtkSourceLanguage        *language);
+
+G_END_DECLS
+
+#endif /* __GEDIT_HIGHLIGHT_MODE_WIDGET_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-highlight-mode-widget.ui b/gedit/gedit-highlight-mode-widget.ui
new file mode 100644
index 0000000..728f3bc
--- /dev/null
+++ b/gedit/gedit-highlight-mode-widget.ui
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <!-- interface-requires gtk+ 3.8 -->
+  <object class="GtkListStore" id="liststore">
+    <columns>
+      <!-- column-name name -->
+      <column type="gchararray"/>
+      <!-- column-name lang -->
+      <column type="GtkSourceLanguage"/>
+    </columns>
+  </object>
+  <object class="GtkTreeModelFilter" id="treemodelfilter">
+    <property name="child_model">liststore</property>
+  </object>
+  <template class="GeditHighlightModeWidget" parent="GtkGrid">
+    <property name="width_request">300</property>
+    <property name="height_request">400</property>
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="has_focus">False</property>
+    <property name="is_focus">False</property>
+    <property name="row_spacing">3</property>
+    <property name="border_width">6</property>
+    <child>
+      <object class="GtkSearchEntry" id="entry">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="has_focus">False</property>
+        <property name="is_focus">False</property>
+        <property name="activates_default">True</property>
+        <property name="placeholder_text" translatable="yes">Search highlight mode...</property>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">0</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+    <child>
+      <object class="GtkScrolledWindow" id="scrolledwindow1">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="has_focus">False</property>
+        <property name="is_focus">False</property>
+        <property name="hexpand">True</property>
+        <property name="vexpand">True</property>
+        <property name="shadow_type">in</property>
+        <child>
+          <object class="GtkTreeView" id="treeview">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="has_focus">False</property>
+            <property name="is_focus">False</property>
+            <property name="model">treemodelfilter</property>
+            <property name="headers_visible">False</property>
+            <property name="headers_clickable">False</property>
+            <property name="enable_search">False</property>
+            <child internal-child="selection">
+              <object class="GtkTreeSelection" id="treeview_selection"/>
+            </child>
+            <child>
+              <object class="GtkTreeViewColumn" id="treeviewcolumn">
+                <child>
+                  <object class="GtkCellRendererText" id="cellrenderertext"/>
+                  <attributes>
+                    <attribute name="text">0</attribute>
+                  </attributes>
+                </child>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+      <packing>
+        <property name="left_attach">0</property>
+        <property name="top_attach">1</property>
+        <property name="width">1</property>
+        <property name="height">1</property>
+      </packing>
+    </child>
+  </template>
+</interface>
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index d29bcc1..5d8cb0a 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -53,6 +53,7 @@
 #include "gedit-document.h"
 #include "gedit-small-button.h"
 #include "gedit-menu-stack-switcher.h"
+#include "gedit-highlight-mode-widget.h"
 
 #define TAB_WIDTH_DATA "GeditWindowTabWidthData"
 #define FULLSCREEN_ANIMATION_SPEED 4
@@ -815,10 +816,47 @@ setup_headerbar_open_button (GeditWindow *window)
 }
 
 static void
+on_language_selected (GeditHighlightModeWidget *dlg,
+                      GtkSourceLanguage        *language,
+                      GeditWindow              *window)
+{
+       GeditDocument *doc;
+
+       doc = gedit_window_get_active_document (window);
+
+       if (!doc)
+               return;
+
+       gedit_document_set_language (doc, language);
+}
+
+static void
 on_language_button_clicked (GtkButton   *button,
                             GeditWindow *window)
 {
-       _gedit_cmd_view_highlight_mode (NULL, NULL, 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);
+
+       gtk_container_add (GTK_CONTAINER (popover), widget);
+       gtk_widget_show_all (popover);
 }
 
 static void
diff --git a/gedit/gedit.gresource.xml b/gedit/gedit.gresource.xml
index f5dce90..f5ad585 100644
--- a/gedit/gedit.gresource.xml
+++ b/gedit/gedit.gresource.xml
@@ -10,7 +10,7 @@
     <file preprocess="xml-stripblanks">gedit-progress-info-bar.ui</file>
     <file preprocess="xml-stripblanks">gedit-status-menu-button.ui</file>
     <file preprocess="xml-stripblanks">gedit-view-frame.ui</file>
-    <file preprocess="xml-stripblanks">gedit-highlight-mode-dialog.ui</file>
+    <file preprocess="xml-stripblanks">gedit-highlight-mode-widget.ui</file>
     <file preprocess="xml-stripblanks">gedit-window.ui</file>
     <file preprocess="xml-stripblanks">gedit-notebook-popup-menu.ui</file>
     <file>gedit-style.css</file>


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