generated from itdominator/Python-With-Gtk-Template
Added deep indent on : or { ending lines plus regular indent for multi insert
This commit is contained in:
parent
35bc3faa70
commit
d90ed2fdc8
@ -6,6 +6,7 @@ gi.require_version('Gtk', '3.0')
|
|||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
from ..widgets.separator_widget import Separator
|
||||||
from ..widgets.miniview_widget import MiniViewWidget
|
from ..widgets.miniview_widget import MiniViewWidget
|
||||||
from ..widgets.base.notebook.editor_notebook import EditorNotebook
|
from ..widgets.base.notebook.editor_notebook import EditorNotebook
|
||||||
|
|
||||||
@ -38,7 +39,6 @@ class EditorsPaned(Gtk.Paned):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class EditorsContainer(Gtk.Box):
|
class EditorsContainer(Gtk.Box):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(EditorsContainer, self).__init__()
|
super(EditorsContainer, self).__init__()
|
||||||
@ -61,5 +61,7 @@ class EditorsContainer(Gtk.Box):
|
|||||||
...
|
...
|
||||||
|
|
||||||
def _load_widgets(self):
|
def _load_widgets(self):
|
||||||
|
self.add(Separator("separator_left"))
|
||||||
self.add(EditorsPaned())
|
self.add(EditorsPaned())
|
||||||
|
self.add(Separator("separator_right"))
|
||||||
self.add(MiniViewWidget())
|
self.add(MiniViewWidget())
|
@ -59,6 +59,7 @@ class EditorControllerMixin:
|
|||||||
if action == "set_buffer_style":
|
if action == "set_buffer_style":
|
||||||
self.set_buffer_style(source_view, query)
|
self.set_buffer_style(source_view, query)
|
||||||
if action == "save_file":
|
if action == "save_file":
|
||||||
source_view.save_file()
|
return source_view.save_file()
|
||||||
if action == "save_file_as":
|
if action == "save_file_as":
|
||||||
source_view.save_file_as()
|
return source_view.save_file_as()
|
||||||
|
|
||||||
|
@ -93,6 +93,49 @@ class MarkEventsMixin:
|
|||||||
|
|
||||||
self.end_user_action(buffer)
|
self.end_user_action(buffer)
|
||||||
|
|
||||||
|
def _new_line_on_multi_line_markers(self, buffer):
|
||||||
|
self.insert_indent_handler(buffer)
|
||||||
|
|
||||||
|
for mark in self._multi_insert_marks:
|
||||||
|
iter = buffer.get_iter_at_mark(mark)
|
||||||
|
self.insert_indent_handler(buffer, iter)
|
||||||
|
|
||||||
|
self.end_user_action(buffer)
|
||||||
|
|
||||||
|
def insert_indent_handler(self, buffer, iter = None):
|
||||||
|
if not iter:
|
||||||
|
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
|
|
||||||
|
iter_copy = iter.copy()
|
||||||
|
iter_moved = iter_copy.backward_char()
|
||||||
|
|
||||||
|
if iter_moved:
|
||||||
|
_char = iter_copy.get_char()
|
||||||
|
self._base_indent(buffer, iter, iter_copy)
|
||||||
|
if _char in ["{", ":"]:
|
||||||
|
self._indent_deeper(buffer, iter)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def _base_indent(self, buffer, iter, iter_copy):
|
||||||
|
line_num = iter_copy.get_line()
|
||||||
|
iter_copy = buffer.get_iter_at_line(line_num)
|
||||||
|
|
||||||
|
spaces = ""
|
||||||
|
_char = iter_copy.get_char()
|
||||||
|
while _char == " ":
|
||||||
|
spaces += " "
|
||||||
|
iter_copy.forward_char()
|
||||||
|
_char = iter_copy.get_char()
|
||||||
|
|
||||||
|
buffer.insert(iter, f"\n{spaces}")
|
||||||
|
|
||||||
|
|
||||||
|
def _indent_deeper(self, buffer, iter):
|
||||||
|
buffer.insert(iter, " ")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def begin_user_action(self, buffer):
|
def begin_user_action(self, buffer):
|
||||||
if len(self._multi_insert_marks) > 0:
|
if len(self._multi_insert_marks) > 0:
|
||||||
buffer.begin_user_action()
|
buffer.begin_user_action()
|
||||||
|
@ -160,9 +160,6 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
is_alt = True if modifiers & Gdk.ModifierType.MOD1_MASK else False
|
is_alt = True if modifiers & Gdk.ModifierType.MOD1_MASK else False
|
||||||
|
|
||||||
if is_control:
|
if is_control:
|
||||||
if keyname in [ "slash", "Up", "Down", "z" ]:
|
|
||||||
return True
|
|
||||||
|
|
||||||
if is_shift:
|
if is_shift:
|
||||||
if keyname in [ "z", "Up", "Down", "Left", "Right" ]:
|
if keyname in [ "z", "Up", "Down", "Left", "Right" ]:
|
||||||
# NOTE: For now do like so for completion sake above.
|
# NOTE: For now do like so for completion sake above.
|
||||||
@ -171,18 +168,32 @@ class SourceView(SourceViewEventsMixin, GtkSource.View):
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if keyname in [ "slash", "Up", "Down", "z" ]:
|
||||||
|
return True
|
||||||
|
|
||||||
if is_alt:
|
if is_alt:
|
||||||
if keyname in [ "Up", "Down", "Left", "Right" ]:
|
if keyname in [ "Up", "Down", "Left", "Right" ]:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if keyname == "BackSpace":
|
|
||||||
if len(self._multi_insert_marks) > 0:
|
if len(self._multi_insert_marks) > 0:
|
||||||
|
if keyname == "BackSpace":
|
||||||
self.begin_user_action(buffer)
|
self.begin_user_action(buffer)
|
||||||
with buffer.freeze_notify():
|
with buffer.freeze_notify():
|
||||||
GLib.idle_add(self._delete_on_multi_line_markers, *(buffer,))
|
GLib.idle_add(self._delete_on_multi_line_markers, *(buffer,))
|
||||||
|
|
||||||
|
if keyname in {"Return", "Enter"}:
|
||||||
|
self.begin_user_action(buffer)
|
||||||
|
with buffer.freeze_notify():
|
||||||
|
GLib.idle_add(self._new_line_on_multi_line_markers, *(buffer,))
|
||||||
|
else:
|
||||||
|
...
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
if keyname in {"Return", "Enter"}:
|
||||||
|
return self.insert_indent_handler(buffer)
|
||||||
|
|
||||||
# NOTE: if a plugin recieves the call and handles, it will be the final decider for propigation
|
# NOTE: if a plugin recieves the call and handles, it will be the final decider for propigation
|
||||||
return event_system.emit_and_await("autopairs", (keyname, is_control, is_alt, is_shift))
|
return event_system.emit_and_await("autopairs", (keyname, is_control, is_alt, is_shift))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user