[anjuta] message-view: Moved buttons into tab header



commit 813843fe4d744ffd8cd0e1b637d22b7005fcff8c
Author: Johannes Schmid <jhs gnome org>
Date:   Mon Apr 19 22:11:31 2010 +0200

    message-view: Moved buttons into tab header
    
    Moved the buttons into the header and added the button text as tooltip. This should
    look better in general and saves a lots of space.
    
    Also clean up message-manager a bit as there were some strange code paths.

 libanjuta/anjuta-tabber.c            |    1 -
 plugins/message-view/anjuta-msgman.c |   53 ++--------
 plugins/message-view/anjuta-msgman.h |    2 +-
 plugins/message-view/message-view.c  |  180 ++++++++--------------------------
 plugins/message-view/message-view.h  |   12 +++
 plugins/message-view/plugin.c        |  137 +++++++++++++++++++++++++-
 plugins/message-view/plugin.h        |    6 +
 7 files changed, 208 insertions(+), 183 deletions(-)
---
diff --git a/libanjuta/anjuta-tabber.c b/libanjuta/anjuta-tabber.c
index 0753865..6ccadc2 100644
--- a/libanjuta/anjuta-tabber.c
+++ b/libanjuta/anjuta-tabber.c
@@ -321,7 +321,6 @@ anjuta_tabber_button_press_event (GtkWidget* widget, GdkEventButton* event)
 			{
 				gint page = g_list_position (tabber->priv->children, child);
 				gtk_notebook_set_current_page (tabber->priv->notebook, page);
-				g_message ("Switched to page %d!", page);
 				return TRUE;
 			}
 		}
diff --git a/plugins/message-view/anjuta-msgman.c b/plugins/message-view/anjuta-msgman.c
index 73011c9..254c4a3 100644
--- a/plugins/message-view/anjuta-msgman.c
+++ b/plugins/message-view/anjuta-msgman.c
@@ -33,7 +33,6 @@ struct _AnjutaMsgmanPriv
 	GList *views;
 
 	GtkWidget* tabber;
-	GtkWidget* hbox;
 	GSList* button_group;
 };
 
@@ -195,14 +194,7 @@ on_notebook_switch_page (GtkNotebook * notebook,
 			 GtkNotebookPage * npage,
 			 gint page_num, AnjutaMsgman * msgman)
 {
-	AnjutaMsgmanPage* page = anjuta_msgman_page_from_widget(msgman,
-	                                                        MESSAGE_VIEW (gtk_notebook_get_nth_page(GTK_NOTEBOOK(msgman), page_num)));
-	
-	g_return_if_fail (notebook != NULL);
-	g_return_if_fail (page != NULL);
-	g_return_if_fail (msgman != NULL);
-
-	anjuta_msgman_set_current_view(msgman, NULL);
+	g_signal_emit_by_name(G_OBJECT(msgman), "view_changed");
 }
 
 static gpointer parent_class;
@@ -229,18 +221,14 @@ anjuta_msgman_finalize (GObject *obj)
 static void
 anjuta_msgman_instance_init (AnjutaMsgman * msgman)
 {
-	g_signal_connect (GTK_NOTEBOOK (msgman), "switch-page",
+	g_signal_connect_after (GTK_NOTEBOOK (msgman), "switch-page",
 			  G_CALLBACK (on_notebook_switch_page), msgman);
 	gtk_notebook_set_scrollable (GTK_NOTEBOOK (msgman), TRUE);
 	msgman->priv = g_new0(AnjutaMsgmanPriv, 1);
 	msgman->priv->views = NULL;
 	msgman->priv->tab_popup = create_tab_popup_menu(msgman);
-	msgman->priv->hbox = gtk_hbox_new (FALSE, 0);
 	msgman->priv->tabber = anjuta_tabber_new (GTK_NOTEBOOK (msgman));
 	msgman->priv->button_group = NULL;
-
-	gtk_box_pack_end (GTK_BOX (msgman->priv->hbox), 
-	                  msgman->priv->tabber, TRUE, TRUE, 5);
 	
 	g_signal_connect(GTK_OBJECT(msgman), "popup-menu", 
                        G_CALLBACK(on_msgman_popup_menu), msgman);
@@ -331,25 +319,12 @@ on_message_view_destroy (MessageView *view, AnjutaMsgman *msgman)
 	g_signal_handlers_disconnect_by_func (G_OBJECT (view),
 					  G_CALLBACK (on_message_view_destroy), msgman);
 
-	g_signal_handlers_block_by_func (GTK_OBJECT (msgman),
-									 G_CALLBACK
-									 (on_notebook_switch_page), msgman);
-
 	page_num =
 		gtk_notebook_page_num (GTK_NOTEBOOK (msgman),
 						       GTK_WIDGET (view));
 	msgman->priv->views = g_list_remove (msgman->priv->views, page);
 	anjuta_msgman_page_destroy (page);
 
-	// gtk_notebook_remove_page (GTK_NOTEBOOK (msgman), page_num);
-	
-	/* This is called to set the next active document */
-	if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (msgman)) == 0)
-		anjuta_msgman_set_current_view (msgman, NULL);
-
-	g_signal_handlers_unblock_by_func (GTK_OBJECT (msgman),
-									   G_CALLBACK
-									   (on_notebook_switch_page), msgman);
 }
 
 static void
@@ -357,7 +332,6 @@ anjuta_msgman_append_view (AnjutaMsgman * msgman, GtkWidget *mv,
 						   const gchar * name, const gchar * pixmap)
 {
 	AnjutaMsgmanPage *page;
-	int page_num;
 
 	g_return_if_fail (msgman != NULL);
 	g_return_if_fail (mv != NULL);
@@ -369,13 +343,12 @@ anjuta_msgman_append_view (AnjutaMsgman * msgman, GtkWidget *mv,
 	msgman->priv->views =
 		g_list_prepend (msgman->priv->views, (gpointer) page);
 
-	page_num = gtk_notebook_append_page (GTK_NOTEBOOK (msgman), mv, NULL);
+	gtk_notebook_append_page (GTK_NOTEBOOK (msgman), mv, NULL);
 
 	anjuta_tabber_add_tab (ANJUTA_TABBER(msgman->priv->tabber), page->box);
 	
 	g_signal_connect (G_OBJECT (mv), "destroy",
 					  G_CALLBACK (on_message_view_destroy), msgman);
-	g_signal_emit_by_name(G_OBJECT(msgman), "view_changed");
 }
 
 MessageView *
@@ -415,9 +388,6 @@ anjuta_msgman_remove_all_views (AnjutaMsgman * msgman)
 	GList *views, *node;
 	AnjutaMsgmanPage *page;
 	
-	g_signal_handlers_block_by_func (GTK_OBJECT (msgman),
-									 G_CALLBACK
-									 (on_notebook_switch_page), msgman);
 	views = NULL;
 	node = msgman->priv->views;
 	while (node)
@@ -437,18 +407,16 @@ anjuta_msgman_remove_all_views (AnjutaMsgman * msgman)
 	g_list_free (views);
 	
 	msgman->priv->views = NULL;
-	anjuta_msgman_set_current_view (msgman, NULL);
-	g_signal_handlers_unblock_by_func (GTK_OBJECT (msgman),
-									   G_CALLBACK
-									   (on_notebook_switch_page), msgman);
 }
 
 MessageView *
 anjuta_msgman_get_current_view (AnjutaMsgman * msgman)
 {
-	gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(msgman));
-	return MESSAGE_VIEW (gtk_notebook_get_nth_page (GTK_NOTEBOOK(msgman),
-													current_page));
+	gint page = gtk_notebook_get_current_page (GTK_NOTEBOOK(msgman));
+	if (page != -1)
+		return MESSAGE_VIEW (gtk_notebook_get_nth_page (GTK_NOTEBOOK(msgman), page));
+	else
+		return NULL;
 }
 
 MessageView *
@@ -490,7 +458,6 @@ anjuta_msgman_set_current_view (AnjutaMsgman * msgman, MessageView * mv)
 					       GTK_WIDGET (mv));
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (msgman), page_num);
 	}
-	g_signal_emit_by_name(G_OBJECT(msgman), "view_changed");
 }
 
 GList *
@@ -589,7 +556,7 @@ anjuta_msgman_deserialize (AnjutaMsgman *msgman, AnjutaSerializer *serializer)
 	return TRUE;
 }
 
-GtkWidget* anjuta_msgman_get_hbox (AnjutaMsgman* msgman)
+GtkWidget* anjuta_msgman_get_tabber (AnjutaMsgman* msgman)
 {
-	return msgman->priv->hbox;
+	return msgman->priv->tabber;
 }
diff --git a/plugins/message-view/anjuta-msgman.h b/plugins/message-view/anjuta-msgman.h
index cdad12c..4f7fff2 100644
--- a/plugins/message-view/anjuta-msgman.h
+++ b/plugins/message-view/anjuta-msgman.h
@@ -79,7 +79,7 @@ gboolean anjuta_msgman_serialize (AnjutaMsgman *msgman,
 gboolean anjuta_msgman_deserialize (AnjutaMsgman *msgman,
 									AnjutaSerializer *serializer);
 
-GtkWidget* anjuta_msgman_get_hbox (AnjutaMsgman* msgman);
+GtkWidget* anjuta_msgman_get_tabber (AnjutaMsgman* msgman);
 
 void
 on_notify_message_pref (AnjutaPreferences* prefs, const gchar* key,
diff --git a/plugins/message-view/message-view.c b/plugins/message-view/message-view.c
index 5047347..733aa00 100644
--- a/plugins/message-view/message-view.c
+++ b/plugins/message-view/message-view.c
@@ -22,7 +22,7 @@
 
 #include "message-view.h"
 #define MESSAGE_TYPE message_get_type()
-
+	
 struct _MessageViewPrivate
 {
 	//guint num_messages;
@@ -36,10 +36,13 @@ struct _MessageViewPrivate
 	
 	gint adj_chgd_hdlr;
 	
-	/* Messages filter buttons */
-	GtkWidget *normal, *info, *warn, *error;
-	guint normal_count, info_count, warn_count, error_count;
-
+	/* Messages filter */
+	MessageViewFlags flags;
+	gint normal_count;
+	gint warn_count;
+	gint error_count;
+	gint info_count;
+	
 	/* Properties */
 	gchar *label;
 	gchar *pixmap;
@@ -324,14 +327,6 @@ on_message_event (GObject* object, GdkEvent* event, gpointer data)
 	return FALSE;
 }
 
-static void
-on_filter_buttons_toggled (GtkToggleButton *toggle, gpointer user_data) 
-{
-	MessageView *msgview = MESSAGE_VIEW (user_data);
-	
-	gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (msgview->privat->filter));
-}
-
 static void 
 on_adjustment_changed (GtkAdjustment* adj, gpointer data)
 {
@@ -463,8 +458,6 @@ message_view_finalize (GObject *obj)
 static void
 message_view_instance_init (MessageView * self)
 {
-	GtkWidget *vbox;
-	GtkWidget *filter_buttons_box;
 	GtkWidget *scrolled_win;
 	GtkCellRenderer *renderer;
 	GtkCellRenderer *renderer_pixbuf;
@@ -479,72 +472,7 @@ message_view_instance_init (MessageView * self)
 
 	/* Init private data */
 	self->privat->line_buffer = g_strdup("");
-	self->privat->normal_count = 0;
-	self->privat->info_count = 0;
-	self->privat->warn_count = 0;
-	self->privat->error_count = 0;
-
-	/* Create filter buttons */
-	vbox = gtk_hbox_new (FALSE, 0);
-	filter_buttons_box = gtk_vbox_new (FALSE, 1);
-	
-	self->privat->normal = gtk_toggle_button_new_with_label (_("No Messages"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->privat->normal), TRUE);
-	gtk_button_set_focus_on_click (GTK_BUTTON (self->privat->normal), FALSE);
-	gtk_button_set_relief (GTK_BUTTON (self->privat->normal), GTK_RELIEF_HALF);
-	gtk_button_set_alignment (GTK_BUTTON (self->privat->normal), 0.0, 0.5);
-	gtk_widget_show (self->privat->normal);
-	g_signal_connect (G_OBJECT (self->privat->normal), "toggled",
-					  G_CALLBACK (on_filter_buttons_toggled), self);
-	
-	self->privat->info = gtk_toggle_button_new_with_label (_("No Infos"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->privat->info), TRUE);
-	gtk_button_set_focus_on_click (GTK_BUTTON (self->privat->info), FALSE);
-	gtk_button_set_relief (GTK_BUTTON (self->privat->info), GTK_RELIEF_HALF);
-	gtk_button_set_alignment (GTK_BUTTON (self->privat->info), 0.0, 0.5);
-	gtk_button_set_image (GTK_BUTTON (self->privat->info), 
-						  gtk_image_new_from_stock (GTK_STOCK_INFO, 
-													GTK_ICON_SIZE_BUTTON));
-	gtk_widget_show (self->privat->info);
-	g_signal_connect (G_OBJECT (self->privat->info), "toggled",
-					  G_CALLBACK (on_filter_buttons_toggled), self);
-	
-	self->privat->warn = gtk_toggle_button_new_with_label (_("No Warnings"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->privat->warn), TRUE);
-	gtk_button_set_focus_on_click (GTK_BUTTON (self->privat->warn), FALSE);
-	gtk_button_set_relief (GTK_BUTTON (self->privat->warn), GTK_RELIEF_HALF);
-	gtk_button_set_alignment (GTK_BUTTON (self->privat->warn), 0.0, 0.5);
-	/* FIXME: There is not GTK_STOCK_DIALOG_WARNING. */
-	gtk_button_set_image (GTK_BUTTON (self->privat->warn), 
-						  gtk_image_new_from_stock (GTK_STOCK_DIALOG_WARNING, 
-													GTK_ICON_SIZE_BUTTON));
-	gtk_widget_show (self->privat->warn);
-	g_signal_connect (G_OBJECT (self->privat->warn), "toggled",
-					  G_CALLBACK (on_filter_buttons_toggled), self);
-	
-	self->privat->error = gtk_toggle_button_new_with_label (_("No Errors"));
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (self->privat->error), TRUE);
-	gtk_button_set_focus_on_click (GTK_BUTTON (self->privat->error), FALSE);
-	gtk_button_set_relief (GTK_BUTTON (self->privat->error), GTK_RELIEF_HALF);
-	gtk_button_set_alignment (GTK_BUTTON (self->privat->error), 0.0, 0.5);
-	gtk_button_set_image (GTK_BUTTON (self->privat->error), 
-						  gtk_image_new_from_stock (GTK_STOCK_STOP, 
-													GTK_ICON_SIZE_BUTTON));
-	gtk_widget_show (self->privat->error);
-	g_signal_connect (G_OBJECT (self->privat->error), "toggled",
-					  G_CALLBACK (on_filter_buttons_toggled), self);
-	
-	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (self->privat->normal),
-						FALSE, FALSE, 0);
-	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (self->privat->info),
-						FALSE, FALSE, 0);
-	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (self->privat->warn),
-						FALSE, FALSE, 0);
-	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (self->privat->error),
-						FALSE, FALSE, 0);
-	
-	gtk_widget_show (filter_buttons_box);
-	
+	self->privat->flags = 0xF;
 	
 	/* Create the tree widget */
 	model = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING,
@@ -608,22 +536,8 @@ message_view_instance_init (MessageView * self)
 									 G_CALLBACK (on_adjustment_changed), self);
 	g_signal_connect(G_OBJECT(adj), "value_changed",
 					 G_CALLBACK(on_adjustment_value_changed), self);
-
-	/* Add it to the dockitem */
-	if (gtk_widget_get_default_direction () == GTK_TEXT_DIR_LTR) {
-		gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (scrolled_win),
-							TRUE, TRUE, 0);
-		gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (filter_buttons_box),
-							FALSE, FALSE, 0);
-	} else {
-		gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (filter_buttons_box),
-							FALSE, FALSE, 0);
-		gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (scrolled_win),
-							TRUE, TRUE, 0);
-	}
 	
-	gtk_widget_show (vbox);
-	gtk_container_add (GTK_CONTAINER (self), vbox);
+	gtk_container_add (GTK_CONTAINER (self), scrolled_win);
 	
 	/* Connect signals */
 	g_signal_connect (G_OBJECT(self->privat->tree_view), "event", 
@@ -1092,36 +1006,6 @@ imessage_view_buffer_append (IAnjutaMessageView * message_view,
 	}
 }
 
-static void 
-update_button_labels (MessageView* view)
-{
-	gchar* temp;
-	
-	temp = g_strdup_printf(ngettext ("%d Message", "%d Messages", 
-									 view->privat->normal_count),
-						   view->privat->normal_count);
-	gtk_button_set_label (GTK_BUTTON (view->privat->normal), temp);
-	g_free(temp);
-	
-	temp = g_strdup_printf(ngettext ("%d Info", "%d Infos", 
-									 view->privat->info_count),
-						   view->privat->info_count);
-	gtk_button_set_label (GTK_BUTTON (view->privat->info), temp);
-	g_free (temp);
-	temp = g_strdup_printf(ngettext ("%d Warning", "%d Warnings", 
-									 view->privat->warn_count),
-						   view->privat->warn_count);	
-	gtk_button_set_label (GTK_BUTTON (view->privat->warn), temp);
-	g_free (temp);
-	temp = g_strdup_printf(ngettext ("%d Error", "%d Errors", 
-									 view->privat->error_count),
-						   view->privat->error_count);	
-	gtk_button_set_label (GTK_BUTTON (view->privat->error), temp);
-	g_free (temp);
-	
-}
-
-
 static void
 imessage_view_append (IAnjutaMessageView *message_view,
 					  IAnjutaMessageViewType type,
@@ -1174,7 +1058,6 @@ imessage_view_append (IAnjutaMessageView *message_view,
 				view->privat->normal_count++;
 		}
 	}
-	update_button_labels (view);
 	
 	/* Add the message to the tree */
 	store = GTK_LIST_STORE (view->privat->model);
@@ -1230,12 +1113,6 @@ imessage_view_clear (IAnjutaMessageView *message_view, GError **e)
 	view->privat->info_count = 0;
 	view->privat->warn_count = 0;
 	view->privat->error_count = 0;
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (view->privat->normal), TRUE);
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (view->privat->info), TRUE);
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (view->privat->warn), TRUE);
-	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (view->privat->error), TRUE);
-	
-	update_button_labels (view);
 	
 	store = GTK_LIST_STORE (view->privat->model);
 	gtk_list_store_clear (store);
@@ -1365,17 +1242,46 @@ message_view_tree_view_filter (GtkTreeModel *model, GtkTreeIter  *iter,
 
 	if (msg != NULL) {
 		if (msg->type == IANJUTA_MESSAGE_VIEW_TYPE_NORMAL) {
-			return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (msgview->privat->normal));
+			return msgview->privat->flags & MESSAGE_VIEW_SHOW_NORMAL;
 		} else if (msg->type == IANJUTA_MESSAGE_VIEW_TYPE_INFO) {
-			return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (msgview->privat->info));
+			return msgview->privat->flags & MESSAGE_VIEW_SHOW_INFO;
 		} else if (msg->type == IANJUTA_MESSAGE_VIEW_TYPE_WARNING) {
-			return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (msgview->privat->warn));
+			return msgview->privat->flags & MESSAGE_VIEW_SHOW_WARNING;
 		} else if (msg->type == IANJUTA_MESSAGE_VIEW_TYPE_ERROR) {
-			return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (msgview->privat->error));
+			return msgview->privat->flags & MESSAGE_VIEW_SHOW_ERROR;
 		} else return TRUE;
 	} else return FALSE;
 }
 
+MessageViewFlags
+message_view_get_flags (MessageView* view)
+{
+	return view->privat->flags;
+}
+
+void message_view_set_flags (MessageView* view, MessageViewFlags flags)
+{
+	view->privat->flags = flags;
+	gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(view->privat->filter));
+}
+
+gint message_view_get_count (MessageView* view, MessageViewFlags flags)
+{
+	switch (flags)
+	{
+		case MESSAGE_VIEW_SHOW_NORMAL:
+			return view->privat->normal_count;
+		case MESSAGE_VIEW_SHOW_INFO:
+			return view->privat->info_count;
+		case MESSAGE_VIEW_SHOW_WARNING:
+			return view->privat->warn_count;
+		case MESSAGE_VIEW_SHOW_ERROR:
+			return view->privat->error_count;
+		default:
+			g_assert_not_reached ();
+	}
+}
+
 ANJUTA_TYPE_BEGIN(MessageView, message_view, GTK_TYPE_HBOX);
 ANJUTA_TYPE_ADD_INTERFACE(imessage_view, IANJUTA_TYPE_MESSAGE_VIEW);
 ANJUTA_TYPE_END;
diff --git a/plugins/message-view/message-view.h b/plugins/message-view/message-view.h
index e4f772d..7287139 100644
--- a/plugins/message-view/message-view.h
+++ b/plugins/message-view/message-view.h
@@ -59,6 +59,14 @@ struct _MessageViewClass
 	GtkHBoxClass parent;
 };	
 
+typedef enum
+{
+	MESSAGE_VIEW_SHOW_NORMAL = 1 << 0,
+	MESSAGE_VIEW_SHOW_INFO = 1 << 1,
+	MESSAGE_VIEW_SHOW_WARNING = 1 << 2,
+	MESSAGE_VIEW_SHOW_ERROR = 1 << 3,	
+} MessageViewFlags;
+
 /* Note: MessageView implements IAnjutaMessageView interface */
 GType message_view_get_type (void);
 GtkWidget* message_view_new (GtkWidget* popup_menu);
@@ -72,6 +80,10 @@ gboolean message_view_serialize (MessageView *view,
 gboolean message_view_deserialize (MessageView *view,
 								   AnjutaSerializer *serializer);
 
+MessageViewFlags message_view_get_flags (MessageView* view);
+void message_view_set_flags (MessageView* view, MessageViewFlags flags);
+gint message_view_get_count (MessageView* view, MessageViewFlags flags);
+
 G_END_DECLS
 
 #endif
diff --git a/plugins/message-view/plugin.c b/plugins/message-view/plugin.c
index f557f34..43d10c1 100644
--- a/plugins/message-view/plugin.c
+++ b/plugins/message-view/plugin.c
@@ -94,6 +94,7 @@ static GtkActionEntry actions_goto[] = {
 
 static void on_view_changed(AnjutaMsgman* msgman, MessageViewPlugin* plugin)
 {
+	MessageView* view = anjuta_msgman_get_current_view (msgman);
 	AnjutaUI* ui = anjuta_shell_get_ui (ANJUTA_PLUGIN(plugin)->shell, NULL);
 	GtkAction* action_next = anjuta_ui_get_action (ui, "ActionGroupGotoMessages",
 								   "ActionMessageNext");
@@ -108,6 +109,21 @@ static void on_view_changed(AnjutaMsgman* msgman, MessageViewPlugin* plugin)
 	g_object_set (G_OBJECT (action_next), "sensitive", sensitive, NULL);
 	g_object_set (G_OBJECT (action_prev), "sensitive", sensitive, NULL);
 	g_object_set (G_OBJECT (action_copy), "sensitive", sensitive, NULL);
+
+	/* Toggle buttons */
+	gtk_widget_set_sensitive (plugin->normal, view != NULL);	
+	gtk_widget_set_sensitive (plugin->info, view != NULL);
+	gtk_widget_set_sensitive (plugin->warn, view != NULL);
+	gtk_widget_set_sensitive (plugin->error, view != NULL);
+	if (view)
+	{
+		MessageViewFlags flags =
+			message_view_get_flags (view);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin->normal), flags & MESSAGE_VIEW_SHOW_NORMAL);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin->info), flags & MESSAGE_VIEW_SHOW_INFO);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin->warn), flags & MESSAGE_VIEW_SHOW_WARNING);
+		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(plugin->error), flags & MESSAGE_VIEW_SHOW_ERROR);
+	}	
 }
 
 static gpointer parent_class;
@@ -308,6 +324,120 @@ message_view_plugin_class_init (GObjectClass *klass)
 	klass->finalize = message_view_plugin_finalize;
 }
 
+static gboolean
+on_filter_button_tooltip (GtkWidget* widget, 
+                          gint        x,
+                          gint        y,
+                          gboolean    keyboard_mode,
+                          GtkTooltip *tooltip,
+                          MessageViewPlugin* plugin)
+{
+	gchar* temp = NULL;
+	MessageView* view = anjuta_msgman_get_current_view (ANJUTA_MSGMAN(plugin->msgman));
+	if (view)
+		return FALSE;
+	if (widget == plugin->normal)
+	{
+		temp = g_strdup_printf(ngettext ("%d Message", "%d Messages", 
+		                                 message_view_get_count (view,
+		                                                         MESSAGE_VIEW_SHOW_NORMAL)),
+		                       message_view_get_count (view,
+		                                               MESSAGE_VIEW_SHOW_NORMAL));
+		gtk_tooltip_set_text (tooltip, temp);
+	}
+	else if (widget == plugin->info)
+	{
+		temp = g_strdup_printf(ngettext ("%d Info", "%d Infos", 
+		                                 message_view_get_count (view,
+		                                                         MESSAGE_VIEW_SHOW_INFO)),
+		                       message_view_get_count (view,
+		                                               MESSAGE_VIEW_SHOW_INFO));
+		gtk_tooltip_set_text (tooltip, temp);
+	}
+	else if (widget == plugin->warn)
+	{
+		temp = g_strdup_printf(ngettext ("%d Warning", "%d Warnings", 
+		                                 message_view_get_count (view,
+		                                                         MESSAGE_VIEW_SHOW_WARNING)),
+		                       message_view_get_count (view,
+		                                               MESSAGE_VIEW_SHOW_WARNING));
+		gtk_tooltip_set_text (tooltip, temp);
+	}
+	else if (widget == plugin->error)
+	{
+		temp = g_strdup_printf(ngettext ("%d Error", "%d Errors", 
+		                                 message_view_get_count (view,
+		                                                         MESSAGE_VIEW_SHOW_ERROR)),
+		                       message_view_get_count (view,
+		                                               MESSAGE_VIEW_SHOW_ERROR));
+		gtk_tooltip_set_text (tooltip, temp);
+	}
+	else
+		g_assert_not_reached ();
+
+	return TRUE;
+}
+
+static void
+on_filter_buttons_toggled (GtkWidget* button, MessageViewPlugin *plugin)
+{
+	MessageViewFlags flags = 0;
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin->normal)))
+		flags |= MESSAGE_VIEW_SHOW_NORMAL;
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin->info)))
+		flags |= MESSAGE_VIEW_SHOW_INFO;
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin->warn)))
+		flags |= MESSAGE_VIEW_SHOW_WARNING;
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(plugin->error)))
+		flags |= MESSAGE_VIEW_SHOW_ERROR;
+	message_view_set_flags (anjuta_msgman_get_current_view (ANJUTA_MSGMAN(plugin->msgman)),
+	                        flags);
+}
+
+static GtkWidget*
+create_mini_button (MessageViewPlugin* plugin, const gchar* stock_id)
+{
+	GtkWidget* button, *image;
+	gint h,w;
+	image = gtk_image_new_from_stock (stock_id, 
+	                                  GTK_ICON_SIZE_MENU);
+	gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
+	button = gtk_toggle_button_new ();
+	g_signal_connect (G_OBJECT (button), "toggled",
+					  G_CALLBACK (on_filter_buttons_toggled), plugin);
+	gtk_container_add (GTK_CONTAINER (button), image);
+
+	g_object_set (button, "has-tooltip", TRUE, NULL);
+	g_signal_connect (button, "query-tooltip", 
+	                  G_CALLBACK (on_filter_button_tooltip), plugin);
+	
+	return button;
+}
+
+static void
+create_toggle_buttons (MessageViewPlugin* plugin,
+                       GtkWidget* hbox)
+{
+	GtkWidget* filter_buttons_box = gtk_hbox_new (FALSE, 0);
+	
+	plugin->normal = create_mini_button (plugin, "message-manager-plugin-icon");
+	plugin->info = create_mini_button (plugin, GTK_STOCK_INFO);
+	plugin->warn = create_mini_button (plugin, GTK_STOCK_DIALOG_WARNING);
+	plugin->error = create_mini_button (plugin, GTK_STOCK_DIALOG_ERROR);
+	
+	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (plugin->normal),
+						FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (plugin->info),
+						FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (plugin->warn),
+						FALSE, FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (filter_buttons_box), GTK_WIDGET (plugin->error),
+	                    FALSE, FALSE, 0);
+	
+	gtk_widget_show_all (filter_buttons_box);
+	gtk_box_pack_start (GTK_BOX(hbox), filter_buttons_box, FALSE, FALSE, 0);
+}
+
 /*
  * IAnjutaMessagerManager interface implementation 
  */
@@ -321,13 +451,18 @@ ianjuta_msgman_add_view (IAnjutaMessageManager *plugin,
 	GtkWidget *msgman = ANJUTA_PLUGIN_MESSAGE_VIEW (plugin)->msgman;
 	if (ANJUTA_PLUGIN_MESSAGE_VIEW (plugin)->widget_shown == FALSE)
 	{
+		GtkWidget* hbox = gtk_hbox_new (FALSE, 0);
 		GtkWidget* label = gtk_label_new (_("Messages"));
 		GtkWidget* image = gtk_image_new_from_stock ("message-manager-plugin-icon",
 		                                            GTK_ICON_SIZE_MENU);
-		GtkWidget* hbox = anjuta_msgman_get_hbox (ANJUTA_MSGMAN(msgman));
 		gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
 		gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+		gtk_box_pack_start (GTK_BOX(hbox), anjuta_msgman_get_tabber (ANJUTA_MSGMAN(msgman)),
+		                    TRUE, TRUE, 5);
+	
 		gtk_widget_show_all (hbox);
+
+		create_toggle_buttons (ANJUTA_PLUGIN_MESSAGE_VIEW(plugin), hbox);
 		
 		anjuta_shell_add_widget_custom (shell, msgman,
 							 "AnjutaMessageView", _("Messages"),
diff --git a/plugins/message-view/plugin.h b/plugins/message-view/plugin.h
index 0503bc0..40accd8 100644
--- a/plugins/message-view/plugin.h
+++ b/plugins/message-view/plugin.h
@@ -36,6 +36,12 @@ struct _MessageViewPlugin {
 	GtkWidget* msgman;
 	GtkActionGroup *action_group;
 	gint uiid;
+
+	/* Toggle buttons */
+	GtkWidget* normal;
+	GtkWidget* warn;
+	GtkWidget* error;
+	GtkWidget* info;
 	
 	gboolean widget_shown;
 };



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]