generated from itdominator/Python-With-Gtk-Template
Mostly sinking sourceview pre-bound keys
This commit is contained in:
parent
92f1eab4d8
commit
f1cc022079
@ -38,6 +38,10 @@ class EditorControllerMixin:
|
|||||||
# NOTE: These feel bad being here man...
|
# NOTE: These feel bad being here man...
|
||||||
if action == "scale_up_text":
|
if action == "scale_up_text":
|
||||||
self.scale_up_text(source_view)
|
self.scale_up_text(source_view)
|
||||||
|
if action == "keyboard_undo":
|
||||||
|
self.keyboard_undo(source_view)
|
||||||
|
if action == "keyboard_redo":
|
||||||
|
self.keyboard_redo(source_view)
|
||||||
if action == "scale_down_text":
|
if action == "scale_down_text":
|
||||||
self.scale_down_text(source_view)
|
self.scale_down_text(source_view)
|
||||||
if action == "toggle_highlight_line":
|
if action == "toggle_highlight_line":
|
||||||
|
@ -101,6 +101,12 @@ class EditorEventsMixin:
|
|||||||
|
|
||||||
|
|
||||||
# NOTE: These feel bad being here man...
|
# NOTE: These feel bad being here man...
|
||||||
|
def keyboard_undo(self, source_view):
|
||||||
|
source_view.keyboard_undo()
|
||||||
|
|
||||||
|
def keyboard_redo(self, source_view):
|
||||||
|
source_view.keyboard_redo()
|
||||||
|
|
||||||
def scale_up_text(self, source_view):
|
def scale_up_text(self, source_view):
|
||||||
source_view.scale_up_text()
|
source_view.scale_up_text()
|
||||||
|
|
||||||
|
@ -69,6 +69,8 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
event_system.subscribe("keyboard_create_tab", self._keyboard_create_tab)
|
event_system.subscribe("keyboard_create_tab", self._keyboard_create_tab)
|
||||||
event_system.subscribe("keyboard_open_file", self._keyboard_open_file)
|
event_system.subscribe("keyboard_open_file", self._keyboard_open_file)
|
||||||
event_system.subscribe("keyboard_close_tab", self._keyboard_close_tab)
|
event_system.subscribe("keyboard_close_tab", self._keyboard_close_tab)
|
||||||
|
event_system.subscribe("keyboard_undo", self._keyboard_undo)
|
||||||
|
event_system.subscribe("keyboard_redo", self._keyboard_redo)
|
||||||
event_system.subscribe("keyboard_prev_tab", self._keyboard_prev_tab)
|
event_system.subscribe("keyboard_prev_tab", self._keyboard_prev_tab)
|
||||||
event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab)
|
event_system.subscribe("keyboard_next_tab", self._keyboard_next_tab)
|
||||||
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
|
event_system.subscribe("keyboard_move_tab_left", self._keyboard_move_tab_left)
|
||||||
@ -155,9 +157,19 @@ class EditorNotebook(EditorEventsMixin, EditorControllerMixin, Gtk.Notebook):
|
|||||||
self.create_view(gfile = _gfile)
|
self.create_view(gfile = _gfile)
|
||||||
|
|
||||||
|
|
||||||
|
# NOTE: These feel bad being here man...
|
||||||
def _keyboard_close_tab(self):
|
def _keyboard_close_tab(self):
|
||||||
self.action_controller("close_tab")
|
self.action_controller("close_tab")
|
||||||
|
|
||||||
|
def _keyboard_close_tab(self):
|
||||||
|
self.action_controller("close_tab")
|
||||||
|
|
||||||
|
def _keyboard_undo(self):
|
||||||
|
self.action_controller("keyboard_undo")
|
||||||
|
|
||||||
|
def _keyboard_redo(self):
|
||||||
|
self.action_controller("keyboard_redo")
|
||||||
|
|
||||||
def _toggle_highlight_line(self):
|
def _toggle_highlight_line(self):
|
||||||
self.action_controller("toggle_highlight_line")
|
self.action_controller("toggle_highlight_line")
|
||||||
|
|
||||||
|
@ -75,6 +75,24 @@ class MarkEventsMixin:
|
|||||||
iter = self._buffer.get_iter_at_mark(mark)
|
iter = self._buffer.get_iter_at_mark(mark)
|
||||||
self._buffer.insert(iter, text_str, -1)
|
self._buffer.insert(iter, text_str, -1)
|
||||||
|
|
||||||
|
self.end_user_action()
|
||||||
|
|
||||||
|
def _delete_on_multi_line_markers(self):
|
||||||
|
iter = self._buffer.get_iter_at_mark( self._buffer.get_insert() )
|
||||||
|
self._buffer.backspace(iter, interactive = True, default_editable = True)
|
||||||
|
|
||||||
|
for mark in self._multi_insert_marks:
|
||||||
|
iter = self._buffer.get_iter_at_mark(mark)
|
||||||
|
self._buffer.backspace(iter, interactive = True, default_editable = True)
|
||||||
|
|
||||||
|
self.end_user_action()
|
||||||
|
|
||||||
|
def begin_user_action(self):
|
||||||
|
if len(self._multi_insert_marks) > 0:
|
||||||
|
self._buffer.begin_user_action()
|
||||||
|
self.freeze_multi_line_insert = True
|
||||||
|
|
||||||
|
def end_user_action(self):
|
||||||
if len(self._multi_insert_marks) > 0:
|
if len(self._multi_insert_marks) > 0:
|
||||||
self._buffer.end_user_action()
|
self._buffer.end_user_action()
|
||||||
self.freeze_multi_line_insert = False
|
self.freeze_multi_line_insert = False
|
||||||
|
@ -81,6 +81,7 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
self.connect("focus-in-event", self._focus_in_event)
|
self.connect("focus-in-event", self._focus_in_event)
|
||||||
|
|
||||||
self.connect("drag-data-received", self._on_drag_data_received)
|
self.connect("drag-data-received", self._on_drag_data_received)
|
||||||
|
self.connect("key-press-event", self._key_press_event)
|
||||||
self.connect("button-press-event", self._button_press_event)
|
self.connect("button-press-event", self._button_press_event)
|
||||||
|
|
||||||
self._buffer.connect('changed', self._is_modified)
|
self._buffer.connect('changed', self._is_modified)
|
||||||
@ -124,13 +125,43 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
|
def _insert_text(self, text_buffer, location_itr, text_str, len_int):
|
||||||
if self.freeze_multi_line_insert: return
|
if self.freeze_multi_line_insert: return
|
||||||
|
|
||||||
if len(self._multi_insert_marks) > 0:
|
self.begin_user_action()
|
||||||
self._buffer.begin_user_action()
|
|
||||||
self.freeze_multi_line_insert = True
|
|
||||||
|
|
||||||
with self._buffer.freeze_notify():
|
with self._buffer.freeze_notify():
|
||||||
GLib.idle_add(self._update_multi_line_markers, *(text_str,))
|
GLib.idle_add(self._update_multi_line_markers, *(text_str,))
|
||||||
|
|
||||||
|
# NOTE: Mostly sinking pre-bound keys here to let our keybinder control instead...
|
||||||
|
def _key_press_event(self, widget, eve):
|
||||||
|
keyname = Gdk.keyval_name(eve.keyval)
|
||||||
|
modifiers = Gdk.ModifierType(eve.get_state() & ~Gdk.ModifierType.LOCK_MASK)
|
||||||
|
is_control = True if modifiers & Gdk.ModifierType.CONTROL_MASK else False
|
||||||
|
is_shift = True if modifiers & Gdk.ModifierType.SHIFT_MASK else False
|
||||||
|
|
||||||
|
try:
|
||||||
|
is_alt = True if modifiers & Gdk.ModifierType.ALT_MASK else False
|
||||||
|
except Exception:
|
||||||
|
is_alt = True if modifiers & Gdk.ModifierType.MOD1_MASK else False
|
||||||
|
|
||||||
|
if is_control:
|
||||||
|
if keyname in [ "slash", "Up", "Down", "z" ]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if is_shift:
|
||||||
|
if keyname in [ "z", "Up", "Down", "Left", "Right" ]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if is_alt:
|
||||||
|
if keyname in [ "Up", "Down", "Left", "Right" ]:
|
||||||
|
return True
|
||||||
|
|
||||||
|
if keyname == "BackSpace":
|
||||||
|
if len(self._multi_insert_marks) > 0:
|
||||||
|
self.begin_user_action()
|
||||||
|
with self._buffer.freeze_notify():
|
||||||
|
GLib.idle_add(self._delete_on_multi_line_markers)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
def _button_press_event(self, widget = None, eve = None, user_data = None):
|
def _button_press_event(self, widget = None, eve = None, user_data = None):
|
||||||
if eve.type == Gdk.EventType.BUTTON_PRESS and eve.button == 1 : # l-click
|
if eve.type == Gdk.EventType.BUTTON_PRESS and eve.button == 1 : # l-click
|
||||||
if eve.state & Gdk.ModifierType.CONTROL_MASK:
|
if eve.state & Gdk.ModifierType.CONTROL_MASK:
|
||||||
|
@ -63,9 +63,6 @@ class SourceViewEventsMixin(MarkEventsMixin, FileEventsMixin):
|
|||||||
|
|
||||||
event_system.emit("set_line_char_label", (f"{row}:{col}",))
|
event_system.emit("set_line_char_label", (f"{row}:{col}",))
|
||||||
|
|
||||||
def keyboard_tggl_comment(self):
|
|
||||||
logger.info("SourceViewEventsMixin > keyboard_tggl_comment > stub...")
|
|
||||||
|
|
||||||
def got_to_line(self, line: int = 0):
|
def got_to_line(self, line: int = 0):
|
||||||
index = line - 1
|
index = line - 1
|
||||||
buffer = self.get_buffer()
|
buffer = self.get_buffer()
|
||||||
@ -77,6 +74,7 @@ class SourceViewEventsMixin(MarkEventsMixin, FileEventsMixin):
|
|||||||
buffer.create_mark("starting_cursor", char_iter, True)
|
buffer.create_mark("starting_cursor", char_iter, True)
|
||||||
self.scroll_to_mark( buffer.get_mark("starting_cursor"), 0.0, True, 0.0, 0.0 )
|
self.scroll_to_mark( buffer.get_mark("starting_cursor"), 0.0, True, 0.0, 0.0 )
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/ptomato/inform7-ide/blob/main/src/actions.c
|
# https://github.com/ptomato/inform7-ide/blob/main/src/actions.c
|
||||||
def action_uncomment_selection(self):
|
def action_uncomment_selection(self):
|
||||||
...
|
...
|
||||||
@ -84,6 +82,15 @@ class SourceViewEventsMixin(MarkEventsMixin, FileEventsMixin):
|
|||||||
def action_comment_out_selection(self):
|
def action_comment_out_selection(self):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
def keyboard_tggl_comment(self):
|
||||||
|
logger.info("SourceViewEventsMixin > keyboard_tggl_comment > stub...")
|
||||||
|
|
||||||
|
def keyboard_undo(self):
|
||||||
|
self._buffer.undo()
|
||||||
|
|
||||||
|
def keyboard_redo(self):
|
||||||
|
self._buffer.redo()
|
||||||
|
|
||||||
def move_lines_up(self):
|
def move_lines_up(self):
|
||||||
self.emit("move-lines", *(False,))
|
self.emit("move-lines", *(False,))
|
||||||
|
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
"open_files" : "<Control>o",
|
"open_files" : "<Control>o",
|
||||||
"move_lines_up" : "<Control>Up",
|
"move_lines_up" : "<Control>Up",
|
||||||
"move_lines_down" : "<Control>Down",
|
"move_lines_down" : "<Control>Down",
|
||||||
|
"keyboard_undo" : "<Control>z",
|
||||||
|
"keyboard_redo" : "<Control>y",
|
||||||
"keyboard_create_tab" : "<Control>t",
|
"keyboard_create_tab" : "<Control>t",
|
||||||
"keyboard_close_tab" : "<Control>w",
|
"keyboard_close_tab" : "<Control>w",
|
||||||
"keyboard_save_file" : "<Control>s",
|
"keyboard_save_file" : "<Control>s",
|
||||||
|
Loading…
Reference in New Issue
Block a user