Search in sources :

Example 1 with ITextViewerExtension8

use of org.eclipse.jface.text.ITextViewerExtension8 in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method handlePreferenceStoreChanged.

/**
 * Handles a property change event describing a change of the editor's
 * preference store and updates the preference related editor properties.
 * <p>
 * Subclasses may extend.
 * </p>
 *
 * @param event the property change event
 */
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
    if (fSourceViewer == null)
        return;
    String property = event.getProperty();
    if (getFontPropertyPreferenceKey().equals(property))
        // There is a separate handler for font preference changes
        return;
    if (PREFERENCE_COLOR_FOREGROUND.equals(property) || PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT.equals(property)) {
        initializeViewerColors(fSourceViewer);
    } else if (PREFERENCE_COLOR_FIND_SCOPE.equals(property)) {
        initializeFindScopeColor(fSourceViewer);
    } else if (PREFERENCE_USE_CUSTOM_CARETS.equals(property)) {
        updateCaret();
    } else if (PREFERENCE_WIDE_CARET.equals(property)) {
        updateCaret();
    }
    if (affectsTextPresentation(event))
        fSourceViewer.invalidateTextPresentation();
    if (PREFERENCE_HYPERLINKS_ENABLED.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension6) {
            IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
            int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
            ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
            textViewer6.setHyperlinkDetectors(detectors, stateMask);
        }
        return;
    }
    if (PREFERENCE_HYPERLINK_KEY_MODIFIER.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension6) {
            ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
            IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
            int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
            textViewer6.setHyperlinkDetectors(detectors, stateMask);
        }
        return;
    }
    if (PREFERENCE_RULER_CONTRIBUTIONS.equals(property)) {
        String[] difference = StringSetSerializer.getDifference((String) event.getOldValue(), (String) event.getNewValue());
        IColumnSupport support = getAdapter(IColumnSupport.class);
        for (int i = 0; i < difference.length; i++) {
            RulerColumnDescriptor desc = RulerColumnRegistry.getDefault().getColumnDescriptor(difference[i]);
            if (desc != null && support.isColumnSupported(desc)) {
                boolean newState = !support.isColumnVisible(desc);
                support.setColumnVisible(desc, newState);
            }
        }
        return;
    }
    if (PREFERENCE_SHOW_WHITESPACE_CHARACTERS.equals(property) || PREFERENCE_SHOW_LEADING_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_TABS.equals(property) || PREFERENCE_SHOW_ENCLOSED_TABS.equals(property) || PREFERENCE_SHOW_TRAILING_TABS.equals(property) || PREFERENCE_SHOW_CARRIAGE_RETURN.equals(property) || PREFERENCE_SHOW_LINE_FEED.equals(property) || PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE.equals(property)) {
        IAction action = getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
        if (action instanceof IUpdate)
            ((IUpdate) action).update();
        return;
    }
    if (PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED.equals(property)) {
        IPreferenceStore store = getPreferenceStore();
        if (store != null && store.getBoolean(PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED))
            installTextDragAndDrop(getSourceViewer());
        else
            uninstallTextDragAndDrop(getSourceViewer());
        return;
    }
    if (PREFERENCE_HOVER_ENRICH_MODE.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension8) {
            IPreferenceStore store = getPreferenceStore();
            if (store != null) {
                ((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)));
            }
        }
        return;
    }
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) IAction(org.eclipse.jface.action.IAction) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) Point(org.eclipse.swt.graphics.Point) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 2 with ITextViewerExtension8

use of org.eclipse.jface.text.ITextViewerExtension8 in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method initializeSourceViewer.

/**
 * Initializes the editor's source viewer based on the given editor input.
 *
 * @param input the editor input to be used to initialize the source viewer
 */
private void initializeSourceViewer(IEditorInput input) {
    IDocumentProvider documentProvider = getDocumentProvider();
    IAnnotationModel model = documentProvider.getAnnotationModel(input);
    IDocument document = documentProvider.getDocument(input);
    if (document != null) {
        fSourceViewer.setDocument(document, model);
        fSourceViewer.setEditable(isEditable());
        fSourceViewer.showAnnotations(model != null);
    }
    if (fElementStateListener instanceof IElementStateListenerExtension) {
        boolean isStateValidated = false;
        if (documentProvider instanceof IDocumentProviderExtension)
            isStateValidated = ((IDocumentProviderExtension) documentProvider).isStateValidated(input);
        IElementStateListenerExtension extension = (IElementStateListenerExtension) fElementStateListener;
        extension.elementStateValidationChanged(input, isStateValidated);
    }
    if (fInitialCaret == null)
        fInitialCaret = fSourceViewer.getTextWidget().getCaret();
    if (fIsOverwriting)
        fSourceViewer.getTextWidget().invokeAction(ST.TOGGLE_OVERWRITE);
    handleInsertModeChanged();
    if (isTabsToSpacesConversionEnabled())
        installTabsToSpacesConverter();
    if (fSourceViewer instanceof ITextViewerExtension8) {
        IPreferenceStore store = getPreferenceStore();
        EnrichMode mode = store != null ? convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)) : EnrichMode.AFTER_DELAY;
        ((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(mode);
    }
    if (fSourceViewer instanceof ISourceViewerExtension5)
        installCodeMiningProviders();
}
Also used : ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) ISourceViewerExtension5(org.eclipse.jface.text.source.ISourceViewerExtension5) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) EnrichMode(org.eclipse.jface.text.ITextViewerExtension8.EnrichMode) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with ITextViewerExtension8

use of org.eclipse.jface.text.ITextViewerExtension8 in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method createPrintAction.

/**
 * Creates and registers the print action.
 *
 * @since 3.4
 */
private void createPrintAction() {
    final ISourceViewer viewer = getSourceViewer();
    ResourceAction action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.Print.") {

        @Override
        public void run() {
            StyledTextPrintOptions options = new StyledTextPrintOptions();
            options.printTextFontStyle = true;
            options.printTextForeground = true;
            options.printTextBackground = true;
            options.jobName = getTitle();
            options.header = StyledTextPrintOptions.SEPARATOR + getTitle();
            options.footer = StyledTextPrintOptions.SEPARATOR + NLSUtility.format(TextEditorMessages.AbstractDecoratedTextEditor_printPageNumber, StyledTextPrintOptions.PAGE_TAG);
            if (isLineNumberRulerVisible()) {
                options.printLineNumbers = true;
                // Compute line number labels
                options.lineLabels = new String[viewer.getTextWidget().getLineCount()];
                for (int i = 0; i < options.lineLabels.length; i++) options.lineLabels[i] = String.valueOf(JFaceTextUtil.widgetLine2ModelLine(viewer, i) + 1);
            }
            ((ITextViewerExtension8) viewer).print(options);
        }
    };
    action.setHelpContextId(IAbstractTextEditorHelpContextIds.PRINT_ACTION);
    action.setActionDefinitionId(IWorkbenchCommandConstants.FILE_PRINT);
    setAction(ITextEditorActionConstants.PRINT, action);
}
Also used : StyledTextPrintOptions(org.eclipse.swt.custom.StyledTextPrintOptions) ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Point(org.eclipse.swt.graphics.Point)

Example 4 with ITextViewerExtension8

use of org.eclipse.jface.text.ITextViewerExtension8 in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method createActions.

@Override
protected void createActions() {
    super.createActions();
    // $NON-NLS-1$
    ResourceAction action = new AddMarkerAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.AddBookmark.", this, IMarker.BOOKMARK, true);
    action.setHelpContextId(ITextEditorHelpContextIds.BOOKMARK_ACTION);
    action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_ADD_BOOKMARK);
    setAction(IDEActionFactory.BOOKMARK.getId(), action);
    // $NON-NLS-1$
    action = new AddTaskAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.AddTask.", this);
    action.setHelpContextId(ITextEditorHelpContextIds.ADD_TASK_ACTION);
    action.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_ADD_TASK);
    setAction(IDEActionFactory.ADD_TASK.getId(), action);
    // $NON-NLS-1$
    action = new ChangeEncodingAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ChangeEncodingAction.", this);
    action.setHelpContextId(ITextEditorHelpContextIds.CHANGE_ENCODING);
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.CHANGE_ENCODING);
    setAction(ITextEditorActionConstants.CHANGE_ENCODING, action);
    markAsPropertyDependentAction(ITextEditorActionConstants.CHANGE_ENCODING, true);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.ToggleLineNumbersAction.", // $NON-NLS-1$
    IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            toggleLineNumberRuler();
        }
    };
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.LINENUMBER_TOGGLE);
    setAction(ITextEditorActionConstants.LINENUMBERS_TOGGLE, action);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.ToggleQuickDiffAction.", // $NON-NLS-1$
    IAction.AS_CHECK_BOX) {

        @Override
        public void run() {
            toggleQuickDiffRuler();
        }
    };
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICKDIFF_TOGGLE);
    setAction(ITextEditorActionConstants.QUICKDIFF_TOGGLE, action);
    action = new RevertLineAction(this, false);
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICKDIFF_REVERTLINE);
    setAction(ITextEditorActionConstants.QUICKDIFF_REVERTLINE, action);
    action = new RevertSelectionAction(this, false);
    setAction(ITextEditorActionConstants.QUICKDIFF_REVERTSELECTION, action);
    action = new RevertBlockAction(this, false);
    setAction(ITextEditorActionConstants.QUICKDIFF_REVERTBLOCK, action);
    action = new RestoreAction(this, false);
    setAction(ITextEditorActionConstants.QUICKDIFF_REVERTDELETION, action);
    IAction action2 = new CompositeRevertAction(this, new IAction[] { getAction(ITextEditorActionConstants.QUICKDIFF_REVERTSELECTION), getAction(ITextEditorActionConstants.QUICKDIFF_REVERTBLOCK), getAction(ITextEditorActionConstants.QUICKDIFF_REVERTDELETION), getAction(ITextEditorActionConstants.QUICKDIFF_REVERTLINE) });
    action2.setActionDefinitionId(ITextEditorActionDefinitionIds.QUICKDIFF_REVERT);
    setAction(ITextEditorActionConstants.QUICKDIFF_REVERT, action2);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.HideRevisionInformationAction.") {

        @Override
        public void run() {
            if (fLineColumn != null)
                fLineColumn.hideRevisionInformation();
        }
    };
    setAction(ITextEditorActionConstants.REVISION_HIDE_INFO, action);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.CycleRevisionRenderingAction.") {

        @Override
        public void run() {
            final RenderingMode[] modes = { IRevisionRulerColumnExtension.AGE, IRevisionRulerColumnExtension.AUTHOR, IRevisionRulerColumnExtension.AUTHOR_SHADED_BY_AGE };
            IPreferenceStore store = EditorsUI.getPreferenceStore();
            String current = store.getString(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE);
            for (int i = 0; i < modes.length; i++) {
                String mode = modes[i].name();
                if (mode.equals(current)) {
                    int nextIndex = (i + 1) % modes.length;
                    RenderingMode nextMode = modes[nextIndex];
                    store.setValue(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, nextMode.name());
                }
            }
        }
    };
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.REVISION_RENDERING_CYCLE);
    setAction(ITextEditorActionConstants.REVISION_RENDERING_CYCLE, action);
    // $NON-NLS-1$
    action = new BooleanPreferenceToggleAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ToggleRevisionAuthorAction.", IAction.AS_CHECK_BOX, EditorsUI.getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_AUTHOR);
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.REVISION_AUTHOR_TOGGLE);
    setAction(ITextEditorActionConstants.REVISION_SHOW_AUTHOR_TOGGLE, action);
    // $NON-NLS-1$
    action = new BooleanPreferenceToggleAction(TextEditorMessages.getBundleForConstructedKeys(), "Editor.ToggleRevisionIdAction.", IAction.AS_CHECK_BOX, EditorsUI.getPreferenceStore(), AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_REVISION);
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.REVISION_ID_TOGGLE);
    setAction(ITextEditorActionConstants.REVISION_SHOW_ID_TOGGLE, action);
    final Shell shell;
    if (getSourceViewer() != null)
        shell = getSourceViewer().getTextWidget().getShell();
    else
        shell = null;
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.RulerPreferencesAction.") {

        @Override
        public void run() {
            String[] preferencePages = collectRulerMenuPreferencePages();
            if (preferencePages.length > 0 && (shell == null || !shell.isDisposed()))
                PreferencesUtil.createPreferenceDialogOn(shell, preferencePages[0], preferencePages, null).open();
        }
    };
    setAction(ITextEditorActionConstants.RULER_PREFERENCES, action);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.ContextPreferencesAction.") {

        @Override
        public void run() {
            String[] preferencePages = collectContextMenuPreferencePages();
            if (preferencePages.length > 0 && (shell == null || !shell.isDisposed()))
                PreferencesUtil.createPreferenceDialogOn(shell, preferencePages[0], preferencePages, null).open();
        }
    };
    setAction(ITextEditorActionConstants.CONTEXT_PREFERENCES, action);
    IAction showWhitespaceCharactersAction = getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
    if (showWhitespaceCharactersAction instanceof ShowWhitespaceCharactersAction)
        ((ShowWhitespaceCharactersAction) showWhitespaceCharactersAction).setPreferenceStore(EditorsUI.getPreferenceStore());
    setAction(ITextEditorActionConstants.REFRESH, new RefreshEditorAction(this));
    markAsPropertyDependentAction(ITextEditorActionConstants.REFRESH, true);
    // Override print action to provide additional options
    if (getAction(ITextEditorActionConstants.PRINT).isEnabled() && getSourceViewer() instanceof ITextViewerExtension8)
        createPrintAction();
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.ShowChangeRulerInformation.", // $NON-NLS-1$
    IAction.AS_PUSH_BUTTON) {

        @Override
        public void run() {
            showChangeRulerInformation();
        }
    };
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_CHANGE_RULER_INFORMATION_ID);
    setAction(ITextEditorActionConstants.SHOW_CHANGE_RULER_INFORMATION, action);
    action = new // $NON-NLS-1$
    ResourceAction(// $NON-NLS-1$
    TextEditorMessages.getBundleForConstructedKeys(), // $NON-NLS-1$
    "Editor.ShowRulerAnnotationInformation.", // $NON-NLS-1$
    IAction.AS_PUSH_BUTTON) {

        @Override
        public void run() {
            showRulerAnnotationInformation();
        }
    };
    action.setActionDefinitionId(ITextEditorActionDefinitionIds.SHOW_RULER_ANNOTATION_INFORMATION_ID);
    setAction(ITextEditorActionConstants.SHOW_RULER_ANNOTATION_INFORMATION, action);
}
Also used : RevertSelectionAction(org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction) IAction(org.eclipse.jface.action.IAction) RestoreAction(org.eclipse.ui.internal.editors.quickdiff.RestoreAction) RevertBlockAction(org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction) Shell(org.eclipse.swt.widgets.Shell) RevertLineAction(org.eclipse.ui.internal.editors.quickdiff.RevertLineAction) RenderingMode(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode) BooleanPreferenceToggleAction(org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction) RefreshEditorAction(org.eclipse.ui.internal.editors.text.RefreshEditorAction) ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) CompositeRevertAction(org.eclipse.ui.internal.editors.quickdiff.CompositeRevertAction) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

ITextViewerExtension8 (org.eclipse.jface.text.ITextViewerExtension8)4 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)3 IAction (org.eclipse.jface.action.IAction)2 Point (org.eclipse.swt.graphics.Point)2 IDocument (org.eclipse.jface.text.IDocument)1 ITextViewerExtension6 (org.eclipse.jface.text.ITextViewerExtension6)1 EnrichMode (org.eclipse.jface.text.ITextViewerExtension8.EnrichMode)1 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)1 RenderingMode (org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode)1 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ISourceViewerExtension5 (org.eclipse.jface.text.source.ISourceViewerExtension5)1 StyledTextPrintOptions (org.eclipse.swt.custom.StyledTextPrintOptions)1 Shell (org.eclipse.swt.widgets.Shell)1 CompositeRevertAction (org.eclipse.ui.internal.editors.quickdiff.CompositeRevertAction)1 RestoreAction (org.eclipse.ui.internal.editors.quickdiff.RestoreAction)1 RevertBlockAction (org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction)1 RevertLineAction (org.eclipse.ui.internal.editors.quickdiff.RevertLineAction)1 RevertSelectionAction (org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction)1 RefreshEditorAction (org.eclipse.ui.internal.editors.text.RefreshEditorAction)1