parent
7e6b54b760
commit
e389368a91
|
@ -31,9 +31,11 @@
|
|||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gmodule.h>
|
||||
#include <libpeas/peas-activatable.h>
|
||||
#include <libpeas-gtk/peas-gtk-configurable.h>
|
||||
|
||||
#include <xed/xed-window.h>
|
||||
#include <xed/xed-debug.h>
|
||||
#include <xed/xed-help.h>
|
||||
#include <xed/xed-prefs-manager.h>
|
||||
#include <xed/xed-statusbar.h>
|
||||
#include <xed/xed-utils.h>
|
||||
|
@ -46,7 +48,6 @@
|
|||
#define XED_METADATA_ATTRIBUTE_SPELL_LANGUAGE "metadata::xed-spell-language"
|
||||
#define XED_METADATA_ATTRIBUTE_SPELL_ENABLED "metadata::xed-spell-enabled"
|
||||
|
||||
#define WINDOW_DATA_KEY "XedSpellPluginWindowData"
|
||||
#define MENU_PATH "/MenuBar/ToolsMenu/ToolsOps_1"
|
||||
|
||||
#define XED_SPELL_PLUGIN_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
||||
|
@ -57,32 +58,40 @@
|
|||
#define SPELL_SCHEMA "org.x.editor.plugins.spell"
|
||||
#define AUTOCHECK_TYPE_KEY "autocheck-type"
|
||||
|
||||
XED_PLUGIN_REGISTER_TYPE(XedSpellPlugin, xed_spell_plugin)
|
||||
static void peas_activatable_iface_init (PeasActivatableInterface *iface);
|
||||
static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface);
|
||||
|
||||
typedef struct
|
||||
G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedSpellPlugin,
|
||||
xed_spell_plugin,
|
||||
PEAS_TYPE_EXTENSION_BASE,
|
||||
0,
|
||||
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_TYPE_ACTIVATABLE,
|
||||
peas_activatable_iface_init)
|
||||
G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE,
|
||||
peas_gtk_configurable_iface_init))
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_OBJECT
|
||||
};
|
||||
|
||||
struct _XedSpellPluginPrivate
|
||||
{
|
||||
GtkWidget *window;
|
||||
|
||||
GtkActionGroup *action_group;
|
||||
guint ui_id;
|
||||
guint message_cid;
|
||||
gulong tab_added_id;
|
||||
gulong tab_removed_id;
|
||||
XedSpellPlugin *plugin;
|
||||
} WindowData;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
XedPlugin *plugin;
|
||||
XedWindow *window;
|
||||
} ActionData;
|
||||
|
||||
struct _XedSpellPluginPrivate
|
||||
{
|
||||
GSettings *settings;
|
||||
};
|
||||
|
||||
static void spell_cb (GtkAction *action, ActionData *action_data);
|
||||
static void set_language_cb (GtkAction *action, ActionData *action_data);
|
||||
static void auto_spell_cb (GtkAction *action, XedWindow *window);
|
||||
static void spell_cb (GtkAction *action, XedSpellPlugin *plugin);
|
||||
static void set_language_cb (GtkAction *action, XedSpellPlugin *plugin);
|
||||
static void auto_spell_cb (GtkAction *action, XedSpellPlugin *plugin);
|
||||
|
||||
/* UI actions. */
|
||||
static const GtkActionEntry action_entries[] =
|
||||
|
@ -120,13 +129,13 @@ typedef struct _SpellConfigureDialog SpellConfigureDialog;
|
|||
|
||||
struct _SpellConfigureDialog
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkWidget *content;
|
||||
|
||||
GtkWidget *never;
|
||||
GtkWidget *always;
|
||||
GtkWidget *document;
|
||||
|
||||
XedSpellPlugin *plugin;
|
||||
GSettings *settings;
|
||||
};
|
||||
|
||||
typedef enum
|
||||
|
@ -163,15 +172,27 @@ xed_spell_plugin_init (XedSpellPlugin *plugin)
|
|||
}
|
||||
|
||||
static void
|
||||
xed_spell_plugin_finalize (GObject *object)
|
||||
xed_spell_plugin_dispose (GObject *object)
|
||||
{
|
||||
XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object);
|
||||
|
||||
xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin finalizing");
|
||||
xed_debug_message (DEBUG_PLUGINS, "XedSpellPlugin disposing");
|
||||
|
||||
if (plugin->priv->window != NULL)
|
||||
{
|
||||
g_object_unref (plugin->priv->window);
|
||||
plugin->priv->window = NULL;
|
||||
}
|
||||
|
||||
if (plugin->priv->action_group)
|
||||
{
|
||||
g_object_unref (plugin->priv->action_group);
|
||||
plugin->priv->action_group = NULL;
|
||||
}
|
||||
|
||||
g_object_unref (G_OBJECT (plugin->priv->settings));
|
||||
|
||||
G_OBJECT_CLASS (xed_spell_plugin_parent_class)->finalize (object);
|
||||
G_OBJECT_CLASS (xed_spell_plugin_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -226,16 +247,16 @@ get_autocheck_type (XedSpellPlugin *plugin)
|
|||
}
|
||||
|
||||
static void
|
||||
set_autocheck_type (XedSpellPlugin *plugin,
|
||||
set_autocheck_type (GSettings *settings,
|
||||
XedSpellPluginAutocheckType autocheck_type)
|
||||
{
|
||||
if (!g_settings_is_writable (plugin->priv->settings,
|
||||
if (!g_settings_is_writable (settings,
|
||||
AUTOCHECK_TYPE_KEY))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
g_settings_set_enum (plugin->priv->settings,
|
||||
g_settings_set_enum (settings,
|
||||
AUTOCHECK_TYPE_KEY,
|
||||
autocheck_type);
|
||||
}
|
||||
|
@ -739,7 +760,6 @@ get_configure_dialog (XedSpellPlugin *plugin)
|
|||
SpellConfigureDialog *dialog = NULL;
|
||||
gchar *data_dir;
|
||||
gchar *ui_file;
|
||||
GtkWidget *content;
|
||||
XedSpellPluginAutocheckType autocheck_type;
|
||||
GtkWidget *error_widget;
|
||||
gboolean ret;
|
||||
|
@ -750,37 +770,15 @@ get_configure_dialog (XedSpellPlugin *plugin)
|
|||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
GtkWidget *dlg = gtk_dialog_new_with_buttons (_("Configure Spell Checker plugin..."),
|
||||
NULL,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_STOCK_CANCEL,
|
||||
GTK_RESPONSE_CANCEL,
|
||||
GTK_STOCK_OK,
|
||||
GTK_RESPONSE_OK,
|
||||
GTK_STOCK_HELP,
|
||||
GTK_RESPONSE_HELP,
|
||||
NULL);
|
||||
dialog = g_slice_new (SpellConfigureDialog);
|
||||
dialog->settings = g_object_ref (plugin->priv->settings);
|
||||
|
||||
g_return_val_if_fail (dlg != NULL, NULL);
|
||||
|
||||
dialog = g_new0 (SpellConfigureDialog, 1);
|
||||
dialog->dialog = dlg;
|
||||
|
||||
|
||||
/* HIG defaults */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG (dialog->dialog)), 5);
|
||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
|
||||
2); /* 2 * 5 + 2 = 12 */
|
||||
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))),
|
||||
5);
|
||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dialog->dialog))), 6);
|
||||
|
||||
data_dir = xed_plugin_get_data_dir (XED_PLUGIN (plugin));
|
||||
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
|
||||
ui_file = g_build_filename (data_dir, "xed-spell-setup-dialog.ui", NULL);
|
||||
ret = xed_utils_get_ui_objects (ui_file,
|
||||
root_objects,
|
||||
&error_widget,
|
||||
"spell_dialog_content", &content,
|
||||
"spell_dialog_content", &dialog->content,
|
||||
"autocheck_never", &dialog->never,
|
||||
"autocheck_document", &dialog->document,
|
||||
"autocheck_always", &dialog->always,
|
||||
|
@ -791,18 +789,9 @@ get_configure_dialog (XedSpellPlugin *plugin)
|
|||
|
||||
if (!ret)
|
||||
{
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
|
||||
error_widget, TRUE, TRUE, 0);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5);
|
||||
|
||||
gtk_widget_show (error_widget);
|
||||
|
||||
return dialog;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
|
||||
|
||||
autocheck_type = get_autocheck_type (plugin);
|
||||
|
||||
if (autocheck_type == AUTOCHECK_ALWAYS)
|
||||
|
@ -818,75 +807,46 @@ get_configure_dialog (XedSpellPlugin *plugin)
|
|||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->never), TRUE);
|
||||
}
|
||||
|
||||
gtk_window_set_default_size (GTK_WIDGET (content), 15, 120);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog->dialog))),
|
||||
content, FALSE, FALSE, 0);
|
||||
g_object_unref (content);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (content), 5);
|
||||
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (dialog->dialog),
|
||||
GTK_RESPONSE_OK);
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
static void
|
||||
ok_button_pressed (SpellConfigureDialog *dialog)
|
||||
configure_dialog_button_toggled (GtkToggleButton *button,
|
||||
SpellConfigureDialog *dialog)
|
||||
{
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->always)))
|
||||
{
|
||||
set_autocheck_type (dialog->plugin, AUTOCHECK_ALWAYS);
|
||||
set_autocheck_type (dialog->settings, AUTOCHECK_ALWAYS);
|
||||
}
|
||||
else if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->document)))
|
||||
{
|
||||
set_autocheck_type (dialog->plugin, AUTOCHECK_DOCUMENT);
|
||||
set_autocheck_type (dialog->settings, AUTOCHECK_DOCUMENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
set_autocheck_type (dialog->plugin, AUTOCHECK_NEVER);
|
||||
set_autocheck_type (dialog->settings, AUTOCHECK_NEVER);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
configure_dialog_response_cb (GtkWidget *widget,
|
||||
gint response,
|
||||
SpellConfigureDialog *dialog)
|
||||
configure_dialog_destroyed (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
switch (response)
|
||||
{
|
||||
case GTK_RESPONSE_HELP:
|
||||
{
|
||||
xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_HELP");
|
||||
SpellConfigureDialog *dialog = (SpellConfigureDialog *) data;
|
||||
|
||||
xed_help_display (GTK_WINDOW (widget),
|
||||
NULL,
|
||||
"xed-spell-checker-plugin");
|
||||
break;
|
||||
}
|
||||
case GTK_RESPONSE_OK:
|
||||
{
|
||||
xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK");
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
ok_button_pressed (dialog);
|
||||
|
||||
gtk_widget_destroy (dialog->dialog);
|
||||
break;
|
||||
}
|
||||
case GTK_RESPONSE_CANCEL:
|
||||
{
|
||||
xed_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CANCEL");
|
||||
gtk_widget_destroy (dialog->dialog);
|
||||
}
|
||||
}
|
||||
g_object_unref (dialog->settings);
|
||||
g_slice_free (SpellConfigureDialog, data);
|
||||
}
|
||||
|
||||
static void
|
||||
set_language_cb (GtkAction *action,
|
||||
ActionData *action_data)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedWindow *window;
|
||||
XedDocument *doc;
|
||||
XedSpellChecker *spell;
|
||||
const XedSpellCheckerLanguage *lang;
|
||||
|
@ -896,7 +856,8 @@ set_language_cb (GtkAction *action,
|
|||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
doc = xed_window_get_active_document (action_data->window);
|
||||
window = XED_WINDOW (plugin->priv->window);
|
||||
doc = xed_window_get_active_document (window);
|
||||
g_return_if_fail (doc != NULL);
|
||||
|
||||
spell = get_spell_checker_from_document (doc);
|
||||
|
@ -904,13 +865,13 @@ set_language_cb (GtkAction *action,
|
|||
|
||||
lang = xed_spell_checker_get_language (spell);
|
||||
|
||||
data_dir = xed_plugin_get_data_dir (action_data->plugin);
|
||||
dlg = xed_spell_language_dialog_new (GTK_WINDOW (action_data->window),
|
||||
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
|
||||
dlg = xed_spell_language_dialog_new (GTK_WINDOW (window),
|
||||
lang,
|
||||
data_dir);
|
||||
g_free (data_dir);
|
||||
|
||||
wg = xed_window_get_group (action_data->window);
|
||||
wg = xed_window_get_group (window);
|
||||
|
||||
gtk_window_group_add_window (wg, GTK_WINDOW (dlg));
|
||||
|
||||
|
@ -926,8 +887,10 @@ set_language_cb (GtkAction *action,
|
|||
|
||||
static void
|
||||
spell_cb (GtkAction *action,
|
||||
ActionData *action_data)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedSpellPluginPrivate *data;
|
||||
XedWindow *window;
|
||||
XedView *view;
|
||||
XedDocument *doc;
|
||||
XedSpellChecker *spell;
|
||||
|
@ -938,7 +901,9 @@ spell_cb (GtkAction *action,
|
|||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
view = xed_window_get_active_view (action_data->window);
|
||||
data = plugin->priv;
|
||||
window = XED_WINDOW (data->window);
|
||||
view = xed_window_get_active_view (window);
|
||||
g_return_if_fail (view != NULL);
|
||||
|
||||
doc = XED_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
|
||||
|
@ -949,14 +914,9 @@ spell_cb (GtkAction *action,
|
|||
|
||||
if (gtk_text_buffer_get_char_count (GTK_TEXT_BUFFER (doc)) <= 0)
|
||||
{
|
||||
WindowData *data;
|
||||
GtkWidget *statusbar;
|
||||
|
||||
data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window),
|
||||
WINDOW_DATA_KEY);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
statusbar = xed_window_get_statusbar (action_data->window);
|
||||
statusbar = xed_window_get_statusbar (window);
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (statusbar),
|
||||
data->message_cid,
|
||||
_("The document is empty."));
|
||||
|
@ -979,14 +939,9 @@ spell_cb (GtkAction *action,
|
|||
word = get_next_misspelled_word (view);
|
||||
if (word == NULL)
|
||||
{
|
||||
WindowData *data;
|
||||
GtkWidget *statusbar;
|
||||
|
||||
data = (WindowData *) g_object_get_data (G_OBJECT (action_data->window),
|
||||
WINDOW_DATA_KEY);
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
statusbar = xed_window_get_statusbar (action_data->window);
|
||||
statusbar = xed_window_get_statusbar (window);
|
||||
xed_statusbar_flash_message (XED_STATUSBAR (statusbar),
|
||||
data->message_cid,
|
||||
_("No misspelled words"));
|
||||
|
@ -994,12 +949,13 @@ spell_cb (GtkAction *action,
|
|||
return;
|
||||
}
|
||||
|
||||
data_dir = xed_plugin_get_data_dir (action_data->plugin);
|
||||
data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin));
|
||||
dlg = xed_spell_checker_dialog_new_from_spell_checker (spell, data_dir);
|
||||
g_free (data_dir);
|
||||
|
||||
gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dlg),
|
||||
GTK_WINDOW (action_data->window));
|
||||
GTK_WINDOW (window));
|
||||
|
||||
g_signal_connect (dlg, "ignore", G_CALLBACK (ignore_cb), view);
|
||||
g_signal_connect (dlg, "ignore_all", G_CALLBACK (ignore_cb), view);
|
||||
|
@ -1054,15 +1010,16 @@ set_auto_spell (XedWindow *window,
|
|||
|
||||
static void
|
||||
auto_spell_cb (GtkAction *action,
|
||||
XedWindow *window)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
|
||||
XedWindow *window;
|
||||
XedDocument *doc;
|
||||
gboolean active;
|
||||
WindowData *data;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
window = XED_WINDOW (plugin->priv->window);
|
||||
|
||||
active = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
|
||||
|
||||
xed_debug_message (DEBUG_PLUGINS, active ? "Auto Spell activated" : "Auto Spell deactivated");
|
||||
|
@ -1071,12 +1028,8 @@ auto_spell_cb (GtkAction *action,
|
|||
if (doc == NULL)
|
||||
return;
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window),
|
||||
WINDOW_DATA_KEY);
|
||||
|
||||
if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT)
|
||||
if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT)
|
||||
{
|
||||
|
||||
xed_document_set_metadata (doc,
|
||||
XED_METADATA_ATTRIBUTE_SPELL_ENABLED,
|
||||
active ? "1" : NULL, NULL);
|
||||
|
@ -1086,26 +1039,10 @@ auto_spell_cb (GtkAction *action,
|
|||
}
|
||||
|
||||
static void
|
||||
free_window_data (WindowData *data)
|
||||
{
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
g_object_unref (data->action_group);
|
||||
g_slice_free (WindowData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
free_action_data (gpointer data)
|
||||
{
|
||||
g_return_if_fail (data != NULL);
|
||||
|
||||
g_slice_free (ActionData, data);
|
||||
}
|
||||
|
||||
static void
|
||||
update_ui_real (XedWindow *window,
|
||||
WindowData *data)
|
||||
update_ui (XedSpellPlugin *plugin)
|
||||
{
|
||||
XedSpellPluginPrivate *data;
|
||||
XedWindow *window;
|
||||
XedDocument *doc;
|
||||
XedView *view;
|
||||
gboolean autospell;
|
||||
|
@ -1113,6 +1050,8 @@ update_ui_real (XedWindow *window,
|
|||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
data = plugin->priv;
|
||||
window = XED_WINDOW (data->window);
|
||||
doc = xed_window_get_active_document (window);
|
||||
view = xed_window_get_active_view (window);
|
||||
|
||||
|
@ -1135,12 +1074,12 @@ update_ui_real (XedWindow *window,
|
|||
"AutoSpell");
|
||||
|
||||
g_signal_handlers_block_by_func (action, auto_spell_cb,
|
||||
window);
|
||||
plugin);
|
||||
set_auto_spell (window, doc, autospell);
|
||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
|
||||
autospell);
|
||||
g_signal_handlers_unblock_by_func (action, auto_spell_cb,
|
||||
window);
|
||||
plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1150,20 +1089,16 @@ update_ui_real (XedWindow *window,
|
|||
}
|
||||
|
||||
static void
|
||||
set_auto_spell_from_metadata (XedWindow *window,
|
||||
set_auto_spell_from_metadata (XedSpellPlugin *plugin,
|
||||
XedDocument *doc,
|
||||
GtkActionGroup *action_group)
|
||||
{
|
||||
gboolean active = FALSE;
|
||||
gchar *active_str = NULL;
|
||||
XedWindow *window;
|
||||
XedDocument *active_doc;
|
||||
XedSpellPluginAutocheckType autocheck_type;
|
||||
WindowData *data;
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window),
|
||||
WINDOW_DATA_KEY);
|
||||
|
||||
autocheck_type = get_autocheck_type(data->plugin);
|
||||
autocheck_type = get_autocheck_type (plugin);
|
||||
|
||||
switch (autocheck_type)
|
||||
{
|
||||
|
@ -1191,6 +1126,8 @@ set_auto_spell_from_metadata (XedWindow *window,
|
|||
g_free (active_str);
|
||||
}
|
||||
|
||||
window = XED_WINDOW (plugin->priv->window);
|
||||
|
||||
set_auto_spell (window, doc, active);
|
||||
|
||||
/* In case that the doc is the active one we mark the spell action */
|
||||
|
@ -1204,22 +1141,21 @@ set_auto_spell_from_metadata (XedWindow *window,
|
|||
"AutoSpell");
|
||||
|
||||
g_signal_handlers_block_by_func (action, auto_spell_cb,
|
||||
window);
|
||||
plugin);
|
||||
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action),
|
||||
active);
|
||||
g_signal_handlers_unblock_by_func (action, auto_spell_cb,
|
||||
window);
|
||||
plugin);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_document_loaded (XedDocument *doc,
|
||||
const GError *error,
|
||||
XedWindow *window)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
if (error == NULL)
|
||||
{
|
||||
WindowData *data;
|
||||
XedSpellChecker *spell;
|
||||
|
||||
spell = XED_SPELL_CHECKER (g_object_get_qdata (G_OBJECT (doc),
|
||||
|
@ -1229,22 +1165,18 @@ on_document_loaded (XedDocument *doc,
|
|||
set_language_from_metadata (spell, doc);
|
||||
}
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window),
|
||||
WINDOW_DATA_KEY);
|
||||
|
||||
set_auto_spell_from_metadata (window, doc, data->action_group);
|
||||
set_auto_spell_from_metadata (plugin, doc, plugin->priv->action_group);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
on_document_saved (XedDocument *doc,
|
||||
const GError *error,
|
||||
XedWindow *window)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedAutomaticSpellChecker *autospell;
|
||||
XedSpellChecker *spell;
|
||||
const gchar *key;
|
||||
WindowData *data;
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
|
@ -1264,10 +1196,7 @@ on_document_saved (XedDocument *doc,
|
|||
key = NULL;
|
||||
}
|
||||
|
||||
data = g_object_get_data (G_OBJECT (window),
|
||||
WINDOW_DATA_KEY);
|
||||
|
||||
if (get_autocheck_type(data->plugin) == AUTOCHECK_DOCUMENT)
|
||||
if (get_autocheck_type (plugin) == AUTOCHECK_DOCUMENT)
|
||||
{
|
||||
|
||||
xed_document_set_metadata (doc,
|
||||
|
@ -1289,7 +1218,7 @@ on_document_saved (XedDocument *doc,
|
|||
static void
|
||||
tab_added_cb (XedWindow *window,
|
||||
XedTab *tab,
|
||||
gpointer useless)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedDocument *doc;
|
||||
|
||||
|
@ -1297,57 +1226,54 @@ tab_added_cb (XedWindow *window,
|
|||
|
||||
g_signal_connect (doc, "loaded",
|
||||
G_CALLBACK (on_document_loaded),
|
||||
window);
|
||||
plugin);
|
||||
|
||||
g_signal_connect (doc, "saved",
|
||||
G_CALLBACK (on_document_saved),
|
||||
window);
|
||||
plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
tab_removed_cb (XedWindow *window,
|
||||
XedTab *tab,
|
||||
gpointer useless)
|
||||
XedSpellPlugin *plugin)
|
||||
{
|
||||
XedDocument *doc;
|
||||
|
||||
doc = xed_tab_get_document (tab);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_loaded, window);
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_saved, window);
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_loaded, plugin);
|
||||
g_signal_handlers_disconnect_by_func (doc, on_document_saved, plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_activate (XedPlugin *plugin,
|
||||
XedWindow *window)
|
||||
xed_spell_plugin_activate (PeasActivatable *activatable)
|
||||
{
|
||||
XedSpellPlugin *plugin;
|
||||
XedSpellPluginPrivate *data;
|
||||
XedWindow *window;
|
||||
GtkUIManager *manager;
|
||||
WindowData *data;
|
||||
ActionData *action_data;
|
||||
GList *docs, *l;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
data = g_slice_new (WindowData);
|
||||
data->plugin = XED_SPELL_PLUGIN (plugin);
|
||||
action_data = g_slice_new (ActionData);
|
||||
action_data->plugin = plugin;
|
||||
action_data->window = window;
|
||||
plugin = XED_SPELL_PLUGIN (activatable);
|
||||
data = plugin->priv;
|
||||
window = XED_WINDOW (data->window);
|
||||
|
||||
manager = xed_window_get_ui_manager (window);
|
||||
|
||||
data->action_group = gtk_action_group_new ("XedSpellPluginActions");
|
||||
gtk_action_group_set_translation_domain (data->action_group,
|
||||
GETTEXT_PACKAGE);
|
||||
gtk_action_group_add_actions_full (data->action_group,
|
||||
gtk_action_group_add_actions (data->action_group,
|
||||
action_entries,
|
||||
G_N_ELEMENTS (action_entries),
|
||||
action_data,
|
||||
(GDestroyNotify) free_action_data);
|
||||
plugin);
|
||||
gtk_action_group_add_toggle_actions (data->action_group,
|
||||
toggle_action_entries,
|
||||
G_N_ELEMENTS (toggle_action_entries),
|
||||
window);
|
||||
plugin);
|
||||
|
||||
gtk_ui_manager_insert_action_group (manager, data->action_group, -1);
|
||||
|
||||
|
@ -1357,11 +1283,6 @@ impl_activate (XedPlugin *plugin,
|
|||
(GTK_STATUSBAR (xed_window_get_statusbar (window)),
|
||||
"spell_plugin_message");
|
||||
|
||||
g_object_set_data_full (G_OBJECT (window),
|
||||
WINDOW_DATA_KEY,
|
||||
data,
|
||||
(GDestroyNotify) free_window_data);
|
||||
|
||||
gtk_ui_manager_add_ui (manager,
|
||||
data->ui_id,
|
||||
MENU_PATH,
|
||||
|
@ -1386,100 +1307,125 @@ impl_activate (XedPlugin *plugin,
|
|||
GTK_UI_MANAGER_MENUITEM,
|
||||
FALSE);
|
||||
|
||||
update_ui_real (window, data);
|
||||
update_ui (plugin);
|
||||
|
||||
docs = xed_window_get_documents (window);
|
||||
for (l = docs; l != NULL; l = g_list_next (l))
|
||||
{
|
||||
XedDocument *doc = XED_DOCUMENT (l->data);
|
||||
|
||||
set_auto_spell_from_metadata (window, doc,
|
||||
set_auto_spell_from_metadata (plugin, doc,
|
||||
data->action_group);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc,
|
||||
on_document_loaded,
|
||||
window);
|
||||
plugin);
|
||||
|
||||
g_signal_handlers_disconnect_by_func (doc,
|
||||
on_document_saved,
|
||||
window);
|
||||
plugin);
|
||||
}
|
||||
|
||||
data->tab_added_id =
|
||||
g_signal_connect (window, "tab-added",
|
||||
G_CALLBACK (tab_added_cb), NULL);
|
||||
G_CALLBACK (tab_added_cb), plugin);
|
||||
data->tab_removed_id =
|
||||
g_signal_connect (window, "tab-removed",
|
||||
G_CALLBACK (tab_removed_cb), NULL);
|
||||
G_CALLBACK (tab_removed_cb), plugin);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_deactivate (XedPlugin *plugin,
|
||||
XedWindow *window)
|
||||
xed_spell_plugin_deactivate (PeasActivatable *activatable)
|
||||
{
|
||||
XedSpellPluginPrivate *data;
|
||||
XedWindow *window;
|
||||
GtkUIManager *manager;
|
||||
WindowData *data;
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
manager = xed_window_get_ui_manager (window);
|
||||
data = XED_SPELL_PLUGIN (activatable)->priv;
|
||||
window = XED_WINDOW (data->window);
|
||||
|
||||
data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
|
||||
g_return_if_fail (data != NULL);
|
||||
manager = xed_window_get_ui_manager (window);
|
||||
|
||||
gtk_ui_manager_remove_ui (manager, data->ui_id);
|
||||
gtk_ui_manager_remove_action_group (manager, data->action_group);
|
||||
|
||||
g_signal_handler_disconnect (window, data->tab_added_id);
|
||||
g_signal_handler_disconnect (window, data->tab_removed_id);
|
||||
|
||||
g_object_set_data (G_OBJECT (window), WINDOW_DATA_KEY, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
impl_update_ui (XedPlugin *plugin,
|
||||
XedWindow *window)
|
||||
xed_spell_plugin_update_state (PeasActivatable *activatable)
|
||||
{
|
||||
WindowData *data;
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
|
||||
xed_debug (DEBUG_PLUGINS);
|
||||
update_ui (XED_SPELL_PLUGIN (activatable));
|
||||
}
|
||||
|
||||
data = (WindowData *) g_object_get_data (G_OBJECT (window), WINDOW_DATA_KEY);
|
||||
g_return_if_fail (data != NULL);
|
||||
static void
|
||||
xed_spell_plugin_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object);
|
||||
|
||||
update_ui_real (window, data);
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_OBJECT:
|
||||
plugin->priv->window = GTK_WIDGET (g_value_dup_object (value));
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
xed_spell_plugin_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
XedSpellPlugin *plugin = XED_SPELL_PLUGIN (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_OBJECT:
|
||||
g_value_set_object (value, plugin->priv->window);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
impl_create_configure_dialog (XedPlugin *plugin)
|
||||
xed_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable)
|
||||
{
|
||||
SpellConfigureDialog *dialog;
|
||||
|
||||
dialog = get_configure_dialog(XED_SPELL_PLUGIN (plugin));
|
||||
dialog = get_configure_dialog (XED_SPELL_PLUGIN (configurable));
|
||||
|
||||
dialog->plugin = XED_SPELL_PLUGIN (plugin);
|
||||
g_signal_connect (dialog->always, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
|
||||
g_signal_connect (dialog->document, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
|
||||
g_signal_connect (dialog->never, "toggled", G_CALLBACK (configure_dialog_button_toggled), dialog);
|
||||
g_signal_connect (dialog->content, "destroy", G_CALLBACK (configure_dialog_destroyed), dialog);
|
||||
|
||||
g_signal_connect (dialog->dialog,
|
||||
"response",
|
||||
G_CALLBACK (configure_dialog_response_cb),
|
||||
dialog);
|
||||
|
||||
return GTK_WIDGET (dialog->dialog);
|
||||
return dialog->content;
|
||||
}
|
||||
|
||||
static void
|
||||
xed_spell_plugin_class_init (XedSpellPluginClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
XedPluginClass *plugin_class = XED_PLUGIN_CLASS (klass);
|
||||
|
||||
object_class->finalize = xed_spell_plugin_finalize;
|
||||
object_class->dispose = xed_spell_plugin_dispose;
|
||||
object_class->set_property = xed_spell_plugin_set_property;
|
||||
object_class->get_property = xed_spell_plugin_get_property;
|
||||
|
||||
plugin_class->activate = impl_activate;
|
||||
plugin_class->deactivate = impl_deactivate;
|
||||
plugin_class->update_ui = impl_update_ui;
|
||||
|
||||
plugin_class->create_configure_dialog = impl_create_configure_dialog;
|
||||
g_object_class_override_property (object_class, PROP_OBJECT, "object");
|
||||
|
||||
if (spell_checker_id == 0)
|
||||
spell_checker_id = g_quark_from_string ("XedSpellCheckerID");
|
||||
|
@ -1489,3 +1435,37 @@ xed_spell_plugin_class_init (XedSpellPluginClass *klass)
|
|||
|
||||
g_type_class_add_private (object_class, sizeof (XedSpellPluginPrivate));
|
||||
}
|
||||
|
||||
static void
|
||||
xed_spell_plugin_class_finalize (XedSpellPluginClass *klass)
|
||||
{
|
||||
/* dummy function - used by G_DEFINE_DYNAMIC_TYPE_EXTENDED */
|
||||
}
|
||||
|
||||
static void
|
||||
peas_activatable_iface_init (PeasActivatableInterface *iface)
|
||||
{
|
||||
iface->activate = xed_spell_plugin_activate;
|
||||
iface->deactivate = xed_spell_plugin_deactivate;
|
||||
iface->update_state = xed_spell_plugin_update_state;
|
||||
}
|
||||
|
||||
static void
|
||||
peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface)
|
||||
{
|
||||
iface->create_configure_widget = xed_spell_plugin_create_configure_widget;
|
||||
}
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
peas_register_types (PeasObjectModule *module)
|
||||
{
|
||||
xed_spell_plugin_register_type (G_TYPE_MODULE (module));
|
||||
|
||||
peas_object_module_register_extension_type (module,
|
||||
PEAS_TYPE_ACTIVATABLE,
|
||||
XED_TYPE_SPELL_PLUGIN);
|
||||
|
||||
peas_object_module_register_extension_type (module,
|
||||
PEAS_GTK_TYPE_CONFIGURABLE,
|
||||
XED_TYPE_SPELL_PLUGIN);
|
||||
}
|
||||
|
|
|
@ -25,52 +25,53 @@
|
|||
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <xed/xed-plugin.h>
|
||||
#include <libpeas/peas-extension-base.h>
|
||||
#include <libpeas/peas-object-module.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/*
|
||||
* Type checking and casting macros
|
||||
*/
|
||||
#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ())
|
||||
#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin))
|
||||
#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass))
|
||||
#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN))
|
||||
#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN))
|
||||
#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass))
|
||||
#define XED_TYPE_SPELL_PLUGIN (xed_spell_plugin_get_type ())
|
||||
#define XED_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPlugin))
|
||||
#define XED_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass))
|
||||
#define XED_IS_SPELL_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_SPELL_PLUGIN))
|
||||
#define XED_IS_SPELL_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_SPELL_PLUGIN))
|
||||
#define XED_SPELL_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_SPELL_PLUGIN, XedSpellPluginClass))
|
||||
|
||||
/* Private structure type */
|
||||
typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate;
|
||||
typedef struct _XedSpellPluginPrivate XedSpellPluginPrivate;
|
||||
|
||||
/*
|
||||
* Main object structure
|
||||
*/
|
||||
typedef struct _XedSpellPlugin XedSpellPlugin;
|
||||
typedef struct _XedSpellPlugin XedSpellPlugin;
|
||||
|
||||
struct _XedSpellPlugin
|
||||
{
|
||||
XedPlugin parent_instance;
|
||||
PeasExtensionBase parent_instance;
|
||||
|
||||
XedSpellPluginPrivate *priv;
|
||||
XedSpellPluginPrivate *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Class definition
|
||||
*/
|
||||
typedef struct _XedSpellPluginClass XedSpellPluginClass;
|
||||
typedef struct _XedSpellPluginClass XedSpellPluginClass;
|
||||
|
||||
struct _XedSpellPluginClass
|
||||
{
|
||||
XedPluginClass parent_class;
|
||||
PeasExtensionBaseClass parent_class;
|
||||
};
|
||||
|
||||
/*
|
||||
* Public methods
|
||||
*/
|
||||
GType xed_spell_plugin_get_type (void) G_GNUC_CONST;
|
||||
GType xed_spell_plugin_get_type (void) G_GNUC_CONST;
|
||||
|
||||
/* All the plugins must implement this function */
|
||||
G_MODULE_EXPORT GType register_xed_plugin (GTypeModule *module);
|
||||
G_MODULE_EXPORT void peas_register_types (PeasObjectModule *module);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in New Issue