/*
* Menu: Info Support > Find commented code
* Kudos: Peter Hendriks
* License: EPL 1.0
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/
function main() {
loadBundle("org.eclipse.core.jobs");
var ProgressMonitorDialog = Packages.org.eclipse.jface.dialogs.ProgressMonitorDialog;
var IRunnableWithProgress = Packages.org.eclipse.jface.operation.IRunnableWithProgress;
var runnableWithProgress = new IRunnableWithProgress({ run: runCommentSearch });
new ProgressMonitorDialog(window.getShell()).run(true, true, runnableWithProgress);
window.getActivePage().showView("org.eclipse.ui.views.TaskList");
}
function runCommentSearch(monitor) {
var files = resources.filesMatching(".*\\.java");
monitor.beginTask("Searching for commented code...", files.length);
try {
var match;
for each( file in files ) {
monitor.subTask(file.getEclipseObject().getName());
file.removeMyTasks();
var previousLineCodeComment = false;
for each( line in file.lines ) {
if (monitor.isCanceled()) {
return;
}
if (match = line.string.match(/^.*\/\/.*[;{}]\s*$/)) {
if (!previousLineCodeComment) {
line.addMyTask("Commented code: " + match[0]);
}
previousLineCodeComment = true;
} else {
previousLineCodeComment = false;
}
}
monitor.worked(1);
}
} finally {
monitor.done();
}
}
2011-12-21 19:03
[轉載] Aptana Scripting 一個背景處理的範例
轉載自:Monkeying with Eclipse | Info Support
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
2011-12-21 18:58
Aptana Scripting - Find TODOs 範例中的參數
/*
* Menu: Editors > Find TODOs
* Kudos: Ingo Muschenetz
* License: EPL 1.0
* DOM: http://download.eclipse.org/technology/dash/update/org.eclipse.eclipsemonkey.lang.javascript
*/
function main() {
var files = resources.filesMatching(".*\\.js");
var match;
for each( file in files ) {
file.removeMyTasks( );
for each( line in file.lines ) {
if (match = line.string.match(/\/\/TODO: (.*)/)) {
line.addMyTask( match[1] );
}
}
}
window.getActivePage().showView("org.eclipse.ui.views.TaskList");
}
只列出當前文件的方法
var files = resources.filesMatching('.*/'+editors.activeEditor.textEditor.titleToolTip);
resources 部分的方法
filesMatching(".*\\.js")
filesMatchingForProject("Project Name",".*\\.js")
filesMatchingIgnoreCase(".*\\.js")
filesMatchingForProjectIgnoreCase("Project Name",".*\\.js")
file 部分的方法
size lines removeMyTasks()
line 部分的方法
lineNumber
string
addMyTask('Task String')
2011-12-21 18:46
Aptana Scripting 學習筆記
- 在任何一個專案的頂層目錄,建立一個名稱為 scripts 或 monkey 的目錄
- 在此目錄下建立副檔名為 *.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();
分類:
工作備忘,
筆記,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
2
回應
2011-12-21 15:05
[轉載] Aptana Scripting File.js Class Document
轉載自:Koders Code Search: File.js - JavaScript
/**
* File.js
*
* Adding this file to your Active Libraries will give you code assist for the
* Aptana Studio scripting engine.
*
* @author Kevin Lindsey
* @version 1.0
*/
/**
* This object represents a file or a directory in the file system
*
* @constructor
* @param {String} name
* The relative or absolute path to a file or directory
*/
function File(name) {}
/*
* Properties
*
/**
* Get the absolute path for this file or directory
*
* @type {String} Returns the absolute path to this file or directory
*/
File.prototype.absolutePath = "";
/**
* Get the file's base name. This is the filename only without the extension.
* If the file does not have an extension, then this will return the full
* name
*
* @type {String} Returns this file's base name
*/
File.prototype.baseName = "";
/**
* Determine if this file is readable
*
* @type {Boolean} Returns true if this File is readable
*/
File.prototype.canRead = false;
/**
* Determine if ths file is writable
*
* @type {Boolean} Returns true if this File is writable
*/
File.prototype.canWrite = false;
/**
* Determine if this file or directory exists in the file system
*
* @type {Boolean} Returns true if this File exists in the file system
*/
File.prototype.exists = false;
/**
* Returns the file extension of this File
*
* @type {String} Returns the last instance of "." and the text after it.
* An empty string will be returned if no extension if found. The return
* value includes the '.'
*/
File.prototype.extension = "";
/**
* Determines if thie File is a file in the file system
*
* @type {Boolean} Returns true if this File is a file in the file system
*/
File.prototype.isFile = false;
/**
* Determines if this File is a directory in the file system
*
* @type {Boolean} Returns true if this File is a directory in the file
* system
*/
File.prototype.isDirectory = false;
/**
* Returns a list of File objects for all files in the File. This is equivalent
* to listing out all files in a directory
*
* @type {Array} Returns an array of File objects, one for each file and
* directory in this File
*/
File.prototype.list = [];
/**
* Returns the file's name without path information
*
* @type {String} Returns the file's name
*/
File.prototype.name = "";
/**
* Returns a new File object of this object's parent directory
*
* @type {File} Returns this file's parent File
*/
File.prototype.parentFile = {};
/**
* Returns the character used to separate directories on the underlying OS
*
* @type {String} Returns the directory separator
*/
File.prototype.separator = "";
/*
* Methods
*/
/**
* Create a new file in the file system at the location specified by this
* object
*
* @return {Boolean} Returns true if the file was created successfully.
*/
File.prototype.createNewFile = function() {};
/**
* Return all lines from this File's text file
*
* @return {Array} Returns an array of strings, one for each line in the file.
*/
File.prototype.readLines = function() {};
//eof
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
2011-12-21 15:05
[轉載] Aptana Scripting PrintStream.js Class Document
轉載自:Koders Code Search: PrintStream.js - JavaScript
/**
* PrintStream.js
*
* Adding this file to your Active Libraries will give you code assist for the
* Aptana Studio scripting engine.
*
* @author Kevin Lindsey
* @version 1.0
*/
/**
* This object represents an underlying Java PrintStream
*
* @constructor
*
/
function PrintStream() {}
/*
* Methods
*/
/**
* Print the given text to the underlying stream
*
* @param {String} text
* The text to send to the stream
*/
PrintStream.prototype.print = function(text) {};
/**
* Print the given text to the underlying stream followed by end-of-line
*
* @param {String} text
* The text to send to the stream
*/
PrintStream.prototype.println = function(text) {};
//eof
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
2011-12-21 15:04
[轉載] Aptana Scripting Editor.js Class Document
轉載自:Koders Code Search: Editor.js - JavaScript
/**
* Editor.js
*
* Adding this file to your Active Libraries will give you code assist for the
* Aptana Studio scripting engine.
*
* @author Kevin Lindsey
* @version 1.0
*/
/**
* Editor
*
* @constructor
* @extends {EventTarget}
*/
function Editor() {}
/*
* Properties
*/
/**
* Get/set the position of the cursor in this editor
*
* @type {Number} The current cursor offset position
*/
Editor.prototype.currentOffset = 0;
/**
* Get the File object that this editor is editing
*
* @type {File} Returns a File object or undefined
*/
Editor.prototype.file = {};
/**
* Get the language MIME type for this editor
*
* @type {String} Returns this editors language type
*/
Editor.prototype.language = "";
/**
* Get the lexemes associated with this editor
*
* @type {Array} Returns an array of Lexemes
*/
Editor.prototype.lexemes = [];
/**
* Get the line delimiter for this editor
*
* @type {String} Returns the editor's line terminator
*/
Editor.prototype.lineDelimiter = "";
/**
* Get the source associated with this editor
*
* @type {String} Returns the source text in this editor
*/
Editor.prototype.source = "";
/**
* Get the length of the source in this editor
*
* @type {Number} Returns the number of characters in this editor's document
*/
Editor.prototype.sourceLength = 0;
/**
* Get the number of columns in a tab
*
* @type {Number} Returns the number of spaces that equal one tab
*/
Editor.prototype.tabWidth = 0;
/**
* Get the zero-based line number of the line at the top of the editor
*
* @type {Number} The top-most line's index
*/
Editor.prototype.topIndex = 0;
/**
* Get/set the editor's word wrap setting. Setting this to true turns on word
* wrapping.
*
* @type {Boolean} The word wrap setting.
*/
Editor.prototype.wordWrap = false;
/*
* Methods
*/
/**
* Apply an edit to the current document. This function allows you to delete
* and insert text in one operation, if desired.
*
* @param {Number} offset
* The offset within the source where this edit is to take place
* @param {Number} deleteLength
* The number of characters to remove before inserting the new text
* @param {String} insertText
* The new text to insert at the given offset
*/
Editor.prototype.applyEdit = function(offset, deleteLength, insertText) {};
/**
* Get the zero-based line number at the specified character offset
*
* @param {Number} offset
* The character offset within the editor's document
*/
Editor.prototype.getLineAtOffset = function(offset) {};
/**
* Scroll the editor to bring the current selection or caret position into
* view.
*/
Editor.prototype.showSelection = function() {};
//eof
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
2011-12-21 15:04
[轉載] Aptana Scripting Global.js Document
轉載自:Koders Code Search: Global.js - JavaScript
/**
* Global.js
*
* Adding this file to your Active Libraries will give you code assist for the
* Aptana Studio scripting engine.
*
* @author Kevin Lindsey
* @version 1.0
*/
/*
* Properties
*/
/**
* Retrieve the Editors object to access editors and editor events
*
* @type {Editors} Returns the global Editors object
*/
var editors = {};
/**
* Retrieve the error print stream.
*
* @type {PrintStream} Returns the output stream used to display errors
*/
var err = {};
/**
* This is a reference to the only instance of this object. All scripts run in
* their own protected scope. However, this Global is accessible from all
* scripts. Properties placed on "global" will be accessible to all scripts
*
* @type {Global} Returns a reference to the global scope
*/
var global = {};
/**
* Retrieve the Menus object to access menus and menu events
*
* @type {Menus} Returns the global Menus object
*/
var menus = {};
/**
* Retrieve the standard output print stream.
*
* @type {PrintStream} Returns the standard output stream
*/
var out = {};
/**
* Retrieve the View object to access views and view events
*
* @type {Views} Returns the global Views object
*/
var views = {};
/*
* Methods
*/
/**
* Display an alert dialog with the given message
*
* @param {String} message
* The message to display in the dialog
*/
var alert = function(message) {};
/**
* Execute a string in the current shell. This is experimental and may be
* removed in a future version of the scripting environment
*
* @param {String} command
* The command to execute in the shell
* @return {Object} Returns an object with the following properties: code,
* stdout, stderr. Code is the return code from the command. Stdout
* contains any text that was emitted to standard out while it was
* executing. Likewise, stderr contains any errors that were emitted.
*/
var execute = function(command) {};
/**
* Call Java's System.getProperty.
*
* @param {String} property
* The name of the property to retrieve
* @return {String} Returns the specified property value or the string
* "undefined" if the property does not exist
*/
var getProperty = function(property) {};
/**
* Include a JavaScript file into the current script's scope. this is used to
* load dependent libraries into the script that invokes this function.
*
* @param {String} filename
* The name of the file to include in the script
*/
var include = function(filename) {};
/**
* Load a library into the scripting environment. Each script loaded with this
* function will be assigned a unique ID and, if it exists, the init() function
* will be invoked. This gives each script the ability to initialize itself and
* to setup any event listeners it wishes to subscribe to.
*
* Each script will exist in its own scope; however, this Global is also
* included in the scope chain. All variables and functions defined in the
* script will not collide with any other scripts.
*
* Shared properties can be placed on the "global" property. All scripts loaded
* via this function will then be able to see those properties. This can be
* used to share data between scripts.
*
* @param {String} filename
* The file system path to the script to load
* @return {String} Returns a unique string identifier for the loaded script.
* This identifier can be used later to invoke functions within the
* script; however, this is more for internal use at this point. If the
* script fails to load, this will return undefined.
*/
var loadBundle = function(filename) {};
//eof
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
2011-12-21 15:04
[轉載] Aptana Scripting Editors.js Class Document
轉載自:Koders Code Search: Editors.js - JavaScript
/**
* Editors.js
*
* Adding this file to your Active Libraries will give you code assist for the
* Aptana Studio scripting engine.
*
* @author Kevin Lindsey
* @version 1.0
*/
/**
* Editors
*
* @constructor
*/
function Editors(){}
/*
* Properties
*/
/**
* Get all editors currently being displayed
*
* @type {Array} Returns an array of Editor instances, one for each open editor
*/
Editors.prototype.all = [];
/**
* Get the currently active editor
*
* @type {Editor} Returns the currently active editor or undefined if no editor is open
*/
Editors.prototype.activeEditor = {};
/*
* Methods
*/
/**
* Get the object that represents all editors of a given type. This is
* typically used to register event handlers for a given event type for
* all editors of a specified language.
*
* @param {String} type
* The editor type to retrieve. Currently, this is the MIME type for the
* language the editor supports.
* @return {EditorType} Returns the editor type for the given MIME type or
* undefined if no editor type exists for the given MIME type
*/
Editors.prototype.getEditorType = function(type) {};
/**
* Open the specified filename in a new editor
*
* @param {String} filename
* The name of the file to open in the file system
* @return {Editor} Returns a new Editor object for the newly opened editor
*/
Editors.prototype.open = function(filename) {};
//eof
分類:
轉載,
Aptana,
Aptana Scripting,
Eclipse,
Eclipse Monkey,
JavaScript
0
回應
訂閱:
文章 (Atom)