added structural work for more signal handling; fixed focus logic

This commit is contained in:
itdominator 2023-10-09 23:07:10 -05:00
parent 9d4d7555fd
commit 2aa9d3afd9
10 changed files with 68 additions and 12 deletions

View File

@ -50,6 +50,8 @@ class Controller(SignalsMixins, ControllerData):
def _subscribe_to_events(self):
event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc)
event_system.subscribe("set_active_src_view", self.set_active_src_view)
event_system.subscribe("get_active_src_view", self.get_active_src_view)
def load_glade_file(self):
self.builder = Gtk.Builder()
@ -62,4 +64,4 @@ class Controller(SignalsMixins, ControllerData):
settings_manager.register_signals_to_builder([self, self.core_widget])
def get_core_widget(self):
return self.core_widget
return self.core_widget

View File

@ -21,10 +21,20 @@ class ControllerData:
self.ctrl_down = False
self.shift_down = False
self.alt_down = False
self.active_src_view = None
self.load_glade_file()
self.plugins = PluginsController()
def set_active_src_view(self, source_view):
if self.active_src_view:
self.active_src_view.get_parent().get_parent().is_editor_focused = False
self.active_src_view = source_view
def get_active_src_view(self):
return self.active_src_view
def clear_console(self) -> None:
''' Clears the terminal screen. '''

View File

@ -46,6 +46,12 @@ class EditorControllerMixin:
self.keyboard_insert_mark(source_view)
if action == "keyboard_clear_marks":
self.keyboard_clear_marks(source_view)
if action == "move_lines_up":
self.move_lines_up(source_view)
if action == "move_lines_down":
self.move_lines_down(source_view)
if action == "keyboard_tggl_comment":
self.keyboard_tggl_comment(source_view)
if action == "do_text_search":
self.do_text_search(source_view, query)
if action == "set_buffer_language":

View File

@ -116,6 +116,15 @@ class EditorEventsMixin:
def keyboard_clear_marks(self, source_view):
source_view.keyboard_clear_marks()
def move_lines_up(self, source_view):
source_view.move_lines_up()
def move_lines_down(self, source_view):
source_view.move_lines_down()
def keyboard_tggl_comment(self, source_view):
source_view.keyboard_tggl_comment()
def do_text_search(self, query = ""):
# source_view.scale_down_text()
...

View File

@ -64,6 +64,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
event_system.subscribe("set_buffer_language", self.action_controller)
event_system.subscribe("set_buffer_style", self.action_controller)
event_system.subscribe("toggle_highlight_line", self._toggle_highlight_line)
event_system.subscribe("move_lines_up", self._move_lines_up)
event_system.subscribe("move_lines_down", self._move_lines_down)
event_system.subscribe("keyboard_create_tab", self._keyboard_create_tab)
event_system.subscribe("keyboard_open_file", self._keyboard_open_file)
event_system.subscribe("keyboard_close_tab", self._keyboard_close_tab)
@ -72,6 +74,7 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
event_system.subscribe("keyboard_move_tab_right", self._keyboard_move_tab_right)
event_system.subscribe("keyboard_insert_mark", self._keyboard_insert_mark)
event_system.subscribe("keyboard_tggl_comment", self._keyboard_tggl_comment)
event_system.subscribe("keyboard_clear_marks", self._keyboard_clear_marks)
event_system.subscribe("keyboard_move_tab_to_1", self._keyboard_move_tab_to_1)
event_system.subscribe("keyboard_move_tab_to_2", self._keyboard_move_tab_to_2)
@ -175,6 +178,15 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
def _keyboard_insert_mark(self):
self.action_controller("keyboard_insert_mark")
def _move_lines_up(self):
self.action_controller("move_lines_up")
def _move_lines_down(self):
self.action_controller("move_lines_down")
def _keyboard_tggl_comment(self):
self.action_controller("keyboard_tggl_comment")
def _keyboard_clear_marks(self):
self.action_controller("keyboard_clear_marks")

View File

@ -72,13 +72,17 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
self.set_vexpand(True)
def _setup_signals(self):
self.connect("button-release-event", self._keyboard_handle_marks)
self.connect("drag-data-received", self._on_drag_data_received)
self.connect("focus", self._on_widget_focus)
self._buffer.connect("mark-set", self._on_cursor_move)
self.connect("focus-in-event", self._focus_in_event)
self.connect("drag-data-received", self._on_drag_data_received)
self.connect("button-release-event", self._button_release_event)
self._buffer.connect('changed', self._is_modified)
self._buffer.connect("mark-set", self._on_cursor_move)
self._buffer.connect('insert-text', self._insert_text)
def _subscribe_to_events(self):
...
@ -127,6 +131,10 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
self.freeze_multi_line_insert = False
def _focus_in_event(self, widget, eve = None):
event_system.emit("set_active_src_view", (self,))
self.get_parent().get_parent().is_editor_focused = True
def _on_widget_focus(self, widget, eve = None):
target = self.get_parent().get_parent().NAME
path = self._current_file if self._current_file else ""
@ -145,7 +153,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
# NOTE: Not sure but this might not be efficient if the map reloads the same view.
event_system.emit(f"set_source_view", (self,))
def _keyboard_handle_marks(self, widget = None, eve = None, user_data = None):
def _button_release_event(self, widget = None, eve = None, user_data = None):
if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1 : # l-click
if eve.state & Gdk.ModifierType.CONTROL_MASK:
self.keyboard_insert_mark()
@ -244,4 +252,4 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
f.write(text)
f.close()
return gfile
return gfile

View File

@ -50,6 +50,9 @@ class SourceViewEventsMixin:
event_system.emit("set_line_char_label", (f"{row}:{col}",))
def keyboard_tggl_comment(self):
logger.info("SourceViewEventsMixin > keyboard_tggl_comment > stub...")
def keyboard_insert_mark(self):
iter = self._buffer.get_iter_at_mark( self._buffer.get_insert() )
mark = Gtk.TextMark.new(name = f"multi_insert_{len(self._multi_insert_marks)}", left_gravity = False)
@ -86,6 +89,12 @@ class SourceViewEventsMixin:
def action_comment_out_selection(self):
...
def move_lines_up(self):
self.emit("move-lines", *(False,))
def move_lines_down(self):
self.emit("move-lines", *(True,))
def open_file(self, gfile, line: int = 0, *args):
self._current_file = gfile
@ -161,4 +170,4 @@ class SourceViewEventsMixin:
if not gfile: return
event_system.emit("set_bottom_labels", (gfile, None, self._current_filetype, None))
self.update_cursor_position()
self.update_cursor_position()

View File

@ -21,7 +21,7 @@ class ScaleDownButton(Gtk.Button):
def _setup_styling(self):
self.set_label("Zoom")
self.set_image( Gtk.Image.new_from_icon_name("gtk-remove", 4) )
self.set_image( Gtk.Image.new_from_icon_name("gtk-zoom-out", 4) )
self.set_always_show_image(True)
self.set_image_position(1) # Left - 0, Right = 1
self.set_hexpand(False)
@ -36,4 +36,4 @@ class ScaleDownButton(Gtk.Button):
...
def _emit_scale_eve(self, widget, eve = None):
event_system.emit('scale_down_text', ("scale_down_text",))
event_system.emit('keyboard_scale_down_text')

View File

@ -21,7 +21,7 @@ class ScaleUpButton(Gtk.Button):
def _setup_styling(self):
self.set_label("Zoom")
self.set_image( Gtk.Image.new_from_icon_name("gtk-add", 4) )
self.set_image( Gtk.Image.new_from_icon_name("gtk-zoom-in", 4) )
self.set_always_show_image(True)
self.set_image_position(1) # Left - 0, Right = 1
self.set_hexpand(False)
@ -36,4 +36,4 @@ class ScaleUpButton(Gtk.Button):
...
def _emit_scale_eve(self, widget, eve = None):
event_system.emit('scale_up_text', ("scale_up_text",))
event_system.emit('keyboard_scale_up_text')

View File

@ -36,4 +36,4 @@ class ToggleLineHighlight(Gtk.Button):
...
def _emit_toggle_eve(self, widget, eve = None):
event_system.emit('toggle_highlight_line', ("toggle_highlight_line",))
event_system.emit('toggle_highlight_line')