From 9cc75a8fcfc59c6ed490d2eb275cd6c1cb6aeb67 Mon Sep 17 00:00:00 2001 From: yggverse Date: Fri, 19 Jul 2024 20:21:04 +0300 Subject: [PATCH] close tab on double click --- src/Entity/Browser/Container/Tab.php | 96 +++++++++++++-------------- src/Entity/Browser/Menu/Tab/Close.php | 4 +- 2 files changed, 49 insertions(+), 51 deletions(-) diff --git a/src/Entity/Browser/Container/Tab.php b/src/Entity/Browser/Container/Tab.php index 9674af8c..694cf79d 100644 --- a/src/Entity/Browser/Container/Tab.php +++ b/src/Entity/Browser/Container/Tab.php @@ -76,9 +76,7 @@ class Tab ?\GtkWidget $child, int $page_num ) { - $this->reorderPage( - null // all - ); + $this->reorder(); } ); @@ -89,9 +87,7 @@ class Tab ?\GtkWidget $child, int $page_num ) { - $this->reorderPage( - null // all - ); + $this->reorder(); } ); @@ -102,9 +98,21 @@ class Tab ?\GtkWidget $child, int $page_num ) { - $this->reorderPage( - null // all - ); + $this->reorder(); + } + ); + + $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]; } - public function closePage( + public function close( ?int $page_num = null ): void { @@ -196,58 +204,50 @@ class Tab $page->gtk ) ); + + $this->reorder(); } } - public function reorderPage( - ?int $page_num = null, + public function reorder( bool $session = true ): void { - // Reorder all pages - if (is_null($page_num)) + // Init new index + $_page = []; + + foreach ($this->_page as $page) { - // Init new index - $_page = []; - - 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 + // Get current entity $page_num + $page_num = $this->gtk->page_num( + $page->gtk ); - // Update session - if ($session) + // Skip deleted + if ($page_num === -1) { - $this->updateSession(); + // Prevent session update + $session = false; + + continue; } + + // Update position + $_page[$page_num] = $page; } - // Reorder by $page_num - else throw new \Exception( - 'Reorder by $page_num value not implemented' + // Reorder entities + $this->_page = $_page; + + ksort( + $this->_page ); + + // Update session + if ($session) + { + $this->updateSession(); + } } public function updateSession(): void diff --git a/src/Entity/Browser/Menu/Tab/Close.php b/src/Entity/Browser/Menu/Tab/Close.php index a3409213..c8427fa0 100644 --- a/src/Entity/Browser/Menu/Tab/Close.php +++ b/src/Entity/Browser/Menu/Tab/Close.php @@ -33,9 +33,7 @@ class Close 'activate', function() { - $this->tab->menu->browser->container->tab->closePage( - null // active - ); + $this->tab->menu->browser->container->tab->close(); } ); }