Commit 229578ed authored by Christian Hergert's avatar Christian Hergert

spellcheck: start on spellcheck plugin

This starts bringing back the spellcheck plugin using our more
simplified APIs in libide. We still need to bring back the
widgets and transient sidebar features.

Additionally, we've removed the bubble drawing from source view
and we should probably add something that allows us to re-enable
that in a generic fashion.
parent bc659a41
......@@ -62,6 +62,7 @@ option('with_quick_highlight', type: 'boolean')
option('with_retab', type: 'boolean')
option('with_rust_langserv', type: 'boolean')
option('with_rustup', type: 'boolean')
option('with_spellcheck', type: 'boolean')
option('with_support', type: 'boolean')
option('with_symbol_tree', type: 'boolean')
option('with_sysmon', type: 'boolean')
......
......@@ -51,6 +51,7 @@ subdir('quick-highlight')
subdir('retab')
subdir('rust-langserv')
subdir('rustup')
subdir('spellcheck')
subdir('support')
subdir('symbol-tree')
subdir('sysmon')
......@@ -103,6 +104,7 @@ status += [
'Retab ................. : @0@'.format(get_option('with_retab')),
'Rust Language Server .. : @0@'.format(get_option('with_rust_langserv')),
'RustUp ................ : @0@'.format(get_option('with_rustup')),
'Spellchecking ......... : @0@'.format(get_option('with_spellcheck')),
'Support Tool .......... : @0@'.format(get_option('with_support')),
'Symbol Tree ........... : @0@'.format(get_option('with_symbol_tree')),
'System Monitor ........ : @0@'.format(get_option('with_sysmon')),
......
/* gbp-spell-buffer-addin.c
*
* Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
*
* 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 3 of the License, 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "gbp-spell-buffer-addin"
#include "gbp-spell-buffer-addin.h"
struct _GbpSpellBufferAddin
{
GObject parent_instance;
/* Unowned reference to buffer */
IdeBuffer *buffer;
/* Owned spellchecker instance */
GspellChecker *spellchecker;
guint enabled : 1;
};
enum {
PROP_0,
PROP_ENABLED,
N_PROPS
};
static void
gbp_spell_buffer_addin_apply (GbpSpellBufferAddin *self)
{
GspellTextBuffer *spell_buffer;
IDE_ENTRY;
g_assert (GBP_IS_SPELL_BUFFER_ADDIN (self));
if (self->enabled == FALSE || self->buffer == NULL)
{
g_clear_object (&self->spellchecker);
return;
}
/* The returned GspellTextBuffer is owned by self->buffer */
spell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (GTK_TEXT_BUFFER (self->buffer));
g_assert (GSPELL_IS_TEXT_BUFFER (spell_buffer));
/* Setup the spell checker for the buffer. We retrain the spellchecker
* instance so that we can add words/modify the dictionary at runtime.
*/
self->spellchecker = gspell_checker_new (NULL);
gspell_text_buffer_set_spell_checker (spell_buffer, self->spellchecker);
IDE_EXIT;
}
static void
gbp_spell_buffer_addin_load (IdeBufferAddin *addin,
IdeBuffer *buffer)
{
GbpSpellBufferAddin *self = (GbpSpellBufferAddin *)addin;
IDE_ENTRY;
g_assert (GBP_IS_SPELL_BUFFER_ADDIN (self));
g_assert (IDE_IS_BUFFER (buffer));
self->buffer = buffer;
gbp_spell_buffer_addin_apply (self);
IDE_EXIT;
}
static void
gbp_spell_buffer_addin_unload (IdeBufferAddin *addin,
IdeBuffer *buffer)
{
GbpSpellBufferAddin *self = (GbpSpellBufferAddin *)addin;
IDE_ENTRY;
g_assert (GBP_IS_SPELL_BUFFER_ADDIN (self));
g_assert (IDE_IS_BUFFER (buffer));
self->buffer = NULL;
gbp_spell_buffer_addin_apply (self);
IDE_EXIT;
}
static void
buffer_addin_iface_init (IdeBufferAddinInterface *iface)
{
iface->load = gbp_spell_buffer_addin_load;
iface->unload = gbp_spell_buffer_addin_unload;
}
G_DEFINE_TYPE_WITH_CODE (GbpSpellBufferAddin, gbp_spell_buffer_addin, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (IDE_TYPE_BUFFER_ADDIN, buffer_addin_iface_init))
static GParamSpec *properties [N_PROPS];
static void
gbp_spell_buffer_addin_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
GbpSpellBufferAddin *self = GBP_SPELL_BUFFER_ADDIN (object);
switch (prop_id)
{
case PROP_ENABLED:
g_value_set_boolean (value, self->enabled);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gbp_spell_buffer_addin_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
GbpSpellBufferAddin *self = GBP_SPELL_BUFFER_ADDIN (object);
switch (prop_id)
{
case PROP_ENABLED:
self->enabled = g_value_get_boolean (value);
gbp_spell_buffer_addin_apply (self);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
}
static void
gbp_spell_buffer_addin_class_init (GbpSpellBufferAddinClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->get_property = gbp_spell_buffer_addin_get_property;
object_class->set_property = gbp_spell_buffer_addin_set_property;
properties [PROP_ENABLED] =
g_param_spec_boolean ("enabled",
"Enabled",
"If the spellchecker is enabled",
FALSE,
(G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
g_object_class_install_properties (object_class, N_PROPS, properties);
}
static void
gbp_spell_buffer_addin_init (GbpSpellBufferAddin *self)
{
}
/**
* gbp_spell_buffer_addin_get_checker:
* @self: a #GbpSpellBufferAddin
*
* Gets the #GspellChecker used by the underlying buffer, or %NULL if
* no spellchecker is active.
*
* Returns: (transfer none): A #GspellChecker
*
* Since: 3.26
*/
GspellChecker *
gbp_spell_buffer_addin_get_checker (GbpSpellBufferAddin *self)
{
g_return_val_if_fail (GBP_IS_SPELL_BUFFER_ADDIN (self), NULL);
return self->spellchecker;
}
/* gbp-spell-buffer-addin.h
*
* Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
*
* 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 3 of the License, 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <ide.h>
#include <gspell/gspell.h>
G_BEGIN_DECLS
#define GBP_TYPE_SPELL_BUFFER_ADDIN (gbp_spell_buffer_addin_get_type())
G_DECLARE_FINAL_TYPE (GbpSpellBufferAddin, gbp_spell_buffer_addin, GBP, SPELL_BUFFER_ADDIN, GObject)
GspellChecker *gbp_spell_buffer_addin_get_checker (GbpSpellBufferAddin *self);
G_END_DECLS
/* gbp-spell-editor-view-addin.c
*
* Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
*
* 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 3 of the License, 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "gbp-spell-editor-view-addin"
#include "gbp-spell-buffer-addin.h"
#include "gbp-spell-editor-view-addin.h"
struct _GbpSpellEditorViewAddin
{
GObject parent_instance;
DzlBindingGroup *bindings;
};
static void
gbp_spell_editor_view_addin_load (IdeEditorViewAddin *addin,
IdeEditorView *view)
{
GbpSpellEditorViewAddin *self = (GbpSpellEditorViewAddin *)addin;
g_autoptr(DzlPropertiesGroup) group = NULL;
IdeBufferAddin *buffer_addin;
GspellTextView *wrapper;
IdeSourceView *source_view;
IdeBuffer *buffer;
g_assert (GBP_IS_SPELL_EDITOR_VIEW_ADDIN (self));
g_assert (IDE_IS_EDITOR_VIEW (view));
source_view = ide_editor_view_get_view (view);
g_assert (source_view != NULL);
g_assert (IDE_IS_SOURCE_VIEW (source_view));
buffer = ide_editor_view_get_buffer (view);
g_assert (buffer != NULL);
g_assert (IDE_IS_BUFFER (buffer));
buffer_addin = ide_buffer_addin_find_by_module_name (buffer, "spellcheck-plugin");
g_assert (buffer_addin != NULL);
g_assert (GBP_IS_SPELL_BUFFER_ADDIN (buffer_addin));
wrapper = gspell_text_view_get_from_gtk_text_view (GTK_TEXT_VIEW (source_view));
g_assert (wrapper != NULL);
g_assert (GSPELL_IS_TEXT_VIEW (wrapper));
self->bindings = dzl_binding_group_new ();
dzl_binding_group_bind (self->bindings, "enabled", wrapper, "enable-language-menu", 0);
dzl_binding_group_bind (self->bindings, "enabled", wrapper, "inline-spell-checking", 0);
dzl_binding_group_set_source (self->bindings, buffer_addin);
group = dzl_properties_group_new (G_OBJECT (buffer_addin));
dzl_properties_group_add_all_properties (group);
gtk_widget_insert_action_group (GTK_WIDGET (view), "spellcheck", G_ACTION_GROUP (group));
}
static void
gbp_spell_editor_view_addin_unload (IdeEditorViewAddin *addin,
IdeEditorView *view)
{
GbpSpellEditorViewAddin *self = (GbpSpellEditorViewAddin *)addin;
g_assert (GBP_IS_SPELL_EDITOR_VIEW_ADDIN (self));
g_assert (IDE_IS_EDITOR_VIEW (view));
gtk_widget_insert_action_group (GTK_WIDGET (view), "spellcheck", NULL);
dzl_binding_group_set_source (self->bindings, NULL);
g_clear_object (&self->bindings);
}
static void
editor_view_addin_iface_init (IdeEditorViewAddinInterface *iface)
{
iface->load = gbp_spell_editor_view_addin_load;
iface->unload = gbp_spell_editor_view_addin_unload;
}
G_DEFINE_TYPE_WITH_CODE (GbpSpellEditorViewAddin, gbp_spell_editor_view_addin, G_TYPE_OBJECT,
G_IMPLEMENT_INTERFACE (IDE_TYPE_EDITOR_VIEW_ADDIN,
editor_view_addin_iface_init))
static void
gbp_spell_editor_view_addin_class_init (GbpSpellEditorViewAddinClass *klass)
{
}
static void
gbp_spell_editor_view_addin_init (GbpSpellEditorViewAddin *self)
{
}
/* gbp-spell-editor-view-addin.h
*
* Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
*
* 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 3 of the License, 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <ide.h>
G_BEGIN_DECLS
#define GBP_TYPE_SPELL_EDITOR_VIEW_ADDIN (gbp_spell_editor_view_addin_get_type())
G_DECLARE_FINAL_TYPE (GbpSpellEditorViewAddin, gbp_spell_editor_view_addin, GBP, SPELL_EDITOR_VIEW_ADDIN, GObject)
G_END_DECLS
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<menu id="ide-source-view-popup-menu">
<section id="ide-source-view-popup-menu-highlighting-section">
<submenu id="ide-source-view-popup-menu-highlighting-submenu">
<attribute name="label" translatable="yes">Highlighting</attribute>
<item>
<attribute name="label" translatable="yes">Underline misspelled words</attribute>
<attribute name="action">spellcheck.enabled</attribute>
</item>
</submenu>
</section>
</menu>
</interface>
if get_option('with_spellcheck')
spellcheck_resources = gnome.compile_resources(
'gbp-spell-resources',
'spellcheck.gresource.xml',
c_name: 'gbp_spell',
)
spellcheck_sources = [
'spellcheck-plugin.c',
'gbp-spell-buffer-addin.c',
'gbp-spell-buffer-addin.h',
'gbp-spell-editor-view-addin.c',
'gbp-spell-editor-view-addin.h',
spellcheck_resources[0],
]
spellcheck_deps = plugin_deps + [
dependency('gspell-1', version: '>= 1.2.0'),
dependency('enchant'),
]
shared_module('spellcheck-plugin', spellcheck_sources,
dependencies: spellcheck_deps,
link_args: plugin_link_args,
link_depends: plugin_link_deps,
install: true,
install_dir: plugindir,
install_rpath: pkglibdir_abs,
)
configure_file(
input: 'spellcheck.plugin',
output: 'spellcheck.plugin',
configuration: configuration_data(),
install: true,
install_dir: plugindir,
)
endif
/* spellcheck-plugin.c
*
* Copyright (C) 2017 Christian Hergert <chergert@redhat.com>
*
* 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 3 of the License, 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
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <libpeas/peas.h>
#include <ide.h>
#include "gbp-spell-buffer-addin.h"
#include "gbp-spell-editor-view-addin.h"
void
peas_register_types (PeasObjectModule *module)
{
peas_object_module_register_extension_type (module, IDE_TYPE_BUFFER_ADDIN, GBP_TYPE_SPELL_BUFFER_ADDIN);
peas_object_module_register_extension_type (module, IDE_TYPE_EDITOR_VIEW_ADDIN, GBP_TYPE_SPELL_EDITOR_VIEW_ADDIN);
}
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/builder/plugins/spellcheck-plugin">
<file compressed="true" preprocess="xml-stripblanks">gtk/menus.ui</file>
</gresource>
</gresources>
[Plugin]
Module=spellcheck-plugin
Name=Spellcheck
Description=Provides spellchecking for documents
Authors=Sébastien Lafargue <slafargue@gnome.org>
Copyright=Copyright © 2016 Sébastien Lafargue
Depends=editor
Builtin=true
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment