diff --git a/src/core/widgets/code/command_system/__init__.py b/src/core/widgets/code/command_system/__init__.py new file mode 100644 index 0000000..bd5eb3b --- /dev/null +++ b/src/core/widgets/code/command_system/__init__.py @@ -0,0 +1,5 @@ +""" + Code Command System Package +""" + +from .command_system import CommandSystem diff --git a/src/core/widgets/code/command_helpers.py b/src/core/widgets/code/command_system/command_helpers.py similarity index 100% rename from src/core/widgets/code/command_helpers.py rename to src/core/widgets/code/command_system/command_helpers.py diff --git a/src/core/widgets/code/command_system.py b/src/core/widgets/code/command_system/command_system.py similarity index 89% rename from src/core/widgets/code/command_system.py rename to src/core/widgets/code/command_system/command_system.py index c168e83..7e2929f 100644 --- a/src/core/widgets/code/command_system.py +++ b/src/core/widgets/code/command_system/command_system.py @@ -3,13 +3,11 @@ # Lib imports # Application imports -from libs.dto.code import CodeEvent -from .event_factory import Event_Factory, Event_Factory_Types +from ..event_factory import Event_Factory, Event_Factory_Types +from ..source_view import SourceView from . import commands -from .source_view import SourceView - class CommandSystem: @@ -39,11 +37,11 @@ class CommandSystem: return method.execute(*args) - def emit(self, event: CodeEvent): + def emit(self, event: Event_Factory_Types.CodeEvent): """ Monky patch 'emit' from command controller... """ ... - def emit_to(self, controller: str, event: CodeEvent): + def emit_to(self, controller: str, event: Event_Factory_Types.CodeEvent): """ Monky patch 'emit' from command controller... """ ... diff --git a/src/core/widgets/code/commands/__init__.py b/src/core/widgets/code/command_system/commands/__init__.py similarity index 92% rename from src/core/widgets/code/commands/__init__.py rename to src/core/widgets/code/command_system/commands/__init__.py index c646d94..d249eb4 100644 --- a/src/core/widgets/code/commands/__init__.py +++ b/src/core/widgets/code/command_system/commands/__init__.py @@ -1,5 +1,5 @@ """ - Commands Package + Code Commands Package """ import pkgutil diff --git a/src/core/widgets/code/commands/buffer_redo.py b/src/core/widgets/code/command_system/commands/buffer_redo.py similarity index 100% rename from src/core/widgets/code/commands/buffer_redo.py rename to src/core/widgets/code/command_system/commands/buffer_redo.py diff --git a/src/core/widgets/code/commands/buffer_undo.py b/src/core/widgets/code/command_system/commands/buffer_undo.py similarity index 100% rename from src/core/widgets/code/commands/buffer_undo.py rename to src/core/widgets/code/command_system/commands/buffer_undo.py diff --git a/src/core/widgets/code/commands/close_file.py b/src/core/widgets/code/command_system/commands/close_file.py similarity index 100% rename from src/core/widgets/code/commands/close_file.py rename to src/core/widgets/code/command_system/commands/close_file.py diff --git a/src/core/widgets/code/commands/cut_to_temp_buffer.py b/src/core/widgets/code/command_system/commands/cut_to_temp_buffer.py similarity index 100% rename from src/core/widgets/code/commands/cut_to_temp_buffer.py rename to src/core/widgets/code/command_system/commands/cut_to_temp_buffer.py diff --git a/src/core/widgets/code/commands/dnd_load_file_to_buffer.py b/src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py similarity index 100% rename from src/core/widgets/code/commands/dnd_load_file_to_buffer.py rename to src/core/widgets/code/command_system/commands/dnd_load_file_to_buffer.py diff --git a/src/core/widgets/code/commands/dnd_load_files.py b/src/core/widgets/code/command_system/commands/dnd_load_files.py similarity index 81% rename from src/core/widgets/code/commands/dnd_load_files.py rename to src/core/widgets/code/command_system/commands/dnd_load_files.py index c13042c..6e29a2a 100644 --- a/src/core/widgets/code/commands/dnd_load_files.py +++ b/src/core/widgets/code/command_system/commands/dnd_load_files.py @@ -9,7 +9,6 @@ from gi.repository import GtkSource from gi.repository import Gio # Application imports -from ..source_file import SourceFile diff --git a/src/core/widgets/code/commands/duplicate_line.py b/src/core/widgets/code/command_system/commands/duplicate_line.py similarity index 100% rename from src/core/widgets/code/commands/duplicate_line.py rename to src/core/widgets/code/command_system/commands/duplicate_line.py diff --git a/src/core/widgets/code/commands/focus_left_sibling.py b/src/core/widgets/code/command_system/commands/focus_left_sibling.py similarity index 100% rename from src/core/widgets/code/commands/focus_left_sibling.py rename to src/core/widgets/code/command_system/commands/focus_left_sibling.py diff --git a/src/core/widgets/code/commands/focus_right_sibling.py b/src/core/widgets/code/command_system/commands/focus_right_sibling.py similarity index 100% rename from src/core/widgets/code/commands/focus_right_sibling.py rename to src/core/widgets/code/command_system/commands/focus_right_sibling.py diff --git a/src/core/widgets/code/commands/get_current_file.py b/src/core/widgets/code/command_system/commands/get_current_file.py similarity index 100% rename from src/core/widgets/code/commands/get_current_file.py rename to src/core/widgets/code/command_system/commands/get_current_file.py diff --git a/src/core/widgets/code/commands/get_filetype.py b/src/core/widgets/code/command_system/commands/get_filetype.py similarity index 100% rename from src/core/widgets/code/commands/get_filetype.py rename to src/core/widgets/code/command_system/commands/get_filetype.py diff --git a/src/core/widgets/code/commands/get_text.py b/src/core/widgets/code/command_system/commands/get_text.py similarity index 100% rename from src/core/widgets/code/commands/get_text.py rename to src/core/widgets/code/command_system/commands/get_text.py diff --git a/src/core/widgets/code/commands/go_to.py b/src/core/widgets/code/command_system/commands/go_to.py similarity index 100% rename from src/core/widgets/code/commands/go_to.py rename to src/core/widgets/code/command_system/commands/go_to.py diff --git a/src/core/widgets/code/commands/has_focus.py b/src/core/widgets/code/command_system/commands/has_focus.py similarity index 100% rename from src/core/widgets/code/commands/has_focus.py rename to src/core/widgets/code/command_system/commands/has_focus.py diff --git a/src/core/widgets/code/commands/line_down.py b/src/core/widgets/code/command_system/commands/line_down.py similarity index 100% rename from src/core/widgets/code/commands/line_down.py rename to src/core/widgets/code/command_system/commands/line_down.py diff --git a/src/core/widgets/code/commands/line_up.py b/src/core/widgets/code/command_system/commands/line_up.py similarity index 100% rename from src/core/widgets/code/commands/line_up.py rename to src/core/widgets/code/command_system/commands/line_up.py diff --git a/src/core/widgets/code/commands/load_file.py b/src/core/widgets/code/command_system/commands/load_file.py similarity index 92% rename from src/core/widgets/code/commands/load_file.py rename to src/core/widgets/code/command_system/commands/load_file.py index 78c8dbe..637eff6 100644 --- a/src/core/widgets/code/commands/load_file.py +++ b/src/core/widgets/code/command_system/commands/load_file.py @@ -9,7 +9,7 @@ from gi.repository import GtkSource from gi.repository import Gio # Application imports -from ..source_file import SourceFile +from ...source_file import SourceFile from ..command_helpers import set_language_and_style diff --git a/src/core/widgets/code/commands/load_start_files.py b/src/core/widgets/code/command_system/commands/load_start_files.py similarity index 100% rename from src/core/widgets/code/commands/load_start_files.py rename to src/core/widgets/code/command_system/commands/load_start_files.py diff --git a/src/core/widgets/code/commands/move_to_left_sibling.py b/src/core/widgets/code/command_system/commands/move_to_left_sibling.py similarity index 100% rename from src/core/widgets/code/commands/move_to_left_sibling.py rename to src/core/widgets/code/command_system/commands/move_to_left_sibling.py diff --git a/src/core/widgets/code/commands/move_to_right_sibling.py b/src/core/widgets/code/command_system/commands/move_to_right_sibling.py similarity index 100% rename from src/core/widgets/code/commands/move_to_right_sibling.py rename to src/core/widgets/code/command_system/commands/move_to_right_sibling.py diff --git a/src/core/widgets/code/commands/new_file.py b/src/core/widgets/code/command_system/commands/new_file.py similarity index 100% rename from src/core/widgets/code/commands/new_file.py rename to src/core/widgets/code/command_system/commands/new_file.py diff --git a/src/core/widgets/code/commands/open_files.py b/src/core/widgets/code/command_system/commands/open_files.py similarity index 100% rename from src/core/widgets/code/commands/open_files.py rename to src/core/widgets/code/command_system/commands/open_files.py diff --git a/src/core/widgets/code/commands/paste_temp_buffer.py b/src/core/widgets/code/command_system/commands/paste_temp_buffer.py similarity index 100% rename from src/core/widgets/code/commands/paste_temp_buffer.py rename to src/core/widgets/code/command_system/commands/paste_temp_buffer.py diff --git a/src/core/widgets/code/commands/save_file.py b/src/core/widgets/code/command_system/commands/save_file.py similarity index 100% rename from src/core/widgets/code/commands/save_file.py rename to src/core/widgets/code/command_system/commands/save_file.py diff --git a/src/core/widgets/code/commands/save_file_as.py b/src/core/widgets/code/command_system/commands/save_file_as.py similarity index 100% rename from src/core/widgets/code/commands/save_file_as.py rename to src/core/widgets/code/command_system/commands/save_file_as.py diff --git a/src/core/widgets/code/commands/set_buffer.py b/src/core/widgets/code/command_system/commands/set_buffer.py similarity index 92% rename from src/core/widgets/code/commands/set_buffer.py rename to src/core/widgets/code/command_system/commands/set_buffer.py index 2c7d085..119e5a2 100644 --- a/src/core/widgets/code/commands/set_buffer.py +++ b/src/core/widgets/code/command_system/commands/set_buffer.py @@ -9,7 +9,7 @@ gi.require_version('GtkSource', '4') from gi.repository import GtkSource # Application imports -from ..source_file import SourceFile +from ...source_file import SourceFile from ..command_helpers import update_info_bar_if_focused diff --git a/src/core/widgets/code/commands/set_buffer_language.py b/src/core/widgets/code/command_system/commands/set_buffer_language.py similarity index 100% rename from src/core/widgets/code/commands/set_buffer_language.py rename to src/core/widgets/code/command_system/commands/set_buffer_language.py diff --git a/src/core/widgets/code/commands/set_buffer_style.py b/src/core/widgets/code/command_system/commands/set_buffer_style.py similarity index 100% rename from src/core/widgets/code/commands/set_buffer_style.py rename to src/core/widgets/code/command_system/commands/set_buffer_style.py diff --git a/src/core/widgets/code/commands/set_focus_border.py b/src/core/widgets/code/command_system/commands/set_focus_border.py similarity index 100% rename from src/core/widgets/code/commands/set_focus_border.py rename to src/core/widgets/code/command_system/commands/set_focus_border.py diff --git a/src/core/widgets/code/commands/set_miniview.py b/src/core/widgets/code/command_system/commands/set_miniview.py similarity index 71% rename from src/core/widgets/code/commands/set_miniview.py rename to src/core/widgets/code/command_system/commands/set_miniview.py index 553265a..dd3f374 100644 --- a/src/core/widgets/code/commands/set_miniview.py +++ b/src/core/widgets/code/command_system/commands/set_miniview.py @@ -6,12 +6,8 @@ import gi gi.require_version('GtkSource', '4') from gi.repository import GtkSource -from gi.repository import Gio # Application imports -from libs.dto.code import FocusedViewEvent - -from ..source_file import SourceFile diff --git a/src/core/widgets/code/commands/show_completion.py b/src/core/widgets/code/command_system/commands/show_completion.py similarity index 100% rename from src/core/widgets/code/commands/show_completion.py rename to src/core/widgets/code/command_system/commands/show_completion.py diff --git a/src/core/widgets/code/commands/update_info_bar.py b/src/core/widgets/code/command_system/commands/update_info_bar.py similarity index 90% rename from src/core/widgets/code/commands/update_info_bar.py rename to src/core/widgets/code/command_system/commands/update_info_bar.py index c499945..4852570 100644 --- a/src/core/widgets/code/commands/update_info_bar.py +++ b/src/core/widgets/code/command_system/commands/update_info_bar.py @@ -6,10 +6,8 @@ import gi gi.require_version('GtkSource', '4') from gi.repository import GtkSource -from gi.repository import Gio # Application imports -from ..source_file import SourceFile diff --git a/src/core/widgets/code/commands/zoom_in.py b/src/core/widgets/code/command_system/commands/zoom_in.py similarity index 100% rename from src/core/widgets/code/commands/zoom_in.py rename to src/core/widgets/code/command_system/commands/zoom_in.py diff --git a/src/core/widgets/code/commands/zoom_out.py b/src/core/widgets/code/command_system/commands/zoom_out.py similarity index 100% rename from src/core/widgets/code/commands/zoom_out.py rename to src/core/widgets/code/command_system/commands/zoom_out.py diff --git a/src/core/widgets/code/completion_providers/__init__.py b/src/core/widgets/code/completion_providers/__init__.py index fdff2e4..a46072a 100644 --- a/src/core/widgets/code/completion_providers/__init__.py +++ b/src/core/widgets/code/completion_providers/__init__.py @@ -1,3 +1,3 @@ """ - Custom Completion Providers Module + Code Completion Providers Package """ diff --git a/src/core/widgets/code/controllers/__init__.py b/src/core/widgets/code/controllers/__init__.py index 0f53a83..e614b70 100644 --- a/src/core/widgets/code/controllers/__init__.py +++ b/src/core/widgets/code/controllers/__init__.py @@ -1,3 +1,3 @@ """ - Controllers Package + Code Controllers Package """ \ No newline at end of file diff --git a/src/core/widgets/code/controllers/commands_controller.py b/src/core/widgets/code/controllers/commands_controller.py index 9d41a6d..70be1ee 100644 --- a/src/core/widgets/code/controllers/commands_controller.py +++ b/src/core/widgets/code/controllers/commands_controller.py @@ -3,15 +3,11 @@ # Lib imports # Application imports -from libs.dto.code import ( - CodeEvent, - GetCommandSystemEvent, - FocusedViewEvent -) +from ..event_factory import Event_Factory_Types from ..command_system import CommandSystem -from .controller_base import ControllerBase +from .foundation.controller_base import ControllerBase @@ -20,8 +16,8 @@ class CommandsController(ControllerBase, list): super(CommandsController, self).__init__() - def _controller_message(self, event: CodeEvent): - if isinstance(event, GetCommandSystemEvent): + def _controller_message(self, event: Event_Factory_Types.CodeEvent): + if isinstance(event, Event_Factory_Types.GetCommandSystemEvent): event.response = self.get_command_system() def get_command_system(self): diff --git a/src/core/widgets/code/controllers/completion_controller.py b/src/core/widgets/code/controllers/completion_controller.py index cd1722d..0a2921a 100644 --- a/src/core/widgets/code/controllers/completion_controller.py +++ b/src/core/widgets/code/controllers/completion_controller.py @@ -8,19 +8,12 @@ from gi.repository import GLib from gi.repository import GtkSource # Application imports -from libs.dto.code import ( - CodeEvent, - FocusedViewEvent, - RequestCompletionEvent, - CursorMovedEvent, - TextChangedEvent, - TextInsertedEvent -) +from ..event_factory import Event_Factory, Event_Factory_Types from ..completion_providers.example_completion_provider import ExampleCompletionProvider from ..completion_providers.lsp_completion_provider import LSPCompletionProvider -from .controller_base import ControllerBase +from .foundation.controller_base import ControllerBase @@ -33,17 +26,17 @@ class CompletionController(ControllerBase): self._lsp_provider: LSPCompletionProvider = LSPCompletionProvider() - def _controller_message(self, event: CodeEvent): - if isinstance(event, FocusedViewEvent): + def _controller_message(self, event: Event_Factory_Types.CodeEvent): + if isinstance(event, Event_Factory_Types.FocusedViewEvent): self._completor = event.view.get_completion() if not self._timeout_id: return GLib.source_remove(self._timeout_id) self._timeout_id = None - elif isinstance(event, RequestCompletionEvent): + elif isinstance(event, Event_Factory_Types.RequestCompletionEvent): self.request_completion() - # elif isinstance(event, TextInsertedEvent): + # elif isinstance(event, Event_Factory_Types.TextInsertedEvent): # self.request_completion() def _process_request_completion(self): diff --git a/src/core/widgets/code/controllers/controller_manager.py b/src/core/widgets/code/controllers/controller_manager.py index 3dc8810..7e8165a 100644 --- a/src/core/widgets/code/controllers/controller_manager.py +++ b/src/core/widgets/code/controllers/controller_manager.py @@ -7,8 +7,8 @@ from libs.singleton import Singleton from ..event_factory import Event_Factory_Types -from .controller_base import ControllerBase -from .controller_context import ControllerContext +from .foundation.controller_base import ControllerBase +from .foundation.controller_context import ControllerContext diff --git a/src/core/widgets/code/controllers/files_controller.py b/src/core/widgets/code/controllers/files_controller.py index 12ece61..82d9a1c 100644 --- a/src/core/widgets/code/controllers/files_controller.py +++ b/src/core/widgets/code/controllers/files_controller.py @@ -3,13 +3,12 @@ # Lib imports # Application imports -from libs.dto.code import CodeEvent from ..event_factory import Event_Factory, Event_Factory_Types from ..source_file import SourceFile from ..source_buffer import SourceBuffer -from .controller_base import ControllerBase +from .foundation.controller_base import ControllerBase @@ -18,7 +17,7 @@ class FilesController(ControllerBase, list): super(FilesController, self).__init__() - def _controller_message(self, event: CodeEvent): + def _controller_message(self, event: Event_Factory_Types.CodeEvent): if isinstance(event, Event_Factory_Types.AddNewFileEvent): self.new_file(event) elif isinstance(event, Event_Factory_Types.SwapFileEvent): diff --git a/src/core/widgets/code/controllers/foundation/__init__.py b/src/core/widgets/code/controllers/foundation/__init__.py new file mode 100644 index 0000000..fcd302a --- /dev/null +++ b/src/core/widgets/code/controllers/foundation/__init__.py @@ -0,0 +1,3 @@ +""" + Code Controllers Foundation Package +""" \ No newline at end of file diff --git a/src/core/widgets/code/controllers/controller_base.py b/src/core/widgets/code/controllers/foundation/controller_base.py similarity index 95% rename from src/core/widgets/code/controllers/controller_base.py rename to src/core/widgets/code/controllers/foundation/controller_base.py index 67eb76d..30dec2c 100644 --- a/src/core/widgets/code/controllers/controller_base.py +++ b/src/core/widgets/code/controllers/foundation/controller_base.py @@ -5,7 +5,7 @@ # Application imports from libs.singleton import Singleton -from ..event_factory import Event_Factory_Types +from ...event_factory import Event_Factory_Types from .emit_dispatcher import EmitDispatcher from .controller_context import ControllerContext diff --git a/src/core/widgets/code/controllers/controller_context.py b/src/core/widgets/code/controllers/foundation/controller_context.py similarity index 92% rename from src/core/widgets/code/controllers/controller_context.py rename to src/core/widgets/code/controllers/foundation/controller_context.py index 67bb5b4..a790c0c 100644 --- a/src/core/widgets/code/controllers/controller_context.py +++ b/src/core/widgets/code/controllers/foundation/controller_context.py @@ -3,7 +3,7 @@ # Lib imports # Application imports -from ..event_factory import Event_Factory_Types +from ...event_factory import Event_Factory_Types diff --git a/src/core/widgets/code/controllers/emit_dispatcher.py b/src/core/widgets/code/controllers/foundation/emit_dispatcher.py similarity index 88% rename from src/core/widgets/code/controllers/emit_dispatcher.py rename to src/core/widgets/code/controllers/foundation/emit_dispatcher.py index 41d5621..432faad 100644 --- a/src/core/widgets/code/controllers/emit_dispatcher.py +++ b/src/core/widgets/code/controllers/foundation/emit_dispatcher.py @@ -3,7 +3,7 @@ # Lib imports # Application imports -from ..event_factory import Event_Factory_Types +from ...event_factory import Event_Factory_Types diff --git a/src/core/widgets/code/controllers/source_views_controller.py b/src/core/widgets/code/controllers/source_views_controller.py index 212510d..8cf6fe1 100644 --- a/src/core/widgets/code/controllers/source_views_controller.py +++ b/src/core/widgets/code/controllers/source_views_controller.py @@ -10,7 +10,7 @@ from ..key_mapper import KeyMapper from ..source_view import SourceView -from .controller_base import ControllerBase +from .foundation.controller_base import ControllerBase diff --git a/src/core/widgets/code/controllers/tabs_controller.py b/src/core/widgets/code/controllers/tabs_controller.py index ab74c40..71b453f 100644 --- a/src/core/widgets/code/controllers/tabs_controller.py +++ b/src/core/widgets/code/controllers/tabs_controller.py @@ -3,7 +3,6 @@ # Lib imports # Application imports -from libs.dto.code import CodeEvent from ..event_factory import Event_Factory, Event_Factory_Types from ..tabs_widget import TabsWidget @@ -11,7 +10,7 @@ from ..tab_widget import TabWidget from ..source_view import SourceView -from .controller_base import ControllerBase +from .foundation.controller_base import ControllerBase @@ -23,7 +22,7 @@ class TabsController(ControllerBase): self.tabs_widget: TabsWidget = TabsWidget() - def _controller_message(self, event: CodeEvent): + def _controller_message(self, event: Event_Factory_Types.CodeEvent): if isinstance(event, Event_Factory_Types.FocusedViewEvent): self.active_view = event.view elif isinstance(event, Event_Factory_Types.FilePathSetEvent): diff --git a/src/core/widgets/code/event_factory.py b/src/core/widgets/code/event_factory.py index 7e34aae..72b7a21 100644 --- a/src/core/widgets/code/event_factory.py +++ b/src/core/widgets/code/event_factory.py @@ -29,11 +29,11 @@ class EventFactory(Singleton): event = event_class() for key, value in kwargs.items(): - if hasattr(event, key): - setattr(event, key, value) - else: + if not hasattr(event, key): raise ValueError(f"Event class {event_class.__name__} has no attribute '{key}'") + setattr(event, key, value) + return event def _auto_register_events(self): @@ -46,9 +46,11 @@ class EventFactory(Singleton): logger.debug(f"Auto-registered {len(self._event_classes)} event types") def _is_valid_event_class(self, obj) -> bool: - return (inspect.isclass(obj) and - issubclass(obj, CodeEvent) and - obj != CodeEvent) + return ( + inspect.isclass(obj) and + issubclass(obj, CodeEvent) and + obj != CodeEvent + ) def _class_name_to_event_type(self, class_name: str) -> str: base_name = class_name[:-5] if class_name.endswith('Event') else class_name diff --git a/src/core/widgets/code/source_file.py b/src/core/widgets/code/source_file.py index 6c550e8..d039d0b 100644 --- a/src/core/widgets/code/source_file.py +++ b/src/core/widgets/code/source_file.py @@ -12,7 +12,6 @@ from gi.repository import GtkSource from gi.repository import Gio # Application imports -from libs.dto.code import CodeEvent from .event_factory import Event_Factory, Event_Factory_Types from .source_buffer import SourceBuffer @@ -122,8 +121,8 @@ class SourceFile(GtkSource.File): def close(self): del self.buffer - def emit(self, event: CodeEvent): + def emit(self, event: Event_Factory_Types.CodeEvent): ... - def emit_to(self, controller: str, event: CodeEvent): + def emit_to(self, controller: str, event: Event_Factory_Types.CodeEvent): ...