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.xml"
31 #define PREFS_BUILDER PACKAGE_DATA_DIR"/glade/anjuta-message-manager-plugin.ui"
32 #define PREFERENCES_SCHEMA "org.gnome.anjuta.plugins.message-manager"
35 #define ANJUTA_PIXMAP_MESSAGES "anjuta-messages-plugin-48.png"
36 #define ANJUTA_PIXMAP_PREV_MESSAGE "anjuta-go-message-prev"
37 #define ANJUTA_PIXMAP_NEXT_MESSAGE "anjuta-go-message-next"
40 #define ANJUTA_STOCK_MESSAGES "anjuta-messages"
41 #define ANJUTA_STOCK_PREV_MESSAGE "anjuta-prev-message"
42 #define ANJUTA_STOCK_NEXT_MESSAGE "anjuta-next-message"
44 static void on_next_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
46 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
47 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
49 message_view_next(view
);
52 static void on_prev_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
54 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
55 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
57 message_view_previous(view
);
60 static void on_copy_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
62 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
63 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
65 message_view_copy(view
);
68 static void on_save_message(GtkAction
* menuitem
, MessageViewPlugin
*plugin
)
70 AnjutaMsgman
* msgman
= ANJUTA_MSGMAN(plugin
->msgman
);
71 MessageView
* view
= anjuta_msgman_get_current_view(msgman
);
73 message_view_save(view
);
76 static GtkActionEntry actions_goto
[] = {
77 { "ActionMenuGoto", NULL
, N_("_Go to"), NULL
, NULL
, NULL
},
78 { "ActionMessageCopy", GTK_STOCK_COPY
,
79 N_("_Copy Message"), NULL
,
81 G_CALLBACK (on_copy_message
)},
82 { "ActionMessageNext", ANJUTA_STOCK_NEXT_MESSAGE
,
83 N_("_Next Message"), "<control><alt>n",
85 G_CALLBACK (on_next_message
)},
86 { "ActionMessagePrev", ANJUTA_STOCK_PREV_MESSAGE
,
87 N_("_Previous Message"), "<control><alt>p",
88 N_("Previous message"),
89 G_CALLBACK (on_prev_message
)},
90 { "ActionMessageSave", NULL
,
91 N_("_Save Message"), NULL
,
93 G_CALLBACK (on_save_message
)}
96 static void on_view_changed(AnjutaMsgman
* msgman
, MessageViewPlugin
* plugin
)
98 MessageView
* view
= anjuta_msgman_get_current_view (msgman
);
99 AnjutaUI
* ui
= anjuta_shell_get_ui (ANJUTA_PLUGIN(plugin
)->shell
, NULL
);
100 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
101 "ActionMessageNext");
102 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
103 "ActionMessagePrev");
104 GtkAction
* action_copy
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
105 "ActionMessageCopy");
106 gboolean sensitive
= (view
!= NULL
);
108 anjuta_shell_present_widget (ANJUTA_PLUGIN (plugin
)->shell
,
109 GTK_WIDGET(msgman
), NULL
);
110 g_object_set (G_OBJECT (action_next
), "sensitive", sensitive
, NULL
);
111 g_object_set (G_OBJECT (action_prev
), "sensitive", sensitive
, NULL
);
112 g_object_set (G_OBJECT (action_copy
), "sensitive", sensitive
, NULL
);
115 gtk_widget_set_sensitive (plugin
->normal
, sensitive
);
116 gtk_widget_set_sensitive (plugin
->info
, sensitive
);
117 gtk_widget_set_sensitive (plugin
->warn
, sensitive
);
118 gtk_widget_set_sensitive (plugin
->error
, sensitive
);
121 MessageViewFlags flags
=
122 message_view_get_flags (view
);
123 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin
->normal
), flags
& MESSAGE_VIEW_SHOW_NORMAL
);
124 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin
->info
), flags
& MESSAGE_VIEW_SHOW_INFO
);
125 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin
->warn
), flags
& MESSAGE_VIEW_SHOW_WARNING
);
126 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin
->error
), flags
& MESSAGE_VIEW_SHOW_ERROR
);
130 static gpointer parent_class
;
133 register_stock_icons (AnjutaPlugin
*plugin
)
135 static gboolean registered
= FALSE
;
141 /* Register stock icons */
142 BEGIN_REGISTER_ICON (plugin
);
143 REGISTER_ICON (ANJUTA_PIXMAP_MESSAGES
, "message-manager-plugin-icon");
144 REGISTER_ICON (ANJUTA_PIXMAP_MESSAGES
, ANJUTA_STOCK_MESSAGES
);
145 REGISTER_ICON_FULL (ANJUTA_PIXMAP_NEXT_MESSAGE
, ANJUTA_STOCK_NEXT_MESSAGE
);
146 REGISTER_ICON_FULL (ANJUTA_PIXMAP_PREV_MESSAGE
, ANJUTA_STOCK_PREV_MESSAGE
);
151 activate_plugin (AnjutaPlugin
*plugin
)
155 MessageViewPlugin
*mv_plugin
;
156 static gboolean initialized
= FALSE
;
158 DEBUG_PRINT ("%s", "MessageViewPlugin: Activating MessageView plugin ...");
159 mv_plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
163 register_stock_icons (plugin
);
165 ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
166 mv_plugin
->action_group
=
167 anjuta_ui_add_action_group_entries (ui
, "ActionGroupGotoMessages",
168 _("Next/Previous Message"),
170 G_N_ELEMENTS (actions_goto
),
171 GETTEXT_PACKAGE
, TRUE
, plugin
);
172 mv_plugin
->uiid
= anjuta_ui_merge (ui
, UI_FILE
);
173 popup
= gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui
), "/PopupMessageView");
175 anjuta_msgman_new(popup
);
176 g_signal_connect(mv_plugin
->msgman
, "view-changed",
177 G_CALLBACK(on_view_changed
), mv_plugin
);
178 GtkAction
* action_next
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
179 "ActionMessageNext");
180 GtkAction
* action_prev
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
181 "ActionMessagePrev");
182 GtkAction
* action_copy
= anjuta_ui_get_action (ui
, "ActionGroupGotoMessages",
183 "ActionMessageCopy");
184 g_object_set (G_OBJECT (action_next
), "sensitive", FALSE
, NULL
);
185 g_object_set (G_OBJECT (action_prev
), "sensitive", FALSE
, NULL
);
186 g_object_set (G_OBJECT (action_copy
), "sensitive", FALSE
, NULL
);
189 mv_plugin
->widget_shown
= FALSE
;
194 deactivate_plugin (AnjutaPlugin
*plugin
)
196 MessageViewPlugin
*mplugin
;
197 AnjutaUI
*ui
= anjuta_shell_get_ui (plugin
->shell
, NULL
);
199 DEBUG_PRINT ("%s", "MessageViewPlugin: Dectivating message view plugin ...");
201 mplugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
);
203 /* Widget is removed as soon as it is destroyed */
204 if (mplugin
->widget_shown
)
205 gtk_widget_destroy (mplugin
->msgman
);
206 anjuta_ui_unmerge (ui
, mplugin
->uiid
);
207 anjuta_ui_remove_action_group (ui
, mplugin
->action_group
);
209 mplugin
->action_group
= NULL
;
210 mplugin
->msgman
= NULL
;
217 message_view_plugin_dispose (GObject
*obj
)
219 MessageViewPlugin
*plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (obj
);
220 g_object_unref (plugin
->settings
);
221 G_OBJECT_CLASS (parent_class
)->dispose (obj
);
225 message_view_plugin_finalize (GObject
*obj
)
227 // MessageViewPlugin *plugin = ANJUTA_PLUGIN_MESSAGE_VIEW (obj);
228 G_OBJECT_CLASS (parent_class
)->finalize (obj
);
232 message_view_plugin_instance_init (GObject
*obj
)
234 MessageViewPlugin
*plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (obj
);
235 plugin
->action_group
= NULL
;
236 plugin
->msgman
= NULL
;
238 plugin
->settings
= g_settings_new (PREFERENCES_SCHEMA
);
242 message_view_plugin_class_init (GObjectClass
*klass
)
244 AnjutaPluginClass
*plugin_class
= ANJUTA_PLUGIN_CLASS (klass
);
246 parent_class
= g_type_class_peek_parent (klass
);
248 plugin_class
->activate
= activate_plugin
;
249 plugin_class
->deactivate
= deactivate_plugin
;
250 klass
->dispose
= message_view_plugin_dispose
;
251 klass
->finalize
= message_view_plugin_finalize
;
255 on_filter_button_tooltip (GtkWidget
* widget
,
258 gboolean keyboard_mode
,
260 MessageViewPlugin
* plugin
)
263 MessageView
* view
= anjuta_msgman_get_current_view (ANJUTA_MSGMAN(plugin
->msgman
));
266 if (widget
== plugin
->normal
)
268 temp
= g_strdup_printf(ngettext ("%d Message", "%d Messages",
269 message_view_get_count (view
,
270 MESSAGE_VIEW_SHOW_NORMAL
)),
271 message_view_get_count (view
,
272 MESSAGE_VIEW_SHOW_NORMAL
));
273 gtk_tooltip_set_text (tooltip
, temp
);
275 else if (widget
== plugin
->info
)
277 temp
= g_strdup_printf(ngettext ("%d Info", "%d Infos",
278 message_view_get_count (view
,
279 MESSAGE_VIEW_SHOW_INFO
)),
280 message_view_get_count (view
,
281 MESSAGE_VIEW_SHOW_INFO
));
282 gtk_tooltip_set_text (tooltip
, temp
);
284 else if (widget
== plugin
->warn
)
286 temp
= g_strdup_printf(ngettext ("%d Warning", "%d Warnings",
287 message_view_get_count (view
,
288 MESSAGE_VIEW_SHOW_WARNING
)),
289 message_view_get_count (view
,
290 MESSAGE_VIEW_SHOW_WARNING
));
291 gtk_tooltip_set_text (tooltip
, temp
);
293 else if (widget
== plugin
->error
)
295 temp
= g_strdup_printf(ngettext ("%d Error", "%d Errors",
296 message_view_get_count (view
,
297 MESSAGE_VIEW_SHOW_ERROR
)),
298 message_view_get_count (view
,
299 MESSAGE_VIEW_SHOW_ERROR
));
300 gtk_tooltip_set_text (tooltip
, temp
);
303 g_assert_not_reached ();
311 on_filter_buttons_toggled (GtkWidget
* button
, MessageViewPlugin
*plugin
)
313 MessageViewFlags flags
= 0;
314 MessageView
* view
= anjuta_msgman_get_current_view (ANJUTA_MSGMAN(plugin
->msgman
));
315 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin
->normal
)))
316 flags
|= MESSAGE_VIEW_SHOW_NORMAL
;
317 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin
->info
)))
318 flags
|= MESSAGE_VIEW_SHOW_INFO
;
319 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin
->warn
)))
320 flags
|= MESSAGE_VIEW_SHOW_WARNING
;
321 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin
->error
)))
322 flags
|= MESSAGE_VIEW_SHOW_ERROR
;
324 message_view_set_flags (view
,
329 create_mini_button (MessageViewPlugin
* plugin
, const gchar
* stock_id
)
331 GtkWidget
* button
, *image
;
333 image
= gtk_image_new_from_stock (stock_id
,
335 gtk_icon_size_lookup (GTK_ICON_SIZE_MENU
, &w
, &h
);
336 button
= gtk_toggle_button_new ();
337 g_signal_connect (G_OBJECT (button
), "toggled",
338 G_CALLBACK (on_filter_buttons_toggled
), plugin
);
339 gtk_container_add (GTK_CONTAINER (button
), image
);
341 g_object_set (button
, "has-tooltip", TRUE
, NULL
);
342 g_signal_connect (button
, "query-tooltip",
343 G_CALLBACK (on_filter_button_tooltip
), plugin
);
349 create_toggle_buttons (MessageViewPlugin
* plugin
,
352 GtkWidget
* filter_buttons_box
= gtk_hbox_new (FALSE
, 0);
354 plugin
->normal
= create_mini_button (plugin
, "message-manager-plugin-icon");
355 plugin
->info
= create_mini_button (plugin
, GTK_STOCK_INFO
);
356 plugin
->warn
= create_mini_button (plugin
, GTK_STOCK_DIALOG_WARNING
);
357 plugin
->error
= create_mini_button (plugin
, GTK_STOCK_DIALOG_ERROR
);
359 gtk_box_pack_start (GTK_BOX (filter_buttons_box
), GTK_WIDGET (plugin
->normal
),
361 gtk_box_pack_start (GTK_BOX (filter_buttons_box
), GTK_WIDGET (plugin
->info
),
363 gtk_box_pack_start (GTK_BOX (filter_buttons_box
), GTK_WIDGET (plugin
->warn
),
365 gtk_box_pack_start (GTK_BOX (filter_buttons_box
), GTK_WIDGET (plugin
->error
),
368 gtk_widget_show_all (filter_buttons_box
);
369 gtk_box_pack_start (GTK_BOX(hbox
), filter_buttons_box
, FALSE
, FALSE
, 0);
373 * IAnjutaMessagerManager interface implementation
375 static IAnjutaMessageView
*
376 ianjuta_msgman_add_view (IAnjutaMessageManager
*plugin
,
377 const gchar
*file
, const gchar
*icon
,
380 MessageView
* message_view
;
381 AnjutaShell
* shell
= ANJUTA_PLUGIN(plugin
)->shell
;
382 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
383 if (ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->widget_shown
== FALSE
)
385 GtkWidget
* hbox
= gtk_hbox_new (FALSE
, 0);
386 GtkWidget
* label
= gtk_label_new (_("Messages"));
387 GtkWidget
* image
= gtk_image_new_from_stock ("message-manager-plugin-icon",
389 gtk_box_pack_start (GTK_BOX (hbox
), image
, FALSE
, FALSE
, 0);
390 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 0);
391 gtk_box_pack_start (GTK_BOX(hbox
), anjuta_msgman_get_tabber (ANJUTA_MSGMAN(msgman
)),
394 gtk_widget_show_all (hbox
);
396 create_toggle_buttons (ANJUTA_PLUGIN_MESSAGE_VIEW(plugin
), hbox
);
398 gtk_widget_show_all (msgman
);
399 anjuta_shell_add_widget_custom (shell
, msgman
,
400 "AnjutaMessageView", _("Messages"),
401 "message-manager-plugin-icon", hbox
,
402 ANJUTA_SHELL_PLACEMENT_BOTTOM
, NULL
);
403 ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->widget_shown
= TRUE
;
405 anjuta_shell_present_widget(shell
, msgman
, NULL
);
406 message_view
= anjuta_msgman_add_view (ANJUTA_MSGMAN (msgman
), file
, icon
);
407 return IANJUTA_MESSAGE_VIEW (message_view
);
411 ianjuta_msgman_remove_view (IAnjutaMessageManager
*plugin
,
412 IAnjutaMessageView
* view
,
415 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
416 anjuta_msgman_remove_view (ANJUTA_MSGMAN (msgman
), MESSAGE_VIEW (view
));
419 static IAnjutaMessageView
*
420 ianjuta_msgman_get_current_view (IAnjutaMessageManager
*plugin
,
423 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
424 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_current_view
425 (ANJUTA_MSGMAN (msgman
)));
428 static IAnjutaMessageView
*
429 ianjuta_msgman_get_view_by_name (IAnjutaMessageManager
*plugin
,
433 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
434 return IANJUTA_MESSAGE_VIEW (anjuta_msgman_get_view_by_name
435 (ANJUTA_MSGMAN (msgman
), name
));
439 ianjuta_msgman_get_all_views (IAnjutaMessageManager
*plugin
,
442 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
443 return anjuta_msgman_get_all_views (ANJUTA_MSGMAN (msgman
));
447 ianjuta_msgman_set_current_view (IAnjutaMessageManager
*plugin
,
448 IAnjutaMessageView
*message_view
,
452 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
453 anjuta_msgman_set_current_view (ANJUTA_MSGMAN (msgman
),
454 MESSAGE_VIEW (message_view
));
456 /* Ensure the message-view is visible! */
457 g_object_get(G_OBJECT(plugin
), "shell", &shell
, NULL
);
461 ianjuta_msgman_set_view_title (IAnjutaMessageManager
*plugin
,
462 IAnjutaMessageView
*message_view
,
463 const gchar
*title
, GError
** e
)
465 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
466 anjuta_msgman_set_view_title (ANJUTA_MSGMAN (msgman
),
467 MESSAGE_VIEW (message_view
), title
);
471 ianjuta_msgman_set_view_icon_from_stock (IAnjutaMessageManager
*plugin
,
472 IAnjutaMessageView
*message_view
,
473 const gchar
*icon
, GError
** e
)
475 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
476 anjuta_msgman_set_view_icon_from_stock (ANJUTA_MSGMAN (msgman
),
477 MESSAGE_VIEW (message_view
), icon
);
481 ianjuta_msgman_set_view_icon (IAnjutaMessageManager
*plugin
,
482 IAnjutaMessageView
*message_view
,
483 GdkPixbufAnimation
*icon
, GError
** e
)
485 GtkWidget
*msgman
= ANJUTA_PLUGIN_MESSAGE_VIEW (plugin
)->msgman
;
486 anjuta_msgman_set_view_icon (ANJUTA_MSGMAN (msgman
),
487 MESSAGE_VIEW (message_view
), icon
);
491 ianjuta_msgman_iface_init (IAnjutaMessageManagerIface
*iface
)
493 iface
->add_view
= ianjuta_msgman_add_view
;
494 iface
->remove_view
= ianjuta_msgman_remove_view
;
495 iface
->get_view_by_name
= ianjuta_msgman_get_view_by_name
;
496 iface
->get_current_view
= ianjuta_msgman_get_current_view
;
497 iface
->set_current_view
= ianjuta_msgman_set_current_view
;
498 iface
->get_all_views
= ianjuta_msgman_get_all_views
;
499 iface
->set_view_title
= ianjuta_msgman_set_view_title
;
500 iface
->set_view_icon
= ianjuta_msgman_set_view_icon
;
501 iface
->set_view_icon_from_stock
= ianjuta_msgman_set_view_icon_from_stock
;
505 ipreferences_merge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
507 GtkBuilder
*bxml
= gtk_builder_new ();
508 GError
* error
= NULL
;
509 MessageViewPlugin
* plugin
= ANJUTA_PLUGIN_MESSAGE_VIEW (ipref
);
510 /* Create the messages preferences page */
512 if (!gtk_builder_add_from_file (bxml
, PREFS_BUILDER
, &error
))
514 g_warning ("Couldn't load builder file: %s", error
->message
);
515 g_error_free (error
);
518 anjuta_preferences_add_from_builder (prefs
, bxml
, plugin
->settings
,
519 "Messages", _("Messages"),
520 ANJUTA_PIXMAP_MESSAGES
);
522 g_signal_connect (plugin
->settings
, "changed::messages-tab-position",
523 G_CALLBACK (on_notify_message_pref
), plugin
->msgman
);
524 g_object_unref (bxml
);
528 ipreferences_unmerge(IAnjutaPreferences
* ipref
, AnjutaPreferences
* prefs
, GError
** e
)
530 anjuta_preferences_remove_page(prefs
, _("Messages"));
534 ipreferences_iface_init(IAnjutaPreferencesIface
* iface
)
536 iface
->merge
= ipreferences_merge
;
537 iface
->unmerge
= ipreferences_unmerge
;
540 ANJUTA_PLUGIN_BEGIN (MessageViewPlugin
, message_view_plugin
);
541 ANJUTA_PLUGIN_ADD_INTERFACE(ianjuta_msgman
, IANJUTA_TYPE_MESSAGE_MANAGER
);
542 ANJUTA_PLUGIN_ADD_INTERFACE(ipreferences
, IANJUTA_TYPE_PREFERENCES
);
545 ANJUTA_SIMPLE_PLUGIN (MessageViewPlugin
, message_view_plugin
);