generated from itdominator/Python-With-Gtk-Template
Further multi line edit work done; slight pre refactor work
This commit is contained in:
parent
d292a99791
commit
9d4d7555fd
@ -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
|
@ -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)
|
||||
Window(args, unknownargs)
|
||||
|
@ -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":
|
||||
|
@ -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)
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -105,4 +105,4 @@ class IPCServer:
|
||||
except ConnectionRefusedError as e:
|
||||
print("Connection refused...")
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
print(repr(e))
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"keybindings": {
|
||||
"help" : "F1",
|
||||
"tggl_top_main_menubar" : "<Control>0",
|
||||
"open_terminal" : "F4",
|
||||
"tggl_top_main_menubar" : "Alt_L",
|
||||
"tear_down" : "<Control>q",
|
||||
"toggle_highlight_line" : "<Control>h",
|
||||
"open_files" : "<Control>o",
|
||||
@ -10,13 +10,14 @@
|
||||
"keyboard_close_tab" : "<Control>w",
|
||||
"keyboard_save_file" : "<Control>s",
|
||||
"keyboard_insert_mark" : "<Control>m",
|
||||
"keyboard_clear_marks" : "<Shift><Control>m",
|
||||
"keyboard_save_file_as" : "<Shift><Control>s",
|
||||
"keyboard_up" : "Up",
|
||||
"keyboard_down" : "Down",
|
||||
"keyboard_left" : "Left",
|
||||
"keyboard_riht" : "Right",
|
||||
"keyboard_move_tab_to_1" : "<Shift><Control>Down",
|
||||
"keyboard_move_tab_to_2" : "<Shift><Control>Up",
|
||||
"keyboard_move_tab_to_1" : "<Shift><Control>Up",
|
||||
"keyboard_move_tab_to_2" : "<Shift><Control>Down",
|
||||
"keyboard_move_tab_right" : "<Alt>Right",
|
||||
"keyboard_move_tab_left" : "<Alt>Left",
|
||||
"keyboard_next_tab" : "<Alt>Up",
|
||||
|
Loading…
Reference in New Issue
Block a user