use of org.eclipse.jface.text.source.ISourceViewerExtension4 in project xtext-eclipse by eclipse.
the class XtextReconciler method uninstall.
@Override
public void uninstall() {
if (isInstalled) {
textViewer.removeTextInputListener(textInputListener);
isInstalled = false;
if (documentListener != null) {
if (textViewer instanceof ISourceViewerExtension4) {
ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade();
facade.removeCompletionListener(documentListener);
}
if (textViewer.getDocument() instanceof IXtextDocument) {
((IXtextDocument) textViewer.getDocument()).removeXtextDocumentContentObserver(documentListener);
}
}
cancel();
}
}
use of org.eclipse.jface.text.source.ISourceViewerExtension4 in project xtext-eclipse by eclipse.
the class XtextReconciler method handleInputDocumentChanged.
protected void handleInputDocumentChanged(IDocument oldInput, IDocument newInput) {
if (Display.getCurrent() == null) {
log.error("Changes to the document must only be applied from the Display thread to keep them ordered", new Exception());
}
if (shouldInstallCompletionListener) {
ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade();
if (facade != null) {
facade.addCompletionListener(documentListener);
}
shouldInstallCompletionListener = false;
}
if (oldInput != newInput) {
if (oldInput instanceof IXtextDocument) {
((IXtextDocument) oldInput).removeXtextDocumentContentObserver(documentListener);
}
if (newInput instanceof IXtextDocument) {
((IXtextDocument) newInput).addXtextDocumentContentObserver(documentListener);
final IXtextDocument document = XtextDocumentUtil.get(textViewer);
strategy.setDocument(document);
if (!initalProcessDone && strategy instanceof IReconcilingStrategyExtension) {
initalProcessDone = true;
IReconcilingStrategyExtension reconcilingStrategyExtension = (IReconcilingStrategyExtension) strategy;
reconcilingStrategyExtension.initialReconcile();
}
}
}
if (oldInput != null && newInput != null) {
handleDocumentChanged(new InputChangedDocumentEvent(oldInput, newInput));
}
}
use of org.eclipse.jface.text.source.ISourceViewerExtension4 in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createPartControl.
/**
* The <code>AbstractTextEditor</code> implementation of this
* <code>IWorkbenchPart</code> method creates the vertical ruler and
* source viewer.
* <p>
* Subclasses may extend this method. Besides extending this method, the
* behavior of <code>createPartControl</code> may be customized by
* calling, extending or replacing the following methods: <br>
* Subclasses may supply customized implementations for some members using
* the following methods before <code>createPartControl</code> is invoked:
* <ul>
* <li>
* {@linkplain #setSourceViewerConfiguration(SourceViewerConfiguration) setSourceViewerConfiguration}
* to supply a custom source viewer configuration,</li>
* <li>{@linkplain #setRangeIndicator(Annotation) setRangeIndicator} to
* provide a range indicator,</li>
* <li>{@linkplain #setHelpContextId(String) setHelpContextId} to provide a
* help context id,</li>
* <li>{@linkplain #setEditorContextMenuId(String) setEditorContextMenuId}
* to set a custom context menu id,</li>
* <li>{@linkplain #setRulerContextMenuId(String) setRulerContextMenuId} to
* set a custom ruler context menu id.</li>
* </ul>
* <br>
* Subclasses may replace the following methods called from within
* <code>createPartControl</code>:
* <ul>
* <li>{@linkplain #createVerticalRuler() createVerticalRuler} to supply a
* custom vertical ruler,</li>
* <li>{@linkplain #createSourceViewer(Composite, IVerticalRuler, int) createSourceViewer}
* to supply a custom source viewer,</li>
* <li>{@linkplain #getSelectionProvider() getSelectionProvider} to supply
* a custom selection provider.</li>
* </ul>
* <br>
* Subclasses may extend the following methods called from within
* <code>createPartControl</code>:
* <ul>
* <li>
* {@linkplain #initializeViewerColors(ISourceViewer) initializeViewerColors}
* to customize the viewer color scheme (may also be replaced),</li>
* <li>
* {@linkplain #initializeDragAndDrop(ISourceViewer) initializeDragAndDrop}
* to customize drag and drop (may also be replaced),</li>
* <li>{@linkplain #createNavigationActions() createNavigationActions} to
* add navigation actions,</li>
* <li>{@linkplain #createActions() createActions} to add text editor
* actions.</li>
* </ul>
* </p>
*
* @param parent the parent composite
*/
@Override
public void createPartControl(Composite parent) {
fVerticalRuler = createVerticalRuler();
int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
fSourceViewer = createSourceViewer(parent, fVerticalRuler, styles);
if (fConfiguration == null)
fConfiguration = new SourceViewerConfiguration();
fSourceViewer.configure(fConfiguration);
if (fSourceViewer instanceof ISourceViewerExtension4)
fKeyBindingSupportForContentAssistant = new KeyBindingSupportForAssistant(((ISourceViewerExtension4) fSourceViewer));
if (fSourceViewer instanceof ISourceViewerExtension3) {
IQuickAssistAssistant assistant = ((ISourceViewerExtension3) fSourceViewer).getQuickAssistAssistant();
if (assistant != null)
fKeyBindingSupportForQuickAssistant = new KeyBindingSupportForAssistant(assistant);
}
if (fRangeIndicator != null)
fSourceViewer.setRangeIndicator(fRangeIndicator);
fSourceViewer.addTextListener(fTextListener);
fSourceViewer.addTextInputListener(fTextListener);
getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener());
initializeViewerFont(fSourceViewer);
initializeViewerColors(fSourceViewer);
initializeFindScopeColor(fSourceViewer);
initializeDragAndDrop(fSourceViewer);
StyledText styledText = fSourceViewer.getTextWidget();
styledText.addMouseListener(getCursorListener());
styledText.addKeyListener(getCursorListener());
// Disable orientation switching until we fully support it.
styledText.addListener(SWT.OrientationChange, new Listener() {
@Override
public void handleEvent(Event event) {
event.doit = false;
}
});
if (getHelpContextId() != null)
PlatformUI.getWorkbench().getHelpSystem().setHelp(styledText, getHelpContextId());
String id = fEditorContextMenuId != null ? fEditorContextMenuId : DEFAULT_EDITOR_CONTEXT_MENU_ID;
MenuManager manager = new MenuManager(id, id);
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(getContextMenuListener());
fTextContextMenu = manager.createContextMenu(styledText);
styledText.setMenu(fTextContextMenu);
if (fEditorContextMenuId != null)
getEditorSite().registerContextMenu(fEditorContextMenuId, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
else if (fCompatibilityMode)
getEditorSite().registerContextMenu(DEFAULT_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
if ((fEditorContextMenuId != null && fCompatibilityMode) || fEditorContextMenuId == null) {
String partId = getEditorSite().getId();
if (partId != null)
// $NON-NLS-1$
getEditorSite().registerContextMenu(partId + ".EditorContext", manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
}
getEditorSite().registerContextMenu(COMMON_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if (fEditorContextMenuId == null)
fEditorContextMenuId = DEFAULT_EDITOR_CONTEXT_MENU_ID;
id = fRulerContextMenuId != null ? fRulerContextMenuId : DEFAULT_RULER_CONTEXT_MENU_ID;
manager = new MenuManager(id, id);
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(getContextMenuListener());
Control rulerControl = fVerticalRuler.getControl();
fRulerContextMenu = manager.createContextMenu(rulerControl);
rulerControl.setMenu(fRulerContextMenu);
rulerControl.addMouseListener(getRulerMouseListener());
if (fRulerContextMenuId != null)
getEditorSite().registerContextMenu(fRulerContextMenuId, manager, getSelectionProvider(), false);
else if (fCompatibilityMode)
getEditorSite().registerContextMenu(DEFAULT_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if ((fRulerContextMenuId != null && fCompatibilityMode) || fRulerContextMenuId == null) {
String partId = getSite().getId();
if (partId != null)
// $NON-NLS-1$
getEditorSite().registerContextMenu(partId + ".RulerContext", manager, getSelectionProvider(), false);
}
getEditorSite().registerContextMenu(COMMON_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if (fRulerContextMenuId == null)
fRulerContextMenuId = DEFAULT_RULER_CONTEXT_MENU_ID;
initializeZoomGestures(rulerControl, fSourceViewer);
getSite().setSelectionProvider(getSelectionProvider());
fSelectionListener = new SelectionListener();
fSelectionListener.install(getSelectionProvider());
fSelectionListener.setDocument(getDocumentProvider().getDocument(getEditorInput()));
initializeActivationCodeTrigger();
createNavigationActions();
createAccessibilityActions();
createActions();
initializeSourceViewer(getEditorInput());
/* since 3.2 - undo redo actions should be created after
* the source viewer is initialized, so that the undo manager
* can obtain its undo context from its document.
*/
createUndoRedoActions();
JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
IVerticalRuler ruler = getVerticalRuler();
if (ruler instanceof CompositeRuler)
updateContributedRulerColumns((CompositeRuler) ruler);
if (isWordWrapSupported()) {
setWordWrap(getInitialWordWrapStatus());
}
}
use of org.eclipse.jface.text.source.ISourceViewerExtension4 in project xtext-eclipse by eclipse.
the class XtextReconciler method install.
@Override
public void install(ITextViewer textViewer) {
if (!isInstalled) {
this.textViewer = textViewer;
textInputListener = new TextInputListener();
textViewer.addTextInputListener(textInputListener);
handleInputDocumentChanged(null, textViewer.getDocument());
if (textViewer instanceof ISourceViewerExtension4) {
ContentAssistantFacade facade = ((ISourceViewerExtension4) textViewer).getContentAssistantFacade();
if (facade == null) {
shouldInstallCompletionListener = true;
} else {
facade.addCompletionListener(documentListener);
}
if (strategy instanceof ISourceViewerAware) {
((ISourceViewerAware) strategy).setSourceViewer((ISourceViewer) textViewer);
}
}
isInstalled = true;
}
}
Aggregations