[gedit] Implements the possibility to set the default for the highlight misspelled for new documents
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Implements the possibility to set the default for the highlight misspelled for new documents
- Date: Sun, 7 Apr 2019 20:48:34 +0000 (UTC)
commit a648ef46db925c50fff691022caabee8966cd141
Author: Jordi Mas <jmas softcatala org>
Date: Sun Apr 7 20:48:19 2019 +0000
Implements the possibility to set the default for the highlight misspelled for new documents
plugins/spell/gedit-spell-plugin.c | 104 ++++++++++++++++++++-
plugins/spell/meson.build | 13 +++
.../org.gnome.gedit.plugins.spell.gschema.xml.in | 9 ++
plugins/spell/resources/gedit-spell.gresource.xml | 6 ++
plugins/spell/resources/meson.build | 8 ++
.../spell/resources/ui/gedit-spell-setup-dialog.ui | 97 +++++++++++++++++++
po/POTFILES.in | 2 +
7 files changed, 238 insertions(+), 1 deletion(-)
---
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 06af123b6..47d449433 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -26,6 +26,7 @@
#include <gedit/gedit-window.h>
#include <gedit/gedit-window-activatable.h>
#include <gspell/gspell.h>
+#include <libpeas-gtk/peas-gtk-configurable.h>
#include "gedit-spell-app-activatable.h"
@@ -38,12 +39,16 @@
#endif
#define SPELL_ENABLED_STR "1"
+#define SPELL_BASE_SETTINGS "org.gnome.gedit.plugins.spell"
+#define SETTINGS_KEY_HIGHLIGHT_MISSPELLED "highlight-misspelled"
static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
+static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface);
struct _GeditSpellPluginPrivate
{
GeditWindow *window;
+ GSettings *settings;
};
enum
@@ -52,12 +57,24 @@ enum
PROP_WINDOW
};
+typedef struct _SpellConfigureWidget SpellConfigureWidget;
+
+struct _SpellConfigureWidget
+{
+ GtkWidget *content;
+ GtkWidget *highlight_button;
+
+ GSettings *settings;
+};
+
G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditSpellPlugin,
gedit_spell_plugin,
PEAS_TYPE_EXTENSION_BASE,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_WINDOW_ACTIVATABLE,
gedit_window_activatable_iface_init)
+ G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE,
+ peas_gtk_configurable_iface_init)
G_ADD_PRIVATE_DYNAMIC (GeditSpellPlugin))
static void
@@ -108,6 +125,7 @@ gedit_spell_plugin_dispose (GObject *object)
gedit_debug_message (DEBUG_PLUGINS, "GeditSpellPlugin disposing");
g_clear_object (&plugin->priv->window);
+ g_clear_object (&plugin->priv->settings);
G_OBJECT_CLASS (gedit_spell_plugin_parent_class)->dispose (object);
}
@@ -135,6 +153,7 @@ gedit_spell_plugin_init (GeditSpellPlugin *plugin)
gedit_debug_message (DEBUG_PLUGINS, "GeditSpellPlugin initializing");
plugin->priv = gedit_spell_plugin_get_instance_private (plugin);
+ plugin->priv->settings = g_settings_new (SPELL_BASE_SETTINGS);
}
static GspellChecker *
@@ -385,13 +404,14 @@ setup_inline_checker_from_metadata (GeditSpellPlugin *plugin,
GeditView *view)
{
GeditDocument *doc;
- gboolean enabled = FALSE;
+ gboolean enabled;
gchar *enabled_str;
GspellTextView *gspell_view;
GeditView *active_view;
doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
+ enabled = g_settings_get_boolean(plugin->priv->settings, SETTINGS_KEY_HIGHLIGHT_MISSPELLED);
enabled_str = gedit_document_get_metadata (doc, GEDIT_METADATA_ATTRIBUTE_SPELL_ENABLED);
if (enabled_str != NULL)
{
@@ -708,6 +728,88 @@ peas_register_types (PeasObjectModule *module)
peas_object_module_register_extension_type (module,
GEDIT_TYPE_WINDOW_ACTIVATABLE,
GEDIT_TYPE_SPELL_PLUGIN);
+ peas_object_module_register_extension_type (module,
+ PEAS_GTK_TYPE_CONFIGURABLE,
+ GEDIT_TYPE_SPELL_PLUGIN);
+}
+
+static void
+highlight_button_toggled (GtkToggleButton *button,
+ SpellConfigureWidget *widget)
+{
+ gboolean status = gtk_toggle_button_get_active (button);
+ g_settings_set_boolean(widget->settings, SETTINGS_KEY_HIGHLIGHT_MISSPELLED, status);
+}
+
+static void
+configure_widget_destroyed (GtkWidget *widget,
+ gpointer data)
+{
+ SpellConfigureWidget *conf_widget = (SpellConfigureWidget *)data;
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ g_object_unref (conf_widget->settings);
+ g_slice_free (SpellConfigureWidget, data);
+
+ gedit_debug_message (DEBUG_PLUGINS, "END");
+}
+
+static SpellConfigureWidget *
+get_configure_widget (GeditSpellPlugin *plugin)
+{
+ SpellConfigureWidget *widget;
+ GtkBuilder *builder;
+ gchar *root_objects[] = {
+ "spell_dialog_content",
+ NULL
+ };
+
+ gedit_debug (DEBUG_PLUGINS);
+
+ widget = g_slice_new (SpellConfigureWidget);
+ widget->settings = g_object_ref (plugin->priv->settings);
+
+ builder = gtk_builder_new ();
+ gtk_builder_add_objects_from_resource (builder,
"/org/gnome/gedit/plugins/spell/ui/gedit-spell-setup-dialog.ui",
+ root_objects, NULL);
+ widget->content = GTK_WIDGET (gtk_builder_get_object (builder, "spell_dialog_content"));
+ g_object_ref (widget->content);
+
+ widget->highlight_button = GTK_WIDGET (gtk_builder_get_object (builder, "highlight_button"));
+ g_object_unref (builder);
+
+ gboolean status = g_settings_get_boolean(widget->settings, SETTINGS_KEY_HIGHLIGHT_MISSPELLED);
+ gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget->highlight_button), status);
+
+ g_signal_connect (widget->highlight_button,
+ "toggled",
+ G_CALLBACK (highlight_button_toggled),
+ widget);
+
+ g_signal_connect (widget->content,
+ "destroy",
+ G_CALLBACK (configure_widget_destroyed),
+ widget);
+
+ return widget;
+}
+
+
+static GtkWidget *
+gedit_spell_plugin_create_configure_widget (PeasGtkConfigurable *configurable)
+{
+ SpellConfigureWidget *widget;
+
+ widget = get_configure_widget (GEDIT_SPELL_PLUGIN (configurable));
+
+ return widget->content;
+}
+
+static void
+peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface)
+{
+ iface->create_configure_widget = gedit_spell_plugin_create_configure_widget;
}
/* ex:set ts=8 noet: */
diff --git a/plugins/spell/meson.build b/plugins/spell/meson.build
index f9c4f6c13..b7d1bef42 100644
--- a/plugins/spell/meson.build
+++ b/plugins/spell/meson.build
@@ -12,6 +12,8 @@ libspell_c_args = [
'-DHAVE_CONFIG_H',
]
+subdir('resources')
+
libspell_sha = shared_module(
'spell',
sources: libspell_sources,
@@ -25,6 +27,17 @@ libspell_sha = shared_module(
)
)
+configure_file(
+ input: 'org.gnome.gedit.plugins.spell.gschema.xml.in',
+ output: 'org.gnome.gedit.plugins.spell.gschema.xml',
+ configuration: gschema_xml,
+ install: true,
+ install_dir: join_paths(
+ glibdir,
+ 'schemas',
+ )
+)
+
custom_target(
'spell.plugin',
input: 'spell.plugin.desktop.in',
diff --git a/plugins/spell/org.gnome.gedit.plugins.spell.gschema.xml.in
b/plugins/spell/org.gnome.gedit.plugins.spell.gschema.xml.in
new file mode 100644
index 000000000..3d740b659
--- /dev/null
+++ b/plugins/spell/org.gnome.gedit.plugins.spell.gschema.xml.in
@@ -0,0 +1,9 @@
+<schemalist>
+ <schema gettext-domain="@GETTEXT_PACKAGE@" id="org.gnome.gedit.plugins.spell"
path="/org/gnome/gedit/plugins/spell/">
+ <key name="highlight-misspelled" type="b">
+ <default>false</default>
+ <summary>Highlight misspelled words</summary>
+ <description>Default setting for highlight misspelled words.</description>
+ </key>
+ </schema>
+</schemalist>
diff --git a/plugins/spell/resources/gedit-spell.gresource.xml
b/plugins/spell/resources/gedit-spell.gresource.xml
new file mode 100644
index 000000000..861e061e6
--- /dev/null
+++ b/plugins/spell/resources/gedit-spell.gresource.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<gresources>
+ <gresource prefix="/org/gnome/gedit/plugins/spell">
+ <file preprocess="xml-stripblanks">ui/gedit-spell-setup-dialog.ui</file>
+ </gresource>
+</gresources>
diff --git a/plugins/spell/resources/meson.build b/plugins/spell/resources/meson.build
new file mode 100644
index 000000000..ad15d5e2f
--- /dev/null
+++ b/plugins/spell/resources/meson.build
@@ -0,0 +1,8 @@
+libspell_res = gnome.compile_resources(
+ 'gedit-spell-resources',
+ 'gedit-spell.gresource.xml',
+)
+
+libspell_sources += [
+ libspell_res.get(0),
+]
diff --git a/plugins/spell/resources/ui/gedit-spell-setup-dialog.ui
b/plugins/spell/resources/ui/gedit-spell-setup-dialog.ui
new file mode 100644
index 000000000..5e922c2d5
--- /dev/null
+++ b/plugins/spell/resources/ui/gedit-spell-setup-dialog.ui
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.22.1 -->
+<interface>
+ <requires lib="gtk+" version="3.0"/>
+ <object class="GtkDialog" id="spell_dialog">
+ <property name="can_focus">False</property>
+ <property name="title" translatable="yes">Configure spell plugin</property>
+ <property name="type_hint">normal</property>
+ <child>
+ <placeholder/>
+ </child>
+ <child internal-child="vbox">
+ <object class="GtkBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">8</property>
+ <child internal-child="action_area">
+ <object class="GtkButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="layout_style">end</property>
+ <child>
+ <object class="GtkButton" id="button1">
+ <property name="label" translatable="yes">_Close</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="can_default">True</property>
+ <property name="receives_default">True</property>
+ <property name="use_underline">True</property>
+ <property name="always_show_image">True</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="padding">10</property>
+ <property name="pack_type">end</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="spell_dialog_content">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="vexpand">True</property>
+ <property name="border_width">10</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">6</property>
+ <child>
+ <object class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Defaults for new documents</property>
+ <property name="xalign">0</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkCheckButton" id="highlight_button">
+ <property name="label" translatable="yes">Highlight misspelled words</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">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="position">1</property>
+ </packing>
+ </child>
+ </object>
+ </child>
+ </object>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index b99ebd32f..9eabfaa4a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -107,6 +107,8 @@ plugins/sort/resources/ui/gedit-sort-plugin.ui
plugins/sort/sort.plugin.desktop.in
plugins/spell/gedit-spell-app-activatable.c
plugins/spell/gedit-spell-plugin.c
+plugins/spell/org.gnome.gedit.plugins.spell.gschema.xml.in
+plugins/spell/resources/ui/gedit-spell-setup-dialog.ui
plugins/spell/spell.plugin.desktop.in
plugins/time/gedit-time-plugin.c
plugins/time/org.gnome.gedit.plugins.time.gschema.xml.in
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]