diff --git a/tracker/gioui/tracker.go b/tracker/gioui/tracker.go index e44d0e7..8af1d7b 100644 --- a/tracker/gioui/tracker.go +++ b/tracker/gioui/tracker.go @@ -7,6 +7,7 @@ import ( "os/exec" "path/filepath" "runtime" + "strings" "time" "gioui.org/app" @@ -122,11 +123,12 @@ func (t *Tracker) Main() { recoveryTicker := time.NewTicker(time.Second * 30) var ops op.Ops titlePath := "" + changedSinceSave := false globals := make(map[string]any, 1) globals["Tracker"] = t for !t.Quitted() { w := t.newWindow() - w.Option(app.Title(titleFromPath(titlePath))) + w.Option(app.Title(titleFromPath(titlePath, changedSinceSave))) t.Explorer = explorer.NewExplorer(w) acks := make(chan struct{}) events := make(chan event.Event) @@ -171,9 +173,10 @@ func (t *Tracker) Main() { acks <- struct{}{} break F // this window is done, we need to create a new one case app.FrameEvent: - if titlePath != t.filePathString.Value() { + if titlePath != t.filePathString.Value() || changedSinceSave != t.Song().ChangedSinceSave() { titlePath = t.filePathString.Value() - w.Option(app.Title(titleFromPath(titlePath))) + changedSinceSave = t.Song().ChangedSinceSave() + w.Option(app.Title(titleFromPath(titlePath, changedSinceSave))) } gtx := app.NewContext(&ops, e) gtx.Values = globals @@ -211,11 +214,17 @@ func (t *Tracker) newWindow() *app.Window { return w } -func titleFromPath(path string) string { - if path == "" { - return "Sointu Tracker" +func titleFromPath(path string, unsaved bool) string { + var sb strings.Builder + sb.WriteString("Sointu Tracker") + if path != "" { + sb.WriteString(" - ") + sb.WriteString(path) } - return fmt.Sprintf("Sointu Tracker - %s", path) + if unsaved { + sb.WriteString(" *") + } + return sb.String() } func (t *Tracker) Layout(gtx layout.Context) { diff --git a/tracker/song.go b/tracker/song.go index 3239dee..78b1bc8 100644 --- a/tracker/song.go +++ b/tracker/song.go @@ -19,6 +19,9 @@ func (m *Model) Song() *SongModel { return (*SongModel)(m) } type SongModel Model +// ChangesSinceSave returns a Bool representing whether the current song has unsaved +func (m *SongModel) ChangedSinceSave() bool { return m.d.ChangedSinceSave } + // FilePath returns a String representing the file path of the current song. func (m *SongModel) FilePath() String { return MakeString((*songFilePath)(m)) }