Show confirmation popup for delete project and clear completed tasks (#35)
This commit is contained in:
22
app/cli.go
22
app/cli.go
@@ -88,9 +88,12 @@ func setKeyboardShortcuts() *tview.Application {
|
||||
switch unicode.ToLower(event.Rune()) {
|
||||
case 'p':
|
||||
app.SetFocus(projectPane)
|
||||
contents.RemoveItem(taskDetailPane)
|
||||
return nil
|
||||
case 'q':
|
||||
case 't':
|
||||
app.SetFocus(taskPane)
|
||||
contents.RemoveItem(taskDetailPane)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -133,3 +136,22 @@ func makeTitleBar() *tview.Flex {
|
||||
AddItem(titleText, 0, 2, false).
|
||||
AddItem(versionInfo, 0, 1, false)
|
||||
}
|
||||
|
||||
func AskYesNo(text string, f func()) {
|
||||
|
||||
modal := tview.NewModal().
|
||||
SetText(text).
|
||||
AddButtons([]string{"Yes", "No"}).
|
||||
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||
if buttonLabel == "Yes" {
|
||||
f()
|
||||
}
|
||||
pages := tview.NewPages().
|
||||
AddPage("background", layout, true, true)
|
||||
_ = app.SetRoot(pages, true).EnableMouse(true).Run()
|
||||
})
|
||||
pages := tview.NewPages().
|
||||
AddPage("background", layout, true, true).
|
||||
AddPage("modal", modal, true, true)
|
||||
_ = app.SetRoot(pages, true).EnableMouse(true).Run()
|
||||
}
|
||||
|
||||
@@ -20,8 +20,12 @@ func NewProjectDetailPane() *ProjectDetailPane {
|
||||
pane := ProjectDetailPane{
|
||||
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
|
||||
}
|
||||
deleteBtn := makeButton("[::u]D[::-]elete Project", projectPane.RemoveActivateProject)
|
||||
clearBtn := makeButton("[::u]C[::-]lear Completed Tasks", taskPane.ClearCompletedTasks)
|
||||
deleteBtn := makeButton("[::u]D[::-]elete Project", func() {
|
||||
AskYesNo("Do you want to delete Project?", func() { projectPane.RemoveActivateProject() })
|
||||
})
|
||||
clearBtn := makeButton("[::u]C[::-]lear Completed Tasks", func() {
|
||||
AskYesNo("Do you want to clear completed tasks?", func() { taskPane.ClearCompletedTasks() })
|
||||
})
|
||||
|
||||
deleteBtn.SetBackgroundColor(tcell.ColorRed)
|
||||
pane.
|
||||
@@ -48,10 +52,10 @@ func (pd *ProjectDetailPane) isShowing() bool {
|
||||
func (pd *ProjectDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
||||
switch unicode.ToLower(event.Rune()) {
|
||||
case 'd':
|
||||
projectPane.RemoveActivateProject()
|
||||
AskYesNo("Do you want to delete Project?", func() { projectPane.RemoveActivateProject() })
|
||||
return nil
|
||||
case 'c':
|
||||
taskPane.ClearCompletedTasks()
|
||||
AskYesNo("Do you want to clear completed tasks?", func() { taskPane.ClearCompletedTasks() })
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -290,6 +290,7 @@ func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey
|
||||
switch event.Key() {
|
||||
case tcell.KeyEsc:
|
||||
app.SetFocus(taskPane)
|
||||
contents.RemoveItem(taskDetailPane)
|
||||
return nil
|
||||
case tcell.KeyDown:
|
||||
td.taskDetailView.ScrollDown(1)
|
||||
|
||||
Reference in New Issue
Block a user