[anjuta] message-view: Show/hide buttons of the message-view correctly
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] message-view: Show/hide buttons of the message-view correctly
- Date: Wed, 23 Feb 2011 16:09:04 +0000 (UTC)
commit 6a669201135648173665bd6d13299f2308e07460
Author: Johannes Schmid <jhs gnome org>
Date: Wed Feb 23 17:07:19 2011 +0100
message-view: Show/hide buttons of the message-view correctly
This should fix rh#679350
plugins/message-view/anjuta-msgman.c | 50 ++++++++++++++++++++++++++++++---
plugins/message-view/anjuta-msgman.h | 7 +++--
plugins/message-view/message-view.c | 27 ++++++++++++++++--
plugins/message-view/plugin.c | 25 +++++++++--------
4 files changed, 86 insertions(+), 23 deletions(-)
---
diff --git a/plugins/message-view/anjuta-msgman.c b/plugins/message-view/anjuta-msgman.c
index c7ff675..e2b1ca0 100644
--- a/plugins/message-view/anjuta-msgman.c
+++ b/plugins/message-view/anjuta-msgman.c
@@ -46,6 +46,14 @@ struct _AnjutaMsgmanPage
GtkWidget *close_icon;
};
+enum
+{
+ VIEW_CHANGED,
+ LAST_SIGNAL
+};
+
+guint msgman_signal[LAST_SIGNAL];
+
typedef struct _AnjutaMsgmanPage AnjutaMsgmanPage;
static void
@@ -227,13 +235,43 @@ anjuta_msgman_instance_init (AnjutaMsgman * msgman)
}
static void
+anjuta_msgman_switch_page (GtkNotebook* notebook,
+ GtkWidget* page,
+ guint page_num)
+{
+ GTK_NOTEBOOK_CLASS (parent_class)->switch_page (notebook, page, page_num);
+
+ g_signal_emit_by_name (ANJUTA_MSGMAN (notebook),
+ "view-changed");
+}
+
+static void
anjuta_msgman_class_init (AnjutaMsgmanClass * klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+ GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
parent_class = g_type_class_peek_parent (klass);
gobject_class->finalize = anjuta_msgman_finalize;
gobject_class->dispose = anjuta_msgman_dispose;
+
+ notebook_class->switch_page = anjuta_msgman_switch_page;
+
+ /**
+ * AnjutaMsgMan::view-changed:
+ * @msgman: #AnjutaMsgMan
+ *
+ * Emitted when the current view changes
+ */
+
+ msgman_signal[VIEW_CHANGED] = g_signal_new ("view-changed",
+ G_OBJECT_CLASS_TYPE (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (AnjutaMsgmanClass, view_changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
}
static void
@@ -318,6 +356,8 @@ anjuta_msgman_append_view (AnjutaMsgman * msgman, GtkWidget *mv,
gtk_notebook_append_page (GTK_NOTEBOOK (msgman), mv, NULL);
+ g_signal_emit_by_name (msgman, "view-changed");
+
anjuta_tabber_add_tab (ANJUTA_TABBER(msgman->priv->tabber), page->box);
g_signal_connect (G_OBJECT (mv), "destroy",
@@ -342,17 +382,15 @@ anjuta_msgman_add_view (AnjutaMsgman * msgman,
}
void
-anjuta_msgman_remove_view (AnjutaMsgman * msgman, MessageView *passed_view)
+anjuta_msgman_remove_view (AnjutaMsgman * msgman, MessageView *view)
{
- MessageView *view;
-
- view = passed_view;
if (!view)
view = anjuta_msgman_get_current_view (msgman);
g_return_if_fail (view != NULL);
gtk_widget_destroy (GTK_WIDGET (view));
- anjuta_msgman_set_current_view(msgman, NULL);
+
+ g_signal_emit_by_name (msgman, "view-changed");
}
void
@@ -378,6 +416,8 @@ anjuta_msgman_remove_all_views (AnjutaMsgman * msgman)
g_list_free (msgman->priv->views);
g_list_free (views);
+
+ g_signal_emit_by_name (msgman, "view-changed");
msgman->priv->views = NULL;
}
diff --git a/plugins/message-view/anjuta-msgman.h b/plugins/message-view/anjuta-msgman.h
index 143749d..c283486 100644
--- a/plugins/message-view/anjuta-msgman.h
+++ b/plugins/message-view/anjuta-msgman.h
@@ -37,15 +37,16 @@ typedef struct _AnjutaMsgmanClass AnjutaMsgmanClass;
struct _AnjutaMsgman
{
GtkNotebook parent;
+
AnjutaMsgmanPriv *priv;
-
- /* Signal */
- void (*view_changed) (AnjutaMsgman *obj);
};
struct _AnjutaMsgmanClass
{
GtkNotebookClass parent_class;
+
+ /* Signal */
+ void (*view_changed) (AnjutaMsgman *obj);
};
GType anjuta_msgman_get_type (void);
diff --git a/plugins/message-view/message-view.c b/plugins/message-view/message-view.c
index 0c0a8ce..1028359 100644
--- a/plugins/message-view/message-view.c
+++ b/plugins/message-view/message-view.c
@@ -609,6 +609,8 @@ message_view_serialize (MessageView *view, AnjutaSerializer *serializer)
{
GtkTreeModel *model;
GtkTreeIter iter;
+
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
if (!anjuta_serializer_write_string (serializer, "label",
view->privat->label))
@@ -649,6 +651,8 @@ message_view_deserialize (MessageView *view, AnjutaSerializer *serializer)
{
GtkTreeModel *model;
gint messages, i;
+
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
if (!anjuta_serializer_read_string (serializer, "label",
&view->privat->label, TRUE))
@@ -690,6 +694,8 @@ void message_view_next(MessageView* view)
GtkTreeModel *model;
GtkTreeSelection *select;
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
model = view->privat->model;
select = gtk_tree_view_get_selection (GTK_TREE_VIEW
(view->privat->tree_view));
@@ -734,6 +740,8 @@ void message_view_previous(MessageView* view)
GtkTreeSelection *select;
GtkTreePath *path;
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
model = view->privat->model;
select = gtk_tree_view_get_selection (GTK_TREE_VIEW
(view->privat->tree_view));
@@ -786,7 +794,10 @@ static gboolean message_view_save_as(MessageView* view, gchar* uri)
GtkTreeModel *model;
gboolean ok;
- if (uri == NULL) return FALSE;
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
+ if (uri == NULL)
+ return FALSE;
file = g_file_new_for_uri (uri);
os = G_OUTPUT_STREAM (
@@ -845,8 +856,10 @@ void message_view_save(MessageView* view)
{
GtkWindow* parent;
gchar* uri;
-
- parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
+
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
+ parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view)));
uri = ask_user_for_save_uri (parent);
if (uri)
@@ -865,6 +878,8 @@ void message_view_copy(MessageView* view)
GtkTreeModel *model;
GtkTreeSelection *select;
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
model = view->privat->model;
select = gtk_tree_view_get_selection (GTK_TREE_VIEW
(view->privat->tree_view));
@@ -1241,17 +1256,23 @@ message_view_tree_view_filter (GtkTreeModel *model, GtkTreeIter *iter,
MessageViewFlags
message_view_get_flags (MessageView* view)
{
+ g_return_val_if_fail (view != NULL && MESSAGE_IS_VIEW (view), MESSAGE_VIEW_SHOW_NORMAL);
+
return view->privat->flags;
}
void message_view_set_flags (MessageView* view, MessageViewFlags flags)
{
+ g_return_if_fail (view != NULL && MESSAGE_IS_VIEW (view));
+
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)
{
+ g_return_val_if_fail (view != NULL && MESSAGE_IS_VIEW (view), 0);
+
switch (flags)
{
case MESSAGE_VIEW_SHOW_NORMAL:
diff --git a/plugins/message-view/plugin.c b/plugins/message-view/plugin.c
index 745ba49..be4d2a5 100644
--- a/plugins/message-view/plugin.c
+++ b/plugins/message-view/plugin.c
@@ -93,8 +93,7 @@ static GtkActionEntry actions_goto[] = {
G_CALLBACK (on_save_message)}
};
-static void on_view_changed(AnjutaMsgman* msgman, GtkWidget* page,
- gint page_num, MessageViewPlugin* plugin)
+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);
@@ -104,7 +103,7 @@ static void on_view_changed(AnjutaMsgman* msgman, GtkWidget* page,
"ActionMessagePrev");
GtkAction* action_copy = anjuta_ui_get_action (ui, "ActionGroupGotoMessages",
"ActionMessageCopy");
- gboolean sensitive = (anjuta_msgman_get_current_view(msgman) != NULL);
+ gboolean sensitive = (view != NULL);
if (sensitive)
anjuta_shell_present_widget (ANJUTA_PLUGIN (plugin)->shell,
GTK_WIDGET(msgman), NULL);
@@ -113,19 +112,19 @@ static void on_view_changed(AnjutaMsgman* msgman, GtkWidget* page,
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);
+ gtk_widget_set_sensitive (plugin->normal, sensitive);
+ gtk_widget_set_sensitive (plugin->info, sensitive);
+ gtk_widget_set_sensitive (plugin->warn, sensitive);
+ gtk_widget_set_sensitive (plugin->error, sensitive);
if (view)
{
MessageViewFlags flags =
- message_view_get_flags (view);
+ 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;
@@ -174,7 +173,7 @@ activate_plugin (AnjutaPlugin *plugin)
popup = gtk_ui_manager_get_widget (GTK_UI_MANAGER (ui), "/PopupMessageView");
mv_plugin->msgman =
anjuta_msgman_new(popup);
- g_signal_connect(mv_plugin->msgman, "switch-page",
+ g_signal_connect(mv_plugin->msgman, "view-changed",
G_CALLBACK(on_view_changed), mv_plugin);
GtkAction* action_next = anjuta_ui_get_action (ui, "ActionGroupGotoMessages",
"ActionMessageNext");
@@ -312,6 +311,7 @@ static void
on_filter_buttons_toggled (GtkWidget* button, MessageViewPlugin *plugin)
{
MessageViewFlags flags = 0;
+ MessageView* view = anjuta_msgman_get_current_view (ANJUTA_MSGMAN(plugin->msgman));
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)))
@@ -320,8 +320,9 @@ on_filter_buttons_toggled (GtkWidget* button, MessageViewPlugin *plugin)
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);
+ if (view)
+ message_view_set_flags (view,
+ flags);
}
static GtkWidget*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]