feat: Complete plugin lifecycle management with lazy loading and runtime reload
Major changes: - Add unload() method to all plugins for proper cleanup (unregister commands/providers/LSP clients, destroy widgets, clear state) - Implement lazy widget loading via "show" signal across all containers - Add autoload: false manifest option for manual/conditional plugin loading - Add Plugins UI with runtime load/unload toggle via Ctrl+Shift+p - Implement controller unregistration system with proper signal disconnection - Add new events: UnregisterCommandEvent, GetFilesEvent, GetSourceViewsEvent, TogglePluginsUiEvent - Fix signal leaks by tracking and disconnecting handlers in widgets (search/replace, LSP manager, tabs, telescope, markdown preview) - Add Save/Save As to tabs context menu - Improve search/replace behavior (selection handling, focus management) - Add telescope file initialization from existing loaded files - Refactor plugin reload watcher to dynamically add/remove plugins on filesystem changes - Add new plugins: file_history, extend_source_view_menu, godot_lsp_client - Fix bug in prettify_json (undefined variable reference)
This commit is contained in:
@@ -17,19 +17,17 @@ class SearchReplaceMixin(SearchMixin, ReplaceMixin):
|
||||
search_text = entry.get_text()
|
||||
buffer = self.active_view.get_buffer()
|
||||
|
||||
if buffer.get_has_selection() and not search_text:
|
||||
if not self.mode_bttn_box.in_selection:
|
||||
start_itr, end_itr = buffer.get_selection_bounds()
|
||||
if not buffer.get_has_selection() and search_text: return
|
||||
if self.mode_bttn_box.in_selection: return
|
||||
|
||||
entry.set_text(
|
||||
buffer.get_text(
|
||||
start_itr,
|
||||
end_itr,
|
||||
include_hidden_chars = False
|
||||
)
|
||||
)
|
||||
|
||||
return
|
||||
start_itr, end_itr = buffer.get_selection_bounds()
|
||||
entry.set_text(
|
||||
buffer.get_text(
|
||||
start_itr,
|
||||
end_itr,
|
||||
include_hidden_chars = False
|
||||
)
|
||||
)
|
||||
|
||||
def _find_entry_search_change(self, entry):
|
||||
search_text = entry.get_text()
|
||||
|
||||
@@ -33,44 +33,44 @@ class ModeButtons(Gtk.ButtonBox):
|
||||
ctx.add_class("search-replace-mode-buttons")
|
||||
|
||||
def _setup_signals(self):
|
||||
...
|
||||
self.connect("destroy", self._handle_destroy)
|
||||
|
||||
def _load_widgets(self):
|
||||
use_regex_bttn = Gtk.ToggleButton(label = ".*")
|
||||
match_case_bttn = Gtk.ToggleButton(label = "Aa")
|
||||
in_selection_bttn = Gtk.ToggleButton()
|
||||
whole_word_bttn = Gtk.ToggleButton()
|
||||
hide_bttn = Gtk.Button(label = "X")
|
||||
self.use_regex_bttn = Gtk.ToggleButton(label = ".*")
|
||||
self.match_case_bttn = Gtk.ToggleButton(label = "Aa")
|
||||
self.in_selection_bttn = Gtk.ToggleButton()
|
||||
self.whole_word_bttn = Gtk.ToggleButton()
|
||||
self.hide_bttn = Gtk.Button(label = "X")
|
||||
|
||||
use_regex_bttn.set_sensitive(False)
|
||||
self.use_regex_bttn.set_sensitive(False)
|
||||
|
||||
use_regex_bttn.set_tooltip_text("Use Regex")
|
||||
match_case_bttn.set_tooltip_text("Match Case")
|
||||
in_selection_bttn.set_tooltip_text("Only In Selection")
|
||||
whole_word_bttn.set_tooltip_text("Whole Word")
|
||||
self.use_regex_bttn.set_tooltip_text("Use Regex")
|
||||
self.match_case_bttn.set_tooltip_text("Match Case")
|
||||
self.in_selection_bttn.set_tooltip_text("Only In Selection")
|
||||
self.whole_word_bttn.set_tooltip_text("Whole Word")
|
||||
|
||||
use_regex_bttn.connect("toggled", self._toggled_button, "use_regex")
|
||||
match_case_bttn.connect("toggled", self._toggled_button, "match_case")
|
||||
in_selection_bttn.connect("toggled", self._toggled_button, "in_selection")
|
||||
whole_word_bttn.connect("toggled", self._toggled_button, "whole_word")
|
||||
self.use_regex_bttn.connect("toggled", self._toggled_button, "use_regex")
|
||||
self.match_case_bttn.connect("toggled", self._toggled_button, "match_case")
|
||||
self.in_selection_bttn.connect("toggled", self._toggled_button, "in_selection")
|
||||
self.whole_word_bttn.connect("toggled", self._toggled_button, "whole_word")
|
||||
|
||||
hide_bttn.connect(
|
||||
self.hide_bttn_id = self.hide_bttn.connect(
|
||||
"clicked",
|
||||
lambda widget: self.get_parent().hide()
|
||||
)
|
||||
|
||||
in_selection_bttn.set_image(
|
||||
self.in_selection_bttn.set_image(
|
||||
Gtk.Image.new_from_file("images/only-in-selection.png")
|
||||
)
|
||||
whole_word_bttn.set_image(
|
||||
self.whole_word_bttn.set_image(
|
||||
Gtk.Image.new_from_file("images/whole-word.png")
|
||||
)
|
||||
|
||||
self.add(use_regex_bttn)
|
||||
self.add(match_case_bttn)
|
||||
self.add(in_selection_bttn)
|
||||
self.add(whole_word_bttn)
|
||||
self.add(hide_bttn)
|
||||
self.add(self.use_regex_bttn)
|
||||
self.add(self.match_case_bttn)
|
||||
self.add(self.in_selection_bttn)
|
||||
self.add(self.whole_word_bttn)
|
||||
self.add(self.hide_bttn)
|
||||
|
||||
def _toggled_button(self, toggle_button, mode: str):
|
||||
setattr(self, mode, not getattr(self, mode))
|
||||
@@ -79,4 +79,12 @@ class ModeButtons(Gtk.ButtonBox):
|
||||
def request_update(self):
|
||||
raise ModeException("Must by 'monkey' patched from search_replace.py")
|
||||
|
||||
def _handle_destroy(self, widget):
|
||||
self.disconnect_by_func(self._handle_destroy)
|
||||
|
||||
self.use_regex_bttn.disconnect_by_func(self._toggled_button)
|
||||
self.match_case_bttn.disconnect_by_func(self._toggled_button)
|
||||
self.in_selection_bttn.disconnect_by_func(self._toggled_button)
|
||||
self.whole_word_bttn.disconnect_by_func(self._toggled_button)
|
||||
|
||||
self.hide_bttn.disconnect(self.hide_bttn_id)
|
||||
|
||||
@@ -49,6 +49,17 @@ class Plugin(PluginCode):
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
def unload(self):
|
||||
event = Event_Factory.create_event("unregister_command",
|
||||
command_name = "search_replace",
|
||||
command = Handler,
|
||||
binding_mode = "released",
|
||||
binding = ["<Control>f", "<Control>r"]
|
||||
)
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
search_replace.destroy()
|
||||
|
||||
def run(self):
|
||||
...
|
||||
|
||||
@@ -63,4 +74,7 @@ class Handler:
|
||||
logger.debug("Command: Search/Replace")
|
||||
|
||||
search_replace.last_key = args[0]
|
||||
if not search_replace.active_view:
|
||||
search_replace.active_view = view
|
||||
|
||||
search_replace.hide() if search_replace.is_visible() else search_replace.show()
|
||||
|
||||
@@ -22,7 +22,7 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
self.active_view = None
|
||||
self.highlight_tag: Gtk.TextTag = None
|
||||
self.matches: list[tuple] = []
|
||||
self.last_key: str = None
|
||||
self.last_key: str = "f"
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
@@ -48,6 +48,7 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
def _setup_signals(self):
|
||||
self.connect("show", self._handle_show)
|
||||
self.connect("hide", self._handle_hide)
|
||||
self.connect("destroy", self._handle_destroy)
|
||||
|
||||
def _load_widgets(self):
|
||||
self.status_lbl = Gtk.Label(label = "Find in Current Buffer")
|
||||
@@ -57,10 +58,10 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
self.find_entry = Gtk.SearchEntry()
|
||||
self.replace_entry = Gtk.SearchEntry()
|
||||
|
||||
find_bttn = Gtk.Button(label = "Find")
|
||||
find_all_bttn = Gtk.Button(label = "Find All")
|
||||
replace_bttn = Gtk.Button(label = "Replace")
|
||||
replace_all_bttn = Gtk.Button(label = "Replace All")
|
||||
self.find_bttn = Gtk.Button(label = "Find")
|
||||
self.find_all_bttn = Gtk.Button(label = "Find All")
|
||||
self.replace_bttn = Gtk.Button(label = "Replace")
|
||||
self.replace_all_bttn = Gtk.Button(label = "Replace All")
|
||||
|
||||
self.find_entry.set_hexpand(True)
|
||||
self.replace_entry.set_hexpand(True)
|
||||
@@ -81,21 +82,24 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
self.replace_entry.connect("key-release-event", self._replace_entry_key_release_event)
|
||||
self.replace_entry.connect("activate", self._replace_entry_activate)
|
||||
|
||||
find_bttn.connect(
|
||||
self.find_handler_id = self.find_bttn.connect(
|
||||
"clicked",
|
||||
lambda button: self._find_entry_next_match(self.find_entry)
|
||||
)
|
||||
find_all_bttn.connect(
|
||||
|
||||
self.find_all_handler_id = self.find_all_bttn.connect(
|
||||
"clicked",
|
||||
lambda button: self._find_entry_search_change(self.find_entry)
|
||||
)
|
||||
replace_bttn.connect(
|
||||
|
||||
self.replace_handler_id = self.replace_bttn.connect(
|
||||
"clicked",
|
||||
lambda button: self._replace_entry_activate(self.replace_entry)
|
||||
)
|
||||
replace_all_bttn.connect(
|
||||
|
||||
self.replace_all_handler_id = self.replace_all_bttn.connect(
|
||||
"clicked",
|
||||
lambda button: self._replace_all_activate(self.replace_entry)
|
||||
lambda button: self._replace_all_activate(self.replace_entry)
|
||||
)
|
||||
|
||||
self.attach(child = self.status_lbl, left = 0, top = 0, width = 3, height = 1)
|
||||
@@ -103,12 +107,12 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
self.attach(child = self.mode_bttn_box, left = 5, top = 0, width = 2, height = 1)
|
||||
|
||||
self.attach(child = self.find_entry, left = 0, top = 1, width = 5, height = 1)
|
||||
self.attach(child = find_bttn, left = 5, top = 1, width = 1, height = 1)
|
||||
self.attach(child = find_all_bttn, left = 6, top = 1, width = 1, height = 1)
|
||||
self.attach(child = self.find_bttn, left = 5, top = 1, width = 1, height = 1)
|
||||
self.attach(child = self.find_all_bttn, left = 6, top = 1, width = 1, height = 1)
|
||||
|
||||
self.attach(child = self.replace_entry, left = 0, top = 2, width = 5, height = 1)
|
||||
self.attach(child = replace_bttn, left = 5, top = 2, width = 1, height = 1)
|
||||
self.attach(child = replace_all_bttn, left = 6, top = 2, width = 1, height = 1)
|
||||
self.attach(child = self.replace_bttn, left = 5, top = 2, width = 1, height = 1)
|
||||
self.attach(child = self.replace_all_bttn, left = 6, top = 2, width = 1, height = 1)
|
||||
|
||||
|
||||
def _handle_show(self, widget):
|
||||
@@ -117,9 +121,9 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
self.find_entry.grab_focus()
|
||||
return
|
||||
|
||||
self.replace_entry.grab_focus()
|
||||
# Fake focus call to prompt search
|
||||
self._find_entry_focus_in_event(self.find_entry, None)
|
||||
self._find_entry_focus_in_event(self.find_entry, None)
|
||||
self.replace_entry.grab_focus()
|
||||
|
||||
def _handle_hide(self, widget):
|
||||
if not self.active_view: return
|
||||
@@ -197,3 +201,22 @@ class SearchReplace(Gtk.Grid, SearchReplaceMixin):
|
||||
start_itr, end_itr = buffer.get_bounds()
|
||||
buffer.remove_tag(self.highlight_tag, start_itr, end_itr)
|
||||
|
||||
def _handle_destroy(self, widget):
|
||||
self.disconnect_by_func(self._handle_show)
|
||||
self.disconnect_by_func(self._handle_hide)
|
||||
self.disconnect_by_func(self._handle_destroy)
|
||||
|
||||
self.find_entry.disconnect_by_func(self._find_entry_focus_in_event)
|
||||
self.find_entry.disconnect_by_func(self._find_entry_key_release_event)
|
||||
self.find_entry.disconnect_by_func(self._find_entry_activate)
|
||||
self.find_entry.disconnect_by_func(self._find_entry_search_change)
|
||||
self.find_entry.disconnect_by_func(self._find_entry_next_match)
|
||||
self.find_entry.disconnect_by_func(self._find_entry_previous_match)
|
||||
|
||||
self.replace_entry.disconnect_by_func(self._replace_entry_key_release_event)
|
||||
self.replace_entry.disconnect_by_func(self._replace_entry_activate)
|
||||
|
||||
self.find_bttn.disconnect(self.find_handler_id)
|
||||
self.find_all_bttn.disconnect(self.find_all_handler_id)
|
||||
self.replace_bttn.disconnect(self.replace_handler_id)
|
||||
self.replace_all_bttn.disconnect(self.replace_all_handler_id)
|
||||
|
||||
Reference in New Issue
Block a user