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

Method pasteFiles

filetree/copypaste.go:179–279  ·  view source on GitHub ↗

pasteFiles applies a paste / drop of mime data onto this node. always does a copy of files into / onto target. externalDrop is true if this is an externally generated Drop event (from OS)

(md mimedata.Mimes, externalDrop bool, dropFinal func())

Source from the content-addressed store, hash-verified

177// always does a copy of files into / onto target.
178// externalDrop is true if this is an externally generated Drop event (from OS)
179func (fn *Node) pasteFiles(md mimedata.Mimes, externalDrop bool, dropFinal func()) {
180 if len(md) == 0 {
181 return
182 }
183 if fn == nil || fn.isExternal() {
184 return
185 }
186
187 tpath := string(fn.Filepath)
188 isdir := fn.IsDir()
189 if isdir {
190 fn.pasteCopyFilesCheck(fn, md, externalDrop, dropFinal)
191 return
192 }
193 if len(md) > 3 { // multiple files -- automatically goes into parent dir
194 tdir := AsNode(fn.Parent)
195 fn.pasteCopyFilesCheck(tdir, md, externalDrop, dropFinal)
196 return
197 }
198 // single file dropped onto a single target file
199 srcpath := ""
200 if externalDrop || len(md) < 2 {
201 srcpath = string(md[0].Data) // just file path
202 } else {
203 srcpath = string(md[1].Data) // 1 has file path, 0 = tree path, 2 = file data
204 }
205 fname := filepath.Base(srcpath)
206 tdir := AsNode(fn.Parent)
207 existing, sfn := fn.pasteCheckExisting(tdir, md, externalDrop)
208 mode := os.FileMode(0664)
209 if sfn != nil {
210 mode = sfn.Info.Mode
211 }
212 switch {
213 case len(existing) == 1 && fname == fn.Name:
214 d := core.NewBody().AddTitle("Overwrite?").
215 AddText(fmt.Sprintf("Overwrite target file: %s with source file of same name?, or diff (compare) two files?", fn.Name))
216 d.AddBottomBar(func(parent core.Widget) {
217 d.AddCancel(parent)
218 d.AddOK(parent).SetText("Diff (compare)").OnClick(func(e events.Event) {
219 texteditor.DiffFiles(fn, tpath, srcpath)
220 })
221 d.AddOK(parent).SetText("Overwrite").OnClick(func(e events.Event) {
222 fileinfo.CopyFile(tpath, srcpath, mode)
223 if dropFinal != nil {
224 dropFinal()
225 }
226 })
227 })
228 d.RunDialog(fn)
229 case len(existing) > 0:
230 d := core.NewBody().AddTitle("Overwrite?").
231 AddText(fmt.Sprintf("Overwrite target file: %s with source file: %s, or overwrite existing file with same name as source file (%s), or diff (compare) files?", fn.Name, fname, fname))
232 d.AddBottomBar(func(parent core.Widget) {
233 d.AddCancel(parent)
234 d.AddOK(parent).SetText("Diff to target").OnClick(func(e events.Event) {
235 texteditor.DiffFiles(fn, tpath, srcpath)
236 })

Callers 2

PasteMethod · 0.95
DragDropMethod · 0.95

Calls 15

isExternalMethod · 0.95
IsDirMethod · 0.95
pasteCopyFilesCheckMethod · 0.95
pasteCheckExistingMethod · 0.95
NewBodyFunction · 0.92
DiffFilesFunction · 0.92
CopyFileFunction · 0.92
AddTextMethod · 0.80
AddTitleMethod · 0.80
AddBottomBarMethod · 0.80
AddCancelMethod · 0.80
AddOKMethod · 0.80

Tested by

no test coverage detected