Skip to content

Commit e34b864

Browse files
committed
try associating .pyde files with the PDE
1 parent 86f6bb1 commit e34b864

1 file changed

Lines changed: 23 additions & 19 deletions

File tree

app/src/processing/app/platform/WindowsPlatform.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
public class WindowsPlatform extends DefaultPlatform {
5050

5151
static final String APP_NAME = "Processing";
52+
static final String[] APP_EXTENSIONS = { ".pde", ".pyde" };
5253
static final String REG_OPEN_COMMAND =
5354
System.getProperty("user.dir").replace('/', '\\') +
5455
"\\" + APP_NAME.toLowerCase() + ".exe \"%1\"";
@@ -192,33 +193,36 @@ protected void setAssociations() throws UnsupportedEncodingException {
192193
openCommand)) {
193194
*/
194195

196+
// First create the .pde association
197+
for (String extension : APP_EXTENSIONS) {
198+
if (!registerExtension(extension)) {
199+
Messages.log("Could not associate " + extension + "files, " +
200+
"turning off auto-associate pref.");
201+
Preferences.setBoolean("platform.auto_file_type_associations", false);
202+
}
203+
}
204+
}
205+
206+
207+
private boolean registerExtension(String extension) throws UnsupportedEncodingException {
195208
// "To change the settings for the interactive user, store the changes
196209
// under HKEY_CURRENT_USER\Software\Classes rather than HKEY_CLASSES_ROOT."
197210
// msdn.microsoft.com/en-us/library/windows/desktop/ms724475(v=vs.85).aspx
198211
final REGISTRY_ROOT_KEY rootKey = REGISTRY_ROOT_KEY.CURRENT_USER;
199212
final String docPrefix = "Software\\Classes\\" + REG_DOC;
200213

201-
// First create the .pde association
202-
if (WindowsRegistry.createKey(rootKey, "Software\\Classes", ".pde") &&
203-
WindowsRegistry.setStringValue(rootKey, "Software\\Classes\\.pde", "", REG_DOC) &&
204-
205-
// Now give files with a .pde extension a name for the explorer
206-
WindowsRegistry.createKey(rootKey, "Software\\Classes", REG_DOC) &&
207-
WindowsRegistry.setStringValue(rootKey, docPrefix, "", APP_NAME + " Source Code") &&
208-
209-
// Now associate the 'open' command with the current processing.exe
210-
WindowsRegistry.createKey(rootKey, docPrefix, "shell") &&
211-
WindowsRegistry.createKey(rootKey, docPrefix + "\\shell", "open") &&
212-
WindowsRegistry.createKey(rootKey, docPrefix + "\\shell\\open", "command") &&
213-
WindowsRegistry.setStringValue(rootKey, docPrefix + "\\shell\\open\\command", "", REG_OPEN_COMMAND)) {
214+
return (WindowsRegistry.createKey(rootKey, "Software\\Classes", extension) &&
215+
WindowsRegistry.setStringValue(rootKey, "Software\\Classes\\" + extension, "", REG_DOC) &&
214216

215-
// everything ok
216-
// hooray!
217+
// Now give files with a .pde extension a name for the explorer
218+
WindowsRegistry.createKey(rootKey, "Software\\Classes", REG_DOC) &&
219+
WindowsRegistry.setStringValue(rootKey, docPrefix, "", APP_NAME + " Source Code") &&
217220

218-
} else {
219-
Messages.log("Could not associate files, turning off auto-associate pref.");
220-
Preferences.setBoolean("platform.auto_file_type_associations", false);
221-
}
221+
// Now associate the 'open' command with the current processing.exe
222+
WindowsRegistry.createKey(rootKey, docPrefix, "shell") &&
223+
WindowsRegistry.createKey(rootKey, docPrefix + "\\shell", "open") &&
224+
WindowsRegistry.createKey(rootKey, docPrefix + "\\shell\\open", "command") &&
225+
WindowsRegistry.setStringValue(rootKey, docPrefix + "\\shell\\open\\command", "", REG_OPEN_COMMAND));
222226
}
223227

224228

0 commit comments

Comments
 (0)