From e733a0b652d4d86df1892416507055dfc2b543c3 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Tue, 2 Aug 2022 22:15:09 -0400 Subject: [PATCH] add naming options as preference --- app/src/processing/app/SketchName.java | 44 ++++++++++++++----- .../processing/app/ui/PreferencesFrame.java | 15 +++++++ build/shared/lib/defaults.txt | 3 ++ build/shared/lib/languages/PDE.properties | 1 + build/shared/lib/naming.json | 4 +- todo.txt | 20 ++++----- 6 files changed, 65 insertions(+), 22 deletions(-) diff --git a/app/src/processing/app/SketchName.java b/app/src/processing/app/SketchName.java index 930a967c9..6f519250b 100644 --- a/app/src/processing/app/SketchName.java +++ b/app/src/processing/app/SketchName.java @@ -15,6 +15,7 @@ import java.util.Map; public class SketchName { + static final String CLASSIC_NAME = "Classic (sketch_220809a)"; static boolean breakTime = false; static Map wordLists; @@ -29,8 +30,15 @@ public class SketchName { * @return File object for safe new path, or null if there were problems */ static File nextFolder(File parentDir) { - //return classicFolder(parentDir); - return wordsFolder(parentDir); + String approach = Preferences.get("sketch.name.approach"); + if (!approach.equals(CLASSIC_NAME)) { + File folder = wordsFolder(parentDir, approach); + if (folder != null) { + return folder; + } + } + // classic was selected, or fallback due to an error + return classicFolder(parentDir); } @@ -106,7 +114,19 @@ public class SketchName { } - static File wordsFolder(File parentDir) { + static File wordsFolder(File parentDir, String setName) { + WordList wl = getWordLists().get(setName); + File outgoing = null; + if (wl != null) { + do { + outgoing = new File(parentDir, wl.getPair()); + } while (outgoing.exists()); + } + return outgoing; + } + + + static Map getWordLists() { if (wordLists == null) { wordLists = new HashMap<>(); try { @@ -121,12 +141,16 @@ public class SketchName { Messages.showWarning("Naming Error", "Could not load word lists from naming.json", e); } } - final String setName = "Cooking"; - WordList wl = wordLists.get(setName); - File outgoing; - do { - outgoing = new File(parentDir, wl.getPair()); - } while (outgoing.exists()); - return outgoing; + return wordLists; + } + + + static public String[] getOptions() { + StringList outgoing = new StringList(); + outgoing.append(CLASSIC_NAME); + for (String approach : getWordLists().keySet()) { + outgoing.append(approach); + } + return outgoing.array(); } } \ No newline at end of file diff --git a/app/src/processing/app/ui/PreferencesFrame.java b/app/src/processing/app/ui/PreferencesFrame.java index 8614948fd..146c2045f 100644 --- a/app/src/processing/app/ui/PreferencesFrame.java +++ b/app/src/processing/app/ui/PreferencesFrame.java @@ -37,6 +37,7 @@ import processing.app.Language; import processing.app.Messages; import processing.app.Platform; import processing.app.Preferences; +import processing.app.SketchName; import processing.awt.ShimAWT; import processing.core.*; @@ -53,6 +54,8 @@ public class PreferencesFrame { static final Integer[] FONT_SIZES = { 10, 12, 14, 18, 24, 36, 48 }; JTextField sketchbookLocationField; + JComboBox namingSelectionBox; + JTextField presentColor; //JCheckBox editorAntialiasBox; // JCheckBox deletePreviousBox; @@ -144,6 +147,12 @@ public class PreferencesFrame { ); + // Sketch Naming: [ Classic (sketch_220822a) ] + + JLabel namingLabel = new JLabel(Language.text("preferences.sketch_naming")); + namingSelectionBox = new JComboBox<>(SketchName.getOptions()); + + // Language: [ English ] (requires restart of Processing) JLabel languageLabel = new JLabel(Language.text("preferences.language")); @@ -460,6 +469,8 @@ public class PreferencesFrame { addRow(axis, sketchbookLocationLabel, sketchbookLocationField); + addRow(axis, namingLabel, namingSelectionBox); + // JPanel layoutPanel = new JPanel(); @@ -663,6 +674,8 @@ public class PreferencesFrame { base.setSketchbookFolder(new File(newPath)); } + Preferences.set("sketch.name.approach", (String) namingSelectionBox.getSelectedItem()); + // setBoolean("editor.external", externalEditorBox.isSelected()); Preferences.setBoolean("update.check", checkUpdatesBox.isSelected()); //$NON-NLS-1$ @@ -802,6 +815,8 @@ public class PreferencesFrame { // deletePreviousBox.setSelected(Preferences.getBoolean("export.delete_target_folder")); //$NON-NLS-1$ sketchbookLocationField.setText(Preferences.getSketchbookPath()); + namingSelectionBox.setSelectedItem(Preferences.get("sketch.name.approach")); + checkUpdatesBox.setSelected(Preferences.getBoolean("update.check")); //$NON-NLS-1$ defaultDisplayNum = updateDisplayList(); diff --git a/build/shared/lib/defaults.txt b/build/shared/lib/defaults.txt index dfaacb7d2..dc1e8b9be 100644 --- a/build/shared/lib/defaults.txt +++ b/build/shared/lib/defaults.txt @@ -231,6 +231,9 @@ editor.untitled.suffix=yyMMdd # replace underscores in .pde file names with spaces sketch.name.replace_underscore = true +# what to use for generating sketch names (change in the prefs window) +#sketch.name.approach = + # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/build/shared/lib/languages/PDE.properties b/build/shared/lib/languages/PDE.properties index 7e02b132f..300f35a07 100644 --- a/build/shared/lib/languages/PDE.properties +++ b/build/shared/lib/languages/PDE.properties @@ -193,6 +193,7 @@ preferences.button.width = 80 preferences.restart_required = Restart Processing to apply changes preferences.sketchbook_location = Sketchbook folder preferences.sketchbook_location.popup = Sketchbook folder +preferences.sketch_naming = Sketch name preferences.language = Language: preferences.editor_and_console_font = Editor and Console font: preferences.editor_and_console_font.tip = Select the font used in the Editor and the Console.
Only monospaced (fixed-width) fonts may be used,
though the list may be imperfect. diff --git a/build/shared/lib/naming.json b/build/shared/lib/naming.json index 6634d708a..032ab6c43 100644 --- a/build/shared/lib/naming.json +++ b/build/shared/lib/naming.json @@ -1,6 +1,6 @@ [ { - "name": "\"Friendly\" Names", + "name": "“Friendly” Names", "notes": "From https://github.com/glitchdotcom/friendly-words as of 2022-08-02", "prefixes": [ "aback", @@ -4522,7 +4522,7 @@ ] }, { - "name": "Cooking", + "name": "Cooking with Paul", "notes": "Developed by Paul Cronan of Fathom Information Design (https://fathom.info)", "prefixes": [ "cooking", diff --git a/todo.txt b/todo.txt index 7029ddabd..fd872dff0 100755 --- a/todo.txt +++ b/todo.txt @@ -29,6 +29,16 @@ X close the interface issue, major changes done X remove underscore and use (half?) space for tabs? X half space character not implemented, but the space looks good X disable behavior with sketch.name.replace_underscore = false +X add other naming options (cooking and classic) and prefs +X "friendly" naming for sketches +X master list of words +X https://github.com/glitchdotcom/friendly-words/tree/master/words +X exact sources +X https://github.com/glitchdotcom/friendly-words/blob/master/words/predicates.txt +X https://github.com/glitchdotcom/friendly-words/blob/master/words/objects.txt +X how friendly names are used in the p5.js web editor +X https://github.com/processing/p5.js-web-editor/blob/develop/client/utils/generateRandomName.js +X p5.js uses predicate followed by an object bugs X re-post bugzilla entries at https://download.processing.org/bugzilla/ @@ -334,7 +344,6 @@ X re-save svg files using svg 1.0 X sort out hover/press states here (only hovers atm) X also add state for shift-click to search _ theme colors for emoji buttons (new themes across the board) -_ naming options? _ reset the theme because of significant changes _ move away from writing theme.txt? _ instead store the theme name, for easier updating @@ -372,15 +381,6 @@ _ Base.checkSketchFolder() is used to identify sketches for the sketchbook frame _ but it assumes that it's folder name + default extension as the name for it _ that should be moved into the Mode class as a "is this folder a sketch" call _ (so that Modes can work differently too) -_ "friendly" naming for sketches -_ master list of words -_ https://github.com/glitchdotcom/friendly-words/tree/master/words -_ exact sources -_ https://github.com/glitchdotcom/friendly-words/blob/master/words/predicates.txt -_ https://github.com/glitchdotcom/friendly-words/blob/master/words/objects.txt -_ how friendly names are used in the p5.js web editor -_ https://github.com/processing/p5.js-web-editor/blob/develop/client/utils/generateRandomName.js -_ p5.js uses predicate followed by an object detach sketch names