From 847a0fb01db0c99c3fd441f6625d767f6f01e9ed Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 5 Jul 2024 22:04:26 +0300 Subject: [PATCH] init multi-window implementation --- .../Container/Tab/Page/Navbar/Button.php | 18 ++ .../Container/Tab/Page/Navbar/Entry.php | 18 ++ .../History/Container/Navbar/Button.php | 18 ++ .../History/Container/Navbar/Entry.php | 18 ++ .../Entity/HeaderBar.php} | 20 +-- .../Window/Tab/Address/Navbar/Button.php | 18 -- .../Window/Tab/Address/Navbar/Entry.php | 18 -- .../Window/Tab/History/Navbar/Button.php | 18 -- .../Window/Tab/History/Navbar/Entry.php | 18 -- src/Entity/{Window.php => Browser.php} | 23 +-- src/Entity/Browser/Container.php | 47 ++++++ src/Entity/Browser/Container/Tab.php | 97 +++++++++++ src/Entity/Browser/Container/Tab/Page.php | 89 ++++++++++ .../Container/Tab/Page/Content.php} | 156 ++++++++---------- .../Container/Tab/Page/Content/Data.php} | 30 +++- .../Container/Tab/Page}/Navbar.php | 73 ++++---- .../Container/Tab/Page}/Navbar/Base.php | 12 +- .../Container/Tab/Page}/Navbar/Go.php | 6 +- .../Container/Tab/Page}/Navbar/History.php | 28 ++-- .../Tab/Page}/Navbar/History/Back.php | 15 +- .../Tab/Page}/Navbar/History/Forward.php | 15 +- .../Container/Tab/Page}/Navbar/Request.php | 10 +- .../Container/Tab/Page}/Statusbar.php | 16 +- .../Container/Tab/Page}/Title.php | 13 +- src/Entity/Browser/Header.php | 10 ++ src/Entity/Browser/History.php | 63 +++++++ src/Entity/Browser/History/Container.php | 59 +++++++ .../History/Container}/Content.php | 67 ++++---- .../Browser/History/Container/Navbar.php | 104 ++++++++++++ .../History/Container/Navbar/Delete.php | 33 ++++ .../History/Container}/Navbar/Filter.php | 8 +- .../Browser/History/Container/Navbar/Open.php | 28 ++++ .../History/Container/Navbar/Search.php | 20 +++ src/Entity/Browser/History/Header.php | 10 ++ src/Entity/Window/Tab.php | 109 ------------ src/Entity/Window/Tab/Address/Content.php | 45 ----- .../Window/Tab/Address/Content/Plain.php | 54 ------ src/Entity/Window/Tab/History.php | 74 --------- src/Entity/Window/Tab/History/Navbar.php | 99 ----------- .../Window/Tab/History/Navbar/Delete.php | 30 ---- src/Entity/Window/Tab/History/Navbar/Open.php | 31 ---- .../Window/Tab/History/Navbar/Search.php | 28 ---- src/Entity/Window/Tab/History/Title.php | 46 ------ src/Model/Database.php | 2 +- src/Yoda.php | 15 +- 45 files changed, 900 insertions(+), 829 deletions(-) create mode 100644 src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Button.php create mode 100644 src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Entry.php create mode 100644 src/Abstract/Entity/Browser/History/Container/Navbar/Button.php create mode 100644 src/Abstract/Entity/Browser/History/Container/Navbar/Entry.php rename src/{Entity/Window/Header.php => Abstract/Entity/HeaderBar.php} (62%) delete mode 100644 src/Abstract/Entity/Window/Tab/Address/Navbar/Button.php delete mode 100644 src/Abstract/Entity/Window/Tab/Address/Navbar/Entry.php delete mode 100644 src/Abstract/Entity/Window/Tab/History/Navbar/Button.php delete mode 100644 src/Abstract/Entity/Window/Tab/History/Navbar/Entry.php rename src/Entity/{Window.php => Browser.php} (65%) create mode 100644 src/Entity/Browser/Container.php create mode 100644 src/Entity/Browser/Container/Tab.php create mode 100644 src/Entity/Browser/Container/Tab/Page.php rename src/Entity/{Window/Tab/Address.php => Browser/Container/Tab/Page/Content.php} (59%) rename src/Entity/{Window/Tab/Address/Content/Gemtext.php => Browser/Container/Tab/Page/Content/Data.php} (88%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar.php (52%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/Base.php (75%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/Go.php (66%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/History.php (61%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/History/Back.php (52%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/History/Forward.php (52%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Navbar/Request.php (52%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Statusbar.php (76%) rename src/Entity/{Window/Tab/Address => Browser/Container/Tab/Page}/Title.php (65%) create mode 100644 src/Entity/Browser/Header.php create mode 100644 src/Entity/Browser/History.php create mode 100644 src/Entity/Browser/History/Container.php rename src/Entity/{Window/Tab/History => Browser/History/Container}/Content.php (73%) create mode 100644 src/Entity/Browser/History/Container/Navbar.php create mode 100644 src/Entity/Browser/History/Container/Navbar/Delete.php rename src/Entity/{Window/Tab/History => Browser/History/Container}/Navbar/Filter.php (59%) create mode 100644 src/Entity/Browser/History/Container/Navbar/Open.php create mode 100644 src/Entity/Browser/History/Container/Navbar/Search.php create mode 100644 src/Entity/Browser/History/Header.php delete mode 100644 src/Entity/Window/Tab.php delete mode 100644 src/Entity/Window/Tab/Address/Content.php delete mode 100644 src/Entity/Window/Tab/Address/Content/Plain.php delete mode 100644 src/Entity/Window/Tab/History.php delete mode 100644 src/Entity/Window/Tab/History/Navbar.php delete mode 100644 src/Entity/Window/Tab/History/Navbar/Delete.php delete mode 100644 src/Entity/Window/Tab/History/Navbar/Open.php delete mode 100644 src/Entity/Window/Tab/History/Navbar/Search.php delete mode 100644 src/Entity/Window/Tab/History/Title.php diff --git a/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Button.php b/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Button.php new file mode 100644 index 00000000..4e857d71 --- /dev/null +++ b/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Button.php @@ -0,0 +1,18 @@ +navbar = $navbar; + } +} diff --git a/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Entry.php b/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Entry.php new file mode 100644 index 00000000..1d4e4634 --- /dev/null +++ b/src/Abstract/Entity/Browser/Container/Tab/Page/Navbar/Entry.php @@ -0,0 +1,18 @@ +navbar = $navbar; + } +} diff --git a/src/Abstract/Entity/Browser/History/Container/Navbar/Button.php b/src/Abstract/Entity/Browser/History/Container/Navbar/Button.php new file mode 100644 index 00000000..54ca9c9e --- /dev/null +++ b/src/Abstract/Entity/Browser/History/Container/Navbar/Button.php @@ -0,0 +1,18 @@ +navbar = $navbar; + } +} diff --git a/src/Abstract/Entity/Browser/History/Container/Navbar/Entry.php b/src/Abstract/Entity/Browser/History/Container/Navbar/Entry.php new file mode 100644 index 00000000..f3cca0b7 --- /dev/null +++ b/src/Abstract/Entity/Browser/History/Container/Navbar/Entry.php @@ -0,0 +1,18 @@ +navbar = $navbar; + } +} diff --git a/src/Entity/Window/Header.php b/src/Abstract/Entity/HeaderBar.php similarity index 62% rename from src/Entity/Window/Header.php rename to src/Abstract/Entity/HeaderBar.php index 865e27f3..8d69e6c3 100644 --- a/src/Entity/Window/Header.php +++ b/src/Abstract/Entity/HeaderBar.php @@ -2,30 +2,24 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window; +namespace Yggverse\Yoda\Abstract\Entity; -class Header +abstract class HeaderBar { public \GtkHeaderBar $gtk; - public \Yggverse\Yoda\Entity\Window $window; - - // Defaults - private bool $_actions = true; - private string $_title = 'Yoda'; - - public function __construct( - \Yggverse\Yoda\Entity\Window $window - ) { - $this->window = $window; + protected bool $_actions = true; + protected string $_title = 'Yoda'; + public function __construct() + { $this->gtk = new \GtkHeaderBar; $this->gtk->set_show_close_button( $this->_actions ); - $this->setTitle( + $this->gtk->set_title( $this->_title ); } diff --git a/src/Abstract/Entity/Window/Tab/Address/Navbar/Button.php b/src/Abstract/Entity/Window/Tab/Address/Navbar/Button.php deleted file mode 100644 index 89e8e3ed..00000000 --- a/src/Abstract/Entity/Window/Tab/Address/Navbar/Button.php +++ /dev/null @@ -1,18 +0,0 @@ -navbar = $navbar; - } -} diff --git a/src/Abstract/Entity/Window/Tab/Address/Navbar/Entry.php b/src/Abstract/Entity/Window/Tab/Address/Navbar/Entry.php deleted file mode 100644 index ccf2321e..00000000 --- a/src/Abstract/Entity/Window/Tab/Address/Navbar/Entry.php +++ /dev/null @@ -1,18 +0,0 @@ -navbar = $navbar; - } -} diff --git a/src/Abstract/Entity/Window/Tab/History/Navbar/Button.php b/src/Abstract/Entity/Window/Tab/History/Navbar/Button.php deleted file mode 100644 index 31f0d508..00000000 --- a/src/Abstract/Entity/Window/Tab/History/Navbar/Button.php +++ /dev/null @@ -1,18 +0,0 @@ -navbar = $navbar; - } -} diff --git a/src/Abstract/Entity/Window/Tab/History/Navbar/Entry.php b/src/Abstract/Entity/Window/Tab/History/Navbar/Entry.php deleted file mode 100644 index 4a31ad12..00000000 --- a/src/Abstract/Entity/Window/Tab/History/Navbar/Entry.php +++ /dev/null @@ -1,18 +0,0 @@ -navbar = $navbar; - } -} diff --git a/src/Entity/Window.php b/src/Entity/Browser.php similarity index 65% rename from src/Entity/Window.php rename to src/Entity/Browser.php index 161cc241..9519910b 100644 --- a/src/Entity/Window.php +++ b/src/Entity/Browser.php @@ -4,29 +4,32 @@ declare(strict_types=1); namespace Yggverse\Yoda\Entity; -use \Yggverse\Yoda\Entity\Window\Header; -use \Yggverse\Yoda\Entity\Window\Tab; +use \Yggverse\Yoda\Entity\Browser\Header; +use \Yggverse\Yoda\Entity\Browser\Container; -class Window +class Browser { public \GtkWindow $gtk; + // Dependencies public \Yggverse\Yoda\Model\Database $database; - public \Yggverse\Yoda\Entity\Window\Header $header; - public \Yggverse\Yoda\Entity\Window\Tab $tab; + // Requirements + public \Yggverse\Yoda\Entity\Browser\Header $header; + public \Yggverse\Yoda\Entity\Browser\Container $container; // Defaults private int $_width = 640; private int $_height = 480; - private bool $_maximize = true; public function __construct( \Yggverse\Yoda\Model\Database $database ) { + // Init dependencies $this->database = $database; + // Init window $this->gtk = new \GtkWindow; $this->gtk->set_size_request( @@ -39,6 +42,7 @@ class Window $this->gtk->maximize(); } + // Init header $this->header = new Header( $this ); @@ -47,14 +51,13 @@ class Window $this->header->gtk ); - $this->tab = new Tab( + // Init container + $this->container = new Container( $this ); $this->gtk->add( - $this->tab->gtk + $this->container->gtk ); - - $this->gtk->show_all(); } } \ No newline at end of file diff --git a/src/Entity/Browser/Container.php b/src/Entity/Browser/Container.php new file mode 100644 index 00000000..4c553788 --- /dev/null +++ b/src/Entity/Browser/Container.php @@ -0,0 +1,47 @@ +browser = $browser; + + // Init container + $this->gtk = new \GtkBox( + \GtkOrientation::VERTICAL + ); + + // Init tab + $this->tab = new Tab( + $this + ); + + $this->gtk->pack_start( + $this->tab->gtk, + true, + true, + 0 + ); + } + + public function refresh() + { + // @TODO + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab.php b/src/Entity/Browser/Container/Tab.php new file mode 100644 index 00000000..efea51f9 --- /dev/null +++ b/src/Entity/Browser/Container/Tab.php @@ -0,0 +1,97 @@ +container = $container; + + // Init container + $this->gtk = new \GtkNotebook; + + $this->gtk->set_scrollable( + $this->_scrollable + ); + + // Init previous session @TODO + $this->append(); + $this->append(); + + // Connect events + $this->gtk->connect( + 'switch-page', + function ( + \GtkNotebook $entity, + \GtkWidget $child, + int $position + ) { + $this->container->browser->header->setTitle( + $entity->get_tab_label( + $child + )->get_text() + ); + } + ); + } + + public function append( + ?string $request = null, + bool $focus = true + ): void + { + $page = new \Yggverse\Yoda\Entity\Browser\Container\Tab\Page( + $this + ); + + if ($request) + { + $page->navbar->request->setValue( + $request + ); + + $page->content->update(); + } + + $this->gtk->append_page( + $page->gtk, + $page->title->gtk + ); + + $this->gtk->set_tab_reorderable( + $page->gtk, + $this->_reorderable + ); + + if ($focus) + { + // Focus on appended tab + $this->gtk->set_current_page( + $this->gtk->page_num( + $page->gtk + ) + ); + + // Update application title + $this->container->browser->header->setTitle( + $page->title->gtk->get_text() + ); + } + + $this->gtk->show_all(); + } +} \ No newline at end of file diff --git a/src/Entity/Browser/Container/Tab/Page.php b/src/Entity/Browser/Container/Tab/Page.php new file mode 100644 index 00000000..f4178f8c --- /dev/null +++ b/src/Entity/Browser/Container/Tab/Page.php @@ -0,0 +1,89 @@ +tab = $tab; + + // Init container + $this->gtk = new \GtkBox( + \GtkOrientation::VERTICAL + ); + + // Init title + $this->title = new Title( + $this + ); + + // Init navbar + $this->navbar = new Navbar( + $this + ); + + $this->gtk->add( + $this->navbar->gtk + ); + + // Init content + $this->content = new Content( + $this + ); + + $this->gtk->pack_start( + $this->content->gtk, + true, + true, + 0 + ); + + // Init statusbar + $this->statusbar = new Statusbar( + $this + ); + + $this->gtk->add( + $this->statusbar->gtk + ); + } + + public function refresh(): void + { + $this->navbar->refresh(); + $this->content->refresh(); + $this->statusbar->refresh(); + } + + public function update( + bool $history = true + ): void + { + // @TODO navbar + + $this->content->update( + $history + ); + } +} \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address.php b/src/Entity/Browser/Container/Tab/Page/Content.php similarity index 59% rename from src/Entity/Window/Tab/Address.php rename to src/Entity/Browser/Container/Tab/Page/Content.php index c88b4e2a..884f3bc9 100644 --- a/src/Entity/Window/Tab/Address.php +++ b/src/Entity/Browser/Container/Tab/Page/Content.php @@ -2,101 +2,84 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Title; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Content; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Statusbar; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content\Data; -class Address +class Content { - public \GtkBox $gtk; + public \GtkScrolledWindow $gtk; - public \Yggverse\Yoda\Entity\Window\Tab $tab; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Title $title; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar $navbar; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Content $content; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Statusbar $statusbar; + // Requirements + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content\Data $data; + + // Defaults + private int $_margin = 8; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab $tab + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page ) { - $this->tab = $tab; - - $this->title = new Title( - $this - ); - - $this->gtk = new \GtkBox( - \GtkOrientation::VERTICAL - ); - - $this->navbar = new Navbar( - $this - ); + $this->page = $page; - $this->gtk->add( - $this->navbar->gtk - ); + // Init container + $this->gtk = new \GtkScrolledWindow; - $this->content = new Content( - $this + $this->gtk->set_margin_start( + $this->_margin ); - $this->gtk->pack_start( - $this->content->gtk, - true, - true, - 0 + $this->gtk->set_margin_end( + $this->_margin ); - $this->statusbar = new Statusbar( + // Init label + $this->data = new Data( $this ); $this->gtk->add( - $this->statusbar->gtk + $this->data->gtk ); } + public function refresh() + { + // @TODO + } + public function update( bool $history = true ): void { // Parse address $address = new \Yggverse\Net\Address( - $this->navbar->request->gtk->get_text() + $this->page->navbar->request->gtk->get_text() ); // Update title - $this->title->setValue( + $this->page->title->setValue( $address->getHost() ); - // Update navbar elements - $this->navbar->base->refresh(); - if ($history) { // Remember address in the navigation memory - $this->navbar->history->add( + $this->page->navbar->history->add( $address->get() ); // Refresh history in database - $this->navbar->address->tab->window->database->refreshHistory( + $this->page->tab->container->browser->database->renewHistory( $address->get(), // @TODO title ); - - // Refresh tabs - $this->navbar->address->tab->refresh(); } // Update statusbar indicator - $this->statusbar->setValue( + $this->page->statusbar->setValue( 'Loading...' ); @@ -119,7 +102,7 @@ class Address $title = null; - $this->content->data->setValue( + $this->data->setGemtext( file_get_contents( // @TODO format relative links $address->getPath() ), @@ -128,12 +111,12 @@ class Address if ($title) // detect title by document h1 { - $this->title->setValue( + $this->page->title->setValue( $title ); } - $this->statusbar->setValue( + $this->page->statusbar->setValue( null ); @@ -141,15 +124,15 @@ class Address default: - $this->title->setValue( + $this->page->title->setValue( 'Oops!' ); - $this->content->data->setValue( + $this->data->setPlain( 'File extension not supported' ); - $this->statusbar->setValue( + $this->page->statusbar->setValue( null ); } @@ -157,15 +140,15 @@ class Address else { - $this->title->setValue( + $this->page->title->setValue( 'Failure' ); - $this->content->data->setValue( + $this->data->setPlain( 'Could not open file' ); - $this->statusbar->setValue( + $this->page->statusbar->setValue( 'Resource not found or not readable' ); } @@ -196,14 +179,14 @@ class Address $title = null; - $this->content->data->setValue( - $response->getBody(), + $this->data->setGemtext( + $response->getContainer(), $title ); if ($title) // detect title by document h1 { - $this->title->setValue( + $this->page->title->setValue( $title ); } @@ -212,34 +195,34 @@ class Address default: - $this->content->data->setValue( - $response->getBody() + $this->data->setPlain( + $response->getContainer() ); } - $this->statusbar->setValue( + $this->page->statusbar->setValue( $response->getMeta() ); } else { - $this->title->setValue( + $this->page->title->setValue( 'Failure' ); - $this->content->data->setValue( + $this->data->setPlain( + 'Resource not available!' + ); + + $this->page->statusbar->setValue( sprintf( - 'Resource not available (code %d)', + 'code %d', intval( $response->getCode() ) ) ); - - $this->statusbar->setValue( - 'Request failed' - ); } break; @@ -250,30 +233,32 @@ class Address $address = new \Yggverse\Net\Address( sprintf( 'gemini://%s', - $this->navbar->request->gtk->get_text() + trim( + $this->page->navbar->request->gtk->get_text() + ) ) ); - // Hostname request + // Is hostname request if (filter_var( $address->getHost(), FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME ) ) { - $this->navbar->request->setValue( + $this->page->navbar->request->setValue( $address->get() ); } - // Search request + // Is search request else { - $this->navbar->request->setValue( + $this->page->navbar->request->setValue( sprintf( 'gemini://tlgs.one/search?%s', // @TODO custom provider urlencode( - $this->navbar->request->gtk->get_text() + $this->page->navbar->request->gtk->get_text() ) ) ); @@ -285,28 +270,19 @@ class Address default: - $this->title->setValue( + $this->page->title->setValue( 'Oops!' ); - $this->content->data->setValue( - sprintf( - 'Protocol not supported', - intval( - $response->getCode() - ) - ) + $this->data->setPlain( + 'Protocol not supported!' ); - $this->statusbar->setValue( + $this->page->statusbar->setValue( null ); } - $this->tab->window->header->setTitle( - $this->title->gtk->get_text() - ); - $this->gtk->show_all(); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Content/Gemtext.php b/src/Entity/Browser/Container/Tab/Page/Content/Data.php similarity index 88% rename from src/Entity/Window/Tab/Address/Content/Gemtext.php rename to src/Entity/Browser/Container/Tab/Page/Content/Data.php index e3a9ac79..0471ef2e 100644 --- a/src/Entity/Window/Tab/Address/Content/Gemtext.php +++ b/src/Entity/Browser/Container/Tab/Page/Content/Data.php @@ -2,25 +2,28 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Content; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content; use \Yggverse\Gemtext\Document; use \Yggverse\Net\Address; -class Gemtext +class Data { public \GtkLabel $gtk; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Content $content; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content; // Defaults private string $_value = ''; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\Address\Content $content + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Content $content ) { + // Init dependency $this->content = $content; + // Init markup label $this->gtk = new \GtkLabel; $this->gtk->set_use_markup( @@ -43,7 +46,7 @@ class Gemtext 0 ); - $this->setValue( + $this->setPlain( $this->_value ); @@ -53,18 +56,27 @@ class Gemtext \GtkLabel $label, string $href ) { - $this->content->address->navbar->request->setValue( + $this->content->page->navbar->request->setValue( $this->_url( $href ) ); - $this->content->address->update(); + $this->content->page->update(); } ); } - public function setValue( + public function setPlain( + string $value + ): void + { + $this->gtk->set_text( + $value + ); + } + + public function setGemtext( string $value, string | null &$title = null ): void @@ -221,7 +233,7 @@ class Gemtext { $address->toAbsolute( new Address( - $this->content->address->navbar->request->gtk->get_text() + $this->content->page->navbar->request->gtk->get_text() ) ); } diff --git a/src/Entity/Window/Tab/Address/Navbar.php b/src/Entity/Browser/Container/Tab/Page/Navbar.php similarity index 52% rename from src/Entity/Window/Tab/Address/Navbar.php rename to src/Entity/Browser/Container/Tab/Page/Navbar.php index c63c363a..25a287ab 100644 --- a/src/Entity/Window/Tab/Address/Navbar.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar.php @@ -2,38 +2,57 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Base; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Go; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Request; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Base; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Go; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Request; class Navbar { public \GtkBox $gtk; - public \Yggverse\Yoda\Entity\Window\Tab\Address $address; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Base $base; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Go $go; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History $history; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\Request $request; + // Requirements + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Base $base; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Go $go; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History $history; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\Request $request; // Defaults private int $_margin = 8; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\Address $address + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page ) { - $this->address = $address; + // Init dependencies + $this->page = $page; - // Init navbar area + // Init navbar $this->gtk = new \GtkBox( \GtkOrientation::HORIZONTAL ); - $this->setMargins( + $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_spacing( $this->_margin ); @@ -77,28 +96,10 @@ class Navbar ); } - public function setMargins( - ?int $value - ): void + public function refresh() { - $this->gtk->set_margin_top( - $value ?? $this->_margin - ); - - $this->gtk->set_margin_bottom( - $value ?? $this->_margin - ); - - $this->gtk->set_margin_start( - $value ?? $this->_margin - ); - - $this->gtk->set_margin_end( - $value ?? $this->_margin - ); - - $this->gtk->set_spacing( - $value ?? $this->_margin - ); + $this->base->refresh(); + $this->go->refresh(); + $this->history->refresh(); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/Base.php b/src/Entity/Browser/Container/Tab/Page/Navbar/Base.php similarity index 75% rename from src/Entity/Window/Tab/Address/Navbar/Base.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/Base.php index e5d59a7c..c22402e7 100644 --- a/src/Entity/Window/Tab/Address/Navbar/Base.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/Base.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; -class Base extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Button +class Base extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Tab\Page\Navbar\Button { protected string $_label = 'Base'; @@ -13,7 +13,11 @@ class Base extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Butt ): void { $address = new \Yggverse\Net\Address( - $this->navbar->request->gtk->get_text() + trim( + strval( + $this->navbar->request->gtk->get_text() + ) + ) ); if ($address->getHost()) @@ -46,7 +50,7 @@ class Base extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Butt ) ); - $this->navbar->base->gtk->set_sensitive( + $this->gtk->set_sensitive( $address->getHost() && ( $address->getPath() || $address->getQuery() ) diff --git a/src/Entity/Window/Tab/Address/Navbar/Go.php b/src/Entity/Browser/Container/Tab/Page/Navbar/Go.php similarity index 66% rename from src/Entity/Window/Tab/Address/Navbar/Go.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/Go.php index 901b40c8..d09408d4 100644 --- a/src/Entity/Window/Tab/Address/Navbar/Go.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/Go.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; -class Go extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Button +class Go extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Tab\Page\Navbar\Button { protected string $_label = 'Go'; @@ -12,7 +12,7 @@ class Go extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Button \GtkButton $entity ): void { - $this->navbar->address->update(); + $this->navbar->page->update(); } public function refresh(): void diff --git a/src/Entity/Window/Tab/Address/Navbar/History.php b/src/Entity/Browser/Container/Tab/Page/Navbar/History.php similarity index 61% rename from src/Entity/Window/Tab/Address/Navbar/History.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/History.php index b4449731..97e6abb7 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/History.php @@ -2,23 +2,26 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Back; -use \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Forward; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History\Back; +use \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History\Forward; class History { public \GtkButtonBox $gtk; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar $navbar; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Back $back; - public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Forward $forward; - + // Dependencies public \Yggverse\Yoda\Model\History $memory; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar; + + // Requirements + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History\Back $back; + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History\Forward $forward; + public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar $navbar + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar $navbar ) { $this->memory = new \Yggverse\Yoda\Model\History(); @@ -70,12 +73,7 @@ class History public function refresh(): void { - $this->back->gtk->set_sensitive( - (bool) $this->memory->getBack() - ); - - $this->forward->gtk->set_sensitive( - (bool) $this->memory->getForward() - ); + $this->back->refresh(); + $this->forward->refresh(); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/History/Back.php b/src/Entity/Browser/Container/Tab/Page/Navbar/History/Back.php similarity index 52% rename from src/Entity/Window/Tab/Address/Navbar/History/Back.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/History/Back.php index 509f363b..04e96bac 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History/Back.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/History/Back.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History; -class Back extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Button +class Back extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Tab\Page\Navbar\Button { protected string $_label = 'Back'; @@ -18,11 +18,20 @@ class Back extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Butt $this->navbar->history->memory->goBack() ); - $this->navbar->address->update( + $this->navbar->page->update( false ); } $this->navbar->history->refresh(); } + + public function refresh(): void + { + $this->gtk->set_sensitive( + boolval( + $this->navbar->history->memory->getBack() + ) + ); + } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/History/Forward.php b/src/Entity/Browser/Container/Tab/Page/Navbar/History/Forward.php similarity index 52% rename from src/Entity/Window/Tab/Address/Navbar/History/Forward.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/History/Forward.php index 17750d8e..359692aa 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History/Forward.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/History/Forward.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar\History; -class Forward extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Button +class Forward extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Tab\Page\Navbar\Button { protected string $_label = 'Forward'; @@ -18,11 +18,20 @@ class Forward extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\B $this->navbar->history->memory->goForward() ); - $this->navbar->address->update( + $this->navbar->page->update( false ); } $this->navbar->history->refresh(); } + + public function refresh(): void + { + $this->gtk->set_sensitive( + boolval( + $this->navbar->history->memory->getForward() + ) + ); + } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/Request.php b/src/Entity/Browser/Container/Tab/Page/Navbar/Request.php similarity index 52% rename from src/Entity/Window/Tab/Address/Navbar/Request.php rename to src/Entity/Browser/Container/Tab/Page/Navbar/Request.php index 66205a97..447ecbfa 100644 --- a/src/Entity/Window/Tab/Address/Navbar/Request.php +++ b/src/Entity/Browser/Container/Tab/Page/Navbar/Request.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address\Navbar; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page\Navbar; -class Request extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Entry +class Request extends \Yggverse\Yoda\Abstract\Entity\Browser\Container\Tab\Page\Navbar\Entry { private string $_placeholder = 'URL or search term...'; @@ -12,7 +12,7 @@ class Request extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\E \GtkEntry $entry ): void { - $this->navbar->address->update(); + $this->navbar->page->content->update(); } protected function _onKeyRelease( @@ -20,8 +20,6 @@ class Request extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\E \GdkEvent $event ): void { - $this->navbar->base->refresh(); - - $this->navbar->go->refresh(); + $this->navbar->refresh(); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Statusbar.php b/src/Entity/Browser/Container/Tab/Page/Statusbar.php similarity index 76% rename from src/Entity/Window/Tab/Address/Statusbar.php rename to src/Entity/Browser/Container/Tab/Page/Statusbar.php index f72871d1..2861db7f 100644 --- a/src/Entity/Window/Tab/Address/Statusbar.php +++ b/src/Entity/Browser/Container/Tab/Page/Statusbar.php @@ -2,23 +2,26 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; class Statusbar { public \GtkLabel $gtk; - public \Yggverse\Yoda\Entity\Window\Tab\Address $address; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; // Defaults private int $_margin = 8; private string $_value = ''; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\Address $address + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page ) { - $this->address = $address; + // Init dependency + $this->page = $page; + // Init container $this->gtk = new \GtkLabel; $this->gtk->set_use_markup( @@ -72,4 +75,9 @@ class Statusbar ) ); } + + public function refresh() + { + // @TODO + } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Title.php b/src/Entity/Browser/Container/Tab/Page/Title.php similarity index 65% rename from src/Entity/Window/Tab/Address/Title.php rename to src/Entity/Browser/Container/Tab/Page/Title.php index 27ae629f..a94f7654 100644 --- a/src/Entity/Window/Tab/Address/Title.php +++ b/src/Entity/Browser/Container/Tab/Page/Title.php @@ -2,24 +2,27 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\Address; +namespace Yggverse\Yoda\Entity\Browser\Container\Tab\Page; class Title { public \GtkLabel $gtk; - public \Yggverse\Yoda\Entity\Window\Tab\Address $address; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page; // Defaults private int $_ellipsize = 3; private int $_length = 12; - private string $_value = 'New address'; + private string $_value = 'New page'; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\Address $address, + \Yggverse\Yoda\Entity\Browser\Container\Tab\Page $page, ) { - $this->address = $address; + // Init dependencies + $this->page = $page; + // Init container $this->gtk = new \GtkLabel( $this->_value ); diff --git a/src/Entity/Browser/Header.php b/src/Entity/Browser/Header.php new file mode 100644 index 00000000..f2998e64 --- /dev/null +++ b/src/Entity/Browser/Header.php @@ -0,0 +1,10 @@ +browser = $browser; + + // Init window + $this->gtk = new \GtkWindow; + + $this->gtk->set_size_request( + $this->_width, + $this->_height + ); + + if ($this->_maximize) + { + $this->gtk->maximize(); + } + + // Init header + $this->header = new Header( + $this + ); + + $this->gtk->set_titlebar( + $this->header->gtk + ); + + // Init container + $this->container = new Container( + $this + ); + + $this->gtk->add( + $this->container->gtk + ); + } +} \ No newline at end of file diff --git a/src/Entity/Browser/History/Container.php b/src/Entity/Browser/History/Container.php new file mode 100644 index 00000000..f4ef0464 --- /dev/null +++ b/src/Entity/Browser/History/Container.php @@ -0,0 +1,59 @@ +history = $history; + + // Init container + $this->gtk = new \GtkBox( + \GtkOrientation::VERTICAL + ); + + // Init navbar + $this->navbar = new Navbar( + $this + ); + + $this->gtk->add( + $this->navbar->gtk + ); + + // Init content + $this->content = new Content( + $this + ); + + $this->gtk->pack_start( + $this->content->gtk, + true, + true, + 0 + ); + } + + public function refresh() + { + $this->navbar->refresh(); + $this->content->refresh(); + } +} \ No newline at end of file diff --git a/src/Entity/Window/Tab/History/Content.php b/src/Entity/Browser/History/Container/Content.php similarity index 73% rename from src/Entity/Window/Tab/History/Content.php rename to src/Entity/Browser/History/Container/Content.php index 29142772..39e52aa6 100644 --- a/src/Entity/Window/Tab/History/Content.php +++ b/src/Entity/Browser/History/Container/Content.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\History; - -use \Yggverse\Yoda\Entity\Window\Tab\Address; +namespace Yggverse\Yoda\Entity\Browser\History\Container; class Content { public \GtkScrolledWindow $gtk; + // Requirements @TODO entity public \GtkTreeView $treeview; public \GtkListStore $list; - public \Yggverse\Yoda\Entity\Window\Tab\History $history; + // Dependencies + public \Yggverse\Yoda\Entity\Browser\History\Container $container; // Defaults private string $_time = 'Time'; @@ -23,22 +23,25 @@ class Content private int $_margin = 8; public function __construct( - \Yggverse\Yoda\Entity\Window\Tab\History $history + \Yggverse\Yoda\Entity\Browser\History\Container $container ) { - $this->history = $history; + // Init dependency + $this->container = $container; + // Init container $this->gtk = new \GtkScrolledWindow; - $this->gtk->set_margin_start( + // Init records listing + $this->treeview = new \GtkTreeView; + + $this->treeview->set_margin_start( $this->_margin ); - $this->gtk->set_margin_end( + $this->treeview->set_margin_end( $this->_margin ); - $this->treeview = new \GtkTreeView; - $this->treeview->append_column( new \GtkTreeViewColumn( $this->_time, @@ -81,26 +84,15 @@ class Content $this->treeview ); - $this->search(); - + // Connect events $this->treeview->connect( 'row-activated', function( \GtkTreeView $treeview ) { - $address = new Address( - $this->history->tab - ); - - $address->navbar->request->setValue( + $this->container->history->browser->container->tab->append( $this->getSelectedUrl() ); - - $this->history->tab->append( - $address - ); - - $address->update(); } ); @@ -109,17 +101,25 @@ class Content function( \GtkTreeView $treeview ) { - $this->history->navbar->open->gtk->set_sensitive( - (bool) $this->getSelectedId() + $this->container->navbar->open->gtk->set_sensitive( + boolval( + $this->getSelectedId() + ) ); - $this->history->navbar->delete->gtk->set_sensitive( - (bool) $this->getSelectedId() + $this->container->navbar->delete->gtk->set_sensitive( + boolval( + $this->getSelectedId() + ) ); } ); + + // Make initial search + $this->search(); } + // Append new row public function append( int $id, int $time, @@ -142,25 +142,28 @@ class Content ); } + // Remove rows from list public function clear(): void { $this->list->clear(); } - public function update(): void + // Refresh rows using current navbar value + public function refresh(): void { $this->search( - $this->history->navbar->filter->gtk->get_text() + $this->container->navbar->filter->gtk->get_text() ); } + // Do records search in database public function search( string $filter = '' ): void { $this->clear(); - if ($records = $this->history->tab->window->database->findHistory($filter)) + if ($records = $this->container->history->browser->database->findHistory($filter)) { foreach ($records as $record) { @@ -175,11 +178,11 @@ class Content else { - $this->history->navbar->open->gtk->set_sensitive( + $this->container->navbar->open->gtk->set_sensitive( false ); - $this->history->navbar->delete->gtk->set_sensitive( + $this->container->navbar->delete->gtk->set_sensitive( false ); } diff --git a/src/Entity/Browser/History/Container/Navbar.php b/src/Entity/Browser/History/Container/Navbar.php new file mode 100644 index 00000000..d7638aa7 --- /dev/null +++ b/src/Entity/Browser/History/Container/Navbar.php @@ -0,0 +1,104 @@ +container = $container; + + // Init container + $this->gtk = new \GtkBox( + \GtkOrientation::HORIZONTAL + ); + + $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_spacing( + $this->_margin + ); + + // Init open button + $this->open = new Open( + $this + ); + + $this->gtk->add( + $this->open->gtk + ); + + // Init delete button + $this->delete = new Delete( + $this + ); + + $this->gtk->add( + $this->delete->gtk + ); + + // Init filter entry + $this->filter = new Filter( + $this + ); + + $this->gtk->pack_start( + $this->filter->gtk, + true, + true, + 0 + ); + + // Init search button + $this->search = new Search( + $this + ); + + $this->gtk->add( + $this->search->gtk + ); + } + + public function refresh(): void + { + $this->delete->refresh(); + $this->open->refresh(); + } +} \ No newline at end of file diff --git a/src/Entity/Browser/History/Container/Navbar/Delete.php b/src/Entity/Browser/History/Container/Navbar/Delete.php new file mode 100644 index 00000000..d58f9215 --- /dev/null +++ b/src/Entity/Browser/History/Container/Navbar/Delete.php @@ -0,0 +1,33 @@ +navbar->container->content->getSelectedId()) + { + $this->navbar->container->history->browser->database->deleteHistory( + $id + ); + } + + $this->navbar->container->refresh(); + } + + public function refresh(): void + { + $this->gtk->set_sensitive( + boolval( + $this->navbar->container->content->getSelectedId() + ) + ); + } +} diff --git a/src/Entity/Window/Tab/History/Navbar/Filter.php b/src/Entity/Browser/History/Container/Navbar/Filter.php similarity index 59% rename from src/Entity/Window/Tab/History/Navbar/Filter.php rename to src/Entity/Browser/History/Container/Navbar/Filter.php index 5ed87d23..a33765ac 100644 --- a/src/Entity/Window/Tab/History/Navbar/Filter.php +++ b/src/Entity/Browser/History/Container/Navbar/Filter.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Yggverse\Yoda\Entity\Window\Tab\History\Navbar; +namespace Yggverse\Yoda\Entity\Browser\History\Container\Navbar; -class Filter extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\History\Navbar\Entry +class Filter extends \Yggverse\Yoda\Abstract\Entity\Browser\History\Container\Navbar\Entry { private string $_placeholder = 'Search in history...'; @@ -12,7 +12,7 @@ class Filter extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\History\Navbar\En \GtkEntry $entry ): void { - $this->navbar->history->content->search( + $this->navbar->container->content->search( $entry->get_text() ); } @@ -22,7 +22,7 @@ class Filter extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\History\Navbar\En \GdkEvent $event ): void { - $this->navbar->history->content->search( + $this->navbar->container->content->search( $entry->get_text() ); } diff --git a/src/Entity/Browser/History/Container/Navbar/Open.php b/src/Entity/Browser/History/Container/Navbar/Open.php new file mode 100644 index 00000000..0824fda7 --- /dev/null +++ b/src/Entity/Browser/History/Container/Navbar/Open.php @@ -0,0 +1,28 @@ +navbar->container->history->browser->container->tab->append( + $this->navbar->container->content->getSelectedUrl() + ); + } + + public function refresh(): void + { + $this->gtk->set_sensitive( + boolval( + $this->navbar->container->content->getSelectedId() + ) + ); + } +} diff --git a/src/Entity/Browser/History/Container/Navbar/Search.php b/src/Entity/Browser/History/Container/Navbar/Search.php new file mode 100644 index 00000000..973444bf --- /dev/null +++ b/src/Entity/Browser/History/Container/Navbar/Search.php @@ -0,0 +1,20 @@ +navbar->container->content->search( + $this->navbar->filter->gtk->get_text() + ); + } +} diff --git a/src/Entity/Browser/History/Header.php b/src/Entity/Browser/History/Header.php new file mode 100644 index 00000000..86044c41 --- /dev/null +++ b/src/Entity/Browser/History/Header.php @@ -0,0 +1,10 @@ +window = $window; - - $this->gtk = new \GtkNotebook; - - $this->gtk->set_scrollable( - $this->_scrollable - ); - - $this->gtk->connect( - 'switch-page', - function ( - \GtkNotebook $entity, - \GtkWidget $child, - int $position - ) { - $this->window->header->setTitle( - $entity->get_tab_label( - $child - )->get_text() - ); - } - ); - - $this->append( // @TODO remove - new History( - $this - ) - ); - - $this->append( // @TODO remove - new Address( - $this - ) - ); - } - - public function append( - Address | History $entity, - ?bool $reorderable = null - ): void - { - $this->gtk->append_page( - $entity->gtk, - $entity->title->gtk - ); - - $this->gtk->set_tab_reorderable( - $entity->gtk, - is_null($reorderable) ? $this->_reorderable : $reorderable - ); - - $this->gtk->show_all(); - - // Focus on appended tab - $this->gtk->set_current_page( - $this->gtk->page_num( - $entity->gtk - ) - ); - - // Update application title - $this->window->header->setTitle( - $entity->title->gtk->get_text() - ); - - // Register new tab entity - $this->_tab[] = $entity; - } - - public function refresh() - { - foreach ($this->_tab as $entity) - { - switch (true) - { - case $entity instanceof History: - - $entity->content->update(); - - break; - } - } - } -} \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Content.php b/src/Entity/Window/Tab/Address/Content.php deleted file mode 100644 index f789f049..00000000 --- a/src/Entity/Window/Tab/Address/Content.php +++ /dev/null @@ -1,45 +0,0 @@ -address = $address; - - $this->gtk = new \GtkScrolledWindow; - - $this->gtk->set_margin_start( - $this->_margin - ); - - $this->gtk->set_margin_end( - $this->_margin - ); - - $this->data = new Gemtext( - $this - ); - - $this->gtk->add( - $this->data->gtk - ); - - $this->gtk->show_all(); - } -} \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Content/Plain.php b/src/Entity/Window/Tab/Address/Content/Plain.php deleted file mode 100644 index c2ebbbf3..00000000 --- a/src/Entity/Window/Tab/Address/Content/Plain.php +++ /dev/null @@ -1,54 +0,0 @@ -content = $content; - - $this->gtk = new \GtkLabel( - $this->_value - ); - - $this->gtk->set_use_markup( - false - ); - - $this->gtk->set_selectable( - true - ); - - $this->gtk->set_line_wrap( - true - ); - - $this->gtk->set_xalign( - 0 - ); - - $this->gtk->set_yalign( - 0 - ); - } - - public function setValue( - string $value - ): void - { - $this->gtk->set_text( - $value - ); - } -} \ No newline at end of file diff --git a/src/Entity/Window/Tab/History.php b/src/Entity/Window/Tab/History.php deleted file mode 100644 index 9cde9e74..00000000 --- a/src/Entity/Window/Tab/History.php +++ /dev/null @@ -1,74 +0,0 @@ -tab = $tab; - - $this->title = new Title( - $this - ); - - $this->gtk = new \GtkBox( - \GtkOrientation::VERTICAL - ); - - $this->navbar = new Navbar( - $this - ); - - $this->content = new Content( - $this - ); - - $this->gtk->add( - $this->navbar->gtk - ); - - $this->gtk->pack_start( - $this->content->gtk, - true, - true, - 0 - ); - } - - public function search( - ?string $filter = null - ): void - { - $this->navbar->filter->setValue( - trim( - strval( - $filter - ) - ) - ); - - $this->content->search( - trim( - strval( - $filter - ) - ) - ); - } -} \ No newline at end of file diff --git a/src/Entity/Window/Tab/History/Navbar.php b/src/Entity/Window/Tab/History/Navbar.php deleted file mode 100644 index 5cc91b86..00000000 --- a/src/Entity/Window/Tab/History/Navbar.php +++ /dev/null @@ -1,99 +0,0 @@ -history = $history; - - $this->gtk = new \GtkBox( - \GtkOrientation::HORIZONTAL - ); - - $this->setMargin( - $this->_margin - ); - - $this->open = new Open( - $this - ); - - $this->gtk->add( - $this->open->gtk - ); - - $this->delete = new Delete( - $this - ); - - $this->gtk->add( - $this->delete->gtk - ); - - $this->filter = new Filter( - $this - ); - - $this->gtk->pack_start( - $this->filter->gtk, - true, - true, - 0 - ); - - $this->search = new Search( - $this - ); - - $this->gtk->add( - $this->search->gtk - ); - } - - public function setMargin( - ?int $value = null - ): void - { - $this->gtk->set_margin_top( - $margin ?? $this->_margin - ); - - $this->gtk->set_margin_bottom( - $margin ?? $this->_margin - ); - - $this->gtk->set_margin_start( - $margin ?? $this->_margin - ); - - $this->gtk->set_margin_end( - $margin ?? $this->_margin - ); - - $this->gtk->set_spacing( - $margin ?? $this->_margin - ); - } -} \ No newline at end of file diff --git a/src/Entity/Window/Tab/History/Navbar/Delete.php b/src/Entity/Window/Tab/History/Navbar/Delete.php deleted file mode 100644 index 9ae985ef..00000000 --- a/src/Entity/Window/Tab/History/Navbar/Delete.php +++ /dev/null @@ -1,30 +0,0 @@ -navbar->history->content->getSelectedId()) - { - $this->navbar->history->tab->window->database->deleteHistory( - $id - ); - - $this->navbar->open->gtk->set_sensitive( - false - ); - - $this->navbar->history->content->search( - $this->navbar->filter->gtk->get_text() - ); - } - } -} diff --git a/src/Entity/Window/Tab/History/Navbar/Open.php b/src/Entity/Window/Tab/History/Navbar/Open.php deleted file mode 100644 index e08f8a24..00000000 --- a/src/Entity/Window/Tab/History/Navbar/Open.php +++ /dev/null @@ -1,31 +0,0 @@ -navbar->history->tab - ); - - $this->navbar->history->tab->append( // @TODO - $address - ); - - $address->navbar->request->setValue( - $this->navbar->history->content->getSelectedUrl() - ); - - $address->update(); - } -} diff --git a/src/Entity/Window/Tab/History/Navbar/Search.php b/src/Entity/Window/Tab/History/Navbar/Search.php deleted file mode 100644 index 78eea2b2..00000000 --- a/src/Entity/Window/Tab/History/Navbar/Search.php +++ /dev/null @@ -1,28 +0,0 @@ -gtk->set_sensitive( - false - ); - - $this->navbar->history->content->search( - $this->navbar->filter->gtk->get_text() - ); - - $this->gtk->set_sensitive( - true - ); - } -} diff --git a/src/Entity/Window/Tab/History/Title.php b/src/Entity/Window/Tab/History/Title.php deleted file mode 100644 index 0f9f282a..00000000 --- a/src/Entity/Window/Tab/History/Title.php +++ /dev/null @@ -1,46 +0,0 @@ -history = $history; - - $this->gtk = new \GtkLabel( - $this->_value - ); - - $this->gtk->set_width_chars( - $this->_length - ); - - $this->gtk->set_ellipsize( - $this->_ellipsize - ); - } - - public function setValue( - ?string $value = null - ): void - { - $this->gtk->set_text( - is_null($value) ? $this->_value : trim( - $value - ) - ); - } -} \ No newline at end of file diff --git a/src/Model/Database.php b/src/Model/Database.php index c59ca9c8..dff1f6cd 100644 --- a/src/Model/Database.php +++ b/src/Model/Database.php @@ -123,7 +123,7 @@ class Database return $query->rowCount(); } - public function refreshHistory( + public function renewHistory( string $url, ?string $title = null ): void diff --git a/src/Yoda.php b/src/Yoda.php index 06313871..1d849a67 100644 --- a/src/Yoda.php +++ b/src/Yoda.php @@ -23,12 +23,12 @@ $database = new \Yggverse\Yoda\Model\Database( // Init GTK \Gtk::init(); -// Init window -$window = new \Yggverse\Yoda\Entity\Window( +// Init browser +$browser = new \Yggverse\Yoda\Entity\Browser( $database ); -$window->gtk->connect( +$browser->gtk->connect( 'destroy', function() { @@ -36,4 +36,13 @@ $window->gtk->connect( } ); +$browser->gtk->show_all(); + +// Init history (test) +$history = new \Yggverse\Yoda\Entity\Browser\History( + $browser +); + +$history->gtk->show_all(); + \Gtk::main(); \ No newline at end of file