Creation of plugin Word completion (#199)
* Creation of plugin * Correction of shortcut * Update translations+fix code * Add Makefile.in and tab/space fix * Add makefile.am remove makefile.in
This commit is contained in:
		
				
					committed by
					
						 Clement Lefebvre
						Clement Lefebvre
					
				
			
			
				
	
			
			
			
						parent
						
							3999de8f59
						
					
				
				
					commit
					8a32b92c33
				
			
							
								
								
									
										49
									
								
								plugins/wordcompletion/Makefile.am
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										49
									
								
								plugins/wordcompletion/Makefile.am
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,49 @@ | ||||
| # Word completion plugin | ||||
| plugindir = $(XED_PLUGINS_LIBS_DIR) | ||||
|  | ||||
| AM_CPPFLAGS = 							\ | ||||
| 	-I$(top_srcdir)						\ | ||||
| 	$(XED_CFLAGS) 					\ | ||||
| 	$(ENCHANT_CFLAGS)					\ | ||||
| 	$(WARN_CFLAGS)						\ | ||||
| 	$(DISABLE_DEPRECATED_CFLAGS) | ||||
|  | ||||
| plugin_LTLIBRARIES = libwordcompletion.la | ||||
|  | ||||
| libwordcompletion_la_SOURCES = \ | ||||
| 	xed-wordcompletion-plugin.h	\ | ||||
| 	xed-wordcompletion-plugin.c	 | ||||
|  | ||||
| libwordcompletion_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) | ||||
| libwordcompletion_la_LIBADD  = $(XED_LIBS) $(ENCHANT_LIBS) | ||||
|  | ||||
| plugin_in_files = wordcompletion.plugin.desktop.in | ||||
|  | ||||
| %.plugin: %.plugin.desktop.in $(INTLTOOL_MERGE) $(wildcard $(top_srcdir)/po/*po) ; $(INTLTOOL_MERGE) $(top_srcdir)/po $< $@ -d -u -c $(top_builddir)/po/.intltool-merge-cache | ||||
|  | ||||
| plugin_DATA = $(plugin_in_files:.plugin.desktop.in=.plugin) | ||||
|  | ||||
| uidir = $(XED_PLUGINS_DATA_DIR)/wordcompletion | ||||
| ui_DATA = xed-wordcompletion-configure.ui | ||||
|  | ||||
| @INTLTOOL_XML_NOMERGE_RULE@ | ||||
| wordcompletion_gschema_in = org.x.editor.plugins.wordcompletion.gschema.xml.in | ||||
| gsettings_SCHEMAS = $(wordcompletion_gschema_in:.xml.in=.xml) | ||||
| @GSETTINGS_RULES@ | ||||
|  | ||||
| EXTRA_DIST = 					\ | ||||
| 	$(plugin_in_files)			\ | ||||
| 	$(wordcompletion_gschema_in) | ||||
| 	 | ||||
| 	 | ||||
| CLEANFILES = \ | ||||
| 	$(plugin_DATA)		\ | ||||
| 	$(gsettings_SCHEMAS)		 | ||||
|  | ||||
| DISTCLEANFILES = \ | ||||
| 	$(plugin_DATA)		 | ||||
|  | ||||
| dist-hook: | ||||
| 	cd $(distdir); rm -f $(BUILT_SOURCES) | ||||
| 	 | ||||
| -include $(top_srcdir)/git.mk | ||||
| @@ -0,0 +1,16 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <schemalist gettext-domain="xed"> | ||||
|   <schema id="org.x.editor.plugins.wordcompletion" path="/org/x/editor/plugins/wordcompletion/"> | ||||
|     <key name="interactive-completion" type="b"> | ||||
|       <default>true</default> | ||||
|       <summary>Interactive Completion</summary> | ||||
|       <description>Whether to enable interactive completion.</description> | ||||
|     </key> | ||||
|     <key name="minimum-word-size" type="u"> | ||||
|       <range min="2" max="100" /> | ||||
|       <default>2</default> | ||||
|       <summary>Minimum Word Size</summary> | ||||
|       <description>The minimum word size to complete.</description> | ||||
|     </key> | ||||
|   </schema> | ||||
| </schemalist> | ||||
| @@ -0,0 +1,16 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <schemalist gettext-domain="@GETTEXT_PACKAGE@"> | ||||
|   <schema id="org.x.editor.plugins.wordcompletion" path="/org/x/editor/plugins/wordcompletion/"> | ||||
|     <key name="interactive-completion" type="b"> | ||||
|       <default>true</default> | ||||
|       <summary>Interactive Completion</summary> | ||||
|       <description>Whether to enable interactive completion.</description> | ||||
|     </key> | ||||
|     <key name="minimum-word-size" type="u"> | ||||
|       <range min="2" max="100" /> | ||||
|       <default>2</default> | ||||
|       <summary>Minimum Word Size</summary> | ||||
|       <description>The minimum word size to complete.</description> | ||||
|     </key> | ||||
|   </schema> | ||||
| </schemalist> | ||||
							
								
								
									
										9
									
								
								plugins/wordcompletion/wordcompletion.plugin
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								plugins/wordcompletion/wordcompletion.plugin
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| [Plugin] | ||||
| Module=wordcompletion | ||||
| IAge=3 | ||||
| Name=Word Completion | ||||
| Description=Word completion using the completion framework | ||||
| Authors=Jesse van den Kieboom <jesse@gnome.org>\nIgnacio Casal Quinteiro <icq@gnome.org>\nMickael Albertus <mickael.albertus@gmail.com> | ||||
| Copyright=Copyright © 2017 Mickael Albertus\n2009 Jesse van den Kieboom | ||||
| Website=http://www.mate-desktop.org | ||||
| Version=@VERSION@ | ||||
							
								
								
									
										9
									
								
								plugins/wordcompletion/wordcompletion.plugin.desktop.in
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								plugins/wordcompletion/wordcompletion.plugin.desktop.in
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| [Plugin] | ||||
| Module=wordcompletion | ||||
| IAge=3 | ||||
| _Name=Word Completion | ||||
| _Description=Word completion using the completion framework | ||||
| Authors=Jesse van den Kieboom <jesse@gnome.org>\nIgnacio Casal Quinteiro <icq@gnome.org>\nMickael Albertus <mickael.albertus@gmail.com> | ||||
| Copyright=Copyright © 2017 Mickael Albertus\n2009 Jesse van den Kieboom | ||||
| Website=http://www.mate-desktop.org | ||||
| Version=@VERSION@ | ||||
							
								
								
									
										142
									
								
								plugins/wordcompletion/xed-wordcompletion-configure.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										142
									
								
								plugins/wordcompletion/xed-wordcompletion-configure.ui
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,142 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <!-- Generated with glade 3.18.3 --> | ||||
| <interface> | ||||
|   <requires lib="gtk+" version="3.0"/> | ||||
|   <object class="GtkAdjustment" id="adjustment1"> | ||||
|     <property name="lower">2</property> | ||||
|     <property name="upper">100</property> | ||||
|     <property name="value">2</property> | ||||
|     <property name="step_increment">1</property> | ||||
|     <property name="page_increment">10</property> | ||||
|   </object> | ||||
|   <object class="GtkDialog" id="configure_dialog"> | ||||
|     <property name="can_focus">False</property> | ||||
|     <property name="title" translatable="yes">Auto-completion</property> | ||||
|     <property name="resizable">False</property> | ||||
|     <property name="type_hint">normal</property> | ||||
|     <child internal-child="vbox"> | ||||
|       <object class="GtkBox" id="dialog-vbox1"> | ||||
|         <property name="can_focus">False</property> | ||||
|         <property name="margin_left">5</property> | ||||
|         <property name="margin_right">5</property> | ||||
|         <property name="margin_top">2</property> | ||||
|         <property name="margin_bottom">5</property> | ||||
|         <property name="orientation">vertical</property> | ||||
|         <child internal-child="action_area"> | ||||
|           <object class="GtkButtonBox" id="dialog-action_area1"> | ||||
|             <property name="can_focus">False</property> | ||||
|             <property name="layout_style">end</property> | ||||
|             <child> | ||||
|               <object class="GtkButton" id="button1"> | ||||
|                 <property name="label">gtk-ok</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">True</property> | ||||
|                 <property name="use_stock">True</property> | ||||
|                 <property name="yalign">0.52999997138977051</property> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">True</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">0</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">False</property> | ||||
|             <property name="fill">False</property> | ||||
|             <property name="position">0</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|         <child> | ||||
|           <object class="GtkBox" id="box1"> | ||||
|             <property name="visible">True</property> | ||||
|             <property name="can_focus">False</property> | ||||
|             <property name="margin_top">5</property> | ||||
|             <property name="margin_bottom">10</property> | ||||
|             <property name="orientation">vertical</property> | ||||
|             <property name="spacing">9</property> | ||||
|             <child> | ||||
|               <object class="GtkLabel" id="label2"> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">False</property> | ||||
|                 <property name="ypad">6</property> | ||||
|                 <property name="label" translatable="yes">Check if you want to enable automatic completion.  | ||||
| In any case, you can use the tool on <Ctrl>+<Space></property> | ||||
|                 <attributes> | ||||
|                   <attribute name="style" value="italic"/> | ||||
|                   <attribute name="weight" value="semibold"/> | ||||
|                 </attributes> | ||||
|               </object> | ||||
|               <packing> | ||||
|                 <property name="expand">False</property> | ||||
|                 <property name="fill">True</property> | ||||
|                 <property name="position">0</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|             <child> | ||||
|               <object class="GtkCheckButton" id="check_button_interactive_completion"> | ||||
|                 <property name="label" translatable="yes">Automatic completion</property> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">True</property> | ||||
|                 <property name="receives_default">False</property> | ||||
|                 <property name="xalign">0.10000000149011612</property> | ||||
|                 <property name="yalign">0.44999998807907104</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> | ||||
|             <child> | ||||
|               <object class="GtkBox" id="box2"> | ||||
|                 <property name="visible">True</property> | ||||
|                 <property name="can_focus">False</property> | ||||
|                 <property name="spacing">5</property> | ||||
|                 <child> | ||||
|                   <object class="GtkLabel" id="label1"> | ||||
|                     <property name="visible">True</property> | ||||
|                     <property name="can_focus">False</property> | ||||
|                     <property name="label" translatable="yes">Minimum word size for auto-completion</property> | ||||
|                   </object> | ||||
|                   <packing> | ||||
|                     <property name="expand">True</property> | ||||
|                     <property name="fill">True</property> | ||||
|                     <property name="position">0</property> | ||||
|                   </packing> | ||||
|                 </child> | ||||
|                 <child> | ||||
|                   <object class="GtkSpinButton" id="spin_button_min_word_size"> | ||||
|                     <property name="visible">True</property> | ||||
|                     <property name="can_focus">True</property> | ||||
|                     <property name="adjustment">adjustment1</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">2</property> | ||||
|               </packing> | ||||
|             </child> | ||||
|           </object> | ||||
|           <packing> | ||||
|             <property name="expand">False</property> | ||||
|             <property name="fill">True</property> | ||||
|             <property name="position">1</property> | ||||
|           </packing> | ||||
|         </child> | ||||
|       </object> | ||||
|     </child> | ||||
|     <action-widgets> | ||||
|       <action-widget response="0">button1</action-widget> | ||||
|     </action-widgets> | ||||
|   </object> | ||||
| </interface> | ||||
							
								
								
									
										470
									
								
								plugins/wordcompletion/xed-wordcompletion-plugin.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										470
									
								
								plugins/wordcompletion/xed-wordcompletion-plugin.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,470 @@ | ||||
| /* | ||||
|  * Copyright (C) 2009 Ignacio Casal Quinteiro <icq@gnome.org> | ||||
|  *               2009 Jesse van den Kieboom <jesse@gnome.org> | ||||
|  *               2013 Sébastien Wilmet <swilmet@gnome.org> | ||||
|  *               2017 Mickael Albertus <mickael.albertus@gmail.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 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 | ||||
|  * 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, write to the Free Software | ||||
|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|  */ | ||||
|  | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include <config.h> | ||||
| #endif | ||||
|  | ||||
| #include "xed-wordcompletion-plugin.h" | ||||
|  | ||||
| #include <glib/gi18n-lib.h> | ||||
| #include <glib.h> | ||||
| #include <gio/gio.h> | ||||
|  | ||||
| #include <xed/xed-debug.h> | ||||
| #include <xed/xed-window.h> | ||||
| #include <xed/xed-window-activatable.h> | ||||
| #include <xed/xed-utils.h> | ||||
| #include <xed/xed-view.h> | ||||
| #include <xed/xed-view-activatable.h> | ||||
| #include <libpeas-gtk/peas-gtk-configurable.h> | ||||
| #include <gtksourceview/gtksource.h> | ||||
| #include <gtksourceview/completion-providers/words/gtksourcecompletionwords.h> | ||||
|  | ||||
| #define WINDOW_PROVIDER "XedWordCompletionPluginProvider" | ||||
|  | ||||
| #define WORDCOMPLETION_SETTINGS_BASE "org.x.editor.plugins.wordcompletion" | ||||
| #define SETTINGS_KEY_INTERACTIVE_COMPLETION "interactive-completion" | ||||
| #define SETTINGS_KEY_MINIMUM_WORD_SIZE "minimum-word-size" | ||||
|  | ||||
| static void xed_window_activatable_iface_init (XedWindowActivatableInterface *iface); | ||||
| static void xed_view_activatable_iface_init (XedViewActivatableInterface *iface); | ||||
| static void peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface); | ||||
|  | ||||
| G_DEFINE_DYNAMIC_TYPE_EXTENDED (XedWordCompletionPlugin, | ||||
|                                 xed_wordcompletion_plugin, | ||||
|                                 PEAS_TYPE_EXTENSION_BASE, | ||||
|                                 0, | ||||
|                                 G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_WINDOW_ACTIVATABLE, | ||||
|                                                                xed_window_activatable_iface_init) | ||||
|                                 G_IMPLEMENT_INTERFACE_DYNAMIC (XED_TYPE_VIEW_ACTIVATABLE, | ||||
|                                                                xed_view_activatable_iface_init) | ||||
|                                 G_IMPLEMENT_INTERFACE_DYNAMIC (PEAS_GTK_TYPE_CONFIGURABLE, | ||||
|                                                                peas_gtk_configurable_iface_init)) | ||||
|  | ||||
| struct _XedWordCompletionPluginPrivate | ||||
| { | ||||
|     GtkWidget *window; | ||||
|     XedView *view; | ||||
|     GtkSourceCompletionProvider *provider; | ||||
|   GSettings *settings; | ||||
| }; | ||||
|  | ||||
| enum | ||||
| { | ||||
|     PROP_0, | ||||
|     PROP_WINDOW, | ||||
|     PROP_VIEW | ||||
| }; | ||||
|  | ||||
|  | ||||
| typedef struct _WordCompletionConfigureWidget WordCompletionConfigureWidget; | ||||
|  | ||||
| struct _WordCompletionConfigureWidget | ||||
| { | ||||
|     GtkWidget *dialog; | ||||
|     GtkWidget *min_word_size; | ||||
|     GtkWidget *interactive_completion; | ||||
|  | ||||
|     GSettings *settings; | ||||
| }; | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_init (XedWordCompletionPlugin *plugin) | ||||
| { | ||||
|     xed_debug_message (DEBUG_PLUGINS, "XedWordCompletionPlugin initializing"); | ||||
|  | ||||
|     plugin->priv = G_TYPE_INSTANCE_GET_PRIVATE (plugin, | ||||
|                                                 XED_TYPE_WORDCOMPLETION_PLUGIN, | ||||
|                                                 XedWordCompletionPluginPrivate); | ||||
|  | ||||
|     plugin->priv->settings = g_settings_new (WORDCOMPLETION_SETTINGS_BASE); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_finalize (GObject *object) | ||||
| { | ||||
|     XedWordCompletionPlugin *plugin = XED_WORDCOMPLETION_PLUGIN (object); | ||||
|  | ||||
|     xed_debug_message (DEBUG_PLUGINS, "XedWordCompletionPlugin finalizing"); | ||||
|  | ||||
|     g_object_unref (G_OBJECT (plugin->priv->settings)); | ||||
|  | ||||
|     G_OBJECT_CLASS (xed_wordcompletion_plugin_parent_class)->finalize (object); | ||||
| } | ||||
|  | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_dispose (GObject *object) | ||||
| { | ||||
|     XedWordCompletionPlugin *plugin = XED_WORDCOMPLETION_PLUGIN (object); | ||||
|  | ||||
|     if (plugin->priv->window != NULL) | ||||
|     { | ||||
|         g_object_unref (plugin->priv->window); | ||||
|         plugin->priv->window = NULL; | ||||
|     } | ||||
|  | ||||
|     if (plugin->priv->view != NULL) | ||||
|     { | ||||
|         g_object_unref (plugin->priv->view); | ||||
|         plugin->priv->view = NULL; | ||||
|     } | ||||
|  | ||||
|     if (plugin->priv->provider != NULL) | ||||
|     { | ||||
|         g_object_unref (plugin->priv->provider); | ||||
|         plugin->priv->provider = NULL; | ||||
|     } | ||||
|  | ||||
|     G_OBJECT_CLASS (xed_wordcompletion_plugin_parent_class)->dispose (object); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_set_property (GObject      *object, | ||||
|                                            guint         prop_id, | ||||
|                                            const GValue *value, | ||||
|                                            GParamSpec   *pspec) | ||||
| { | ||||
|     XedWordCompletionPlugin *plugin = XED_WORDCOMPLETION_PLUGIN (object); | ||||
|  | ||||
|     switch (prop_id) | ||||
|     { | ||||
|         case PROP_WINDOW: | ||||
|             plugin->priv->window = g_value_dup_object (value); | ||||
|             break; | ||||
|         case PROP_VIEW: | ||||
|             plugin->priv->view = XED_VIEW (g_value_dup_object (value)); | ||||
|             break; | ||||
|         default: | ||||
|             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||||
|             break; | ||||
|     } | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_get_property (GObject    *object, | ||||
|                                         guint       prop_id, | ||||
|                                         GValue     *value, | ||||
|                                         GParamSpec *pspec) | ||||
| { | ||||
|     XedWordCompletionPlugin *plugin = XED_WORDCOMPLETION_PLUGIN (object); | ||||
|  | ||||
|     switch (prop_id) | ||||
|     { | ||||
|         case PROP_WINDOW: | ||||
|             g_value_set_object (value, plugin->priv->window); | ||||
|             break; | ||||
|         case PROP_VIEW: | ||||
|             g_value_set_object (value, plugin->priv->view); | ||||
|             break; | ||||
|         default: | ||||
|             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); | ||||
|             break; | ||||
|     } | ||||
| } | ||||
|  | ||||
| static void | ||||
| update_activation (GtkSourceCompletionWords *provider, | ||||
|                    GSettings                *settings) | ||||
| { | ||||
|     GtkSourceCompletionActivation activation; | ||||
|  | ||||
|     g_object_get (provider, "activation", &activation, NULL); | ||||
|  | ||||
|     if (g_settings_get_boolean (settings, SETTINGS_KEY_INTERACTIVE_COMPLETION)) | ||||
|     { | ||||
|         activation |= GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE; | ||||
|     } | ||||
|     else | ||||
|     { | ||||
|         activation &= ~GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE; | ||||
|     } | ||||
|  | ||||
|     g_object_set (provider, "activation", activation, NULL); | ||||
| } | ||||
|  | ||||
| static void | ||||
| on_interactive_completion_changed_cb (GSettings                *settings, | ||||
|                                       gchar                    *key, | ||||
|                                       GtkSourceCompletionWords *provider) | ||||
| { | ||||
|     update_activation (provider, settings); | ||||
| } | ||||
|  | ||||
| static GtkSourceCompletionWords * | ||||
| create_provider (void) | ||||
| { | ||||
|     GtkSourceCompletionWords *provider; | ||||
|     GSettings *settings; | ||||
|  | ||||
|     provider = gtk_source_completion_words_new (_("Word completion"), NULL); | ||||
|  | ||||
|     settings = g_settings_new (WORDCOMPLETION_SETTINGS_BASE); | ||||
|  | ||||
|     g_settings_bind (settings, SETTINGS_KEY_MINIMUM_WORD_SIZE, | ||||
|              provider, "minimum-word-size", | ||||
|              G_SETTINGS_BIND_GET); | ||||
|  | ||||
|     update_activation (provider, settings); | ||||
|  | ||||
|     g_signal_connect_object (settings, | ||||
|                  "changed::" SETTINGS_KEY_INTERACTIVE_COMPLETION, | ||||
|                  G_CALLBACK (on_interactive_completion_changed_cb), | ||||
|                  provider, | ||||
|                  0); | ||||
|  | ||||
|     g_object_unref (settings); | ||||
|  | ||||
|     return provider; | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_window_activate (XedWindowActivatable *activatable) | ||||
| { | ||||
|     XedWordCompletionPluginPrivate *priv; | ||||
|     GtkSourceCompletionWords *provider; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     priv = XED_WORDCOMPLETION_PLUGIN (activatable)->priv; | ||||
|  | ||||
|     provider = create_provider (); | ||||
|  | ||||
|     g_object_set_data_full (G_OBJECT (priv->window), | ||||
|                             WINDOW_PROVIDER, | ||||
|                             provider, | ||||
|                             (GDestroyNotify)g_object_unref); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_window_deactivate (XedWindowActivatable *activatable) | ||||
| { | ||||
|     XedWordCompletionPluginPrivate *priv; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     priv = XED_WORDCOMPLETION_PLUGIN (activatable)->priv; | ||||
|  | ||||
|     g_object_set_data (G_OBJECT (priv->window), WINDOW_PROVIDER, NULL); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_view_activate (XedViewActivatable *activatable) | ||||
| { | ||||
|     XedWordCompletionPluginPrivate *priv; | ||||
|     GtkSourceCompletion *completion; | ||||
|     GtkSourceCompletionProvider *provider; | ||||
|     GtkTextBuffer *buf; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     priv = XED_WORDCOMPLETION_PLUGIN (activatable)->priv; | ||||
|  | ||||
|     priv->window = gtk_widget_get_toplevel (GTK_WIDGET (priv->view)); | ||||
|  | ||||
|     /* We are disposing the window */ | ||||
|     g_object_ref (priv->window); | ||||
|  | ||||
|     completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->view)); | ||||
|     buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)); | ||||
|  | ||||
|     provider = g_object_get_data (G_OBJECT (priv->window), WINDOW_PROVIDER); | ||||
|  | ||||
|     if (provider == NULL) | ||||
|     { | ||||
|         /* Standalone provider */ | ||||
|         provider = GTK_SOURCE_COMPLETION_PROVIDER (create_provider ()); | ||||
|     } | ||||
|  | ||||
|     priv->provider = g_object_ref (provider); | ||||
|  | ||||
|     gtk_source_completion_add_provider (completion, provider, NULL); | ||||
|     gtk_source_completion_words_register (GTK_SOURCE_COMPLETION_WORDS (provider), | ||||
|                                           buf); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_view_deactivate (XedViewActivatable *activatable) | ||||
| { | ||||
|     XedWordCompletionPluginPrivate *priv; | ||||
|     GtkSourceCompletion *completion; | ||||
|     GtkSourceCompletionProvider *provider; | ||||
|     GtkTextBuffer *buf; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     priv = XED_WORDCOMPLETION_PLUGIN (activatable)->priv; | ||||
|  | ||||
|     completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (priv->view)); | ||||
|     buf = gtk_text_view_get_buffer (GTK_TEXT_VIEW (priv->view)); | ||||
|  | ||||
|     gtk_source_completion_remove_provider (completion, | ||||
|                                            priv->provider, | ||||
|                                            NULL); | ||||
|  | ||||
|     gtk_source_completion_words_unregister (GTK_SOURCE_COMPLETION_WORDS (priv->provider), | ||||
|                                             buf); | ||||
| } | ||||
|  | ||||
| static void | ||||
| dialog_response_cb (GtkWidget          *widget, | ||||
|                     gint                response, | ||||
|                     gpointer                         data) | ||||
| { | ||||
|     gtk_widget_destroy (widget); | ||||
| } | ||||
|  | ||||
| static void | ||||
| configure_widget_destroyed (GtkWidget *widget, | ||||
|                             gpointer   data) | ||||
| { | ||||
|     WordCompletionConfigureWidget *conf_widget = (WordCompletionConfigureWidget *) data; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     g_object_unref (conf_widget->settings); | ||||
|     g_slice_free (WordCompletionConfigureWidget, data); | ||||
|  | ||||
|     xed_debug_message (DEBUG_PLUGINS, "END"); | ||||
| } | ||||
|  | ||||
| static WordCompletionConfigureWidget * | ||||
| get_configure_widget (XedWordCompletionPlugin *plugin) | ||||
| { | ||||
|     WordCompletionConfigureWidget *widget; | ||||
|     gchar *data_dir; | ||||
|     gchar *ui_file; | ||||
|     GtkWidget *error_widget; | ||||
|     gboolean ret; | ||||
|  | ||||
|     xed_debug (DEBUG_PLUGINS); | ||||
|  | ||||
|     widget = g_slice_new (WordCompletionConfigureWidget); | ||||
|     widget->settings = g_object_ref (plugin->priv->settings); | ||||
|  | ||||
|     data_dir = peas_extension_base_get_data_dir (PEAS_EXTENSION_BASE (plugin)); | ||||
|     ui_file = g_build_filename (data_dir, "xed-wordcompletion-configure.ui", NULL); | ||||
|     ret = xed_utils_get_ui_objects (ui_file, | ||||
|                                   NULL, | ||||
|                                   &error_widget, | ||||
|                                   "configure_dialog", &widget->dialog, | ||||
|                                   "spin_button_min_word_size", &widget->min_word_size, | ||||
|                                   "check_button_interactive_completion", &widget->interactive_completion, | ||||
|                                     NULL); | ||||
|  | ||||
|     g_free (data_dir); | ||||
|     g_free (ui_file); | ||||
|  | ||||
|     if (!ret) | ||||
|   { | ||||
|       return NULL; | ||||
|   } | ||||
|  | ||||
|   gtk_window_set_modal (GTK_WINDOW (widget->dialog), TRUE); | ||||
|  | ||||
|     g_settings_bind (widget->settings, SETTINGS_KEY_INTERACTIVE_COMPLETION, | ||||
|              widget->interactive_completion, "active", | ||||
|              G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_GET_NO_CHANGES); | ||||
|  | ||||
|     g_settings_bind (widget->settings, SETTINGS_KEY_MINIMUM_WORD_SIZE, | ||||
|              widget->min_word_size, "value", | ||||
|              G_SETTINGS_BIND_DEFAULT | G_SETTINGS_BIND_GET_NO_CHANGES); | ||||
|  | ||||
|      g_signal_connect (widget->dialog, "destroy", | ||||
|                       G_CALLBACK (configure_widget_destroyed), widget); | ||||
|  | ||||
|     gtk_widget_show (GTK_WIDGET (widget->dialog)); | ||||
|     g_signal_connect (widget->dialog, "response", | ||||
|                               G_CALLBACK (dialog_response_cb), widget); | ||||
|  | ||||
|     return widget; | ||||
| } | ||||
|  | ||||
| static GtkWidget * | ||||
| xed_wordcompletion_create_configure_widget (PeasGtkConfigurable *configurable) | ||||
| { | ||||
|  | ||||
|     WordCompletionConfigureWidget *widget; | ||||
|  | ||||
|     widget = get_configure_widget (XED_WORDCOMPLETION_PLUGIN (configurable)); | ||||
|  | ||||
|     return widget->dialog; | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_class_init (XedWordCompletionPluginClass *klass) | ||||
| { | ||||
|     GObjectClass *object_class = G_OBJECT_CLASS (klass); | ||||
|  | ||||
|     object_class->finalize = xed_wordcompletion_plugin_finalize; | ||||
|     object_class->dispose = xed_wordcompletion_plugin_dispose; | ||||
|     object_class->set_property = xed_wordcompletion_plugin_set_property; | ||||
|     object_class->get_property = xed_wordcompletion_plugin_get_property; | ||||
|  | ||||
|     g_object_class_override_property (object_class, PROP_WINDOW, "window"); | ||||
|     g_object_class_override_property (object_class, PROP_VIEW, "view"); | ||||
|  | ||||
|     g_type_class_add_private (klass, sizeof (XedWordCompletionPluginPrivate)); | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_wordcompletion_plugin_class_finalize (XedWordCompletionPluginClass *klass) | ||||
| { | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_window_activatable_iface_init (XedWindowActivatableInterface *iface) | ||||
| { | ||||
|     iface->activate = xed_wordcompletion_window_activate; | ||||
|     iface->deactivate = xed_wordcompletion_window_deactivate; | ||||
| } | ||||
|  | ||||
| static void | ||||
| xed_view_activatable_iface_init (XedViewActivatableInterface *iface) | ||||
| { | ||||
|     iface->activate = xed_wordcompletion_view_activate; | ||||
|     iface->deactivate = xed_wordcompletion_view_deactivate; | ||||
| } | ||||
|  | ||||
| static void | ||||
| peas_gtk_configurable_iface_init (PeasGtkConfigurableInterface *iface) | ||||
| { | ||||
|     iface->create_configure_widget = xed_wordcompletion_create_configure_widget; | ||||
| } | ||||
|  | ||||
| G_MODULE_EXPORT void | ||||
| peas_register_types (PeasObjectModule *module) | ||||
| { | ||||
|     xed_wordcompletion_plugin_register_type (G_TYPE_MODULE (module)); | ||||
|  | ||||
|     peas_object_module_register_extension_type (module, | ||||
|                                                 XED_TYPE_WINDOW_ACTIVATABLE, | ||||
|                                                 XED_TYPE_WORDCOMPLETION_PLUGIN); | ||||
|  | ||||
|     peas_object_module_register_extension_type (module, | ||||
|                                                 XED_TYPE_VIEW_ACTIVATABLE, | ||||
|                                                 XED_TYPE_WORDCOMPLETION_PLUGIN); | ||||
|  | ||||
|     peas_object_module_register_extension_type (module, | ||||
|                                                 PEAS_GTK_TYPE_CONFIGURABLE, | ||||
|                                                 XED_TYPE_WORDCOMPLETION_PLUGIN); | ||||
| } | ||||
							
								
								
									
										60
									
								
								plugins/wordcompletion/xed-wordcompletion-plugin.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								plugins/wordcompletion/xed-wordcompletion-plugin.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| /* | ||||
|  * Copyright (C) 2009 Ignacio Casal Quinteiro <icq@gnome.org> | ||||
|  *				 2017 Mickael Albertus <mickael.albertus@gmail.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 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 | ||||
|  * 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, write to the Free Software | ||||
|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
|  * | ||||
|  */ | ||||
|  | ||||
| #ifndef __XED_WORDCOMPLETION_PLUGIN_H__ | ||||
| #define __XED_WORDCOMPLETION_PLUGIN_H__ | ||||
|  | ||||
| #include <glib.h> | ||||
| #include <glib-object.h> | ||||
| #include <libpeas/peas-extension-base.h> | ||||
| #include <libpeas/peas-object-module.h> | ||||
|  | ||||
| G_BEGIN_DECLS | ||||
|  | ||||
| #define XED_TYPE_WORDCOMPLETION_PLUGIN		(xed_wordcompletion_plugin_get_type ()) | ||||
| #define XED_WORDCOMPLETION_PLUGIN(o)			(G_TYPE_CHECK_INSTANCE_CAST ((o), XED_TYPE_WORDCOMPLETION_PLUGIN, XedWordCompletionPlugin)) | ||||
| #define XED_WORDCOMPLETION_PLUGIN_CLASS(k)		(G_TYPE_CHECK_CLASS_CAST((k), XED_TYPE_WORDCOMPLETION_PLUGIN, XedWordCompletionPluginClass)) | ||||
| #define XED_IS_WORDCOMPLETION_PLUGIN(o)		(G_TYPE_CHECK_INSTANCE_TYPE ((o), XED_TYPE_WORDCOMPLETION_PLUGIN)) | ||||
| #define XED_IS_WORDCOMPLETION_PLUGIN_CLASS(k)	(G_TYPE_CHECK_CLASS_TYPE ((k), XED_TYPE_WORDCOMPLETION_PLUGIN)) | ||||
| #define XED_WORDCOMPLETION_PLUGIN_GET_CLASS(o)	(G_TYPE_INSTANCE_GET_CLASS ((o), XED_TYPE_WORDCOMPLETION_PLUGIN, XedWordCompletionPluginClass)) | ||||
|  | ||||
| typedef struct _XedWordCompletionPlugin		XedWordCompletionPlugin; | ||||
| typedef struct _XedWordCompletionPluginPrivate	XedWordCompletionPluginPrivate; | ||||
| typedef struct _XedWordCompletionPluginClass		XedWordCompletionPluginClass; | ||||
|  | ||||
| struct _XedWordCompletionPlugin | ||||
| { | ||||
| 	PeasExtensionBase parent_instance; | ||||
|  | ||||
| 	XedWordCompletionPluginPrivate *priv; | ||||
| }; | ||||
|  | ||||
| struct _XedWordCompletionPluginClass | ||||
| { | ||||
| 	PeasExtensionBaseClass parent_class; | ||||
| }; | ||||
|  | ||||
| GType			xed_wordcompletion_plugin_get_type	(void) G_GNUC_CONST; | ||||
|  | ||||
| G_MODULE_EXPORT void	peas_register_types			(PeasObjectModule *module); | ||||
|  | ||||
| G_END_DECLS | ||||
|  | ||||
| #endif /* __XED_WORDCOMPLETION_PLUGIN_H__ */ | ||||
		Reference in New Issue
	
	Block a user