Clean up codebase and improve file loading
- Moved plugins to proper sub groups (autopairs, code_minimap, colorize, commentzar, info_bar, markdown_preview, prettify_json, search_replace, tabs_bar, telescope, toggle_source_view, lsp_client) - Add filter_out_loaded_files to prevent opening already-loaded files - Add INDEPENDENT source view state - Fix cursor scroll position on buffer switch - Fix signal blocking during file load - Fix word boundary in completion provider - Refactor code events into single events module
This commit is contained in:
78
plugins/code/ui/telescope/plugin.py
Normal file
78
plugins/code/ui/telescope/plugin.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
from libs.dto.states import SourceViewStates
|
||||
|
||||
from plugins.plugin_types import PluginCode
|
||||
|
||||
from .telescope import Telescope
|
||||
|
||||
|
||||
|
||||
telescope = Telescope()
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
if isinstance(event, Code_Event_Types.FocusedViewEvent):
|
||||
...
|
||||
elif isinstance(event, Code_Event_Types.AddedNewFileEvent):
|
||||
telescope.list_box.add_row(event)
|
||||
elif isinstance(event, Code_Event_Types.RemovedFileEvent):
|
||||
telescope.list_box.remove_row(event)
|
||||
elif isinstance(event, Code_Event_Types.FilePathSetEvent):
|
||||
telescope.list_box.update_label(event)
|
||||
|
||||
def load(self):
|
||||
window = self.request_ui_element("main-window")
|
||||
|
||||
telescope.map_parent_resize_event(window)
|
||||
telescope.set_transient_for(window)
|
||||
telescope.set_emit(self.emit)
|
||||
|
||||
event = Event_Factory.create_event("register_command",
|
||||
command_name = "telescope",
|
||||
command = Handler,
|
||||
binding_mode = "released",
|
||||
binding = "<Control>b"
|
||||
)
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
event = Event_Factory.create_event(
|
||||
"create_source_view",
|
||||
state = SourceViewStates.INDEPENDENT
|
||||
)
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
source_view = event.response
|
||||
telescope.set_source_view(source_view)
|
||||
|
||||
event = Event_Factory.create_event(
|
||||
"register_completer",
|
||||
completer = source_view.get_completion()
|
||||
)
|
||||
self.emit_to("completion", event)
|
||||
|
||||
|
||||
def run(self):
|
||||
...
|
||||
|
||||
|
||||
class Handler:
|
||||
@staticmethod
|
||||
def execute(
|
||||
view: any,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Telescope")
|
||||
telescope.set_active_row( view.get_buffer() )
|
||||
telescope.hide() if telescope.is_visible() else telescope.show()
|
||||
Reference in New Issue
Block a user