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:
3
plugins/code/ui/telescope/__init__.py
Normal file
3
plugins/code/ui/telescope/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
||||
3
plugins/code/ui/telescope/__main__.py
Normal file
3
plugins/code/ui/telescope/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
||||
137
plugins/code/ui/telescope/list_box.py
Normal file
137
plugins/code/ui/telescope/list_box.py
Normal file
@@ -0,0 +1,137 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('Gtk', '3.0')
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
|
||||
|
||||
class TelescopeListBoxException(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
class ListBox(Gtk.ListBox):
|
||||
def __init__(self):
|
||||
super(ListBox, self).__init__()
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_placeholder( Gtk.Label(label = "Buffers...") )
|
||||
self.set_selection_mode( Gtk.SelectionMode.BROWSE )
|
||||
self.set_vexpand(True)
|
||||
self.set_size_request(120, -1)
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("row-activated", self._row_activated)
|
||||
self.connect("row-selected", self._row_selected)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def _row_activated(self, list_box, row = None):
|
||||
row = self.get_selected_row()
|
||||
file = row.get_children()[0].file
|
||||
|
||||
event = Event_Factory.create_event(
|
||||
"set_active_file",
|
||||
buffer = file.buffer
|
||||
)
|
||||
|
||||
self.emit(event)
|
||||
|
||||
|
||||
def _row_selected(self, list_box, row):
|
||||
if not row: return
|
||||
|
||||
file = row.get_children()[0].file
|
||||
self.set_buffer(file.buffer)
|
||||
|
||||
def set_active_row(self, buffer):
|
||||
for row in self.get_children():
|
||||
child = row.get_children()[0]
|
||||
if not child.file.buffer == buffer: continue
|
||||
self.select_row(row)
|
||||
break
|
||||
|
||||
def search_changed(self, entry):
|
||||
self.search_buffer_names(entry)
|
||||
for row in self.get_children():
|
||||
if not row.is_visible(): continue
|
||||
self.select_row(row)
|
||||
|
||||
def search_buffer_names(self, entry):
|
||||
text = entry.get_text()
|
||||
if not text:
|
||||
for row in self.get_children():
|
||||
row.show()
|
||||
|
||||
return
|
||||
|
||||
for row in self.get_children():
|
||||
child = row.get_children()[0]
|
||||
|
||||
row.show() \
|
||||
if text in child.get_label() else \
|
||||
row.hide()
|
||||
|
||||
def activate_row(self):
|
||||
self._row_activated(self)
|
||||
|
||||
def set_buffer(self, buffer):
|
||||
raise TelescopeListBoxException("ListBox must have 'set_buffer' monkey patched...")
|
||||
|
||||
def move_row_selection_up(self):
|
||||
row = self.get_selected_row()
|
||||
next_row = self.get_row_at_index(row.get_index() - 1)
|
||||
|
||||
if not next_row:
|
||||
next_row = self.get_row_at_index(
|
||||
len( self.get_children() ) - 1
|
||||
)
|
||||
|
||||
self.select_row(next_row)
|
||||
|
||||
def move_row_selection_down(self):
|
||||
row = self.get_selected_row()
|
||||
next_row = self.get_row_at_index(row.get_index() + 1)
|
||||
|
||||
if not next_row:
|
||||
next_row = self.get_row_at_index(0)
|
||||
|
||||
self.select_row(next_row)
|
||||
|
||||
def add_row(self, event):
|
||||
label = Gtk.Label(label = event.file.fname)
|
||||
label.file = event.file
|
||||
label.show()
|
||||
self.add(label)
|
||||
|
||||
def remove_row(self, event):
|
||||
for row in self.get_children():
|
||||
child = row.get_children()[0]
|
||||
if not child.file == event.file: continue
|
||||
child.file = None
|
||||
self.remove(row)
|
||||
break
|
||||
|
||||
def update_label(self, event):
|
||||
for row in self.get_children():
|
||||
child = row.get_children()[0]
|
||||
if not child.file == event.file: continue
|
||||
child.set_label(event.file.fname)
|
||||
break
|
||||
7
plugins/code/ui/telescope/manifest.json
Normal file
7
plugins/code/ui/telescope/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Telescope",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {}
|
||||
}
|
||||
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()
|
||||
96
plugins/code/ui/telescope/search_entry.py
Normal file
96
plugins/code/ui/telescope/search_entry.py
Normal file
@@ -0,0 +1,96 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .list_box import ListBox
|
||||
|
||||
|
||||
|
||||
class TelescopeSearchEntryException(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
class SearchEntry(Gtk.SearchEntry):
|
||||
def __init__(self):
|
||||
super(SearchEntry, self).__init__()
|
||||
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
...
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("search-changed", self._search_changed)
|
||||
self.connect("key-press-event", self._key_press_event)
|
||||
self.connect("key-release-event", self._key_release_event)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
...
|
||||
|
||||
def _key_press_event(self, widget, eve):
|
||||
modifiers = Gdk.ModifierType(eve.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||
is_control = modifiers & Gdk.ModifierType.CONTROL_MASK
|
||||
is_shift = modifiers & Gdk.ModifierType.SHIFT_MASK
|
||||
keyname = Gdk.keyval_name(eve.keyval).lower()
|
||||
char_str = chr( Gdk.keyval_to_unicode(eve.keyval) )
|
||||
|
||||
if keyname == "up":
|
||||
self.move_row_selection_up()
|
||||
return True
|
||||
elif keyname == "down":
|
||||
self.move_row_selection_down()
|
||||
return True
|
||||
|
||||
|
||||
def _key_release_event(self, widget, eve):
|
||||
modifiers = Gdk.ModifierType(eve.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||
is_control = modifiers & Gdk.ModifierType.CONTROL_MASK
|
||||
is_shift = modifiers & Gdk.ModifierType.SHIFT_MASK
|
||||
keyname = Gdk.keyval_name(eve.keyval).lower()
|
||||
char_str = chr( Gdk.keyval_to_unicode(eve.keyval) )
|
||||
|
||||
if is_control:
|
||||
if char_str == "b":
|
||||
self.hide()
|
||||
|
||||
return True
|
||||
|
||||
if keyname in ["enter", "return"]:
|
||||
self.activate_row()
|
||||
self.hide()
|
||||
|
||||
return True
|
||||
|
||||
def _search_changed(self, widget):
|
||||
self.search_changed(widget)
|
||||
|
||||
def hide(self):
|
||||
raise TelescopeSearchEntryException("SearchEntry must have 'hide' monkey patched...")
|
||||
|
||||
def search_changed(self, widget):
|
||||
raise TelescopeSearchEntryException("SearchEntry must have 'search_changed' monkey patched...")
|
||||
|
||||
def activate_row(self):
|
||||
raise TelescopeSearchEntryException("SearchEntry must have 'activate_row' monkey patched...")
|
||||
|
||||
def move_row_selection_up(self):
|
||||
raise TelescopeSearchEntryException("SearchEntry must have 'move_row_selection_up' monkey patched...")
|
||||
|
||||
def move_row_selection_down(self):
|
||||
raise TelescopeSearchEntryException("SearchEntry must have 'move_row_selection_down' monkey patched...")
|
||||
|
||||
105
plugins/code/ui/telescope/telescope.py
Normal file
105
plugins/code/ui/telescope/telescope.py
Normal file
@@ -0,0 +1,105 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
from .list_box import ListBox
|
||||
from .search_entry import SearchEntry
|
||||
|
||||
|
||||
|
||||
class Telescope(Gtk.Dialog):
|
||||
def __init__(self):
|
||||
super(Telescope, self).__init__()
|
||||
|
||||
self.source_view = None
|
||||
|
||||
self._setup_styling()
|
||||
self._setup_signals()
|
||||
self._subscribe_to_events()
|
||||
self._load_widgets()
|
||||
|
||||
|
||||
def _setup_styling(self):
|
||||
self.set_modal(False)
|
||||
self.set_decorated(False)
|
||||
self.set_vexpand(True)
|
||||
self.set_hexpand(True)
|
||||
|
||||
def _setup_signals(self):
|
||||
self.connect("focus-out-event", self._focus_out_event)
|
||||
self.connect("show", self._show)
|
||||
|
||||
def _subscribe_to_events(self):
|
||||
...
|
||||
|
||||
def _load_widgets(self):
|
||||
content_area = self.get_content_area()
|
||||
self.main_box = Gtk.Box()
|
||||
left_box = Gtk.Box()
|
||||
|
||||
self.list_box = ListBox()
|
||||
self.list_box.set_buffer = self.set_buffer
|
||||
|
||||
self.search_entry = SearchEntry()
|
||||
|
||||
self.search_entry.hide = self._focus_out_event
|
||||
self.search_entry.search_changed = self.list_box.search_changed
|
||||
self.search_entry.activate_row = self.list_box.activate_row
|
||||
self.search_entry.move_row_selection_up = self.list_box.move_row_selection_up
|
||||
self.search_entry.move_row_selection_down = self.list_box.move_row_selection_down
|
||||
|
||||
self.main_box.set_orientation(Gtk.Orientation.HORIZONTAL)
|
||||
left_box.set_orientation(Gtk.Orientation.VERTICAL)
|
||||
|
||||
left_box.add(self.list_box)
|
||||
left_box.add(self.search_entry)
|
||||
self.main_box.pack_start(left_box, False, False, 0)
|
||||
|
||||
content_area.add(self.main_box)
|
||||
content_area.show_all()
|
||||
|
||||
def _focus_out_event(self, widget = None, event = None):
|
||||
self.hide()
|
||||
|
||||
def _show(self, widget):
|
||||
GLib.idle_add(self.search_entry.grab_focus)
|
||||
|
||||
def _map_resize(self, widget, parent):
|
||||
parent_x, parent_y = parent.get_position()
|
||||
parent_width, parent_height = parent.get_size()
|
||||
if parent_width == 0 or parent_height == 0: return
|
||||
|
||||
width = int(parent_width * 0.75)
|
||||
height = int(parent_height * 0.75)
|
||||
|
||||
widget.resize(width, height)
|
||||
|
||||
x = parent_x + (parent_width - width) // 2
|
||||
y = parent_y + (parent_height - height) // 2
|
||||
widget.move(x, y)
|
||||
|
||||
def set_emit(self, emit):
|
||||
self.list_box.emit = emit
|
||||
|
||||
def set_active_row(self, buffer):
|
||||
self.list_box.set_active_row(buffer)
|
||||
|
||||
def set_buffer(self, buffer):
|
||||
self.source_view.set_buffer(buffer)
|
||||
|
||||
def map_parent_resize_event(self, parent):
|
||||
parent.connect("size-allocate", lambda w, r: self._map_resize(self, parent))
|
||||
|
||||
def set_source_view(self, source_view):
|
||||
scrolled_win = Gtk.ScrolledWindow()
|
||||
self.source_view = source_view
|
||||
|
||||
scrolled_win.add(self.source_view)
|
||||
self.main_box.pack_end(scrolled_win, True, True, 0)
|
||||
|
||||
scrolled_win.show_all()
|
||||
Reference in New Issue
Block a user