MCPcopy Index your code
hub / github.com/benfry/processing4 / importData

Method importData

app/src/processing/app/ui/Editor.java:386–437  ·  view source on GitHub ↗
(TransferHandler.TransferSupport support)

Source from the content-addressed store, hash-verified

384 }
385
386 public boolean importData(TransferHandler.TransferSupport support) {
387 int successful = 0;
388
389 if (!canImport(support)) {
390 return false;
391 }
392
393 try {
394 Transferable transferable = support.getTransferable();
395 DataFlavor uriListFlavor =
396 new DataFlavor("text/uri-list;class=java.lang.String");
397
398 if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
399 List<?> list = (List<?>)
400 transferable.getTransferData(DataFlavor.javaFileListFlavor);
401 for (Object o : list) {
402 File file = (File) o;
403 if (sketch.addFile(file)) {
404 successful++;
405 }
406 }
407 } else if (transferable.isDataFlavorSupported(uriListFlavor)) {
408 // Some platforms (Mac OS X and Linux, when this began) preferred
409 // this method of moving files.
410 String data = (String)transferable.getTransferData(uriListFlavor);
411 String[] pieces = PApplet.splitTokens(data, "\r\n");
412 for (String piece : pieces) {
413 if (piece.startsWith("#")) continue;
414
415 String path = null;
416 if (piece.startsWith("file:///")) {
417 path = piece.substring(7);
418 } else if (piece.startsWith("file:/")) {
419 path = piece.substring(5);
420 }
421 if (path != null) {
422 if (sketch.addFile(new File(path))) {
423 successful++;
424 }
425 } else {
426 System.err.println("Path not found for: " + data);
427 }
428 }
429 }
430 } catch (Exception e) {
431 Messages.showWarning("Drag & Drop Problem",
432 "An error occurred while trying to add files to the sketch.", e);
433 return false;
434 }
435 statusNotice(Language.pluralize("editor.status.drag_and_drop.files_added", successful));
436 return true;
437 }
438 }
439
440

Callers

nothing calls this directly

Calls 9

canImportMethod · 0.95
splitTokensMethod · 0.95
showWarningMethod · 0.95
pluralizeMethod · 0.95
isDataFlavorSupportedMethod · 0.80
getTransferDataMethod · 0.80
addFileMethod · 0.80
statusNoticeMethod · 0.65
printlnMethod · 0.45

Tested by

no test coverage detected