Internal function to actually open the sketch. At this point, the sketch file/folder must have been vetted, and nextMode set properly.
(String path, boolean untitled)
| 1607 | * sketch file/folder must have been vetted, and nextMode set properly. |
| 1608 | */ |
| 1609 | protected Editor handleOpenInternal(String path, boolean untitled) { |
| 1610 | try { |
| 1611 | try { |
| 1612 | EditorState state = EditorState.nextEditor(editors); |
| 1613 | Editor editor = nextMode.createEditor(this, path, state); |
| 1614 | |
| 1615 | // opened successfully, let's go to work |
| 1616 | editor.setUpdatesAvailable(updatesAvailable); |
| 1617 | editor.getSketch().setUntitled(untitled); |
| 1618 | editors.add(editor); |
| 1619 | Recent.append(editor); |
| 1620 | |
| 1621 | // now that we're ready, show the window |
| 1622 | // (don't do earlier, cuz we might move it based on a window being closed) |
| 1623 | editor.setVisible(true); |
| 1624 | |
| 1625 | return editor; |
| 1626 | |
| 1627 | } catch (EditorException ee) { |
| 1628 | if (ee.getMessage() != null) { // null if the user canceled |
| 1629 | Messages.showWarning("Error opening sketch", ee.getMessage(), ee); |
| 1630 | } |
| 1631 | } catch (NoSuchMethodError me) { |
| 1632 | Messages.showWarning("Mode out of date", |
| 1633 | nextMode.getTitle() + " is not compatible with this version of Processing.\n" + |
| 1634 | "Try updating the Mode or contact its author for a new version.", me); |
| 1635 | } catch (Throwable t) { |
| 1636 | if (nextMode.equals(getDefaultMode())) { |
| 1637 | Messages.showTrace("Serious Problem", |
| 1638 | "An unexpected, unknown, and unrecoverable error occurred\n" + |
| 1639 | "while opening a new editor window. Please report this.", t, true); |
| 1640 | } else { |
| 1641 | Messages.showTrace("Mode Problems", |
| 1642 | "A nasty error occurred while trying to use “" + nextMode.getTitle() + "”.\n" + |
| 1643 | "It may not be compatible with this version of Processing.\n" + |
| 1644 | "Try updating the Mode or contact its author for a new version.", t, false); |
| 1645 | } |
| 1646 | } |
| 1647 | if (editors.isEmpty()) { |
| 1648 | Mode defaultMode = getDefaultMode(); |
| 1649 | if (nextMode == defaultMode) { |
| 1650 | // unreachable? hopefully? |
| 1651 | Messages.showError("Editor Problems", """ |
| 1652 | An error occurred while trying to change modes. |
| 1653 | We'll have to quit for now because it's an |
| 1654 | unfortunate bit of indigestion with the default Mode. |
| 1655 | """, null); |
| 1656 | } else { |
| 1657 | // Don't leave the user hanging or the PDE locked up |
| 1658 | // https://github.com/processing/processing/issues/4467 |
| 1659 | if (untitled) { |
| 1660 | nextMode = defaultMode; |
| 1661 | handleNew(); |
| 1662 | return null; // ignored by any caller |
| 1663 | |
| 1664 | } else { |
| 1665 | // This null response will be kicked back to changeMode(), |
| 1666 | // signaling it to re-open the sketch in the default Mode. |
no test coverage detected