feat: rename toggle_messages_text_view to toggle_messages_panel

BREAKING: create a backup of your existing configuration file, delete it, and restart the application again to generate a new configuration file with updated fields.
This commit is contained in:
ayntgl 2022-08-19 23:57:54 +05:30
parent 10cc5772ed
commit 119772a983
5 changed files with 77 additions and 77 deletions

View file

@ -17,10 +17,10 @@ type IdentifyConfig struct {
}
type KeysConfig struct {
ToggleGuildsTree string `toml:"toggle_guilds_tree"`
ToggleChannelsTree string `toml:"toggle_channels_tree"`
ToggleMessagesTextView string `toml:"toggle_messages_text_view"`
ToggleMessageInput string `toml:"toggle_message_input"`
ToggleGuildsTree string `toml:"toggle_guilds_tree"`
ToggleChannelsTree string `toml:"toggle_channels_tree"`
ToggleMessagesPanel string `toml:"toggle_messages_panel"`
ToggleMessageInput string `toml:"toggle_message_input"`
OpenMessageActionsList string `toml:"open_message_actions_list"`
OpenExternalEditor string `toml:"open_external_editor"`
@ -68,10 +68,10 @@ func New() *Config {
Title: "white",
},
Keys: KeysConfig{
ToggleGuildsTree: "Rune[g]",
ToggleChannelsTree: "Rune[c]",
ToggleMessagesTextView: "Rune[m]",
ToggleMessageInput: "Rune[i]",
ToggleGuildsTree: "Rune[g]",
ToggleChannelsTree: "Rune[c]",
ToggleMessagesPanel: "Rune[m]",
ToggleMessageInput: "Rune[i]",
OpenMessageActionsList: "Rune[a]",
OpenExternalEditor: "Ctrl+E",

View file

@ -18,7 +18,7 @@ type App struct {
MainFlex *tview.Flex
GuildsTree *GuildsTree
ChannelsTree *ChannelsTree
MessagesTextView *MessagesTextView
MessagesPanel *MessagesPanel
MessageInputField *MessageInput
Config *config.Config
@ -48,7 +48,7 @@ func NewApp(token string, c *config.Config) *App {
app.GuildsTree = NewGuildsTree(app)
app.ChannelsTree = NewChannelsTree(app)
app.MessagesTextView = NewMessagesTextView(app)
app.MessagesPanel = NewMessagesPanel(app)
app.MessageInputField = NewMessageInput(app)
app.EnableMouse(app.Config.Mouse)
app.MainFlex.SetInputCapture(app.onInputCapture)
@ -83,8 +83,8 @@ func (app *App) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
case app.Config.Keys.ToggleChannelsTree:
app.SetFocus(app.ChannelsTree)
return nil
case app.Config.Keys.ToggleMessagesTextView:
app.SetFocus(app.MessagesTextView)
case app.Config.Keys.ToggleMessagesPanel:
app.SetFocus(app.MessagesPanel)
return nil
case app.Config.Keys.ToggleMessageInput:
app.SetFocus(app.MessageInputField)
@ -102,7 +102,7 @@ func (app *App) DrawMainFlex() {
AddItem(app.ChannelsTree, 0, 1, false)
rightFlex := tview.NewFlex().
SetDirection(tview.FlexRow).
AddItem(app.MessagesTextView, 0, 1, false).
AddItem(app.MessagesPanel, 0, 1, false).
AddItem(app.MessageInputField, 3, 1, false)
app.MainFlex.
AddItem(leftFlex, 0, 1, false).
@ -194,13 +194,13 @@ func (app *App) onStateGuildDelete(g *gateway.GuildDeleteEvent) {
func (app *App) onStateMessageCreate(m *gateway.MessageCreateEvent) {
if app.SelectedChannel != nil && app.SelectedChannel.ID == m.ChannelID {
_, err := app.MessagesTextView.Write(buildMessage(app, m.Message))
_, err := app.MessagesPanel.Write(buildMessage(app, m.Message))
if err != nil {
return
}
if len(app.MessagesTextView.GetHighlights()) == 0 {
app.MessagesTextView.ScrollToEnd()
if len(app.MessagesPanel.GetHighlights()) == 0 {
app.MessagesPanel.ScrollToEnd()
}
}
}

View file

@ -31,7 +31,7 @@ func NewChannelsTree(app *App) *ChannelsTree {
func (ct *ChannelsTree) onSelected(node *tview.TreeNode) {
ct.app.SelectedChannel = nil
ct.app.SelectedMessage = -1
ct.app.MessagesTextView.
ct.app.MessagesPanel.
Highlight().
Clear().
SetTitle("")
@ -56,7 +56,7 @@ func (ct *ChannelsTree) onSelected(node *tview.TreeNode) {
if c.Topic != "" {
title += " - " + parseMarkdown(c.Topic)
}
ct.app.MessagesTextView.SetTitle(title)
ct.app.MessagesPanel.SetTitle(title)
go func() {
// The returned slice will be sorted from latest to oldest.
@ -66,12 +66,12 @@ func (ct *ChannelsTree) onSelected(node *tview.TreeNode) {
}
for i := len(ms) - 1; i >= 0; i-- {
_, err = ct.app.MessagesTextView.Write(buildMessage(ct.app, ms[i]))
_, err = ct.app.MessagesPanel.Write(buildMessage(ct.app, ms[i]))
if err != nil {
return
}
}
ct.app.MessagesTextView.ScrollToEnd()
ct.app.MessagesPanel.ScrollToEnd()
}()
}

View file

@ -38,7 +38,7 @@ func (gt *GuildsTree) onSelected(node *tview.TreeNode) {
gt.app.SelectedMessage = -1
rootNode := gt.app.ChannelsTree.GetRoot()
rootNode.ClearChildren()
gt.app.MessagesTextView.
gt.app.MessagesPanel.
Highlight().
Clear().
SetTitle("")

View file

@ -20,13 +20,13 @@ import (
var linkRegex = regexp.MustCompile("https?://.+")
type MessagesTextView struct {
type MessagesPanel struct {
*tview.TextView
app *App
}
func NewMessagesTextView(app *App) *MessagesTextView {
mtv := &MessagesTextView{
func NewMessagesPanel(app *App) *MessagesPanel {
mtv := &MessagesPanel{
TextView: tview.NewTextView(),
app: app,
}
@ -46,66 +46,66 @@ func NewMessagesTextView(app *App) *MessagesTextView {
return mtv
}
func (mtv *MessagesTextView) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
if mtv.app.SelectedChannel == nil {
func (mp *MessagesPanel) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
if mp.app.SelectedChannel == nil {
return nil
}
// Messages should return messages ordered from latest to earliest.
ms, err := mtv.app.State.Cabinet.Messages(mtv.app.SelectedChannel.ID)
ms, err := mp.app.State.Cabinet.Messages(mp.app.SelectedChannel.ID)
if err != nil || len(ms) == 0 {
return nil
}
switch e.Name() {
case mtv.app.Config.Keys.SelectPreviousMessage:
// If there are no highlighted regions, select the latest (last) message in the messages TextView.
if len(mtv.app.MessagesTextView.GetHighlights()) == 0 {
mtv.app.SelectedMessage = 0
case mp.app.Config.Keys.SelectPreviousMessage:
// If there are no highlighted regions, select the latest (last) message in the messages panel.
if len(mp.app.MessagesPanel.GetHighlights()) == 0 {
mp.app.SelectedMessage = 0
} else {
// If the selected message is the oldest (first) message, select the latest (last) message in the messages TextView.
if mtv.app.SelectedMessage == len(ms)-1 {
mtv.app.SelectedMessage = 0
// If the selected message is the oldest (first) message, select the latest (last) message in the messages panel.
if mp.app.SelectedMessage == len(ms)-1 {
mp.app.SelectedMessage = 0
} else {
mtv.app.SelectedMessage++
mp.app.SelectedMessage++
}
}
mtv.app.MessagesTextView.
Highlight(ms[mtv.app.SelectedMessage].ID.String()).
mp.app.MessagesPanel.
Highlight(ms[mp.app.SelectedMessage].ID.String()).
ScrollToHighlight()
return nil
case mtv.app.Config.Keys.SelectNextMessage:
// If there are no highlighted regions, select the latest (last) message in the messages TextView.
if len(mtv.app.MessagesTextView.GetHighlights()) == 0 {
mtv.app.SelectedMessage = 0
case mp.app.Config.Keys.SelectNextMessage:
// If there are no highlighted regions, select the latest (last) message in the messages panel.
if len(mp.app.MessagesPanel.GetHighlights()) == 0 {
mp.app.SelectedMessage = 0
} else {
// If the selected message is the latest (last) message, select the oldest (first) message in the messages TextView.
if mtv.app.SelectedMessage == 0 {
mtv.app.SelectedMessage = len(ms) - 1
// If the selected message is the latest (last) message, select the oldest (first) message in the messages panel.
if mp.app.SelectedMessage == 0 {
mp.app.SelectedMessage = len(ms) - 1
} else {
mtv.app.SelectedMessage--
mp.app.SelectedMessage--
}
}
mtv.app.MessagesTextView.
Highlight(ms[mtv.app.SelectedMessage].ID.String()).
mp.app.MessagesPanel.
Highlight(ms[mp.app.SelectedMessage].ID.String()).
ScrollToHighlight()
return nil
case mtv.app.Config.Keys.SelectFirstMessage:
mtv.app.SelectedMessage = len(ms) - 1
mtv.app.MessagesTextView.
Highlight(ms[mtv.app.SelectedMessage].ID.String()).
case mp.app.Config.Keys.SelectFirstMessage:
mp.app.SelectedMessage = len(ms) - 1
mp.app.MessagesPanel.
Highlight(ms[mp.app.SelectedMessage].ID.String()).
ScrollToHighlight()
return nil
case mtv.app.Config.Keys.SelectLastMessage:
mtv.app.SelectedMessage = 0
mtv.app.MessagesTextView.
Highlight(ms[mtv.app.SelectedMessage].ID.String()).
case mp.app.Config.Keys.SelectLastMessage:
mp.app.SelectedMessage = 0
mp.app.MessagesPanel.
Highlight(ms[mp.app.SelectedMessage].ID.String()).
ScrollToHighlight()
return nil
case mtv.app.Config.Keys.OpenMessageActionsList:
hs := mtv.app.MessagesTextView.GetHighlights()
case mp.app.Config.Keys.OpenMessageActionsList:
hs := mp.app.MessagesPanel.GetHighlights()
if len(hs) == 0 {
return nil
}
@ -120,13 +120,13 @@ func (mtv *MessagesTextView) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
return nil
}
actionsList := NewMessageActionsList(mtv.app, m)
mtv.app.SetRoot(actionsList, true)
actionsList := NewMessageActionsList(mp.app, m)
mp.app.SetRoot(actionsList, true)
return nil
case "Esc":
mtv.app.SelectedMessage = -1
mtv.app.SetFocus(mtv.app.MainFlex)
mtv.app.MessagesTextView.
mp.app.SelectedMessage = -1
mp.app.SetFocus(mp.app.MainFlex)
mp.app.MessagesPanel.
Clear().
Highlight().
SetTitle("")
@ -153,7 +153,7 @@ func NewMessageActionsList(app *App, m *discord.Message) *MessageActionsList {
mal.SetDoneFunc(func() {
app.
SetRoot(app.MainFlex, true).
SetFocus(app.MessagesTextView)
SetFocus(app.MessagesPanel)
})
// If the client user has the `SEND_MESSAGES` permission, add "Reply" and "Mention Reply" actions.
@ -176,7 +176,7 @@ func NewMessageActionsList(app *App, m *discord.Message) *MessageActionsList {
}
app.SetRoot(app.MainFlex, true)
app.SetFocus(app.MessagesTextView)
app.SetFocus(app.MessagesPanel)
})
}
@ -225,13 +225,13 @@ func (mal *MessageActionsList) selectReplyAction() {
}
mal.app.SelectedMessage, _ = findMessageByID(ms, mal.message.ReferencedMessage.ID)
mal.app.MessagesTextView.
mal.app.MessagesPanel.
Highlight(mal.message.ReferencedMessage.ID.String()).
ScrollToHighlight()
mal.app.
SetRoot(mal.app.MainFlex, true).
SetFocus(mal.app.MessagesTextView)
SetFocus(mal.app.MessagesPanel)
}
func (mal *MessageActionsList) openAttachmentAction() {
@ -259,7 +259,7 @@ func (mal *MessageActionsList) openAttachmentAction() {
mal.app.
SetRoot(mal.app.MainFlex, true).
SetFocus(mal.app.MessagesTextView)
SetFocus(mal.app.MessagesPanel)
}
func (mal *MessageActionsList) downloadAttachmentAction() {
@ -285,11 +285,11 @@ func (mal *MessageActionsList) downloadAttachmentAction() {
mal.app.
SetRoot(mal.app.MainFlex, true).
SetFocus(mal.app.MessagesTextView)
SetFocus(mal.app.MessagesPanel)
}
func (mal *MessageActionsList) deleteAction() {
mal.app.MessagesTextView.Clear()
mal.app.MessagesPanel.Clear()
err := mal.app.State.MessageRemove(mal.message.ChannelID, mal.message.ID)
if err != nil {
@ -308,7 +308,7 @@ func (mal *MessageActionsList) deleteAction() {
}
for i := len(ms) - 1; i >= 0; i-- {
_, err = mal.app.MessagesTextView.Write(buildMessage(mal.app, ms[i]))
_, err = mal.app.MessagesPanel.Write(buildMessage(mal.app, ms[i]))
if err != nil {
return
}
@ -316,7 +316,7 @@ func (mal *MessageActionsList) deleteAction() {
mal.app.
SetRoot(mal.app.MainFlex, true).
SetFocus(mal.app.MessagesTextView)
SetFocus(mal.app.MessagesPanel)
}
func (mal *MessageActionsList) copyContentAction() {
@ -326,7 +326,7 @@ func (mal *MessageActionsList) copyContentAction() {
}
mal.app.SetRoot(mal.app.MainFlex, true)
mal.app.SetFocus(mal.app.MessagesTextView)
mal.app.SetFocus(mal.app.MessagesPanel)
}
func (mal *MessageActionsList) copyIDAction() {
@ -336,7 +336,7 @@ func (mal *MessageActionsList) copyIDAction() {
}
mal.app.SetRoot(mal.app.MainFlex, true)
mal.app.SetFocus(mal.app.MessagesTextView)
mal.app.SetFocus(mal.app.MessagesPanel)
}
type MessageInput struct {
@ -379,8 +379,8 @@ func (mi *MessageInput) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
return nil
}
if len(mi.app.MessagesTextView.GetHighlights()) != 0 {
mID, err := discord.ParseSnowflake(mi.app.MessagesTextView.GetHighlights()[0])
if len(mi.app.MessagesPanel.GetHighlights()) != 0 {
mID, err := discord.ParseSnowflake(mi.app.MessagesPanel.GetHighlights()[0])
if err != nil {
return nil
}
@ -400,7 +400,7 @@ func (mi *MessageInput) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
go mi.app.State.SendMessageComplex(m.ChannelID, d)
mi.app.SelectedMessage = -1
mi.app.MessagesTextView.Highlight()
mi.app.MessagesPanel.Highlight()
mi.app.MessageInputField.SetTitle("")
} else {
@ -423,7 +423,7 @@ func (mi *MessageInput) onInputCapture(e *tcell.EventKey) *tcell.EventKey {
mi.app.SetFocus(mi.app.MainFlex)
mi.app.SelectedMessage = -1
mi.app.MessagesTextView.Highlight()
mi.app.MessagesPanel.Highlight()
return nil
case mi.app.Config.Keys.OpenExternalEditor: