Updated Spanish translation
[anjuta-git-plugin.git] / plugins / sourceview / plugin.c
blob84506a9e7d0a52b6483f872f3d9118b919c48e97
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
2 /*
3 * plugin.c
4 * Copyright (C) Johannes Schmid 2005 <jhs@gnome.org>
5 *
6 * plugin.c is free software.
7 *
8 * You may redistribute it and/or modify it under the terms of the
9 * GNU General Public License, as published by the Free Software
10 * Foundation; either version 2 of the License, or (at your option)
11 * any later version.
13 * plugin.c is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with plugin.c. If not, write to:
20 * The Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor
22 * Boston, MA 02110-1301, USA.
25 #include <config.h>
26 #include <libanjuta/anjuta-shell.h>
27 #include <libanjuta/anjuta-debug.h>
28 #include <libanjuta/anjuta-preferences.h>
29 #include <libanjuta/anjuta-status.h>
30 #include <libanjuta/interfaces/ianjuta-document-manager.h>
31 #include <libanjuta/interfaces/ianjuta-editor-factory.h>
32 #include <libanjuta/interfaces/ianjuta-editor.h>
33 #include <libanjuta/interfaces/ianjuta-preferences.h>
35 #include "plugin.h"
36 #include "sourceview.h"
38 #define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-editor-sourceview.glade"
39 #define ICON_FILE "anjuta-editor-sourceview-plugin-48.png"
41 #define COLOR_USE_THEME_BUTTON "preferences_toggle:bool:1:0:sourceview.color.use_theme"
42 #define COLOR_TEXT "preferences_color:color:#FFFFFF:0:sourceview.color.text"
43 #define COLOR_BACKGROUND "preferences_color:color:#000000:0:sourceview.color.background"
44 #define COLOR_SELECTED_TEXT "preferences_color:color:#000000:0:sourceview.color.selected_text"
45 #define COLOR_SELECTION "preferences_color:color:#0000FF:0:sourceview.color.selection"
47 #define FONT_USE_THEME_BUTTON "preferences_toggle:bool:1:0:sourceview.font.use_theme"
48 #define FONT_BUTTON "preferences_font:font:Sans:0:sourceview.font"
50 static gpointer parent_class;
52 static GladeXML* gxml = NULL;
54 static void
55 on_color_check_toggled(GtkToggleButton* button, GladeXML* gxml)
57 GtkWidget* color_button;
58 color_button = glade_xml_get_widget(gxml, COLOR_TEXT);
59 gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
61 color_button = glade_xml_get_widget(gxml, COLOR_BACKGROUND);
62 gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
64 color_button = glade_xml_get_widget(gxml, COLOR_SELECTED_TEXT);
65 gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
67 color_button = glade_xml_get_widget(gxml, COLOR_SELECTION);
68 gtk_widget_set_sensitive(color_button, !gtk_toggle_button_get_active(button));
71 static void
72 on_font_check_toggled(GtkToggleButton* button, GladeXML* gxml)
74 GtkWidget* font_button;
75 font_button = glade_xml_get_widget(gxml, FONT_BUTTON);
76 gtk_widget_set_sensitive(font_button, !gtk_toggle_button_get_active(button));
79 static gboolean
80 sourceview_plugin_activate (AnjutaPlugin *plugin)
82 DEBUG_PRINT ("SourceviewPlugin: Activating SourceviewPlugin plugin ...");
84 return TRUE;
87 static gboolean
88 sourceview_plugin_deactivate (AnjutaPlugin *plugin)
90 DEBUG_PRINT ("SourceviewPlugin: Dectivating SourceviewPlugin plugin ...");
92 return TRUE;
95 static void
96 sourceview_plugin_finalize (GObject *obj)
98 /* Finalization codes here */
99 GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (obj));
102 static void
103 sourceview_plugin_dispose (GObject *obj)
105 /* Disposition codes */
106 GNOME_CALL_PARENT (G_OBJECT_CLASS, dispose, (obj));
109 static void
110 sourceview_plugin_instance_init (GObject *obj)
115 static void
116 sourceview_plugin_class_init (GObjectClass *klass)
118 AnjutaPluginClass *plugin_class = ANJUTA_PLUGIN_CLASS (klass);
120 parent_class = g_type_class_peek_parent (klass);
122 plugin_class->activate = sourceview_plugin_activate;
123 plugin_class->deactivate = sourceview_plugin_deactivate;
124 klass->finalize = sourceview_plugin_finalize;
125 klass->dispose = sourceview_plugin_dispose;
128 static IAnjutaEditor*
129 ieditor_factory_new_editor(IAnjutaEditorFactory* factory,
130 const gchar* uri,
131 const gchar* filename,
132 GError** error)
134 AnjutaPlugin* plugin = ANJUTA_PLUGIN(factory);
135 IAnjutaEditor* editor = IANJUTA_EDITOR(sourceview_new(uri, filename, plugin)); return editor;
136 return editor;
139 static void
140 ieditor_factory_iface_init (IAnjutaEditorFactoryIface *iface)
142 iface->new_editor = ieditor_factory_new_editor;
145 static void
146 ipreferences_merge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
148 /* Add preferences */
149 SourceviewPlugin* plugin = ANJUTA_PLUGIN_SOURCEVIEW (ipref);
150 gxml = glade_xml_new (PREFS_GLADE, "preferences_dialog", NULL);
151 anjuta_preferences_add_page (prefs,
152 gxml, "Editor", _("GtkSourceView Editor"), ICON_FILE);
154 plugin->check_color = glade_xml_get_widget(gxml, COLOR_USE_THEME_BUTTON);
155 g_signal_connect(G_OBJECT(plugin->check_color), "toggled", G_CALLBACK(on_color_check_toggled), gxml);
156 plugin->check_font = glade_xml_get_widget(gxml, FONT_USE_THEME_BUTTON);
157 g_signal_connect(G_OBJECT(plugin->check_font), "toggled", G_CALLBACK(on_font_check_toggled), gxml);
160 static void
161 ipreferences_unmerge(IAnjutaPreferences* ipref, AnjutaPreferences* prefs, GError** e)
163 SourceviewPlugin* plugin = ANJUTA_PLUGIN_SOURCEVIEW (ipref);
164 g_signal_handlers_disconnect_by_func(G_OBJECT(plugin->check_color),
165 G_CALLBACK(on_color_check_toggled), gxml);
166 g_signal_handlers_disconnect_by_func(G_OBJECT(plugin->check_font),
167 G_CALLBACK(on_font_check_toggled), gxml);
169 anjuta_preferences_remove_page(prefs, _("GtkSourceView Editor"));
170 g_object_unref(gxml);
171 gxml = NULL;
174 static void
175 ipreferences_iface_init(IAnjutaPreferencesIface* iface)
177 iface->merge = ipreferences_merge;
178 iface->unmerge = ipreferences_unmerge;
181 ANJUTA_PLUGIN_BEGIN (SourceviewPlugin, sourceview_plugin);
182 ANJUTA_TYPE_ADD_INTERFACE(ieditor_factory, IANJUTA_TYPE_EDITOR_FACTORY);
183 ANJUTA_TYPE_ADD_INTERFACE(ipreferences, IANJUTA_TYPE_PREFERENCES);
184 ANJUTA_PLUGIN_END;
186 ANJUTA_SIMPLE_PLUGIN (SourceviewPlugin, sourceview_plugin);