Eclipse開發經驗:文本替換和操作介面

來源:互聯網
上載者:User

快速Eclipse外掛程式開發經驗:

1.取得對當前選中常值內容,並轉換。

1)定義Action實現IEditorActionDelegate介面。

2)取得當前編輯器(getEditor())。

PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();

3)取得選中文本。

(ITextSelection) getEditor().getEditorSite().getSelectionProvider().getSelection();

4)替換選中文本。

AbstractTextEditor editor = (AbstractTextEditor) getEditor();

editor.getDocumentProvider().getDocument(editor.getEditorInput());

document.replace(offset, length, replaceText);

5)選中替換後的文本。

ITextSelection tsNew = new TextSelection(document, offset, length);

getEditor().getEditorSite().getSelectionProvider().setSelection(tsNew);

2.菜單分組,表徵圖,快速鍵,工具條的實現。

1)菜單分組。如下分成4組,組之間有分隔線。

<menu label="XXXXTools(&amp;T)" id="XXXXToolsMenu">
<separator name="XXXXToolsGroupTxt"></separator>
<separator name="XXXXToolsGroupSql"></separator>
<separator name="XXXXToolsGroupCode"></separator>
<separator name="XXXXToolsGroupRefrence"></separator>
</menu>

2)分配Action到組。設定表徵圖。和工具條。

<action label="To Lower Case(&amp;L)"
    class="XXXXTools.actions.text.ToLowerCaseAction"
    icon="icons/lower.gif"
    menubarPath="XXXXToolsMenu/XXXXToolsGroupTxt"
    toolbarPath="XXXXToolsGroupTxt"
    id="XXXXTools.actions.text.ToLowerCaseAction"
    definitionId="XXXXTools.actions.text.ToLowerCaseAction">
    <selection class="org.eclipse.jface.text.ITextSelection" />
</action>

3)設定快速鍵。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.