use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class LinkedModeUI method leave.
void leave(final int flags) {
if (!fIsActive)
return;
fIsActive = false;
endCompoundChangeIfNeeded();
Display display = null;
if (fCurrentTarget.fWidget != null && !fCurrentTarget.fWidget.isDisposed())
display = fCurrentTarget.fWidget.getDisplay();
if (fCurrentTarget.fAnnotationModel != null)
fCurrentTarget.fAnnotationModel.removeAllAnnotations();
disconnect();
for (LinkedModeUITarget fTarget : fTargets) {
LinkedModeUITarget target = fTarget;
ITextViewer viewer = target.getViewer();
if (target.fKeyListener != null) {
((ITextViewerExtension) viewer).removeVerifyKeyListener(target.fKeyListener);
target.fKeyListener = null;
}
viewer.removeTextInputListener(fCloser);
}
for (int i = 0; i < fTargets.length; i++) {
if (fTargets[i].fAnnotationModel != null) {
fTargets[i].fAnnotationModel.removeAllAnnotations();
fTargets[i].fAnnotationModel.disconnect(fTargets[i].getViewer().getDocument());
fTargets[i].fAnnotationModel = null;
}
uninstallAnnotationModel(fTargets[i]);
}
if ((flags & ILinkedModeListener.UPDATE_CARET) != 0 && fExitPosition != null && fFramePosition != fExitPosition && !fExitPosition.isDeleted())
switchPosition(fExitPosition, true, false);
final List<IDocument> docs = new ArrayList<>();
for (LinkedModeUITarget fTarget : fTargets) {
IDocument doc = fTarget.getViewer().getDocument();
if (doc != null)
docs.add(doc);
}
fModel.stopForwarding(flags);
Runnable runnable = new Runnable() {
@Override
public void run() {
if (fExitPosition != null)
fExitPosition.getDocument().removePosition(fExitPosition);
for (IDocument doc : docs) {
doc.removePositionUpdater(fPositionUpdater);
boolean uninstallCat = false;
String[] cats = doc.getPositionCategories();
for (String cat : cats) {
if (getCategory().equals(cat)) {
uninstallCat = true;
break;
}
}
if (uninstallCat)
try {
doc.removePositionCategory(getCategory());
} catch (BadPositionCategoryException e) {
// ignore
}
}
fModel.exit(flags);
}
};
// gets correct document offsets.
if (display != null)
display.asyncExec(runnable);
else
runnable.run();
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class LinkedModeUI method endCompoundChangeIfNeeded.
private void endCompoundChangeIfNeeded() {
if (fHasOpenCompoundChange) {
ITextViewerExtension extension = (ITextViewerExtension) fCurrentTarget.getViewer();
IRewriteTarget target = extension.getRewriteTarget();
target.endCompoundChange();
fHasOpenCompoundChange = false;
}
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class LinkedModeUI method connect.
private void connect() {
Assert.isNotNull(fCurrentTarget);
ITextViewer viewer = fCurrentTarget.getViewer();
Assert.isNotNull(viewer);
fCurrentTarget.fWidget = viewer.getTextWidget();
if (fCurrentTarget.fWidget == null)
leave(ILinkedModeListener.EXIT_ALL);
if (fCurrentTarget.fKeyListener == null) {
fCurrentTarget.fKeyListener = new KeyListener();
((ITextViewerExtension) viewer).prependVerifyKeyListener(fCurrentTarget.fKeyListener);
} else
fCurrentTarget.fKeyListener.setEnabled(true);
registerAutoEditVetoer(viewer);
((IPostSelectionProvider) viewer).addPostSelectionChangedListener(fSelectionListener);
createAnnotationModel();
showSelection();
fCurrentTarget.fShell = fCurrentTarget.fWidget.getShell();
if (fCurrentTarget.fShell == null)
leave(ILinkedModeListener.EXIT_ALL);
fCurrentTarget.fShell.addShellListener(fCloser);
fAssistant.install(viewer);
viewer.addTextInputListener(fCloser);
viewer.getDocument().addDocumentListener(fDocumentListener);
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class ContextInformationPopup method createContextSelector.
/**
* Creates the context selector in case the user has the choice between multiple valid contexts
* at a given offset.
*/
private void createContextSelector() {
if (Helper.okToUse(fContextSelectorShell))
return;
Control control = fContentAssistSubjectControlAdapter.getControl();
fContextSelectorShell = new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
GridLayout layout = new GridLayout();
layout.marginWidth = 0;
layout.marginHeight = 0;
fContextSelectorShell.setLayout(layout);
fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
fContextSelectorShell.addControlListener(new ControlListener() {
@Override
public void controlMoved(ControlEvent e) {
}
@Override
public void controlResized(ControlEvent e) {
fContextSelectorPopupSize = fContextSelectorShell.getSize();
}
});
if (fViewer instanceof ITextViewerExtension) {
final ITextViewerExtension textViewerExtension = (ITextViewerExtension) fViewer;
final StyledText textWidget = fViewer.getTextWidget();
final VerifyKeyListener verifyListener = new VerifyKeyListener() {
@Override
public void verifyKey(VerifyEvent event) {
if (isActive() && event.keyCode == 13 && event.character == '\r' && event.widget == textWidget) {
event.doit = false;
insertSelectedContext();
hideContextSelector();
}
}
};
textViewerExtension.prependVerifyKeyListener(verifyListener);
fContextSelectorShell.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent e) {
textViewerExtension.removeVerifyKeyListener(verifyListener);
}
});
}
fContextSelectorTable = new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
fContextSelectorTable.setLocation(1, 1);
GridData gd = new GridData(GridData.FILL_BOTH);
gd.heightHint = fContextSelectorTable.getItemHeight() * 10;
gd.widthHint = 300;
fContextSelectorTable.setLayoutData(gd);
Point size = fContentAssistant.restoreContextSelectorPopupSize();
if (size != null)
fContextSelectorShell.setSize(size);
else
fContextSelectorShell.pack(true);
Color c = fContentAssistant.getContextSelectorBackground();
if (c == null)
c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
fContextSelectorTable.setBackground(c);
c = fContentAssistant.getContextSelectorForeground();
if (c == null)
c = control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
fContextSelectorTable.setForeground(c);
fContextSelectorTable.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
insertSelectedContext();
hideContextSelector();
}
});
fPopupCloser.install(fContentAssistant, fContextSelectorTable);
fContextSelectorTable.setHeaderVisible(false);
fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class LineNumberRulerColumn method layout.
/**
* Layouts the enclosing viewer to adapt the layout to changes of the
* size of the individual components.
*
* @param redraw <code>true</code> if this column can be redrawn
*/
protected void layout(boolean redraw) {
if (!redraw) {
fRelayoutRequired = true;
return;
}
fRelayoutRequired = false;
if (fCachedTextViewer instanceof ITextViewerExtension) {
ITextViewerExtension extension = (ITextViewerExtension) fCachedTextViewer;
Control control = extension.getControl();
if (control instanceof Composite && !control.isDisposed()) {
Composite composite = (Composite) control;
composite.layout(true);
}
}
}
Aggregations