Search in sources :

Example 1 with QuickDiff

use of org.eclipse.ui.texteditor.quickdiff.QuickDiff 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 2 with QuickDiff

use of org.eclipse.ui.texteditor.quickdiff.QuickDiff in project eclipse.platform.text by eclipse.

the class LineNumberColumn method ensureQuickDiffProvider.

/**
 * Ensures that quick diff information is displayed and the quick diff provider is the one with
 * the specified id. If a different quick diff provider is in use, the user may be asked whether
 * he wants to switch.
 *
 * @param diffProviderId the quick diff provider id to use
 * @return <code>true</code> if quick diff could be enabled for the given id,
 *         <code>false</code> otherwise
 */
private boolean ensureQuickDiffProvider(String diffProviderId) {
    if (!isShowingChangeInformation())
        // FIXME pass provider id
        installChangeRulerModel(fDelegate);
    IAnnotationModel annotationModel = fViewer.getAnnotationModel();
    IAnnotationModel oldDiffer = getDiffer();
    if (oldDiffer == null && annotationModel != null)
        // quick diff is enabled, but no differ? not working for whatever reason
        return false;
    if (annotationModel == null)
        annotationModel = new AnnotationModel();
    if (!(annotationModel instanceof IAnnotationModelExtension))
        return false;
    QuickDiff util = new QuickDiff();
    Object oldDifferId = util.getConfiguredQuickDiffProvider(oldDiffer);
    if (oldDifferId.equals(diffProviderId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // Check whether the desired provider is available at all
    IAnnotationModel newDiffer = util.createQuickDiffAnnotationModel(getEditor(), diffProviderId);
    if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) {
        if (oldDiffer instanceof ILineDifferExtension)
            ((ILineDifferExtension) oldDiffer).resume();
        return true;
    }
    // quick diff is showing with the wrong provider - ask the user whether he wants to switch
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) {
        MessageDialogWithToggle toggleDialog = MessageDialogWithToggle.openOkCancelConfirm(fViewer.getTextWidget().getShell(), RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, RulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, true, store, REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY);
        if (toggleDialog.getReturnCode() != Window.OK)
            return false;
    }
    IAnnotationModelExtension modelExtension = (IAnnotationModelExtension) annotationModel;
    modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
    modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer);
    if (fDelegate instanceof IChangeRulerColumn)
        // picks up the new model attachment
        ((IChangeRulerColumn) fDelegate).setModel(annotationModel);
    return true;
}
Also used : QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) IChangeRulerColumn(org.eclipse.jface.text.source.IChangeRulerColumn) ILineDifferExtension(org.eclipse.jface.text.source.ILineDifferExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) AnnotationModel(org.eclipse.jface.text.source.AnnotationModel) MessageDialogWithToggle(org.eclipse.jface.dialogs.MessageDialogWithToggle) IAnnotationModelExtension(org.eclipse.jface.text.source.IAnnotationModelExtension) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 3 with QuickDiff

use of org.eclipse.ui.texteditor.quickdiff.QuickDiff in project eclipse.platform.text by eclipse.

the class QuickDiffConfigurationBlock method createQuickDiffReferenceListModel.

private String[][] createQuickDiffReferenceListModel() {
    List<ReferenceProviderDescriptor> descriptors = new QuickDiff().getReferenceProviderDescriptors();
    ArrayList<String[]> listModelItems = new ArrayList<>();
    for (Iterator<ReferenceProviderDescriptor> it = descriptors.iterator(); it.hasNext(); ) {
        ReferenceProviderDescriptor descriptor = it.next();
        String label = LegacyActionTools.removeMnemonics(descriptor.getLabel());
        listModelItems.add(new String[] { descriptor.getId(), label });
    }
    String[][] items = new String[listModelItems.size()][];
    listModelItems.toArray(items);
    return items;
}
Also used : ReferenceProviderDescriptor(org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor) QuickDiff(org.eclipse.ui.texteditor.quickdiff.QuickDiff) ArrayList(java.util.ArrayList)

Aggregations

QuickDiff (org.eclipse.ui.texteditor.quickdiff.QuickDiff)3 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 AnnotationModel (org.eclipse.jface.text.source.AnnotationModel)2 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)2 IAnnotationModelExtension (org.eclipse.jface.text.source.IAnnotationModelExtension)2 ILineDifferExtension (org.eclipse.jface.text.source.ILineDifferExtension)2 ArrayList (java.util.ArrayList)1 MessageDialogWithToggle (org.eclipse.jface.dialogs.MessageDialogWithToggle)1 IChangeRulerColumn (org.eclipse.jface.text.source.IChangeRulerColumn)1 ILineDifferExtension2 (org.eclipse.jface.text.source.ILineDifferExtension2)1 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)1 ReferenceProviderDescriptor (org.eclipse.ui.texteditor.quickdiff.ReferenceProviderDescriptor)1