From 4f59b529fc2b56f0100fc00468b6bb1f7058aa07 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 24 Jul 2024 18:35:55 +0300 Subject: [PATCH] implement bookmark button --- src/Abstract/Entity/Button.php | 32 ++++++++++------ src/Entity/Browser/Container/Page/Navbar.php | 10 +++++ .../Container/Page/Navbar/Bookmark.php | 38 +++++++++++++++++++ 3 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 src/Entity/Browser/Container/Page/Navbar/Bookmark.php diff --git a/src/Abstract/Entity/Button.php b/src/Abstract/Entity/Button.php index 8ae26d07..9f60df33 100644 --- a/src/Abstract/Entity/Button.php +++ b/src/Abstract/Entity/Button.php @@ -17,17 +17,7 @@ abstract class Button { $this->gtk = new \GtkButton; - if (\GtkIconTheme::get_default()->has_icon($this::IMAGE)) - { - $this->gtk->set_image( - \GtkImage::new_from_icon_name( - $this::IMAGE, - \GtkIconSize::BUTTON - ) - ); - } - - else + if (!$this->setImage($this::IMAGE)) { $this->gtk->set_label( _($this::LABEL) @@ -61,4 +51,24 @@ abstract class Button abstract protected function _onClick( \GtkButton $entity ): void; + + public function setImage( + ?string $image = null, + int $size = \GtkIconSize::BUTTON + ): bool + { + if (\GtkIconTheme::get_default()->has_icon($image)) + { + $this->gtk->set_image( + \GtkImage::new_from_icon_name( + $image, + $size + ) + ); + + return true; + } + + return false; + } } \ No newline at end of file diff --git a/src/Entity/Browser/Container/Page/Navbar.php b/src/Entity/Browser/Container/Page/Navbar.php index e0e1eedd..7be36d26 100644 --- a/src/Entity/Browser/Container/Page/Navbar.php +++ b/src/Entity/Browser/Container/Page/Navbar.php @@ -15,6 +15,7 @@ class Navbar // Requirements public Navbar\Base $base; + public Navbar\Bookmark $bookmark; public Navbar\History $history; public Navbar\Request $request; public Navbar\Update $update; @@ -92,6 +93,15 @@ class Navbar 0 ); + // Append bookmark button + $this->bookmark = new Navbar\Bookmark( + $this + ); + + $this->gtk->add( + $this->bookmark->gtk + ); + // Render $this->gtk->show(); } diff --git a/src/Entity/Browser/Container/Page/Navbar/Bookmark.php b/src/Entity/Browser/Container/Page/Navbar/Bookmark.php new file mode 100644 index 00000000..360f3e60 --- /dev/null +++ b/src/Entity/Browser/Container/Page/Navbar/Bookmark.php @@ -0,0 +1,38 @@ +setImage( + $this->navbar->page->container->browser->database->toggleBookmark( + $this->navbar->request->getValue() + ) ? self::_IMAGE_STARRED_YES : self::_IMAGE_STARRED_NON + ); + } + + public function refresh(): void + { + $this->setImage( + $this->navbar->page->container->browser->database->getBookmark( + $this->navbar->request->getValue() + ) ? self::_IMAGE_STARRED_YES : self::_IMAGE_STARRED_NON + ); + } +} \ No newline at end of file