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

Method handleOpenPrompt

app/src/processing/app/Base.java:1142–1211  ·  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

1140 * Prompt for a sketch to open, and open it in a new window.
1141 */
1142 public void handleOpenPrompt() {
1143 final StringList extensions = new StringList();
1144
1145 // Add support for pdez files
1146 extensions.append(SKETCH_BUNDLE_EXT);
1147
1148 // Add the extensions for each installed Mode
1149 for (Mode mode : getModeList()) {
1150 extensions.append(mode.getDefaultExtension());
1151 // not adding aux extensions b/c we're looking for the main
1152 }
1153
1154 final String prompt = Language.text("open");
1155
1156 if (Preferences.getBoolean("chooser.files.native")) { //$NON-NLS-1$
1157 // use the front-most window frame for placing file dialog
1158 FileDialog openDialog =
1159 new FileDialog(activeEditor, prompt, FileDialog.LOAD);
1160
1161 // Only show .pde files as eligible bachelors
1162 openDialog.setFilenameFilter((dir, name) -> {
1163 // confirmed to be working properly [fry 110128]
1164 for (String ext : extensions) {
1165 if (name.toLowerCase().endsWith("." + ext)) { //$NON-NLS-1$
1166 return true;
1167 }
1168 }
1169 return false;
1170 });
1171
1172 openDialog.setVisible(true);
1173
1174 String directory = openDialog.getDirectory();
1175 String filename = openDialog.getFile();
1176 if (filename != null) {
1177 File inputFile = new File(directory, filename);
1178 handleOpen(inputFile.getAbsolutePath());
1179 }
1180
1181 } else {
1182 if (openChooser == null) {
1183 openChooser = new JFileChooser();
1184 openChooser.setDialogTitle(prompt);
1185 }
1186
1187 openChooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
1188 public boolean accept(File file) {
1189 // JFileChooser requires you to explicitly say yes to directories
1190 // as well (unlike the AWT chooser). Useful, but... different.
1191 // https://github.com/processing/processing/issues/1189
1192 if (file.isDirectory()) {
1193 return true;
1194 }
1195 for (String ext : extensions) {
1196 if (file.getName().toLowerCase().endsWith("." + ext)) { //$NON-NLS-1$
1197 return true;
1198 }
1199 }

Callers 3

initDefaultFileMenuMethod · 0.95
rebuildToolbarMenuMethod · 0.80
buildFileMenuMethod · 0.80

Calls 8

appendMethod · 0.95
getModeListMethod · 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