Skip to content

Commit

Permalink
feat: impl WorkspaceDescriptionChanged event
Browse files Browse the repository at this point in the history
  • Loading branch information
kraanzu committed Oct 2, 2024
1 parent 1a88e80 commit fa43b7c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion dooit/ui/widgets/trees/workspaces_tree.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
from sqlalchemy.event import listen
from sqlalchemy.orm.attributes import get_history

from typing import TYPE_CHECKING, List, Optional
from textual import on
from textual.widgets.option_list import Option

from dooit.api import Workspace
from dooit.ui.events.events import WorkspaceRemoved, WorkspaceSelected
from dooit.ui.events.events import (
WorkspaceDescriptionChanged,
WorkspaceRemoved,
WorkspaceSelected,
)
from .model_tree import ModelTree
from .todos_tree import TodosTree
from ._render_dict import WorkspaceRenderDict
Expand Down Expand Up @@ -68,3 +75,19 @@ def workspace_highlighted(self, event: ModelTree.OptionHighlighted):

event.stop()
self.post_message(WorkspaceSelected(Workspace.from_id(event.option_id)))

# Listeners

def setup_listeners(self) -> None:
listen(Workspace, "after_update", self._track_description_update)

def _track_description_update(self, _mapper, _connection, target: Workspace):
history = get_history(target, "description")
if history.has_changes():
old = history.deleted[0] if history.deleted else ""
new = history.added[0] if history.added else ""

if old or new:
self.post_message(
WorkspaceDescriptionChanged(old, new, target),
)

0 comments on commit fa43b7c

Please sign in to comment.