From bb42afd2ce26b1d80f9dd2c1b81b30a770957df9 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 17 Apr 2024 23:47:56 +0300 Subject: [PATCH] implement tab width settings --- config.json | 10 +++++++++- src/Entity/Tab/Page.php | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/config.json b/config.json index bd7724c1..c10021b4 100644 --- a/config.json +++ b/config.json @@ -25,7 +25,15 @@ { "title": { - "default":"New page" + "default":"New page", + "width": + { + "chars":32 + }, + "ellipsize": + { + "mode":3 + } }, "redirect": { diff --git a/src/Entity/Tab/Page.php b/src/Entity/Tab/Page.php index ccdc8932..5e2d8c0a 100644 --- a/src/Entity/Tab/Page.php +++ b/src/Entity/Tab/Page.php @@ -763,23 +763,45 @@ class Page ?string $value = null ): void { - if ($value) + // Build new tab label on title length reached + if ($value && mb_strlen($value) > $this->config->title->width->chars) { - $title = $value; + $label = new \GtkLabel( + $value ? $value : $this->config->title->default + ); + + if ($this->config->title->width->chars) + { + $label->set_width_chars( + $this->config->title->width->chars + ); + } + + if ($this->config->title->ellipsize->mode) + { + $label->set_ellipsize( + // https://docs.gtk.org/Pango/enum.EllipsizeMode.html + $this->config->title->ellipsize->mode + ); + } + + $this->app->tabs->set_tab_label( + $this->box, + $label + ); } else { - $title = $this->config->title->default; + $this->app->tabs->set_tab_label_text( + $this->box, + $value + ); } - $this->app->tabs->set_tab_label_text( - $this->box, - $title - ); - + // Update window title $this->app->setTitle( - $title + $value ? $value : $this->config->title->default ); }