Improved folder structure for commamd system and controllers
This commit is contained in:
5
src/core/widgets/code/command_system/__init__.py
Normal file
5
src/core/widgets/code/command_system/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
Code Command System Package
|
||||
"""
|
||||
|
||||
from .command_system import CommandSystem
|
||||
@@ -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... """
|
||||
...
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Commands Package
|
||||
Code Commands Package
|
||||
"""
|
||||
|
||||
import pkgutil
|
||||
@@ -9,7 +9,6 @@ from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from ..source_file import SourceFile
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Custom Completion Providers Module
|
||||
Code Completion Providers Package
|
||||
"""
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
"""
|
||||
Controllers Package
|
||||
Code Controllers Package
|
||||
"""
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
3
src/core/widgets/code/controllers/foundation/__init__.py
Normal file
3
src/core/widgets/code/controllers/foundation/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
Code Controllers Foundation Package
|
||||
"""
|
||||
@@ -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
|
||||
@@ -3,7 +3,7 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory_Types
|
||||
from ...event_factory import Event_Factory_Types
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory_Types
|
||||
from ...event_factory import Event_Factory_Types
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
return (
|
||||
inspect.isclass(obj) and
|
||||
issubclass(obj, CodeEvent) and
|
||||
obj != CodeEvent)
|
||||
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
|
||||
|
||||
@@ -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):
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user