Aptana Scripting常用方法 函数 快键键
时间:2014-07-22 15:33 来源: 我爱IT技术网 作者:山风
Aptana Scripting入门,常用方法、 函数、 快键键、替换选择、存取等合集整理
1、在任何一个专案的顶层目录,建立一个名称为 scripts 或 monkey 的目录
2、在此目录下建立副档名为 *.js 或 *.em 的 JavaScript 的文件
一个空白文件的内容如下:
- /*
- * Menu: Samples > Execute Snippet
- * Key: M1+M2+M3+F
- * Kudos: Jax Hu
- * License: EPL 1.0
- * DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
- */
- function main(){
- }
快捷键的代号对应:
M1 Control/Command
M2 Shift
M3 Alt/Option
一个可以用来显示对象成员的函数:
- /**显示对象的成员
- * @param {Object} val 对象
- */
- function var_dump(val){
- var name, value, temp=[];
- for (name in val) {
- try {
- value = (val[name]+'').
- replace("function",'<b style="color:#00f;">$&</b>');
- }catch (e) {
- value = (e+'').fontcolor('red');
- }
- temp.push('<b style="color:#707;">'+name+'</b> = '+value);
- }
- webView = views.getView("var_dump");
- webView.showView(true);
- webView.setTitle('var_dump');
- webView.setHTML(temp.join("<hr/>").fixed());
- }
常用方法以及数值:
- /*当前文件的位置
- * => D:/WorkSpace/my_project/test.js */
- location
- /*当前文件的名称
- * => test.js */
- editors.activeEditor.title
- /*当前的文件内容*/
- editors.activeEditor.source
- /*当前文件的 URI 地址*/
- editors.activeEditor.uri
- /*储存当前文件*/
- editors.activeEditor.save();
- /*对当前文件-开启另存新档的对话匡*/
- editors.activeEditor.textEditor.doSaveAs()
- /*对当前文件的目录路径
- * => D:/WorkSpace/my_project */
- editors.activeEditor.textEditor.editorInput.file.parent.location
- /*目前开启的所有文件*/
- editors.all[];
- /*储存全部编辑器,传入 true 会开启存档提示*/
- window.workbench.saveAllEditors(false);
- /*重新开启 Eclipse*/
- window.workbench.restart();
- /*关闭 Eclipse*/
- window.workbench.close();
- /* 开新的编辑器,可以通过这个开启空白文件,或是已经存在的文件,
- * 之后 editors.activeEditor 会转到这个文件上 */
- fileUtils.open('textile_to_redmine.txt');
- /*取得当前的项目名称*/
- editors.activeEditor.textEditor.editorInput.file.project.name;
- /*取得所有的项目*/
- Packages.org.eclipse.core.resources.ResourcesPlugin.workspace.root.projects;
- editors.activeEditor.textEditor.editorInput.file.workspace.root.projects
建立一个新的窗口,或开启已存在的窗口:
- webView = views.getView("my_view_name");
- /*显示视图*/
- webView.showView(true);
- /*设置标题*/
- webView.setTitle("My View Title");
- /*设置内容的HTML*/
- webView.setHTML('<h1>OK</h1>');
- /*或指定内容的网址*/
- webView.url = "http://www.google.com";
- webView.addEventListener("LocationChanging", function(event){
- var location = event.innerEvent.location;
- // Print out the location to the Java console
- Packages.java.lang.System.out.println("You clicked on: " + location);
- });
替换选择的文字区段:
- /*选择的起始位置*/
- var starting = editors.activeEditor.selectionRange.startingOffset;
- /*选择的结束位置*/
- var ending = editors.activeEditor.selectionRange.endingOffset;
- /*选择的文字内容*/
- var text = editors.activeEditor.source.substring(starting, ending);
- /*文字跳脱处理,或其他自定义的处理*/
- text = escape(text);
- /*替换选择的文字*/
- editors.activeEditor.applyEdit(starting, ending-starting, text);
- /*重新选择文字区段*/
- editors.activeEditor.selectAndReveal(starting, text.length);
文件存取:
- var file = new File("myFile.txt");
- file.createNewFile();
- file.write("Date: ");
- var text = file.readLines();
Web 数据请求的方式:
- var req = new WebRequest();
- req.open("GET", "http://xml.weather.yahoo.com/forecastrss?p=94103");
- var text = req.send();
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
