Skip to content

Commit

Permalink
saved paths update
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoreilly committed Jan 21, 2024
1 parent 0d9b291 commit 30fb2a9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
6 changes: 3 additions & 3 deletions code/code/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ var (
CodeViewEditRecents = "<i>Edit Recents...</i>"

// SavedPathsExtras are the reset and edit items we add to the recents menu
SavedPathsExtras = []string{gi.MenuTextSeparator, CodeViewResetRecents, CodeViewEditRecents}
SavedPathsExtras = []string{CodeViewResetRecents, CodeViewEditRecents}
)

// SavePaths saves the active SavedPaths to prefs dir
Expand All @@ -329,7 +329,7 @@ func SavePaths() {
pnm := filepath.Join(pdir, SavedPathsFilename)
SavedPaths.Save(pnm)
// add back after save
gi.StringsAddExtras((*[]string)(&SavedPaths), SavedPathsExtras)
SavedPaths = append(SavedPaths, SavedPathsExtras...)
}

// OpenPaths loads the active SavedPaths from prefs dir
Expand All @@ -339,5 +339,5 @@ func OpenPaths() {
pdir := AppDataDir()
pnm := filepath.Join(pdir, SavedPathsFilename)
SavedPaths.Open(pnm)
gi.StringsAddExtras((*[]string)(&SavedPaths), SavedPathsExtras)
gi.SavedPaths = append(gi.SavedPaths, gi.SavedPathsExtras...)
}
3 changes: 3 additions & 0 deletions code/codev/appbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (ge *CodeView) ConfigToolbar(tb *gi.Toolbar) { //gti:add
gi.NewButton(tb).SetText("Open Recent").SetMenu(func(m *gi.Scene) {
for _, sp := range code.SavedPaths {
sp := sp
if sp == code.SavedPathsExtras[0] {
gi.NewSeparator(m)
}
gi.NewButton(m).SetText(sp).OnClick(func(e events.Event) {
ge.OpenRecent(gi.Filename(sp))
})
Expand Down
4 changes: 2 additions & 2 deletions code/codev/codeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (ge *CodeView) IsEmpty() bool {
func (ge *CodeView) OpenRecent(filename gi.Filename) { //gti:add
if string(filename) == code.CodeViewResetRecents {
code.SavedPaths = nil
gi.StringsAddExtras((*[]string)(&code.SavedPaths), code.SavedPathsExtras)
code.SavedPaths = append(code.SavedPaths, code.SavedPathsExtras...)
} else if string(filename) == code.CodeViewEditRecents {
ge.EditRecents()
} else {
Expand All @@ -189,7 +189,7 @@ func (ge *CodeView) EditRecents() {
d.AddBottomBar(func(pw gi.Widget) {
d.AddOk(pw).OnClick(func(e events.Event) {
code.SavedPaths = tmp
gi.StringsAddExtras((*[]string)(&code.SavedPaths), code.SavedPathsExtras)
code.SavedPaths = append(code.SavedPaths, code.SavedPathsExtras...)
})
})
d.NewDialog(ge).Run()
Expand Down

0 comments on commit 30fb2a9

Please sign in to comment.