From 2aa9d3afd9b2f1fa6d3d873621e5439cbf7d7ab6 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 9 Oct 2023 23:07:10 -0500 Subject: [PATCH] added structural work for more signal handling; fixed focus logic --- src/core/controller.py | 4 +++- src/core/controller_data.py | 10 ++++++++++ .../widgets/base/notebook/editor_controller.py | 6 ++++++ .../widgets/base/notebook/editor_events.py | 9 +++++++++ .../widgets/base/notebook/editor_notebook.py | 12 ++++++++++++ .../widgets/base/sourceview/source_view.py | 18 +++++++++++++----- .../base/sourceview/source_view_events.py | 11 ++++++++++- src/core/widgets/controls/scale_down_button.py | 4 ++-- src/core/widgets/controls/scale_up_button.py | 4 ++-- .../widgets/controls/toggle_line_highlight.py | 2 +- 10 files changed, 68 insertions(+), 12 deletions(-) diff --git a/src/core/controller.py b/src/core/controller.py index 61b9347..e818f8b 100644 --- a/src/core/controller.py +++ b/src/core/controller.py @@ -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 \ No newline at end of file diff --git a/src/core/controller_data.py b/src/core/controller_data.py index afc1ddc..5a49e62 100644 --- a/src/core/controller_data.py +++ b/src/core/controller_data.py @@ -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. ''' diff --git a/src/core/widgets/base/notebook/editor_controller.py b/src/core/widgets/base/notebook/editor_controller.py index 308d8cf..c6b3f76 100644 --- a/src/core/widgets/base/notebook/editor_controller.py +++ b/src/core/widgets/base/notebook/editor_controller.py @@ -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": diff --git a/src/core/widgets/base/notebook/editor_events.py b/src/core/widgets/base/notebook/editor_events.py index b5976d9..779200c 100644 --- a/src/core/widgets/base/notebook/editor_events.py +++ b/src/core/widgets/base/notebook/editor_events.py @@ -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() ... diff --git a/src/core/widgets/base/notebook/editor_notebook.py b/src/core/widgets/base/notebook/editor_notebook.py index 6984eff..53e200e 100644 --- a/src/core/widgets/base/notebook/editor_notebook.py +++ b/src/core/widgets/base/notebook/editor_notebook.py @@ -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") diff --git a/src/core/widgets/base/sourceview/source_view.py b/src/core/widgets/base/sourceview/source_view.py index a2acf42..b520636 100644 --- a/src/core/widgets/base/sourceview/source_view.py +++ b/src/core/widgets/base/sourceview/source_view.py @@ -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 \ No newline at end of file diff --git a/src/core/widgets/base/sourceview/source_view_events.py b/src/core/widgets/base/sourceview/source_view_events.py index f6fbdbb..81e9f1c 100644 --- a/src/core/widgets/base/sourceview/source_view_events.py +++ b/src/core/widgets/base/sourceview/source_view_events.py @@ -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() \ No newline at end of file diff --git a/src/core/widgets/controls/scale_down_button.py b/src/core/widgets/controls/scale_down_button.py index b734769..49399d5 100644 --- a/src/core/widgets/controls/scale_down_button.py +++ b/src/core/widgets/controls/scale_down_button.py @@ -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') diff --git a/src/core/widgets/controls/scale_up_button.py b/src/core/widgets/controls/scale_up_button.py index 0ae383f..b090dfe 100644 --- a/src/core/widgets/controls/scale_up_button.py +++ b/src/core/widgets/controls/scale_up_button.py @@ -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') diff --git a/src/core/widgets/controls/toggle_line_highlight.py b/src/core/widgets/controls/toggle_line_highlight.py index 2b8f5ec..4218044 100644 --- a/src/core/widgets/controls/toggle_line_highlight.py +++ b/src/core/widgets/controls/toggle_line_highlight.py @@ -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')