選択したコードのセクション (マウス選択で選択) を Eclipse エディターで置き換え/* selected text */、プラグインを介してのみ同じコードに置き換えるにはどうすればよいですか? ツールバーにボタンを作成するためのプラグインを既に設計しています。クリックすると、選択したテキストを変更して に入れる必要があります/* */。
3009 次
1 に答える
8
このスニペットを試してみてください。仕事をするのに十分なヒントが得られるはずです:
try {
IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
if ( part instanceof ITextEditor ) {
final ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorInput() );
ISelection sel = editor.getSelectionProvider().getSelection();
if ( sel instanceof TextSelection ) {
final TextSelection textSel = (TextSelection)sel;
String newText = "/*" + textSel.getText() + "*/";
doc.replace( textSel.getOffset(), textSel.getLength(), newText );
}
}
} catch ( Exception ex ) {
ex.printStackTrace();
}
于 2009-08-26T06:21:42.160 に答える