Просмотр исходного кода

Revert "Move ui events handlers to corresponding file"

This reverts commit 585e5e26d93093c7b0ddf555a69c306f45ba0198.
rigormorrtiss 4 лет назад
Родитель
Сommit
a9ea2244f5
4 измененных файлов с 21 добавлено и 25 удалено
  1. 16 4
      discordo.go
  2. 1 5
      ui/app.go
  3. 2 8
      ui/forms.go
  4. 2 8
      ui/textviews.go

+ 16 - 4
discordo.go

@@ -46,9 +46,9 @@ func main() {
 	loginModal = ui.NewLoginModal(onLoginModalDone)
 	guildsDropDown = ui.NewGuildsDropDown(onGuildsDropDownSelected)
 	channelsList = ui.NewChannelsList(onChannelsListSelected)
-	messagesTextView = ui.NewMessagesTextView(app)
+	messagesTextView = ui.NewMessagesTextView(onMessagesTextViewChanged)
 	mainFlex = ui.NewMainFlex(guildsDropDown, channelsList, messagesTextView)
-	app = ui.NewApp()
+	app = ui.NewApp(onAppInputCapture)
 
 	token := util.GetPassword("token")
 	if token != "" {
@@ -66,14 +66,26 @@ func main() {
 	}
 }
 
+func onAppInputCapture(event *tcell.EventKey) *tcell.EventKey {
+	return event
+}
+
+func onLoginFormQuitButtonSelected() {
+	app.Stop()
+}
+
+func onMessagesTextViewChanged() {
+	app.Draw()
+}
+
 func onLoginModalDone(buttonIndex int, buttonLabel string) {
 	if buttonLabel == ui.LoginViaEmailPasswordLoginModalButton {
 		loginVia = "emailpassword"
-		loginForm = ui.NewLoginForm(app, loginVia, onLoginFormLoginButtonSelected)
+		loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected, onLoginFormQuitButtonSelected)
 		app.SetRoot(loginForm, true)
 	} else if buttonLabel == ui.LoginViaTokenLoginModalButton {
 		loginVia = "token"
-		loginForm = ui.NewLoginForm(app, loginVia, onLoginFormLoginButtonSelected)
+		loginForm = ui.NewLoginForm(loginVia, onLoginFormLoginButtonSelected, onLoginFormQuitButtonSelected)
 		app.SetRoot(loginForm, true)
 	}
 }

+ 1 - 5
ui/app.go

@@ -5,14 +5,10 @@ import (
 	"github.com/rivo/tview"
 )
 
-func NewApp() (app *tview.Application) {
+func NewApp(onAppInputCapture func(event *tcell.EventKey) *tcell.EventKey) (app *tview.Application) {
 	app = tview.NewApplication().
 		EnableMouse(true).
 		SetInputCapture(onAppInputCapture)
 
 	return
 }
-
-func onAppInputCapture(event *tcell.EventKey) *tcell.EventKey {
-	return event
-}

+ 2 - 8
ui/forms.go

@@ -5,10 +5,10 @@ import (
 	"github.com/rivo/tview"
 )
 
-func NewLoginForm(app *tview.Application, via string, onLoginFormLoginButtonSelected func()) (loginForm *tview.Form) {
+func NewLoginForm(via string, onLoginFormLoginButtonSelected func(), onLoginFormQuitButtonSelected func()) (loginForm *tview.Form) {
 	loginForm = tview.NewForm().
 		AddButton("Login", onLoginFormLoginButtonSelected).
-		AddButton("Quit", onLoginFormQuitButtonSelected(app)).
+		AddButton("Quit", onLoginFormQuitButtonSelected).
 		SetButtonsAlign(tview.AlignCenter)
 	loginForm.
 		SetButtonBackgroundColor(tcell.GetColor("#5865F2")).
@@ -25,9 +25,3 @@ func NewLoginForm(app *tview.Application, via string, onLoginFormLoginButtonSele
 
 	return loginForm
 }
-
-func onLoginFormQuitButtonSelected(app *tview.Application) func() {
-	return func() {
-		app.Stop()
-	}
-}

+ 2 - 8
ui/textviews.go

@@ -4,23 +4,17 @@ import (
 	"github.com/rivo/tview"
 )
 
-func NewMessagesTextView(app *tview.Application) (messagesTextView *tview.TextView) {
+func NewMessagesTextView(onMessagesTextViewChanged func()) (messagesTextView *tview.TextView) {
 	messagesTextView = tview.NewTextView().
 		SetDynamicColors(true).
 		SetWrap(true).
 		SetWordWrap(true).
 		SetScrollable(true).
 		ScrollToEnd().
-		SetChangedFunc(onMessagesTextViewChanged(app))
+		SetChangedFunc(onMessagesTextViewChanged)
 	messagesTextView.
 		SetBorder(true).
 		SetBorderPadding(0, 0, 1, 1)
 
 	return
 }
-
-func onMessagesTextViewChanged(app *tview.Application) func() {
-	return func() {
-		app.Draw()
-	}
-}