add multi-server functionality pt. 2 - delete server

This commit is contained in:
Drew Weymouth
2023-05-17 16:19:24 -07:00
parent 85eb790cd1
commit 4d4b14e4de
8 changed files with 113 additions and 18 deletions
+24 -5
View File
@@ -21,6 +21,7 @@ type AddEditServerDialog struct {
Password string
LegacyAuth bool
OnSubmit func()
OnCancel func()
passField *widget.Entry
submitBtn *widget.Button
@@ -30,7 +31,7 @@ type AddEditServerDialog struct {
var _ fyne.Widget = (*AddEditServerDialog)(nil)
func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig, focusHandler func(fyne.Focusable)) *AddEditServerDialog {
func NewAddEditServerDialog(title string, cancelable bool, prefillServer *backend.ServerConfig, focusHandler func(fyne.Focusable)) *AddEditServerDialog {
a := &AddEditServerDialog{}
a.ExtendBaseWidget(a)
if prefillServer != nil {
@@ -57,11 +58,26 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig, f
nickField.SetPlaceHolder("My Server")
nickField.OnSubmitted = func(_ string) { focusHandler(hostField) }
a.submitBtn = widget.NewButton("Enter", a.doSubmit)
a.submitBtn.Importance = widget.HighImportance
a.promptText = widget.NewRichTextWithText("")
a.promptText.Hidden = true
legacyAuthCheck := widget.NewCheckWithData("Use legacy authentication", binding.BindBool(&a.LegacyAuth))
var bottomRow *fyne.Container
if cancelable {
bottomRow = container.NewHBox(
a.promptText,
layout.NewSpacer(),
widget.NewButton("Cancel", a.onCancel),
a.submitBtn)
} else {
bottomRow = container.NewHBox(
a.promptText,
layout.NewSpacer(),
a.submitBtn)
}
a.container = container.NewVBox(
container.NewHBox(layout.NewSpacer(), titleLabel, layout.NewSpacer()),
container.New(layout.NewFormLayout(),
@@ -78,10 +94,7 @@ func NewAddEditServerDialog(title string, prefillServer *backend.ServerConfig, f
),
container.NewHBox(layout.NewSpacer(), legacyAuthCheck),
widget.NewSeparator(),
container.NewHBox(
a.promptText,
layout.NewSpacer(),
a.submitBtn),
bottomRow,
)
return a
}
@@ -111,6 +124,12 @@ func (a *AddEditServerDialog) doSubmit() {
}
}
func (a *AddEditServerDialog) onCancel() {
if a.OnCancel != nil {
a.OnCancel()
}
}
func (a *AddEditServerDialog) doSetPromptText(text string, color fyne.ThemeColorName) {
ts := a.promptText.Segments[0].(*widget.TextSegment)
ts.Text = text