1 /*
2  * gedit-docinfo-plugin.c
3  *
4  * Copyright (C) 2002-2005 Paolo Maggi
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 #include "config.h"
22 
23 #include "gedit-docinfo-plugin.h"
24 
25 #include <string.h> /* For strlen (...) */
26 
27 #include <glib/gi18n.h>
28 #include <pango/pango-break.h>
29 #include <gmodule.h>
30 
31 #include <gedit/gedit-app.h>
32 #include <gedit/gedit-window.h>
33 #include <gedit/gedit-debug.h>
34 #include <gedit/gedit-utils.h>
35 #include <gedit/gedit-menu-extension.h>
36 #include <gedit/gedit-app-activatable.h>
37 #include <gedit/gedit-window-activatable.h>
38 
39 struct _GeditDocinfoPluginPrivate
40 {
41 	GeditWindow *window;
42 
43 	GSimpleAction *action;
44 
45 	GtkWidget *dialog;
46 	GtkWidget *header_bar;
47 	GtkWidget *lines_label;
48 	GtkWidget *words_label;
49 	GtkWidget *chars_label;
50 	GtkWidget *chars_ns_label;
51 	GtkWidget *bytes_label;
52 	GtkWidget *document_label;
53 	GtkWidget *document_lines_label;
54 	GtkWidget *document_words_label;
55 	GtkWidget *document_chars_label;
56 	GtkWidget *document_chars_ns_label;
57 	GtkWidget *document_bytes_label;
58 	GtkWidget *selection_label;
59 	GtkWidget *selected_lines_label;
60 	GtkWidget *selected_words_label;
61 	GtkWidget *selected_chars_label;
62 	GtkWidget *selected_chars_ns_label;
63 	GtkWidget *selected_bytes_label;
64 
65 	GeditApp  *app;
66 	GeditMenuExtension *menu_ext;
67 };
68 
69 enum
70 {
71 	PROP_0,
72 	PROP_WINDOW,
73 	PROP_APP
74 };
75 
76 static void gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface);
77 static void gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface);
78 
79 G_DEFINE_DYNAMIC_TYPE_EXTENDED (GeditDocinfoPlugin,
80 				gedit_docinfo_plugin,
81 				PEAS_TYPE_EXTENSION_BASE,
82 				0,
83 				G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_APP_ACTIVATABLE,
84 							       gedit_app_activatable_iface_init)
85 				G_IMPLEMENT_INTERFACE_DYNAMIC (GEDIT_TYPE_WINDOW_ACTIVATABLE,
86 							       gedit_window_activatable_iface_init)
87 				G_ADD_PRIVATE_DYNAMIC (GeditDocinfoPlugin))
88 
89 static void
calculate_info(GeditDocument * doc,GtkTextIter * start,GtkTextIter * end,gint * chars,gint * words,gint * white_chars,gint * bytes)90 calculate_info (GeditDocument *doc,
91 		GtkTextIter   *start,
92 		GtkTextIter   *end,
93 		gint          *chars,
94 		gint          *words,
95 		gint          *white_chars,
96 		gint          *bytes)
97 {
98 	gchar *text;
99 
100 	gedit_debug (DEBUG_PLUGINS);
101 
102 	text = gtk_text_buffer_get_slice (GTK_TEXT_BUFFER (doc),
103 					  start,
104 					  end,
105 					  TRUE);
106 
107 	*chars = g_utf8_strlen (text, -1);
108 	*bytes = strlen (text);
109 
110 	if (*chars > 0)
111 	{
112 		PangoLogAttr *attrs;
113 		gint i;
114 
115 		attrs = g_new0 (PangoLogAttr, *chars + 1);
116 
117 		pango_get_log_attrs (text,
118 				     -1,
119 				     0,
120 				     pango_language_from_string ("C"),
121 				     attrs,
122 				     *chars + 1);
123 
124 		for (i = 0; i < (*chars); i++)
125 		{
126 			if (attrs[i].is_white)
127 				++(*white_chars);
128 
129 			if (attrs[i].is_word_start)
130 				++(*words);
131 		}
132 
133 		g_free (attrs);
134 	}
135 	else
136 	{
137 		*white_chars = 0;
138 		*words = 0;
139 	}
140 
141 	g_free (text);
142 }
143 
144 static void
update_document_info(GeditDocinfoPlugin * plugin,GeditDocument * doc)145 update_document_info (GeditDocinfoPlugin *plugin,
146 		      GeditDocument      *doc)
147 {
148 	GeditDocinfoPluginPrivate *priv;
149 	GtkTextIter start, end;
150 	gint words = 0;
151 	gint chars = 0;
152 	gint white_chars = 0;
153 	gint lines = 0;
154 	gint bytes = 0;
155 	gchar *doc_name;
156 	gchar *tmp_str;
157 
158 	gedit_debug (DEBUG_PLUGINS);
159 
160 	priv = plugin->priv;
161 
162 	gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (doc),
163 				    &start,
164 				    &end);
165 
166 	lines = gtk_text_buffer_get_line_count (GTK_TEXT_BUFFER (doc));
167 
168 	calculate_info (doc,
169 			&start, &end,
170 			&chars, &words, &white_chars, &bytes);
171 
172 	if (chars == 0)
173 	{
174 		lines = 0;
175 	}
176 
177 	gedit_debug_message (DEBUG_PLUGINS, "Chars: %d", chars);
178 	gedit_debug_message (DEBUG_PLUGINS, "Lines: %d", lines);
179 	gedit_debug_message (DEBUG_PLUGINS, "Words: %d", words);
180 	gedit_debug_message (DEBUG_PLUGINS, "Chars non-space: %d", chars - white_chars);
181 	gedit_debug_message (DEBUG_PLUGINS, "Bytes: %d", bytes);
182 
183 	doc_name = gedit_document_get_short_name_for_display (doc);
184 	gtk_header_bar_set_subtitle (GTK_HEADER_BAR (priv->header_bar), doc_name);
185 	g_free (doc_name);
186 
187 	tmp_str = g_strdup_printf("%d", lines);
188 	gtk_label_set_text (GTK_LABEL (priv->document_lines_label), tmp_str);
189 	g_free (tmp_str);
190 
191 	tmp_str = g_strdup_printf("%d", words);
192 	gtk_label_set_text (GTK_LABEL (priv->document_words_label), tmp_str);
193 	g_free (tmp_str);
194 
195 	tmp_str = g_strdup_printf("%d", chars);
196 	gtk_label_set_text (GTK_LABEL (priv->document_chars_label), tmp_str);
197 	g_free (tmp_str);
198 
199 	tmp_str = g_strdup_printf("%d", chars - white_chars);
200 	gtk_label_set_text (GTK_LABEL (priv->document_chars_ns_label), tmp_str);
201 	g_free (tmp_str);
202 
203 	tmp_str = g_strdup_printf("%d", bytes);
204 	gtk_label_set_text (GTK_LABEL (priv->document_bytes_label), tmp_str);
205 	g_free (tmp_str);
206 }
207 
208 static void
update_selection_info(GeditDocinfoPlugin * plugin,GeditDocument * doc)209 update_selection_info (GeditDocinfoPlugin *plugin,
210 		       GeditDocument      *doc)
211 {
212 	GeditDocinfoPluginPrivate *priv;
213 	gboolean sel;
214 	GtkTextIter start, end;
215 	gint words = 0;
216 	gint chars = 0;
217 	gint white_chars = 0;
218 	gint lines = 0;
219 	gint bytes = 0;
220 	gchar *tmp_str;
221 
222 	gedit_debug (DEBUG_PLUGINS);
223 
224 	priv = plugin->priv;
225 
226 	sel = gtk_text_buffer_get_selection_bounds (GTK_TEXT_BUFFER (doc),
227 						    &start,
228 						    &end);
229 
230 	if (sel)
231 	{
232 		lines = gtk_text_iter_get_line (&end) - gtk_text_iter_get_line (&start) + 1;
233 
234 		calculate_info (doc,
235 				&start, &end,
236 				&chars, &words, &white_chars, &bytes);
237 
238 		gedit_debug_message (DEBUG_PLUGINS, "Selected chars: %d", chars);
239 		gedit_debug_message (DEBUG_PLUGINS, "Selected lines: %d", lines);
240 		gedit_debug_message (DEBUG_PLUGINS, "Selected words: %d", words);
241 		gedit_debug_message (DEBUG_PLUGINS, "Selected chars non-space: %d", chars - white_chars);
242 		gedit_debug_message (DEBUG_PLUGINS, "Selected bytes: %d", bytes);
243 
244 		gtk_widget_set_sensitive (priv->selection_label, TRUE);
245 		gtk_widget_set_sensitive (priv->selected_words_label, TRUE);
246 		gtk_widget_set_sensitive (priv->selected_bytes_label, TRUE);
247 		gtk_widget_set_sensitive (priv->selected_lines_label, TRUE);
248 		gtk_widget_set_sensitive (priv->selected_chars_label, TRUE);
249 		gtk_widget_set_sensitive (priv->selected_chars_ns_label, TRUE);
250 	}
251 	else
252 	{
253 		gedit_debug_message (DEBUG_PLUGINS, "Selection empty");
254 
255 		gtk_widget_set_sensitive (priv->selection_label, FALSE);
256 		gtk_widget_set_sensitive (priv->selected_words_label, FALSE);
257 		gtk_widget_set_sensitive (priv->selected_bytes_label, FALSE);
258 		gtk_widget_set_sensitive (priv->selected_lines_label, FALSE);
259 		gtk_widget_set_sensitive (priv->selected_chars_label, FALSE);
260 		gtk_widget_set_sensitive (priv->selected_chars_ns_label, FALSE);
261 	}
262 
263 	if (chars == 0)
264 		lines = 0;
265 
266 	tmp_str = g_strdup_printf("%d", lines);
267 	gtk_label_set_text (GTK_LABEL (priv->selected_lines_label), tmp_str);
268 	g_free (tmp_str);
269 
270 	tmp_str = g_strdup_printf("%d", words);
271 	gtk_label_set_text (GTK_LABEL (priv->selected_words_label), tmp_str);
272 	g_free (tmp_str);
273 
274 	tmp_str = g_strdup_printf("%d", chars);
275 	gtk_label_set_text (GTK_LABEL (priv->selected_chars_label), tmp_str);
276 	g_free (tmp_str);
277 
278 	tmp_str = g_strdup_printf("%d", chars - white_chars);
279 	gtk_label_set_text (GTK_LABEL (priv->selected_chars_ns_label), tmp_str);
280 	g_free (tmp_str);
281 
282 	tmp_str = g_strdup_printf("%d", bytes);
283 	gtk_label_set_text (GTK_LABEL (priv->selected_bytes_label), tmp_str);
284 	g_free (tmp_str);
285 }
286 
287 static void
docinfo_dialog_response_cb(GtkDialog * widget,gint res_id,GeditDocinfoPlugin * plugin)288 docinfo_dialog_response_cb (GtkDialog          *widget,
289 			    gint                res_id,
290 			    GeditDocinfoPlugin *plugin)
291 {
292 	GeditDocinfoPluginPrivate *priv;
293 
294 	gedit_debug (DEBUG_PLUGINS);
295 
296 	priv = plugin->priv;
297 
298 	switch (res_id)
299 	{
300 		case GTK_RESPONSE_CLOSE:
301 		{
302 			gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_CLOSE");
303 
304 			gtk_widget_destroy (priv->dialog);
305 
306 			break;
307 		}
308 
309 		case GTK_RESPONSE_OK:
310 		{
311 			GeditDocument *doc;
312 
313 			gedit_debug_message (DEBUG_PLUGINS, "GTK_RESPONSE_OK");
314 
315 			doc = gedit_window_get_active_document (priv->window);
316 
317 			update_document_info (plugin, doc);
318 			update_selection_info (plugin, doc);
319 
320 			break;
321 		}
322 	}
323 }
324 
325 static void
create_docinfo_dialog(GeditDocinfoPlugin * plugin)326 create_docinfo_dialog (GeditDocinfoPlugin *plugin)
327 {
328 	GeditDocinfoPluginPrivate *priv;
329 	GtkBuilder *builder;
330 
331 	gedit_debug (DEBUG_PLUGINS);
332 
333 	priv = plugin->priv;
334 
335 	builder = gtk_builder_new ();
336 	gtk_builder_add_from_resource (builder, "/org/gnome/gedit/plugins/docinfo/ui/gedit-docinfo-plugin.ui", NULL);
337 	priv->dialog = GTK_WIDGET (gtk_builder_get_object (builder, "dialog"));
338 	priv->header_bar = GTK_WIDGET (gtk_builder_get_object (builder, "header_bar"));
339 	priv->words_label = GTK_WIDGET (gtk_builder_get_object (builder, "words_label"));
340 	priv->bytes_label = GTK_WIDGET (gtk_builder_get_object (builder, "bytes_label"));
341 	priv->lines_label = GTK_WIDGET (gtk_builder_get_object (builder, "lines_label"));
342 	priv->chars_label = GTK_WIDGET (gtk_builder_get_object (builder, "chars_label"));
343 	priv->chars_ns_label = GTK_WIDGET (gtk_builder_get_object (builder, "chars_ns_label"));
344 	priv->document_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_label"));
345 	priv->document_words_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_words_label"));
346 	priv->document_bytes_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_bytes_label"));
347 	priv->document_lines_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_lines_label"));
348 	priv->document_chars_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_chars_label"));
349 	priv->document_chars_ns_label = GTK_WIDGET (gtk_builder_get_object (builder, "document_chars_ns_label"));
350 	priv->selection_label = GTK_WIDGET (gtk_builder_get_object (builder, "selection_label"));
351 	priv->selected_words_label = GTK_WIDGET (gtk_builder_get_object (builder, "selected_words_label"));
352 	priv->selected_bytes_label = GTK_WIDGET (gtk_builder_get_object (builder, "selected_bytes_label"));
353 	priv->selected_lines_label = GTK_WIDGET (gtk_builder_get_object (builder, "selected_lines_label"));
354 	priv->selected_chars_label = GTK_WIDGET (gtk_builder_get_object (builder, "selected_chars_label"));
355 	priv->selected_chars_ns_label = GTK_WIDGET (gtk_builder_get_object (builder, "selected_chars_ns_label"));
356 	g_object_unref (builder);
357 
358 	gtk_dialog_set_default_response (GTK_DIALOG (priv->dialog),
359 					 GTK_RESPONSE_OK);
360 	gtk_window_set_transient_for (GTK_WINDOW (priv->dialog),
361 				      GTK_WINDOW (priv->window));
362 
363 	g_signal_connect (priv->dialog,
364 			  "destroy",
365 			  G_CALLBACK (gtk_widget_destroyed),
366 			  &priv->dialog);
367 	g_signal_connect (priv->dialog,
368 			  "response",
369 			  G_CALLBACK (docinfo_dialog_response_cb),
370 			  plugin);
371 
372 	/* We set this explictely with code since glade does not
373 	 * save the can_focus property when set to false :(
374 	 * Making sure the labels are not focusable is needed to
375 	 * prevent loosing the selection in the document when
376 	 * creating the dialog.
377 	 */
378 	gtk_widget_set_can_focus (priv->words_label, FALSE);
379 	gtk_widget_set_can_focus (priv->bytes_label, FALSE);
380 	gtk_widget_set_can_focus (priv->lines_label, FALSE);
381 	gtk_widget_set_can_focus (priv->chars_label, FALSE);
382 	gtk_widget_set_can_focus (priv->chars_ns_label, FALSE);
383 	gtk_widget_set_can_focus (priv->document_label, FALSE);
384 	gtk_widget_set_can_focus (priv->document_words_label, FALSE);
385 	gtk_widget_set_can_focus (priv->document_bytes_label, FALSE);
386 	gtk_widget_set_can_focus (priv->document_lines_label, FALSE);
387 	gtk_widget_set_can_focus (priv->document_chars_label, FALSE);
388 	gtk_widget_set_can_focus (priv->document_chars_ns_label, FALSE);
389 	gtk_widget_set_can_focus (priv->selection_label, FALSE);
390 	gtk_widget_set_can_focus (priv->selected_words_label, FALSE);
391 	gtk_widget_set_can_focus (priv->selected_bytes_label, FALSE);
392 	gtk_widget_set_can_focus (priv->selected_lines_label, FALSE);
393 	gtk_widget_set_can_focus (priv->selected_chars_label, FALSE);
394 	gtk_widget_set_can_focus (priv->selected_chars_ns_label, FALSE);
395 }
396 
397 static void
docinfo_cb(GAction * action,GVariant * parameter,GeditDocinfoPlugin * plugin)398 docinfo_cb (GAction            *action,
399             GVariant           *parameter,
400             GeditDocinfoPlugin *plugin)
401 {
402 	GeditDocinfoPluginPrivate *priv;
403 	GeditDocument *doc;
404 
405 	gedit_debug (DEBUG_PLUGINS);
406 
407 	priv = plugin->priv;
408 
409 	doc = gedit_window_get_active_document (priv->window);
410 
411 	if (priv->dialog != NULL)
412 	{
413 		gtk_window_present (GTK_WINDOW (priv->dialog));
414 		gtk_widget_grab_focus (GTK_WIDGET (priv->dialog));
415 	}
416 	else
417 	{
418 		create_docinfo_dialog (plugin);
419 		gtk_widget_show (GTK_WIDGET (priv->dialog));
420 	}
421 
422 	update_document_info (plugin, doc);
423 	update_selection_info (plugin, doc);
424 }
425 
426 static void
gedit_docinfo_plugin_init(GeditDocinfoPlugin * plugin)427 gedit_docinfo_plugin_init (GeditDocinfoPlugin *plugin)
428 {
429 	gedit_debug_message (DEBUG_PLUGINS, "GeditDocinfoPlugin initializing");
430 
431 	plugin->priv = gedit_docinfo_plugin_get_instance_private (plugin);
432 }
433 
434 static void
gedit_docinfo_plugin_dispose(GObject * object)435 gedit_docinfo_plugin_dispose (GObject *object)
436 {
437 	GeditDocinfoPlugin *plugin = GEDIT_DOCINFO_PLUGIN (object);
438 
439 	gedit_debug_message (DEBUG_PLUGINS, "GeditDocinfoPlugin dispose");
440 
441 	g_clear_object (&plugin->priv->action);
442 	g_clear_object (&plugin->priv->window);
443 	g_clear_object (&plugin->priv->menu_ext);
444 	g_clear_object (&plugin->priv->app);
445 
446 	G_OBJECT_CLASS (gedit_docinfo_plugin_parent_class)->dispose (object);
447 }
448 
449 
450 static void
gedit_docinfo_plugin_finalize(GObject * object)451 gedit_docinfo_plugin_finalize (GObject *object)
452 {
453 	gedit_debug_message (DEBUG_PLUGINS, "GeditDocinfoPlugin finalizing");
454 
455 	G_OBJECT_CLASS (gedit_docinfo_plugin_parent_class)->finalize (object);
456 }
457 
458 static void
gedit_docinfo_plugin_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)459 gedit_docinfo_plugin_set_property (GObject      *object,
460                                    guint         prop_id,
461                                    const GValue *value,
462                                    GParamSpec   *pspec)
463 {
464 	GeditDocinfoPlugin *plugin = GEDIT_DOCINFO_PLUGIN (object);
465 
466 	switch (prop_id)
467 	{
468 		case PROP_WINDOW:
469 			plugin->priv->window = GEDIT_WINDOW (g_value_dup_object (value));
470 			break;
471 		case PROP_APP:
472 			plugin->priv->app = GEDIT_APP (g_value_dup_object (value));
473 			break;
474 		default:
475 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
476 			break;
477 	}
478 }
479 
480 static void
gedit_docinfo_plugin_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)481 gedit_docinfo_plugin_get_property (GObject    *object,
482                                    guint       prop_id,
483                                    GValue     *value,
484                                    GParamSpec *pspec)
485 {
486 	GeditDocinfoPlugin *plugin = GEDIT_DOCINFO_PLUGIN (object);
487 
488 	switch (prop_id)
489 	{
490 		case PROP_WINDOW:
491 			g_value_set_object (value, plugin->priv->window);
492 			break;
493 		case PROP_APP:
494 			g_value_set_object (value, plugin->priv->app);
495 			break;
496 		default:
497 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
498 			break;
499 	}
500 }
501 
502 static void
update_ui(GeditDocinfoPlugin * plugin)503 update_ui (GeditDocinfoPlugin *plugin)
504 {
505 	GeditDocinfoPluginPrivate *priv;
506 	GeditView *view;
507 
508 	gedit_debug (DEBUG_PLUGINS);
509 
510 	priv = plugin->priv;
511 
512 	view = gedit_window_get_active_view (priv->window);
513 
514 	g_simple_action_set_enabled (G_SIMPLE_ACTION (priv->action), view != NULL);
515 
516 	if (priv->dialog != NULL)
517 	{
518 		gtk_dialog_set_response_sensitive (GTK_DIALOG (priv->dialog),
519 						   GTK_RESPONSE_OK,
520 						   (view != NULL));
521 	}
522 }
523 
524 static void
gedit_docinfo_plugin_app_activate(GeditAppActivatable * activatable)525 gedit_docinfo_plugin_app_activate (GeditAppActivatable *activatable)
526 {
527 	GeditDocinfoPluginPrivate *priv;
528 	GMenuItem *item;
529 
530 	gedit_debug (DEBUG_PLUGINS);
531 
532 	priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
533 
534 	priv->menu_ext = gedit_app_activatable_extend_menu (activatable, "tools-section");
535 	item = g_menu_item_new (_("_Document Statistics"), "win.docinfo");
536 	gedit_menu_extension_append_menu_item (priv->menu_ext, item);
537 	g_object_unref (item);
538 }
539 
540 static void
gedit_docinfo_plugin_app_deactivate(GeditAppActivatable * activatable)541 gedit_docinfo_plugin_app_deactivate (GeditAppActivatable *activatable)
542 {
543 	GeditDocinfoPluginPrivate *priv;
544 
545 	gedit_debug (DEBUG_PLUGINS);
546 
547 	priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
548 
549 	g_clear_object (&priv->menu_ext);
550 }
551 
552 static void
gedit_docinfo_plugin_window_activate(GeditWindowActivatable * activatable)553 gedit_docinfo_plugin_window_activate (GeditWindowActivatable *activatable)
554 {
555 	GeditDocinfoPluginPrivate *priv;
556 
557 	gedit_debug (DEBUG_PLUGINS);
558 
559 	priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
560 
561 	priv->action = g_simple_action_new ("docinfo", NULL);
562 	g_signal_connect (priv->action, "activate",
563 	                  G_CALLBACK (docinfo_cb), activatable);
564 	g_action_map_add_action (G_ACTION_MAP (priv->window),
565 	                         G_ACTION (priv->action));
566 
567 	update_ui (GEDIT_DOCINFO_PLUGIN (activatable));
568 }
569 
570 static void
gedit_docinfo_plugin_window_deactivate(GeditWindowActivatable * activatable)571 gedit_docinfo_plugin_window_deactivate (GeditWindowActivatable *activatable)
572 {
573 	GeditDocinfoPluginPrivate *priv;
574 
575 	gedit_debug (DEBUG_PLUGINS);
576 
577 	priv = GEDIT_DOCINFO_PLUGIN (activatable)->priv;
578 
579 	g_action_map_remove_action (G_ACTION_MAP (priv->window), "docinfo");
580 }
581 
582 static void
gedit_docinfo_plugin_window_update_state(GeditWindowActivatable * activatable)583 gedit_docinfo_plugin_window_update_state (GeditWindowActivatable *activatable)
584 {
585 	gedit_debug (DEBUG_PLUGINS);
586 
587 	update_ui (GEDIT_DOCINFO_PLUGIN (activatable));
588 }
589 
590 static void
gedit_docinfo_plugin_class_init(GeditDocinfoPluginClass * klass)591 gedit_docinfo_plugin_class_init (GeditDocinfoPluginClass *klass)
592 {
593 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
594 
595 	object_class->dispose = gedit_docinfo_plugin_dispose;
596 	object_class->finalize = gedit_docinfo_plugin_finalize;
597 	object_class->set_property = gedit_docinfo_plugin_set_property;
598 	object_class->get_property = gedit_docinfo_plugin_get_property;
599 
600 	g_object_class_override_property (object_class, PROP_WINDOW, "window");
601 	g_object_class_override_property (object_class, PROP_APP, "app");
602 }
603 
604 static void
gedit_app_activatable_iface_init(GeditAppActivatableInterface * iface)605 gedit_app_activatable_iface_init (GeditAppActivatableInterface *iface)
606 {
607 	iface->activate = gedit_docinfo_plugin_app_activate;
608 	iface->deactivate = gedit_docinfo_plugin_app_deactivate;
609 }
610 
611 static void
gedit_window_activatable_iface_init(GeditWindowActivatableInterface * iface)612 gedit_window_activatable_iface_init (GeditWindowActivatableInterface *iface)
613 {
614 	iface->activate = gedit_docinfo_plugin_window_activate;
615 	iface->deactivate = gedit_docinfo_plugin_window_deactivate;
616 	iface->update_state = gedit_docinfo_plugin_window_update_state;
617 }
618 
619 static void
gedit_docinfo_plugin_class_finalize(GeditDocinfoPluginClass * klass)620 gedit_docinfo_plugin_class_finalize (GeditDocinfoPluginClass *klass)
621 {
622 }
623 
624 
625 G_MODULE_EXPORT void
peas_register_types(PeasObjectModule * module)626 peas_register_types (PeasObjectModule *module)
627 {
628 	gedit_docinfo_plugin_register_type (G_TYPE_MODULE (module));
629 
630 	peas_object_module_register_extension_type (module,
631 						    GEDIT_TYPE_APP_ACTIVATABLE,
632 						    GEDIT_TYPE_DOCINFO_PLUGIN);
633 	peas_object_module_register_extension_type (module,
634 						    GEDIT_TYPE_WINDOW_ACTIVATABLE,
635 						    GEDIT_TYPE_DOCINFO_PLUGIN);
636 }
637 
638 /* ex:set ts=8 noet: */
639