Add a confirmation dialogue when deleting activites..
..which have >0 facts. Re #2
This commit is contained in:
parent
2a1d13236b
commit
fea15472e3
@ -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%;
|
||||
}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user