diff --git a/plugins/code/commands/nanoesq_temp_buffer/__init__.py b/plugins/code/commands/nanoesq_temp_buffer/__init__.py new file mode 100644 index 0000000..d36fa8c --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/__init__.py @@ -0,0 +1,3 @@ +""" + Pligin Module +""" diff --git a/plugins/code/commands/nanoesq_temp_buffer/__main__.py b/plugins/code/commands/nanoesq_temp_buffer/__main__.py new file mode 100644 index 0000000..a576329 --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/__main__.py @@ -0,0 +1,3 @@ +""" + Pligin Package +""" diff --git a/plugins/code/commands/nanoesq_temp_buffer/cut_to_temp_buffer.py b/plugins/code/commands/nanoesq_temp_buffer/cut_to_temp_buffer.py new file mode 100644 index 0000000..15cf79e --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/cut_to_temp_buffer.py @@ -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) diff --git a/plugins/code/commands/nanoesq_temp_buffer/helpers.py b/plugins/code/commands/nanoesq_temp_buffer/helpers.py new file mode 100644 index 0000000..86a8671 --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/helpers.py @@ -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) diff --git a/plugins/code/commands/nanoesq_temp_buffer/manifest.json b/plugins/code/commands/nanoesq_temp_buffer/manifest.json new file mode 100644 index 0000000..383903a --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/manifest.json @@ -0,0 +1,7 @@ +{ + "name": "Nanoesq Temp Buffer", + "author": "ITDominator", + "version": "0.0.1", + "support": "", + "requests": {} +} diff --git a/plugins/code/commands/nanoesq_temp_buffer/paste_temp_buffer.py b/plugins/code/commands/nanoesq_temp_buffer/paste_temp_buffer.py new file mode 100644 index 0000000..be8d7e2 --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/paste_temp_buffer.py @@ -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) diff --git a/plugins/code/commands/nanoesq_temp_buffer/plugin.py b/plugins/code/commands/nanoesq_temp_buffer/plugin.py new file mode 100644 index 0000000..392caf0 --- /dev/null +++ b/plugins/code/commands/nanoesq_temp_buffer/plugin.py @@ -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 = "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 = "u" + ) + + self.emit_to("source_views", event) + + def run(self): + ... diff --git a/src/core/widgets/code/command_system/commands/cut_to_temp_buffer.py b/src/core/widgets/code/command_system/commands/cut_to_temp_buffer.py deleted file mode 100644 index 0941b38..0000000 --- a/src/core/widgets/code/command_system/commands/cut_to_temp_buffer.py +++ /dev/null @@ -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() diff --git a/src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py b/src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py index ab1da13..165ad5f 100644 --- a/src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py +++ b/src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py @@ -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()) diff --git a/src/core/widgets/code/command_system/commands/paste_temp_buffer.py b/src/core/widgets/code/command_system/commands/paste_temp_buffer.py deleted file mode 100644 index 8c7cd7a..0000000 --- a/src/core/widgets/code/command_system/commands/paste_temp_buffer.py +++ /dev/null @@ -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() diff --git a/src/core/widgets/code/controllers/files_controller.py b/src/core/widgets/code/controllers/files_controller.py index ba660b2..6f7fa00 100644 --- a/src/core/widgets/code/controllers/files_controller.py +++ b/src/core/widgets/code/controllers/files_controller.py @@ -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) ] diff --git a/src/core/widgets/code/source_view.py b/src/core/widgets/code/source_view.py index 9dc749f..4f348cd 100644 --- a/src/core/widgets/code/source_view.py +++ b/src/core/widgets/code/source_view.py @@ -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) diff --git a/user_config/usr/share/newton/code-key-bindings.json b/user_config/usr/share/newton/code-key-bindings.json index e35ca74..7cecd01 100644 --- a/user_config/usr/share/newton/code-key-bindings.json +++ b/user_config/usr/share/newton/code-key-bindings.json @@ -15,18 +15,12 @@ "zoom_out": { "held": "minus" }, - "cut_to_temp_buffer": { - "held": "k" - }, "duplicate_line": { "held": "d" }, "go_to": { "released": "g" }, - "paste_temp_buffer": { - "held": "u" - }, "new_file": { "released": "t" },