From ab9c521af1be66cc0887adec6ea2615eed007071 Mon Sep 17 00:00:00 2001 From: yggverse Date: Wed, 31 Jul 2024 01:42:18 +0300 Subject: [PATCH] implement about menu item dialog --- src/Entity/Browser/Menu/Help/About.php | 81 +++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-) diff --git a/src/Entity/Browser/Menu/Help/About.php b/src/Entity/Browser/Menu/Help/About.php index 94fc3d1a..ae9fa9a6 100644 --- a/src/Entity/Browser/Menu/Help/About.php +++ b/src/Entity/Browser/Menu/Help/About.php @@ -5,7 +5,13 @@ declare(strict_types=1); namespace Yggverse\Yoda\Entity\Browser\Menu\Help; use \Gtk; +use \GtkButtonsType; +use \GtkDialogFlags; +use \GtkJustification; use \GtkMenuItem; +use \GtkMessageDialog; +use \GtkMessageType; +use \GtkResponseType; use \Yggverse\Yoda\Entity\Browser\Menu\Help; @@ -20,6 +26,14 @@ class About // Defaults public const LABEL = 'About'; + public const DIALOG_MESSAGE_FORMAT = 'About'; + public const DIALOG_FORMAT_SECONDARY_MARKUP_APP_SRC_VERSION = 'Yoda dev'; // @TODO + public const DIALOG_FORMAT_SECONDARY_MARKUP_PHP_SRC_VERSION = 'PHP %d.%d.%d'; + public const DIALOG_FORMAT_SECONDARY_MARKUP_PHP_GTK_VERSION = 'PHP-GTK %s'; + public const DIALOG_FORMAT_SECONDARY_MARKUP_LIB_GTK_VERSION = 'GTK %d.%d.%d'; + + public const PHP_VERSION_GTK_EXTENSION = 'php-gtk3'; + public function __construct( Help $help ) { @@ -39,7 +53,72 @@ class About 'activate', function() { - // @TODO + $dialog = new GtkMessageDialog( + $this->help->menu->browser->gtk, + GtkDialogFlags::MODAL, + GtkMessageType::INFO, + GtkButtonsType::OK, + _($this::DIALOG_MESSAGE_FORMAT) + ); + + $dialog->format_secondary_markup( + implode( + PHP_EOL, + [ + _($this::DIALOG_FORMAT_SECONDARY_MARKUP_APP_SRC_VERSION), + sprintf( + _($this::DIALOG_FORMAT_SECONDARY_MARKUP_PHP_SRC_VERSION), + PHP_MAJOR_VERSION, + PHP_MINOR_VERSION, + PHP_RELEASE_VERSION + ), + implode( + ' / ', + [ + sprintf( + _($this::DIALOG_FORMAT_SECONDARY_MARKUP_PHP_GTK_VERSION), + phpversion( + $this::PHP_VERSION_GTK_EXTENSION + ) + ), + sprintf( + _($this::DIALOG_FORMAT_SECONDARY_MARKUP_LIB_GTK_VERSION), + 0, // @TODO pending for PR #153 + 0, + 0 + ) + ] + ) + ] + ) + ); + + // Tune up the label + if ($label = $dialog->get_message_area()->get_children()) + { + if (!isset($label[1])) + { + throw new Exception; + } + + $label[1]->set_selectable( + true + ); + + $label[1]->set_track_visited_links( + false + ); + + $label[1]->set_justify( + GtkJustification::CENTER + ); + } + + // Await for action + if (GtkResponseType::OK == $dialog->run()) + { + $dialog->destroy(); + } } ); }