<!-- markdown -->
[JAVAの記事一覧](./JAVA%E3%81%AE%E8%A8%98%E4%BA%8B%E4%B8%80%E8%A6%A7)
# 目次
[TOC]
# 趣旨
Eclipseでマクロ機能を使えるようにする
# Eclipse Monkeyの導入
まずはEclipse Monkeyをアップデートサイト経由で導入します。
http://download.eclipse.org/technology/dash/update/
Eclipse MonkeyをインストールするとEclipseのメニューバーに「Scripts」メニューが追加される。
# 「Examples」を選択
メニューバーに「Scripts」から「Examples」を選択することでワークスペースに「Eclipse Monkey Examples」プロジェクトが作成される
# Eclipseのメニューに表示する
エクリプスでjsファイルを新規作成し、
下記ソースを保存する。
すぐさま
Hello > NanimoShinai
にメニューが登録されているのがわかる。
/*
* Menu: Hello > NanimoShinai
*/
function main() {
}
# メッセージボックスを表示する
/*
* Menu: Hello > HelloWorld
*/
function main() {
Packages.org.eclipse.jface.dialogs.MessageDialog.openInformation(
window.getShell(),
"Monkey Dialog",
"Hello World"
)
}
## alert
alert文でもアラート表示できた。
alert("1");
## 他ファイルの読み込み
まず、下記のファイルを作成しておく
### LibHello.js
function lib_function() {
return "Hello libfunction";
}
### インクルード例
/*
* Menu: Hello > LibHello
*/
include("LibHello.js");
function main() {
alert(lib_function());
}
# Eclipse Monkeyで使えるオブジェクト
下記のようにコメント箇所に
* DOM: http://localhost/org.eclipse.eclipsemonkey.lang.javascript
をいれるとエクリプスのオブジェクトにアクセスできる
/*
* Menu: Views > Google Web View
* DOM: http://localhost/org.eclipse.eclipsemonkey.lang.javascript
*/
## 参考URL
http://d.hatena.ne.jp/ZoAmichi/20080801/1217631793
## ビューの取得
views.getView("GoogleWebView");
## Resourcesオブジェクトを取得
o Resources
+ Object[] filesMatching(String) ワークスペース上のパターンに一致するファイルオブジェクトを返します
## View
### void setHTML(String)
### void execute(String)
引数はorg.eclipse.swt.Browser#executeで実行するスクリプトです
### void showView(boolean)
### void setTitle(String)
### String url
### addEventListener(String, js関数)
これどこに定義されてるんですか?
## editorsオブジェクトを取得
### Editor[] all
開いてる全てのエディタ
### Editor
activeEditor 開いてるアクティブなエディタ
### String toString()
## Editorオブジェクト
### void applyEdit(int,int,String) 引数は(開始位置、置換される長さ、挿入するテキスト)
### void beginCompoundChange()
### void close(boolean)
引数にtrueで保存して閉じる
### void endCompoundChange()
### int getLineAtOffset(int) 指定したテキスト位置から行を取得
### int getOffsetAtLine(int) 指定した行のテキスト位置を取得
### void save()
### void selectAndReveal(int,int)
### String toString()
### String id
### String lineDelimiter
### int sourceLength
### [JSO] selectionRange 選択範囲。
{"startingOffset":開始位置,"endingOffset":終了位置}
+ String title
+ ITextEditor textEditor
+ int currentOffset 書き込み可能プロパティ
## io
未調査。
# Eclipse/保存と同時にブラウザを自動リロードする方法
http://tobysoft.net/wiki/index.php?Eclipse%2F%CA%DD%C2%B8%A4%C8%C6%B1%BB%FE%A4%CB%A5%D6%A5%E9%A5%A6%A5%B6%A4%F2%BC%AB%C6%B0%A5%EA%A5%ED%A1%BC%A5%C9%A4%B9%A4%EB%CA%FD%CB%A1
http://d.hatena.ne.jp/tomo_snowbug/20080809/1218294986