[gedit] Add missing files
- From: Ignacio Casal Quinteiro <icq src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Add missing files
- Date: Thu, 16 May 2013 10:06:07 +0000 (UTC)
commit 09a8518b0322e4177e70f06d9e8be3eab128bdc9
Author: Ignacio Casal Quinteiro <icq gnome org>
Date: Thu May 16 12:05:55 2013 +0200
Add missing files
gedit/gedit-highlight-mode-dialog.c | 345 ++++++++++++++++++++++++++++++++++
gedit/gedit-highlight-mode-dialog.h | 66 +++++++
gedit/gedit-highlight-mode-dialog.ui | 161 ++++++++++++++++
3 files changed, 572 insertions(+), 0 deletions(-)
---
diff --git a/gedit/gedit-highlight-mode-dialog.c b/gedit/gedit-highlight-mode-dialog.c
new file mode 100644
index 0000000..02ba355
--- /dev/null
+++ b/gedit/gedit-highlight-mode-dialog.c
@@ -0,0 +1,345 @@
+/*
+ * gedit-highlight-mode-dialog.c
+ * 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/>.
+ */
+
+
+#include "gedit-highlight-mode-dialog.h"
+
+#include <gdk/gdkkeysyms.h>
+#include <glib/gi18n.h>
+#include <string.h>
+
+enum
+{
+ COLUMN_NAME,
+ COLUMN_LANG,
+ N_COLUMNS
+};
+
+struct _GeditHighlightModeDialogPrivate
+{
+ GtkWidget *treeview;
+ GtkWidget *entry;
+ GtkListStore *liststore;
+ GtkTreeModelFilter *treemodelfilter;
+ GtkTreeSelection *treeview_selection;
+};
+
+/* Signals */
+enum
+{
+ LANGUAGE_SELECTED,
+ LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GeditHighlightModeDialog, gedit_highlight_mode_dialog, GTK_TYPE_DIALOG)
+
+static void
+gedit_highlight_mode_dialog_finalize (GObject *object)
+{
+ G_OBJECT_CLASS (gedit_highlight_mode_dialog_parent_class)->finalize (object);
+}
+
+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)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GtkDialogClass *dialog_class = GTK_DIALOG_CLASS (klass);
+
+ object_class->finalize = gedit_highlight_mode_dialog_finalize;
+
+ dialog_class->response = gedit_highlight_mode_dialog_response;
+
+ signals[LANGUAGE_SELECTED] =
+ g_signal_new ("language-selected",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_STRUCT_OFFSET (GeditHighlightModeDialogClass, language_selected),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__OBJECT,
+ G_TYPE_NONE,
+ 1,
+ GTK_SOURCE_TYPE_LANGUAGE);
+
+ /* 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_child (widget_class, GeditHighlightModeDialogPrivate, treeview);
+ gtk_widget_class_bind_child (widget_class, GeditHighlightModeDialogPrivate, entry);
+ gtk_widget_class_bind_child (widget_class, GeditHighlightModeDialogPrivate, liststore);
+ gtk_widget_class_bind_child (widget_class, GeditHighlightModeDialogPrivate, treemodelfilter);
+ gtk_widget_class_bind_child (widget_class, GeditHighlightModeDialogPrivate, treeview_selection);
+
+ g_type_class_add_private (object_class, sizeof (GeditHighlightModeDialogPrivate));
+}
+
+static gboolean
+visible_func (GtkTreeModel *model,
+ GtkTreeIter *iter,
+ GeditHighlightModeDialog *dlg)
+{
+ const gchar *entry_text;
+ gchar *name;
+ gchar *name_lower;
+ gchar *text_lower;
+ gboolean visible = FALSE;
+
+ entry_text = gtk_entry_get_text (GTK_ENTRY (dlg->priv->entry));
+
+ if (*entry_text == '\0')
+ {
+ return TRUE;
+ }
+
+ gtk_tree_model_get (model, iter, COLUMN_NAME, &name, -1);
+
+ name_lower = g_utf8_strdown (name, -1);
+ g_free (name);
+
+ text_lower = g_utf8_strdown (entry_text, -1);
+
+ if (strstr (name_lower, text_lower) != NULL)
+ {
+ visible = TRUE;
+ }
+
+ g_free (name_lower);
+ g_free (text_lower);
+
+ return visible;
+}
+
+static void
+on_entry_changed (GtkEntry *entry,
+ GeditHighlightModeDialog *dlg)
+{
+ GtkTreeIter iter;
+
+ gtk_tree_model_filter_refilter (dlg->priv->treemodelfilter);
+
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+ {
+ gtk_tree_selection_select_iter (dlg->priv->treeview_selection, &iter);
+ }
+}
+
+static gboolean
+move_selection (GeditHighlightModeDialog *dlg,
+ gint howmany)
+{
+ GtkTreeIter iter;
+ GtkTreePath *path;
+ 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))
+ {
+ return FALSE;
+ }
+
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter);
+ indices = gtk_tree_path_get_indices (path);
+
+ if (indices)
+ {
+ gint num;
+ gint idx;
+ GtkTreePath *new_path;
+
+ idx = indices[0];
+ num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (dlg->priv->treemodelfilter), NULL);
+
+ if ((idx + howmany) < 0)
+ {
+ idx = 0;
+ }
+ else if ((idx + howmany) >= num)
+ {
+ idx = num - 1;
+ }
+ else
+ {
+ idx = idx + howmany;
+ }
+
+ 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),
+ new_path, NULL, TRUE, 0.5, 0);
+ gtk_tree_path_free (new_path);
+
+ ret = TRUE;
+ }
+
+ gtk_tree_path_free (path);
+
+ return ret;
+}
+
+static gboolean
+on_entry_key_press_event (GtkWidget *entry,
+ GdkEventKey *event,
+ GeditHighlightModeDialog *dlg)
+{
+ if (event->keyval == GDK_KEY_Down)
+ {
+ return move_selection (dlg, 1);
+ }
+ else if (event->keyval == GDK_KEY_Up)
+ {
+ return move_selection (dlg, -1);
+ }
+ else if (event->keyval == GDK_KEY_Page_Down)
+ {
+ return move_selection (dlg, 5);
+ }
+ else if (event->keyval == GDK_KEY_Page_Up)
+ {
+ return move_selection (dlg, -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)
+{
+ gtk_window_activate_default (GTK_WINDOW (dlg));
+}
+
+static void
+gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
+{
+ GeditHighlightModeDialogPrivate *priv;
+ GtkSourceLanguageManager *lm;
+ const gchar * const *ids;
+ gint i;
+ GtkTreeIter iter;
+
+ dlg->priv = G_TYPE_INSTANCE_GET_PRIVATE (dlg,
+ GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG,
+ GeditHighlightModeDialogPrivate);
+ 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,
+ dlg,
+ NULL);
+
+ g_signal_connect (priv->entry, "changed",
+ G_CALLBACK (on_entry_changed), 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);
+
+ /* Populate tree model */
+ gtk_list_store_append (priv->liststore, &iter);
+ gtk_list_store_set (priv->liststore, &iter,
+ COLUMN_NAME, _("Plain Text"),
+ COLUMN_LANG, NULL,
+ -1);
+
+ lm = gtk_source_language_manager_get_default ();
+ ids = gtk_source_language_manager_get_language_ids (lm);
+
+ for (i = 0; ids[i] != NULL; i++)
+ {
+ GtkSourceLanguage *lang;
+
+ lang = gtk_source_language_manager_get_language (lm, ids[i]);
+
+ if (!gtk_source_language_get_hidden (lang))
+ {
+ gtk_list_store_append (priv->liststore, &iter);
+ gtk_list_store_set (priv->liststore, &iter,
+ COLUMN_NAME, gtk_source_language_get_name (lang),
+ COLUMN_LANG, lang,
+ -1);
+ }
+ }
+
+ /* select first item */
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (dlg->priv->treemodelfilter), &iter))
+ {
+ gtk_tree_selection_select_iter (dlg->priv->treeview_selection, &iter);
+ }
+}
+
+GtkWidget *
+gedit_highlight_mode_dialog_new (GtkWindow *parent)
+{
+ return GTK_WIDGET (g_object_new (GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG,
+ "transient-for", parent,
+ NULL));
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-highlight-mode-dialog.h b/gedit/gedit-highlight-mode-dialog.h
new file mode 100644
index 0000000..65cb7d5
--- /dev/null
+++ b/gedit/gedit-highlight-mode-dialog.h
@@ -0,0 +1,66 @@
+/*
+ * gedit-highlight-mode-dialog.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_DIALOG_H__
+#define __GEDIT_HIGHLIGHT_MODE_DIALOG_H__
+
+#include <glib-object.h>
+#include <gtksourceview/gtksource.h>
+#include "gedit-window.h"
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG (gedit_highlight_mode_dialog_get_type ())
+#define GEDIT_HIGHLIGHT_MODE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG, GeditHighlightModeDialog))
+#define GEDIT_HIGHLIGHT_MODE_DIALOG_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG, GeditHighlightModeDialog const))
+#define GEDIT_HIGHLIGHT_MODE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG, GeditHighlightModeDialogClass))
+#define GEDIT_IS_HIGHLIGHT_MODE_DIALOG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG))
+#define GEDIT_IS_HIGHLIGHT_MODE_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG))
+#define GEDIT_HIGHLIGHT_MODE_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG, GeditHighlightModeDialogClass))
+
+typedef struct _GeditHighlightModeDialog GeditHighlightModeDialog;
+typedef struct _GeditHighlightModeDialogClass GeditHighlightModeDialogClass;
+typedef struct _GeditHighlightModeDialogPrivate GeditHighlightModeDialogPrivate;
+
+struct _GeditHighlightModeDialog
+{
+ GtkDialog parent;
+
+ GeditHighlightModeDialogPrivate *priv;
+};
+
+struct _GeditHighlightModeDialogClass
+{
+ GtkDialogClass parent_class;
+
+ void (* language_selected) (GeditHighlightModeDialog *dialog,
+ GtkSourceLanguage *language);
+};
+
+GType gedit_highlight_mode_dialog_get_type (void) G_GNUC_CONST;
+
+GtkWidget *gedit_highlight_mode_dialog_new (GtkWindow *parent);
+
+G_END_DECLS
+
+#endif /* __GEDIT_HIGHLIGHT_MODE_DIALOG_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-highlight-mode-dialog.ui b/gedit/gedit-highlight-mode-dialog.ui
new file mode 100644
index 0000000..672041e
--- /dev/null
+++ b/gedit/gedit-highlight-mode-dialog.ui
@@ -0,0 +1,161 @@
+<?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="GeditHighlightModeDialog" parent="GtkDialog">
+ <property name="width_request">300</property>
+ <property name="height_request">400</property>
+ <property name="can_focus">False</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Highlight Mode</property>
+ <property name="type_hint">dialog</property>
+ <property name="modal">True</property>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="can_focus">False</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">2</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="can_focus">False</property>
+ <property name="has_focus">False</property>
+ <property name="is_focus">False</property>
+ <property name="layout_style">end</property>
+ <property name="border_width">5</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkButton" id="cancel_button">
+ <property name="label">gtk-cancel</property>
+ <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="receives_default">True</property>
+ <property name="use_stock">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkButton" id="ok_button">
+ <property name="label">gtk-ok</property>
+ <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="receives_default">True</property>
+ <property name="use_stock">True</property>
+ <property name="can_default">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkGrid" id="grid">
+ <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>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ <action-widgets>
+ <action-widget response="-6">cancel_button</action-widget>
+ <action-widget response="-5">ok_button</action-widget>
+ </action-widgets>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]