Created libs.code package and moved pertinant DTOs to it as well as widget.code that can go there too
This commit is contained in:
@@ -31,11 +31,13 @@ class CodeBase:
|
||||
completion_controller = CompletionController()
|
||||
source_views_controller = SourceViewsController()
|
||||
|
||||
# self.controller_manager.register_controller("base", self)
|
||||
self.controller_manager.register_controller("files", files_controller)
|
||||
self.controller_manager.register_controller("tabs", tabs_controller)
|
||||
self.controller_manager.register_controller("commands", commands_controller)
|
||||
self.controller_manager.register_controller("completion", completion_controller)
|
||||
self.controller_manager.register_controller("source_views", source_views_controller)
|
||||
# self.controller_manager.register_controller("plugins", plugins_controller)
|
||||
|
||||
def get_tabs_widget(self):
|
||||
return self.controller_manager["tabs"].get_tabs_widget()
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
|
||||
from ..source_view import SourceView
|
||||
|
||||
from . import commands
|
||||
|
||||
@@ -3,11 +3,12 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory_Types
|
||||
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
|
||||
from ..command_system import CommandSystem
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -8,13 +8,12 @@ from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
|
||||
from ..completion_providers.example_completion_provider import ExampleCompletionProvider
|
||||
from ..completion_providers.lsp_completion_provider import LSPCompletionProvider
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
|
||||
|
||||
|
||||
class CompletionController(ControllerBase):
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
# Application imports
|
||||
from libs.singleton import Singleton
|
||||
|
||||
from ..event_factory import Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory_Types
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
from .foundation.controller_context import ControllerContext
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
from libs.code.controllers.controller_context import ControllerContext
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
|
||||
from ..source_file import SourceFile
|
||||
from ..source_buffer import SourceBuffer
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
"""
|
||||
Code Controllers Foundation Package
|
||||
"""
|
||||
@@ -1,38 +0,0 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.singleton import Singleton
|
||||
|
||||
from ...event_factory import Event_Factory_Types
|
||||
|
||||
from .emit_dispatcher import EmitDispatcher
|
||||
from .controller_context import ControllerContext
|
||||
|
||||
|
||||
|
||||
class ControllerBaseException(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
class ControllerBase(Singleton, EmitDispatcher):
|
||||
def __init__(self):
|
||||
super(ControllerBase, self).__init__()
|
||||
|
||||
self.controller_context: ControllerContext = None
|
||||
|
||||
|
||||
def _controller_message(self, event: Event_Factory_Types.CodeEvent):
|
||||
raise ControllerBaseException("Controller Base must override '_controller_message'...")
|
||||
|
||||
def set_controller_context(self, controller_context: ControllerContext):
|
||||
self.controller_context = controller_context
|
||||
|
||||
def message_to(self, name: str, event: Event_Factory_Types.CodeEvent):
|
||||
return self.controller_context.message_to(name, event)
|
||||
|
||||
def message_all(self, event: Event_Factory_Types.CodeEvent):
|
||||
return self.controller_context.message_all(event)
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ...event_factory import Event_Factory_Types
|
||||
|
||||
|
||||
|
||||
class ControllerContextException(Exception):
|
||||
...
|
||||
|
||||
|
||||
|
||||
class ControllerContext:
|
||||
def __init__(self):
|
||||
super(ControllerContext, self).__init__()
|
||||
|
||||
|
||||
def message_to(self, name: str, event: Event_Factory_Types.CodeEvent):
|
||||
raise ControllerContextException("Controller Context 'message_to' must be overriden by Controller Manager...")
|
||||
|
||||
def message_all(self, event: Event_Factory_Types.CodeEvent):
|
||||
raise ControllerContextException("Controller Context 'message_all' must be overriden by Controller Manager...")
|
||||
@@ -1,19 +0,0 @@
|
||||
# Python imports
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ...event_factory import Event_Factory_Types
|
||||
|
||||
|
||||
|
||||
class EmitDispatcher:
|
||||
def __init__(self):
|
||||
super(EmitDispatcher, self).__init__()
|
||||
|
||||
|
||||
def emit(self, event: Event_Factory_Types.CodeEvent):
|
||||
self.message_all(event)
|
||||
|
||||
def emit_to(self, controller: str, event: Event_Factory_Types.CodeEvent):
|
||||
self.message_to(controller, event)
|
||||
@@ -3,15 +3,14 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
|
||||
from ..command_system import CommandSystem
|
||||
from ..key_mapper import KeyMapper
|
||||
|
||||
from ..source_view import SourceView
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
|
||||
|
||||
|
||||
class SourceViewsController(ControllerBase, list):
|
||||
|
||||
@@ -3,15 +3,14 @@
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.controllers.controller_base import ControllerBase
|
||||
|
||||
from ..tabs_widget import TabsWidget
|
||||
from ..tab_widget import TabWidget
|
||||
|
||||
from ..source_view import SourceView
|
||||
|
||||
from .foundation.controller_base import ControllerBase
|
||||
|
||||
|
||||
|
||||
class TabsController(ControllerBase):
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
# Python imports
|
||||
import inspect
|
||||
from typing import Dict, Type
|
||||
import re
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from libs.singleton import Singleton
|
||||
from libs.dto.code import CodeEvent
|
||||
from libs.dto import code
|
||||
|
||||
|
||||
|
||||
class EventFactory(Singleton):
|
||||
def __init__(self):
|
||||
self._event_classes: Dict[str, Type[CodeEvent]] = {}
|
||||
|
||||
self._auto_register_events()
|
||||
|
||||
def register_event(self, event_type: str, event_class: Type[CodeEvent]):
|
||||
self._event_classes[event_type] = event_class
|
||||
|
||||
def create_event(self, event_type: str, **kwargs) -> CodeEvent:
|
||||
if event_type not in self._event_classes:
|
||||
raise ValueError(f"Unknown event type: {event_type}")
|
||||
|
||||
event_class = self._event_classes[event_type]
|
||||
event = event_class()
|
||||
|
||||
for key, value in kwargs.items():
|
||||
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):
|
||||
for name, obj in code.__dict__.items():
|
||||
if not self._is_valid_event_class(obj): continue
|
||||
|
||||
event_type = self._class_name_to_event_type(name)
|
||||
self.register_event(event_type, obj)
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
def _class_name_to_event_type(self, class_name: str) -> str:
|
||||
base_name = class_name[:-5] if class_name.endswith('Event') else class_name
|
||||
return re.sub(r'(?<!^)(?=[A-Z])', '_', base_name).lower()
|
||||
|
||||
def create_cursor_moved(self, **kwargs):
|
||||
return self.create_event("cursor_moved", **kwargs)
|
||||
|
||||
def create_text_changed(self, **kwargs):
|
||||
return self.create_event("text_changed", **kwargs)
|
||||
|
||||
def create_focused_view(self, **kwargs):
|
||||
return self.create_event("focused_view", **kwargs)
|
||||
|
||||
def create_modified_changed(self, **kwargs):
|
||||
return self.create_event("modified_changed", **kwargs)
|
||||
|
||||
def create_get_command_system(self, **kwargs):
|
||||
return self.create_event("get_command_system", **kwargs)
|
||||
|
||||
def create_file_path_set(self, **kwargs):
|
||||
return self.create_event("file_path_set", **kwargs)
|
||||
|
||||
def create_text_inserted(self, **kwargs):
|
||||
return self.create_event("text_inserted", **kwargs)
|
||||
|
||||
def create_set_active_file(self, **kwargs):
|
||||
return self.create_event("set_active_file", **kwargs)
|
||||
|
||||
def create_added_new_file(self, **kwargs):
|
||||
return self.create_event("added_new_file", **kwargs)
|
||||
|
||||
def create_popped_file(self, **kwargs):
|
||||
return self.create_event("popped_file", **kwargs)
|
||||
|
||||
def create_get_file(self, **kwargs):
|
||||
return self.create_event("get_file", **kwargs)
|
||||
|
||||
def create_get_swap_file(self, **kwargs):
|
||||
return self.create_event("get_swap_file", **kwargs)
|
||||
|
||||
def create_remove_file(self, **kwargs):
|
||||
return self.create_event("remove_file", **kwargs)
|
||||
|
||||
def create_removed_file(self, **kwargs):
|
||||
return self.create_event("removed_file", **kwargs)
|
||||
|
||||
|
||||
Event_Factory = EventFactory()
|
||||
Event_Factory_Types = code
|
||||
@@ -12,7 +12,7 @@ from gi.repository import GtkSource
|
||||
from gi.repository import Gio
|
||||
|
||||
# Application imports
|
||||
from .event_factory import Event_Factory, Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory, Event_Factory_Types
|
||||
|
||||
from .source_buffer import SourceBuffer
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ from gi.repository import Gtk
|
||||
from gi.repository import GLib
|
||||
from gi.repository import GtkSource
|
||||
|
||||
# Application imports
|
||||
from .mixins.source_view_dnd_mixin import SourceViewDnDMixin
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ gi.require_version('Gtk', '3.0')
|
||||
from gi.repository import Gtk
|
||||
|
||||
# Application imports
|
||||
from .event_factory import Event_Factory_Types
|
||||
from libs.code.event_factory import Event_Factory_Types
|
||||
|
||||
from .source_view import SourceView
|
||||
from .source_file import SourceFile
|
||||
|
||||
Reference in New Issue
Block a user