From 0db319a5196cd48cf10effbc083f7a9e42cee688 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 5 Jul 2024 03:59:19 +0300 Subject: [PATCH] implement history navigation --- src/Entity/Window/Tab/Address.php | 33 +++++++++++-------- .../Window/Tab/Address/Navbar/History.php | 23 ++++++++----- .../Tab/Address/Navbar/History/Back.php | 13 +++++++- .../Tab/Address/Navbar/History/Forward.php | 13 +++++++- 4 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/Entity/Window/Tab/Address.php b/src/Entity/Window/Tab/Address.php index d6046590..71055045 100644 --- a/src/Entity/Window/Tab/Address.php +++ b/src/Entity/Window/Tab/Address.php @@ -61,7 +61,9 @@ class Address ); } - public function update(): void + public function update( + bool $history = true + ): void { // Parse address $address = new \Yggverse\Net\Address( @@ -78,19 +80,22 @@ class Address $address ); - // Remember address in the navigation memory - $this->navbar->history->add( - $address->get() - ); - - // Refresh history in database - $this->navbar->address->tab->window->database->refreshHistory( - $address->get(), - // @TODO title - ); - - // Refresh tabs - $this->navbar->address->tab->refresh(); + if ($history) + { + // Remember address in the navigation memory + $this->navbar->history->add( + $address->get() + ); + + // Refresh history in database + $this->navbar->address->tab->window->database->refreshHistory( + $address->get(), + // @TODO title + ); + + // Refresh tabs + $this->navbar->address->tab->refresh(); + } // Update statusbar indicator $this->statusbar->setValue( diff --git a/src/Entity/Window/Tab/Address/Navbar/History.php b/src/Entity/Window/Tab/Address/Navbar/History.php index bd244264..b4449731 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History.php +++ b/src/Entity/Window/Tab/Address/Navbar/History.php @@ -15,12 +15,12 @@ class History public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Back $back; public \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar\History\Forward $forward; - private \Yggverse\Yoda\Model\History $_history; + public \Yggverse\Yoda\Model\History $memory; public function __construct( \Yggverse\Yoda\Entity\Window\Tab\Address\Navbar $navbar ) { - $this->_history = new \Yggverse\Yoda\Model\History(); + $this->memory = new \Yggverse\Yoda\Model\History(); $this->navbar = $navbar; @@ -50,27 +50,32 @@ class History } public function add( - string $url + string $value ): void { - if (empty($url)) + if (empty($value)) { throw new \Exception; } - if ($url != $this->_history->getCurrent()) + if ($value != $this->memory->getCurrent()) { - $this->_history->add( - $url + $this->memory->add( + $value ); } + $this->refresh(); + } + + public function refresh(): void + { $this->back->gtk->set_sensitive( - (bool) $this->_history->getBack() + (bool) $this->memory->getBack() ); $this->forward->gtk->set_sensitive( - (bool) $this->_history->getForward() + (bool) $this->memory->getForward() ); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/History/Back.php b/src/Entity/Window/Tab/Address/Navbar/History/Back.php index 7e39d47b..509f363b 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History/Back.php +++ b/src/Entity/Window/Tab/Address/Navbar/History/Back.php @@ -12,6 +12,17 @@ class Back extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\Butt \GtkButton $entity ): void { - // @TODO + if ($this->navbar->history->memory->getBack()) + { + $this->navbar->request->setValue( + $this->navbar->history->memory->goBack() + ); + + $this->navbar->address->update( + false + ); + } + + $this->navbar->history->refresh(); } } \ No newline at end of file diff --git a/src/Entity/Window/Tab/Address/Navbar/History/Forward.php b/src/Entity/Window/Tab/Address/Navbar/History/Forward.php index 6a38af08..17750d8e 100644 --- a/src/Entity/Window/Tab/Address/Navbar/History/Forward.php +++ b/src/Entity/Window/Tab/Address/Navbar/History/Forward.php @@ -12,6 +12,17 @@ class Forward extends \Yggverse\Yoda\Abstract\Entity\Window\Tab\Address\Navbar\B \GtkButton $entity ): void { - // @TODO + if ($this->navbar->history->memory->getForward()) + { + $this->navbar->request->setValue( + $this->navbar->history->memory->goForward() + ); + + $this->navbar->address->update( + false + ); + } + + $this->navbar->history->refresh(); } } \ No newline at end of file