Remove temp cut buffer commands and cleanup related SourceView code
- Moved cut_to_temp_buffer and paste_temp_buffer commands to plugin - Remove temp buffer state and timeout logic from SourceView - Remove associated keybindings (Ctrl+K / Ctrl+U) - Ignore "buffer" pseudo-path when filtering loaded files - Ensure view receives focus after DnD file load
This commit is contained in:
3
plugins/code/commands/nanoesq_temp_buffer/__init__.py
Normal file
3
plugins/code/commands/nanoesq_temp_buffer/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Module
|
||||
"""
|
||||
3
plugins/code/commands/nanoesq_temp_buffer/__main__.py
Normal file
3
plugins/code/commands/nanoesq_temp_buffer/__main__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Pligin Package
|
||||
"""
|
||||
@@ -0,0 +1,44 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .helpers import clear_temp_cut_buffer_delayed, set_temp_cut_buffer_delayed
|
||||
|
||||
|
||||
|
||||
class Handler:
|
||||
@staticmethod
|
||||
def execute(
|
||||
view: GtkSource.View,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Cut to Temp Buffer")
|
||||
|
||||
clear_temp_cut_buffer_delayed(view)
|
||||
|
||||
buffer = view.get_buffer()
|
||||
itr = buffer.get_iter_at_mark(buffer.get_insert())
|
||||
|
||||
start_itr = itr.copy()
|
||||
start_itr.set_line_offset(0)
|
||||
|
||||
end_itr = start_itr.copy()
|
||||
if not end_itr.forward_line():
|
||||
end_itr = buffer.get_end_iter()
|
||||
|
||||
if not hasattr(view, "_cut_buffer"):
|
||||
view._cut_buffer = ""
|
||||
|
||||
line_str = buffer.get_text(start_itr, end_itr, True)
|
||||
view._cut_buffer += line_str
|
||||
|
||||
buffer.delete(start_itr, end_itr)
|
||||
|
||||
set_temp_cut_buffer_delayed(view)
|
||||
24
plugins/code/commands/nanoesq_temp_buffer/helpers.py
Normal file
24
plugins/code/commands/nanoesq_temp_buffer/helpers.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
from gi.repository import GLib
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
def clear_temp_cut_buffer_delayed(view: any):
|
||||
if not hasattr(view, "_cut_temp_timeout_id"): return
|
||||
if not view._cut_temp_timeout_id: return
|
||||
|
||||
GLib.source_remove(view._cut_temp_timeout_id)
|
||||
|
||||
def set_temp_cut_buffer_delayed(view: any):
|
||||
def clear_temp_buffer(view: any):
|
||||
view._cut_buffer = ""
|
||||
view._cut_temp_timeout_id = None
|
||||
return False
|
||||
|
||||
view._cut_temp_timeout_id = GLib.timeout_add(15000, clear_temp_buffer, view)
|
||||
7
plugins/code/commands/nanoesq_temp_buffer/manifest.json
Normal file
7
plugins/code/commands/nanoesq_temp_buffer/manifest.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "Nanoesq Temp Buffer",
|
||||
"author": "ITDominator",
|
||||
"version": "0.0.1",
|
||||
"support": "",
|
||||
"requests": {}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .helpers import clear_temp_cut_buffer_delayed, set_temp_cut_buffer_delayed
|
||||
|
||||
|
||||
class Handler2:
|
||||
@staticmethod
|
||||
def execute(
|
||||
view: GtkSource.View,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Paste Temp Buffer")
|
||||
if not hasattr(view, "_cut_temp_timeout_id"): return
|
||||
if not hasattr(view, "_cut_buffer"): return
|
||||
if not view._cut_buffer: return
|
||||
|
||||
clear_temp_cut_buffer_delayed(view)
|
||||
|
||||
buffer = view.get_buffer()
|
||||
itr = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||
insert_itr = itr.copy()
|
||||
|
||||
buffer.insert(insert_itr, view._cut_buffer, -1)
|
||||
|
||||
set_temp_cut_buffer_delayed(view)
|
||||
43
plugins/code/commands/nanoesq_temp_buffer/plugin.py
Normal file
43
plugins/code/commands/nanoesq_temp_buffer/plugin.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.event_factory import Event_Factory, Code_Event_Types
|
||||
|
||||
from plugins.plugin_types import PluginCode
|
||||
|
||||
from .cut_to_temp_buffer import Handler
|
||||
from .paste_temp_buffer import Handler2
|
||||
|
||||
|
||||
|
||||
class Plugin(PluginCode):
|
||||
def __init__(self):
|
||||
super(Plugin, self).__init__()
|
||||
|
||||
|
||||
def _controller_message(self, event: Code_Event_Types.CodeEvent):
|
||||
...
|
||||
|
||||
def load(self):
|
||||
event = Event_Factory.create_event("register_command",
|
||||
command_name = "cut_to_temp_buffer",
|
||||
command = Handler,
|
||||
binding_mode = "held",
|
||||
binding = "<Control>k"
|
||||
)
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
event = Event_Factory.create_event("register_command",
|
||||
command_name = "paste_temp_buffer",
|
||||
command = Handler2,
|
||||
binding_mode = "held",
|
||||
binding = "<Control>u"
|
||||
)
|
||||
|
||||
self.emit_to("source_views", event)
|
||||
|
||||
def run(self):
|
||||
...
|
||||
@@ -1,41 +0,0 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
view: GtkSource.View,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Cut to Temp Buffer")
|
||||
|
||||
view.clear_temp_cut_buffer_delayed()
|
||||
|
||||
buffer = view.get_buffer()
|
||||
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()
|
||||
|
||||
if not start_itr.starts_line():
|
||||
start_itr.backward_visible_line()
|
||||
start_itr.forward_line()
|
||||
|
||||
if not end_itr.ends_line():
|
||||
end_itr.forward_line()
|
||||
|
||||
line_str = buffer.get_slice(start_itr, end_itr, True)
|
||||
view._cut_buffer += f"{line_str}"
|
||||
buffer.delete(start_itr, end_itr)
|
||||
|
||||
view.set_temp_cut_buffer_delayed()
|
||||
@@ -7,6 +7,7 @@ gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GtkSource
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gdk
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
@@ -21,9 +22,9 @@ def execute(
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: DnD Load File To Buffer")
|
||||
file = view.command.new_file(view)
|
||||
file = view.command.new_file(view)
|
||||
gfile = Gio.File.new_for_uri(uri)
|
||||
|
||||
gfile = Gio.File.new_for_uri(uri)
|
||||
view.command.exec_with_args(
|
||||
"load_file",
|
||||
view, gfile, file
|
||||
@@ -32,3 +33,4 @@ def execute(
|
||||
view.set_buffer(file.buffer)
|
||||
|
||||
update_info_bar_if_focused(view.command, view)
|
||||
view.emit("focus-in-event", Gdk.Event())
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
import gi
|
||||
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
|
||||
def execute(
|
||||
view: GtkSource.View,
|
||||
*args,
|
||||
**kwargs
|
||||
):
|
||||
logger.debug("Command: Paste Temp Buffer")
|
||||
|
||||
view.clear_temp_cut_buffer_delayed()
|
||||
|
||||
buffer = view.get_buffer()
|
||||
itr = buffer.get_iter_at_mark( buffer.get_insert() )
|
||||
insert_itr = itr.copy()
|
||||
|
||||
buffer.insert(insert_itr, view._cut_buffer, -1)
|
||||
|
||||
view.set_temp_cut_buffer_delayed()
|
||||
@@ -33,7 +33,8 @@ class FilesController(ControllerBase, list):
|
||||
|
||||
|
||||
def filter_loaded(self, event: Code_Event_Types.FilterOutLoadedFilesEvent):
|
||||
loaded_paths = {file.fpath for file in self}
|
||||
loaded_paths = {file.fpath for file in self if not file.fpath == "buffer"}
|
||||
|
||||
files = [
|
||||
uri for uri in event.uris if not any(path in uri for path in loaded_paths)
|
||||
]
|
||||
|
||||
@@ -6,7 +6,6 @@ gi.require_version('Gtk', '3.0')
|
||||
gi.require_version('GtkSource', '4')
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
@@ -22,9 +21,6 @@ class SourceView(GtkSource.View, SourceViewDnDMixin):
|
||||
|
||||
self.state = state
|
||||
|
||||
self._cut_temp_timeout_id = None
|
||||
self._cut_buffer = ""
|
||||
|
||||
self.sibling_right = None
|
||||
self.sibling_left = None
|
||||
|
||||
@@ -74,15 +70,3 @@ class SourceView(GtkSource.View, SourceViewDnDMixin):
|
||||
)
|
||||
|
||||
self._set_up_dnd()
|
||||
|
||||
def clear_temp_cut_buffer_delayed(self):
|
||||
if self._cut_temp_timeout_id:
|
||||
GLib.source_remove(self._cut_temp_timeout_id)
|
||||
|
||||
def set_temp_cut_buffer_delayed(self):
|
||||
def clear_temp_buffer():
|
||||
self._cut_buffer = ""
|
||||
self._cut_temp_timeout_id = None
|
||||
return False
|
||||
|
||||
self._cut_temp_timeout_id = GLib.timeout_add(15000, clear_temp_buffer)
|
||||
|
||||
@@ -15,18 +15,12 @@
|
||||
"zoom_out": {
|
||||
"held": "<Control>minus"
|
||||
},
|
||||
"cut_to_temp_buffer": {
|
||||
"held": "<Control>k"
|
||||
},
|
||||
"duplicate_line": {
|
||||
"held": "<Control>d"
|
||||
},
|
||||
"go_to": {
|
||||
"released": "<Control>g"
|
||||
},
|
||||
"paste_temp_buffer": {
|
||||
"held": "<Control>u"
|
||||
},
|
||||
"new_file": {
|
||||
"released": "<Control>t"
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user