Skip to content

Commit

Permalink
adding quit prompt when settings not saved
Browse files Browse the repository at this point in the history
  • Loading branch information
andro404-MC committed Jun 7, 2024
1 parent b1e5520 commit 3131357
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion data.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ type prompt struct {
Text string
}

var config configSTR
var (
config configSTR
unstagedChanges bool
)

const configPath = "/.config/quigo/quigo.conf"

Expand Down Expand Up @@ -75,5 +78,6 @@ func save(c *configSTR) {
fmt.Println("Error:", err)
return
}
unstagedChanges = false
return
}
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/theme"
"github.com/sqweek/dialog"
"golang.design/x/clipboard"
)

Expand All @@ -32,6 +33,23 @@ func main() {
container.NewTabItemWithIcon("Settings", theme.SettingsIcon(), settingTab()),
)

myWindow.SetCloseIntercept(
func() {
if unstagedChanges {
ok := dialog.Message("%s", "Changes not saved. Do you still want to Quit?").
Title("Quit ?").
YesNo()

if ok {
myApp.Quit()
}

} else {
myApp.Quit()
}
},
)

tabs.SetTabLocation(container.TabLocationTop)
myWindow.SetContent(tabs)
myWindow.ShowAndRun()
Expand Down
9 changes: 8 additions & 1 deletion settingTab.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ func settingTab() *fyne.Container {
apiLabel := widget.NewLabel("APIKEY")
apiInput := widget.NewPasswordEntry()
apiInput.Text = config.Apikey
apiInput.OnChanged = func(s string) { config.Apikey = s }
apiInput.OnChanged = func(s string) {
config.Apikey = s
unstagedChanges = true
}

promptNameInput := widget.NewEntry()
promptInput := widget.NewMultiLineEntry()
Expand Down Expand Up @@ -43,6 +46,8 @@ func settingTab() *fyne.Container {
combo.Options = maps.Keys(config.Prompts)
combo.Selected = ""
promptShowText.ParseMarkdown("")

unstagedChanges = true
})

promptAdd.OnTapped = func() {
Expand All @@ -55,6 +60,8 @@ func settingTab() *fyne.Container {

form.Refresh()
promptAdd.Disable()

unstagedChanges = true
}

dataChanged := func(_ string) {
Expand Down

0 comments on commit 3131357

Please sign in to comment.