diff --git a/README.md b/README.md index 0d9684e..4cffa55 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ At this moment project under development! * [x] Custom DNS resolver with memory cache, oriented to alt networks like [Yggdrasil](https://github.com/yggdrasil-network/yggdrasil-go) * [x] Flexible settings in `config.json`, then UI * [x] Native GTK environment, no custom colors until you change it in `css` -* [ ] Page tabs +* [x] Page tabs * [ ] Local pages history snaps to make it accessible even offline * [ ] Bookmarks * [ ] Certificate features diff --git a/src/Entity/App.php b/src/Entity/App.php index b8b4125..a88ea04 100644 --- a/src/Entity/App.php +++ b/src/Entity/App.php @@ -14,9 +14,11 @@ class App public function __construct() { + // Init config $this->config = \Yggverse\Yoda\Model\File::getConfig()->app; // @TODO - $this->window = new \GtkWindow(); + // Init window + $this->window = new \GtkWindow; $this->window->set_size_request( $this->config->width, @@ -25,7 +27,7 @@ class App if ($this->config->header->enabled) { - $this->header = new \GtkHeaderBar(); + $this->header = new \GtkHeaderBar; $this->header->set_title( $this->config->header->title->default @@ -40,34 +42,72 @@ class App ); } - $this->window->connect( - 'destroy', - function() - { - \Gtk::main_quit(); - } + // Init tabs + $this->tabs = new \GtkNotebook; + + $this->tabs->set_scrollable( + true ); - $this->tabs = new \GtkNotebook(); + // + button + $blank = new \GtkLabel; - $this->tabs->set_scrollable( + $this->tabs->append_page( + $blank, + new \GtkLabel( + '+' + ) + ); + + $this->tabs->set_tab_reorderable( + $blank, true ); + // Append blank page + $page = $this->blankPage(); + + $page->open( + $this->config->tab->page->header->button->home->url // @TODO + ); + + // Render $this->window->add( $this->tabs ); - $this->openPage( - $this->config->tab->page->header->button->home->url // @TODO + $this->window->show_all(); + + // Init event listener + $this->tabs->connect( + 'switch-page', + function ($tabs, $child, $position) + { + if ('+' == $tabs->get_tab_label_text($child)) + { + $page = $this->blankPage(); + + $this->tabs->show_all(); + + $this->tabs->set_current_page( + $this->tabs->page_num( + $page->box + ) + ); + } + } ); - $this->window->show_all(); + $this->window->connect( + 'destroy', + function() + { + \Gtk::main_quit(); + } + ); } - public function openPage( - string $url - ): void + public function blankPage(): \Yggverse\Yoda\Entity\Tab\Page { $page = new \Yggverse\Yoda\Entity\Tab\Page( $this @@ -85,9 +125,15 @@ class App true ); - $page->open( - $url + $this->tabs->show_all(); + + $this->tabs->set_current_page( + $this->tabs->page_num( + $page->box + ) ); + + return $page; } public function setTitle(