Search in sources :

Example 1 with LinkedPositionGroup

use of org.eclipse.jface.text.link.LinkedPositionGroup in project ow by vtst.

the class AbstractCompletionProposal method setUpLinkedMode.

/**
   * Set up the linked mode for the replacement text.
   * @param document  The document in which the replacement is made.
   * @param replacementOffset  The offset at which the replacement is made.
   * @param fragments   The fragments to insert.
   * @param closingChar  The closing character (used for the exit mode).
   * @throws BadLocationException
   */
private void setUpLinkedMode(IDocument document, int replacementOffset, Iterable<Fragment> fragments) throws BadLocationException {
    int currentOffset = replacementOffset;
    boolean hasLinkedFragment = false;
    LinkedModeModel model = new LinkedModeModel();
    for (Fragment fragment : fragments) {
        int length = fragment.getText().length();
        if (fragment instanceof LinkedFragment) {
            LinkedPositionGroup group = new LinkedPositionGroup();
            group.addPosition(new LinkedPosition(document, currentOffset, length, LinkedPositionGroup.NO_STOP));
            model.addGroup(group);
            hasLinkedFragment = true;
        }
        currentOffset += length;
    }
    if (!hasLinkedFragment)
        return;
    model.forceInstall();
    LinkedModeUI ui = new EditorLinkedModeUI(model, context.getViewer());
    ui.setExitPosition(context.getViewer(), currentOffset, 0, Integer.MAX_VALUE);
    ui.setExitPolicy(new ExitPolicy(makeExitCharactersForLinkedMode(), document));
    ui.setDoContextInfo(true);
    ui.setCyclingMode(LinkedModeUI.CYCLE_WHEN_NO_PARENT);
    ui.enter();
    IRegion region = ui.getSelectedRegion();
    regionToSelect = new Point(region.getOffset(), region.getLength());
}
Also used : IExitPolicy(org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy) LinkedPositionGroup(org.eclipse.jface.text.link.LinkedPositionGroup) LinkedPosition(org.eclipse.jface.text.link.LinkedPosition) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) LinkedModeModel(org.eclipse.jface.text.link.LinkedModeModel) LinkedModeUI(org.eclipse.jface.text.link.LinkedModeUI) EditorLinkedModeUI(org.eclipse.ui.texteditor.link.EditorLinkedModeUI) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) IRegion(org.eclipse.jface.text.IRegion)

Aggregations

IRegion (org.eclipse.jface.text.IRegion)1 LinkedModeModel (org.eclipse.jface.text.link.LinkedModeModel)1 LinkedModeUI (org.eclipse.jface.text.link.LinkedModeUI)1 IExitPolicy (org.eclipse.jface.text.link.LinkedModeUI.IExitPolicy)1 LinkedPosition (org.eclipse.jface.text.link.LinkedPosition)1 LinkedPositionGroup (org.eclipse.jface.text.link.LinkedPositionGroup)1 Point (org.eclipse.swt.graphics.Point)1 EditorLinkedModeUI (org.eclipse.ui.texteditor.link.EditorLinkedModeUI)1