From 4d0f7706aebe3f1a3fd8623fc819ea637e6ef6b7 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Tue, 8 Aug 2006 22:10:24 +0000 Subject: Attach/detach buttons in main toolbar are only active when meaningful. E.g., if all windows are detached, no 'detach' button appears. git-archimport-id: mdk@sv.gnu.org/mdk--devel--1--patch-35 --- mixgtk/mixgtk.glade | 2 +- mixgtk/mixgtk_widgets.c | 1 + mixgtk/mixgtk_widgets.h | 1 + mixgtk/mixgtk_wm.c | 40 ++++++++++++++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 3 deletions(-) diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index 8664f96..1de46eb 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -798,7 +798,7 @@ - + True Detach window Detach diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index ee6dc69..98e335c 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -49,6 +49,7 @@ static const gchar * dnames_[] = { static const gchar *names_[] = { "main_statusbar", "attach_button", + "detach_button", "main_notebook", "mixvm_widget", "mixvm_container", diff --git a/mixgtk/mixgtk_widgets.h b/mixgtk/mixgtk_widgets.h index d34f819..f89d8e1 100644 --- a/mixgtk/mixgtk_widgets.h +++ b/mixgtk/mixgtk_widgets.h @@ -47,6 +47,7 @@ typedef enum { typedef enum { MIXGTK_WIDGET_STATUSBAR, MIXGTK_WIDGET_ATTACH_BUTTON, + MIXGTK_WIDGET_DETACH_BUTTON, MIXGTK_WIDGET_NOTEBOOK, /* the notebook */ MIXGTK_WIDGET_MIXVM, /* virtual machine */ MIXGTK_WIDGET_MIXVM_CONTAINER, diff --git a/mixgtk/mixgtk_wm.c b/mixgtk/mixgtk_wm.c index 59f3a7d..6bf691e 100644 --- a/mixgtk/mixgtk_wm.c +++ b/mixgtk/mixgtk_wm.c @@ -23,7 +23,6 @@ #include "mixgtk_wm.h" -#include "mixgtk_widgets.h" #include "mixgtk_config.h" #include "mixgtk_device.h" #include "mixgtk_mixvm.h" @@ -53,6 +52,9 @@ static GtkContainer *mixvm_container_ = NULL; static GtkContainer *mixal_container_ = NULL; static GtkContainer *dev_container_ = NULL; +static GtkToolItem *attach_button_ = NULL; +static GtkToolItem *detach_button_ = NULL; + static const gchar *TB_MENU_NAME_ = "show_toolbars"; static GtkCheckMenuItem *tb_menu_ = NULL; static GtkNotebook *notebook_ = NULL; @@ -78,6 +80,7 @@ static void mixal_attach_ (void); static void mixal_detach_ (void); static void dev_attach_ (void); static void dev_detach_ (void); +static void update_attach_buttons_ (void); static void on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, guint page_num, gpointer user_data); @@ -104,6 +107,7 @@ mixgtk_wm_init (void) init_mixvm_ (); init_mixal_ (); init_dev_ (); + init_tb_ (); for (k = 0; k < INF_NO_; ++k) { @@ -113,7 +117,6 @@ mixgtk_wm_init (void) mixgtk_wm_attach_window (k); } - init_tb_ (); init_about_ (); init_autosave_ (); init_visibility_ (); @@ -135,6 +138,7 @@ mixgtk_wm_detach_window (mixgtk_window_id_t w) if (gtk_notebook_get_n_pages (notebook_) < 1) gtk_widget_hide (GTK_WIDGET (notebook_)); gtk_widget_show (mixgtk_widget_factory_get_dialog (infos_[w].dialog)); + update_attach_buttons_ (); } } @@ -154,6 +158,7 @@ mixgtk_wm_attach_window (mixgtk_window_id_t w) mixgtk_config_update (infos_[w].config_key, DETACH_NO_); if (gtk_notebook_get_n_pages (notebook_) == 1) gtk_widget_show (GTK_WIDGET (notebook_)); + update_attach_buttons_ (); } } @@ -443,6 +448,14 @@ init_tb_ (void) g_signal_connect (G_OBJECT (tb_menu_), "toggled", G_CALLBACK (on_show_toolbars_toggled), NULL); + + attach_button_ = GTK_TOOL_ITEM + (mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_ATTACH_BUTTON)); + detach_button_ = GTK_TOOL_ITEM + (mixgtk_widget_factory_get (MIXGTK_MAIN, MIXGTK_WIDGET_DETACH_BUTTON)); + + g_assert (attach_button_); + g_assert (detach_button_); } static void @@ -575,4 +588,27 @@ on_nb_switch_ (GtkNotebook *notebook, GtkWidget *page, mixgtk_mixal_pop_status (); } +static void +update_attach_buttons_ (void) +{ + gint k; + gboolean wants_attach = FALSE; + gboolean wants_detach = FALSE; + + g_assert (attach_button_); + g_assert (detach_button_); + + for (k = 0; k < INF_NO_; ++k) + { + wants_attach = wants_attach || infos_[k].detached; + wants_detach = wants_detach || !infos_[k].detached; + } + + gtk_tool_item_set_visible_horizontal (attach_button_, wants_attach); + gtk_tool_item_set_visible_vertical (attach_button_, wants_attach); + gtk_tool_item_set_visible_horizontal (detach_button_, wants_detach); + gtk_tool_item_set_visible_vertical (detach_button_, wants_detach); +} + + -- cgit v1.2.3