Show dirty TextEdit tabs

This commit is contained in:
Luke I. Wilson 2021-03-20 13:46:44 -05:00
parent ca4a847547
commit bc08505fa8
3 changed files with 20 additions and 1 deletions

View File

@ -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() {

View File

@ -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

View File

@ -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