MCPcopy Index your code
hub / github.com/processing/processing / handleOpenInternal

Method handleOpenInternal

app/src/processing/app/ui/Editor.java:2513–2600  ·  view source on GitHub ↗

Second stage of open, occurs after having checked to see if the modifications (if any) to the previous sketch need to be saved. Because this method is called in Editor's constructor, a subclass shouldn't rely on any of its variables being initialized already.

(String path)

Source from the content-addressed store, hash-verified

2511 * shouldn't rely on any of its variables being initialized already.
2512 */
2513 protected void handleOpenInternal(String path) throws EditorException {
2514 // check to make sure that this .pde file is
2515 // in a folder of the same name
2516 final File file = new File(path);
2517 final File parentFile = new File(file.getParent());
2518 final String parentName = parentFile.getName();
2519 final String defaultName = parentName + "." + mode.getDefaultExtension();
2520 final File altFile = new File(file.getParent(), defaultName);
2521
2522 if (defaultName.equals(file.getName())) {
2523 // no beef with this guy
2524 } else if (altFile.exists()) {
2525 // The user selected a source file from the same sketch,
2526 // but open the file with the default extension instead.
2527 path = altFile.getAbsolutePath();
2528 } else if (!mode.canEdit(file)) {
2529 final String modeName = mode.getTitle().equals("Java") ?
2530 "Processing" : (mode.getTitle() + " Mode");
2531 throw new EditorException(modeName + " can only open its own sketches\n" +
2532 "and other files ending in " +
2533 mode.getDefaultExtension());
2534 } else {
2535 final String properParent =
2536 file.getName().substring(0, file.getName().lastIndexOf('.'));
2537
2538 Object[] options = { Language.text("prompt.ok"), Language.text("prompt.cancel") };
2539 String prompt =
2540 "The file \"" + file.getName() + "\" needs to be inside\n" +
2541 "a sketch folder named \"" + properParent + "\".\n" +
2542 "Create this folder, move the file, and continue?";
2543
2544 int result = JOptionPane.showOptionDialog(this,
2545 prompt,
2546 "Moving",
2547 JOptionPane.YES_NO_OPTION,
2548 JOptionPane.QUESTION_MESSAGE,
2549 null,
2550 options,
2551 options[0]);
2552
2553 if (result == JOptionPane.YES_OPTION) {
2554 // create properly named folder
2555 File properFolder = new File(file.getParent(), properParent);
2556 if (properFolder.exists()) {
2557 throw new EditorException("A folder named \"" + properParent + "\" " +
2558 "already exists. Can't open sketch.");
2559 }
2560 if (!properFolder.mkdirs()) {
2561 throw new EditorException("Could not create the sketch folder.");
2562 }
2563 // copy the sketch inside
2564 File properPdeFile = new File(properFolder, file.getName());
2565 File origPdeFile = new File(path);
2566 try {
2567 Util.copyFile(origPdeFile, properPdeFile);
2568 } catch (IOException e) {
2569 throw new EditorException("Could not copy to a proper location.", e);
2570 }

Callers 1

EditorMethod · 0.95

Calls 12

textMethod · 0.95
copyFileMethod · 0.95
updateTitleMethod · 0.95
saveMethod · 0.95
canEditMethod · 0.80
deleteMethod · 0.80
getParentMethod · 0.45
getNameMethod · 0.45
getDefaultExtensionMethod · 0.45
equalsMethod · 0.45
getTitleMethod · 0.45
rebuildMethod · 0.45

Tested by

no test coverage detected