Search in sources :

Example 1 with RulerColumnPreferenceAdapter

use of org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method updateContributedRulerColumns.

/**
 * Adds enabled ruler contributions to the vertical ruler.
 * <p>
 * Clients may extend or replace.</p>
 *
 * @param ruler the composite ruler to add contributions to
 * @since 3.3
 */
protected void updateContributedRulerColumns(CompositeRuler ruler) {
    IColumnSupport support = getAdapter(IColumnSupport.class);
    if (support == null)
        return;
    RulerColumnPreferenceAdapter adapter = null;
    if (fPreferenceStore != null)
        adapter = new RulerColumnPreferenceAdapter(getPreferenceStore(), PREFERENCE_RULER_CONTRIBUTIONS);
    RulerColumnRegistry registry = RulerColumnRegistry.getDefault();
    List<RulerColumnDescriptor> descriptors = registry.getColumnDescriptors();
    for (Iterator<RulerColumnDescriptor> it = descriptors.iterator(); it.hasNext(); ) {
        final RulerColumnDescriptor descriptor = it.next();
        support.setColumnVisible(descriptor, adapter == null || adapter.isEnabled(descriptor));
    }
}
Also used : RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) RulerColumnRegistry(org.eclipse.ui.texteditor.rulers.RulerColumnRegistry) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) RulerColumnPreferenceAdapter(org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter)

Example 2 with RulerColumnPreferenceAdapter

use of org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method addRulerContributionActions.

/**
 * Adds "show" actions for all contributed rulers that support it.
 *
 * @param menu the ruler context menu
 * @since 3.3
 */
private void addRulerContributionActions(IMenuManager menu) {
    // store directly in generic editor preferences
    final IColumnSupport support = getAdapter(IColumnSupport.class);
    IPreferenceStore store = EditorsUI.getPreferenceStore();
    final RulerColumnPreferenceAdapter adapter = new RulerColumnPreferenceAdapter(store, AbstractTextEditor.PREFERENCE_RULER_CONTRIBUTIONS);
    List<RulerColumnDescriptor> descriptors = RulerColumnRegistry.getDefault().getColumnDescriptors();
    for (Iterator<RulerColumnDescriptor> t = descriptors.iterator(); t.hasNext(); ) {
        final RulerColumnDescriptor descriptor = t.next();
        if (!descriptor.isIncludedInMenu() || !support.isColumnSupported(descriptor))
            continue;
        final boolean isVisible = support.isColumnVisible(descriptor);
        IAction action = new Action(MessageFormat.format(TextEditorMessages.AbstractDecoratedTextEditor_show_ruler_label, new Object[] { descriptor.getName() }), IAction.AS_CHECK_BOX) {

            @Override
            public void run() {
                if (descriptor.isGlobal())
                    // column state is modified via preference listener of AbstractTextEditor
                    adapter.setEnabled(descriptor, !isVisible);
                else
                    // directly modify column for this editor instance
                    support.setColumnVisible(descriptor, !isVisible);
            }
        };
        action.setChecked(isVisible);
        action.setImageDescriptor(descriptor.getIcon());
        menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, action);
    }
}
Also used : 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) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) RulerColumnPreferenceAdapter(org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Aggregations

IColumnSupport (org.eclipse.ui.texteditor.rulers.IColumnSupport)2 RulerColumnDescriptor (org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor)2 RulerColumnPreferenceAdapter (org.eclipse.ui.texteditor.rulers.RulerColumnPreferenceAdapter)2 Action (org.eclipse.jface.action.Action)1 IAction (org.eclipse.jface.action.IAction)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)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 BooleanPreferenceToggleAction (org.eclipse.ui.internal.texteditor.BooleanPreferenceToggleAction)1 RulerColumnRegistry (org.eclipse.ui.texteditor.rulers.RulerColumnRegistry)1