window.currentContainer has been removed
* callbacks used for updating #currentContainer have been removed as
well
MODIFY
main.go
main.go
@@ -8,7 +8,7 @@ import (
"github.com/Bios-Marcel/cordless/app"
"github.com/Bios-Marcel/cordless/config"
- "github.com/Bios-Marcel/cordless/shortcuts"
+ "github.com/Bios-Marcel/cordless/ui/shortcutdialog"
"github.com/Bios-Marcel/cordless/version"
)
@@ -21,7 +21,7 @@ func main() {
flag.Parse()
if showShortcutsDialog != nil && *showShortcutsDialog {
- shortcuts.RunShortcutsDialogStandalone()
+ shortcutdialog.RunShortcutsDialogStandalone()
} else if showVersion != nil && *showVersion {
fmt.Printf("You are running cordless version %s\nKeep in mind that this version might not be correct for manually built versions, as those can contain additional commits.\n", version.Version)
} else {

MODIFY
ui/shortcutdialog/dialog.go
ui/shortcutdialog/dialog.go
@@ -23,7 +23,7 @@ func checkVT() bool {
var vtxxx = checkVT()
-func ShowShortcutsDialog(app *tview.Application, onClose func(), beforeShow func(view *tview.Flex)) {
+func ShowShortcutsDialog(app *tview.Application, onClose func()) {
var table *ShortcutTable
var shortcutDescription *tview.TextView
var exitButton *tview.Button
@@ -105,9 +105,6 @@ func ShowShortcutsDialog(app *tview.Application, onClose func(), beforeShow func
app.SetRoot(shortcutsView, true)
app.SetFocus(table.GetPrimitive())
- if beforeShow != nil {
- beforeShow(shortcutsView)
- }
}
func RunShortcutsDialogStandalone() {
@@ -118,7 +115,7 @@ func RunShortcutsDialogStandalone() {
app := tview.NewApplication()
ShowShortcutsDialog(app, func() {
app.Stop()
- }, nil)
+ })
startError := app.Run()
if startError != nil {
log.Fatalf("Error launching shortcuts dialog: %s\n", startError)

MODIFY
ui/tviewutil/dialogs.go
ui/tviewutil/dialogs.go
@@ -10,20 +10,18 @@ import (
// PrompSecretSingleLineInput shows a fullscreen input dialog that masks the
// user input. The returned value will either be empty or what the user
// has entered.
-func PrompSecretSingleLineInput(app *tview.Application,
- activePrimitiveChanged func(primitive tview.Primitive), title, message string) string {
- return promptSingleLineInput(app, '*', activePrimitiveChanged, title, message)
+func PrompSecretSingleLineInput(app *tview.Application, title, message string) string {
+ return promptSingleLineInput(app, '*', title, message)
}
// PromptSingleLineInput shows a fullscreen input dialog.
// The returned value will either be empty or what the user has entered.
func PromptSingleLineInput(app *tview.Application,
activePrimitiveChanged func(primitive tview.Primitive), title, message string) string {
- return promptSingleLineInput(app, 0, activePrimitiveChanged, title, message)
+ return promptSingleLineInput(app, 0, title, message)
}
-func promptSingleLineInput(app *tview.Application, maskCharacter rune,
- activePrimitiveChanged func(primitive tview.Primitive), title, message string) string {
+func promptSingleLineInput(app *tview.Application, maskCharacter rune, title, message string) string {
waitChannel := make(chan struct{})
var output string
@@ -58,12 +56,10 @@ func promptSingleLineInput(app *tview.Application, maskCharacter rune,
frame.SetBorder(true)
frame.AddText(message, true, tview.AlignLeft, tcell.ColorDefault)
app.SetRoot(frame, true)
- activePrimitiveChanged(frame)
})
<-waitChannel
app.QueueUpdateDraw(func() {
app.SetRoot(previousRoot, true)
- activePrimitiveChanged(previousRoot)
app.SetFocus(previousFocus)
waitChannel <- struct{}{}
})

MODIFY
ui/window.go
ui/window.go
@@ -51,7 +51,6 @@ type Window struct {
dialogReplacement *tview.Flex
dialogButtonBar *tview.Flex
dialogTextView *tview.TextView
- currentContainer tview.Primitive
leftArea *tview.Flex
guildList *GuildList
@@ -1113,7 +1112,6 @@ func NewWindow(doRestart chan bool, app *tview.Application, session *discordgo.S
}
app.SetRoot(window.rootContainer, true)
- window.currentContainer = window.rootContainer
app.SetInputCapture(window.handleGlobalShortcuts)
if config.Current.UseFixedLayout {
@@ -2232,7 +2230,7 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
return nil
}
- if window.currentContainer != window.rootContainer {
+ if window.app.GetRoot() != window.rootContainer {
return event
}
@@ -2243,10 +2241,7 @@ func (window *Window) handleGlobalShortcuts(event *tcell.EventKey) *tcell.EventK
if shortcuts.EventsEqual(event, shortcutsDialogShortcut) {
shortcutdialog.ShowShortcutsDialog(window.app, func() {
window.app.SetRoot(window.rootContainer, true)
- window.currentContainer = window.rootContainer
window.app.ForceDraw()
- }, func(view *tview.Flex) {
- window.currentContainer = view
})
} else if shortcuts.ToggleCommandView.Equals(event) {
window.SetCommandModeEnabled(!window.commandMode)
@@ -2328,11 +2323,9 @@ func (window *Window) toggleBareChat() {
window.bareChat = !window.bareChat
if window.bareChat {
window.chatView.internalTextView.SetBorder(false)
- window.currentContainer = window.chatView.GetPrimitive()
window.app.SetRoot(window.chatView.GetPrimitive(), true)
} else {
window.chatView.internalTextView.SetBorder(true)
- window.currentContainer = window.rootContainer
window.app.SetRoot(window.rootContainer, true)
}
}
@@ -2539,7 +2532,8 @@ func (window *Window) SwitchToFriendsPage() {
window.activeView = Dms
}
-// Switches to the previous channel and layout.
+// SwitchToPreviousChannel loads the previously loaded channel and focuses it
+// in it's respective UI primitive.
func (window *Window) SwitchToPreviousChannel() error {
if window.previousChannel == nil || window.previousChannel == window.selectedChannel {
// No previous channel.
@@ -2734,12 +2728,10 @@ func (window *Window) GetSelectedChannel() *discordgo.Channel {
return window.selectedChannel
}
-// PromptSecretInput shows an input dialog that masks the user input. The
-// returned value will either be empty or what the user has entered.
+// PromptSecretInput shows a fullscreen input dialog that masks the user input.
+// The returned value will either be empty or what the user has entered.
func (window *Window) PromptSecretInput(title, message string) string {
- return tviewutil.PrompSecretSingleLineInput(window.app, func(root tview.Primitive) {
- window.currentContainer = root
- }, title, message)
+ return tviewutil.PrompSecretSingleLineInput(window.app, title, message)
}
// ForceRedraw triggers ForceDraw on the underlying tview application, causing

window.currentContainer has been removed

* callbacks used for updating #currentContainer have been removed as
well