Some refactoring and fixing in confirmation popup implementation
- Restoring focus to previous (taskPane) panel after closing modal (works only when invoked with shortcut)
- `projectPane.RemoveActivateProject()` and `taskPane.ClearCompletedTasks()` do comply with `func()`. So no need to wrap within `func() {}`
- Fixed issue - Project dosen't exit with Ctrl+C once (maybe because of re-running `.Run()` in `AskYesNo()`).
- When focusing back to tasklist from task detail, re-showing projectDetail pane
This commit is contained in:
@@ -139,6 +139,7 @@ func makeTitleBar() *tview.Flex {
|
|||||||
|
|
||||||
func AskYesNo(text string, f func()) {
|
func AskYesNo(text string, f func()) {
|
||||||
|
|
||||||
|
activePane := app.GetFocus()
|
||||||
modal := tview.NewModal().
|
modal := tview.NewModal().
|
||||||
SetText(text).
|
SetText(text).
|
||||||
AddButtons([]string{"Yes", "No"}).
|
AddButtons([]string{"Yes", "No"}).
|
||||||
@@ -146,12 +147,12 @@ func AskYesNo(text string, f func()) {
|
|||||||
if buttonLabel == "Yes" {
|
if buttonLabel == "Yes" {
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
pages := tview.NewPages().
|
app.SetRoot(layout, true).EnableMouse(true)
|
||||||
AddPage("background", layout, true, true)
|
app.SetFocus(activePane)
|
||||||
_ = app.SetRoot(pages, true).EnableMouse(true).Run()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
pages := tview.NewPages().
|
pages := tview.NewPages().
|
||||||
AddPage("background", layout, true, true).
|
AddPage("background", layout, true, true).
|
||||||
AddPage("modal", modal, true, true)
|
AddPage("modal", modal, true, true)
|
||||||
_ = app.SetRoot(pages, true).EnableMouse(true).Run()
|
_ = app.SetRoot(pages, true).EnableMouse(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,17 +15,21 @@ type ProjectDetailPane struct {
|
|||||||
project *model.Project
|
project *model.Project
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeProjectWithConfirmation() {
|
||||||
|
AskYesNo("Do you want to delete Project?", projectPane.RemoveActivateProject)
|
||||||
|
}
|
||||||
|
|
||||||
|
func clearCompletedWithConfirmation() {
|
||||||
|
AskYesNo("Do you want to clear completed tasks?", taskPane.ClearCompletedTasks)
|
||||||
|
}
|
||||||
|
|
||||||
// NewProjectDetailPane Initializes ProjectDetailPane
|
// NewProjectDetailPane Initializes ProjectDetailPane
|
||||||
func NewProjectDetailPane() *ProjectDetailPane {
|
func NewProjectDetailPane() *ProjectDetailPane {
|
||||||
pane := ProjectDetailPane{
|
pane := ProjectDetailPane{
|
||||||
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
|
Flex: tview.NewFlex().SetDirection(tview.FlexRow),
|
||||||
}
|
}
|
||||||
deleteBtn := makeButton("[::u]D[::-]elete Project", func() {
|
deleteBtn := makeButton("[::u]D[::-]elete Project", removeProjectWithConfirmation)
|
||||||
AskYesNo("Do you want to delete Project?", func() { projectPane.RemoveActivateProject() })
|
clearBtn := makeButton("[::u]C[::-]lear Completed Tasks", clearCompletedWithConfirmation)
|
||||||
})
|
|
||||||
clearBtn := makeButton("[::u]C[::-]lear Completed Tasks", func() {
|
|
||||||
AskYesNo("Do you want to clear completed tasks?", func() { taskPane.ClearCompletedTasks() })
|
|
||||||
})
|
|
||||||
|
|
||||||
deleteBtn.SetBackgroundColor(tcell.ColorRed)
|
deleteBtn.SetBackgroundColor(tcell.ColorRed)
|
||||||
pane.
|
pane.
|
||||||
@@ -52,10 +56,10 @@ func (pd *ProjectDetailPane) isShowing() bool {
|
|||||||
func (pd *ProjectDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
func (pd *ProjectDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch unicode.ToLower(event.Rune()) {
|
switch unicode.ToLower(event.Rune()) {
|
||||||
case 'd':
|
case 'd':
|
||||||
AskYesNo("Do you want to delete Project?", func() { projectPane.RemoveActivateProject() })
|
removeProjectWithConfirmation()
|
||||||
return nil
|
return nil
|
||||||
case 'c':
|
case 'c':
|
||||||
AskYesNo("Do you want to clear completed tasks?", func() { taskPane.ClearCompletedTasks() })
|
clearCompletedWithConfirmation()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -289,8 +289,9 @@ func writeToTmpFile(content string) (string, error) {
|
|||||||
func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
func (td *TaskDetailPane) handleShortcuts(event *tcell.EventKey) *tcell.EventKey {
|
||||||
switch event.Key() {
|
switch event.Key() {
|
||||||
case tcell.KeyEsc:
|
case tcell.KeyEsc:
|
||||||
|
removeThirdCol()
|
||||||
app.SetFocus(taskPane)
|
app.SetFocus(taskPane)
|
||||||
contents.RemoveItem(taskDetailPane)
|
contents.AddItem(projectDetailPane, 25, 0, false)
|
||||||
return nil
|
return nil
|
||||||
case tcell.KeyDown:
|
case tcell.KeyDown:
|
||||||
td.taskDetailView.ScrollDown(1)
|
td.taskDetailView.ScrollDown(1)
|
||||||
|
|||||||
Reference in New Issue
Block a user