diff --git a/dooit/ui/api/api_components/layout.py b/dooit/ui/api/api_components/layout.py index 5c00cf00..60f62faf 100644 --- a/dooit/ui/api/api_components/layout.py +++ b/dooit/ui/api/api_components/layout.py @@ -1,9 +1,12 @@ +from textual.app import App from dooit.ui.api.widgets import TodoLayout, WorkspaceLayout +from dooit.ui.widgets.trees import TodosTree, WorkspacesTree from ._base import ApiComponent class LayoutManager(ApiComponent): - def __init__(self) -> None: + def __init__(self, app: App) -> None: + self.app = app self._todo_layout: TodoLayout = [] self._workspace_layout: WorkspaceLayout = [] @@ -14,6 +17,8 @@ def todo_layout(self) -> TodoLayout: @todo_layout.setter def todo_layout(self, layout: TodoLayout): self._todo_layout = layout + for tree in self.app.query(TodosTree): + tree.refresh_options() @property def workspace_layout(self) -> WorkspaceLayout: @@ -22,3 +27,5 @@ def workspace_layout(self) -> WorkspaceLayout: @workspace_layout.setter def workspace_layout(self, layout: WorkspaceLayout): self._workspace_layout = layout + for tree in self.app.query(WorkspacesTree): + tree.refresh_options() diff --git a/dooit/ui/api/dooit_api.py b/dooit/ui/api/dooit_api.py index ca79ce22..e7d7a36e 100644 --- a/dooit/ui/api/dooit_api.py +++ b/dooit/ui/api/dooit_api.py @@ -1,15 +1,12 @@ from typing import TYPE_CHECKING, List from dooit.ui.api.plug import PluginManager -from dooit.ui.api.widgets import TodoLayout, WorkspaceLayout - from dooit.ui.events.events import DooitEvent, SwitchTab -from dooit.ui.registry import registry from dooit.ui.widgets import ModelTree from dooit.ui.widgets.bars import StatusBarWidget from dooit.utils import CssManager -from .api_components import KeyManager +from .api_components import KeyManager, LayoutManager if TYPE_CHECKING: from ..tui import Dooit @@ -22,6 +19,7 @@ def __init__(self, app: "Dooit") -> None: self.plugin_manager.scan() self.css_manager = CssManager() self.keys = KeyManager(self.app.get_mode) + self.layouts = LayoutManager(self.app) self.css_manager.refresh_css() @@ -111,12 +109,5 @@ def start_search(self): def start_sort(self): self.focused.start_sort() - def set_workspace_layout(self, layout: WorkspaceLayout): - registry.set_workspace_layout(layout) - self.app.workspace_tree.refresh_options() - - def set_todo_layout(self, layout: TodoLayout): - registry.set_todo_layout(layout) - def set_bar(self, widgets: List[StatusBarWidget]): self.app.bar.set_widgets(widgets) diff --git a/dooit/ui/widgets/renderers/base_renderer.py b/dooit/ui/widgets/renderers/base_renderer.py index d1489be3..4b15747e 100644 --- a/dooit/ui/widgets/renderers/base_renderer.py +++ b/dooit/ui/widgets/renderers/base_renderer.py @@ -32,7 +32,7 @@ def id(self) -> str: @property def table_layout(self) -> List: - raise NotImplementedError + return self.tree.layout @property def prompt(self) -> RenderableType: diff --git a/dooit/ui/widgets/renderers/todo_renderer.py b/dooit/ui/widgets/renderers/todo_renderer.py index ac222eae..5aa07fbf 100644 --- a/dooit/ui/widgets/renderers/todo_renderer.py +++ b/dooit/ui/widgets/renderers/todo_renderer.py @@ -9,7 +9,6 @@ Urgency, ) from .base_renderer import BaseRenderer, Todo -from ...registry import registry class TodoRender(BaseRenderer): @@ -19,10 +18,6 @@ def model(self) -> Todo: raise ValueError(f"Expected Todo, got {type(self._model)}") return self._model - @property - def table_layout(self) -> List: - return registry.get_todo_layout() - def post_init(self): self.description = TodoDescription(self.model) self.due = Due(self.model) diff --git a/dooit/ui/widgets/renderers/workspace_renderer.py b/dooit/ui/widgets/renderers/workspace_renderer.py index 6202febc..f23d2983 100644 --- a/dooit/ui/widgets/renderers/workspace_renderer.py +++ b/dooit/ui/widgets/renderers/workspace_renderer.py @@ -1,7 +1,6 @@ from typing import List from .base_renderer import BaseRenderer, Workspace from ..inputs.model_inputs import WorkspaceDescription -from ...registry import registry class WorkspaceRender(BaseRenderer): @@ -11,9 +10,6 @@ def model(self) -> Workspace: raise ValueError(f"Expected Workspace, got {type(self._model)}") return self._model - @property - def table_layout(self) -> List: - return registry.get_workspace_layout() def post_init(self): self.description = WorkspaceDescription(self.model) diff --git a/dooit/ui/widgets/trees/model_tree.py b/dooit/ui/widgets/trees/model_tree.py index 6c900a24..a84bfdb7 100644 --- a/dooit/ui/widgets/trees/model_tree.py +++ b/dooit/ui/widgets/trees/model_tree.py @@ -1,5 +1,5 @@ from collections import defaultdict -from typing import Generic, Iterable, Optional, TypeVar, Union +from typing import Any, Generic, Iterable, Optional, TypeVar, Union from textual.widgets.option_list import Option from dooit.api import Todo, Workspace from dooit.ui.events.events import ModeChanged, ShowConfirm, StartSearch, StartSort @@ -28,6 +28,10 @@ def __init__(self, model: ModelType, render_dict: RenderDictType) -> None: self._renderers: RenderDictType = render_dict self._filter_refresh = False + @property + def layout(self) -> Any: + raise NotImplementedError + @property def filter_refresh(self): return self._filter_refresh diff --git a/dooit/ui/widgets/trees/todos_tree.py b/dooit/ui/widgets/trees/todos_tree.py index a3126546..8818b15c 100644 --- a/dooit/ui/widgets/trees/todos_tree.py +++ b/dooit/ui/widgets/trees/todos_tree.py @@ -27,6 +27,10 @@ def _switch_to_workspace(self) -> None: self.screen.query_one("WorkspacesTree").focus() + @property + def layout(self): + return self.app.api.layouts.todo_layout + def add_todo(self) -> str: todo = self.model.add_todo() render = TodoRender(todo, tree=self) diff --git a/dooit/ui/widgets/trees/workspaces_tree.py b/dooit/ui/widgets/trees/workspaces_tree.py index a14ce420..495f3a59 100644 --- a/dooit/ui/widgets/trees/workspaces_tree.py +++ b/dooit/ui/widgets/trees/workspaces_tree.py @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import TYPE_CHECKING, List, Optional from textual import on from textual.widgets import ContentSwitcher from textual.widgets.option_list import Option @@ -22,6 +22,10 @@ def _get_parent(self, id: str) -> Optional[Workspace]: def _get_children(self, id: str) -> List[Workspace]: return Workspace.from_id(id).workspaces + @property + def layout(self): + return self.app.api.layouts.workspace_layout + @on(ModelTree.OptionHighlighted) async def update_todo_tree(self, event: ModelTree.OptionHighlighted): if not event.option_id: diff --git a/dooit/utils/default_config.py b/dooit/utils/default_config.py index 9a841e78..1604aea0 100644 --- a/dooit/utils/default_config.py +++ b/dooit/utils/default_config.py @@ -47,8 +47,7 @@ def key_setup(api: DooitAPI): api.keys.set_normal("/", api.start_search) api.keys.set_normal("ctrl+s", api.start_sort) - api.set_workspace_layout([WorkspaceWidget.description]) - - api.set_todo_layout([TodoWidget.description, TodoWidget.due]) + api.layouts.workspace_layout = [WorkspaceWidget.description] + api.layouts.todo_layout = [TodoWidget.description, TodoWidget.due] api.set_bar(bar_widgets)