Eclipse Development Experience: Text substitution and Operation interface

Source: Internet
Author: User

Fast Eclipse plug-in development experience:

1. Gets the contents of the currently selected text and converts it.

1 defines the action implementation Ieditoractiondelegate interface.

2 Gets the current editor (Geteditor ()).

Platformui.getworkbench (). Getactiveworkbenchwindow (). GetActivePage (). Getactiveeditor ();

3) Get the selected text.

(itextselection) Geteditor (). Geteditorsite (). Getselectionprovider (). GetSelection ();

4) Replace the selected text.

Abstracttexteditor editor = (abstracttexteditor) geteditor ();

Editor.getdocumentprovider (). GetDocument (Editor.geteditorinput ());

Document.replace (offset, length, replacetext);

5 Select the replaced text.

Itextselection tsnew = new TextSelection (document, offset, length);

Geteditor (). Geteditorsite (). Getselectionprovider (). SetSelection (tsnew);

2. Menu grouping, icons, shortcuts, implementation of the sidebar.

1) Menu grouping. If divided into 4 groups, there is a dividing line between the groups.

<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 Assign action to group. Set the icon. and tool bars.

<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) Set the shortcut key.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.