close tab on double click

This commit is contained in:
yggverse 2024-07-19 20:21:04 +03:00
parent fb2f135e0d
commit 9cc75a8fcf
2 changed files with 49 additions and 51 deletions

View file

@ -76,9 +76,7 @@ class Tab
?\GtkWidget $child, ?\GtkWidget $child,
int $page_num int $page_num
) { ) {
$this->reorderPage( $this->reorder();
null // all
);
} }
); );
@ -89,9 +87,7 @@ class Tab
?\GtkWidget $child, ?\GtkWidget $child,
int $page_num int $page_num
) { ) {
$this->reorderPage( $this->reorder();
null // all
);
} }
); );
@ -102,9 +98,21 @@ class Tab
?\GtkWidget $child, ?\GtkWidget $child,
int $page_num int $page_num
) { ) {
$this->reorderPage( $this->reorder();
null // all }
); );
$this->gtk->connect(
'button-press-event',
function (
?\GtkNotebook $self,
?\GdkEvent $event
) {
// Close tab on double click
if ($event->type == 5) // @TODO PHP-GTK3 Gdk.EventType.DOUBLE_BUTTON_PRESS
{
$this->close();
}
} }
); );
} }
@ -185,7 +193,7 @@ class Tab
return $this->_page[$page_num]; return $this->_page[$page_num];
} }
public function closePage( public function close(
?int $page_num = null ?int $page_num = null
): void ): void
{ {
@ -196,58 +204,50 @@ class Tab
$page->gtk $page->gtk
) )
); );
$this->reorder();
} }
} }
public function reorderPage( public function reorder(
?int $page_num = null,
bool $session = true bool $session = true
): void ): void
{ {
// Reorder all pages // Init new index
if (is_null($page_num)) $_page = [];
foreach ($this->_page as $page)
{ {
// Init new index // Get current entity $page_num
$_page = []; $page_num = $this->gtk->page_num(
$page->gtk
foreach ($this->_page as $page)
{
// Get current entity $page_num
$page_num = $this->gtk->page_num(
$page->gtk
);
// Skip deleted
if ($page_num === -1)
{
// Prevent session update
$session = false;
continue;
}
// Update position
$_page[$page_num] = $page;
}
// Reorder entities
$this->_page = $_page;
ksort(
$this->_page
); );
// Update session // Skip deleted
if ($session) if ($page_num === -1)
{ {
$this->updateSession(); // Prevent session update
$session = false;
continue;
} }
// Update position
$_page[$page_num] = $page;
} }
// Reorder by $page_num // Reorder entities
else throw new \Exception( $this->_page = $_page;
'Reorder by $page_num value not implemented'
ksort(
$this->_page
); );
// Update session
if ($session)
{
$this->updateSession();
}
} }
public function updateSession(): void public function updateSession(): void

View file

@ -33,9 +33,7 @@ class Close
'activate', 'activate',
function() function()
{ {
$this->tab->menu->browser->container->tab->closePage( $this->tab->menu->browser->container->tab->close();
null // active
);
} }
); );
} }