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:
2026-03-08 14:51:11 -05:00
parent 99dc917de3
commit 7ee484f0c0
13 changed files with 165 additions and 96 deletions

View File

@@ -0,0 +1,3 @@
"""
Pligin Module
"""

View File

@@ -0,0 +1,3 @@
"""
Pligin Package
"""

View File

@@ -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)

View 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)

View File

@@ -0,0 +1,7 @@
{
"name": "Nanoesq Temp Buffer",
"author": "ITDominator",
"version": "0.0.1",
"support": "",
"requests": {}
}

View File

@@ -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)

View 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):
...

View File

@@ -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()

View File

@@ -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
@@ -22,8 +23,8 @@ def execute(
):
logger.debug("Command: DnD Load File To Buffer")
file = view.command.new_file(view)
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())

View File

@@ -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()

View File

@@ -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)
]

View File

@@ -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)

View File

@@ -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"
},