-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add insert require statement to sublime PhET Package, phetsims/chippe…
- Loading branch information
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# PhET Sublime Package | ||
|
||
This package can be used with sublime to add phet tasks to the command palette. To use these tools, | ||
you must know how to access the `command palette`. | ||
|
||
To add these to your copy of sublime, locate your Packages folder. `Preferences --> Browser Packages`. Then copy this | ||
folder into that `PhET Package` folder into the `Packages` directory. (On Windows the file path looks like: | ||
`C:\Users\{{USER}}\AppData\Roaming\Sublime Text 3\Packages\`). | ||
|
||
When these commands are added into the `Packages` folder in the Sublime installation directory, then they will also be | ||
added to the command palette, although a restart may be required. | ||
|
||
Usage: | ||
|
||
Type `PhET: ` into the command palette for a list of available scripts to be run. | ||
You can open up the Sublime terminal (ctrl + \`) to see results from scripts that are run. | ||
|
||
|
||
* PhET: Insert Require Statement | ||
* Used to add the require statement of the type that is highlighted. | ||
* This will also sort the list of require statements. | ||
* Example: Highlight the word "Node"; open command palette; run command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[ | ||
{ | ||
"caption": "PhET: Insert Require Statement", | ||
"command": "phet_run_cmd", | ||
"args": { | ||
"cmd": "grunt insert-require-statement --name=$selectedText --file=$file_name" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import sublime | ||
import sublime_plugin | ||
import subprocess | ||
|
||
# class generally copied from http://mreq.eu/2014/10/running-custom-command/ | ||
class RunCmd(sublime_plugin.WindowCommand): | ||
def run(self, cmd): | ||
|
||
# Save the file first so you don't look working copy changes | ||
window = self.window | ||
view = window.active_view() | ||
view.run_command('save') | ||
|
||
if "$file_name" in cmd: | ||
view = self.window.active_view() | ||
cmd = cmd.replace("$file_name",view.file_name()) | ||
if "$file_dir" in cmd: | ||
view = self.window.active_view() | ||
cmd = cmd.replace("$file_dir",os.path.split(view.file_name())[0]) | ||
|
||
if "$selectedText" in cmd: | ||
|
||
# code section copied from https://stackoverflow.com/questions/19707727/api-how-to-get-selected-text-from-object-sublime-selection | ||
sel = view.sel() | ||
region1 = sel[0] | ||
selectionText = view.substr(region1) | ||
|
||
cmd = cmd.replace("$selectedText", selectionText) | ||
|
||
|
||
print ('Running custom command:', cmd) | ||
|
||
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, cwd=os.path.split(view.file_name())[0]) | ||
while proc.poll() is None: | ||
line = proc.stdout.readline() | ||
if( len(line) > 0): | ||
print (line.decode("utf-8")) # give output from your execution/your own message | ||
self.commandResult = proc.wait() # catch return code |