Co-authored-by: Ayyan <ayn2op@gmail.com>
This commit is contained in:
parent
0dbd8ce007
commit
a2f16a4d72
4 changed files with 44 additions and 5 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"github.com/ayn2op/discordo/internal/config"
|
||||
"github.com/ayn2op/discordo/internal/consts"
|
||||
"github.com/ayn2op/discordo/internal/login"
|
||||
"github.com/ayn2op/discordo/internal/ui"
|
||||
"github.com/ayn2op/tview"
|
||||
"github.com/gdamore/tcell/v2"
|
||||
"github.com/zalando/go-keyring"
|
||||
|
|
@ -15,6 +16,7 @@ const (
|
|||
flexPageName = "flex"
|
||||
mentionsListPageName = "mentionsList"
|
||||
attachmentsListPageName = "attachmentsList"
|
||||
confirmModalPageName = "confirmModal"
|
||||
)
|
||||
|
||||
type application struct {
|
||||
|
|
@ -151,3 +153,23 @@ func (a *application) onFlexInputCapture(event *tcell.EventKey) *tcell.EventKey
|
|||
|
||||
return event
|
||||
}
|
||||
|
||||
func (a *application) showConfirmModal(prompt string, buttons []string, onDone func(label string)) {
|
||||
previousFocus := a.GetFocus()
|
||||
|
||||
modal := tview.NewModal().
|
||||
SetText(prompt).
|
||||
AddButtons(buttons).
|
||||
SetDoneFunc(func(_ int, buttonLabel string) {
|
||||
a.pages.RemovePage(confirmModalPageName).SwitchToPage(flexPageName)
|
||||
a.SetFocus(previousFocus)
|
||||
|
||||
if onDone != nil {
|
||||
onDone(buttonLabel)
|
||||
}
|
||||
})
|
||||
|
||||
a.pages.
|
||||
AddAndSwitchToPage(confirmModalPageName, ui.Centered(modal, 40, 10), true).
|
||||
ShowPage(flexPageName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -282,8 +282,9 @@ func (ml *messagesList) onInputCapture(event *tcell.EventKey) *tcell.EventKey {
|
|||
ml.reply(true)
|
||||
case ml.cfg.Keys.MessagesList.Delete:
|
||||
ml.delete()
|
||||
case ml.cfg.Keys.MessagesList.DeleteConfirm:
|
||||
ml.confirmDelete()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -557,6 +558,20 @@ func (ml *messagesList) reply(mention bool) {
|
|||
app.SetFocus(app.messageInput)
|
||||
}
|
||||
|
||||
func (ml *messagesList) confirmDelete() {
|
||||
onChoice := func(choice string) {
|
||||
if choice == "Yes" {
|
||||
ml.delete()
|
||||
}
|
||||
}
|
||||
|
||||
app.showConfirmModal(
|
||||
"Are you sure you want to delete this message?",
|
||||
[]string{"Yes", "No"},
|
||||
onChoice,
|
||||
)
|
||||
}
|
||||
|
||||
func (ml *messagesList) delete() {
|
||||
msg, err := ml.selectedMsg()
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,8 @@ reply = "Rune[r]"
|
|||
# Reply (with mention) to the selected message.
|
||||
reply_mention = "Rune[R]"
|
||||
cancel = "Esc"
|
||||
delete = "Rune[d]"
|
||||
delete = "Rune[D]"
|
||||
delete_confirm = "Rune[d]"
|
||||
# Open the selected message's attachments or hyperlinks in the message
|
||||
# using the default browser application.
|
||||
open = "Rune[o]"
|
||||
|
|
|
|||
|
|
@ -40,9 +40,10 @@ type (
|
|||
Reply string `toml:"reply"`
|
||||
ReplyMention string `toml:"reply_mention"`
|
||||
|
||||
Cancel string `toml:"cancel"`
|
||||
Delete string `toml:"delete"`
|
||||
Open string `toml:"open"`
|
||||
Cancel string `toml:"cancel"`
|
||||
Delete string `toml:"delete"`
|
||||
DeleteConfirm string `toml:"delete_confirm"`
|
||||
Open string `toml:"open"`
|
||||
|
||||
YankContent string `toml:"yank_content"`
|
||||
YankURL string `toml:"yank_url"`
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue