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

Method handleOpenPrompt

app/src/processing/app/Base.java:1229–1296  ·  view source on GitHub ↗

Prompt for a sketch to open, and open it in a new window.

()

Source from the content-addressed store, hash-verified

1227 * Prompt for a sketch to open, and open it in a new window.
1228 */
1229 public void handleOpenPrompt() {
1230 final StringList extensions = new StringList();
1231 for (Mode mode : getModeList()) {
1232 extensions.append(mode.getDefaultExtension());
1233 }
1234
1235
1236 final String prompt = Language.text("open");
1237
1238 // don't use native dialogs on Linux (or anyone else w/ override)
1239 if (Preferences.getBoolean("chooser.files.native")) { //$NON-NLS-1$
1240 // use the front-most window frame for placing file dialog
1241 FileDialog openDialog =
1242 new FileDialog(activeEditor, prompt, FileDialog.LOAD);
1243
1244 // Only show .pde files as eligible bachelors
1245 openDialog.setFilenameFilter(new FilenameFilter() {
1246 public boolean accept(File dir, String name) {
1247 // confirmed to be working properly [fry 110128]
1248 for (String ext : extensions) {
1249 if (name.toLowerCase().endsWith("." + ext)) { //$NON-NLS-1$
1250 return true;
1251 }
1252 }
1253 return false;
1254 }
1255 });
1256
1257 openDialog.setVisible(true);
1258
1259 String directory = openDialog.getDirectory();
1260 String filename = openDialog.getFile();
1261 if (filename != null) {
1262 File inputFile = new File(directory, filename);
1263 handleOpen(inputFile.getAbsolutePath());
1264 }
1265
1266 } else {
1267 if (openChooser == null) {
1268 openChooser = new JFileChooser();
1269 }
1270 openChooser.setDialogTitle(prompt);
1271
1272 openChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
1273 public boolean accept(File file) {
1274 // JFileChooser requires you to explicitly say yes to directories
1275 // as well (unlike the AWT chooser). Useful, but... different.
1276 // http://code.google.com/p/processing/issues/detail?id=1151
1277 if (file.isDirectory()) {
1278 return true;
1279 }
1280 for (String ext : extensions) {
1281 if (file.getName().toLowerCase().endsWith("." + ext)) { //$NON-NLS-1$
1282 return true;
1283 }
1284 }
1285 return false;
1286 }

Callers 3

actionPerformedMethod · 0.80
actionPerformedMethod · 0.80
actionPerformedMethod · 0.80

Calls 8

getModeListMethod · 0.95
appendMethod · 0.95
textMethod · 0.95
getBooleanMethod · 0.95
handleOpenMethod · 0.95
getFileMethod · 0.80
setVisibleMethod · 0.65
getDefaultExtensionMethod · 0.45

Tested by

no test coverage detected