[gedit] highlight-selector: port to G_DECLARE macros
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] highlight-selector: port to G_DECLARE macros
- Date: Sat, 2 May 2015 17:05:29 +0000 (UTC)
commit cfadf2d76d036bc221df9bf1132d1a74c8665c06
Author: Paolo Borelli <pborelli gnome org>
Date: Sat May 2 18:49:02 2015 +0200
highlight-selector: port to G_DECLARE macros
gedit/gedit-highlight-mode-dialog.c | 38 ++++++-------
gedit/gedit-highlight-mode-dialog.h | 26 +--------
gedit/gedit-highlight-mode-selector.c | 102 +++++++++++++++++----------------
gedit/gedit-highlight-mode-selector.h | 29 +---------
4 files changed, 75 insertions(+), 120 deletions(-)
---
diff --git a/gedit/gedit-highlight-mode-dialog.c b/gedit/gedit-highlight-mode-dialog.c
index bb5c75a..c43776c 100644
--- a/gedit/gedit-highlight-mode-dialog.c
+++ b/gedit/gedit-highlight-mode-dialog.c
@@ -22,25 +22,27 @@
#include <gtk/gtk.h>
-struct _GeditHighlightModeDialogPrivate
+struct _GeditHighlightModeDialog
{
+ GtkDialog parent_instance;
+
GeditHighlightModeSelector *selector;
- gulong on_language_selected_id;
+ gulong on_language_selected_id;
};
-G_DEFINE_TYPE_WITH_PRIVATE (GeditHighlightModeDialog, gedit_highlight_mode_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE (GeditHighlightModeDialog, gedit_highlight_mode_dialog, GTK_TYPE_DIALOG)
static void
gedit_highlight_mode_dialog_response (GtkDialog *dialog,
gint response_id)
{
- GeditHighlightModeDialogPrivate *priv = GEDIT_HIGHLIGHT_MODE_DIALOG (dialog)->priv;
+ GeditHighlightModeDialog *dlg = GEDIT_HIGHLIGHT_MODE_DIALOG (dialog);
if (response_id == GTK_RESPONSE_OK)
{
- g_signal_handler_block (priv->selector, priv->on_language_selected_id);
- gedit_highlight_mode_selector_activate_selected_language (priv->selector);
- g_signal_handler_unblock (priv->selector, priv->on_language_selected_id);
+ g_signal_handler_block (dlg->selector, dlg->on_language_selected_id);
+ gedit_highlight_mode_selector_activate_selected_language (dlg->selector);
+ g_signal_handler_unblock (dlg->selector, dlg->on_language_selected_id);
}
gtk_widget_destroy (GTK_WIDGET (dialog));
@@ -49,15 +51,13 @@ gedit_highlight_mode_dialog_response (GtkDialog *dialog,
static void
on_language_selected (GeditHighlightModeSelector *sel,
GtkSourceLanguage *language,
- GtkDialog *dialog)
+ GeditHighlightModeDialog *dlg)
{
- GeditHighlightModeDialogPrivate *priv = GEDIT_HIGHLIGHT_MODE_DIALOG (dialog)->priv;
-
- g_signal_handler_block (priv->selector, priv->on_language_selected_id);
- gedit_highlight_mode_selector_activate_selected_language (priv->selector);
- g_signal_handler_unblock (priv->selector, priv->on_language_selected_id);
+ g_signal_handler_block (dlg->selector, dlg->on_language_selected_id);
+ gedit_highlight_mode_selector_activate_selected_language (dlg->selector);
+ g_signal_handler_unblock (dlg->selector, dlg->on_language_selected_id);
- gtk_widget_destroy (GTK_WIDGET (dialog));
+ gtk_widget_destroy (GTK_WIDGET (dlg));
}
static void
@@ -71,19 +71,17 @@ 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, selector);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeDialog, selector);
}
static void
gedit_highlight_mode_dialog_init (GeditHighlightModeDialog *dlg)
{
- dlg->priv = gedit_highlight_mode_dialog_get_instance_private (dlg);
-
gtk_widget_init_template (GTK_WIDGET (dlg));
gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK);
- dlg->priv->on_language_selected_id = g_signal_connect (dlg->priv->selector, "language-selected",
- G_CALLBACK (on_language_selected), dlg);
+ dlg->on_language_selected_id = g_signal_connect (dlg->selector, "language-selected",
+ G_CALLBACK (on_language_selected), dlg);
}
GtkWidget *
@@ -100,7 +98,7 @@ gedit_highlight_mode_dialog_get_selector (GeditHighlightModeDialog *dlg)
{
g_return_val_if_fail (GEDIT_IS_HIGHLIGHT_MODE_DIALOG (dlg), NULL);
- return dlg->priv->selector;
+ return dlg->selector;
}
/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-highlight-mode-dialog.h b/gedit/gedit-highlight-mode-dialog.h
index dd54e04..df67fc1 100644
--- a/gedit/gedit-highlight-mode-dialog.h
+++ b/gedit/gedit-highlight-mode-dialog.h
@@ -27,31 +27,9 @@
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))
+#define GEDIT_TYPE_HIGHLIGHT_MODE_DIALOG (gedit_highlight_mode_dialog_get_type ())
-typedef struct _GeditHighlightModeDialog GeditHighlightModeDialog;
-typedef struct _GeditHighlightModeDialogClass GeditHighlightModeDialogClass;
-typedef struct _GeditHighlightModeDialogPrivate GeditHighlightModeDialogPrivate;
-
-struct _GeditHighlightModeDialog
-{
- GtkDialog parent;
-
- GeditHighlightModeDialogPrivate *priv;
-};
-
-struct _GeditHighlightModeDialogClass
-{
- GtkDialogClass parent_class;
-};
-
-GType gedit_highlight_mode_dialog_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (GeditHighlightModeDialog, gedit_highlight_mode_dialog, GEDIT, HIGHLIGHT_MODE_DIALOG,
GtkDialog)
GtkWidget *gedit_highlight_mode_dialog_new (GtkWindow *parent);
diff --git a/gedit/gedit-highlight-mode-selector.c b/gedit/gedit-highlight-mode-selector.c
index 901896d..5f9e3de 100644
--- a/gedit/gedit-highlight-mode-selector.c
+++ b/gedit/gedit-highlight-mode-selector.c
@@ -31,8 +31,10 @@ enum
N_COLUMNS
};
-struct _GeditHighlightModeSelectorPrivate
+struct _GeditHighlightModeSelector
{
+ GtkGrid parent_instance;
+
GtkWidget *treeview;
GtkWidget *entry;
GtkListStore *liststore;
@@ -49,7 +51,13 @@ enum
static guint signals[LAST_SIGNAL] = { 0 };
-G_DEFINE_TYPE_WITH_PRIVATE (GeditHighlightModeSelector, gedit_highlight_mode_selector, GTK_TYPE_GRID)
+G_DEFINE_TYPE (GeditHighlightModeSelector, gedit_highlight_mode_selector, GTK_TYPE_GRID)
+
+static void
+gedit_highlight_mode_selector_language_selected (GeditHighlightModeSelector *widget,
+ GtkSourceLanguage *language)
+{
+}
static void
gedit_highlight_mode_selector_class_init (GeditHighlightModeSelectorClass *klass)
@@ -57,24 +65,23 @@ gedit_highlight_mode_selector_class_init (GeditHighlightModeSelectorClass *klass
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
signals[LANGUAGE_SELECTED] =
- g_signal_new ("language-selected",
- G_TYPE_FROM_CLASS (klass),
- G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
- G_STRUCT_OFFSET (GeditHighlightModeSelectorClass, language_selected),
- NULL, NULL,
- g_cclosure_marshal_VOID__OBJECT,
- G_TYPE_NONE,
- 1,
- GTK_SOURCE_TYPE_LANGUAGE);
+ g_signal_new_class_handler ("language-selected",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+ G_CALLBACK (gedit_highlight_mode_selector_language_selected),
+ NULL, NULL, NULL,
+ 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-selector.ui");
- gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeSelector, treeview);
- gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeSelector, entry);
- gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeSelector, liststore);
- gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeSelector,
treemodelfilter);
- gtk_widget_class_bind_template_child_private (widget_class, GeditHighlightModeSelector,
treeview_selection);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeSelector, treeview);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeSelector, entry);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeSelector, liststore);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeSelector, treemodelfilter);
+ gtk_widget_class_bind_template_child (widget_class, GeditHighlightModeSelector, treeview_selection);
}
static gboolean
@@ -88,7 +95,7 @@ visible_func (GtkTreeModel *model,
gchar *text_lower;
gboolean visible = FALSE;
- entry_text = gtk_entry_get_text (GTK_ENTRY (selector->priv->entry));
+ entry_text = gtk_entry_get_text (GTK_ENTRY (selector->entry));
if (*entry_text == '\0')
{
@@ -126,11 +133,11 @@ on_entry_changed (GtkEntry *entry,
{
GtkTreeIter iter;
- gtk_tree_model_filter_refilter (selector->priv->treemodelfilter);
+ gtk_tree_model_filter_refilter (selector->treemodelfilter);
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter))
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->treemodelfilter), &iter))
{
- gtk_tree_selection_select_iter (selector->priv->treeview_selection, &iter);
+ gtk_tree_selection_select_iter (selector->treeview_selection, &iter);
}
}
@@ -143,13 +150,13 @@ move_selection (GeditHighlightModeSelector *selector,
gint *indices;
gint ret = FALSE;
- if (!gtk_tree_selection_get_selected (selector->priv->treeview_selection, NULL, &iter) &&
- !gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter))
+ if (!gtk_tree_selection_get_selected (selector->treeview_selection, NULL, &iter) &&
+ !gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->treemodelfilter), &iter))
{
return FALSE;
}
- path = gtk_tree_model_get_path (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL (selector->treemodelfilter), &iter);
indices = gtk_tree_path_get_indices (path);
if (indices)
@@ -159,7 +166,7 @@ move_selection (GeditHighlightModeSelector *selector,
GtkTreePath *new_path;
idx = indices[0];
- num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (selector->priv->treemodelfilter), NULL);
+ num = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (selector->treemodelfilter), NULL);
if ((idx + howmany) < 0)
{
@@ -175,8 +182,8 @@ move_selection (GeditHighlightModeSelector *selector,
}
new_path = gtk_tree_path_new_from_indices (idx, -1);
- gtk_tree_selection_select_path (selector->priv->treeview_selection, new_path);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (selector->priv->treeview),
+ gtk_tree_selection_select_path (selector->treeview_selection, new_path);
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (selector->treeview),
new_path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (new_path);
@@ -225,35 +232,33 @@ on_row_activated (GtkTreeView *tree_view,
static void
gedit_highlight_mode_selector_init (GeditHighlightModeSelector *selector)
{
- GeditHighlightModeSelectorPrivate *priv;
GtkSourceLanguageManager *lm;
const gchar * const *ids;
gint i;
GtkTreeIter iter;
- selector->priv = gedit_highlight_mode_selector_get_instance_private (selector);
- priv = selector->priv;
+ selector = gedit_highlight_mode_selector_get_instance_private (selector);
gtk_widget_init_template (GTK_WIDGET (selector));
- gtk_tree_model_filter_set_visible_func (priv->treemodelfilter,
+ gtk_tree_model_filter_set_visible_func (selector->treemodelfilter,
(GtkTreeModelFilterVisibleFunc)visible_func,
selector,
NULL);
- g_signal_connect (priv->entry, "activate",
+ g_signal_connect (selector->entry, "activate",
G_CALLBACK (on_entry_activate), selector);
- g_signal_connect (priv->entry, "changed",
+ g_signal_connect (selector->entry, "changed",
G_CALLBACK (on_entry_changed), selector);
- g_signal_connect (priv->entry, "key-press-event",
+ g_signal_connect (selector->entry, "key-press-event",
G_CALLBACK (on_entry_key_press_event), selector);
- g_signal_connect (priv->treeview, "row-activated",
+ g_signal_connect (selector->treeview, "row-activated",
G_CALLBACK (on_row_activated), selector);
/* Populate tree model */
- gtk_list_store_append (priv->liststore, &iter);
- gtk_list_store_set (priv->liststore, &iter,
+ gtk_list_store_append (selector->liststore, &iter);
+ gtk_list_store_set (selector->liststore, &iter,
COLUMN_NAME, _("Plain Text"),
COLUMN_LANG, NULL,
-1);
@@ -269,8 +274,8 @@ gedit_highlight_mode_selector_init (GeditHighlightModeSelector *selector)
if (!gtk_source_language_get_hidden (lang))
{
- gtk_list_store_append (priv->liststore, &iter);
- gtk_list_store_set (priv->liststore, &iter,
+ gtk_list_store_append (selector->liststore, &iter);
+ gtk_list_store_set (selector->liststore, &iter,
COLUMN_NAME, gtk_source_language_get_name (lang),
COLUMN_LANG, lang,
-1);
@@ -278,9 +283,9 @@ gedit_highlight_mode_selector_init (GeditHighlightModeSelector *selector)
}
/* select first item */
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter))
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->treemodelfilter), &iter))
{
- gtk_tree_selection_select_iter (selector->priv->treeview_selection, &iter);
+ gtk_tree_selection_select_iter (selector->treeview_selection, &iter);
}
}
@@ -303,13 +308,13 @@ gedit_highlight_mode_selector_select_language (GeditHighlightModeSelector *selec
return;
}
- if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter))
+ if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (selector->treemodelfilter), &iter))
{
do
{
GtkSourceLanguage *lang;
- gtk_tree_model_get (GTK_TREE_MODEL (selector->priv->treemodelfilter),
+ gtk_tree_model_get (GTK_TREE_MODEL (selector->treemodelfilter),
&iter,
COLUMN_LANG, &lang,
-1);
@@ -324,35 +329,34 @@ gedit_highlight_mode_selector_select_language (GeditHighlightModeSelector *selec
{
GtkTreePath *path;
- path = gtk_tree_model_get_path (GTK_TREE_MODEL
(selector->priv->treemodelfilter), &iter);
+ path = gtk_tree_model_get_path (GTK_TREE_MODEL
(selector->treemodelfilter), &iter);
- gtk_tree_selection_select_iter (selector->priv->treeview_selection,
&iter);
- gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW
(selector->priv->treeview),
+ gtk_tree_selection_select_iter (selector->treeview_selection, &iter);
+ gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (selector->treeview),
path, NULL, TRUE, 0.5, 0);
gtk_tree_path_free (path);
break;
}
}
}
- while (gtk_tree_model_iter_next (GTK_TREE_MODEL (selector->priv->treemodelfilter), &iter));
+ while (gtk_tree_model_iter_next (GTK_TREE_MODEL (selector->treemodelfilter), &iter));
}
}
void
gedit_highlight_mode_selector_activate_selected_language (GeditHighlightModeSelector *selector)
{
- GeditHighlightModeSelectorPrivate *priv = selector->priv;
GtkSourceLanguage *lang;
GtkTreeIter iter;
g_return_if_fail (GEDIT_IS_HIGHLIGHT_MODE_SELECTOR (selector));
- if (!gtk_tree_selection_get_selected (priv->treeview_selection, NULL, &iter))
+ if (!gtk_tree_selection_get_selected (selector->treeview_selection, NULL, &iter))
{
return;
}
- gtk_tree_model_get (GTK_TREE_MODEL (priv->treemodelfilter), &iter,
+ gtk_tree_model_get (GTK_TREE_MODEL (selector->treemodelfilter), &iter,
COLUMN_LANG, &lang,
-1);
diff --git a/gedit/gedit-highlight-mode-selector.h b/gedit/gedit-highlight-mode-selector.h
index cdada3e..bcf853c 100644
--- a/gedit/gedit-highlight-mode-selector.h
+++ b/gedit/gedit-highlight-mode-selector.h
@@ -27,34 +27,9 @@
G_BEGIN_DECLS
-#define GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR (gedit_highlight_mode_selector_get_type ())
-#define GEDIT_HIGHLIGHT_MODE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR, GeditHighlightModeSelector))
-#define GEDIT_HIGHLIGHT_MODE_SELECTOR_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR, GeditHighlightModeSelector const))
-#define GEDIT_HIGHLIGHT_MODE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR, GeditHighlightModeSelectorClass))
-#define GEDIT_IS_HIGHLIGHT_MODE_SELECTOR(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR))
-#define GEDIT_IS_HIGHLIGHT_MODE_SELECTOR_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR))
-#define GEDIT_HIGHLIGHT_MODE_SELECTOR_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR, GeditHighlightModeSelectorClass))
+#define GEDIT_TYPE_HIGHLIGHT_MODE_SELECTOR (gedit_highlight_mode_selector_get_type ())
-typedef struct _GeditHighlightModeSelector GeditHighlightModeSelector;
-typedef struct _GeditHighlightModeSelectorClass GeditHighlightModeSelectorClass;
-typedef struct _GeditHighlightModeSelectorPrivate GeditHighlightModeSelectorPrivate;
-
-struct _GeditHighlightModeSelector
-{
- GtkGrid parent;
-
- GeditHighlightModeSelectorPrivate *priv;
-};
-
-struct _GeditHighlightModeSelectorClass
-{
- GtkGridClass parent_class;
-
- void (* language_selected) (GeditHighlightModeSelector *widget,
- GtkSourceLanguage *language);
-};
-
-GType gedit_highlight_mode_selector_get_type (void) G_GNUC_CONST;
+G_DECLARE_FINAL_TYPE (GeditHighlightModeSelector, gedit_highlight_mode_selector, GEDIT,
HIGHLIGHT_MODE_SELECTOR, GtkGrid)
GeditHighlightModeSelector *gedit_highlight_mode_selector_new (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]