diff --git a/main.go b/main.go index 40a6f4a..384f5c7 100644 --- a/main.go +++ b/main.go @@ -135,6 +135,8 @@ func main() { if err != nil { panic("Could not write file at path " + te.FilePath) } + + te.Dirty = false } } }}, &ui.ItemEntry{Name: "Save _As...", Callback: func() { diff --git a/ui/container.go b/ui/container.go index 37f9a14..15257a5 100644 --- a/ui/container.go +++ b/ui/container.go @@ -192,7 +192,19 @@ func (c *TabContainer) Draw(s tcell.Screen) { } else { sty = c.Theme.GetOrDefault("Tab") } - str := fmt.Sprintf(" %s ", tab.Name) + + var dirty bool + switch typ := tab.Child.(type) { + case *TextEdit: + dirty = typ.Dirty + } + + name := tab.Name + if dirty { + name = "*" + name + } + + str := fmt.Sprintf(" %s ", name) //DrawStr(s, c.x+c.width/2-len(str)/2, c.y, str, sty) DrawStr(s, c.x+col, c.y, str, sty) col += len(str) + 1 // Add one for spacing between tabs diff --git a/ui/textedit.go b/ui/textedit.go index ca2f8da..16157d6 100644 --- a/ui/textedit.go +++ b/ui/textedit.go @@ -104,6 +104,7 @@ func (t *TextEdit) String() string { // LF (\n). The TextEdit `IsCRLF` variable is updated with the new value. func (t *TextEdit) ChangeLineDelimiters(crlf bool) { t.IsCRLF = crlf + t.Dirty = true // line delimiters are constructed with String() function } @@ -111,6 +112,8 @@ func (t *TextEdit) ChangeLineDelimiters(crlf bool) { // while Delete with `forwards` true will delete the character after (or on) the cursor. // In insert mode, forwards is always true. func (t *TextEdit) Delete(forwards bool) { + t.Dirty = true + if t.selectMode { // If text is selected, delete the whole selection t.cury, t.curx = t.clampLineCol(t.selection.EndLine, t.selection.EndCol) t.selectMode = false // Disable selection and prevent infinite loop @@ -172,6 +175,8 @@ func (t *TextEdit) Delete(forwards bool) { // Writes `contents` at the cursor position. Line delimiters and tab character supported. // Any other control characters will be printed. Overwrites any active selection. func (t *TextEdit) Insert(contents string) { + t.Dirty = true + if t.selectMode { // If there is a selection... // Go to and delete the selection t.Delete(true) // The parameter doesn't matter with selection