[gedit/wip/redesign2] spell: implement app activatable to add accelerator



commit 3c46c0b5b9a4d55b1b6c368b693dea0664c6adb1
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Jan 6 22:06:52 2014 +0100

    spell: implement app activatable to add accelerator

 plugins/spell/Makefile.am                   |    2 +
 plugins/spell/gedit-spell-app-activatable.c |  159 +++++++++++++++++++++++++++
 plugins/spell/gedit-spell-app-activatable.h |   56 ++++++++++
 plugins/spell/gedit-spell-plugin.c          |    2 +
 4 files changed, 219 insertions(+), 0 deletions(-)
---
diff --git a/plugins/spell/Makefile.am b/plugins/spell/Makefile.am
index a113b0d..8e07ebf 100644
--- a/plugins/spell/Makefile.am
+++ b/plugins/spell/Makefile.am
@@ -18,6 +18,8 @@ plugin_LTLIBRARIES = libspell.la
 libspell_la_SOURCES = \
        gedit-spell-plugin.c                            \
        gedit-spell-plugin.h                            \
+       gedit-spell-app-activatable.c                   \
+       gedit-spell-app-activatable.h                   \
        gedit-spell-checker.c                           \
        gedit-spell-checker.h                           \
        gedit-spell-checker-dialog.c                    \
diff --git a/plugins/spell/gedit-spell-app-activatable.c b/plugins/spell/gedit-spell-app-activatable.c
new file mode 100644
index 0000000..e926c7e
--- /dev/null
+++ b/plugins/spell/gedit-spell-app-activatable.c
@@ -0,0 +1,159 @@
+/*
+ * gedit-spell-app-activatable.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gedit 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 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "gedit-spell-app-activatable.h"
+#include <gedit/gedit-app-activatable.h>
+#include <gedit/gedit-app.h>
+#include <libpeas/peas-object-module.h>
+
+
+typedef struct _GeditSpellAppActivatablePrivate
+{
+       GeditApp *app;
+} GeditSpellAppActivatablePrivate;
+
+enum
+{
+       PROP_0,
+       PROP_APP
+};
+
+static void gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface);
+
+G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditSpellAppActivatable,
+                               gedit_spell_app_activatable,
+                               G_TYPE_OBJECT,
+                               0,
+                               G_ADD_PRIVATE_DYNAMIC (GeditSpellAppActivatable)
+                               G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_APP_ACTIVATABLE,
+                                                              gedit_app_activatable_iface_init))
+
+static void
+gedit_spell_app_activatable_dispose (GObject *object)
+{
+       GeditSpellAppActivatable *activatable = GEDIT_SPELL_APP_ACTIVATABLE (object);
+       GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(activatable);
+
+       g_clear_object (&priv->app);
+
+       G_OBJECT_CLASS (gedit_spell_app_activatable_parent_class)->dispose (object);
+}
+
+static void
+gedit_spell_app_activatable_set_property (GObject      *object,
+                                          guint         prop_id,
+                                          const GValue *value,
+                                          GParamSpec   *pspec)
+{
+       GeditSpellAppActivatable *activatable = GEDIT_SPELL_APP_ACTIVATABLE (object);
+       GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(activatable);
+
+       switch (prop_id)
+       {
+               case PROP_APP:
+                       priv->app = GEDIT_APP (g_value_dup_object (value));
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gedit_spell_app_activatable_get_property (GObject    *object,
+                                          guint       prop_id,
+                                          GValue     *value,
+                                          GParamSpec *pspec)
+{
+       GeditSpellAppActivatable *activatable = GEDIT_SPELL_APP_ACTIVATABLE (object);
+       GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(activatable);
+
+       switch (prop_id)
+       {
+               case PROP_APP:
+                       g_value_set_object (value, priv->app);
+                       break;
+
+               default:
+                       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+                       break;
+       }
+}
+
+static void
+gedit_spell_app_activatable_class_init (GeditSpellAppActivatableClass *klass)
+{
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->dispose = gedit_spell_app_activatable_dispose;
+       object_class->set_property = gedit_spell_app_activatable_set_property;
+       object_class->get_property = gedit_spell_app_activatable_get_property;
+
+       g_object_class_override_property (object_class, PROP_APP, "app");
+}
+
+static void
+gedit_spell_app_activatable_class_finalize (GeditSpellAppActivatableClass *klass)
+{
+}
+
+static void
+gedit_spell_app_activatable_init (GeditSpellAppActivatable *self)
+{
+}
+
+static void
+gedit_spell_app_activatable_activate (GeditAppActivatable *activatable)
+{
+       GeditSpellAppActivatable *app_activatable = GEDIT_SPELL_APP_ACTIVATABLE (activatable);
+       GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(app_activatable);
+
+       gtk_application_add_accelerator (GTK_APPLICATION (priv->app), "<Shift>F7", "win.check_spell", NULL);
+}
+
+static void
+gedit_spell_app_activatable_deactivate (GeditAppActivatable *activatable)
+{
+       GeditSpellAppActivatable *app_activatable = GEDIT_SPELL_APP_ACTIVATABLE (activatable);
+       GeditSpellAppActivatablePrivate *priv = gedit_spell_app_activatable_get_instance_private 
(app_activatable);
+
+       gtk_application_remove_accelerator (GTK_APPLICATION (priv->app), "win.check_spell", NULL);
+}
+
+static void
+gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface)
+{
+       iface->activate = gedit_spell_app_activatable_activate;
+       iface->deactivate = gedit_spell_app_activatable_deactivate;
+}
+
+void
+gedit_spell_app_activatable_register (GTypeModule *module)
+{
+       gedit_spell_app_activatable_register_type (module);
+
+       peas_object_module_register_extension_type (PEAS_OBJECT_MODULE (module),
+                                                   GEDIT_TYPE_APP_ACTIVATABLE,
+                                                   GEDIT_TYPE_SPELL_APP_ACTIVATABLE);
+}
+
+/* ex:ts=8:noet: */
diff --git a/plugins/spell/gedit-spell-app-activatable.h b/plugins/spell/gedit-spell-app-activatable.h
new file mode 100644
index 0000000..4dc2f02
--- /dev/null
+++ b/plugins/spell/gedit-spell-app-activatable.h
@@ -0,0 +1,56 @@
+/*
+ * gedit-spell-app-activatable.h
+ * This file is part of gedit
+ *
+ * Copyright (C) 2014 - Ignacio Casal Quinteiro
+ *
+ * gedit 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 of the License, or
+ * (at your option) any later version.
+ *
+ * gedit 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 gedit. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __GEDIT_SPELL_APP_ACTIVATABLE_H__
+#define __GEDIT_SPELL_APP_ACTIVATABLE_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_SPELL_APP_ACTIVATABLE               (gedit_spell_app_activatable_get_type ())
+#define GEDIT_SPELL_APP_ACTIVATABLE(obj)               (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE, GeditSpellAppActivatable))
+#define GEDIT_SPELL_APP_ACTIVATABLE_CONST(obj)         (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE, GeditSpellAppActivatable const))
+#define GEDIT_SPELL_APP_ACTIVATABLE_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST ((klass), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE, GeditSpellAppActivatableClass))
+#define GEDIT_IS_SPELL_APP_ACTIVATABLE(obj)            (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE))
+#define GEDIT_IS_SPELL_APP_ACTIVATABLE_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE))
+#define GEDIT_SPELL_APP_ACTIVATABLE_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GEDIT_TYPE_SPELL_APP_ACTIVATABLE, GeditSpellAppActivatableClass))
+
+typedef struct _GeditSpellAppActivatable       GeditSpellAppActivatable;
+typedef struct _GeditSpellAppActivatableClass  GeditSpellAppActivatableClass;
+
+struct _GeditSpellAppActivatable
+{
+       GObject parent;
+};
+
+struct _GeditSpellAppActivatableClass
+{
+       GObjectClass parent_class;
+};
+
+GType          gedit_spell_app_activatable_get_type (void) G_GNUC_CONST;
+
+void           gedit_spell_app_activatable_register (GTypeModule *module);
+
+G_END_DECLS
+
+#endif /* __GEDIT_SPELL_APP_ACTIVATABLE_H__ */
diff --git a/plugins/spell/gedit-spell-plugin.c b/plugins/spell/gedit-spell-plugin.c
index 854f57e..708de5d 100644
--- a/plugins/spell/gedit-spell-plugin.c
+++ b/plugins/spell/gedit-spell-plugin.c
@@ -23,6 +23,7 @@
 #endif
 
 #include "gedit-spell-plugin.h"
+#include "gedit-spell-app-activatable.h"
 #include "gedit-spell-utils.h"
 
 #include <string.h> /* For strlen */
@@ -1229,6 +1230,7 @@ G_MODULE_EXPORT void
 peas_register_types (PeasObjectModule *module)
 {
        gedit_spell_plugin_register_type (G_TYPE_MODULE (module));
+       gedit_spell_app_activatable_register (G_TYPE_MODULE (module));
 
        peas_object_module_register_extension_type (module,
                                                    GEDIT_TYPE_WINDOW_ACTIVATABLE,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]