Compare commits

...

2 Commits

Author SHA1 Message Date
3wc
fea15472e3 Add a confirmation dialogue when deleting activites..
..which have >0 facts.

Re #2
2023-12-25 19:28:42 -03:00
3wc
2a1d13236b Update requirements 2023-12-25 19:12:03 -03:00
3 changed files with 65 additions and 5 deletions

View File

@ -18,7 +18,7 @@ DataTable:focus .datatable--cursor {
width: 50%;
}
ActivityEditScreen, ActivityMappingScreen {
ActivityEditScreen, ActivityMappingScreen, ActivityDeleteConfirmScreen {
align: center middle;
}
@ -62,3 +62,25 @@ ActivityMappingScreen AutoComplete {
ActivityEditScreen Input {
width: 60;
}
#dialog {
grid-size: 2;
grid-gutter: 1 2;
grid-rows: 1fr 3;
padding: 0 1;
width: 60;
height: 11;
border: thick $background 80%;
background: $surface;
}
#question {
column-span: 2;
height: 1fr;
width: 1fr;
content-align: center middle;
}
Button {
width: 100%;
}

View File

@ -4,7 +4,7 @@ from textual import on
from textual.app import ComposeResult
from textual.binding import Binding
from textual.coordinate import Coordinate
from textual.containers import Horizontal, Vertical
from textual.containers import Horizontal, Vertical, Grid
from textual.events import DescendantBlur
from textual.screen import Screen, ModalScreen
from textual.widgets import (
@ -16,6 +16,7 @@ from textual.widgets import (
Checkbox,
TabbedContent,
TabPane,
Button
)
from peewee import fn, JOIN
@ -273,6 +274,29 @@ class ActivityMappingScreen(ModalScreen):
self.dismiss(None)
class ActivityDeleteConfirmScreen(ModalScreen):
BINDINGS = [
("escape", "cancel", "Cancel"),
]
def compose(self) -> ComposeResult:
yield Grid(
Label("Are you sure you want to delete this activity?", id="question"),
Button("Confirm", variant="error", id="confirm"),
Button("Cancel", variant="primary", id="cancel"),
id="dialog",
)
def on_button_pressed(self, event: Button.Pressed) -> None:
if event.button.id == "quit":
self.dismiss(True)
else:
self.dismiss(False)
def action_cancel(self):
self.dismiss(False)
class ActivityList(ListPane):
BINDINGS = [
("s", "sort", "Sort"),
@ -384,10 +408,19 @@ class ActivityList(ListPane):
)
activity = HamsterActivity.get(id=activity_id)
activity.delete_instance()
# supply the row key to `remove_row` to delete the row.
self.table.remove_row(row_key)
def check_delete(delete: bool) -> None:
"""Called when QuitScreen is dismissed."""
if delete:
activity.delete_instance()
# supply the row key to `remove_row` to delete the row.
self.table.remove_row(row_key)
if activity.facts.count() > 0:
self.app.push_screen(ActivityDeleteConfirmScreen(), check_delete)
else:
check_delete(True)
def action_move_facts(self) -> None:
row_idx: int = self.table.cursor_row

View File

@ -1,2 +1,7 @@
click==8.0.3
requests==2.26.0
peewee==3.17.0
requests-cache==1.1.1
textual==0.44.1
textual-autocomplete==2.1.0b0
textual-dev==1.2.1