Commit e9343d93 authored by Steve Frécinaux's avatar Steve Frécinaux Committed by Paolo Borelli

handle the visibility changes of panels, toolbar and statusbar connecting

2006-02-12  Steve Frécinaux <steve@istique.net>

	* gedit/gedit-window.[ch]: handle the visibility changes of panels,
	toolbar and statusbar connecting to the show and hide signals.

	* gedit/gedit-commands-view.c:
	* gedit/gedit-session.c:

	adapt for above changes (use directly gtk_widget_show/hide instead of a
	custom function)
parent 1d3f5029
2006-02-12 Steve Frécinaux <steve@istique.net>
* gedit/gedit-window.[ch]: handle the visibility changes of panels,
toolbar and statusbar connecting to the show and hide signals.
* gedit/gedit-commands-view.c:
* gedit/gedit-session.c:
adapt for above changes (use directly gtk_widget_show/hide instead of a
custom function)
2006-02-12 Paolo Maggi <paolo@gnome.org> 2006-02-12 Paolo Maggi <paolo@gnome.org>
* plugins/externaltools/tools/tools.glade: use GTK_SHADOW_IN for * plugins/externaltools/tools/tools.glade: use GTK_SHADOW_IN for
......
...@@ -37,8 +37,10 @@ ...@@ -37,8 +37,10 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "gedit-commands.h" #include "gedit-commands.h"
#include "gedit-window.h"
#include "gedit-debug.h" #include "gedit-debug.h"
#include "gedit-window.h"
#include "gedit-window-private.h"
void void
gedit_cmd_view_show_toolbar (GtkAction *action, gedit_cmd_view_show_toolbar (GtkAction *action,
...@@ -50,7 +52,10 @@ gedit_cmd_view_show_toolbar (GtkAction *action, ...@@ -50,7 +52,10 @@ gedit_cmd_view_show_toolbar (GtkAction *action,
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
_gedit_window_set_toolbar_visible (window, visible); if (visible)
gtk_widget_show (window->priv->toolbar);
else
gtk_widget_hide (window->priv->toolbar);
} }
void void
...@@ -63,7 +68,10 @@ gedit_cmd_view_show_statusbar (GtkAction *action, ...@@ -63,7 +68,10 @@ gedit_cmd_view_show_statusbar (GtkAction *action,
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
_gedit_window_set_statusbar_visible (window, visible); if (visible)
gtk_widget_show (window->priv->statusbar);
else
gtk_widget_hide (window->priv->statusbar);
} }
void void
...@@ -71,12 +79,23 @@ gedit_cmd_view_show_side_pane (GtkAction *action, ...@@ -71,12 +79,23 @@ gedit_cmd_view_show_side_pane (GtkAction *action,
GeditWindow *window) GeditWindow *window)
{ {
gboolean visible; gboolean visible;
GeditPanel *panel;
gedit_debug (DEBUG_COMMANDS); gedit_debug (DEBUG_COMMANDS);
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
_gedit_window_set_side_panel_visible (window, visible); panel = gedit_window_get_side_panel (window);
if (visible)
{
gtk_widget_show (panel);
gtk_widget_grab_focus (panel);
}
else
{
gtk_widget_hide (panel);
}
} }
void void
...@@ -84,10 +103,21 @@ gedit_cmd_view_show_bottom_panel (GtkAction *action, ...@@ -84,10 +103,21 @@ gedit_cmd_view_show_bottom_panel (GtkAction *action,
GeditWindow *window) GeditWindow *window)
{ {
gboolean visible; gboolean visible;
GeditPanel *panel;
gedit_debug (DEBUG_COMMANDS); gedit_debug (DEBUG_COMMANDS);
visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); visible = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
_gedit_window_set_bottom_panel_visible (window, visible); panel = gedit_window_get_bottom_panel (window);
if (visible)
{
gtk_widget_show (panel);
gtk_widget_grab_focus (panel);
}
else
{
gtk_widget_hide (panel);
}
} }
...@@ -694,22 +694,21 @@ parse_window (xmlNodePtr node) ...@@ -694,22 +694,21 @@ parse_window (xmlNodePtr node)
if (strcmp ((char *) child->name, "side-pane") == 0) if (strcmp ((char *) child->name, "side-pane") == 0)
{ {
xmlChar *visible; xmlChar *visible;
GeditPanel *panel;
visible = xmlGetProp (child, (const xmlChar *) "visible"); visible = xmlGetProp (child, (const xmlChar *) "visible");
panel = gedit_window_get_side_panel (window);
if ((visible != NULL) && if ((visible != NULL) &&
(strcmp ((char *) visible, "yes") == 0)) (strcmp ((char *) visible, "yes") == 0))
{ {
gedit_debug_message (DEBUG_SESSION, "Side panel visible"); gedit_debug_message (DEBUG_SESSION, "Side panel visible");
_gedit_window_set_side_panel_visible (window, gtk_widget_show (GTK_WIDGET (panel));
TRUE);
} }
else else
{ {
gedit_debug_message (DEBUG_SESSION, "Side panel _NOT_ visible"); gedit_debug_message (DEBUG_SESSION, "Side panel _NOT_ visible");
_gedit_window_set_side_panel_visible (window, gtk_widget_hide (GTK_WIDGET (panel));
FALSE);
} }
if (visible != NULL) if (visible != NULL)
...@@ -718,22 +717,21 @@ parse_window (xmlNodePtr node) ...@@ -718,22 +717,21 @@ parse_window (xmlNodePtr node)
else if (strcmp ((char *) child->name, "bottom-panel") == 0) else if (strcmp ((char *) child->name, "bottom-panel") == 0)
{ {
xmlChar *visible; xmlChar *visible;
GeditPanel *panel;
visible = xmlGetProp (child, (const xmlChar *) "visible"); visible = xmlGetProp (child, (const xmlChar *) "visible");
panel = gedit_window_get_bottom_panel (window);
if ((visible != NULL) && if ((visible != NULL) &&
(strcmp ((char *) visible, "yes") == 0)) (strcmp ((char *) visible, "yes") == 0))
{ {
gedit_debug_message (DEBUG_SESSION, "Bottom panel visible"); gedit_debug_message (DEBUG_SESSION, "Bottom panel visible");
_gedit_window_set_bottom_panel_visible (window, gtk_widget_show (GTK_WIDGET (panel));
TRUE);
} }
else else
{ {
gedit_debug_message (DEBUG_SESSION, "Bottom panel _NOT_ visible"); gedit_debug_message (DEBUG_SESSION, "Bottom panel _NOT_ visible");
_gedit_window_set_bottom_panel_visible (window, gtk_widget_hide (GTK_WIDGET (panel));
FALSE);
} }
if (visible != NULL) if (visible != NULL)
......
...@@ -929,6 +929,25 @@ set_non_homogeneus (GtkWidget *widget, gpointer data) ...@@ -929,6 +929,25 @@ set_non_homogeneus (GtkWidget *widget, gpointer data)
gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), FALSE); gtk_tool_item_set_homogeneous (GTK_TOOL_ITEM (widget), FALSE);
} }
static void
toolbar_visibility_changed (GtkWidget *toolbar,
GeditWindow *window)
{
gboolean visible;
GtkAction *action;
visible = GTK_WIDGET_VISIBLE (toolbar);
if (gedit_prefs_manager_toolbar_visible_can_set ())
gedit_prefs_manager_set_toolbar_visible (visible);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewToolbar");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
}
static void static void
create_menu_bar_and_toolbar (GeditWindow *window, create_menu_bar_and_toolbar (GeditWindow *window,
GtkWidget *main_box) GtkWidget *main_box)
...@@ -1104,7 +1123,16 @@ create_menu_bar_and_toolbar (GeditWindow *window, ...@@ -1104,7 +1123,16 @@ create_menu_bar_and_toolbar (GeditWindow *window,
gtk_container_foreach (GTK_CONTAINER (window->priv->toolbar), gtk_container_foreach (GTK_CONTAINER (window->priv->toolbar),
(GtkCallback)set_non_homogeneus, (GtkCallback)set_non_homogeneus,
NULL); NULL);
g_signal_connect_after (G_OBJECT (window->priv->toolbar),
"show",
G_CALLBACK (toolbar_visibility_changed),
window);
g_signal_connect_after (G_OBJECT (window->priv->toolbar),
"hide",
G_CALLBACK (toolbar_visibility_changed),
window);
} }
static void static void
...@@ -1250,6 +1278,25 @@ set_statusbar_style (GeditWindow *window, ...@@ -1250,6 +1278,25 @@ set_statusbar_style (GeditWindow *window,
return visible; return visible;
} }
static void
statusbar_visibility_changed (GtkWidget *statusbar,
GeditWindow *window)
{
gboolean visible;
GtkAction *action;
visible = GTK_WIDGET_VISIBLE (statusbar);
if (gedit_prefs_manager_statusbar_visible_can_set ())
gedit_prefs_manager_set_statusbar_visible (visible);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewStatusbar");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
}
static void static void
create_statusbar (GeditWindow *window, create_statusbar (GeditWindow *window,
GtkWidget *main_box) GtkWidget *main_box)
...@@ -1267,9 +1314,18 @@ create_statusbar (GeditWindow *window, ...@@ -1267,9 +1314,18 @@ create_statusbar (GeditWindow *window,
window->priv->statusbar, window->priv->statusbar,
FALSE, FALSE,
TRUE, TRUE,
0); 0);
g_signal_connect_after (G_OBJECT (window->priv->statusbar),
"show",
G_CALLBACK (statusbar_visibility_changed),
window);
g_signal_connect_after (G_OBJECT (window->priv->statusbar),
"hide",
G_CALLBACK (statusbar_visibility_changed),
window);
set_statusbar_style (window, NULL); set_statusbar_style (window, NULL);
} }
static GeditWindow * static GeditWindow *
...@@ -2430,6 +2486,30 @@ vpaned_restore_position (GtkWidget *widget, ...@@ -2430,6 +2486,30 @@ vpaned_restore_position (GtkWidget *widget,
g_signal_handlers_disconnect_by_func (widget, vpaned_restore_position, window); g_signal_handlers_disconnect_by_func (widget, vpaned_restore_position, window);
} }
static void
side_panel_visibility_changed (GtkWidget *side_panel,
GeditWindow *window)
{
gboolean visible;
GtkAction *action;
visible = GTK_WIDGET_VISIBLE (side_panel);
if (gedit_prefs_manager_side_pane_visible_can_set ())
gedit_prefs_manager_set_side_pane_visible (visible);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewSidePane");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
/* focus the document */
if (!visible && window->priv->active_tab != NULL)
gtk_widget_grab_focus (GTK_WIDGET (
gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
}
static void static void
side_panel_size_allocate (GtkWidget *widget, side_panel_size_allocate (GtkWidget *widget,
GtkAllocation *allocation, GtkAllocation *allocation,
...@@ -2438,13 +2518,6 @@ side_panel_size_allocate (GtkWidget *widget, ...@@ -2438,13 +2518,6 @@ side_panel_size_allocate (GtkWidget *widget,
window->priv->side_panel_size = allocation->width; window->priv->side_panel_size = allocation->width;
} }
static void
side_panel_hide (GtkWidget *panel,
GeditWindow *window)
{
_gedit_window_set_side_panel_visible (window, FALSE);
}
static void static void
create_side_panel (GeditWindow *window) create_side_panel (GeditWindow *window)
{ {
...@@ -2461,14 +2534,18 @@ create_side_panel (GeditWindow *window) ...@@ -2461,14 +2534,18 @@ create_side_panel (GeditWindow *window)
gtk_widget_set_size_request (window->priv->side_panel, 100, -1); gtk_widget_set_size_request (window->priv->side_panel, 100, -1);
g_signal_connect (window->priv->side_panel, g_signal_connect (window->priv->side_panel,
"size_allocate", "size-allocate",
G_CALLBACK (side_panel_size_allocate), G_CALLBACK (side_panel_size_allocate),
window); window);
g_signal_connect (window->priv->side_panel, g_signal_connect_after (window->priv->side_panel,
"hide", "show",
G_CALLBACK (side_panel_hide), G_CALLBACK (side_panel_visibility_changed),
window); window);
g_signal_connect_after (window->priv->side_panel,
"hide",
G_CALLBACK (side_panel_visibility_changed),
window);
gtk_paned_set_position (GTK_PANED (window->priv->hpaned), gtk_paned_set_position (GTK_PANED (window->priv->hpaned),
MAX (100, gedit_prefs_manager_get_side_panel_size ())); MAX (100, gedit_prefs_manager_get_side_panel_size ()));
...@@ -2481,18 +2558,35 @@ create_side_panel (GeditWindow *window) ...@@ -2481,18 +2558,35 @@ create_side_panel (GeditWindow *window)
} }
static void static void
bottom_panel_size_allocate (GtkWidget *widget, bottom_panel_visibility_changed (GeditPanel *bottom_panel,
GtkAllocation *allocation, GeditWindow *window)
GeditWindow *window)
{ {
window->priv->bottom_panel_size = allocation->height; gboolean visible;
GtkAction *action;
visible = GTK_WIDGET_VISIBLE (bottom_panel);
if (gedit_prefs_manager_bottom_panel_visible_can_set ())
gedit_prefs_manager_set_bottom_panel_visible (visible);
action = gtk_action_group_get_action (window->priv->action_group,
"ViewBottomPanel");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
/* focus the document */
if (!visible && window->priv->active_tab != NULL)
gtk_widget_grab_focus (GTK_WIDGET (
gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
} }
static void static void
bottom_panel_hide (GtkWidget *panel, bottom_panel_size_allocate (GtkWidget *widget,
GeditWindow *window) GtkAllocation *allocation,
GeditWindow *window)
{ {
_gedit_window_set_bottom_panel_visible (window, FALSE); window->priv->bottom_panel_size = allocation->height;
} }
static void static void
...@@ -2504,7 +2598,7 @@ bottom_panel_item_removed (GeditPanel *panel, ...@@ -2504,7 +2598,7 @@ bottom_panel_item_removed (GeditPanel *panel,
{ {
GtkAction *action; GtkAction *action;
_gedit_window_set_bottom_panel_visible (window, FALSE); gtk_widget_hide (GTK_WIDGET (panel));
action = gtk_action_group_get_action (window->priv->action_group, action = gtk_action_group_get_action (window->priv->action_group,
"ViewBottomPanel"); "ViewBottomPanel");
...@@ -2529,7 +2623,8 @@ bottom_panel_item_added (GeditPanel *panel, ...@@ -2529,7 +2623,8 @@ bottom_panel_item_added (GeditPanel *panel,
gtk_action_set_sensitive (action, TRUE); gtk_action_set_sensitive (action, TRUE);
show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)); show = gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action));
_gedit_window_set_bottom_panel_visible (window, show); if (show)
gtk_widget_show (GTK_WIDGET (panel));
} }
} }
...@@ -2546,54 +2641,43 @@ create_bottom_panel (GeditWindow *window) ...@@ -2546,54 +2641,43 @@ create_bottom_panel (GeditWindow *window)
FALSE); FALSE);
g_signal_connect (window->priv->bottom_panel, g_signal_connect (window->priv->bottom_panel,
"size_allocate", "size-allocate",
G_CALLBACK (bottom_panel_size_allocate), G_CALLBACK (bottom_panel_size_allocate),
window); window);
g_signal_connect (window->priv->bottom_panel,
"hide", g_signal_connect_after (window->priv->bottom_panel,
G_CALLBACK (bottom_panel_hide), "show",
window); G_CALLBACK (bottom_panel_visibility_changed),
window);
g_signal_connect_after (window->priv->bottom_panel,
"hide",
G_CALLBACK (bottom_panel_visibility_changed),
window);
gtk_paned_set_position (GTK_PANED (window->priv->vpaned), gtk_paned_set_position (GTK_PANED (window->priv->vpaned),
MAX (50, gedit_prefs_manager_get_bottom_panel_size ())); MAX (50, gedit_prefs_manager_get_bottom_panel_size ()));
} }
static void static void
init_panes_visibility (GeditWindow *window) init_panels_visibility (GeditWindow *window)
{ {
GtkAction *action;
gboolean visible;
gedit_debug (DEBUG_WINDOW); gedit_debug (DEBUG_WINDOW);
/* side pane */ /* side pane */
visible = gedit_prefs_manager_get_side_pane_visible (); if (gedit_prefs_manager_get_side_pane_visible ())
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewSidePane");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
if (visible)
gtk_widget_show (window->priv->side_panel); gtk_widget_show (window->priv->side_panel);
/* bottom pane, it can be empty */ /* bottom pane, it can be empty */
action = gtk_action_group_get_action (window->priv->action_group,
"ViewBottomPanel");
if (gedit_panel_get_n_items (GEDIT_PANEL (window->priv->bottom_panel)) > 0) if (gedit_panel_get_n_items (GEDIT_PANEL (window->priv->bottom_panel)) > 0)
{ {
visible = gedit_prefs_manager_get_bottom_panel_visible(); if (gedit_prefs_manager_get_bottom_panel_visible ())
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
if(visible)
gtk_widget_show (window->priv->bottom_panel); gtk_widget_show (window->priv->bottom_panel);
} }
else else
{ {
GtkAction *action;
action = gtk_action_group_get_action (window->priv->action_group,
"ViewBottomPanel");
gtk_action_set_sensitive (action, FALSE); gtk_action_set_sensitive (action, FALSE);
} }
...@@ -2739,7 +2823,7 @@ gedit_window_init (GeditWindow *window) ...@@ -2739,7 +2823,7 @@ gedit_window_init (GeditWindow *window)
/* set visibility of panes. /* set visibility of panes.
* This needs to be done after plugins activatation */ * This needs to be done after plugins activatation */
init_panes_visibility (window); init_panels_visibility (window);
gedit_debug_message (DEBUG_WINDOW, "END"); gedit_debug_message (DEBUG_WINDOW, "END");
} }
...@@ -2930,193 +3014,21 @@ gedit_window_close_tabs (GeditWindow *window, ...@@ -2930,193 +3014,21 @@ gedit_window_close_tabs (GeditWindow *window,
if (tabs == NULL) if (tabs == NULL)
return; return;
window->priv->removing_tabs = TRUE; window->priv->removing_tabs = TRUE;
while (tabs != NULL) while (tabs != NULL)
{ {
if (tabs->next == NULL) if (tabs->next == NULL)
window->priv->removing_tabs = FALSE; window->priv->removing_tabs = FALSE;
gedit_notebook_remove_tab (GEDIT_NOTEBOOK (window->priv->notebook), gedit_notebook_remove_tab (GEDIT_NOTEBOOK (window->priv->notebook),
GEDIT_TAB (tabs->data)); GEDIT_TAB (tabs->data));
tabs = g_list_next (tabs); tabs = g_list_next (tabs);
} }
g_return_if_fail (window->priv->removing_tabs == FALSE);
}
void g_return_if_fail (window->priv->removing_tabs == FALSE);
_gedit_window_set_statusbar_visible (GeditWindow *window,
gboolean visible)
{
GtkAction *action;
static gboolean recursion_guard = FALSE;
gedit_debug (DEBUG_WINDOW);
g_return_if_fail (GEDIT_IS_WINDOW (window));
if (recursion_guard)
return;
recursion_guard = TRUE;
visible = (visible != FALSE);
if (visible)
gtk_widget_show (window->priv->statusbar);
else
gtk_widget_hide (window->priv->statusbar);
if (gedit_prefs_manager_statusbar_visible_can_set ())
gedit_prefs_manager_set_statusbar_visible (visible);
action = gtk_action_group_get_action (window->priv->always_sensitive_action_group,
"ViewStatusbar");
if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) != visible)
gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), visible);
recursion_guard = FALSE;
}
void
_gedit_window_set_toolbar_visible (GeditWindow *window,
gboolean visible)
{
GtkAction *action;
static gboolean recursion_guard = FALSE;