mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 01:15:29 +02:00
Implement TogglePresentatiion.
This commit is contained in:
parent
c15e5acca5
commit
19278dab53
6 changed files with 164 additions and 8 deletions
|
@ -38,6 +38,7 @@ import org.eclipse.ui.IActionBars;
|
|||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.IStorageEditorInput;
|
||||
import org.eclipse.ui.part.IPageSite;
|
||||
import org.eclipse.ui.part.Page;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
@ -47,6 +48,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
private WorkingCopy fInput;
|
||||
private ProblemTreeViewer treeViewer;
|
||||
private ListenerList selectionChangedListeners = new ListenerList();
|
||||
private TogglePresentationAction fTogglePresentation;
|
||||
|
||||
private OpenIncludeAction fOpenIncludeAction;
|
||||
private SearchForReferencesAction fSearchForReferencesAction;
|
||||
|
@ -55,6 +57,9 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
super();
|
||||
fEditor= editor;
|
||||
fInput= null;
|
||||
|
||||
fTogglePresentation= new TogglePresentationAction();
|
||||
fTogglePresentation.setEditor(editor);
|
||||
|
||||
fOpenIncludeAction= new OpenIncludeAction(this);
|
||||
fSearchForReferencesAction= new SearchForReferencesAction(this);
|
||||
|
@ -147,6 +152,12 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
|||
Control control= treeViewer.getControl();
|
||||
Menu menu= manager.createContextMenu(control);
|
||||
control.setMenu(menu);
|
||||
|
||||
// register global actions
|
||||
IPageSite site= getSite();
|
||||
IActionBars bars= site.getActionBars();
|
||||
bars.setGlobalActionHandler(ICEditorActionDefinitionIds.TOGGLE_PRESENTATION, fTogglePresentation);
|
||||
|
||||
|
||||
//IFileEditorInput editorInput= (IFileEditorInput)fEditor.getEditorInput();
|
||||
IEditorInput editorInput= (IEditorInput)fEditor.getEditorInput();
|
||||
|
|
|
@ -87,6 +87,7 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
protected SelectionAction fShiftLeft;
|
||||
protected SelectionAction fShiftRight;
|
||||
private TextOperationAction caAction;
|
||||
private TogglePresentationAction fTogglePresentation;
|
||||
//private ToggleTextHoverAction fToggleTextHover;
|
||||
private GotoErrorAction fPreviousError;
|
||||
private GotoErrorAction fNextError;
|
||||
|
@ -108,6 +109,8 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
fAddInclude = new RetargetTextEditorAction(bundle, "AddIncludeOnSelection.");
|
||||
fOpenOnSelection = new RetargetTextEditorAction(bundle, "OpenOnSelection.");
|
||||
|
||||
// actions that are "contributed" to editors, they are considered belonging to the active editor
|
||||
fTogglePresentation= new TogglePresentationAction();
|
||||
//fToggleTextHover= new ToggleTextHoverAction();
|
||||
fPreviousError= new GotoErrorAction("Editor.PreviousError.", false); //$NON-NLS-1$
|
||||
CPluginImages.setImageDescriptors(fPreviousError, CPluginImages.T_TOOL, CPluginImages.IMG_TOOL_GOTO_PREV_ERROR);
|
||||
|
@ -150,10 +153,10 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
public void contributeToToolBar(IToolBarManager tbm) {
|
||||
super.contributeToToolBar(tbm);
|
||||
tbm.add(new Separator());
|
||||
//tbm.add(fTogglePresentation);
|
||||
tbm.add(fTogglePresentation);
|
||||
//tbm.add(fToggleTextHover);
|
||||
tbm.add(fNextError);
|
||||
tbm.add(fPreviousError);
|
||||
tbm.add(fPreviousError);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -172,6 +175,8 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
|||
fShiftLeft.setEditor(textEditor);
|
||||
fNextError.setEditor(textEditor);
|
||||
fPreviousError.setEditor(textEditor);
|
||||
fTogglePresentation.setEditor(textEditor);
|
||||
|
||||
//caAction.setEditor(textEditor);
|
||||
//caAction.update();
|
||||
fContentAssist.setAction(getAction(textEditor, "ContentAssistProposal")); //$NON-NLS-1$
|
||||
|
|
|
@ -88,11 +88,11 @@ RunToLine.error.title1=Run to Line
|
|||
RunToLine.label=R&un to Line
|
||||
RunToLine.tooltip=Run to line
|
||||
|
||||
TogglePresentation.tooltip.checked=Show Complete Source
|
||||
TogglePresentation.tooltip.unchecked=Show Source of Selected Element Only
|
||||
TogglePresentation.label=Show Source of Selected Element Only
|
||||
TogglePresentation.tooltip=Show Source of Selected Element Only
|
||||
|
||||
ToggleTextHover.tooltip.checked=Hide Text Hover
|
||||
ToggleTextHover.tooltip.unchecked=Show Text Hover
|
||||
ToggleTextHover.label=Show Text Hover
|
||||
ToggleTextHover.tooltip=Show Text Hover
|
||||
|
||||
NextError.label=Ne&xt Problem@Ctrl+P
|
||||
NextError.tooltip=Go to Next Problem
|
||||
|
|
|
@ -20,7 +20,6 @@ public interface CTextEditorActionConstants extends IWorkbenchActionConstants {
|
|||
*/
|
||||
static final String STATUS_INPUT_MODE= "InputMode";
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -40,6 +40,13 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
|||
* Action definition ID of the source -> add include action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.add.include"</code>).
|
||||
*/
|
||||
public static final String ADD_INCLUDE= "org.eclipse.cdt.ui.edit.text.c.add.include"; //$NON-NLS-1$
|
||||
public static final String ADD_INCLUDE= "org.eclipse.cdt.ui.edit.text.c.add.include"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Action definition ID of the toggle presentation toolbar button action
|
||||
* (value <code>"org.eclipse.cdt.ui.edit.text.java.toggle.presentation"</code>).
|
||||
*/
|
||||
public static final String TOGGLE_PRESENTATION= "org.eclipse.cdt.ui.edit.text.c.toggle.presentation"; //$NON-NLS-1$
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,134 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2003 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
|
||||
|
||||
import org.eclipse.cdt.internal.ui.CPluginImages;
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.IRegion;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
|
||||
import org.eclipse.ui.help.WorkbenchHelp;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.TextEditorAction;
|
||||
|
||||
|
||||
/**
|
||||
* A toolbar action which toggles the presentation model of the
|
||||
* connected text editor. The editor shows either the highlight range
|
||||
* only or always the whole document.
|
||||
*/
|
||||
public class TogglePresentationAction extends TextEditorAction implements IPropertyChangeListener {
|
||||
|
||||
private IPreferenceStore fStore;
|
||||
|
||||
/**
|
||||
* Constructs and updates the action.
|
||||
*/
|
||||
public TogglePresentationAction() {
|
||||
super(CEditorMessages.getResourceBundle(), "TogglePresentation.", null); //$NON-NLS-1$
|
||||
CPluginImages.setImageDescriptors(this, CPluginImages.T_LCL, CPluginImages.IMG_MENU_SEGMENT_EDIT);
|
||||
setToolTipText(CEditorMessages.getString("TogglePresentation.tooltip")); //$NON-NLS-1$
|
||||
setActionDefinitionId(ICEditorActionDefinitionIds.TOGGLE_PRESENTATION);
|
||||
WorkbenchHelp.setHelp(this, ICHelpContextIds.TOGGLE_PRESENTATION_ACTION);
|
||||
update();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IAction#actionPerformed
|
||||
*/
|
||||
public void run() {
|
||||
|
||||
ITextEditor editor= getTextEditor();
|
||||
if (editor == null)
|
||||
return;
|
||||
|
||||
IRegion remembered= editor.getHighlightRange();
|
||||
editor.resetHighlightRange();
|
||||
|
||||
boolean showAll= !editor.showsHighlightRangeOnly();
|
||||
setChecked(showAll);
|
||||
|
||||
editor.showHighlightRangeOnly(showAll);
|
||||
if (remembered != null)
|
||||
editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);
|
||||
|
||||
fStore.removePropertyChangeListener(this);
|
||||
fStore.setValue(PreferenceConstants.EDITOR_SHOW_SEGMENTS, showAll);
|
||||
fStore.addPropertyChangeListener(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TextEditorAction#update
|
||||
*/
|
||||
public void update() {
|
||||
ITextEditor editor= getTextEditor();
|
||||
boolean checked= (editor != null && editor.showsHighlightRangeOnly());
|
||||
setChecked(checked);
|
||||
setEnabled(editor != null);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see TextEditorAction#setEditor(ITextEditor)
|
||||
*/
|
||||
public void setEditor(ITextEditor editor) {
|
||||
|
||||
super.setEditor(editor);
|
||||
|
||||
if (editor != null) {
|
||||
|
||||
if (fStore == null) {
|
||||
fStore= CUIPlugin.getDefault().getPreferenceStore();
|
||||
fStore.addPropertyChangeListener(this);
|
||||
}
|
||||
synchronizeWithPreference(editor);
|
||||
|
||||
} else if (fStore != null) {
|
||||
fStore.removePropertyChangeListener(this);
|
||||
fStore= null;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Synchronizes the appearance of the editor with what the preference store tells him.
|
||||
*/
|
||||
private void synchronizeWithPreference(ITextEditor editor) {
|
||||
|
||||
if (editor == null)
|
||||
return;
|
||||
|
||||
boolean showSegments= fStore.getBoolean(PreferenceConstants.EDITOR_SHOW_SEGMENTS);
|
||||
setChecked(showSegments);
|
||||
|
||||
if (editor.showsHighlightRangeOnly() != showSegments) {
|
||||
IRegion remembered= editor.getHighlightRange();
|
||||
editor.resetHighlightRange();
|
||||
editor.showHighlightRangeOnly(showSegments);
|
||||
if (remembered != null)
|
||||
editor.setHighlightRange(remembered.getOffset(), remembered.getLength(), true);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IPropertyChangeListener#propertyChange(PropertyChangeEvent)
|
||||
*/
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
if (event.getProperty().equals(PreferenceConstants.EDITOR_SHOW_SEGMENTS))
|
||||
synchronizeWithPreference(getTextEditor());
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue