From 12a5e4935ea9b74763b1ac9370e6c0618b01c298 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 23 Mar 2026 23:08:00 -0500 Subject: [PATCH] Fix plugin lifecycle, tabs cleanup, and add auto-scroll to tabs - Fix unload() method naming in nanoesq_temp_buffer plugin - Wrap tabs_widget in ScrolledWindow/Viewport for proper scrolling - Add auto-scroll to center when switching/adding tabs - Return manifest_meta in manifest_manager for manual plugins - Refactor remove_plugin() to properly clean up all manifest lists - Fix widget references in plugins_ui for proper removal --- .../commands/nanoesq_temp_buffer/plugin.py | 2 +- plugins/code/ui/tabs_bar/plugin.py | 27 ++++++++++++++++--- plugins/code/ui/tabs_bar/tabs_widget.py | 19 ++++++++++++- src/plugins/manifest_manager.py | 2 +- src/plugins/plugin_reload_mixin.py | 23 +++++++++++----- src/plugins/plugins_ui.py | 3 ++- 6 files changed, 63 insertions(+), 13 deletions(-) diff --git a/plugins/code/commands/nanoesq_temp_buffer/plugin.py b/plugins/code/commands/nanoesq_temp_buffer/plugin.py index 028c460..3b01b2d 100644 --- a/plugins/code/commands/nanoesq_temp_buffer/plugin.py +++ b/plugins/code/commands/nanoesq_temp_buffer/plugin.py @@ -23,7 +23,7 @@ class Plugin(PluginCode): def load(self): self._manage_signals("register_command") - def load(self): + def unload(self): self._manage_signals("unregister_command") def _manage_signals(self, action: str): diff --git a/plugins/code/ui/tabs_bar/plugin.py b/plugins/code/ui/tabs_bar/plugin.py index 1911b6b..0095953 100644 --- a/plugins/code/ui/tabs_bar/plugin.py +++ b/plugins/code/ui/tabs_bar/plugin.py @@ -1,6 +1,9 @@ # Python imports # Lib imports +import gi + +from gi.repository import Gtk # Application imports from libs.event_factory import Event_Factory, Code_Event_Types @@ -25,8 +28,19 @@ class Plugin(PluginCode): self.register_controller("tabs", self.tabs_controller) - code_container.add( self.tabs_controller.tabs_widget ) - code_container.reorder_child(self.tabs_controller.tabs_widget, 0) + scrolled_win = Gtk.ScrolledWindow() + viewport = Gtk.Viewport() + + scrolled_win.set_overlay_scrolling(False) + scrolled_win.set_size_request(-1, 50) + + viewport.add( self.tabs_controller.tabs_widget ) + scrolled_win.add( viewport ) + code_container.add( scrolled_win ) + code_container.reorder_child(scrolled_win, 0) + + viewport.show() + scrolled_win.show() event = Event_Factory.create_event("get_files") self.emit_to("files", event) @@ -36,7 +50,14 @@ class Plugin(PluginCode): def unload(self): self.unregister_controller("tabs") self.tabs_controller.unload_tabs() - self.tabs_controller.tabs_widget.destroy() + + tabs_widget = self.tabs_controller.tabs_widget + viewport = tabs_widget.get_parent() + scrolled_win = viewport.get_parent() + + tabs_widget.destroy() + viewport.destroy() + scrolled_win.destroy() self.tabs_controller.tabs_widget = None self.tabs_controller = None diff --git a/plugins/code/ui/tabs_bar/tabs_widget.py b/plugins/code/ui/tabs_bar/tabs_widget.py index 9a8b18d..f4d6af0 100644 --- a/plugins/code/ui/tabs_bar/tabs_widget.py +++ b/plugins/code/ui/tabs_bar/tabs_widget.py @@ -27,7 +27,7 @@ class TabsWidget(Gtk.Notebook): def _setup_styling(self): - self.set_scrollable(True) + ... def _setup_signals(self): self.connect("page-added", self._page_added) @@ -67,6 +67,7 @@ class TabsWidget(Gtk.Notebook): ) self.emit(event) + self._scroll_to_center(tab) def _bind_tab_menu(self, tab, page_widget): def do_context_menu(tab, eve, page_widget): @@ -81,6 +82,21 @@ class TabsWidget(Gtk.Notebook): page_widget ) + def _scroll_to_center(self, tab): + scrolled_win = self.get_parent().get_parent() + alloc = tab.get_allocation() + tab_x = alloc.x + tab_width = alloc.width + view_width = scrolled_win.get_allocated_width() + target = tab_x + tab_width / 2 - view_width / 2 + adj = scrolled_win.get_hadjustment() + lower = adj.get_lower() + upper = adj.get_upper() + page_size = adj.get_page_size() + target = max(lower, min(target, upper - page_size)) + + adj.set_value(target) + def create_menu(self, page_widget) -> Gtk.Menu: context_menu = Gtk.Menu() close_submenu = Gtk.Menu() @@ -130,6 +146,7 @@ class TabsWidget(Gtk.Notebook): self.page_num(page_widget) ) self.handler_unblock(self.switch_page_id) + self._scroll_to_center(tab) break diff --git a/src/plugins/manifest_manager.py b/src/plugins/manifest_manager.py index 0f7add3..ffe7e91 100644 --- a/src/plugins/manifest_manager.py +++ b/src/plugins/manifest_manager.py @@ -56,7 +56,7 @@ class ManifestManager: if not manifest.autoload: self.manual_launch_manifests.append(manifest_meta) - return + return manifest_meta if manifest.pre_launch: self.pre_launch_manifests.append(manifest_meta) diff --git a/src/plugins/plugin_reload_mixin.py b/src/plugins/plugin_reload_mixin.py index eea9a9e..9b665e2 100644 --- a/src/plugins/plugin_reload_mixin.py +++ b/src/plugins/plugin_reload_mixin.py @@ -48,13 +48,13 @@ class PluginReloadMixin: def remove_plugin(self, file: str) -> None: logger.info(f"Removing plugin: {file.get_uri()}") - for manifest_meta in self._plugin_collection[:]: - if not manifest_meta.folder in file.get_uri(): continue - manifest_meta.instance.unload() - manifest_meta.instance = None - self._plugin_collection.remove(manifest_meta) - self.plugins_ui.remove_row(manifest_meta) + manifests = self._manifest_manager.pre_launch_manifests \ + + self._manifest_manager.post_launch_manifests \ + + self._manifest_manager.manual_launch_manifests + + for manifest_meta in manifests: + if not manifest_meta.folder in file.get_uri(): continue if manifest_meta in self._manifest_manager.pre_launch_manifests: self._manifest_manager.pre_launch_manifests.remove(manifest_meta) @@ -63,4 +63,15 @@ class PluginReloadMixin: elif manifest_meta in self._manifest_manager.manual_launch_manifests: self._manifest_manager.manual_launch_manifests.remove(manifest_meta) + self.plugins_ui.remove_row(manifest_meta) + break + + del manifests + for manifest_meta in self._plugin_collection[:]: + if not manifest_meta.folder in file.get_uri(): continue + + manifest_meta.instance.unload() + manifest_meta.instance = None + self._plugin_collection.remove(manifest_meta) + break diff --git a/src/plugins/plugins_ui.py b/src/plugins/plugins_ui.py index 34efa56..60e729f 100644 --- a/src/plugins/plugins_ui.py +++ b/src/plugins/plugins_ui.py @@ -76,6 +76,7 @@ class PluginsUI(Gtk.Dialog): toggle_bttn.toggle_id = \ toggle_bttn.connect("toggled", callback, manifest_meta) + box.toggle_bttn = toggle_bttn box.add(plugin_lbl) box.add(author_lbl) @@ -96,5 +97,5 @@ class PluginsUI(Gtk.Dialog): toggle_bttn.disconnect(toggle_bttn.toggle_id) self.list_box.remove(row) - box.destroy() + child.destroy() break