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.
()
| 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. |
| 297 | func (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. |
| 334 | func (tb *Buffer) Open(filename core.Filename) error { //types:add |
no test coverage detected