Skip to content

Commit

Permalink
feat: add <Model>Removed events
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Oct 2, 2024
1 parent 52a2ef7 commit 2f38740
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dooit/ui/screens/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
ShowConfirm,
StartSearch,
StartSort,
TodoRemoved,
WorkspaceSelected,
)
from dooit.ui.events import (
Expand Down Expand Up @@ -124,3 +125,7 @@ def workspace_selected(self, event: WorkspaceSelected):
switcher.add_content(tree, set_current=True)
else:
switcher.current = tree.id

@on(TodoRemoved)
def todo_removed(self, event: TodoRemoved):
self.notify(event.todo.description)
8 changes: 8 additions & 0 deletions dooit/ui/widgets/trees/todos_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from textual.widgets.option_list import Option

from dooit.api import Todo, Workspace
from dooit.ui.events.events import TodoRemoved
from .model_tree import ModelTree
from ..renderers.todo_renderer import TodoRender
from ._render_dict import TodoRenderDict
Expand Down Expand Up @@ -51,3 +52,10 @@ def _add_first_item(self) -> Todo:

def _create_child_node(self) -> Todo:
return self.current_model.add_todo()

def _remove_node(self) -> None:
assert isinstance(self.current_model, Todo)
self.post_message(TodoRemoved(self.current_model))

return super()._remove_node()

6 changes: 5 additions & 1 deletion dooit/ui/widgets/trees/workspaces_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from textual.widgets.option_list import Option

from dooit.api import Workspace
from dooit.ui.events.events import WorkspaceSelected
from dooit.ui.events.events import WorkspaceRemoved, WorkspaceSelected
from .model_tree import ModelTree
from .todos_tree import TodosTree
from ._render_dict import WorkspaceRenderDict
Expand Down Expand Up @@ -58,6 +58,10 @@ def _create_child_node(self) -> Workspace:
def _add_first_item(self) -> Workspace:
return self.model.add_workspace()

def _remove_node(self) -> None:
self.post_message(WorkspaceRemoved(self.current_model))
return super()._remove_node()

@on(ModelTree.OptionHighlighted)
def workspace_highlighted(self, event: ModelTree.OptionHighlighted):
assert event.option_id
Expand Down

0 comments on commit 2f38740

Please sign in to comment.