mirror of
https://github.com/GNOME/gedit
synced 2024-06-30 23:15:01 +00:00
BottomPanel: port to TeplPanel
This commit is contained in:
parent
1909fdc0fe
commit
ad471ec953
|
@ -3,14 +3,14 @@
|
|||
*/
|
||||
|
||||
#include "gedit-bottom-panel.h"
|
||||
#include <tepl/tepl.h>
|
||||
#include <glib/gi18n.h>
|
||||
#include "gedit-notebook-stack-switcher.h"
|
||||
#include "gedit-settings.h"
|
||||
|
||||
struct _GeditBottomPanelPrivate
|
||||
{
|
||||
GtkStack *stack;
|
||||
TeplPanelSimple *panel_simple;
|
||||
TeplPanelNotebook *panel_notebook;
|
||||
|
||||
gint height;
|
||||
};
|
||||
|
||||
|
@ -21,7 +21,8 @@ _gedit_bottom_panel_dispose (GObject *object)
|
|||
{
|
||||
GeditBottomPanel *panel = GEDIT_BOTTOM_PANEL (object);
|
||||
|
||||
g_clear_object (&panel->priv->stack);
|
||||
g_clear_object (&panel->priv->panel_simple);
|
||||
g_clear_object (&panel->priv->panel_notebook);
|
||||
|
||||
G_OBJECT_CLASS (_gedit_bottom_panel_parent_class)->dispose (object);
|
||||
}
|
||||
|
@ -47,42 +48,55 @@ init_height (GeditBottomPanel *panel)
|
|||
GEDIT_SETTINGS_BOTTOM_PANEL_SIZE);
|
||||
}
|
||||
|
||||
static void
|
||||
_gedit_bottom_panel_init (GeditBottomPanel *panel)
|
||||
static GtkNotebook *
|
||||
create_notebook (void)
|
||||
{
|
||||
GtkNotebook *notebook;
|
||||
|
||||
notebook = GTK_NOTEBOOK (gtk_notebook_new ());
|
||||
gtk_notebook_set_tab_pos (notebook, GTK_POS_BOTTOM);
|
||||
gtk_notebook_set_scrollable (notebook, TRUE);
|
||||
gtk_notebook_set_show_border (notebook, FALSE);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (notebook), 0);
|
||||
gtk_widget_set_hexpand (GTK_WIDGET (notebook), TRUE);
|
||||
gtk_widget_set_vexpand (GTK_WIDGET (notebook), TRUE);
|
||||
gtk_widget_show (GTK_WIDGET (notebook));
|
||||
|
||||
return notebook;
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_close_button (void)
|
||||
{
|
||||
GtkWidget *close_button;
|
||||
GtkWidget *switcher;
|
||||
|
||||
panel->priv = _gedit_bottom_panel_get_instance_private (panel);
|
||||
|
||||
init_height (panel);
|
||||
|
||||
panel->priv->stack = GTK_STACK (gtk_stack_new ());
|
||||
g_object_ref_sink (panel->priv->stack);
|
||||
gtk_widget_set_hexpand (GTK_WIDGET (panel->priv->stack), TRUE);
|
||||
gtk_widget_set_vexpand (GTK_WIDGET (panel->priv->stack), TRUE);
|
||||
gtk_widget_show (GTK_WIDGET (panel->priv->stack));
|
||||
gtk_grid_attach (GTK_GRID (panel),
|
||||
GTK_WIDGET (panel->priv->stack),
|
||||
0, 0, 1, 1);
|
||||
|
||||
switcher = gedit_notebook_stack_switcher_new ();
|
||||
gtk_widget_set_vexpand (switcher, TRUE);
|
||||
gedit_notebook_stack_switcher_set_stack (GEDIT_NOTEBOOK_STACK_SWITCHER (switcher),
|
||||
panel->priv->stack);
|
||||
gtk_widget_show (switcher);
|
||||
gtk_grid_attach (GTK_GRID (panel),
|
||||
switcher,
|
||||
0, 1, 1, 1);
|
||||
|
||||
close_button = tepl_utils_create_close_button ();
|
||||
gtk_widget_set_tooltip_text (close_button, _("Hide panel"));
|
||||
gtk_actionable_set_action_name (GTK_ACTIONABLE (close_button), "win.bottom-panel");
|
||||
gtk_widget_set_valign (close_button, GTK_ALIGN_START);
|
||||
gtk_widget_show (close_button);
|
||||
gtk_grid_attach (GTK_GRID (panel),
|
||||
close_button,
|
||||
1, 0, 1, 2);
|
||||
|
||||
return close_button;
|
||||
}
|
||||
|
||||
static void
|
||||
_gedit_bottom_panel_init (GeditBottomPanel *panel)
|
||||
{
|
||||
GtkNotebook *notebook;
|
||||
|
||||
panel->priv = _gedit_bottom_panel_get_instance_private (panel);
|
||||
|
||||
init_height (panel);
|
||||
|
||||
notebook = create_notebook ();
|
||||
gtk_container_add (GTK_CONTAINER (panel),
|
||||
GTK_WIDGET (notebook));
|
||||
gtk_container_add (GTK_CONTAINER (panel),
|
||||
create_close_button ());
|
||||
|
||||
panel->priv->panel_simple = tepl_panel_simple_new ();
|
||||
panel->priv->panel_notebook = tepl_panel_notebook_new (panel->priv->panel_simple,
|
||||
notebook);
|
||||
}
|
||||
|
||||
GeditBottomPanel *
|
||||
|
@ -91,11 +105,11 @@ _gedit_bottom_panel_new (void)
|
|||
return g_object_new (GEDIT_TYPE_BOTTOM_PANEL, NULL);
|
||||
}
|
||||
|
||||
GtkStack *
|
||||
_gedit_bottom_panel_get_stack (GeditBottomPanel *panel)
|
||||
TeplPanelSimple *
|
||||
_gedit_bottom_panel_get_panel_simple (GeditBottomPanel *panel)
|
||||
{
|
||||
g_return_val_if_fail (GEDIT_IS_BOTTOM_PANEL (panel), NULL);
|
||||
return panel->priv->stack;
|
||||
return panel->priv->panel_simple;
|
||||
}
|
||||
|
||||
gint
|
||||
|
@ -118,19 +132,19 @@ _gedit_bottom_panel_save_state (GeditBottomPanel *panel)
|
|||
{
|
||||
GeditSettings *settings;
|
||||
GSettings *window_state_settings;
|
||||
const gchar *panel_page;
|
||||
const gchar *active_item_name;
|
||||
|
||||
g_return_if_fail (GEDIT_IS_BOTTOM_PANEL (panel));
|
||||
|
||||
settings = _gedit_settings_get_singleton ();
|
||||
window_state_settings = _gedit_settings_peek_window_state_settings (settings);
|
||||
|
||||
panel_page = gtk_stack_get_visible_child_name (panel->priv->stack);
|
||||
if (panel_page != NULL)
|
||||
active_item_name = tepl_panel_simple_get_active_item_name (panel->priv->panel_simple);
|
||||
if (active_item_name != NULL)
|
||||
{
|
||||
g_settings_set_string (window_state_settings,
|
||||
GEDIT_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE,
|
||||
panel_page);
|
||||
active_item_name);
|
||||
}
|
||||
|
||||
if (panel->priv->height > 0)
|
||||
|
@ -145,18 +159,18 @@ void
|
|||
_gedit_bottom_panel_copy_settings (GeditBottomPanel *origin,
|
||||
GeditBottomPanel *target)
|
||||
{
|
||||
const gchar *visible_child_name;
|
||||
const gchar *active_item_name;
|
||||
|
||||
g_return_if_fail (GEDIT_IS_BOTTOM_PANEL (origin));
|
||||
g_return_if_fail (GEDIT_IS_BOTTOM_PANEL (target));
|
||||
|
||||
target->priv->height = origin->priv->height;
|
||||
|
||||
visible_child_name = gtk_stack_get_visible_child_name (origin->priv->stack);
|
||||
if (visible_child_name != NULL)
|
||||
active_item_name = tepl_panel_simple_get_active_item_name (origin->priv->panel_simple);
|
||||
if (active_item_name != NULL)
|
||||
{
|
||||
gtk_stack_set_visible_child_name (target->priv->stack,
|
||||
visible_child_name);
|
||||
tepl_panel_simple_set_active_item_name (target->priv->panel_simple,
|
||||
active_item_name);
|
||||
}
|
||||
|
||||
gtk_widget_set_visible (GTK_WIDGET (target),
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#ifndef GEDIT_BOTTOM_PANEL_H
|
||||
#define GEDIT_BOTTOM_PANEL_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <tepl/tepl.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -39,7 +39,7 @@ G_GNUC_INTERNAL
|
|||
GeditBottomPanel * _gedit_bottom_panel_new (void);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
GtkStack * _gedit_bottom_panel_get_stack (GeditBottomPanel *panel);
|
||||
TeplPanelSimple * _gedit_bottom_panel_get_panel_simple (GeditBottomPanel *panel);
|
||||
|
||||
G_GNUC_INTERNAL
|
||||
gint _gedit_bottom_panel_get_height (GeditBottomPanel *panel);
|
||||
|
|
|
@ -66,7 +66,7 @@ struct _GeditWindowPrivate
|
|||
|
||||
GeditSidePanel *side_panel;
|
||||
GeditBottomPanel *bottom_panel;
|
||||
gint bottom_panel_item_removed_handler_id;
|
||||
gint bottom_panel_remove_item_handler_id;
|
||||
|
||||
GtkWidget *hpaned;
|
||||
GtkWidget *vpaned;
|
||||
|
@ -193,14 +193,14 @@ gedit_window_dispose (GObject *object)
|
|||
/* Stop tracking removal of panels otherwise we always
|
||||
* end up with thinking we had no panel active, since they
|
||||
* should all be removed below */
|
||||
if (window->priv->bottom_panel_item_removed_handler_id != 0)
|
||||
if (window->priv->bottom_panel_remove_item_handler_id != 0)
|
||||
{
|
||||
GtkStack *stack;
|
||||
TeplPanelSimple *panel_simple;
|
||||
|
||||
stack = _gedit_bottom_panel_get_stack (window->priv->bottom_panel);
|
||||
panel_simple = _gedit_bottom_panel_get_panel_simple (window->priv->bottom_panel);
|
||||
|
||||
g_signal_handler_disconnect (stack, window->priv->bottom_panel_item_removed_handler_id);
|
||||
window->priv->bottom_panel_item_removed_handler_id = 0;
|
||||
g_signal_handler_disconnect (panel_simple, window->priv->bottom_panel_remove_item_handler_id);
|
||||
window->priv->bottom_panel_remove_item_handler_id = 0;
|
||||
}
|
||||
|
||||
/* First of all, force collection so that plugins
|
||||
|
@ -2070,11 +2070,11 @@ bottom_panel_visibility_changed (GtkWidget *bottom_panel,
|
|||
}
|
||||
|
||||
static void
|
||||
bottom_panel_item_removed (GtkStack *bottom_panel_stack,
|
||||
GtkWidget *item,
|
||||
GeditWindow *window)
|
||||
bottom_panel_remove_item_cb (TeplPanelSimple *panel_simple,
|
||||
TeplPanelItem *item,
|
||||
GeditWindow *window)
|
||||
{
|
||||
if (gtk_stack_get_visible_child (bottom_panel_stack) == NULL)
|
||||
if (tepl_panel_simple_get_active_item (panel_simple) == NULL)
|
||||
{
|
||||
gtk_widget_hide (GTK_WIDGET (window->priv->bottom_panel));
|
||||
}
|
||||
|
@ -2083,19 +2083,19 @@ bottom_panel_item_removed (GtkStack *bottom_panel_stack,
|
|||
}
|
||||
|
||||
static void
|
||||
bottom_panel_item_added (GtkStack *bottom_panel_stack,
|
||||
GtkWidget *item,
|
||||
GeditWindow *window)
|
||||
bottom_panel_add_item_cb (TeplPanelSimple *panel_simple,
|
||||
TeplPanelItem *item,
|
||||
GeditWindow *window)
|
||||
{
|
||||
GList *children;
|
||||
int n_children;
|
||||
GList *items;
|
||||
gint n_items;
|
||||
|
||||
children = gtk_container_get_children (GTK_CONTAINER (bottom_panel_stack));
|
||||
n_children = g_list_length (children);
|
||||
g_list_free (children);
|
||||
items = tepl_panel_simple_get_items (panel_simple);
|
||||
n_items = g_list_length (items);
|
||||
g_list_free_full (items, g_object_unref);
|
||||
|
||||
/* First item added. */
|
||||
if (n_children == 1)
|
||||
if (n_items == 1)
|
||||
{
|
||||
gboolean show;
|
||||
|
||||
|
@ -2113,8 +2113,6 @@ bottom_panel_item_added (GtkStack *bottom_panel_stack,
|
|||
static void
|
||||
setup_bottom_panel (GeditWindow *window)
|
||||
{
|
||||
gedit_debug (DEBUG_WINDOW);
|
||||
|
||||
g_signal_connect_after (window->priv->bottom_panel,
|
||||
"notify::visible",
|
||||
G_CALLBACK (bottom_panel_visibility_changed),
|
||||
|
@ -2161,28 +2159,20 @@ init_side_panel_visibility (GeditWindow *window)
|
|||
static void
|
||||
init_bottom_panel_visibility (GeditWindow *window)
|
||||
{
|
||||
GtkStack *stack;
|
||||
TeplPanelSimple *panel_simple;
|
||||
|
||||
gedit_debug (DEBUG_WINDOW);
|
||||
|
||||
stack = _gedit_bottom_panel_get_stack (window->priv->bottom_panel);
|
||||
panel_simple = _gedit_bottom_panel_get_panel_simple (window->priv->bottom_panel);
|
||||
|
||||
/* The bottom panel can be empty, in which case it isn't shown. */
|
||||
if (gtk_stack_get_visible_child (stack) != NULL)
|
||||
if (tepl_panel_simple_get_active_item (panel_simple) != NULL)
|
||||
{
|
||||
gchar *child_name;
|
||||
GtkWidget *child_widget;
|
||||
gchar *item_name;
|
||||
gboolean bottom_panel_visible;
|
||||
|
||||
child_name = g_settings_get_string (window->priv->window_settings,
|
||||
GEDIT_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE);
|
||||
child_widget = gtk_stack_get_child_by_name (stack, child_name);
|
||||
if (child_widget != NULL)
|
||||
{
|
||||
gtk_stack_set_visible_child (stack, child_widget);
|
||||
}
|
||||
|
||||
g_free (child_name);
|
||||
item_name = g_settings_get_string (window->priv->window_settings,
|
||||
GEDIT_SETTINGS_BOTTOM_PANEL_ACTIVE_PAGE);
|
||||
tepl_panel_simple_set_active_item_name (panel_simple, item_name);
|
||||
g_free (item_name);
|
||||
|
||||
bottom_panel_visible = g_settings_get_boolean (window->priv->ui_settings,
|
||||
GEDIT_SETTINGS_BOTTOM_PANEL_VISIBLE);
|
||||
|
@ -2194,16 +2184,17 @@ init_bottom_panel_visibility (GeditWindow *window)
|
|||
}
|
||||
|
||||
/* start track sensitivity after the initial state is set */
|
||||
window->priv->bottom_panel_item_removed_handler_id =
|
||||
g_signal_connect (stack,
|
||||
"remove",
|
||||
G_CALLBACK (bottom_panel_item_removed),
|
||||
window);
|
||||
window->priv->bottom_panel_remove_item_handler_id =
|
||||
g_signal_connect_after (panel_simple,
|
||||
"remove-item",
|
||||
G_CALLBACK (bottom_panel_remove_item_cb),
|
||||
window);
|
||||
|
||||
g_signal_connect_after (stack,
|
||||
"add",
|
||||
G_CALLBACK (bottom_panel_item_added),
|
||||
window);
|
||||
g_signal_connect_object (panel_simple,
|
||||
"add-item",
|
||||
G_CALLBACK (bottom_panel_add_item_cb),
|
||||
window,
|
||||
G_CONNECT_AFTER);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -3006,14 +2997,14 @@ _gedit_window_get_whole_bottom_panel (GeditWindow *window)
|
|||
* gedit_window_get_bottom_panel:
|
||||
* @window: a #GeditWindow.
|
||||
*
|
||||
* Returns: (transfer none): the bottom panel's #GtkStack that is part of
|
||||
* @window.
|
||||
* Returns: (transfer none): the bottom panel of @window.
|
||||
* Since: 48
|
||||
*/
|
||||
GtkWidget *
|
||||
TeplPanel *
|
||||
gedit_window_get_bottom_panel (GeditWindow *window)
|
||||
{
|
||||
g_return_val_if_fail (GEDIT_IS_WINDOW (window), NULL);
|
||||
return GTK_WIDGET (_gedit_bottom_panel_get_stack (window->priv->bottom_panel));
|
||||
return TEPL_PANEL (_gedit_bottom_panel_get_panel_simple (window->priv->bottom_panel));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -111,7 +111,7 @@ GtkWindowGroup *gedit_window_get_group (GeditWindow *window);
|
|||
|
||||
TeplPanel * gedit_window_get_side_panel (GeditWindow *window);
|
||||
|
||||
GtkWidget * gedit_window_get_bottom_panel (GeditWindow *window);
|
||||
TeplPanel * gedit_window_get_bottom_panel (GeditWindow *window);
|
||||
|
||||
GtkWidget * gedit_window_get_statusbar (GeditWindow *window);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user