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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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"
34 #define ANJUTA_PIXMAP_MESSAGES "anjuta-messages-plugin-48.png"
35 #define ANJUTA_PIXMAP_PREV_MESSAGE "anjuta-go-message-prev"
36 #define ANJUTA_PIXMAP_NEXT_MESSAGE "anjuta-go-message-next"
39 #define ANJUTA_STOCK_MESSAGES "anjuta-messages"
40 #define ANJUTA_STOCK_PREV_MESSAGE "anjuta-prev-message"
41 #define ANJUTA_STOCK_NEXT_MESSAGE "anjuta-next-message"
43 static void on_next_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
45 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
46 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
48 message_view_next(view
);
51 static void on_prev_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
53 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
54 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
56 message_view_previous(view
);
59 static void on_save_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
61 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
62 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
64 message_view_save(view
);
67 static GtkActionEntry actions_goto
[] = {
68 { "ActionMenuGoto", NULL
, N_("_Goto"), NULL
, NULL
, NULL
},
69 { "ActionMessageNext", ANJUTA_STOCK_NEXT_MESSAGE
,
70 N_("_Next Message"), "<control><alt>n",
72 G_CALLBACK (on_next_message
)},
73 { "ActionMessagePrev", ANJUTA_STOCK_PREV_MESSAGE
,
74 N_("_Previous Message"), "<control><alt>p",
75 N_("Previous message"),
76 G_CALLBACK (on_prev_message
)},
77 { "ActionMessageSave", NULL
,
78 N_("_Save Message"), NULL
,
80 G_CALLBACK (on_save_message
)}
83 static void on_view_changed(AnjutaMsgman
* msgman
, MessageViewPlugin
* plugin
)
85 AnjutaUI
* ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN(plugin
)->shell
, NULL
);
86 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
88 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
90 gboolean sensitive
= (anjuta_msgman_get_current_view(msgman
) != NULL
);
92 anjuta_shell_present_widget (ANJUTA_PLUGIN (plugin
)->shell
,
93 GTK_WIDGET(msgman
), NULL
);
94 g_object_set (G_OBJECT (action_next
), "sensitive", sensitive
, NULL
);
95 g_object_set (G_OBJECT (action_prev
), "sensitive", sensitive
, NULL
);
98 static gpointer parent_class
;
101 register_stock_icons (AnjutaPlugin
*plugin
)
103 static gboolean registered
= FALSE
;
109 /* Register stock icons */
110 BEGIN_REGISTER_ICON (plugin
);
111 REGISTER_ICON (ANJUTA_PIXMAP_MESSAGES
, "message-manager-plugin-icon");
112 REGISTER_ICON (ANJUTA_PIXMAP_MESSAGES
, ANJUTA_STOCK_MESSAGES
);
113 REGISTER_ICON_FULL (ANJUTA_PIXMAP_NEXT_MESSAGE
, ANJUTA_STOCK_NEXT_MESSAGE
);
114 REGISTER_ICON_FULL (ANJUTA_PIXMAP_PREV_MESSAGE
, ANJUTA_STOCK_PREV_MESSAGE
);
118 #if 0 /* Disable session saving/loading until a way is found to avoid
119 * number of message panes infinitely growing */
121 on_session_save (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
122 AnjutaSession
*session
, MessageViewPlugin
*plugin
)
126 gchar
*messages_file
;
127 AnjutaSerializer
*serializer
;
129 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
132 dir
= anjuta_session_get_session_directory (session
);
133 messages_file
= g_build_filename (dir
, "messages.txt", NULL
);
134 serializer
= anjuta_serializer_new (messages_file
,
135 ANJUTA_SERIALIZER_WRITE
);
138 g_free (messages_file
);
141 success
= anjuta_msgman_serialize (ANJUTA_MSGMAN (plugin
->msgman
),
143 g_object_unref (serializer
);
146 g_warning ("Serialization failed: deleting %s", messages_file
);
147 unlink (messages_file
);
149 g_free (messages_file
);
153 on_session_load (AnjutaShell
*shell
, AnjutaSessionPhase phase
,
154 AnjutaSession
*session
, MessageViewPlugin
*plugin
)
157 gchar
*messages_file
;
158 AnjutaSerializer
*serializer
;
160 if (phase
!= ANJUTA_SESSION_PHASE_NORMAL
)
163 dir
= anjuta_session_get_session_directory (session
);
164 messages_file
= g_build_filename (dir
, "messages.txt", NULL
);
165 serializer
= anjuta_serializer_new (messages_file
,
166 ANJUTA_SERIALIZER_READ
);
169 g_free (messages_file
);
172 anjuta_msgman_remove_all_views (ANJUTA_MSGMAN (plugin
->msgman
));
173 anjuta_msgman_deserialize (ANJUTA_MSGMAN (plugin
->msgman
), serializer
);
174 g_object_unref (serializer
);
175 g_free (messages_file
);
180 activate_plugin (AnjutaPlugin
*plugin
)
184 MessageViewPlugin
*mv_plugin
;
185 static gboolean initialized
= FALSE
;
187 DEBUG_PRINT ("MessageViewPlugin: Activating MessageView plugin ...");
188 mv_plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
192 register_stock_icons (plugin
);
194 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
195 mv_plugin
->action_group
=
196 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGotoMessages",
197 _("Next/Previous Message"),
199 G_N_ELEMENTS (actions_goto
),
200 GETTEXT_PACKAGE
, TRUE
, plugin
);
201 mv_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
202 popup
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
), "/PopupMessageView");
204 anjuta_msgman_new(anjuta_shell_get_preferences(plugin
->shell
, NULL
), popup
);
205 g_signal_connect(G_OBJECT(mv_plugin
->msgman
), "view_changed",
206 G_CALLBACK(on_view_changed
), mv_plugin
);
207 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
208 "ActionMessageNext");
209 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
210 "ActionMessagePrev");
211 g_object_set (G_OBJECT (action_next
), "sensitive", FALSE
, NULL
);
212 g_object_set (G_OBJECT (action_prev
), "sensitive", FALSE
, NULL
);
214 anjuta_shell_add_widget (plugin
->shell
, mv_plugin
->msgman
,
215 "AnjutaMessageView", _("Messages"),
216 "message-manager-plugin-icon",
217 ANJUTA_SHELL_PLACEMENT_BOTTOM
, NULL
);
219 /* Connect to save and load session */
220 g_signal_connect (G_OBJECT (plugin
->shell
), "save-session",
221 G_CALLBACK (on_session_save
), plugin
);
222 g_signal_connect (G_OBJECT (plugin
->shell
), "load-session",
223 G_CALLBACK (on_session_load
), plugin
);
230 deactivate_plugin (AnjutaPlugin
*plugin
)
232 MessageViewPlugin
*mplugin
;
233 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
235 DEBUG_PRINT ("MessageViewPlugin: Dectivating message view plugin ...");
237 mplugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
239 /* Disconnect signals */
240 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
241 G_CALLBACK (on_session_save
),
243 g_signal_handlers_disconnect_by_func (G_OBJECT (plugin
->shell
),
244 G_CALLBACK (on_session_load
),
247 /* Widget is destroyed as soon as it is removed */
248 anjuta_shell_remove_widget (plugin
->shell
, mplugin
->msgman
, NULL
);
249 anjuta_ui_unmerge (ui
, mplugin
->uiid
);
250 anjuta_ui_remove_action_group (ui
, mplugin
->action_group
);
252 mplugin
->action_group
= NULL
;
253 mplugin
->msgman
= NULL
;
260 message_view_plugin_dispose (GObject
*obj
)
262 // MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
263 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
267 message_view_plugin_finalize (GObject
*obj
)
269 // MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
270 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
274 message_view_plugin_instance_init (GObject
*obj
)
276 MessageViewPlugin
*plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (obj
);
277 plugin
->action_group
= NULL
;
278 plugin
->msgman
= NULL
;
283 message_view_plugin_class_init (GObjectClass
*klass
)
285 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
287 parent_class
= g_type_class_peek_parent (klass
);
289 plugin_class
->activate
= activate_plugin
;
290 plugin_class
->deactivate
= deactivate_plugin
;
291 klass
->dispose
= message_view_plugin_dispose
;
292 klass
->finalize
= message_view_plugin_finalize
;
296 * IAnjutaMessagerManager interface implementation
298 static IAnjutaMessageView
*
299 ianjuta_msgman_add_view (IAnjutaMessageManager
*plugin
,
300 const gchar
*file
, const gchar
*icon
,
303 MessageView
* message_view
;
304 AnjutaShell
* shell
= ANJUTA_PLUGIN(plugin
)->shell
;
305 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
306 anjuta_shell_present_widget(shell
, msgman
, NULL
);
307 message_view
= anjuta_msgman_add_view (ANJUTA_MSGMAN (msgman
), file
, icon
);
308 return IANJUTA_MESSAGE_VIEW (message_view
);
312 ianjuta_msgman_remove_view (IAnjutaMessageManager
*plugin
,
313 IAnjutaMessageView
* view
,
316 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
317 anjuta_msgman_remove_view (ANJUTA_MSGMAN (msgman
), MESSAGE_VIEW (view
));
320 static IAnjutaMessageView
*
321 ianjuta_msgman_get_current_view (IAnjutaMessageManager
*plugin
,
324 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
325 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_current_view
326 (ANJUTA_MSGMAN (msgman
)));
329 static IAnjutaMessageView
*
330 ianjuta_msgman_get_view_by_name (IAnjutaMessageManager
*plugin
,
334 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
335 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_view_by_name
336 (ANJUTA_MSGMAN (msgman
), name
));
340 ianjuta_msgman_get_all_views (IAnjutaMessageManager
*plugin
,
343 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
344 return anjuta_msgman_get_all_views (ANJUTA_MSGMAN (msgman
));
348 ianjuta_msgman_set_current_view (IAnjutaMessageManager
*plugin
,
349 IAnjutaMessageView
*message_view
,
353 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
354 anjuta_msgman_set_current_view (ANJUTA_MSGMAN (msgman
),
355 MESSAGE_VIEW (message_view
));
357 /* Ensure the message-view is visible! */
358 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
362 ianjuta_msgman_set_view_title (IAnjutaMessageManager
*plugin
,
363 IAnjutaMessageView
*message_view
,
364 const gchar
*title
, GError
** e
)
366 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
367 anjuta_msgman_set_view_title (ANJUTA_MSGMAN (msgman
),
368 MESSAGE_VIEW (message_view
), title
);
372 ianjuta_msgman_iface_init (IAnjutaMessageManagerIface
*iface
)
374 iface
->add_view
= ianjuta_msgman_add_view
;
375 iface
->remove_view
= ianjuta_msgman_remove_view
;
376 iface
->get_view_by_name
= ianjuta_msgman_get_view_by_name
;
377 iface
->get_current_view
= ianjuta_msgman_get_current_view
;
378 iface
->set_current_view
= ianjuta_msgman_set_current_view
;
379 iface
->get_all_views
= ianjuta_msgman_get_all_views
;
380 iface
->set_view_title
= ianjuta_msgman_set_view_title
;
383 static guint notify_id
;
386 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
389 MessageViewPlugin
* plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (ipref
);
390 /* Create the messages preferences page */
391 gxml
= glade_xml_new (PREFS_GLADE
, "preferences_dialog_messages", NULL
);
392 anjuta_preferences_add_page (prefs
, gxml
,
393 "Messages", _("Messages"),
394 ANJUTA_PIXMAP_MESSAGES
);
395 notify_id
= anjuta_preferences_notify_add (prefs
, MESSAGES_TABS_POS
,
396 on_gconf_notify_message_pref
, plugin
->msgman
, NULL
);
398 g_object_unref (gxml
);
402 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
404 anjuta_preferences_notify_remove(prefs
, notify_id
);
405 anjuta_preferences_remove_page(prefs
, _("Messages"));
409 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
411 iface
->merge
= ipreferences_merge
;
412 iface
->unmerge
= ipreferences_unmerge
;
415 ANJUTA_PLUGIN_BEGIN (MessageViewPlugin
, message_view_plugin
);
416 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_msgman
, IANJUTA_TYPE_MESSAGE_MANAGER
);
417 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
420 ANJUTA_SIMPLE_PLUGIN (MessageViewPlugin
, message_view_plugin
);