Search in sources :

Example 81 with IPreferenceStore

use of org.eclipse.jface.preference.IPreferenceStore in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method rulerContextMenuAboutToShow.

@Override
protected void rulerContextMenuAboutToShow(IMenuManager menu) {
    /*
		 * XXX: workaround for reliable menu item ordering.
		 * This can be changed once the action contribution story converges,
		 * see http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-ui-home/R3_1/dynamic_teams/dynamic_teams.html#actionContributions
		 */
    // pre-install menus for contributions and call super
    // $NON-NLS-1$
    menu.add(new Separator("debug"));
    menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_RESTORE));
    // $NON-NLS-1$
    menu.add(new Separator("add"));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_RULERS));
    menu.add(new Separator(ITextEditorActionConstants.GROUP_REST));
    super.rulerContextMenuAboutToShow(menu);
    addRulerContributionActions(menu);
    /* quick diff */
    if (isEditorInputModifiable()) {
        IAction quickdiffAction = getAction(ITextEditorActionConstants.QUICKDIFF_TOGGLE);
        quickdiffAction.setChecked(isChangeInformationShowing());
        menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, quickdiffAction);
        if (isChangeInformationShowing()) {
            TextEditorAction revertLine = new RevertLineAction(this, true);
            TextEditorAction revertSelection = new RevertSelectionAction(this, true);
            TextEditorAction revertBlock = new RevertBlockAction(this, true);
            TextEditorAction revertDeletion = new RestoreAction(this, true);
            revertSelection.update();
            revertBlock.update();
            revertLine.update();
            revertDeletion.update();
            // only add block action if selection action is not enabled
            if (revertSelection.isEnabled())
                menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertSelection);
            else if (revertBlock.isEnabled())
                menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertBlock);
            if (revertLine.isEnabled())
                menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertLine);
            if (revertDeletion.isEnabled())
                menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertDeletion);
        }
    }
    // revision info
    if (fLineColumn != null && fLineColumn.isShowingRevisionInformation()) {
        IMenuManager revisionMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_revisions_menu);
        menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, revisionMenu);
        IAction hideRevisionInfoAction = getAction(ITextEditorActionConstants.REVISION_HIDE_INFO);
        revisionMenu.add(hideRevisionInfoAction);
        revisionMenu.add(new Separator());
        String[] labels = { TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_date, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author_and_date };
        final RenderingMode[] modes = { IRevisionRulerColumnExtension.AGE, IRevisionRulerColumnExtension.AUTHOR, IRevisionRulerColumnExtension.AUTHOR_SHADED_BY_AGE };
        final IPreferenceStore uiStore = EditorsUI.getPreferenceStore();
        String current = uiStore.getString(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE);
        for (int i = 0; i < modes.length; i++) {
            final String mode = modes[i].name();
            IAction action = new Action(labels[i], IAction.AS_RADIO_BUTTON) {

                @Override
                public void run() {
                    // set preference globally, LineNumberColumn reacts on preference change
                    uiStore.setValue(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, mode);
                }
            };
            action.setChecked(mode.equals(current));
            revisionMenu.add(action);
        }
        revisionMenu.add(new Separator());
        IAction action = getAction(ITextEditorActionConstants.REVISION_SHOW_AUTHOR_TOGGLE);
        if (action instanceof IUpdate)
            ((IUpdate) action).update();
        revisionMenu.add(action);
        action = getAction(ITextEditorActionConstants.REVISION_SHOW_ID_TOGGLE);
        if (action instanceof IUpdate)
            ((IUpdate) action).update();
        revisionMenu.add(action);
    }
    IAction lineNumberAction = getAction(ITextEditorActionConstants.LINENUMBERS_TOGGLE);
    lineNumberAction.setChecked(fLineColumn != null && fLineColumn.isShowingLineNumbers());
    menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, lineNumberAction);
    IAction preferencesAction = getAction(ITextEditorActionConstants.RULER_PREFERENCES);
    menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
    menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
}
Also used : RevertSelectionAction(org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction) RevertLineAction(org.eclipse.ui.internal.editors.quickdiff.RevertLineAction) RevertBlockAction(org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction) BooleanPreferenceToggleAction(org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction) RevertSelectionAction(org.eclipse.ui.internal.editors.quickdiff.RevertSelectionAction) CompositeRevertAction(org.eclipse.ui.internal.editors.quickdiff.CompositeRevertAction) RestoreAction(org.eclipse.ui.internal.editors.quickdiff.RestoreAction) IAction(org.eclipse.jface.action.IAction) RefreshEditorAction(org.eclipse.ui.internal.editors.text.RefreshEditorAction) Action(org.eclipse.jface.action.Action) IAction(org.eclipse.jface.action.IAction) RestoreAction(org.eclipse.ui.internal.editors.quickdiff.RestoreAction) RevertBlockAction(org.eclipse.ui.internal.editors.quickdiff.RevertBlockAction) Point(org.eclipse.swt.graphics.Point) RevertLineAction(org.eclipse.ui.internal.editors.quickdiff.RevertLineAction) RenderingMode(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) GroupMarker(org.eclipse.jface.action.GroupMarker) IMenuManager(org.eclipse.jface.action.IMenuManager) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Separator(org.eclipse.jface.action.Separator)

Example 82 with IPreferenceStore

use of org.eclipse.jface.preference.IPreferenceStore in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method validateEditorInputDerived.

/**
 * Validates the editor input for derived state.
 * If the given input is derived then this method
 * can show a dialog asking whether to edit the
 * derived file.
 *
 * @return <code>true</code> if the input is OK for editing, <code>false</code> otherwise
 * @since 3.3
 */
private boolean validateEditorInputDerived() {
    if (fIsDerivedStateValidated)
        return fIsEditingDerivedFileAllowed;
    if (getDocumentProvider() instanceof IDocumentProviderExtension) {
        IDocumentProviderExtension extension = (IDocumentProviderExtension) getDocumentProvider();
        IStatus status = extension.getStatus(getEditorInput());
        String pluginId = status.getPlugin();
        boolean isDerivedStatus = status.getCode() == IFileBufferStatusCodes.DERIVED_FILE && (FileBuffers.PLUGIN_ID.equals(pluginId) || EditorsUI.PLUGIN_ID.equals(pluginId));
        if (!isDerivedStatus)
            return true;
    }
    final String warnKey = AbstractDecoratedTextEditorPreferenceConstants.EDITOR_WARN_IF_INPUT_DERIVED;
    IPreferenceStore store = getPreferenceStore();
    if (!store.getBoolean(warnKey))
        return true;
    MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openYesNoQuestion(getSite().getShell(), TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_title, TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_message, TextEditorMessages.AbstractDecoratedTextEditor_warning_derived_dontShowAgain, false, null, null);
    EditorsUI.getPreferenceStore().setValue(warnKey, !toggleDialog.getToggleState());
    fIsDerivedStateValidated = true;
    return fIsEditingDerivedFileAllowed = toggleDialog.getReturnCode() == IDialogConstants.YES_ID;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 83 with IPreferenceStore

use of org.eclipse.jface.preference.IPreferenceStore in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method performDefaults.

@Override
protected void performDefaults() {
    if (isShowFormatterSetting()) {
        IPreferenceStore prefs = getPreferenceStore();
        fFormatButton.setSelection(prefs.getDefaultBoolean(getFormatterPreferenceKey()));
    }
    fTemplateStore.restoreDefaults(false);
    // refresh
    fTableViewer.refresh();
    fTableViewer.setAllChecked(false);
    fTableViewer.setCheckedElements(getEnabledTemplates());
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 84 with IPreferenceStore

use of org.eclipse.jface.preference.IPreferenceStore in project eclipse.platform.text by eclipse.

the class LineNumberColumn method getAnnotationModelWithDiffer.

/**
 * Returns the annotation model that contains the quick diff annotation model.
 * <p>
 * Extracts the line differ from the displayed document's annotation model. If none can be found,
 * a new differ is created and attached to the annotation model.</p>
 *
 * @return the annotation model that contains the line differ, or <code>null</code> if none could be found or created
 * @see IChangeRulerColumn#QUICK_DIFF_MODEL_ID
 */
private IAnnotationModel getAnnotationModelWithDiffer() {
    ISourceViewer viewer = fViewer;
    if (viewer == null)
        return null;
    IAnnotationModel m = viewer.getAnnotationModel();
    IAnnotationModelExtension model = null;
    if (m instanceof IAnnotationModelExtension)
        model = (IAnnotationModelExtension) m;
    IAnnotationModel differ = getDiffer();
    // create diff model if it doesn't
    if (differ == null) {
        IPreferenceStore store = getPreferenceStore();
        if (store != null) {
            String defaultId = store.getString(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER);
            differ = new QuickDiff().createQuickDiffAnnotationModel(getEditor(), defaultId);
            if (differ != null) {
                if (model == null)
                    model = new AnnotationModel();
                model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ);
            }
        }
    } else if (differ instanceof ILineDifferExtension2) {
        if (((ILineDifferExtension2) differ).isSuspended())
            ((ILineDifferExtension) differ).resume();
    } else if (differ instanceof ILineDifferExtension) {
        ((ILineDifferExtension) differ).resume();
    }
    return (IAnnotationModel) model;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) ILineDifferExtension2(org.eclipse.jface.text.source.ILineDifferExtension2) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 85 with IPreferenceStore

use of org.eclipse.jface.preference.IPreferenceStore in project eclipse.platform.text by eclipse.

the class LineNumberColumn method initialize.

/**
 * Initializes the given line number ruler column from the preference store.
 */
private void initialize() {
    final IPreferenceStore store = getPreferenceStore();
    if (store == null)
        return;
    // initial set up
    updateForegroundColor(store, fDelegate);
    updateBackgroundColor(store, fDelegate);
    updateLineNumbersVisibility(fDelegate);
    updateQuickDiffVisibility(fDelegate);
    updateCharacterMode(store, fDelegate);
    updateRevisionRenderingMode(store, fDelegate);
    updateRevisionAuthorVisibility(store, fDelegate);
    updateRevisionIdVisibility(store, fDelegate);
    Map<Object, AnnotationPreference> annotationPrefs = getAnnotationPreferenceMap();
    // $NON-NLS-1$
    final AnnotationPreference changedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffChange");
    // $NON-NLS-1$
    final AnnotationPreference addedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffAddition");
    // $NON-NLS-1$
    final AnnotationPreference deletedPref = annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffDeletion");
    updateChangedColor(changedPref, store, fDelegate);
    updateAddedColor(addedPref, store, fDelegate);
    updateDeletedColor(deletedPref, store, fDelegate);
    fDelegate.redraw();
    // listen to changes
    fDispatcher = new PropertyEventDispatcher(store);
    fDispatcher.addPropertyChangeListener(FG_COLOR_KEY, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateForegroundColor(store, fDelegate);
            fDelegate.redraw();
        }
    });
    IPropertyChangeListener backgroundHandler = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateBackgroundColor(store, fDelegate);
            fDelegate.redraw();
        }
    };
    fDispatcher.addPropertyChangeListener(BG_COLOR_KEY, backgroundHandler);
    fDispatcher.addPropertyChangeListener(USE_DEFAULT_BG_KEY, backgroundHandler);
    fDispatcher.addPropertyChangeListener(LINE_NUMBER_KEY, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            // only handle quick diff on/off information, but not ruler visibility (handled by AbstractDecoratedTextEditor)
            updateLineNumbersVisibility(fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateCharacterMode(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionRenderingMode(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_AUTHOR, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionAuthorVisibility(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_REVISION, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateRevisionIdVisibility(store, fDelegate);
        }
    });
    fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON, new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            updateQuickDiffVisibility(fDelegate);
        }
    });
    if (changedPref != null) {
        fDispatcher.addPropertyChangeListener(changedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateChangedColor(changedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
    if (addedPref != null) {
        fDispatcher.addPropertyChangeListener(addedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateAddedColor(addedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
    if (deletedPref != null) {
        fDispatcher.addPropertyChangeListener(deletedPref.getColorPreferenceKey(), new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                updateDeletedColor(deletedPref, store, fDelegate);
                fDelegate.redraw();
            }
        });
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) AnnotationPreference(org.eclipse.ui.texteditor.AnnotationPreference)

Aggregations

IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)311 ArrayList (java.util.ArrayList)35 Test (org.junit.Test)23 Hashtable (java.util.Hashtable)19 File (java.io.File)18 Before (org.junit.Before)17 List (java.util.List)14 IPath (org.eclipse.core.runtime.IPath)14 InvocationTargetException (java.lang.reflect.InvocationTargetException)13 IOException (java.io.IOException)12 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)12 IElementParameter (org.talend.core.model.process.IElementParameter)12 CoreException (org.eclipse.core.runtime.CoreException)11 Path (org.eclipse.core.runtime.Path)11 Font (org.eclipse.swt.graphics.Font)11 Point (org.eclipse.swt.graphics.Point)11 Composite (org.eclipse.swt.widgets.Composite)11 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)10 IStatus (org.eclipse.core.runtime.IStatus)10 StyledText (org.eclipse.swt.custom.StyledText)10