diff --git a/src/__builtins__.py b/src/__builtins__.py index 4686531..7dc3a0e 100644 --- a/src/__builtins__.py +++ b/src/__builtins__.py @@ -48,4 +48,4 @@ builtins.logger = Logger(settings_manager.get_home_config_path(), \ builtins.threaded = threaded_wrapper builtins.daemon_threaded = daemon_threaded_wrapper -builtins.event_sleep_time = 0.05 +builtins.event_sleep_time = 0.05 \ No newline at end of file diff --git a/src/app.py b/src/app.py index 2884083..f0d74f3 100644 --- a/src/app.py +++ b/src/app.py @@ -33,4 +33,4 @@ class Application(IPCServer): raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...") - Window(args, unknownargs) \ No newline at end of file + Window(args, unknownargs) diff --git a/src/core/widgets/base/notebook/editor_controller.py b/src/core/widgets/base/notebook/editor_controller.py index 9d4af23..308d8cf 100644 --- a/src/core/widgets/base/notebook/editor_controller.py +++ b/src/core/widgets/base/notebook/editor_controller.py @@ -19,18 +19,6 @@ class EditorControllerMixin: return page_num, container, source_view = self.get_active_view() - if action == "do_text_search": - self.do_text_search(source_view, query) - if action == "set_buffer_language": - self.set_buffer_language(source_view, query) - if action == "set_buffer_style": - self.set_buffer_style(source_view, query) - if action == "toggle_highlight_line": - self.toggle_highlight_line(source_view) - if action == "scale_up_text": - self.scale_up_text(source_view) - if action == "scale_down_text": - self.scale_down_text(source_view) if action == "close_tab": self.close_tab(None, container, source_view) if action == "keyboard_prev_tab": @@ -41,12 +29,29 @@ class EditorControllerMixin: self.keyboard_move_tab_left(page_num) if action == "keyboard_move_tab_right": self.keyboard_move_tab_right(page_num) - if action == "keyboard_insert_mark": - self.keyboard_insert_mark(source_view) if action == "keyboard_move_tab_to_1": self.keyboard_move_tab_to_1(page_num) if action == "keyboard_move_tab_to_2": self.keyboard_move_tab_to_2(page_num) + + + # NOTE: These feel bad being here man... + if action == "scale_up_text": + self.scale_up_text(source_view) + if action == "scale_down_text": + self.scale_down_text(source_view) + if action == "toggle_highlight_line": + self.toggle_highlight_line(source_view) + if action == "keyboard_insert_mark": + self.keyboard_insert_mark(source_view) + if action == "keyboard_clear_marks": + self.keyboard_clear_marks(source_view) + if action == "do_text_search": + self.do_text_search(source_view, query) + if action == "set_buffer_language": + self.set_buffer_language(source_view, query) + if action == "set_buffer_style": + self.set_buffer_style(source_view, query) if action == "save_file": source_view.save_file() if action == "save_file_as": diff --git a/src/core/widgets/base/notebook/editor_events.py b/src/core/widgets/base/notebook/editor_events.py index b2a2783..b5976d9 100644 --- a/src/core/widgets/base/notebook/editor_events.py +++ b/src/core/widgets/base/notebook/editor_events.py @@ -47,16 +47,6 @@ class EditorEventsMixin: if self.NAME == "notebook_2" and self.get_n_pages() == 0: self.hide() - - def do_text_search(self, query = ""): - source_view.scale_down_text() - - def set_buffer_language(self, source_view, language = "python3"): - source_view.set_buffer_language(language) - - def set_buffer_style(self, source_view, style = "tango"): - source_view.set_buffer_style(style) - def keyboard_prev_tab(self, page_num): page_num = self.get_n_pages() - 1 if page_num == 0 else page_num - 1 self.set_current_page(page_num) @@ -65,10 +55,6 @@ class EditorEventsMixin: page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1 self.set_current_page(page_num) - # NOTE: This feels bad man... - def keyboard_insert_mark(self, source_view): - source_view.keyboard_insert_mark() - def keyboard_move_tab_to_1(self, page_num): notebook = self.builder.get_object("notebook_1") if self.NAME == "notebook_1": @@ -111,6 +97,10 @@ class EditorEventsMixin: page_num = 0 if self.get_n_pages() - 1 == page_num else page_num + 1 self.reorder_child(page, page_num) + + + + # NOTE: These feel bad being here man... def scale_up_text(self, source_view): source_view.scale_up_text() @@ -119,3 +109,19 @@ class EditorEventsMixin: def toggle_highlight_line(self, source_view): source_view.toggle_highlight_line() + + def keyboard_insert_mark(self, source_view): + source_view.keyboard_insert_mark() + + def keyboard_clear_marks(self, source_view): + source_view.keyboard_clear_marks() + + def do_text_search(self, query = ""): + # source_view.scale_down_text() + ... + + def set_buffer_language(self, source_view, language = "python3"): + source_view.set_buffer_language(language) + + def set_buffer_style(self, source_view, style = "tango"): + source_view.set_buffer_style(style) diff --git a/src/core/widgets/base/notebook/editor_notebook.py b/src/core/widgets/base/notebook/editor_notebook.py index f408ef4..6984eff 100644 --- a/src/core/widgets/base/notebook/editor_notebook.py +++ b/src/core/widgets/base/notebook/editor_notebook.py @@ -72,6 +72,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_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) event_system.subscribe("keyboard_scale_up_text", self._keyboard_scale_up_text) @@ -174,6 +175,9 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook): def _keyboard_insert_mark(self): self.action_controller("keyboard_insert_mark") + def _keyboard_clear_marks(self): + self.action_controller("keyboard_clear_marks") + def _keyboard_move_tab_to_1(self): self.action_controller("keyboard_move_tab_to_1") diff --git a/src/core/widgets/base/sourceview/source_view.py b/src/core/widgets/base/sourceview/source_view.py index 9d41afc..a2acf42 100644 --- a/src/core/widgets/base/sourceview/source_view.py +++ b/src/core/widgets/base/sourceview/source_view.py @@ -41,7 +41,9 @@ class SourceView(SourceViewEventsMixin, GtkSource.View): self._ignore_internal_change = False self._buffer = self.get_buffer() self._completion = self.get_completion() - self._insert_marks = [] + + self._multi_insert_marks = [] + self.freeze_multi_line_insert = False self._setup_styling() self._setup_signals() @@ -70,6 +72,7 @@ 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) @@ -110,13 +113,19 @@ class SourceView(SourceViewEventsMixin, GtkSource.View): self.update_cursor_position() def _insert_text(self, text_buffer, location_itr, text_str, len_int): - with text_buffer.freeze_notify(): - for mark in self._insert_marks: - itr = text_buffer.get_iter_at_mark(mark) - print(itr) + if self.freeze_multi_line_insert: return - # GLib.idle_add(text_buffer.insert, *(itr, text_str, -1)) - text_buffer.insert(itr, text_str, -1) + with self._buffer.freeze_notify(): + GLib.idle_add(self._update_multi_line_markers, *(text_str,)) + + def _update_multi_line_markers(self, text_str): + self.freeze_multi_line_insert = True + + for mark in self._multi_insert_marks: + itr = self._buffer.get_iter_at_mark(mark) + self._buffer.insert(itr, text_str, -1) + + self.freeze_multi_line_insert = False def _on_widget_focus(self, widget, eve = None): target = self.get_parent().get_parent().NAME @@ -136,6 +145,15 @@ 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): + if eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 1 : # l-click + if eve.state & Gdk.ModifierType.CONTROL_MASK: + self.keyboard_insert_mark() + else: + self.keyboard_clear_marks() + elif eve.type == Gdk.EventType.BUTTON_RELEASE and eve.button == 3: # r-click + ... + def _set_up_dnd(self): PLAIN_TEXT_TARGET_TYPE = 70 URI_TARGET_TYPE = 80 diff --git a/src/core/widgets/base/sourceview/source_view_events.py b/src/core/widgets/base/sourceview/source_view_events.py index feda4e6..f6fbdbb 100644 --- a/src/core/widgets/base/sourceview/source_view_events.py +++ b/src/core/widgets/base/sourceview/source_view_events.py @@ -52,12 +52,22 @@ class SourceViewEventsMixin: def keyboard_insert_mark(self): iter = self._buffer.get_iter_at_mark( self._buffer.get_insert() ) - mark = Gtk.TextMark.new(name = None, left_gravity = False) + mark = Gtk.TextMark.new(name = f"multi_insert_{len(self._multi_insert_marks)}", left_gravity = False) self._buffer.add_mark(mark, iter) - self._insert_marks.append(mark) + self._multi_insert_marks.append(mark) mark.set_visible(True) + def keyboard_clear_marks(self): + self._buffer.begin_user_action() + + for mark in self._multi_insert_marks: + mark.set_visible(False) + self._buffer.delete_mark(mark) + + self._multi_insert_marks.clear() + self._buffer.end_user_action() + def got_to_line(self, line: int = 0): index = line - 1 buffer = self.get_buffer() diff --git a/src/utils/ipc_server.py b/src/utils/ipc_server.py index 29c4776..2ad105f 100644 --- a/src/utils/ipc_server.py +++ b/src/utils/ipc_server.py @@ -105,4 +105,4 @@ class IPCServer: except ConnectionRefusedError as e: print("Connection refused...") except Exception as e: - print(repr(e)) \ No newline at end of file + print(repr(e)) diff --git a/user_config/usr/share/newton/key-bindings.json b/user_config/usr/share/newton/key-bindings.json index 0a19457..7c98d49 100644 --- a/user_config/usr/share/newton/key-bindings.json +++ b/user_config/usr/share/newton/key-bindings.json @@ -1,8 +1,8 @@ { "keybindings": { "help" : "F1", + "tggl_top_main_menubar" : "0", "open_terminal" : "F4", - "tggl_top_main_menubar" : "Alt_L", "tear_down" : "q", "toggle_highlight_line" : "h", "open_files" : "o", @@ -10,13 +10,14 @@ "keyboard_close_tab" : "w", "keyboard_save_file" : "s", "keyboard_insert_mark" : "m", + "keyboard_clear_marks" : "m", "keyboard_save_file_as" : "s", "keyboard_up" : "Up", "keyboard_down" : "Down", "keyboard_left" : "Left", "keyboard_riht" : "Right", - "keyboard_move_tab_to_1" : "Down", - "keyboard_move_tab_to_2" : "Up", + "keyboard_move_tab_to_1" : "Up", + "keyboard_move_tab_to_2" : "Down", "keyboard_move_tab_right" : "Right", "keyboard_move_tab_left" : "Left", "keyboard_next_tab" : "Up",