Search in sources :

Example 86 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class InlinedAnnotationSupport method install.

/**
 * Install the inlined annotation support for the given viewer.
 *
 * @param viewer the source viewer
 * @param painter the annotation painter to use to draw the inlined annotations.
 */
public void install(ISourceViewer viewer, AnnotationPainter painter) {
    Assert.isNotNull(viewer);
    Assert.isNotNull(painter);
    fViewer = viewer;
    fPainter = painter;
    initPainter();
    StyledText text = fViewer.getTextWidget();
    if (text == null || text.isDisposed()) {
        return;
    }
    if (fViewer instanceof ITextViewerExtension4) {
        updateStylesWidth = new UpdateStylesWidth();
        ((ITextViewerExtension4) fViewer).addTextPresentationListener(updateStylesWidth);
    }
    visibleLines = new VisibleLines();
    fViewer.addViewportListener(visibleLines);
    text.addMouseListener(fMouseTracker);
    text.addMouseTrackListener(fMouseTracker);
    text.addMouseMoveListener(fMouseTracker);
    setColor(text.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension4(org.eclipse.jface.text.ITextViewerExtension4)

Example 87 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class InlinedAnnotationSupport method uninstall.

/**
 * Unisntall the inlined annotation support
 */
public void uninstall() {
    StyledText text = this.fViewer.getTextWidget();
    if (text != null && !text.isDisposed()) {
        text.removeMouseListener(this.fMouseTracker);
        text.removeMouseTrackListener(this.fMouseTracker);
        text.removeMouseMoveListener(this.fMouseTracker);
    }
    if (fViewer != null) {
        if (fViewer instanceof ITextViewerExtension4) {
            ((ITextViewerExtension4) fViewer).removeTextPresentationListener(updateStylesWidth);
        }
        fViewer.removeViewportListener(visibleLines);
    }
    if (visibleLines != null) {
        visibleLines.uninstall();
        visibleLines = null;
    }
    disposeFont();
    fViewer = null;
    fPainter = null;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextViewerExtension4(org.eclipse.jface.text.ITextViewerExtension4)

Example 88 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method initializeFindScopeColor.

/**
 * Initializes the background color used for highlighting the document ranges
 * defining search scopes.
 *
 * @param viewer the viewer to initialize
 * @since 2.0
 */
private void initializeFindScopeColor(ISourceViewer viewer) {
    IPreferenceStore store = getPreferenceStore();
    if (store != null) {
        StyledText styledText = viewer.getTextWidget();
        Color color = createColor(store, PREFERENCE_COLOR_FIND_SCOPE, styledText.getDisplay());
        IFindReplaceTarget target = viewer.getFindReplaceTarget();
        if (target != null && target instanceof IFindReplaceTargetExtension)
            ((IFindReplaceTargetExtension) target).setScopeHighlightColor(color);
        if (fFindScopeHighlightColor != null)
            fFindScopeHighlightColor.dispose();
        fFindScopeHighlightColor = color;
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Color(org.eclipse.swt.graphics.Color) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IFindReplaceTarget(org.eclipse.jface.text.IFindReplaceTarget) IFindReplaceTargetExtension(org.eclipse.jface.text.IFindReplaceTargetExtension)

Example 89 with StyledText

use of org.eclipse.swt.custom.StyledText 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());
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) ITextListener(org.eclipse.jface.text.ITextListener) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) ISaveablesLifecycleListener(org.eclipse.ui.ISaveablesLifecycleListener) IPartListener(org.eclipse.ui.IPartListener) KeyListener(org.eclipse.swt.events.KeyListener) GestureListener(org.eclipse.swt.events.GestureListener) IDocumentListener(org.eclipse.jface.text.IDocumentListener) Listener(org.eclipse.swt.widgets.Listener) ITextInputListener(org.eclipse.jface.text.ITextInputListener) VerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener) VerifyListener(org.eclipse.swt.events.VerifyListener) MouseListener(org.eclipse.swt.events.MouseListener) IWindowListener(org.eclipse.ui.IWindowListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetListener(org.eclipse.swt.dnd.DropTargetListener) IVerticalRuler(org.eclipse.jface.text.source.IVerticalRuler) CompositeRuler(org.eclipse.jface.text.source.CompositeRuler) ISourceViewerExtension3(org.eclipse.jface.text.source.ISourceViewerExtension3) ISourceViewerExtension4(org.eclipse.jface.text.source.ISourceViewerExtension4) Point(org.eclipse.swt.graphics.Point) SourceViewerConfiguration(org.eclipse.jface.text.source.SourceViewerConfiguration) Control(org.eclipse.swt.widgets.Control) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SaveablesLifecycleEvent(org.eclipse.ui.SaveablesLifecycleEvent) DragSourceEvent(org.eclipse.swt.dnd.DragSourceEvent) TextEvent(org.eclipse.jface.text.TextEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) MouseEvent(org.eclipse.swt.events.MouseEvent) GestureEvent(org.eclipse.swt.events.GestureEvent) DocumentEvent(org.eclipse.jface.text.DocumentEvent) Event(org.eclipse.swt.widgets.Event) VerifyEvent(org.eclipse.swt.events.VerifyEvent) IQuickAssistAssistant(org.eclipse.jface.text.quickassist.IQuickAssistAssistant)

Example 90 with StyledText

use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method setWordWrap.

/**
 * @see org.eclipse.ui.texteditor.ITextEditorExtension6#setWordWrap(boolean)
 * @since 3.10
 */
@Override
public void setWordWrap(boolean enable) {
    if (!isWordWrapSupported() || isWordWrapEnabled() == enable) {
        return;
    }
    ISourceViewer viewer = getSourceViewer();
    if (viewer != null) {
        StyledText styledText = viewer.getTextWidget();
        if (styledText != null) {
            if (isBlockSelectionModeEnabled()) {
                setBlockSelectionMode(false);
            }
            styledText.setWordWrap(enable);
            if (fVerticalRuler != null) {
                // update ruler layout so that it can consider
                // changed horizontal scrollbar visibility
                boolean updated = false;
                if (viewer instanceof ITextViewerExtension) {
                    Control control = ((ITextViewerExtension) viewer).getControl();
                    if (control instanceof Composite) {
                        ((Composite) control).layout();
                        updated = true;
                    }
                }
                if (!updated) {
                    fVerticalRuler.update();
                }
            }
        }
    }
}
Also used : ITextViewerExtension(org.eclipse.jface.text.ITextViewerExtension) Control(org.eclipse.swt.widgets.Control) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer)

Aggregations

StyledText (org.eclipse.swt.custom.StyledText)329 Point (org.eclipse.swt.graphics.Point)102 GridData (org.eclipse.swt.layout.GridData)68 Composite (org.eclipse.swt.widgets.Composite)63 GridLayout (org.eclipse.swt.layout.GridLayout)62 Control (org.eclipse.swt.widgets.Control)46 SelectionEvent (org.eclipse.swt.events.SelectionEvent)32 Label (org.eclipse.swt.widgets.Label)32 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Display (org.eclipse.swt.widgets.Display)30 Shell (org.eclipse.swt.widgets.Shell)30 Rectangle (org.eclipse.swt.graphics.Rectangle)27 Color (org.eclipse.swt.graphics.Color)25 FillLayout (org.eclipse.swt.layout.FillLayout)25 Button (org.eclipse.swt.widgets.Button)23 Text (org.eclipse.swt.widgets.Text)21 StyleRange (org.eclipse.swt.custom.StyleRange)20 Font (org.eclipse.swt.graphics.Font)20 Event (org.eclipse.swt.widgets.Event)20 Test (org.junit.Test)20