From cf3fde37fafece2a0d825b8700e71f5b60244cc1 Mon Sep 17 00:00:00 2001 From: yggverse Date: Sun, 7 Jul 2024 08:05:04 +0300 Subject: [PATCH] move statusbar feature to gtk header subtitle --- src/Entity/Browser/Container/Tab.php | 12 ++- src/Entity/Browser/Container/Tab/Page.php | 17 +--- .../Browser/Container/Tab/Page/Content.php | 71 ++++++++-------- .../Browser/Container/Tab/Page/Statusbar.php | 83 ------------------- .../Browser/Container/Tab/Page/Title.php | 35 +++++++- src/Entity/Browser/Header.php | 7 +- .../Container/Tab/Page/Title/Label.php | 22 +++++ 7 files changed, 104 insertions(+), 143 deletions(-) delete mode 100644 src/Entity/Browser/Container/Tab/Page/Statusbar.php create mode 100644 src/Gtk/Browser/Container/Tab/Page/Title/Label.php diff --git a/src/Entity/Browser/Container/Tab.php b/src/Entity/Browser/Container/Tab.php index 94f3c27f..e75d4bbc 100644 --- a/src/Entity/Browser/Container/Tab.php +++ b/src/Entity/Browser/Container/Tab.php @@ -41,10 +41,13 @@ class Tab \GtkWidget $child, int $position ) { + $label = $entity->get_tab_label( + $child + ); + $this->container->browser->header->setTitle( - $entity->get_tab_label( - $child - )->get_text() + $label->get_text(), + $label->get_subtitle() // @TODO extension not supported by GTK-PHP ); // Keep current selection @@ -92,7 +95,8 @@ class Tab // Update application title $this->container->browser->header->setTitle( - $page->title->gtk->get_text() + $page->title->getValue(), + $page->title->getSubtitle() ); } diff --git a/src/Entity/Browser/Container/Tab/Page.php b/src/Entity/Browser/Container/Tab/Page.php index 2b70a7f2..58fca566 100644 --- a/src/Entity/Browser/Container/Tab/Page.php +++ b/src/Entity/Browser/Container/Tab/Page.php @@ -7,7 +7,6 @@ namespace Yggverse\Yoda\Entity\Browser\Container\Tab; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content; -use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar; class Page { @@ -20,7 +19,6 @@ class Page public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Title $title; public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar; public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content; - public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Statusbar $statusbar; public function __construct( \Yggverse\Yoda\Entity\Browser\Container\Tab $tab @@ -52,20 +50,8 @@ class Page $this ); - $this->gtk->pack_start( - $this->content->gtk, - true, - true, - 0 - ); - - // Init statusbar - $this->statusbar = new Statusbar( - $this - ); - $this->gtk->add( - $this->statusbar->gtk + $this->content->gtk ); // Render @@ -76,7 +62,6 @@ class Page { $this->navbar->refresh(); $this->content->refresh(); - $this->statusbar->refresh(); } public function update( diff --git a/src/Entity/Browser/Container/Tab/Page/Content.php b/src/Entity/Browser/Container/Tab/Page/Content.php index 205b5b34..fd2a64f1 100644 --- a/src/Entity/Browser/Container/Tab/Page/Content.php +++ b/src/Entity/Browser/Container/Tab/Page/Content.php @@ -37,6 +37,18 @@ class Content $this->_margin ); + $this->gtk->set_margin_bottom( + $this->_margin + ); + + $this->gtk->set_propagate_natural_height( // instead of pack to parent + true + ); + + $this->gtk->set_propagate_natural_width( + true + ); + // Init viewport // to integrate scrolled window features for data label $this->viewport = new Viewport( @@ -73,7 +85,8 @@ class Content // Init new title $this->page->title->setValue( - $address->getHost() + $address->getHost(), + 'loading...' ); if ($history) @@ -90,11 +103,6 @@ class Content ); } - // Update statusbar indicator - $this->page->statusbar->setValue( - 'Loading...' - ); - // Detect protocol switch ($address->getScheme()) { @@ -124,45 +132,36 @@ class Content if ($title) // detect title by document h1 { $this->page->title->setValue( - $title + $title, + $this->page->title->subtitle ); } - $this->page->statusbar->setValue( - null - ); - break; default: $this->page->title->setValue( - 'Oops!' + 'Oops!', + 'file extension not supported' ); $this->data->setPlain( 'File extension not supported' ); - - $this->page->statusbar->setValue( - null - ); } } else { $this->page->title->setValue( - 'Failure' + 'Failure', + 'resource not found or not readable' ); $this->data->setPlain( 'Could not open file' ); - - $this->page->statusbar->setValue( - 'Resource not found or not readable' - ); } break; @@ -212,7 +211,7 @@ class Content ); } - $this->page->statusbar->setValue( + $this->page->title->setSubtitle( $response->getMeta() ); } @@ -220,21 +219,18 @@ class Content else { $this->page->title->setValue( - 'Failure' - ); - - $this->data->setPlain( - 'Resource not available!' - ); - - $this->page->statusbar->setValue( + 'Failure', sprintf( - 'code %d', + 'could not open resource (code %d)', intval( $response->getCode() ) ) ); + + $this->data->setPlain( + 'Requested resource not available!' + ); } break; @@ -283,16 +279,13 @@ class Content default: $this->page->title->setValue( - 'Oops!' + 'Oops!', + 'protocol not supported!' ); $this->data->setPlain( 'Protocol not supported!' ); - - $this->page->statusbar->setValue( - null - ); } // Render content @@ -300,5 +293,11 @@ class Content // Refresh page components $this->page->refresh(); + + // Update window header + $this->page->tab->container->browser->header->setTitle( + $this->page->title->getValue(), + $this->page->title->getSubtitle(), + ); } } \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page/Statusbar.php b/src/Entity/Browser/Container/Tab/Page/Statusbar.php deleted file mode 100644 index 2861db7f..00000000 --- a/src/Entity/Browser/Container/Tab/Page/Statusbar.php +++ /dev/null @@ -1,83 +0,0 @@ -page = $page; - - // Init container - $this->gtk = new \GtkLabel; - - $this->gtk->set_use_markup( - true - ); - - $this->gtk->set_selectable( - true - ); - - $this->gtk->set_line_wrap( - true - ); - - $this->gtk->set_xalign( - 0 - ); - - $this->gtk->set_yalign( - 0 - ); - - $this->gtk->set_margin_top( - $this->_margin - ); - - $this->gtk->set_margin_bottom( - $this->_margin - ); - - $this->gtk->set_margin_start( - $this->_margin - ); - - $this->gtk->set_margin_end( - $this->_margin - ); - - $this->gtk->set_markup( - $this->_value - ); - } - - public function setValue( - ?string $value = null - ): void - { - $this->gtk->set_markup( - is_null($value) ? $this->_value : trim( - $value - ) - ); - } - - public function refresh() - { - // @TODO - } -} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page/Title.php b/src/Entity/Browser/Container/Tab/Page/Title.php index a94f7654..61b2535a 100644 --- a/src/Entity/Browser/Container/Tab/Page/Title.php +++ b/src/Entity/Browser/Container/Tab/Page/Title.php @@ -4,9 +4,11 @@ declare(strict_types=1); namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; +use \Yggverse\Yoda\Gtk\Browser\Container\Tab\Page\Title\Label; + class Title { - public \GtkLabel $gtk; + public Label $gtk; // Dependencies public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; @@ -15,6 +17,7 @@ class Title private int $_ellipsize = 3; private int $_length = 12; private string $_value = 'New page'; + private string $_subtitle = ''; public function __construct( \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page, @@ -23,7 +26,7 @@ class Title $this->page = $page; // Init container - $this->gtk = new \GtkLabel( + $this->gtk = new Label( $this->_value ); @@ -37,7 +40,8 @@ class Title } public function setValue( - ?string $value = null + ?string $value = null, + ?string $subtitle = null ): void { $this->gtk->set_text( @@ -45,5 +49,30 @@ class Title $value ) ); + + $this->setSubtitle( + $subtitle + ); + } + + public function setSubtitle( + ?string $subtitle = null + ): void + { + $this->gtk->set_subtitle( + is_null($subtitle) ? $this->_subtitle : trim( + $subtitle + ) + ); + } + + public function getValue(): string + { + return $this->gtk->get_text(); + } + + public function getSubtitle(): string + { + return $this->gtk->get_subtitle(); } } \ No newline at end of file diff --git a/src/Entity/Browser/Header.php b/src/Entity/Browser/Header.php index 78f32ddb..acb70891 100644 --- a/src/Entity/Browser/Header.php +++ b/src/Entity/Browser/Header.php @@ -53,7 +53,8 @@ class Header } public function setTitle( - ?string $value = null + ?string $value = null, + ?string $subtitle = null ): void { $this->gtk->set_title( @@ -65,6 +66,10 @@ class Header $this->_title ) ); + + $this->setSubtitle( + $subtitle + ); } public function setSubtitle( diff --git a/src/Gtk/Browser/Container/Tab/Page/Title/Label.php b/src/Gtk/Browser/Container/Tab/Page/Title/Label.php new file mode 100644 index 00000000..a1d018bc --- /dev/null +++ b/src/Gtk/Browser/Container/Tab/Page/Title/Label.php @@ -0,0 +1,22 @@ +_subtitle = $value; + } + + public function get_subtitle(): string + { + return $this->_subtitle; + } +} \ No newline at end of file