[ghex] notebook: Tab tweaks; don't show tab-bar when only 1 tab open
- From: Logan Rathbone <larathbone src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ghex] notebook: Tab tweaks; don't show tab-bar when only 1 tab open
- Date: Tue, 3 May 2022 04:36:07 +0000 (UTC)
commit 1e57c1a1425c6c2fb09ba1375eb70fa7268edc8f
Author: Logan Rathbone <poprocks gmail com>
Date: Tue May 3 00:34:35 2022 -0400
notebook: Tab tweaks; don't show tab-bar when only 1 tab open
- When closing a window with only 1 tab open, show the singular tab
close dialog. This also now disallows the closing of a singular tab,
leaving the 'no file open' screen,
src/ghex-application-window.c | 41 ++++++++++++++++++++++++++++++++++++++-
src/ghex-application-window.ui.in | 1 +
src/ghex-notebook-tab.c | 3 +++
3 files changed, 44 insertions(+), 1 deletion(-)
---
diff --git a/src/ghex-application-window.c b/src/ghex-application-window.c
index 7f46b68..2c26296 100644
--- a/src/ghex-application-window.c
+++ b/src/ghex-application-window.c
@@ -150,6 +150,8 @@ static GHexNotebookTab * ghex_application_window_get_current_tab (GHexApplicatio
static void update_status_message (GHexApplicationWindow *self);
static void update_gui_data (GHexApplicationWindow *self);
static gboolean assess_can_save (HexDocument *doc);
+static void do_close_window (GHexApplicationWindow *self);
+static void close_doc_confirmation_dialog (GHexApplicationWindow *self, GHexNotebookTab *tab);
static void doc_read_ready_cb (GObject *source_object, GAsyncResult *res,
gpointer user_data);
@@ -303,7 +305,13 @@ ghex_application_window_remove_tab (GHexApplicationWindow *self,
page_num = gtk_notebook_page_num (notebook, GTK_WIDGET(tab_gh));
gtk_notebook_remove_page (notebook, page_num);
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->hex_notebook)) == 1)
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->hex_notebook), FALSE);
+
update_gui_data (self);
+
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->hex_notebook)) == 0)
+ do_close_window (self);
}
static void
@@ -401,8 +409,28 @@ check_close_window (GHexApplicationWindow *self)
GtkNotebook *notebook = GTK_NOTEBOOK(self->hex_notebook);
gboolean unsaved_found = FALSE;
int i;
+ const int num_pages = gtk_notebook_get_n_pages (notebook);
- for (i = gtk_notebook_get_n_pages(notebook) - 1; i >= 0; --i)
+ /* We have only one tab open: */
+ if (num_pages == 1)
+ {
+ GHexNotebookTab *tab = ghex_application_window_get_current_tab (self);
+ HexDocument *doc = hex_widget_get_document (ACTIVE_GH);
+
+ if (hex_document_has_changed (doc))
+ {
+ close_doc_confirmation_dialog (self,
+ ghex_application_window_get_current_tab (self));
+ }
+ else
+ {
+ do_close_window (self);
+ }
+ return;
+ }
+
+ /* We have more than one tab open: */
+ for (i = num_pages - 1; i >= 0; --i)
{
HexWidget *gh;
HexDocument *doc = NULL;
@@ -1970,6 +1998,17 @@ ghex_application_window_add_hex (GHexApplicationWindow *self,
GTK_WIDGET(gh),
tab);
+ /* Because we ellipsize labels in ghex-notebook-tab, we need to set this
+ * property to TRUE according to TFM, otherwise all the labels will just
+ * show up as '...' */
+ g_object_set (gtk_notebook_get_page (GTK_NOTEBOOK(self->hex_notebook), GTK_WIDGET(gh)),
+ "tab-expand", TRUE,
+ NULL);
+
+ /* Only show the tab bar if there's more than one (1) tab. */
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(self->hex_notebook)) > 1)
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK(self->hex_notebook), TRUE);
+
/* FIXME - this seems to result in GTK_IS_BOX assertion failures.
* These seem harmless as everything still seems to *work*, but just
* documenting it here in case it becomes an issue in future.
diff --git a/src/ghex-application-window.ui.in b/src/ghex-application-window.ui.in
index 8d098dc..6d8eef8 100644
--- a/src/ghex-application-window.ui.in
+++ b/src/ghex-application-window.ui.in
@@ -239,6 +239,7 @@
<property name="scrollable">true</property>
<property name="vexpand">true</property>
<property name="hexpand">true</property>
+ <property name="show-tabs">false</property>
<!-- invisible by default to show the
no_doc_label -->
<property name="visible">false</property>
</object>
diff --git a/src/ghex-notebook-tab.c b/src/ghex-notebook-tab.c
index 2e02bc8..79e4e51 100644
--- a/src/ghex-notebook-tab.c
+++ b/src/ghex-notebook-tab.c
@@ -106,6 +106,9 @@ ghex_notebook_tab_init (GHexNotebookTab *self)
/* Set up our label to hold the document name and the close button. */
self->label = gtk_label_new (_(untitled_label));
+ gtk_label_set_ellipsize (GTK_LABEL(self->label), PANGO_ELLIPSIZE_END);
+ gtk_widget_set_hexpand (self->label, TRUE);
+
self->close_btn = gtk_button_new ();
gtk_widget_set_halign (self->close_btn, GTK_ALIGN_END);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]