Added undo, redo, go-to, and duplicate lines commands; updated styles for line highlight color; cleanup
This commit is contained in:
23
src/core/widgets/code/commands/buffer_redo.py
Normal file
23
src/core/widgets/code/commands/buffer_redo.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Buffer Redo Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
undo_manager = buffer.get_undo_manager()
|
||||||
|
|
||||||
|
if undo_manager.can_redo():
|
||||||
|
buffer.redo()
|
||||||
23
src/core/widgets/code/commands/buffer_undo.py
Normal file
23
src/core/widgets/code/commands/buffer_undo.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Buffer Undo Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
undo_manager = buffer.get_undo_manager()
|
||||||
|
|
||||||
|
if undo_manager.can_undo():
|
||||||
|
buffer.undo()
|
||||||
53
src/core/widgets/code/commands/duplicate_line.py
Normal file
53
src/core/widgets/code/commands/duplicate_line.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Duplicate Line Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
|
||||||
|
if not buffer.get_has_selection():
|
||||||
|
had_selection = False
|
||||||
|
itr = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
|
start_itr = itr.copy()
|
||||||
|
end_itr = itr.copy()
|
||||||
|
start_line = itr.get_line() + 1
|
||||||
|
start_char = itr.get_line_offset()
|
||||||
|
else:
|
||||||
|
had_selection = True
|
||||||
|
start_itr, end_itr = buffer.get_selection_bounds()
|
||||||
|
sline = start_itr.get_line()
|
||||||
|
eline = end_itr.get_line()
|
||||||
|
start_line = eline + 1
|
||||||
|
start_char = start_itr.get_line_offset()
|
||||||
|
end_char = end_itr.get_line_offset()
|
||||||
|
range_line_size = eline - sline
|
||||||
|
|
||||||
|
start_itr.backward_visible_line()
|
||||||
|
start_itr.forward_line()
|
||||||
|
end_itr.forward_line()
|
||||||
|
end_itr.backward_char()
|
||||||
|
|
||||||
|
line_str = buffer.get_slice(start_itr, end_itr, True)
|
||||||
|
end_itr.forward_char()
|
||||||
|
buffer.insert(end_itr, f"{line_str}\n", -1)
|
||||||
|
|
||||||
|
if not had_selection:
|
||||||
|
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
|
||||||
|
buffer.place_cursor(new_itr)
|
||||||
|
else:
|
||||||
|
new_itr = buffer.get_iter_at_line_offset(start_line, start_char)
|
||||||
|
new_end_itr = buffer.get_iter_at_line_offset((start_line + range_line_size), end_char)
|
||||||
|
buffer.select_range(new_itr, new_end_itr)
|
||||||
@@ -17,4 +17,3 @@ def execute(
|
|||||||
logger.debug("Focus Left Sibling Command")
|
logger.debug("Focus Left Sibling Command")
|
||||||
if not view.sibling_left: return
|
if not view.sibling_left: return
|
||||||
view.sibling_left.grab_focus()
|
view.sibling_left.grab_focus()
|
||||||
view.sibling_left.command.exec("set_miniview")
|
|
||||||
|
|||||||
@@ -17,4 +17,3 @@ def execute(
|
|||||||
logger.debug("Focus Right Sibling Command")
|
logger.debug("Focus Right Sibling Command")
|
||||||
if not view.sibling_right: return
|
if not view.sibling_right: return
|
||||||
view.sibling_right.grab_focus()
|
view.sibling_right.grab_focus()
|
||||||
view.sibling_right.command.exec("set_miniview")
|
|
||||||
20
src/core/widgets/code/commands/get_current_file.py
Normal file
20
src/core/widgets/code/commands/get_current_file.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Get Current File Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
return view.files_manager.get_file(buffer)
|
||||||
21
src/core/widgets/code/commands/get_text.py
Normal file
21
src/core/widgets/code/commands/get_text.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Get Text Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
start_itr, end_itr = buffer.get_bounds()
|
||||||
|
return buffer.get_text(start_itr, end_itr, True)
|
||||||
31
src/core/widgets/code/commands/go_to.py
Normal file
31
src/core/widgets/code/commands/go_to.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Go-To Command")
|
||||||
|
|
||||||
|
file = view.command.exec("get_current_file")
|
||||||
|
gfile = file.get_location()
|
||||||
|
uri = gfile.get_uri()
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
iter = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||||
|
line = iter.get_line()
|
||||||
|
offset = iter.get_line_offset()
|
||||||
|
|
||||||
|
event_system.emit(
|
||||||
|
"textDocument/definition",
|
||||||
|
(view, file.ftype, uri, line, offset,)
|
||||||
|
)
|
||||||
23
src/core/widgets/code/commands/set_buffer_language.py
Normal file
23
src/core/widgets/code/commands/set_buffer_language.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View,
|
||||||
|
language: str
|
||||||
|
):
|
||||||
|
logger.debug("Set Buffer Language Command")
|
||||||
|
|
||||||
|
buffer = editor.get_buffer()
|
||||||
|
buffer.set_language(
|
||||||
|
view.language_manager.get_language(language)
|
||||||
|
)
|
||||||
23
src/core/widgets/code/commands/set_buffer_style.py
Normal file
23
src/core/widgets/code/commands/set_buffer_style.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View,
|
||||||
|
style: str
|
||||||
|
):
|
||||||
|
logger.debug("Set Buffer Style Command")
|
||||||
|
|
||||||
|
buffer = editor.get_buffer()
|
||||||
|
buffer.set_style_scheme(
|
||||||
|
view.style_scheme_manager.get_scheme(style)
|
||||||
|
)
|
||||||
21
src/core/widgets/code/get_filetype.py
Normal file
21
src/core/widgets/code/get_filetype.py
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
import gi
|
||||||
|
|
||||||
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def execute(
|
||||||
|
view: GtkSource.View = None
|
||||||
|
):
|
||||||
|
logger.debug("Get File Type Command")
|
||||||
|
|
||||||
|
buffer = view.get_buffer()
|
||||||
|
file = view.files_manager.get_file(buffer)
|
||||||
|
return file.ftype
|
||||||
@@ -86,9 +86,8 @@ class SourceFile(GtkSource.File, ObservableMixin):
|
|||||||
if not gfile: return
|
if not gfile: return
|
||||||
|
|
||||||
with open(gfile.get_path(), 'w') as f:
|
with open(gfile.get_path(), 'w') as f:
|
||||||
start_itr = self.buffer.get_start_iter()
|
start_itr, end_itr = self.buffer.get_bounds()
|
||||||
end_itr = self.buffer.get_end_iter()
|
text = self.buffer.get_text(start_itr, end_itr, True)
|
||||||
text = self.buffer.get_text(start_itr, end_itr, True)
|
|
||||||
|
|
||||||
f.write(text)
|
f.write(text)
|
||||||
|
|
||||||
@@ -99,9 +98,12 @@ class SourceFile(GtkSource.File, ObservableMixin):
|
|||||||
if not gfile: return
|
if not gfile: return
|
||||||
|
|
||||||
self.set_path(gfile)
|
self.set_path(gfile)
|
||||||
data = gfile.load_bytes()[0].get_data().decode("UTF-8")
|
data = gfile.load_bytes()[0].get_data().decode("UTF-8")
|
||||||
|
undo_manager = self.buffer.get_undo_manager()
|
||||||
|
|
||||||
|
undo_manager.begin_not_undoable_action()
|
||||||
self.buffer.insert_at_cursor(data)
|
self.buffer.insert_at_cursor(data)
|
||||||
|
undo_manager.end_not_undoable_action()
|
||||||
|
|
||||||
def set_path(self, gfile: Gio.File):
|
def set_path(self, gfile: Gio.File):
|
||||||
if not gfile: return
|
if not gfile: return
|
||||||
|
|||||||
@@ -18,12 +18,24 @@
|
|||||||
"cut_to_temp_buffer": {
|
"cut_to_temp_buffer": {
|
||||||
"held": "<Control>k"
|
"held": "<Control>k"
|
||||||
},
|
},
|
||||||
|
"duplicate_line": {
|
||||||
|
"held": "<Control>d"
|
||||||
|
},
|
||||||
|
"go_to": {
|
||||||
|
"released": "<Control>g"
|
||||||
|
},
|
||||||
"paste_temp_buffer": {
|
"paste_temp_buffer": {
|
||||||
"held": "<Control>u"
|
"held": "<Control>u"
|
||||||
},
|
},
|
||||||
"new_file": {
|
"new_file": {
|
||||||
"released": "<Control>t"
|
"released": "<Control>t"
|
||||||
},
|
},
|
||||||
|
"buffer_undo": {
|
||||||
|
"held": "<Control>z"
|
||||||
|
},
|
||||||
|
"buffer_redo": {
|
||||||
|
"held": "<Control>y"
|
||||||
|
},
|
||||||
"open_files": {
|
"open_files": {
|
||||||
"released": "<Control>o"
|
"released": "<Control>o"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<author> ITDominator</author>
|
<author> ITDominator</author>
|
||||||
<description>An attempted clone of Dayle Rees' Peacocks In Space theme.</description>
|
<description>An attempted clone of Dayle Rees' Peacocks In Space theme.</description>
|
||||||
|
|
||||||
<style name="current-line" background="#2b303b" />
|
<!--<style name="current-line" background="#2b303b" />-->
|
||||||
|
<style name="current-line" background="#44475a" />
|
||||||
<style name="current-line-number" background="#f7b83d" />
|
<style name="current-line-number" background="#f7b83d" />
|
||||||
<style name="draw-spaces" foreground="#babdb6" />
|
<style name="draw-spaces" foreground="#babdb6" />
|
||||||
<style name="background-pattern" background="#6e7a94" />
|
<style name="background-pattern" background="#6e7a94" />
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
<author> ITDominator</author>
|
<author> ITDominator</author>
|
||||||
<description>An homage to Dayle Rees' Peacocks In Space theme.</description>
|
<description>An homage to Dayle Rees' Peacocks In Space theme.</description>
|
||||||
|
|
||||||
<style name="current-line" background="#2b303b" />
|
<!--<style name="current-line" background="#2b303b" />-->
|
||||||
|
<style name="current-line" background="#44475a" />
|
||||||
<style name="current-line-number" background="#f7b83d" />
|
<style name="current-line-number" background="#f7b83d" />
|
||||||
<style name="draw-spaces" foreground="#babdb6" />
|
<style name="draw-spaces" foreground="#babdb6" />
|
||||||
<style name="background-pattern" background="#6e7a94" />
|
<style name="background-pattern" background="#6e7a94" />
|
||||||
|
|||||||
Reference in New Issue
Block a user