[gedit] Port docinfo plugin to libpeas
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Port docinfo plugin to libpeas
- Date: Sat, 26 Jun 2010 10:29:13 +0000 (UTC)
commit c950fdf896b89f77cc7e9c065df33e2952f43165
Author: Paolo Borelli <pborelli gnome org>
Date: Sat Jun 26 12:28:40 2010 +0200
Port docinfo plugin to libpeas
plugins/Makefile.am | 8 +-
plugins/docinfo/Makefile.am | 2 +-
plugins/docinfo/docinfo.gedit-plugin.desktop.in | 1 +
plugins/docinfo/gedit-docinfo-plugin.c | 581 +++++++++-----------
plugins/docinfo/gedit-docinfo-plugin.h | 46 +-
.../{docinfo.ui => gedit-docinfo-plugin.ui} | 0
po/POTFILES.in | 2 +-
7 files changed, 296 insertions(+), 344 deletions(-)
---
diff --git a/plugins/Makefile.am b/plugins/Makefile.am
index 2c4855a..2e53d59 100644
--- a/plugins/Makefile.am
+++ b/plugins/Makefile.am
@@ -1,9 +1,9 @@
DIST_SUBDIRS = \
modelines \
- changecase
+ changecase \
+ docinfo
# checkupdate \
-# docinfo \
# filebrowser \
# modelines \
# sort \
@@ -17,9 +17,9 @@ DIST_SUBDIRS = \
SUBDIRS = \
modelines \
- changecase
+ changecase \
+ docinfo
-# docinfo
# filebrowser
# modelines
# sort
diff --git a/plugins/docinfo/Makefile.am b/plugins/docinfo/Makefile.am
index edf2909..eadd23e 100644
--- a/plugins/docinfo/Makefile.am
+++ b/plugins/docinfo/Makefile.am
@@ -17,7 +17,7 @@ libdocinfo_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS)
libdocinfo_la_LIBADD = $(GEDIT_LIBS)
uidir = $(GEDIT_PLUGINS_DATA_DIR)/docinfo
-ui_DATA = docinfo.ui
+ui_DATA = gedit-docinfo-plugin.ui
plugin_in_files = docinfo.gedit-plugin.desktop.in
diff --git a/plugins/docinfo/docinfo.gedit-plugin.desktop.in b/plugins/docinfo/docinfo.gedit-plugin.desktop.in
index e62598e..7beebfd 100644
--- a/plugins/docinfo/docinfo.gedit-plugin.desktop.in
+++ b/plugins/docinfo/docinfo.gedit-plugin.desktop.in
@@ -5,3 +5,4 @@ _Name=Document Statistics
_Description=Analyzes the current document and reports the number of words, lines, characters and non-space characters in it.
Authors=Paolo Maggi <paolo maggi polito it>;Jorge Alberto Torres <jorge deadoak com>
Copyright=Copyright © 2002-2005 Paolo Maggi
+Website=http://www.gedit.org
diff --git a/plugins/docinfo/gedit-docinfo-plugin.c b/plugins/docinfo/gedit-docinfo-plugin.c
index ec2f311..d58f7d6 100644
--- a/plugins/docinfo/gedit-docinfo-plugin.c
+++ b/plugins/docinfo/gedit-docinfo-plugin.c
@@ -1,13 +1,13 @@
/*
* gedit-docinfo-plugin.c
- *
- * Copyright (C) 2002-2005 Paolo Maggi
+ *
+ * Copyright (C) 2002-2005 Paolo Maggi
*
* This program 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, or (at your option)
* any later version.
- *
+ *
* This program 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
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id$
*/
#ifdef HAVE_CONFIG_H
@@ -32,16 +31,20 @@
#include <pango/pango-break.h>
#include <gmodule.h>
+#include <gedit/gedit-window.h>
+#include <gedit/gedit-window-activatable.h>
#include <gedit/gedit-debug.h>
#include <gedit/gedit-utils.h>
-#define WINDOW_DATA_KEY "GeditDocInfoWindowData"
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_2"
-GEDIT_PLUGIN_REGISTER_TYPE(GeditDocInfoPlugin, gedit_docinfo_plugin)
-
-typedef struct
+struct _GeditDocinfoPluginPrivate
{
+ GeditWindow *window;
+
+ GtkActionGroup *action_group;
+ guint ui_id;
+
GtkWidget *dialog;
GtkWidget *file_name_label;
GtkWidget *lines_label;
@@ -61,144 +64,26 @@ typedef struct
GtkWidget *selected_chars_label;
GtkWidget *selected_chars_ns_label;
GtkWidget *selected_bytes_label;
-} DocInfoDialog;
-
-typedef struct
-{
- GeditPlugin *plugin;
-
- GtkActionGroup *ui_action_group;
- guint ui_id;
+};
- DocInfoDialog *dialog;
-} WindowData;
+static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
-static void docinfo_dialog_response_cb (GtkDialog *widget,
- gint res_id,
- GeditWindow *window);
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDocinfoPlugin,
+ gedit_docinfo_plugin,
+ PEAS_TYPE_EXTENSION_BASE,
+ 0,
+ G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_WINDOW_ACTIVATABLE,
+ gedit_window_activatable_iface_init))
static void
-docinfo_dialog_destroy_cb (GtkObject *obj,
- WindowData *data)
-{
- gedit_debug (DEBUG_PLUGINS);
-
- if (data != NULL)
- {
- g_free (data->dialog);
- data->dialog = NULL;
- }
-}
-
-static DocInfoDialog *
-get_docinfo_dialog (GeditWindow *window,
- WindowData *data)
-{
- DocInfoDialog *dialog;
- gchar *data_dir;
- gchar *ui_file;
- GtkWidget *content;
- GtkWidget *error_widget;
- gboolean ret;
-
- gedit_debug (DEBUG_PLUGINS);
-
- dialog = g_new (DocInfoDialog, 1);
-
- data_dir = gedit_plugin_get_data_dir (data->plugin);
- ui_file = g_build_filename (data_dir, "docinfo.ui", NULL);
- ret = gedit_utils_get_ui_objects (ui_file,
- NULL,
- &error_widget,
- "dialog", &dialog->dialog,
- "docinfo_dialog_content", &content,
- "file_name_label", &dialog->file_name_label,
- "words_label", &dialog->words_label,
- "bytes_label", &dialog->bytes_label,
- "lines_label", &dialog->lines_label,
- "chars_label", &dialog->chars_label,
- "chars_ns_label", &dialog->chars_ns_label,
- "document_label", &dialog->document_label,
- "document_words_label", &dialog->document_words_label,
- "document_bytes_label", &dialog->document_bytes_label,
- "document_lines_label", &dialog->document_lines_label,
- "document_chars_label", &dialog->document_chars_label,
- "document_chars_ns_label", &dialog->document_chars_ns_label,
- "selection_label", &dialog->selection_label,
- "selected_words_label", &dialog->selected_words_label,
- "selected_bytes_label", &dialog->selected_bytes_label,
- "selected_lines_label", &dialog->selected_lines_label,
- "selected_chars_label", &dialog->selected_chars_label,
- "selected_chars_ns_label", &dialog->selected_chars_ns_label,
- NULL);
-
- g_free (data_dir);
- g_free (ui_file);
-
- if (!ret)
- {
- const gchar *err_message;
-
- err_message = gtk_label_get_label (GTK_LABEL (error_widget));
- gedit_warning (GTK_WINDOW (window), "%s", err_message);
-
- g_free (dialog);
- gtk_widget_destroy (error_widget);
-
- return NULL;
- }
-
- gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
- GTK_RESPONSE_OK);
- gtk_window_set_transient_for (GTK_WINDOW (dialog->dialog),
- GTK_WINDOW (window));
-
- g_signal_connect (dialog->dialog,
- "destroy",
- G_CALLBACK (docinfo_dialog_destroy_cb),
- data);
- g_signal_connect (dialog->dialog,
- "response",
- G_CALLBACK (docinfo_dialog_response_cb),
- window);
-
- /* We set this explictely with code since glade does not
- * save the can_focus property when set to false :(
- * Making sure the labels are not focusable is needed to
- * prevent loosing the selection in the document when
- * creating the dialog.
- */
- gtk_widget_set_can_focus (dialog->file_name_label, FALSE);
- gtk_widget_set_can_focus (dialog->words_label, FALSE);
- gtk_widget_set_can_focus (dialog->bytes_label, FALSE);
- gtk_widget_set_can_focus (dialog->lines_label, FALSE);
- gtk_widget_set_can_focus (dialog->chars_label, FALSE);
- gtk_widget_set_can_focus (dialog->chars_ns_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_words_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_bytes_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_lines_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_chars_label, FALSE);
- gtk_widget_set_can_focus (dialog->document_chars_ns_label, FALSE);
- gtk_widget_set_can_focus (dialog->selection_label, FALSE);
- gtk_widget_set_can_focus (dialog->selected_words_label, FALSE);
- gtk_widget_set_can_focus (dialog->selected_bytes_label, FALSE);
- gtk_widget_set_can_focus (dialog->selected_lines_label, FALSE);
- gtk_widget_set_can_focus (dialog->selected_chars_label, FALSE);
- gtk_widget_set_can_focus (dialog->selected_chars_ns_label, FALSE);
-
- return dialog;
-}
-
-static void
calculate_info (GeditDocument *doc,
GtkTextIter *start,
- GtkTextIter *end,
+ GtkTextIter *end,
gint *chars,
gint *words,
gint *white_chars,
gint *bytes)
-{
+{
gchar *text;
gedit_debug (DEBUG_PLUGINS);
@@ -246,9 +131,10 @@ calculate_info (GeditDocument *doc,
}
static void
-docinfo_real (GeditDocument *doc,
- DocInfoDialog *dialog)
+update_document_info (GeditDocinfoPlugin *plugin,
+ GeditDocument *doc)
{
+ GeditDocinfoPluginPrivate *priv;
GtkTextIter start, end;
gint words = 0;
gint chars = 0;
@@ -260,6 +146,8 @@ docinfo_real (GeditDocument *doc,
gedit_debug (DEBUG_PLUGINS);
+ priv = plugin->priv;
+
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc),
&start,
&end);
@@ -271,7 +159,9 @@ docinfo_real (GeditDocument *doc,
&chars, &words, &white_chars, &bytes);
if (chars == 0)
+ {
lines = 0;
+ }
gedit_debug_message (DEBUG_PLUGINS, "Chars: %d", chars);
gedit_debug_message (DEBUG_PLUGINS, "Lines: %d", lines);
@@ -281,35 +171,36 @@ docinfo_real (GeditDocument *doc,
doc_name = gedit_document_get_short_name_for_display (doc);
tmp_str = g_strdup_printf ("<span weight=\"bold\">%s</span>", doc_name);
- gtk_label_set_markup (GTK_LABEL (dialog->file_name_label), tmp_str);
+ gtk_label_set_markup (GTK_LABEL (priv->file_name_label), tmp_str);
g_free (doc_name);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", lines);
- gtk_label_set_text (GTK_LABEL (dialog->document_lines_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->document_lines_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", words);
- gtk_label_set_text (GTK_LABEL (dialog->document_words_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->document_words_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars);
- gtk_label_set_text (GTK_LABEL (dialog->document_chars_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->document_chars_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars - white_chars);
- gtk_label_set_text (GTK_LABEL (dialog->document_chars_ns_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->document_chars_ns_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", bytes);
- gtk_label_set_text (GTK_LABEL (dialog->document_bytes_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->document_bytes_label), tmp_str);
g_free (tmp_str);
}
static void
-selectioninfo_real (GeditDocument *doc,
- DocInfoDialog *dialog)
+update_selection_info (GeditDocinfoPlugin *plugin,
+ GeditDocument *doc)
{
+ GeditDocinfoPluginPrivate *priv;
gboolean sel;
GtkTextIter start, end;
gint words = 0;
@@ -321,6 +212,8 @@ selectioninfo_real (GeditDocument *doc,
gedit_debug (DEBUG_PLUGINS);
+ priv = plugin->priv;
+
sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
&start,
&end);
@@ -339,105 +232,67 @@ selectioninfo_real (GeditDocument *doc,
gedit_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars);
gedit_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes);
- gtk_widget_set_sensitive (dialog->selection_label, TRUE);
- gtk_widget_set_sensitive (dialog->selected_words_label, TRUE);
- gtk_widget_set_sensitive (dialog->selected_bytes_label, TRUE);
- gtk_widget_set_sensitive (dialog->selected_lines_label, TRUE);
- gtk_widget_set_sensitive (dialog->selected_chars_label, TRUE);
- gtk_widget_set_sensitive (dialog->selected_chars_ns_label, TRUE);
+ gtk_widget_set_sensitive (priv->selection_label, TRUE);
+ gtk_widget_set_sensitive (priv->selected_words_label, TRUE);
+ gtk_widget_set_sensitive (priv->selected_bytes_label, TRUE);
+ gtk_widget_set_sensitive (priv->selected_lines_label, TRUE);
+ gtk_widget_set_sensitive (priv->selected_chars_label, TRUE);
+ gtk_widget_set_sensitive (priv->selected_chars_ns_label, TRUE);
}
else
{
gedit_debug_message (DEBUG_PLUGINS, "Selection empty");
- gtk_widget_set_sensitive (dialog->selection_label, FALSE);
- gtk_widget_set_sensitive (dialog->selected_words_label, FALSE);
- gtk_widget_set_sensitive (dialog->selected_bytes_label, FALSE);
- gtk_widget_set_sensitive (dialog->selected_lines_label, FALSE);
- gtk_widget_set_sensitive (dialog->selected_chars_label, FALSE);
- gtk_widget_set_sensitive (dialog->selected_chars_ns_label, FALSE);
+ gtk_widget_set_sensitive (priv->selection_label, FALSE);
+ gtk_widget_set_sensitive (priv->selected_words_label, FALSE);
+ gtk_widget_set_sensitive (priv->selected_bytes_label, FALSE);
+ gtk_widget_set_sensitive (priv->selected_lines_label, FALSE);
+ gtk_widget_set_sensitive (priv->selected_chars_label, FALSE);
+ gtk_widget_set_sensitive (priv->selected_chars_ns_label, FALSE);
}
if (chars == 0)
lines = 0;
tmp_str = g_strdup_printf("%d", lines);
- gtk_label_set_text (GTK_LABEL (dialog->selected_lines_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->selected_lines_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", words);
- gtk_label_set_text (GTK_LABEL (dialog->selected_words_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->selected_words_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars);
- gtk_label_set_text (GTK_LABEL (dialog->selected_chars_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->selected_chars_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", chars - white_chars);
- gtk_label_set_text (GTK_LABEL (dialog->selected_chars_ns_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->selected_chars_ns_label), tmp_str);
g_free (tmp_str);
tmp_str = g_strdup_printf("%d", bytes);
- gtk_label_set_text (GTK_LABEL (dialog->selected_bytes_label), tmp_str);
+ gtk_label_set_text (GTK_LABEL (priv->selected_bytes_label), tmp_str);
g_free (tmp_str);
}
static void
-docinfo_cb (GtkAction *action,
- GeditWindow *window)
+docinfo_dialog_response_cb (GtkDialog *widget,
+ gint res_id,
+ GeditDocinfoPlugin *plugin)
{
- GeditDocument *doc;
- WindowData *data;
+ GeditDocinfoPluginPrivate *priv;
gedit_debug (DEBUG_PLUGINS);
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
-
- doc = gedit_window_get_active_document (window);
- g_return_if_fail (doc != NULL);
-
- if (data->dialog != NULL)
- {
- gtk_window_present (GTK_WINDOW (data->dialog->dialog));
- gtk_widget_grab_focus (GTK_WIDGET (data->dialog->dialog));
- }
- else
- {
- DocInfoDialog *dialog;
-
- dialog = get_docinfo_dialog (window, data);
- g_return_if_fail (dialog != NULL);
-
- data->dialog = dialog;
-
- gtk_widget_show (GTK_WIDGET (dialog->dialog));
- }
-
- docinfo_real (doc,
- data->dialog);
- selectioninfo_real (doc,
- data->dialog);
-}
-
-static void
-docinfo_dialog_response_cb (GtkDialog *widget,
- gint res_id,
- GeditWindow *window)
-{
- WindowData *data;
-
- gedit_debug (DEBUG_PLUGINS);
-
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
+ priv = plugin->priv;
switch (res_id)
{
case GTK_RESPONSE_CLOSE:
{
gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE");
- gtk_widget_destroy (data->dialog->dialog);
+
+ gtk_widget_destroy (priv->dialog);
break;
}
@@ -445,23 +300,144 @@ docinfo_dialog_response_cb (GtkDialog *widget,
case GTK_RESPONSE_OK:
{
GeditDocument *doc;
-
+
gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK");
-
- doc = gedit_window_get_active_document (window);
- g_return_if_fail (doc != NULL);
-
- docinfo_real (doc,
- data->dialog);
-
- selectioninfo_real (doc,
- data->dialog);
-
+
+ doc = gedit_window_get_active_document (priv->window);
+
+ update_document_info (plugin, doc);
+ update_selection_info (plugin, doc);
+
break;
}
}
}
+static void
+create_docinfo_dialog (GeditDocinfoPlugin *plugin)
+{
+ GeditDocinfoPluginPrivate *priv;
+ gchar *data_dir;
+ gchar *ui_file;
+ GtkWidget *content;
+ GtkWidget *error_widget;
+ gboolean ret;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = plugin->priv;
+
+ data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
+
+ ui_file = g_build_filename (data_dir, "gedit-docinfo-plugin.ui", NULL);
+ ret = gedit_utils_get_ui_objects (ui_file,
+ NULL,
+ &error_widget,
+ "dialog", &priv->dialog,
+ "docinfo_dialog_content", &content,
+ "file_name_label", &priv->file_name_label,
+ "words_label", &priv->words_label,
+ "bytes_label", &priv->bytes_label,
+ "lines_label", &priv->lines_label,
+ "chars_label", &priv->chars_label,
+ "chars_ns_label", &priv->chars_ns_label,
+ "document_label", &priv->document_label,
+ "document_words_label", &priv->document_words_label,
+ "document_bytes_label", &priv->document_bytes_label,
+ "document_lines_label", &priv->document_lines_label,
+ "document_chars_label", &priv->document_chars_label,
+ "document_chars_ns_label", &priv->document_chars_ns_label,
+ "selection_label", &priv->selection_label,
+ "selected_words_label", &priv->selected_words_label,
+ "selected_bytes_label", &priv->selected_bytes_label,
+ "selected_lines_label", &priv->selected_lines_label,
+ "selected_chars_label", &priv->selected_chars_label,
+ "selected_chars_ns_label", &priv->selected_chars_ns_label,
+ NULL);
+
+ g_free (data_dir);
+ g_free (ui_file);
+
+ if (!ret)
+ {
+ const gchar *err_message;
+
+ err_message = gtk_label_get_label (GTK_LABEL (error_widget));
+ gedit_warning (GTK_WINDOW (priv->window), "%s", err_message);
+
+ gtk_widget_destroy (error_widget);
+
+ return;
+ }
+
+ gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog),
+ GTK_RESPONSE_OK);
+ gtk_window_set_transient_for (GTK_WINDOW (priv->dialog),
+ GTK_WINDOW (priv->window));
+
+ g_signal_connect (priv->dialog,
+ "destroy",
+ G_CALLBACK (gtk_widget_destroyed),
+ &priv->dialog);
+ g_signal_connect (priv->dialog,
+ "response",
+ G_CALLBACK (docinfo_dialog_response_cb),
+ plugin);
+
+ /* We set this explictely with code since glade does not
+ * save the can_focus property when set to false :(
+ * Making sure the labels are not focusable is needed to
+ * prevent loosing the selection in the document when
+ * creating the dialog.
+ */
+ gtk_widget_set_can_focus (priv->file_name_label, FALSE);
+ gtk_widget_set_can_focus (priv->words_label, FALSE);
+ gtk_widget_set_can_focus (priv->bytes_label, FALSE);
+ gtk_widget_set_can_focus (priv->lines_label, FALSE);
+ gtk_widget_set_can_focus (priv->chars_label, FALSE);
+ gtk_widget_set_can_focus (priv->chars_ns_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_words_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_bytes_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_lines_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_chars_label, FALSE);
+ gtk_widget_set_can_focus (priv->document_chars_ns_label, FALSE);
+ gtk_widget_set_can_focus (priv->selection_label, FALSE);
+ gtk_widget_set_can_focus (priv->selected_words_label, FALSE);
+ gtk_widget_set_can_focus (priv->selected_bytes_label, FALSE);
+ gtk_widget_set_can_focus (priv->selected_lines_label, FALSE);
+ gtk_widget_set_can_focus (priv->selected_chars_label, FALSE);
+ gtk_widget_set_can_focus (priv->selected_chars_ns_label, FALSE);
+}
+
+static void
+docinfo_cb (GtkAction *action,
+ GeditDocinfoPlugin *plugin)
+{
+ GeditDocinfoPluginPrivate *priv;
+ GeditDocument *doc;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ priv = plugin->priv;
+
+ doc = gedit_window_get_active_document (priv->window);
+
+ if (priv->dialog != NULL)
+ {
+ gtk_window_present (GTK_WINDOW (priv->dialog));
+ gtk_widget_grab_focus (GTK_WIDGET (priv->dialog));
+ }
+ else
+ {
+ create_docinfo_dialog (plugin);
+ gtk_widget_show (GTK_WIDGET (priv->dialog));
+ }
+
+ update_document_info (plugin, doc);
+ update_selection_info (plugin, doc);
+}
+
static const GtkActionEntry action_entries[] =
{
{ "DocumentStatistics",
@@ -473,156 +449,143 @@ static const GtkActionEntry action_entries[] =
};
static void
-free_window_data (WindowData *data)
+gedit_docinfo_plugin_init (GeditDocinfoPlugin *plugin)
{
- g_return_if_fail (data != NULL);
-
- gedit_debug (DEBUG_PLUGINS);
+ gedit_debug_message (DEBUG_PLUGINS, "GeditDocinfoPlugin initializing");
- g_object_unref (data->plugin);
+ plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin,
+ GEDIT_TYPE_DOCINFO_PLUGIN,
+ GeditDocinfoPluginPrivate);
+}
- g_object_unref (data->ui_action_group);
-
- if (data->dialog != NULL)
- {
- gtk_widget_destroy (data->dialog->dialog);
- }
-
- g_free (data);
+static void
+gedit_docinfo_plugin_finalize (GObject *object)
+{
+ gedit_debug_message (DEBUG_PLUGINS, "GeditDocinfoPlugin finalizing");
+
+ G_OBJECT_CLASS (gedit_docinfo_plugin_parent_class)->finalize (object);
}
static void
-update_ui_real (GeditWindow *window,
- WindowData *data)
+update_ui (GeditDocinfoPlugin *plugin,
+ GeditWindow *window)
{
+ GeditDocinfoPluginPrivate *priv;
GeditView *view;
gedit_debug (DEBUG_PLUGINS);
+ priv = plugin->priv;
+
view = gedit_window_get_active_view (window);
- gtk_action_group_set_sensitive (data->ui_action_group,
+ gtk_action_group_set_sensitive (priv->action_group,
(view != NULL));
-
- if (data->dialog != NULL)
+
+ if (priv->dialog != NULL)
{
- gtk_dialog_set_response_sensitive (GTK_DIALOG (data->dialog->dialog),
+ gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
GTK_RESPONSE_OK,
(view != NULL));
}
}
static void
-gedit_docinfo_plugin_init (GeditDocInfoPlugin *plugin)
+gedit_docinfo_plugin_activate (GeditWindowActivatable *activatable,
+ GeditWindow *window)
{
- gedit_debug_message (DEBUG_PLUGINS, "GeditDocInfoPlugin initializing");
-}
+ GeditDocinfoPluginPrivate *priv;
+ GtkUIManager *manager;
-static void
-gedit_docinfo_plugin_finalize (GObject *object)
-{
- gedit_debug_message (DEBUG_PLUGINS, "GeditDocInfoPlugin finalizing");
+ gedit_debug (DEBUG_PLUGINS);
- G_OBJECT_CLASS (gedit_docinfo_plugin_parent_class)->finalize (object);
-}
+ priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
-static void
-impl_activate (GeditPlugin *plugin,
- GeditWindow *window)
-{
- GtkUIManager *manager;
- WindowData *data;
-
- gedit_debug (DEBUG_PLUGINS);
+ priv->window = window;
- data = g_new (WindowData, 1);
+ manager = gedit_window_get_ui_manager (window);
- data->plugin = g_object_ref (plugin);
- data->dialog = NULL;
- data->ui_action_group = gtk_action_group_new ("GeditDocInfoPluginActions");
-
- gtk_action_group_set_translation_domain (data->ui_action_group,
+ priv->action_group = gtk_action_group_new ("GeditDocinfoPluginActions");
+ gtk_action_group_set_translation_domain (priv->action_group,
GETTEXT_PACKAGE);
- gtk_action_group_add_actions (data->ui_action_group,
+ gtk_action_group_add_actions (priv->action_group,
action_entries,
G_N_ELEMENTS (action_entries),
- window);
+ activatable);
- manager = gedit_window_get_ui_manager (window);
- gtk_ui_manager_insert_action_group (manager,
- data->ui_action_group,
- -1);
-
- data->ui_id = gtk_ui_manager_new_merge_id (manager);
+ gtk_ui_manager_insert_action_group (manager, priv->action_group, -1);
- g_object_set_data_full (G_OBJECT (window),
- WINDOW_DATA_KEY,
- data,
- (GDestroyNotify) free_window_data);
+ priv->ui_id = gtk_ui_manager_new_merge_id (manager);
- gtk_ui_manager_add_ui (manager,
- data->ui_id,
+ gtk_ui_manager_add_ui (manager,
+ priv->ui_id,
MENU_PATH,
- "DocumentStatistics",
"DocumentStatistics",
- GTK_UI_MANAGER_MENUITEM,
+ "DocumentStatistics",
+ GTK_UI_MANAGER_MENUITEM,
FALSE);
- update_ui_real (window,
- data);
+ update_ui (GEDIT_DOCINFO_PLUGIN (activatable), window);
}
static void
-impl_deactivate (GeditPlugin *plugin,
- GeditWindow *window)
+gedit_docinfo_plugin_deactivate (GeditWindowActivatable *activatable,
+ GeditWindow *window)
{
+ GeditDocinfoPluginPrivate *priv;
GtkUIManager *manager;
- WindowData *data;
gedit_debug (DEBUG_PLUGINS);
+ priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
+
manager = gedit_window_get_ui_manager (window);
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ gtk_ui_manager_remove_ui (manager, priv->ui_id);
+ gtk_ui_manager_remove_action_group (manager, priv->action_group);
+}
- gtk_ui_manager_remove_ui (manager,
- data->ui_id);
- gtk_ui_manager_remove_action_group (manager,
- data->ui_action_group);
+static void
+gedit_docinfo_plugin_update_state (GeditWindowActivatable *activatable,
+ GeditWindow *window)
+{
+ gedit_debug (DEBUG_PLUGINS);
- g_object_set_data (G_OBJECT (window),
- WINDOW_DATA_KEY,
- NULL);
+ update_ui (GEDIT_DOCINFO_PLUGIN (activatable), window);
}
static void
-impl_update_ui (GeditPlugin *plugin,
- GeditWindow *window)
+gedit_docinfo_plugin_class_init (GeditDocinfoPluginClass *klass)
{
- WindowData *data;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- gedit_debug (DEBUG_PLUGINS);
+ object_class->finalize = gedit_docinfo_plugin_finalize;
- data = (WindowData *) g_object_get_data (G_OBJECT (window),
- WINDOW_DATA_KEY);
- g_return_if_fail (data != NULL);
+ g_type_class_add_private (klass, sizeof (GeditDocinfoPluginPrivate));
+}
- update_ui_real (window,
- data);
+static void
+gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface)
+{
+ iface->activate = gedit_docinfo_plugin_activate;
+ iface->deactivate = gedit_docinfo_plugin_deactivate;
+ iface->update_state = gedit_docinfo_plugin_update_state;
}
static void
-gedit_docinfo_plugin_class_init (GeditDocInfoPluginClass *klass)
+gedit_docinfo_plugin_class_finalize (GeditDocinfoPluginClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass);
+}
- object_class->finalize = gedit_docinfo_plugin_finalize;
- plugin_class->activate = impl_activate;
- plugin_class->deactivate = impl_deactivate;
- plugin_class->update_ui = impl_update_ui;
+G_MODULE_EXPORT void
+peas_register_types (PeasObjectModule *module)
+{
+ gedit_docinfo_plugin_register_type (G_TYPE_MODULE (module));
+
+ peas_object_module_register_extension_type (module,
+ GEDIT_TYPE_WINDOW_ACTIVATABLE,
+ GEDIT_TYPE_DOCINFO_PLUGIN);
}
-/* ex:ts=8:noet: */
+
+/* ex:set ts=8 noet: */
diff --git a/plugins/docinfo/gedit-docinfo-plugin.h b/plugins/docinfo/gedit-docinfo-plugin.h
index 506d010..311c38d 100644
--- a/plugins/docinfo/gedit-docinfo-plugin.h
+++ b/plugins/docinfo/gedit-docinfo-plugin.h
@@ -17,7 +17,6 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
- * $Id$
*/
#ifndef __GEDIT_DOCINFO_PLUGIN_H__
@@ -25,52 +24,41 @@
#include <glib.h>
#include <glib-object.h>
-#include <gedit/gedit-plugin.h>
+#include <libpeas/peas-extension-base.h>
+#include <libpeas/peas-object-module.h>
G_BEGIN_DECLS
-/*
- * Type checking and casting macros
- */
#define GEDIT_TYPE_DOCINFO_PLUGIN (gedit_docinfo_plugin_get_type ())
-#define GEDIT_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPlugin))
-#define GEDIT_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPluginClass))
+#define GEDIT_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocinfoPlugin))
+#define GEDIT_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocinfoPluginClass))
#define GEDIT_IS_DOCINFO_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_DOCINFO_PLUGIN))
#define GEDIT_IS_DOCINFO_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_DOCINFO_PLUGIN))
-#define GEDIT_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocInfoPluginClass))
-
-/* Private structure type */
-typedef struct _GeditDocInfoPluginPrivate GeditDocInfoPluginPrivate;
+#define GEDIT_DOCINFO_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_DOCINFO_PLUGIN, GeditDocinfoPluginClass))
-/*
- * Main object structure
- */
-typedef struct _GeditDocInfoPlugin GeditDocInfoPlugin;
+typedef struct _GeditDocinfoPlugin GeditDocinfoPlugin;
+typedef struct _GeditDocinfoPluginPrivate GeditDocinfoPluginPrivate;
+typedef struct _GeditDocinfoPluginClass GeditDocinfoPluginClass;
-struct _GeditDocInfoPlugin
+struct _GeditDocinfoPlugin
{
- GeditPlugin parent_instance;
-};
+ PeasExtensionBase parent;
-/*
- * Class definition
- */
-typedef struct _GeditDocInfoPluginClass GeditDocInfoPluginClass;
+ /*< private >*/
+ GeditDocinfoPluginPrivate *priv;
+};
-struct _GeditDocInfoPluginClass
+struct _GeditDocinfoPluginClass
{
- GeditPluginClass parent_class;
+ PeasExtensionBaseClass parent_class;
};
-/*
- * Public methods
- */
GType gedit_docinfo_plugin_get_type (void) G_GNUC_CONST;
-/* All the plugins must implement this function */
-G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module);
+G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
G_END_DECLS
#endif /* __GEDIT_DOCINFO_PLUGIN_H__ */
+
/* ex:ts=8:noet: */
diff --git a/plugins/docinfo/docinfo.ui b/plugins/docinfo/gedit-docinfo-plugin.ui
similarity index 100%
rename from plugins/docinfo/docinfo.ui
rename to plugins/docinfo/gedit-docinfo-plugin.ui
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 81e3055..0a4af68 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -47,7 +47,7 @@ plugins/checkupdate/checkupdate.gedit-plugin.desktop.in
plugins/checkupdate/gedit-check-update-plugin.c
plugins/checkupdate/org.gnome.gedit.checkupdate.gschema.xml.in.in
plugins/docinfo/docinfo.gedit-plugin.desktop.in
-[type: gettext/glade]plugins/docinfo/docinfo.ui
+[type: gettext/glade]plugins/docinfo/gedit-docinfo-plugin.ui
plugins/docinfo/gedit-docinfo-plugin.c
plugins/externaltools/data/open-terminal-here-osx.desktop.in
plugins/externaltools/externaltools.gedit-plugin.desktop.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]