OpenBuf opens the file in its buffer if it is not already open. returns true if file is newly opened
()
| 450 | // OpenBuf opens the file in its buffer if it is not already open. |
| 451 | // returns true if file is newly opened |
| 452 | func (fn *Node) OpenBuf() (bool, error) { |
| 453 | if fn.IsDir() { |
| 454 | err := fmt.Errorf("filetree.Node cannot open directory in editor: %v", fn.Filepath) |
| 455 | log.Println(err) |
| 456 | return false, err |
| 457 | } |
| 458 | if fn.Buffer != nil { |
| 459 | if fn.Buffer.Filename == fn.Filepath { // close resets filename |
| 460 | return false, nil |
| 461 | } |
| 462 | } else { |
| 463 | fn.Buffer = texteditor.NewBuffer() |
| 464 | fn.Buffer.OnChange(func(e events.Event) { |
| 465 | if fn.Info.VCS == vcs.Stored { |
| 466 | fn.Info.VCS = vcs.Modified |
| 467 | } |
| 468 | }) |
| 469 | } |
| 470 | fn.Buffer.SetHighlighting(NodeHighlighting) |
| 471 | return true, fn.Buffer.Open(fn.Filepath) |
| 472 | } |
| 473 | |
| 474 | // removeFromExterns removes file from list of external files |
| 475 | func (fn *Node) removeFromExterns() { //types:add |