mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-03-31 16:45:27 +00:00
implement clean session menu item
This commit is contained in:
parent
1aef42348c
commit
e24ce589bf
2 changed files with 97 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ namespace Yggverse\Yoda\Entity\Browser\Menu;
|
|||
|
||||
use \GtkMenu;
|
||||
use \GtkMenuItem;
|
||||
use \GtkSeparatorMenuItem;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\Menu;
|
||||
|
||||
|
|
@ -20,6 +21,7 @@ class Tab
|
|||
// Requirements
|
||||
public Tab\Add $add;
|
||||
public Tab\Close $close;
|
||||
public Tab\Clean $clean;
|
||||
|
||||
// Defaults
|
||||
public const LABEL = 'Tab';
|
||||
|
|
@ -60,6 +62,24 @@ class Tab
|
|||
$tab
|
||||
);
|
||||
|
||||
// Add separator
|
||||
$tab->append(
|
||||
new GtkSeparatorMenuItem
|
||||
);
|
||||
|
||||
// Init close all tabs menu item
|
||||
$this->clean = new Tab\Clean(
|
||||
$this
|
||||
);
|
||||
|
||||
$tab->append(
|
||||
$this->clean->gtk
|
||||
);
|
||||
|
||||
$this->gtk->set_submenu(
|
||||
$tab
|
||||
);
|
||||
|
||||
// Render
|
||||
$this->gtk->show();
|
||||
}
|
||||
|
|
|
|||
77
src/Entity/Browser/Menu/Tab/Clean.php
Normal file
77
src/Entity/Browser/Menu/Tab/Clean.php
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Yggverse\Yoda\Entity\Browser\Menu\Tab;
|
||||
|
||||
use \GtkButtonsType;
|
||||
use \GtkDialogFlags;
|
||||
use \GtkMessageDialog;
|
||||
use \GtkMessageType;
|
||||
use \GtkResponseType;
|
||||
|
||||
use \Yggverse\Yoda\Entity\Browser\Menu\Tab;
|
||||
|
||||
class Clean
|
||||
{
|
||||
public \GtkMenuItem $gtk;
|
||||
|
||||
// Dependencies
|
||||
public Tab $tab;
|
||||
|
||||
// Defaults
|
||||
public const LABEL = 'Clean session';
|
||||
public const TOOLTIP = 'Close all tabs';
|
||||
public const DIALOG_MESSAGE_FORMAT = 'Clean session';
|
||||
public const DIALOG_FORMAT_SECONDARY_TEXT = 'Close all tabs and start new session?';
|
||||
|
||||
public function __construct(
|
||||
Tab $tab
|
||||
) {
|
||||
// Init dependencies
|
||||
$this->tab = $tab;
|
||||
|
||||
// Init menu item
|
||||
$this->gtk = \GtkMenuItem::new_with_label(
|
||||
_($this::LABEL)
|
||||
);
|
||||
|
||||
$this->gtk->set_tooltip_text(
|
||||
_($this::TOOLTIP)
|
||||
);
|
||||
|
||||
// Render
|
||||
$this->gtk->show();
|
||||
|
||||
// Int events
|
||||
$this->gtk->connect(
|
||||
'activate',
|
||||
function()
|
||||
{
|
||||
$dialog = new GtkMessageDialog(
|
||||
$this->tab->menu->browser->gtk,
|
||||
GtkDialogFlags::MODAL,
|
||||
GtkMessageType::WARNING,
|
||||
GtkButtonsType::OK_CANCEL,
|
||||
$this::DIALOG_MESSAGE_FORMAT
|
||||
);
|
||||
|
||||
$dialog->format_secondary_text(
|
||||
$this::DIALOG_FORMAT_SECONDARY_TEXT
|
||||
);
|
||||
|
||||
if (GtkResponseType::OK == $dialog->run())
|
||||
{
|
||||
foreach ($this->tab->menu->browser->container->tab->pages as $page_num => $page)
|
||||
{
|
||||
$this->tab->menu->browser->container->tab->close(
|
||||
$page_num
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$dialog->destroy();
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue