[gedit/wip/statusbar-buttons] Embed the language switcher into a popover.
- From: Steve Frécinaux <sfre src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/statusbar-buttons] Embed the language switcher into a popover.
- Date: Tue, 11 Feb 2014 09:43:11 +0000 (UTC)
commit 46af25dbac5babdb2ecde6a3e5a22236c42c627a
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} | 114 +++++---------
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, 238 insertions(+), 338 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 73%
rename from gedit/gedit-highlight-mode-dialog.c
rename to gedit/gedit-highlight-mode-widget.c
index d0bd533..84ca079 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 *dlg)
{
const gchar *entry_text;
gchar *name;
@@ -149,7 +117,7 @@ visible_func (GtkTreeModel *model,
static void
on_entry_changed (GtkEntry *entry,
- GeditHighlightModeDialog *dlg)
+ GeditHighlightModeWidget *dlg)
{
GtkTreeIter iter;
@@ -162,7 +130,7 @@ on_entry_changed (GtkEntry *entry,
}
static gboolean
-move_selection (GeditHighlightModeDialog *dlg,
+move_selection (GeditHighlightModeWidget *dlg,
gint howmany)
{
GtkTreeIter iter;
@@ -218,7 +186,7 @@ move_selection (GeditHighlightModeDialog *dlg,
static gboolean
on_entry_key_press_event (GtkWidget *entry,
GdkEventKey *event,
- GeditHighlightModeDialog *dlg)
+ GeditHighlightModeWidget *dlg)
{
if (event->keyval == GDK_KEY_Down)
{
@@ -241,37 +209,43 @@ on_entry_key_press_event (GtkWidget *entry,
}
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 *dlg)
{
- gtk_window_activate_default (GTK_WINDOW (dlg));
+ GeditHighlightModeWidgetPrivate *priv = dlg->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 (dlg), 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 *dlg)
{
- GeditHighlightModeDialogPrivate *priv;
+ GeditHighlightModeWidgetPrivate *priv;
GtkSourceLanguageManager *lm;
const gchar * const *ids;
gint i;
GtkTreeIter iter;
- dlg->priv = gedit_highlight_mode_dialog_get_instance_private (dlg);
+ dlg->priv = gedit_highlight_mode_widget_get_instance_private (dlg);
priv = dlg->priv;
gtk_widget_init_template (GTK_WIDGET (dlg));
- gtk_dialog_set_default_response(GTK_DIALOG (dlg), GTK_RESPONSE_OK);
gtk_tree_model_filter_set_visible_func (priv->treemodelfilter,
(GtkTreeModelFilterVisibleFunc)visible_func,
@@ -283,9 +257,6 @@ gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
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_signal_connect (priv->treeview, "row-activated",
G_CALLBACK (on_row_activated), dlg);
@@ -323,20 +294,19 @@ gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
}
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 *dlg,
GtkSourceLanguage *language)
{
GtkTreeIter iter;
- g_return_if_fail (GEDIT_IS_HIGHLIGHT_MODE_DIALOG (dlg));
+ g_return_if_fail (GEDIT_IS_HIGHLIGHT_MODE_WIDGET (dlg));
if (language == NULL)
{
diff --git a/gedit/gedit-highlight-mode-widget.h b/gedit/gedit-highlight-mode-widget.h
new file mode 100644
index 0000000..c9f1a4d
--- /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 *dlg,
+ 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]