1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2004 Johannes Schmid
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 of the License, or
9 (at your option) any later version.
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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <libanjuta/anjuta-shell.h>
23 #include <libanjuta/anjuta-debug.h>
24 #include <libanjuta/interfaces/ianjuta-message-manager.h>
25 #include <libanjuta/interfaces/ianjuta-preferences.h>
28 #include "anjuta-msgman.h"
30 #define UI_FILE PACKAGE_DATA_DIR"/ui/anjuta-message-manager.ui"
31 #define PREFS_GLADE PACKAGE_DATA_DIR"/glade/anjuta-message-manager-plugin.glade"
32 #define ICON_FILE "preferences-messages.png"
35 #define ANJUTA_PIXMAP_MESSAGES "messages.xpm"
36 #define ANJUTA_PIXMAP_PREV_MESSAGE "error-prev.png"
37 #define ANJUTA_PIXMAP_NEXT_MESSAGE "error-next.png"
38 #define ANJUTA_PIXMAP_PREV_MESSAGE_16 "error-prev-16.png"
39 #define ANJUTA_PIXMAP_NEXT_MESSAGE_16 "error-next-16.png"
42 #define ANJUTA_STOCK_MESSAGES "anjuta-messages"
43 #define ANJUTA_STOCK_PREV_MESSAGE "anjuta-prev-message"
44 #define ANJUTA_STOCK_NEXT_MESSAGE "anjuta-next-message"
46 static void on_next_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
48 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
49 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
51 message_view_next(view
);
54 static void on_prev_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
56 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
57 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
59 message_view_previous(view
);
62 static void on_save_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
64 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
65 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
67 message_view_save(view
);
70 static GtkActionEntry actions_goto
[] = {
71 { "ActionMenuGoto", NULL
, N_("_Goto"), NULL
, NULL
, NULL
},
72 { "ActionMessageNext", ANJUTA_STOCK_NEXT_MESSAGE
,
73 N_("_Next Message"), "<control><alt>n",
75 G_CALLBACK (on_next_message
)},
76 { "ActionMessagePrev", ANJUTA_STOCK_PREV_MESSAGE
,
77 N_("_Previous Message"), "<control><alt>p",
78 N_("Previous message"),
79 G_CALLBACK (on_prev_message
)},
80 { "ActionMessageSave", NULL
,
81 N_("_Save Message"), NULL
,
83 G_CALLBACK (on_save_message
)}
86 static void on_view_changed(AnjutaMsgman
* msgman
, MessageViewPlugin
* plugin
)
88 AnjutaUI
* ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN(plugin
)->shell
, NULL
);
89 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
91 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
93 gboolean sensitive
= (anjuta_msgman_get_current_view(msgman
) != NULL
);
95 anjuta_shell_present_widget (ANJUTA_PLUGIN (plugin
)->shell
,
96 GTK_WIDGET(msgman
), NULL
);
97 g_object_set (G_OBJECT (action_next
), "sensitive", sensitive
, NULL
);
98 g_object_set (G_OBJECT (action_prev
), "sensitive", sensitive
, NULL
);
101 static gpointer parent_class
;
103 #define REGISTER_ICON(icon, stock_id) \
104 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"icon, NULL); \
105 icon_set = gtk_icon_set_new_from_pixbuf (pixbuf); \
106 gtk_icon_factory_add (icon_factory, stock_id, icon_set); \
107 g_object_unref (pixbuf);
109 #define ADD_ICON(icon) \
110 pixbuf = gdk_pixbuf_new_from_file (PACKAGE_PIXMAPS_DIR"/"icon, NULL); \
111 gtk_icon_source_set_pixbuf (source, pixbuf); \
112 gtk_icon_set_add_source (icon_set, source); \
113 g_object_unref (pixbuf);
116 register_stock_icons (AnjutaPlugin
*plugin
)
119 GtkIconFactory
*icon_factory
;
120 GtkIconSet
*icon_set
;
122 GtkIconSource
*source
;
124 static gboolean registered
= FALSE
;
130 /* Register stock icons */
131 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
132 icon_factory
= anjuta_ui_get_icon_factory (ui
);
134 source
= gtk_icon_source_new ();
135 gtk_icon_source_set_size (source
, GTK_ICON_SIZE_MENU
);
137 REGISTER_ICON (ICON_FILE
, "message-manager-plugin-icon");
138 REGISTER_ICON (ANJUTA_PIXMAP_MESSAGES
, ANJUTA_STOCK_MESSAGES
);
139 REGISTER_ICON (ANJUTA_PIXMAP_NEXT_MESSAGE
, ANJUTA_STOCK_NEXT_MESSAGE
);
140 //ADD_ICON (ANJUTA_PIXMAP_NEXT_MESSAGE_16);
141 REGISTER_ICON (ANJUTA_PIXMAP_PREV_MESSAGE
, ANJUTA_STOCK_PREV_MESSAGE
);
142 //ADD_ICON (ANJUTA_PIXMAP_PREV_MESSAGE_16);
144 gtk_icon_source_free (source
);
147 #if 0 /* Disable session saving/loading until a way is found to avoid
148 * number of message panes infinitely growing */
150 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
151 AnjutaSession
*session
, MessageViewPlugin
*plugin
)
155 gchar
*messages_file
;
156 AnjutaSerializer
*serializer
;
158 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
161 dir
= anjuta_session_get_session_directory (session
);
162 messages_file
= g_build_filename (dir
, "messages.txt", NULL
);
163 serializer
= anjuta_serializer_new (messages_file
,
164 ANJUTA_SERIALIZER_WRITE
);
167 g_free (messages_file
);
170 success
= anjuta_msgman_serialize (ANJUTA_MSGMAN (plugin
->msgman
),
172 g_object_unref (serializer
);
175 g_warning ("Serialization failed: deleting %s", messages_file
);
176 unlink (messages_file
);
178 g_free (messages_file
);
182 on_session_load (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
183 AnjutaSession
*session
, MessageViewPlugin
*plugin
)
186 gchar
*messages_file
;
187 AnjutaSerializer
*serializer
;
189 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
192 dir
= anjuta_session_get_session_directory (session
);
193 messages_file
= g_build_filename (dir
, "messages.txt", NULL
);
194 serializer
= anjuta_serializer_new (messages_file
,
195 ANJUTA_SERIALIZER_READ
);
198 g_free (messages_file
);
201 anjuta_msgman_remove_all_views (ANJUTA_MSGMAN (plugin
->msgman
));
202 anjuta_msgman_deserialize (ANJUTA_MSGMAN (plugin
->msgman
), serializer
);
203 g_object_unref (serializer
);
204 g_free (messages_file
);
209 activate_plugin (AnjutaPlugin
*plugin
)
213 MessageViewPlugin
*mv_plugin
;
214 static gboolean initialized
= FALSE
;
216 DEBUG_PRINT ("MessageViewPlugin: Activating MessageView plugin ...");
217 mv_plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
221 register_stock_icons (plugin
);
223 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
224 mv_plugin
->action_group
=
225 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGotoMessages",
226 _("Next/Prev Message"),
228 G_N_ELEMENTS (actions_goto
),
229 GETTEXT_PACKAGE
, TRUE
, plugin
);
230 mv_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
231 popup
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
), "/PopupMessageView");
233 anjuta_msgman_new(anjuta_shell_get_preferences(plugin
->shell
, NULL
), popup
);
234 g_signal_connect(G_OBJECT(mv_plugin
->msgman
), "view_changed",
235 G_CALLBACK(on_view_changed
), mv_plugin
);
236 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
237 "ActionMessageNext");
238 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
239 "ActionMessagePrev");
240 g_object_set (G_OBJECT (action_next
), "sensitive", FALSE
, NULL
);
241 g_object_set (G_OBJECT (action_prev
), "sensitive", FALSE
, NULL
);
243 anjuta_shell_add_widget (plugin
->shell
, mv_plugin
->msgman
,
244 "AnjutaMessageView", _("Messages"),
245 "message-manager-plugin-icon",
246 ANJUTA_SHELL_PLACEMENT_BOTTOM
, NULL
);
248 /* Connect to save and load session */
249 g_signal_connect (G_OBJECT (plugin
->shell
), "save-session",
250 G_CALLBACK (on_session_save
), plugin
);
251 g_signal_connect (G_OBJECT (plugin
->shell
), "load-session",
252 G_CALLBACK (on_session_load
), plugin
);
259 deactivate_plugin (AnjutaPlugin
*plugin
)
261 MessageViewPlugin
*mplugin
;
262 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
264 DEBUG_PRINT ("MessageViewPlugin: Dectivating message view plugin ...");
266 mplugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
268 /* Disconnect signals */
269 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
270 G_CALLBACK (on_session_save
),
272 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
273 G_CALLBACK (on_session_load
),
276 /* Widget is destroyed as soon as it is removed */
277 anjuta_shell_remove_widget (plugin
->shell
, mplugin
->msgman
, NULL
);
278 anjuta_ui_unmerge (ui
, mplugin
->uiid
);
279 anjuta_ui_remove_action_group (ui
, mplugin
->action_group
);
281 mplugin
->action_group
= NULL
;
282 mplugin
->msgman
= NULL
;
289 message_view_plugin_dispose (GObject
*obj
)
291 // MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
292 GNOME_CALL_PARENT (G_OBJECT_CLASS
, dispose
, (obj
));
296 message_view_plugin_finalize (GObject
*obj
)
298 // MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
299 GNOME_CALL_PARENT (G_OBJECT_CLASS
, finalize
, (obj
));
303 message_view_plugin_instance_init (GObject
*obj
)
305 MessageViewPlugin
*plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (obj
);
306 plugin
->action_group
= NULL
;
307 plugin
->msgman
= NULL
;
312 message_view_plugin_class_init (GObjectClass
*klass
)
314 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
316 parent_class
= g_type_class_peek_parent (klass
);
318 plugin_class
->activate
= activate_plugin
;
319 plugin_class
->deactivate
= deactivate_plugin
;
320 klass
->dispose
= message_view_plugin_dispose
;
321 klass
->finalize
= message_view_plugin_finalize
;
325 * IAnjutaMessagerManager interface implementation
327 static IAnjutaMessageView
*
328 ianjuta_msgman_add_view (IAnjutaMessageManager
*plugin
,
329 const gchar
*file
, const gchar
*icon
,
332 MessageView
* message_view
;
333 AnjutaShell
* shell
= ANJUTA_PLUGIN(plugin
)->shell
;
334 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
335 anjuta_shell_present_widget(shell
, msgman
, NULL
);
336 message_view
= anjuta_msgman_add_view (ANJUTA_MSGMAN (msgman
), file
, icon
);
337 return IANJUTA_MESSAGE_VIEW (message_view
);
341 ianjuta_msgman_remove_view (IAnjutaMessageManager
*plugin
,
342 IAnjutaMessageView
* view
,
345 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
346 anjuta_msgman_remove_view (ANJUTA_MSGMAN (msgman
), MESSAGE_VIEW (view
));
349 static IAnjutaMessageView
*
350 ianjuta_msgman_get_current_view (IAnjutaMessageManager
*plugin
,
353 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
354 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_current_view
355 (ANJUTA_MSGMAN (msgman
)));
358 static IAnjutaMessageView
*
359 ianjuta_msgman_get_view_by_name (IAnjutaMessageManager
*plugin
,
363 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
364 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_view_by_name
365 (ANJUTA_MSGMAN (msgman
), name
));
369 ianjuta_msgman_get_all_views (IAnjutaMessageManager
*plugin
,
372 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
373 return anjuta_msgman_get_all_views (ANJUTA_MSGMAN (msgman
));
377 ianjuta_msgman_set_current_view (IAnjutaMessageManager
*plugin
,
378 IAnjutaMessageView
*message_view
,
382 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
383 anjuta_msgman_set_current_view (ANJUTA_MSGMAN (msgman
),
384 MESSAGE_VIEW (message_view
));
386 /* Ensure the message-view is visible! */
387 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
391 ianjuta_msgman_set_view_title (IAnjutaMessageManager
*plugin
,
392 IAnjutaMessageView
*message_view
,
393 const gchar
*title
, GError
** e
)
395 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
396 anjuta_msgman_set_view_title (ANJUTA_MSGMAN (msgman
),
397 MESSAGE_VIEW (message_view
), title
);
401 ianjuta_msgman_iface_init (IAnjutaMessageManagerIface
*iface
)
403 iface
->add_view
= ianjuta_msgman_add_view
;
404 iface
->remove_view
= ianjuta_msgman_remove_view
;
405 iface
->get_view_by_name
= ianjuta_msgman_get_view_by_name
;
406 iface
->get_current_view
= ianjuta_msgman_get_current_view
;
407 iface
->set_current_view
= ianjuta_msgman_set_current_view
;
408 iface
->get_all_views
= ianjuta_msgman_get_all_views
;
409 iface
->set_view_title
= ianjuta_msgman_set_view_title
;
412 static guint notify_id
;
415 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
418 MessageViewPlugin
* plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (ipref
);
419 /* Create the messages preferences page */
420 gxml
= glade_xml_new (PREFS_GLADE
, "preferences_dialog_messages", NULL
);
421 anjuta_preferences_add_page (prefs
, gxml
,
422 "Messages", _("Messages"), ICON_FILE
);
423 notify_id
= anjuta_preferences_notify_add (prefs
, MESSAGES_TABS_POS
,
424 on_gconf_notify_message_pref
, plugin
->msgman
, NULL
);
426 g_object_unref (gxml
);
430 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
432 anjuta_preferences_notify_remove(prefs
, notify_id
);
433 anjuta_preferences_dialog_remove_page(ANJUTA_PREFERENCES_DIALOG(prefs
),
438 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
440 iface
->merge
= ipreferences_merge
;
441 iface
->unmerge
= ipreferences_unmerge
;
444 ANJUTA_PLUGIN_BEGIN (MessageViewPlugin
, message_view_plugin
);
445 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_msgman
, IANJUTA_TYPE_MESSAGE_MANAGER
);
446 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
449 ANJUTA_SIMPLE_PLUGIN (MessageViewPlugin
, message_view_plugin
);