diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index c3d6382f59..61c4c2b9ce 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1210,7 +1210,7 @@ public void handleAddFile() { if (result) { // editor.statusNotice("One file added to the sketch."); - //Done from within TaskAddFile inner class when copying is completed + //Done from within TaskAddFile inner class when copying is completed } } @@ -1720,6 +1720,43 @@ static final boolean asciiLetter(char c) { static public String sanitizeName(String origName) { char orig[] = origName.toCharArray(); StringBuilder sb = new StringBuilder(); + boolean keywordFlag = false; + + // Opening the reservedKeywords.txt file to be check if the 'origName' + // is a 'Reserved Keyword' in Processing or class Name or primitive. + String keywordFileName = "lib/reservedKeywords.txt"; + File keywordFile = new File(keywordFileName); + + try { + FileReader fileReader = new FileReader(keywordFile); + BufferedReader bufferedReader = new BufferedReader(fileReader); + + String keyword; + + while ((keyword = bufferedReader.readLine()) != null) { + + if (origName.equalsIgnoreCase(keyword) == true) { + keywordFlag = true; + break; + } + } + } + catch (FileNotFoundException ex) { + System.out.println("File not found!"); + } + catch(IOException ex) { + System.out.println("IOException"); + } + + // If 'origName' is found in the 'reservedKeywords.txt' file + // Pop up a Warning message + if (keywordFlag == true) { + Messages.showWarning(Language.text("check_name.messages.is_reserved_keyword"), + Language.interpolate("check_name.messages.is_reserved_keyword.description", origName)); + return "bad_sketch_name_please_fix"; + } + + // Can't lead with a digit (or anything besides a letter), so prefix with // "sketch_". In 1.x this prefixed with an underscore, but those get shaved diff --git a/build/shared/lib/languages/PDE.properties b/build/shared/lib/languages/PDE.properties index 52fb6aeed4..eaf7d51d7a 100644 --- a/build/shared/lib/languages/PDE.properties +++ b/build/shared/lib/languages/PDE.properties @@ -439,6 +439,8 @@ ensure_exist.messages.unrecoverable.description = Could not properly re-save the # Check name check_name.messages.is_name_modified = The sketch name had to be modified. Sketch names can only consist\nof ASCII characters and numbers (but cannot start with a number).\nThey should also be less than 64 characters long. +check_name.messages.is_reserved_keyword = Invalid name +check_name.messages.is_reserved_keyword.description = Name '%s' is a not allowed(reserved keyword), \nplease 'Save As' with another name. # --------------------------------------- # Contributions diff --git a/build/shared/lib/reservedKeywords.txt b/build/shared/lib/reservedKeywords.txt new file mode 100644 index 0000000000..dc8df3cfd9 --- /dev/null +++ b/build/shared/lib/reservedKeywords.txt @@ -0,0 +1,487 @@ +/* THIS FILE CONTAINS ALL THE RESERVED KEYWORDS IN JAVA AND PROCESSING LANGUAGE */ +/* THESE KEYWORDS CANNOT BE USED AS SKETCH NAME! */ +/* THIS FILE WAS CREATED AS A RESOLUTION TO ISSUES #196 */ + + + + +/*Reserved Keywords in Java Language*/ +abstract +continue +for +new +switch +assert +default +goto +package +synchronized +boolean +do +if +private +this +break +double +implements +protected +throw +byte +else +import +public +throws +case +enum +instanceof +return +transient +catch +extends +int +short +try +char +final +interface +static +void +class +finally +long +strictfp +volatile +const +float +native +super +while + + +/*Reserved Keywords in Processing Languages*/ + + + +TextAreaPainter +Highlight +Texture +Parameters +BufferData +DetailPanel +JSONObject +Null +JSONException +JSONTokener +Editor +FileDropHandler +UpdatableAction +CutAction +CopyAction +CopyAsHtmlAction +PasteAction +UndoAction +RedoAction +FindNextAction +FindPreviousAction +SelectionForFindAction +TextAreaPopup +LineID +IgnorableException +ImageOutputStreamAdapter +Splasher +SplashWindow +MouseEvent +PGraphicsPDF +DefaultPlatform +CLibrary +StringList +KeywordMap +Keyword +PdeInputHandler +MessageConsumer +CompositeTransferable +MessageStream +JavaToolbar +XML +XQPreprocessor +XQVisitor +VMEventListener +EditorConsole +EditorConsoleStream +BufferedStyledDocument +CompletionPanel +CompletionScrollBarUI +CustomListRenderer +FindReplace +SketchParser +Range +MarkerColumn +Client +SingleInstance +JavaTextArea +MouseHandler +TweakClient +Mode +EditorToolbar +ModeSelector +JavaMode +RPI +PApplet +RendererChangeException +RegisteredMethods +InternalEventQueue +AsyncImageLoader +WriteSVG +CreateFont +SampleComponent +CharacterSelector +CheckBoxList +CellRenderer +LinuxPlatform +NonRepeatable +NonRecordable +Wrapper +MacroRecorder +backspace +delete +delete_word +end +document_end +home +document_home +insert_break +toggle_rect +clipboard_cut +clipboard_copy +clipboard_paste +WebServer +WebServerWorker +HttpConstants +ProcessingTestUtil +Settings +OffsetMatcher +OffsetPair +StringTransferable +ManagerFrame +SpacedTabbedPaneUI +SketchOutline +CustomCellRenderer +Util +ProcessResult +ColorMode +Table +RowPointer +RowIterator +RowIndexIterator +HashMapBlows +HashMapSucks +Runner +JavaInputHandler +BundleDocument +LineStroker +PVector +Sketch +EditorFooter +Controller +Tab +ColorControlBox +ContribProgressBar +Test +FocusHandler +MouseHandler +CaretUndo +MP3ElementaryInputStream +Frame +MacPlatform +PGraphicsSVG +MP3AudioInputStream +ImportStatement +ColorScheme +Library +PGraphics3D +PFont +Glyph +StatusPanel +HtmlSelection +GPIO +EditorException +EditorException +JAppleMenuBar +ProcessHelper +Preferences +EditorStatus +Welcome +IntDict +Commander +PdePreprocessor +PSurfaceJOGL +DrawListener +NEWTWindowListener +NEWTMouseListener +NEWTKeyListener +CursorInfo +Contribution +Filter +UpdateCheck +AvailableContribution +AppBundlerTask +ErrorCheckerService +CodeCheckResult +ColorSelector +ColorSelectorBox +ColorSelectorSlider +SelectorTopBar +UpdateStatusPanel +Compiler +CompositionTextPainter +About +UTCompiler +ToolContribution +AutoFormatTests +Toolkit +SketchReference +JSONTokener +TokenUtil +ChangeDetector +PropertyLister +PMatrix3D +IntList +VMEventReader +LinePath +PathIterator +PGraphics +AsyncImageSaver +TouchEvent +DataAtomOutputStream +FontTexture +TextureInfo +Event +FloatDict +KeyIterator +InternalSort +PSurfaceFX +ResizableCanvas +PApplicationFX +ContribHeaderRenderer +ContribStatusRenderer +ContribTableModel +VariableInspector +EditorFollower +VariableRowModel +OutlineRenderer +ValueCellRenderer +ValueCellEditor +ExpansionHandler +VariableNodeFilter +P5BuiltinsFilter +ThisFilter +LocalHidesThisFilter +ClassLoadListener +LED +LocalContribution +FloatList +PAppletMethods +Archiver +PSurfaceNone +AnimationThread +RawDXF +Handle +HandleComparator +StreamRedirectThread +PWM +CompilationChecker +CompilationUnitImpl +CompileRequestorImpl +NameEnvironmentImpl +CustomClassLoader +SampleComposite +JSONArray +TabOutline +Downloader +VariableNode +ContributionTab +FilterField +Debugger +HProgressBar +Problem +PreferencesFrame +FontNamer +LocalVariableNode +PStyle +PShapeOBJ +OBJFace +OBJMaterial +JavaBuild +PSurface +SPI +LineHighlight +MovieMaker +FormListener +SyntaxStyle +RunnerListener +AbstractTransferable +ContributionListing +ChangeListener +PdeKeywords +WindowsPlatform +ShellAPI +WinLibC +HANDLE +HWND +Shell32 +InstallCommander +PShape +PGL +Tessellator +TessellatorCallback +FontOutline +PGraphicsOpenGL +GLResourceTexture +GLResourceVertexBuffer +GLResourceShader +GLResourceFrameBuffer +AsyncPixelReader +AttributeMap +VertexAttribute +TexCache +IndexCache +InGeometry +TessGeometry +Tessellator +TessellatorCallback +DepthSorter +Architecture +PJOGL +Tessellator +GLUCallback +FontOutline +PShapeSVG +Gradient +LinearGradient +RadialGradient +Font +FontFace +FontGlyph +ContributionManager +PGraphicsFX2D +ImageCache +FontInfo +FontCache +Key +Base +ModeInfo +SeekableByteArrayOutputStream +Brackets +PShapeJava2D +LinearGradientPaint +LinearGradientContext +RadialGradientPaint +RadialGradientContext +Messages +ExamplesFrame +VertexBuffer +NativeInterface +TextAreaDefaults +EditorState +LineProcessor +SurfaceInfo +ASTGenerator +ClassMember +Chooser +Callback +PSurfaceAWT +SmoothCanvas +LineMarker +Tool +ArrayFieldNode +PShader +UniformValue +Formatter +Language +UTF8Control +LanguageBundle +PGraphicsJava2D +BlendingContext +ImageCache +ParserTests +WindowsRegistry +Option +QuickTimeWriter +Edit +Track +VideoTrack +AudioTrack +Sample +Group +TimeToSampleGroup +SampleSizeGroup +Chunk +Atom +CompositeAtom +DataAtom +WideDataAtom +TableRow +ContribProgressMonitor +BaseSplash +MessageSiphon +PGraphics2D +ExamplesContribution +ThinkDifferent +I2C +AutoFormat +PShapeOpenGL +FieldNode +EditorHeader +Tab +FrameBuffer +Platform +StringDict +CompletionCandidate +PMatrix2D +ErrorMessageSimplifier +ManagerTabs +Controller +Tab +ProcessRegistry +FileTextFieldTransferHandler +PdeEmitter +WebFrame +Sort +ErrorTable +Entry +GradyHeaderRenderer +GradyRowRenderer +UpdateContributionTab +PreprocessorResult +UpdateListPanel +Recent +Record +ColorChooser +ColorListener +ColorRange +ColorSlider +NumberField +NumberDocument +AppleRLEEncoder +KeyEvent +PImage +ASTNodeWrapper +SystemOutSiphon +Token +PlainTextTransferable +CompositionTextManager +JavaEditor +ColorPreference +PConstants +SketchCode +SketchbookFrame +ModeContribution +LineBreakpoint +not +Argument +PMatrix +PdeTextAreaDefaults +StreamPump +WriterLineProcessor +SketchException +Server