From f6e4b9f482e9f68e4c6e31230fbfe5616b99f371 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Sun, 7 Dec 2014 19:45:25 -0600 Subject: [PATCH 1/7] Initial plugin implementation for generating java ant projects. Generate buildfile from template, sans Processing library path. --- .gitignore | 1 + .../new_java_ant_project/build.xml.template | 55 ++++++++++++++++++ .../src/renameMe/Main.java.template | 13 +++++ .../src/renameMe/Sketch.java.template | 15 +++++ Default.sublime-commands | 6 ++ Main.sublime-menu | 21 +++++++ Processing.py | 57 +++++++++++++++++++ 7 files changed, 168 insertions(+) create mode 100644 Commands/templates/new_java_ant_project/build.xml.template create mode 100644 Commands/templates/new_java_ant_project/src/renameMe/Main.java.template create mode 100644 Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template create mode 100644 Default.sublime-commands create mode 100644 Main.sublime-menu create mode 100644 Processing.py diff --git a/.gitignore b/.gitignore index e815db8..f8bce47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .DS_Store *.cache +*.pyc \ No newline at end of file diff --git a/Commands/templates/new_java_ant_project/build.xml.template b/Commands/templates/new_java_ant_project/build.xml.template new file mode 100644 index 0000000..1646ece --- /dev/null +++ b/Commands/templates/new_java_ant_project/build.xml.template @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Commands/templates/new_java_ant_project/src/renameMe/Main.java.template b/Commands/templates/new_java_ant_project/src/renameMe/Main.java.template new file mode 100644 index 0000000..017791c --- /dev/null +++ b/Commands/templates/new_java_ant_project/src/renameMe/Main.java.template @@ -0,0 +1,13 @@ +package $package_name; + +import processing.core.*; + +class Main { + + private final static String[] OPTIONS = new String[] { "--present", "$package_name.Sketch" }; + + public static void main(String[] args) { + PApplet.main(OPTIONS); + } + +} diff --git a/Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template b/Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template new file mode 100644 index 0000000..4ac1981 --- /dev/null +++ b/Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template @@ -0,0 +1,15 @@ +package $package_name; + +import processing.core.*; + +public class Sketch extends PApplet { + + public void setup() { + + } + + public void draw() { + + } + +} \ No newline at end of file diff --git a/Default.sublime-commands b/Default.sublime-commands new file mode 100644 index 0000000..b9cd496 --- /dev/null +++ b/Default.sublime-commands @@ -0,0 +1,6 @@ +[ + { + "caption": "Processing: New Java Ant project", + "command": "new_java_ant_project" + } +] \ No newline at end of file diff --git a/Main.sublime-menu b/Main.sublime-menu new file mode 100644 index 0000000..19a6197 --- /dev/null +++ b/Main.sublime-menu @@ -0,0 +1,21 @@ +[ + { + "caption": "Tools", + "mnemonic": "T", + "id": "tools", + "children": + [ + { + "caption": "Processing", + "mnemonic": "P", + "id": "Processing", + "children": + [ + { "caption": "New Java Ant Project", "command": "new_java_ant_project"} + ] + } + ] + + } +] + diff --git a/Processing.py b/Processing.py new file mode 100644 index 0000000..5d8fb55 --- /dev/null +++ b/Processing.py @@ -0,0 +1,57 @@ +import sublime, sublime_plugin, sys, functools, os, re, string + +#from plugins.new_java_project import * + +PROJECT_TEMPLATE_PATH = os.path.abspath("Commands/templates/new_java_ant_project") +SOURCE_DIRECTORY_NAME = "src" +BUILDFILE_TEMPLATE_NAME = "build.xml.template" +GENERATED_BUILDFILE_NAME = "build.xml" + +class NewJavaAntProjectCommand(sublime_plugin.WindowCommand): + + def run(self): + # TODO: app command w/o window: create window, self.window.run_command("prompt_add_folder") + self.window.show_input_panel("Package Name:", + "com.foo.appname or simplepackagename", + functools.partial(self.generate_project), + None, None) + + def generate_project(self, package_name): + project_path = os.path.join(self.window.folders()[0], + SOURCE_DIRECTORY_NAME, + re.sub('\.', '/', package_name.lower())) + self.create_project_directories(project_path) + self.generate_files_from_template(PROJECT_TEMPLATE_PATH, + project_path, + package_name) + + def create_project_directories(self, path): + if not os.path.exists(path): + os.makedirs(path) + + def generate_files_from_template(self, template_path, project_path, package_name): + processing_library_path = self.determine_processing_library_path() + with open(os.path.join(template_path, BUILDFILE_TEMPLATE_NAME), 'r') as build_template: + template_contents = build_template.read() + template = string.Template(template_contents) + build_file_contents = template.substitute(processing_library_path = processing_library_path, + ant_project_name = package_name.split('.')[-1], + package_name = package_name) + with open(os.path.join(self.window.folders()[0], GENERATED_BUILDFILE_NAME), 'w') as buildfile: + buildfile.write(build_file_contents) + + def determine_processing_library_path(self): + return "TODO" + +#open_file(file, contents) + + +# class NewFolderCommand(sublime_plugin.WindowCommand): +# def run(self, dirs): +# self.window.show_input_panel("Folder Name:", "", functools.partial(self.on_done, dirs[0]), None, None) + +# def on_done(self, dir, name): +# os.makedirs(os.path.join(dir, name)) + +# def is_visible(self, dirs): +# return len(dirs) == 1 \ No newline at end of file From 2390f2e9dfa903d2df512216f9aa098499b5fe5e Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Sun, 7 Dec 2014 21:40:05 -0600 Subject: [PATCH 2/7] Complete generation of boilerplate Java files.Reorganize template files. Refactor implementation. --- .../{src/renameMe => }/Main.java.template | 0 .../{src/renameMe => }/Sketch.java.template | 0 Processing.py | 42 ++++++++++++------- 3 files changed, 26 insertions(+), 16 deletions(-) rename Commands/templates/new_java_ant_project/{src/renameMe => }/Main.java.template (100%) rename Commands/templates/new_java_ant_project/{src/renameMe => }/Sketch.java.template (100%) diff --git a/Commands/templates/new_java_ant_project/src/renameMe/Main.java.template b/Commands/templates/new_java_ant_project/Main.java.template similarity index 100% rename from Commands/templates/new_java_ant_project/src/renameMe/Main.java.template rename to Commands/templates/new_java_ant_project/Main.java.template diff --git a/Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template b/Commands/templates/new_java_ant_project/Sketch.java.template similarity index 100% rename from Commands/templates/new_java_ant_project/src/renameMe/Sketch.java.template rename to Commands/templates/new_java_ant_project/Sketch.java.template diff --git a/Processing.py b/Processing.py index 5d8fb55..1be2db9 100644 --- a/Processing.py +++ b/Processing.py @@ -6,6 +6,7 @@ SOURCE_DIRECTORY_NAME = "src" BUILDFILE_TEMPLATE_NAME = "build.xml.template" GENERATED_BUILDFILE_NAME = "build.xml" +JAVA_TEMPLATE_FILENAMES = ["Main.java.template", "Sketch.java.template"] class NewJavaAntProjectCommand(sublime_plugin.WindowCommand): @@ -17,35 +18,44 @@ def run(self): None, None) def generate_project(self, package_name): - project_path = os.path.join(self.window.folders()[0], - SOURCE_DIRECTORY_NAME, - re.sub('\.', '/', package_name.lower())) - self.create_project_directories(project_path) + generated_source_path = os.path.join(self.window.folders()[0], + SOURCE_DIRECTORY_NAME, + re.sub('\.', '/', package_name.lower())) + self.create_project_directories(generated_source_path) self.generate_files_from_template(PROJECT_TEMPLATE_PATH, - project_path, + generated_source_path, package_name) + self.window.status_message("New Java Ant project created.") def create_project_directories(self, path): if not os.path.exists(path): os.makedirs(path) - def generate_files_from_template(self, template_path, project_path, package_name): - processing_library_path = self.determine_processing_library_path() + def generate_files_from_template(self, template_path, generated_source_path, package_name): + self.generate_buildfile(template_path, package_name) + self.generate_java_boilerplate(template_path, generated_source_path, package_name) + + def generate_buildfile(self, template_path, package_name): with open(os.path.join(template_path, BUILDFILE_TEMPLATE_NAME), 'r') as build_template: - template_contents = build_template.read() - template = string.Template(template_contents) - build_file_contents = template.substitute(processing_library_path = processing_library_path, - ant_project_name = package_name.split('.')[-1], - package_name = package_name) + template = string.Template(build_template.read()) with open(os.path.join(self.window.folders()[0], GENERATED_BUILDFILE_NAME), 'w') as buildfile: - buildfile.write(build_file_contents) - + buildfile.write(template.substitute(ant_project_name = package_name.split('.')[-1], + processing_library_path = self.determine_processing_library_path(), + package_name = package_name)) + + def generate_java_boilerplate(self, template_path, generated_source_path, package_name): + for template_name in JAVA_TEMPLATE_FILENAMES: + with open(os.path.join(template_path, template_name), 'r') as java_template: + template = string.Template(java_template.read()) + with open(os.path.join(generated_source_path, template_name.rsplit('.', 1)[0]), 'w') as source_file: + source_file.write(template.substitute(package_name = package_name)) + def determine_processing_library_path(self): - return "TODO" + # TODO: determine path from OS? Or use explicit settings. + return "/Applications/Processing.app/Contents/Java/core/library" #open_file(file, contents) - # class NewFolderCommand(sublime_plugin.WindowCommand): # def run(self, dirs): # self.window.show_input_panel("Folder Name:", "", functools.partial(self.on_done, dirs[0]), None, None) From f03ebe9033176a5aafb49afd38b0c7950d064325 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Sun, 7 Dec 2014 22:30:08 -0600 Subject: [PATCH 3/7] Add opening of sketch file upon completion. --- Processing.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Processing.py b/Processing.py index 1be2db9..48a3783 100644 --- a/Processing.py +++ b/Processing.py @@ -7,6 +7,8 @@ BUILDFILE_TEMPLATE_NAME = "build.xml.template" GENERATED_BUILDFILE_NAME = "build.xml" JAVA_TEMPLATE_FILENAMES = ["Main.java.template", "Sketch.java.template"] +SKETCH_FILE_NAME = "Sketch.java" +STATUS_MESSAGE = "New Java Ant Processing project created. Be sure to use the Ant build system, not JavaC." class NewJavaAntProjectCommand(sublime_plugin.WindowCommand): @@ -25,7 +27,8 @@ def generate_project(self, package_name): self.generate_files_from_template(PROJECT_TEMPLATE_PATH, generated_source_path, package_name) - self.window.status_message("New Java Ant project created.") + self.window.open_file(os.path.join(generated_source_path, SKETCH_FILE_NAME)) + sublime.status_message(STATUS_MESSAGE) def create_project_directories(self, path): if not os.path.exists(path): @@ -64,4 +67,4 @@ def determine_processing_library_path(self): # os.makedirs(os.path.join(dir, name)) # def is_visible(self, dirs): -# return len(dirs) == 1 \ No newline at end of file +# return len(dirs) == 1 From a5e2b34263c8aa4869ce1b6883a7d147eb685c44 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Wed, 17 Jun 2015 10:28:02 -0600 Subject: [PATCH 4/7] Reorganize files to match latest directory structure. --- Default.sublime-commands => Commands/Default.sublime-commands | 0 Main.sublime-menu => Menus/Main.sublime-menu | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename Default.sublime-commands => Commands/Default.sublime-commands (100%) rename Main.sublime-menu => Menus/Main.sublime-menu (100%) diff --git a/Default.sublime-commands b/Commands/Default.sublime-commands similarity index 100% rename from Default.sublime-commands rename to Commands/Default.sublime-commands diff --git a/Main.sublime-menu b/Menus/Main.sublime-menu similarity index 100% rename from Main.sublime-menu rename to Menus/Main.sublime-menu From 209035f1d4e786204331040a840290bbe9d0c2d6 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Wed, 17 Jun 2015 11:47:39 -0600 Subject: [PATCH 5/7] Update README. Add section for New Java Ant Project command. Clean up and standardize formatting, fix minor spelling issues. --- README.md | 109 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 47 deletions(-) diff --git a/README.md b/README.md index 9df2b0f..633e402 100644 --- a/README.md +++ b/README.md @@ -1,86 +1,101 @@ -# Processing Bundle for Sublime Text +# Processing Package for Sublime Text -A [Processing](http://processing.org/) bundle for [Sublime Text 2 and 3](http://www.sublimetext.com/). Check the [demo video](https://vimeo.com/45573600) on vimeo! -Please note: you must have at least (>=Processing 2.0b6), otherwise the buildsystem of the this bundle won't work. The video is a bit outdated, you don't have to run any longer the Processing.app in parallel to run sketches. If you have to stick for some reason to an old Processing verion e.g. 1.5.1 you can use the [old version](https://github.com/b-g/processing-sublime/tags) of this bundle. +A [Processing](http://processing.org/) package for [Sublime Text 2 and 3](http://www.sublimetext.com/). Check the [demo video](https://vimeo.com/45573600) on vimeo! +Please note: you must have at least (>=Processing 2.0b6), otherwise the build system of the this package won't work. The video is a bit outdated, you don't have to run any longer the Processing.app in parallel to run sketches. If you have to use an old Processing verion (e.g. 1.5.1), you can use [version 1.0 of this package](https://github.com/b-g/processing-sublime/releases/tag/v1.0_Processing_1.5.1). [](https://vimeo.com/45573600) ## Preparations -###OSX -Make sure to run `Tools -> Install "processing-java"` after you have installed the Processing.app. +### OSX +Use Processing's _Tools > Install "processing-java"_ menu item after you have installed Processing. ![Use external editor preference](https://github.com/b-g/processing-sublime/raw/master/Images/processing_preferences.gif "Use external editor preference") -This bundle assumes that you chose to install processing-java for all users (recomended). If you choose/have to install processing-java only in your home directory, then you have to slightly change the build script, see comment in `Processing.sublime-build`. +This package assumes that you chose to install `processing-java` for all users (recommended). If you choose to install `processing-java` only in your home directory, then you have to slightly change the build script, see the comment in the file [Processing.sublime-build](https://github.com/b-g/processing-sublime/blob/master/Build%20Systems/Processing.sublime-build). -###Linux -You will need to set your PATH to where your processing application is located, e.g.: +### Linux +You will need to set your `PATH` to where your processing application is located, e.g.: `export PATH=$PATH:/opt/processing/processing-2.0b4` You also need to create an alias for `processing-java` in `/bin/` instead of `/usr/bin/`, e.g.: `sudo ln -s /opt/processing/processing-java /bin/processing-java` -###Windows -You will need to set your PATH environment variable to where your processing application is located: -- Open the "Advanced System Settings". e.g. by running "sysdm.cpl" -- In the System Properties window, click on the Advanced tab. -- In the Advanced section, click the Environment Variables button. -- Edit the "Path" variable. Append the processing path (e.g.: `;C:\Program Files\Processing-2.0b6\`) to Variable value. - Each entry is separated with a semicolon. +### Windows +You will need to set your `PATH` environment variable to where your processing application is located: -or write a seperate build system as documented in this [comment](https://github.com/b-g/processing-sublime/issues/17#issuecomment-15585500) +- Open the "Advanced System Settings" by running `sysdm.cpl` +- In the "System Properties" window, click on the _Advanced_ tab. +- In the "Advanced" section, click the _Environment Variables_ button. +- Edit the "Path" variable. Append the processing path (e.g. `;C:\Program Files\Processing-2.0b6\`) to the variable value. Each entry is separated with a semicolon. -![Advanced System Settings -> Environment Variables](https://github.com/b-g/processing-sublime/raw/master/Images/processing_path_windows.gif) +Or, write a separate build system as documented in this [comment](https://github.com/b-g/processing-sublime/issues/17#issuecomment-15585500). + +![Advanced System Settings > Environment Variables](https://github.com/b-g/processing-sublime/raw/master/Images/processing_path_windows.gif "Windows Environment Variables") ## Installation -There are 3 easy ways to install the Processing Bundle: +There are three easy ways to install the Processing package: ### Using Sublime Package Control -If you are using [Sublime Package Control](http://wbond.net/sublime_packages/package_control), you can easily install the Processing Bundle via the `Sublime Text -> Preferences -> Package Control: Install Package` menu item. +If you are using [Sublime Package Control](https://packagecontrol.io/), you can easily install the [Processing Package](https://packagecontrol.io/packages/Processing) via the _Sublime Text > Preferences > Package Control: Install Package_ menu item. ### Using Git -Alternatively you can install the theme and keep up to date by cloning the repo directly into your `Packages` directory in the Sublime Text application settings area. +Alternatively you can install the package and keep up to date by cloning the repo directly into your Sublime Text `Packages` directory. -Go to your Sublime Text `Packages` directory and clone the theme repository using the command below: -`git clone https://github.com/b-g/processing-sublime/ "Processing"` +Go to your Sublime Text `Packages` directory and clone this repository: +`git clone https://github.com/b-g/processing-sublime/ Processing` ### Download Manually -- Download the files using the GitHub .zip download option -- Unzip the files and rename the folder to `Processing` -- Copy the folder to your Sublime Text `Packages` directory e.g. OS X: `~/Library/Application Support/Sublime Text 2/Packages/Processing` +- Download the files using the GitHub [.zip download option](https://github.com/b-g/processing-sublime/archive/master.zip). +- Unzip the file and rename the directory to `Processing`. +- Copy the directory to your Sublime Text `Packages` directory e.g. OS X: `~/Library/Application Support/Sublime Text 2/Packages/Processing`. ## Usage -- Select in Sublime Text the Processing buildsystem: `Tools -> Build system -> Processing` -- Run the sketch: `cmd+b` (make sure that you have the normal sketch structure of a folder and a pde-file: mysketch/mysketch.pde) -- With `cmd+shift+b` and typing `build` you get alternative buildsystems: `Run sketch fullscreen` and various `Export sketch options` +- Open the directory containing a Processing sketch in Sublime Text. (e.g. Drag the folder to Sublime Text.) +- In Sublime Text, select the _Tools > Build System > Processing_ menu item. +- In Sublime Text, select your main `.pde` file and use **⌘B** to run the sketch. The build system expects that your sketch follows the normal directory structure and naming conventions of a Processing sketch (e.g. `mysketch/mysketch.pde`). +- With **⇧⌘B** and typing `build`, you can select alternative build systems, such as _Run sketch fullscreen_ and various _Export sketch_ options. ### Custom shortcuts -To get .pde files to run with `cmd+r` and `cmd+shift+r` instead of `cmd+b` and `cmd+shift+b` Add the following code to ```Preferences``` > ```Key Bindings - User``` in Sublime Text: +To get `.pde` files to run with **⌘R** and **⇧⌘R** (like Processing) instead of **⌘B** and **⇧⌘B**, add the following code to the User Key Bindings file via the _Preferences > Key Bindings - User_ menu item in Sublime Text. ``` - { "keys": ["super+r"], "command": "build", "context": - [ - { "key": "selector", "operator": "equal", "operand": "source.pde" } - ]}, - { "keys": ["super+shift+r"], "command": "build", "args": {"variant": "Run sketch fullscreen"}, "context": - [ - { "key": "selector", "operator": "equal", "operand": "source.pde" } - ]} +{ + "keys": ["super+r"], "command": "build", + "context": [{ "key": "selector", "operator": "equal", "operand": "source.pde" }] +}, +{ + "keys": ["super+shift+r"], "command": "build", + "args": {"variant": "Run sketch fullscreen"}, + "context": [{ "key": "selector", "operator": "equal", "operand": "source.pde" }] +} ``` +### _New Java Ant Project_ Command + +Want a "pure Java" Processing project but don't like [Eclipse](http://eclipse.org)? Try creating a project with the _New Java Ant Project_ command. (See [issue 61](https://github.com/b-g/processing-sublime/issues/61).) + +1. Create an empty directory (folder) for your new project, and open that empty directory in Sublime. +2. Use either the menu item _Tools > Processing > New Java Ant Project_ or select the _Processing: New Java Ant Project_ command from the command pallete (**⇧⌘P**). +3. Specify a Java package name for your source code. +4. Use the _Tools > Build System > Ant_ menu item to ensure that Ant is the active build system. +5. Use **⌘B** to build and run your sketch. + +You can now continue to add classes to your sketch, and run it with **⌘B**. Just be sure that _Ant_ is the active build system. +**Note:** OS X users may need to install the [Fix Mac Path](https://packagecontrol.io/packages/Fix%20Mac%20Path) package, due to the way Sublime manages environment variables such as `PATH`. ## Hints -- Console error messages are clickable: e.g. double click `test.pde:10:0:10:0: The function reect(int, int, int, int) does not exist.` to jump to the related line and file. +Console error messages are clickable: e.g. double click `test.pde:10:0:10:0: The function rEEct(int, int, int, int) does not exist` to jump to the related line and file. ## Getting Started With Sublime Text -If you are new to Sublime I recommend the excellent and free video tutorial by nettuts: [Perfect Workflow in Sublime Text](http://net.tutsplus.com/articles/news/perfect-workflow-in-sublime-text-free-course/). If you are short of time, then make sure to watch at least the lession [Multiple Cursors and Incremental Search]( https://tutsplus.com/lesson/multiple-cursors-and-incremental-search/) (~6min), highly recommended! +If you are new to Sublime I recommend the [Perfect Workflow in Sublime Text](http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2) tutorial. If you are short of time, then make sure to at least watch [Multiple Cursors and Incremental Search](http://code.tutsplus.com/courses/perfect-workflow-in-sublime-text-2/lessons/multiple-cursors-and-incremental-search) (~6min), highly recommended! ## Acknowledgements -- This bundle is very much based on [Processing TextMate Bundle by Leon Hong](http://www.onebitwonder.com/projects/processing/), thanks for all the good work! -- I used the [textmate-to-sublime-converter](https://github.com/srbs/textmate-to-sublime-converter) to convert the snippets from the original Processing TextMate Bundle to Sublime Text speak. -- Syntax highlighting tweaking [Mark Brand](https://github.com/ignism) -- Linux build script and testing [Julien Deswaef](http://xuv.be/) -- Windows build script and documention [Ralf Baecker](http://github.com/rlfbckr) -- Error console capturer [Greger Stolt Nilsen](http://gregerstoltnilsen.net/) -- Master of the syntax definition. Whitespace and indentation cleanup. Processing reference vs. sublime [diff tool](https://github.com/ybakos/processing-sublime-util). [Yong Joseph Bakos](http://yongbakos.com/). -- How to set custom shortcuts [Raphaël de Courville](https://github.com/SableRaf) +- Original [Processing TextMate Bundle](http://www.onebitwonder.com/projects/processing/): [Leon Hong](http://www.onebitwonder.com/) +- Textmate Bundle to Sublime snippet conversion: [textmate-to-sublime-converter](https://github.com/srbs/textmate-to-sublime-converter) +- Maintainer: [Benedikt Groß](http://benedikt-gross.de/log/) +- Syntax highlighting tweaking: [Mark Brand](https://github.com/ignism) +- Linux build script and testing: [Julien Deswaef](http://xuv.be/) +- Windows build script and documention: [Ralf Baecker](http://github.com/rlfbckr) +- Error console capturer: [Greger Stolt Nilsen](http://gregerstoltnilsen.net/) +- Syntax definition, snippet cleansing, Processing reference vs. sublime [diff tool](https://github.com/ybakos/processing-sublime-util), and _New Java Ant Project_ command: [Yong Joseph Bakos](http://yongbakos.com) +- How to set custom shortcuts: [Raphaël de Courville](https://github.com/SableRaf) From e8512479694c3d2fc1fdb1a12f283560ceab6905 Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Thu, 18 Jun 2015 12:27:05 -0600 Subject: [PATCH 6/7] Extract processing library path into global variable with comment to edit. Update README instructions with prerequisites. --- Processing.py | 6 +++--- README.md | 15 ++++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Processing.py b/Processing.py index 48a3783..cd20af1 100644 --- a/Processing.py +++ b/Processing.py @@ -1,7 +1,7 @@ import sublime, sublime_plugin, sys, functools, os, re, string -#from plugins.new_java_project import * - +# NOTE: Change this next line to match the correct library path for your system. +DEFAULT_PROCESSING_LIBRARY_PATH = "/Applications/Processing.app/Contents/Java/core/library" PROJECT_TEMPLATE_PATH = os.path.abspath("Commands/templates/new_java_ant_project") SOURCE_DIRECTORY_NAME = "src" BUILDFILE_TEMPLATE_NAME = "build.xml.template" @@ -55,7 +55,7 @@ def generate_java_boilerplate(self, template_path, generated_source_path, packag def determine_processing_library_path(self): # TODO: determine path from OS? Or use explicit settings. - return "/Applications/Processing.app/Contents/Java/core/library" + return DEFAULT_PROCESSING_LIBRARY_PATH #open_file(file, contents) diff --git a/README.md b/README.md index 633e402..e21c29b 100644 --- a/README.md +++ b/README.md @@ -73,16 +73,21 @@ To get `.pde` files to run with **⌘R** and **⇧⌘R** (like Processing) inste Want a "pure Java" Processing project but don't like [Eclipse](http://eclipse.org)? Try creating a project with the _New Java Ant Project_ command. (See [issue 61](https://github.com/b-g/processing-sublime/issues/61).) +#### Prerequisites +Be sure that [ant](http://ant.apache.org/) is installed and on your environment's `PATH`. You know this is right when you can open a terminal, run `ant`, and see a `Build failed` message. This means that [ant](http://ant.apache.org/) is runnable, and failing is ok because there is no "Buildfile." + +Make sure that the variable `DEFAULT_PROCESSING_LIBRARY_PATH` within the file `Processing.py` inside this package matches your installation of Processing. If you are on OS X and `Processing.app` is in the `Applications` directory, then you do not need to edit this. Despite this, OS X users may need to install the [Fix Mac Path](https://packagecontrol.io/packages/Fix%20Mac%20Path) package, due to the way Sublime manages environment variables such as `PATH`. + +#### Using the Command + 1. Create an empty directory (folder) for your new project, and open that empty directory in Sublime. 2. Use either the menu item _Tools > Processing > New Java Ant Project_ or select the _Processing: New Java Ant Project_ command from the command pallete (**⇧⌘P**). -3. Specify a Java package name for your source code. -4. Use the _Tools > Build System > Ant_ menu item to ensure that Ant is the active build system. -5. Use **⌘B** to build and run your sketch. +3. Specify a Java package name for your source code (e.g. `com.myorg.myapp`). +4. Use the _Tools > Build System > Ant_ menu item to ensure that _Ant_ is the active build system. +5. Use **⌘B** to build and run your sketch. Out of the box, you should see a full screen app that displays the default 200x200px gray sketch, which is the Processing default. You can now continue to add classes to your sketch, and run it with **⌘B**. Just be sure that _Ant_ is the active build system. -**Note:** OS X users may need to install the [Fix Mac Path](https://packagecontrol.io/packages/Fix%20Mac%20Path) package, due to the way Sublime manages environment variables such as `PATH`. - ## Hints Console error messages are clickable: e.g. double click `test.pde:10:0:10:0: The function rEEct(int, int, int, int) does not exist` to jump to the related line and file. From 56317334253a79255e5377776009df7ce623920c Mon Sep 17 00:00:00 2001 From: Yong Bakos Date: Sat, 20 Jun 2015 11:40:27 -0600 Subject: [PATCH 7/7] Adjust project template path to accommodate ST3. --- Processing.py | 2 +- README.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Processing.py b/Processing.py index cd20af1..1617a94 100644 --- a/Processing.py +++ b/Processing.py @@ -2,7 +2,7 @@ # NOTE: Change this next line to match the correct library path for your system. DEFAULT_PROCESSING_LIBRARY_PATH = "/Applications/Processing.app/Contents/Java/core/library" -PROJECT_TEMPLATE_PATH = os.path.abspath("Commands/templates/new_java_ant_project") +PROJECT_TEMPLATE_PATH = os.path.dirname(os.path.abspath(__file__)) + "/Commands/templates/new_java_ant_project" SOURCE_DIRECTORY_NAME = "src" BUILDFILE_TEMPLATE_NAME = "build.xml.template" GENERATED_BUILDFILE_NAME = "build.xml" diff --git a/README.md b/README.md index e21c29b..614ec57 100644 --- a/README.md +++ b/README.md @@ -69,9 +69,10 @@ To get `.pde` files to run with **⌘R** and **⇧⌘R** (like Processing) inste "context": [{ "key": "selector", "operator": "equal", "operand": "source.pde" }] } ``` -### _New Java Ant Project_ Command -Want a "pure Java" Processing project but don't like [Eclipse](http://eclipse.org)? Try creating a project with the _New Java Ant Project_ command. (See [issue 61](https://github.com/b-g/processing-sublime/issues/61).) +### Want a "Pure Java" Project without Eclipse? + +Complex projects often lead people into using Processing with [Eclipse](http://eclipse.org). If you want to stick with Sublime Text, but want a "pure Java" Processing project _and_ the convenience of a fast "build and run" workflow, try creating a project with the _New Java Ant Project_ command (see [issue 61](https://github.com/b-g/processing-sublime/issues/61)) and run your sketch with the _Ant_ build system. #### Prerequisites Be sure that [ant](http://ant.apache.org/) is installed and on your environment's `PATH`. You know this is right when you can open a terminal, run `ant`, and see a `Build failed` message. This means that [ant](http://ant.apache.org/) is runnable, and failing is ok because there is no "Buildfile." @@ -86,7 +87,7 @@ Make sure that the variable `DEFAULT_PROCESSING_LIBRARY_PATH` within the file `P 4. Use the _Tools > Build System > Ant_ menu item to ensure that _Ant_ is the active build system. 5. Use **⌘B** to build and run your sketch. Out of the box, you should see a full screen app that displays the default 200x200px gray sketch, which is the Processing default. -You can now continue to add classes to your sketch, and run it with **⌘B**. Just be sure that _Ant_ is the active build system. +You can now implement `setup` and `draw`, add additional classes to your sketch, and run it with **⌘B**. Just be sure that _Ant_ is the active build system. ## Hints Console error messages are clickable: e.g. double click `test.pde:10:0:10:0: The function rEEct(int, int, int, int) does not exist` to jump to the related line and file.