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

Method newFile

filetree/file.go:207–231  ·  view source on GitHub ↗

newFile makes a new file in this directory node

(filename string, addToVCS bool)

Source from the content-addressed store, hash-verified

205
206// newFile makes a new file in this directory node
207func (fn *Node) newFile(filename string, addToVCS bool) { //types:add
208 if fn.isExternal() {
209 return
210 }
211 ppath := string(fn.Filepath)
212 if !fn.IsDir() {
213 ppath, _ = filepath.Split(ppath)
214 }
215 np := filepath.Join(ppath, filename)
216 _, err := os.Create(np)
217 if err != nil {
218 core.ErrorSnackbar(fn, err)
219 return
220 }
221 if addToVCS {
222 nfn, ok := fn.FileRoot.FindFile(np)
223 if ok && nfn.This != fn.FileRoot.This && string(nfn.Filepath) == np {
224 // todo: this is where it is erroneously adding too many files to vcs!
225 fmt.Println("Adding new file to VCS:", nfn.Filepath)
226 core.MessageSnackbar(fn, "Adding new file to VCS: "+fsx.DirAndFile(string(nfn.Filepath)))
227 nfn.AddToVCS()
228 }
229 }
230 fn.FileRoot.UpdatePath(np)
231}
232
233// makes a new folder in the given selected directory
234func (fn *Node) newFolders(foldername string) { //types:add

Callers 1

newFilesMethod · 0.80

Calls 11

isExternalMethod · 0.95
IsDirMethod · 0.95
ErrorSnackbarFunction · 0.92
MessageSnackbarFunction · 0.92
DirAndFileFunction · 0.92
SplitMethod · 0.80
CreateMethod · 0.80
FindFileMethod · 0.80
PrintlnMethod · 0.80
AddToVCSMethod · 0.80
UpdatePathMethod · 0.80

Tested by

no test coverage detected