MCPcopy Create free account
hub / github.com/cogentcore/core / FileModCheck

Method FileModCheck

texteditor/buffer.go:297–331  ·  view source on GitHub ↗

FileModCheck checks if the underlying file has been modified since last Stat (open, save); if haven't yet prompted, user is prompted to ensure that this is OK. It returns true if the file was modified.

()

Source from the content-addressed store, hash-verified

295// Stat (open, save); if haven't yet prompted, user is prompted to ensure
296// that this is OK. It returns true if the file was modified.
297func (tb *Buffer) FileModCheck() bool {
298 if tb.fileModOK {
299 return false
300 }
301 info, err := os.Stat(string(tb.Filename))
302 if err != nil {
303 return false
304 }
305 if info.ModTime() != time.Time(tb.Info.ModTime) {
306 if !tb.IsNotSaved() { // we haven't edited: just revert
307 tb.Revert()
308 return true
309 }
310 sc := tb.sceneFromEditor()
311 d := core.NewBody().AddTitle("File changed on disk: " + fsx.DirAndFile(string(tb.Filename))).
312 AddText(fmt.Sprintf("File has changed on disk since being opened or saved by you; what do you want to do? If you <code>Revert from Disk</code>, you will lose any existing edits in open buffer. If you <code>Ignore and Proceed</code>, the next save will overwrite the changed file on disk, losing any changes there. File: %v", tb.Filename))
313 d.AddBottomBar(func(parent core.Widget) {
314 core.NewButton(parent).SetText("Save as to different file").OnClick(func(e events.Event) {
315 d.Close()
316 core.CallFunc(sc, tb.SaveAs)
317 })
318 core.NewButton(parent).SetText("Revert from disk").OnClick(func(e events.Event) {
319 d.Close()
320 tb.Revert()
321 })
322 core.NewButton(parent).SetText("Ignore and proceed").OnClick(func(e events.Event) {
323 d.Close()
324 tb.fileModOK = true
325 })
326 })
327 d.RunDialog(sc)
328 return true
329 }
330 return false
331}
332
333// Open loads the given file into the buffer.
334func (tb *Buffer) Open(filename core.Filename) error { //types:add

Callers 4

DeleteTextMethod · 0.95
deleteTextRectMethod · 0.95
insertTextMethod · 0.95
insertTextRectMethod · 0.95

Calls 15

IsNotSavedMethod · 0.95
RevertMethod · 0.95
sceneFromEditorMethod · 0.95
NewBodyFunction · 0.92
DirAndFileFunction · 0.92
NewButtonFunction · 0.92
CallFuncFunction · 0.92
ModTimeMethod · 0.80
AddTextMethod · 0.80
AddTitleMethod · 0.80
AddBottomBarMethod · 0.80
RunDialogMethod · 0.80

Tested by

no test coverage detected