Show dirty TextEdit tabs
This commit is contained in:
parent
ca4a847547
commit
bc08505fa8
2
main.go
2
main.go
@ -135,6 +135,8 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic("Could not write file at path " + te.FilePath)
|
panic("Could not write file at path " + te.FilePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
te.Dirty = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}, &ui.ItemEntry{Name: "Save _As...", Callback: func() {
|
}}, &ui.ItemEntry{Name: "Save _As...", Callback: func() {
|
||||||
|
@ -192,7 +192,19 @@ func (c *TabContainer) Draw(s tcell.Screen) {
|
|||||||
} else {
|
} else {
|
||||||
sty = c.Theme.GetOrDefault("Tab")
|
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+c.width/2-len(str)/2, c.y, str, sty)
|
||||||
DrawStr(s, c.x+col, c.y, str, sty)
|
DrawStr(s, c.x+col, c.y, str, sty)
|
||||||
col += len(str) + 1 // Add one for spacing between tabs
|
col += len(str) + 1 // Add one for spacing between tabs
|
||||||
|
@ -104,6 +104,7 @@ func (t *TextEdit) String() string {
|
|||||||
// LF (\n). The TextEdit `IsCRLF` variable is updated with the new value.
|
// LF (\n). The TextEdit `IsCRLF` variable is updated with the new value.
|
||||||
func (t *TextEdit) ChangeLineDelimiters(crlf bool) {
|
func (t *TextEdit) ChangeLineDelimiters(crlf bool) {
|
||||||
t.IsCRLF = crlf
|
t.IsCRLF = crlf
|
||||||
|
t.Dirty = true
|
||||||
// line delimiters are constructed with String() function
|
// 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.
|
// while Delete with `forwards` true will delete the character after (or on) the cursor.
|
||||||
// In insert mode, forwards is always true.
|
// In insert mode, forwards is always true.
|
||||||
func (t *TextEdit) Delete(forwards bool) {
|
func (t *TextEdit) Delete(forwards bool) {
|
||||||
|
t.Dirty = true
|
||||||
|
|
||||||
if t.selectMode { // If text is selected, delete the whole selection
|
if t.selectMode { // If text is selected, delete the whole selection
|
||||||
t.cury, t.curx = t.clampLineCol(t.selection.EndLine, t.selection.EndCol)
|
t.cury, t.curx = t.clampLineCol(t.selection.EndLine, t.selection.EndCol)
|
||||||
t.selectMode = false // Disable selection and prevent infinite loop
|
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.
|
// Writes `contents` at the cursor position. Line delimiters and tab character supported.
|
||||||
// Any other control characters will be printed. Overwrites any active selection.
|
// Any other control characters will be printed. Overwrites any active selection.
|
||||||
func (t *TextEdit) Insert(contents string) {
|
func (t *TextEdit) Insert(contents string) {
|
||||||
|
t.Dirty = true
|
||||||
|
|
||||||
if t.selectMode { // If there is a selection...
|
if t.selectMode { // If there is a selection...
|
||||||
// Go to and delete the selection
|
// Go to and delete the selection
|
||||||
t.Delete(true) // The parameter doesn't matter with selection
|
t.Delete(true) // The parameter doesn't matter with selection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user