From 5ded9cba8563f336939400303d6a841d5089b107 Mon Sep 17 00:00:00 2001 From: Perberos Date: Mon, 7 Nov 2011 19:52:18 -0300 Subject: renaming from gedit to pluma --- plugins/modelines/Makefile.am | 18 +- plugins/modelines/gedit-modeline-plugin.c | 248 --------------------- plugins/modelines/gedit-modeline-plugin.h | 48 ---- plugins/modelines/modeline-parser.c | 38 ++-- plugins/modelines/modeline-parser.h | 2 +- .../modelines/modelines.gedit-plugin.desktop.in | 8 - .../modelines/modelines.pluma-plugin.desktop.in | 8 + plugins/modelines/pluma-modeline-plugin.c | 248 +++++++++++++++++++++ plugins/modelines/pluma-modeline-plugin.h | 48 ++++ 9 files changed, 333 insertions(+), 333 deletions(-) delete mode 100755 plugins/modelines/gedit-modeline-plugin.c delete mode 100755 plugins/modelines/gedit-modeline-plugin.h delete mode 100755 plugins/modelines/modelines.gedit-plugin.desktop.in create mode 100755 plugins/modelines/modelines.pluma-plugin.desktop.in create mode 100755 plugins/modelines/pluma-modeline-plugin.c create mode 100755 plugins/modelines/pluma-modeline-plugin.h (limited to 'plugins/modelines') diff --git a/plugins/modelines/Makefile.am b/plugins/modelines/Makefile.am index ddcfccc8..d1b59b85 100755 --- a/plugins/modelines/Makefile.am +++ b/plugins/modelines/Makefile.am @@ -1,31 +1,31 @@ # Modelines Plugin -plugindir = $(GEDIT_PLUGINS_LIBS_DIR) +plugindir = $(PLUMA_PLUGINS_LIBS_DIR) INCLUDES = \ -I$(top_srcdir) \ - $(GEDIT_CFLAGS) \ + $(PLUMA_CFLAGS) \ $(WARN_CFLAGS) \ $(DISABLE_DEPRECATED_CFLAGS) -modelinesdir = $(GEDIT_PLUGINS_DATA_DIR)/modelines +modelinesdir = $(PLUMA_PLUGINS_DATA_DIR)/modelines modelines_DATA = \ language-mappings plugin_LTLIBRARIES = libmodelines.la libmodelines_la_SOURCES = \ - gedit-modeline-plugin.h \ - gedit-modeline-plugin.c \ + pluma-modeline-plugin.h \ + pluma-modeline-plugin.c \ modeline-parser.h \ modeline-parser.c libmodelines_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) -libmodelines_la_LIBADD = $(GEDIT_LIBS) +libmodelines_la_LIBADD = $(PLUMA_LIBS) -plugin_in_files = modelines.gedit-plugin.desktop.in -%.gedit-plugin: %.gedit-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_in_files = modelines.pluma-plugin.desktop.in +%.pluma-plugin: %.pluma-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:.gedit-plugin.desktop.in=.gedit-plugin) +plugin_DATA = $(plugin_in_files:.pluma-plugin.desktop.in=.pluma-plugin) EXTRA_DIST = \ $(plugin_in_files) \ diff --git a/plugins/modelines/gedit-modeline-plugin.c b/plugins/modelines/gedit-modeline-plugin.c deleted file mode 100755 index 49fc2f69..00000000 --- a/plugins/modelines/gedit-modeline-plugin.c +++ /dev/null @@ -1,248 +0,0 @@ -/* - * gedit-modeline-plugin.c - * Emacs, Kate and Vim-style modelines support for gedit. - * - * Copyright (C) 2005-2007 - Steve Frécinaux - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -# include -#endif - -#include -#include -#include "gedit-modeline-plugin.h" -#include "modeline-parser.h" - -#include -#include - -#define WINDOW_DATA_KEY "GeditModelinePluginWindowData" -#define DOCUMENT_DATA_KEY "GeditModelinePluginDocumentData" - -typedef struct -{ - gulong tab_added_handler_id; - gulong tab_removed_handler_id; -} WindowData; - -typedef struct -{ - gulong document_loaded_handler_id; - gulong document_saved_handler_id; -} DocumentData; - -static void gedit_modeline_plugin_activate (GeditPlugin *plugin, GeditWindow *window); -static void gedit_modeline_plugin_deactivate (GeditPlugin *plugin, GeditWindow *window); -static GObject *gedit_modeline_plugin_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_param); -static void gedit_modeline_plugin_finalize (GObject *object); - -GEDIT_PLUGIN_REGISTER_TYPE(GeditModelinePlugin, gedit_modeline_plugin) - -static void -window_data_free (WindowData *wdata) -{ - g_slice_free (WindowData, wdata); -} - -static void -document_data_free (DocumentData *ddata) -{ - g_slice_free (DocumentData, ddata); -} - -static void -gedit_modeline_plugin_class_init (GeditModelinePluginClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GeditPluginClass *plugin_class = GEDIT_PLUGIN_CLASS (klass); - - object_class->constructor = gedit_modeline_plugin_constructor; - object_class->finalize = gedit_modeline_plugin_finalize; - - plugin_class->activate = gedit_modeline_plugin_activate; - plugin_class->deactivate = gedit_modeline_plugin_deactivate; -} - -static GObject * -gedit_modeline_plugin_constructor (GType type, - guint n_construct_properties, - GObjectConstructParam *construct_param) -{ - GObject *object; - gchar *data_dir; - - object = G_OBJECT_CLASS (gedit_modeline_plugin_parent_class)->constructor (type, - n_construct_properties, - construct_param); - - data_dir = gedit_plugin_get_data_dir (GEDIT_PLUGIN (object)); - - modeline_parser_init (data_dir); - - g_free (data_dir); - - return object; -} - -static void -gedit_modeline_plugin_init (GeditModelinePlugin *plugin) -{ - gedit_debug_message (DEBUG_PLUGINS, "GeditModelinePlugin initializing"); -} - -static void -gedit_modeline_plugin_finalize (GObject *object) -{ - gedit_debug_message (DEBUG_PLUGINS, "GeditModelinePlugin finalizing"); - - modeline_parser_shutdown (); - - G_OBJECT_CLASS (gedit_modeline_plugin_parent_class)->finalize (object); -} - -static void -on_document_loaded_or_saved (GeditDocument *document, - const GError *error, - GtkSourceView *view) -{ - modeline_parser_apply_modeline (view); -} - -static void -connect_handlers (GeditView *view) -{ - DocumentData *data; - GtkTextBuffer *doc; - - doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - - data = g_slice_new (DocumentData); - - data->document_loaded_handler_id = - g_signal_connect (doc, "loaded", - G_CALLBACK (on_document_loaded_or_saved), - view); - data->document_saved_handler_id = - g_signal_connect (doc, "saved", - G_CALLBACK (on_document_loaded_or_saved), - view); - - g_object_set_data_full (G_OBJECT (doc), DOCUMENT_DATA_KEY, - data, (GDestroyNotify) document_data_free); -} - -static void -disconnect_handlers (GeditView *view) -{ - DocumentData *data; - GtkTextBuffer *doc; - - doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - - data = g_object_steal_data (G_OBJECT (doc), DOCUMENT_DATA_KEY); - - if (data) - { - g_signal_handler_disconnect (doc, data->document_loaded_handler_id); - g_signal_handler_disconnect (doc, data->document_saved_handler_id); - - document_data_free (data); - } - else - { - g_warning ("Modeline handlers not found"); - } -} - -static void -on_window_tab_added (GeditWindow *window, - GeditTab *tab, - gpointer user_data) -{ - connect_handlers (gedit_tab_get_view (tab)); -} - -static void -on_window_tab_removed (GeditWindow *window, - GeditTab *tab, - gpointer user_data) -{ - disconnect_handlers (gedit_tab_get_view (tab)); -} - -static void -gedit_modeline_plugin_activate (GeditPlugin *plugin, - GeditWindow *window) -{ - WindowData *wdata; - GList *views; - GList *l; - - gedit_debug (DEBUG_PLUGINS); - - views = gedit_window_get_views (window); - for (l = views; l != NULL; l = l->next) - { - connect_handlers (GEDIT_VIEW (l->data)); - modeline_parser_apply_modeline (GTK_SOURCE_VIEW (l->data)); - } - g_list_free (views); - - wdata = g_slice_new (WindowData); - - wdata->tab_added_handler_id = - g_signal_connect (window, "tab-added", - G_CALLBACK (on_window_tab_added), NULL); - - wdata->tab_removed_handler_id = - g_signal_connect (window, "tab-removed", - G_CALLBACK (on_window_tab_removed), NULL); - - g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, - wdata, (GDestroyNotify) window_data_free); -} - -static void -gedit_modeline_plugin_deactivate (GeditPlugin *plugin, - GeditWindow *window) -{ - WindowData *wdata; - GList *views; - GList *l; - - gedit_debug (DEBUG_PLUGINS); - - wdata = g_object_steal_data (G_OBJECT (window), WINDOW_DATA_KEY); - - g_signal_handler_disconnect (window, wdata->tab_added_handler_id); - g_signal_handler_disconnect (window, wdata->tab_removed_handler_id); - - window_data_free (wdata); - - views = gedit_window_get_views (window); - - for (l = views; l != NULL; l = l->next) - { - disconnect_handlers (GEDIT_VIEW (l->data)); - - modeline_parser_deactivate (GTK_SOURCE_VIEW (l->data)); - } - - g_list_free (views); -} - diff --git a/plugins/modelines/gedit-modeline-plugin.h b/plugins/modelines/gedit-modeline-plugin.h deleted file mode 100755 index 92b01e70..00000000 --- a/plugins/modelines/gedit-modeline-plugin.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * gedit-modeline-plugin.h - * Emacs, Kate and Vim-style modelines support for gedit. - * - * Copyright (C) 2005-2007 - Steve Frécinaux - * - * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __GEDIT_MODELINE_PLUGIN_H__ -#define __GEDIT_MODELINE_PLUGIN_H__ - -#include -#include -#include - -G_BEGIN_DECLS - -#define GEDIT_TYPE_MODELINE_PLUGIN (gedit_modeline_plugin_get_type ()) -#define GEDIT_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GEDIT_TYPE_MODELINE_PLUGIN, GeditModelinePlugin)) -#define GEDIT_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GEDIT_TYPE_MODELINE_PLUGIN, GeditModelinePluginClass)) -#define GEDIT_IS_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GEDIT_TYPE_MODELINE_PLUGIN)) -#define GEDIT_IS_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GEDIT_TYPE_MODELINE_PLUGIN)) -#define GEDIT_MODELINE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GEDIT_TYPE_MODELINE_PLUGIN, GeditModelinePluginClass)) - -/* Private structure type */ -typedef GeditPluginClass GeditModelinePluginClass; -typedef GeditPlugin GeditModelinePlugin; - -GType gedit_modeline_plugin_get_type (void) G_GNUC_CONST; - -G_MODULE_EXPORT GType register_gedit_plugin (GTypeModule *module); - -G_END_DECLS - -#endif /* __GEDIT_MODELINE_PLUGIN_H__ */ diff --git a/plugins/modelines/modeline-parser.c b/plugins/modelines/modeline-parser.c index 6feafc55..23304e38 100755 --- a/plugins/modelines/modeline-parser.c +++ b/plugins/modelines/modeline-parser.c @@ -1,6 +1,6 @@ /* * modeline-parser.c - * Emacs, Kate and Vim-style modelines support for gedit. + * Emacs, Kate and Vim-style modelines support for pluma. * * Copyright (C) 2005-2007 - Steve Frécinaux * @@ -22,9 +22,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include #include "modeline-parser.h" #define MODELINES_LANGUAGE_MAPPINGS_FILE "language-mappings" @@ -32,7 +32,7 @@ /* base dir to lookup configuration files */ static gchar *modelines_data_dir; -/* Mappings: language name -> Gedit language ID */ +/* Mappings: language name -> Pluma language ID */ static GHashTable *vim_languages; static GHashTable *emacs_languages; static GHashTable *kate_languages; @@ -112,7 +112,7 @@ load_language_mappings_group (GKeyFile *key_file, const gchar *group) keys = g_key_file_get_keys (key_file, group, &length, NULL); - gedit_debug_message (DEBUG_PLUGINS, + pluma_debug_message (DEBUG_PLUGINS, "%" G_GSIZE_FORMAT " mappings in group %s", length, group); @@ -143,7 +143,7 @@ load_language_mappings (void) if (g_key_file_load_from_file (mappings, fname, 0, &error)) { - gedit_debug_message (DEBUG_PLUGINS, + pluma_debug_message (DEBUG_PLUGINS, "Loaded language mappings from %s", fname); @@ -153,7 +153,7 @@ load_language_mappings (void) } else { - gedit_debug_message (DEBUG_PLUGINS, + pluma_debug_message (DEBUG_PLUGINS, "Failed to loaded language mappings from %s: %s", fname, error->message); @@ -395,7 +395,7 @@ parse_emacs_modeline (gchar *s, s++; } - gedit_debug_message (DEBUG_PLUGINS, + pluma_debug_message (DEBUG_PLUGINS, "Emacs modeline bit: %s = %s", key->str, value->str); @@ -493,7 +493,7 @@ parse_kate_modeline (gchar *s, s++; } - gedit_debug_message (DEBUG_PLUGINS, + pluma_debug_message (DEBUG_PLUGINS, "Kate modeline bit: %s = %s", key->str, value->str); @@ -582,21 +582,21 @@ parse_modeline (gchar *s, strncmp (s, "vi:", 3) == 0 || strncmp (s, "vim:", 4) == 0)) { - gedit_debug_message (DEBUG_PLUGINS, "Vim modeline on line %d", line_number); + pluma_debug_message (DEBUG_PLUGINS, "Vim modeline on line %d", line_number); while (*s != ':') s++; s = parse_vim_modeline (s + 1, options); } else if (line_number <= 2 && strncmp (s, "-*-", 3) == 0) { - gedit_debug_message (DEBUG_PLUGINS, "Emacs modeline on line %d", line_number); + pluma_debug_message (DEBUG_PLUGINS, "Emacs modeline on line %d", line_number); s = parse_emacs_modeline (s + 3, options); } else if ((line_number <= 10 || line_number > line_count - 10) && strncmp (s, "kate:", 5) == 0) { - gedit_debug_message (DEBUG_PLUGINS, "Kate modeline on line %d", line_number); + pluma_debug_message (DEBUG_PLUGINS, "Kate modeline on line %d", line_number); s = parse_kate_modeline (s + 5, options); } @@ -744,7 +744,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) GtkSourceLanguageManager *manager; GtkSourceLanguage *language; - manager = gedit_get_language_manager (); + manager = pluma_get_language_manager (); language = gtk_source_language_manager_get_language (manager, options.language_id); @@ -769,7 +769,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) { gtk_source_view_set_insert_spaces_instead_of_tabs (view, - gedit_prefs_manager_get_insert_spaces ()); + pluma_prefs_manager_get_insert_spaces ()); } if (has_option (&options, MODELINE_SET_TAB_WIDTH)) @@ -779,7 +779,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_TAB_WIDTH)) { gtk_source_view_set_tab_width (view, - gedit_prefs_manager_get_tabs_size ()); + pluma_prefs_manager_get_tabs_size ()); } if (has_option (&options, MODELINE_SET_INDENT_WIDTH)) @@ -798,7 +798,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_WRAP_MODE)) { gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), - gedit_prefs_manager_get_wrap_mode ()); + pluma_prefs_manager_get_wrap_mode ()); } if (has_option (&options, MODELINE_SET_RIGHT_MARGIN_POSITION)) @@ -808,7 +808,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_RIGHT_MARGIN_POSITION)) { gtk_source_view_set_right_margin_position (view, - gedit_prefs_manager_get_right_margin_position ()); + pluma_prefs_manager_get_right_margin_position ()); } if (has_option (&options, MODELINE_SET_SHOW_RIGHT_MARGIN)) @@ -818,7 +818,7 @@ modeline_parser_apply_modeline (GtkSourceView *view) else if (check_previous (view, previous, MODELINE_SET_SHOW_RIGHT_MARGIN)) { gtk_source_view_set_show_right_margin (view, - gedit_prefs_manager_get_display_right_margin ()); + pluma_prefs_manager_get_display_right_margin ()); } if (previous) diff --git a/plugins/modelines/modeline-parser.h b/plugins/modelines/modeline-parser.h index 2e8559e4..11e06c34 100755 --- a/plugins/modelines/modeline-parser.h +++ b/plugins/modelines/modeline-parser.h @@ -1,6 +1,6 @@ /* * modelie-parser.h - * Emacs, Kate and Vim-style modelines support for gedit. + * Emacs, Kate and Vim-style modelines support for pluma. * * Copyright (C) 2005-2007 - Steve Frécinaux * diff --git a/plugins/modelines/modelines.gedit-plugin.desktop.in b/plugins/modelines/modelines.gedit-plugin.desktop.in deleted file mode 100755 index c72f0199..00000000 --- a/plugins/modelines/modelines.gedit-plugin.desktop.in +++ /dev/null @@ -1,8 +0,0 @@ -[Gedit Plugin] -Module=modelines -IAge=2 -_Name=Modelines -_Description=Emacs, Kate and Vim-style modelines support for gedit. -Authors=Steve Frécinaux -Copyright=Copyright © 2005 Steve Frécinaux -Website=http://www.gedit.org diff --git a/plugins/modelines/modelines.pluma-plugin.desktop.in b/plugins/modelines/modelines.pluma-plugin.desktop.in new file mode 100755 index 00000000..0d5f8389 --- /dev/null +++ b/plugins/modelines/modelines.pluma-plugin.desktop.in @@ -0,0 +1,8 @@ +[Pluma Plugin] +Module=modelines +IAge=2 +_Name=Modelines +_Description=Emacs, Kate and Vim-style modelines support for pluma. +Authors=Steve Frécinaux +Copyright=Copyright © 2005 Steve Frécinaux +Website=http://www.pluma.org diff --git a/plugins/modelines/pluma-modeline-plugin.c b/plugins/modelines/pluma-modeline-plugin.c new file mode 100755 index 00000000..db5fc1e3 --- /dev/null +++ b/plugins/modelines/pluma-modeline-plugin.c @@ -0,0 +1,248 @@ +/* + * pluma-modeline-plugin.c + * Emacs, Kate and Vim-style modelines support for pluma. + * + * Copyright (C) 2005-2007 - Steve Frécinaux + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include "pluma-modeline-plugin.h" +#include "modeline-parser.h" + +#include +#include + +#define WINDOW_DATA_KEY "PlumaModelinePluginWindowData" +#define DOCUMENT_DATA_KEY "PlumaModelinePluginDocumentData" + +typedef struct +{ + gulong tab_added_handler_id; + gulong tab_removed_handler_id; +} WindowData; + +typedef struct +{ + gulong document_loaded_handler_id; + gulong document_saved_handler_id; +} DocumentData; + +static void pluma_modeline_plugin_activate (PlumaPlugin *plugin, PlumaWindow *window); +static void pluma_modeline_plugin_deactivate (PlumaPlugin *plugin, PlumaWindow *window); +static GObject *pluma_modeline_plugin_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_param); +static void pluma_modeline_plugin_finalize (GObject *object); + +PLUMA_PLUGIN_REGISTER_TYPE(PlumaModelinePlugin, pluma_modeline_plugin) + +static void +window_data_free (WindowData *wdata) +{ + g_slice_free (WindowData, wdata); +} + +static void +document_data_free (DocumentData *ddata) +{ + g_slice_free (DocumentData, ddata); +} + +static void +pluma_modeline_plugin_class_init (PlumaModelinePluginClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + PlumaPluginClass *plugin_class = PLUMA_PLUGIN_CLASS (klass); + + object_class->constructor = pluma_modeline_plugin_constructor; + object_class->finalize = pluma_modeline_plugin_finalize; + + plugin_class->activate = pluma_modeline_plugin_activate; + plugin_class->deactivate = pluma_modeline_plugin_deactivate; +} + +static GObject * +pluma_modeline_plugin_constructor (GType type, + guint n_construct_properties, + GObjectConstructParam *construct_param) +{ + GObject *object; + gchar *data_dir; + + object = G_OBJECT_CLASS (pluma_modeline_plugin_parent_class)->constructor (type, + n_construct_properties, + construct_param); + + data_dir = pluma_plugin_get_data_dir (PLUMA_PLUGIN (object)); + + modeline_parser_init (data_dir); + + g_free (data_dir); + + return object; +} + +static void +pluma_modeline_plugin_init (PlumaModelinePlugin *plugin) +{ + pluma_debug_message (DEBUG_PLUGINS, "PlumaModelinePlugin initializing"); +} + +static void +pluma_modeline_plugin_finalize (GObject *object) +{ + pluma_debug_message (DEBUG_PLUGINS, "PlumaModelinePlugin finalizing"); + + modeline_parser_shutdown (); + + G_OBJECT_CLASS (pluma_modeline_plugin_parent_class)->finalize (object); +} + +static void +on_document_loaded_or_saved (PlumaDocument *document, + const GError *error, + GtkSourceView *view) +{ + modeline_parser_apply_modeline (view); +} + +static void +connect_handlers (PlumaView *view) +{ + DocumentData *data; + GtkTextBuffer *doc; + + doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + + data = g_slice_new (DocumentData); + + data->document_loaded_handler_id = + g_signal_connect (doc, "loaded", + G_CALLBACK (on_document_loaded_or_saved), + view); + data->document_saved_handler_id = + g_signal_connect (doc, "saved", + G_CALLBACK (on_document_loaded_or_saved), + view); + + g_object_set_data_full (G_OBJECT (doc), DOCUMENT_DATA_KEY, + data, (GDestroyNotify) document_data_free); +} + +static void +disconnect_handlers (PlumaView *view) +{ + DocumentData *data; + GtkTextBuffer *doc; + + doc = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); + + data = g_object_steal_data (G_OBJECT (doc), DOCUMENT_DATA_KEY); + + if (data) + { + g_signal_handler_disconnect (doc, data->document_loaded_handler_id); + g_signal_handler_disconnect (doc, data->document_saved_handler_id); + + document_data_free (data); + } + else + { + g_warning ("Modeline handlers not found"); + } +} + +static void +on_window_tab_added (PlumaWindow *window, + PlumaTab *tab, + gpointer user_data) +{ + connect_handlers (pluma_tab_get_view (tab)); +} + +static void +on_window_tab_removed (PlumaWindow *window, + PlumaTab *tab, + gpointer user_data) +{ + disconnect_handlers (pluma_tab_get_view (tab)); +} + +static void +pluma_modeline_plugin_activate (PlumaPlugin *plugin, + PlumaWindow *window) +{ + WindowData *wdata; + GList *views; + GList *l; + + pluma_debug (DEBUG_PLUGINS); + + views = pluma_window_get_views (window); + for (l = views; l != NULL; l = l->next) + { + connect_handlers (PLUMA_VIEW (l->data)); + modeline_parser_apply_modeline (GTK_SOURCE_VIEW (l->data)); + } + g_list_free (views); + + wdata = g_slice_new (WindowData); + + wdata->tab_added_handler_id = + g_signal_connect (window, "tab-added", + G_CALLBACK (on_window_tab_added), NULL); + + wdata->tab_removed_handler_id = + g_signal_connect (window, "tab-removed", + G_CALLBACK (on_window_tab_removed), NULL); + + g_object_set_data_full (G_OBJECT (window), WINDOW_DATA_KEY, + wdata, (GDestroyNotify) window_data_free); +} + +static void +pluma_modeline_plugin_deactivate (PlumaPlugin *plugin, + PlumaWindow *window) +{ + WindowData *wdata; + GList *views; + GList *l; + + pluma_debug (DEBUG_PLUGINS); + + wdata = g_object_steal_data (G_OBJECT (window), WINDOW_DATA_KEY); + + g_signal_handler_disconnect (window, wdata->tab_added_handler_id); + g_signal_handler_disconnect (window, wdata->tab_removed_handler_id); + + window_data_free (wdata); + + views = pluma_window_get_views (window); + + for (l = views; l != NULL; l = l->next) + { + disconnect_handlers (PLUMA_VIEW (l->data)); + + modeline_parser_deactivate (GTK_SOURCE_VIEW (l->data)); + } + + g_list_free (views); +} + diff --git a/plugins/modelines/pluma-modeline-plugin.h b/plugins/modelines/pluma-modeline-plugin.h new file mode 100755 index 00000000..cdd77b20 --- /dev/null +++ b/plugins/modelines/pluma-modeline-plugin.h @@ -0,0 +1,48 @@ +/* + * pluma-modeline-plugin.h + * Emacs, Kate and Vim-style modelines support for pluma. + * + * Copyright (C) 2005-2007 - Steve Frécinaux + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __PLUMA_MODELINE_PLUGIN_H__ +#define __PLUMA_MODELINE_PLUGIN_H__ + +#include +#include +#include + +G_BEGIN_DECLS + +#define PLUMA_TYPE_MODELINE_PLUGIN (pluma_modeline_plugin_get_type ()) +#define PLUMA_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), PLUMA_TYPE_MODELINE_PLUGIN, PlumaModelinePlugin)) +#define PLUMA_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), PLUMA_TYPE_MODELINE_PLUGIN, PlumaModelinePluginClass)) +#define PLUMA_IS_MODELINE_PLUGIN(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), PLUMA_TYPE_MODELINE_PLUGIN)) +#define PLUMA_IS_MODELINE_PLUGIN_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), PLUMA_TYPE_MODELINE_PLUGIN)) +#define PLUMA_MODELINE_PLUGIN_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PLUMA_TYPE_MODELINE_PLUGIN, PlumaModelinePluginClass)) + +/* Private structure type */ +typedef PlumaPluginClass PlumaModelinePluginClass; +typedef PlumaPlugin PlumaModelinePlugin; + +GType pluma_modeline_plugin_get_type (void) G_GNUC_CONST; + +G_MODULE_EXPORT GType register_pluma_plugin (GTypeModule *module); + +G_END_DECLS + +#endif /* __PLUMA_MODELINE_PLUGIN_H__ */ -- cgit v1.2.1