mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-02 17:45:28 +00:00
implement bookmark button
This commit is contained in:
parent
f77375d14c
commit
4f59b529fc
3 changed files with 69 additions and 11 deletions
|
|
@ -17,17 +17,7 @@ abstract class Button
|
||||||
{
|
{
|
||||||
$this->gtk = new \GtkButton;
|
$this->gtk = new \GtkButton;
|
||||||
|
|
||||||
if (\GtkIconTheme::get_default()->has_icon($this::IMAGE))
|
if (!$this->setImage($this::IMAGE))
|
||||||
{
|
|
||||||
$this->gtk->set_image(
|
|
||||||
\GtkImage::new_from_icon_name(
|
|
||||||
$this::IMAGE,
|
|
||||||
\GtkIconSize::BUTTON
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
$this->gtk->set_label(
|
$this->gtk->set_label(
|
||||||
_($this::LABEL)
|
_($this::LABEL)
|
||||||
|
|
@ -61,4 +51,24 @@ abstract class Button
|
||||||
abstract protected function _onClick(
|
abstract protected function _onClick(
|
||||||
\GtkButton $entity
|
\GtkButton $entity
|
||||||
): void;
|
): 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -15,6 +15,7 @@ class Navbar
|
||||||
|
|
||||||
// Requirements
|
// Requirements
|
||||||
public Navbar\Base $base;
|
public Navbar\Base $base;
|
||||||
|
public Navbar\Bookmark $bookmark;
|
||||||
public Navbar\History $history;
|
public Navbar\History $history;
|
||||||
public Navbar\Request $request;
|
public Navbar\Request $request;
|
||||||
public Navbar\Update $update;
|
public Navbar\Update $update;
|
||||||
|
|
@ -92,6 +93,15 @@ class Navbar
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Append bookmark button
|
||||||
|
$this->bookmark = new Navbar\Bookmark(
|
||||||
|
$this
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->gtk->add(
|
||||||
|
$this->bookmark->gtk
|
||||||
|
);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
$this->gtk->show();
|
$this->gtk->show();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
38
src/Entity/Browser/Container/Page/Navbar/Bookmark.php
Normal file
38
src/Entity/Browser/Container/Page/Navbar/Bookmark.php
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Yggverse\Yoda\Entity\Browser\Container\Page\Navbar;
|
||||||
|
|
||||||
|
use \Yggverse\Yoda\Abstract\Entity\Browser\Container\Page\Navbar\Button;
|
||||||
|
|
||||||
|
class Bookmark extends Button
|
||||||
|
{
|
||||||
|
private const _IMAGE_STARRED_YES = 'starred-symbolic';
|
||||||
|
private const _IMAGE_STARRED_NON = 'non-starred-symbolic';
|
||||||
|
|
||||||
|
public const IMAGE = self::_IMAGE_STARRED_NON;
|
||||||
|
public const LABEL = 'Bookmark';
|
||||||
|
public const TOOLTIP = 'Toggle bookmark';
|
||||||
|
public const SENSITIVE = true;
|
||||||
|
|
||||||
|
protected function _onCLick(
|
||||||
|
\GtkButton $entity
|
||||||
|
): void
|
||||||
|
{
|
||||||
|
$this->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
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue