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
|
# Lib imports
|
||||||
|
|
||||||
# Application 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 . import commands
|
||||||
|
|
||||||
from .source_view import SourceView
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class CommandSystem:
|
class CommandSystem:
|
||||||
@@ -39,11 +37,11 @@ class CommandSystem:
|
|||||||
return method.execute(*args)
|
return method.execute(*args)
|
||||||
|
|
||||||
|
|
||||||
def emit(self, event: CodeEvent):
|
def emit(self, event: Event_Factory_Types.CodeEvent):
|
||||||
""" Monky patch 'emit' from command controller... """
|
""" 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... """
|
""" Monky patch 'emit' from command controller... """
|
||||||
...
|
...
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Commands Package
|
Code Commands Package
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pkgutil
|
import pkgutil
|
||||||
@@ -9,7 +9,6 @@ from gi.repository import GtkSource
|
|||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..source_file import SourceFile
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ from gi.repository import GtkSource
|
|||||||
from gi.repository import Gio
|
from gi.repository import Gio
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..source_file import SourceFile
|
from ...source_file import SourceFile
|
||||||
from ..command_helpers import set_language_and_style
|
from ..command_helpers import set_language_and_style
|
||||||
|
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ gi.require_version('GtkSource', '4')
|
|||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..source_file import SourceFile
|
from ...source_file import SourceFile
|
||||||
from ..command_helpers import update_info_bar_if_focused
|
from ..command_helpers import update_info_bar_if_focused
|
||||||
|
|
||||||
|
|
||||||
@@ -6,12 +6,8 @@ import gi
|
|||||||
gi.require_version('GtkSource', '4')
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
from gi.repository import Gio
|
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from libs.dto.code import FocusedViewEvent
|
|
||||||
|
|
||||||
from ..source_file import SourceFile
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -6,10 +6,8 @@ import gi
|
|||||||
gi.require_version('GtkSource', '4')
|
gi.require_version('GtkSource', '4')
|
||||||
|
|
||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
from gi.repository import Gio
|
|
||||||
|
|
||||||
# Application imports
|
# 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
|
# Lib imports
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from libs.dto.code import (
|
from ..event_factory import Event_Factory_Types
|
||||||
CodeEvent,
|
|
||||||
GetCommandSystemEvent,
|
|
||||||
FocusedViewEvent
|
|
||||||
)
|
|
||||||
|
|
||||||
from ..command_system import CommandSystem
|
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__()
|
super(CommandsController, self).__init__()
|
||||||
|
|
||||||
|
|
||||||
def _controller_message(self, event: CodeEvent):
|
def _controller_message(self, event: Event_Factory_Types.CodeEvent):
|
||||||
if isinstance(event, GetCommandSystemEvent):
|
if isinstance(event, Event_Factory_Types.GetCommandSystemEvent):
|
||||||
event.response = self.get_command_system()
|
event.response = self.get_command_system()
|
||||||
|
|
||||||
def get_command_system(self):
|
def get_command_system(self):
|
||||||
|
|||||||
@@ -8,19 +8,12 @@ from gi.repository import GLib
|
|||||||
from gi.repository import GtkSource
|
from gi.repository import GtkSource
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from libs.dto.code import (
|
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||||
CodeEvent,
|
|
||||||
FocusedViewEvent,
|
|
||||||
RequestCompletionEvent,
|
|
||||||
CursorMovedEvent,
|
|
||||||
TextChangedEvent,
|
|
||||||
TextInsertedEvent
|
|
||||||
)
|
|
||||||
|
|
||||||
from ..completion_providers.example_completion_provider import ExampleCompletionProvider
|
from ..completion_providers.example_completion_provider import ExampleCompletionProvider
|
||||||
from ..completion_providers.lsp_completion_provider import LSPCompletionProvider
|
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()
|
self._lsp_provider: LSPCompletionProvider = LSPCompletionProvider()
|
||||||
|
|
||||||
|
|
||||||
def _controller_message(self, event: CodeEvent):
|
def _controller_message(self, event: Event_Factory_Types.CodeEvent):
|
||||||
if isinstance(event, FocusedViewEvent):
|
if isinstance(event, Event_Factory_Types.FocusedViewEvent):
|
||||||
self._completor = event.view.get_completion()
|
self._completor = event.view.get_completion()
|
||||||
|
|
||||||
if not self._timeout_id: return
|
if not self._timeout_id: return
|
||||||
|
|
||||||
GLib.source_remove(self._timeout_id)
|
GLib.source_remove(self._timeout_id)
|
||||||
self._timeout_id = None
|
self._timeout_id = None
|
||||||
elif isinstance(event, RequestCompletionEvent):
|
elif isinstance(event, Event_Factory_Types.RequestCompletionEvent):
|
||||||
self.request_completion()
|
self.request_completion()
|
||||||
# elif isinstance(event, TextInsertedEvent):
|
# elif isinstance(event, Event_Factory_Types.TextInsertedEvent):
|
||||||
# self.request_completion()
|
# self.request_completion()
|
||||||
|
|
||||||
def _process_request_completion(self):
|
def _process_request_completion(self):
|
||||||
|
|||||||
@@ -7,8 +7,8 @@ from libs.singleton import Singleton
|
|||||||
|
|
||||||
from ..event_factory import Event_Factory_Types
|
from ..event_factory import Event_Factory_Types
|
||||||
|
|
||||||
from .controller_base import ControllerBase
|
from .foundation.controller_base import ControllerBase
|
||||||
from .controller_context import ControllerContext
|
from .foundation.controller_context import ControllerContext
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,13 +3,12 @@
|
|||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application 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_file import SourceFile
|
from ..source_file import SourceFile
|
||||||
from ..source_buffer import SourceBuffer
|
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__()
|
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):
|
if isinstance(event, Event_Factory_Types.AddNewFileEvent):
|
||||||
self.new_file(event)
|
self.new_file(event)
|
||||||
elif isinstance(event, Event_Factory_Types.SwapFileEvent):
|
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
|
# Application imports
|
||||||
from libs.singleton import Singleton
|
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 .emit_dispatcher import EmitDispatcher
|
||||||
from .controller_context import ControllerContext
|
from .controller_context import ControllerContext
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..event_factory import Event_Factory_Types
|
from ...event_factory import Event_Factory_Types
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application 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 ..source_view import SourceView
|
||||||
|
|
||||||
from .controller_base import ControllerBase
|
from .foundation.controller_base import ControllerBase
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application 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 ..tabs_widget import TabsWidget
|
from ..tabs_widget import TabsWidget
|
||||||
@@ -11,7 +10,7 @@ from ..tab_widget import TabWidget
|
|||||||
|
|
||||||
from ..source_view import SourceView
|
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()
|
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):
|
if isinstance(event, Event_Factory_Types.FocusedViewEvent):
|
||||||
self.active_view = event.view
|
self.active_view = event.view
|
||||||
elif isinstance(event, Event_Factory_Types.FilePathSetEvent):
|
elif isinstance(event, Event_Factory_Types.FilePathSetEvent):
|
||||||
|
|||||||
@@ -29,11 +29,11 @@ class EventFactory(Singleton):
|
|||||||
event = event_class()
|
event = event_class()
|
||||||
|
|
||||||
for key, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
if hasattr(event, key):
|
if not hasattr(event, key):
|
||||||
setattr(event, key, value)
|
|
||||||
else:
|
|
||||||
raise ValueError(f"Event class {event_class.__name__} has no attribute '{key}'")
|
raise ValueError(f"Event class {event_class.__name__} has no attribute '{key}'")
|
||||||
|
|
||||||
|
setattr(event, key, value)
|
||||||
|
|
||||||
return event
|
return event
|
||||||
|
|
||||||
def _auto_register_events(self):
|
def _auto_register_events(self):
|
||||||
@@ -46,9 +46,11 @@ class EventFactory(Singleton):
|
|||||||
logger.debug(f"Auto-registered {len(self._event_classes)} event types")
|
logger.debug(f"Auto-registered {len(self._event_classes)} event types")
|
||||||
|
|
||||||
def _is_valid_event_class(self, obj) -> bool:
|
def _is_valid_event_class(self, obj) -> bool:
|
||||||
return (inspect.isclass(obj) and
|
return (
|
||||||
|
inspect.isclass(obj) and
|
||||||
issubclass(obj, CodeEvent) and
|
issubclass(obj, CodeEvent) and
|
||||||
obj != CodeEvent)
|
obj != CodeEvent
|
||||||
|
)
|
||||||
|
|
||||||
def _class_name_to_event_type(self, class_name: str) -> str:
|
def _class_name_to_event_type(self, class_name: str) -> str:
|
||||||
base_name = class_name[:-5] if class_name.endswith('Event') else class_name
|
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
|
from gi.repository import Gio
|
||||||
|
|
||||||
# Application 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_buffer import SourceBuffer
|
from .source_buffer import SourceBuffer
|
||||||
@@ -122,8 +121,8 @@ class SourceFile(GtkSource.File):
|
|||||||
def close(self):
|
def close(self):
|
||||||
del self.buffer
|
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