mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 22:35:43 +02:00
Bug 326265 - [Makefile Editor] Folding actions in its rulers context menu
Patch from Patrick Hofer
This commit is contained in:
parent
24af3b858a
commit
87f0ba4453
7 changed files with 417 additions and 1 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: org.eclipse.cdt.make.ui; singleton:=true
|
||||
Bundle-Version: 7.0.0.qualifier
|
||||
Bundle-Version: 7.1.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.make.internal.ui.MakeUIPlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -0,0 +1,200 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* Patrick Hofer - Bug 326265
|
||||
*******************************************************************************/
|
||||
|
||||
// this file is based on org.eclipse.cdt.internal.ui.actions.FoldingActionGroup
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.actions;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.text.ITextViewer;
|
||||
import org.eclipse.jface.text.source.projection.IProjectionListener;
|
||||
import org.eclipse.jface.text.source.projection.ProjectionViewer;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.ui.editors.text.IFoldingCommandIds;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.IUpdate;
|
||||
import org.eclipse.ui.texteditor.ResourceAction;
|
||||
import org.eclipse.ui.texteditor.TextOperationAction;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.editor.MakefileEditor;
|
||||
|
||||
/**
|
||||
* Groups the CDT folding actions.
|
||||
*/
|
||||
public class FoldingActionGroup extends ActionGroup {
|
||||
|
||||
private static abstract class PreferenceAction extends ResourceAction implements IUpdate {
|
||||
PreferenceAction(ResourceBundle bundle, String prefix, int style) {
|
||||
super(bundle, prefix, style);
|
||||
update();
|
||||
}
|
||||
}
|
||||
|
||||
private class FoldingAction extends PreferenceAction {
|
||||
|
||||
FoldingAction(ResourceBundle bundle, String prefix) {
|
||||
super(bundle, prefix, IAction.AS_PUSH_BUTTON);
|
||||
}
|
||||
|
||||
public void update() {
|
||||
setEnabled(FoldingActionGroup.this.isEnabled() && fViewer.isProjectionMode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private ProjectionViewer fViewer;
|
||||
private IProjectionListener fProjectionListener;
|
||||
|
||||
private TextOperationAction fToggle;
|
||||
private TextOperationAction fExpand;
|
||||
private TextOperationAction fCollapse;
|
||||
private TextOperationAction fExpandAll;
|
||||
|
||||
private TextOperationAction fCollapseAll;
|
||||
private PreferenceAction fRestoreDefaults;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new projection action group for <code>editor</code>. If the
|
||||
* supplied viewer is not an instance of <code>ProjectionViewer</code>, the
|
||||
* action group is disabled.
|
||||
*
|
||||
* @param editor the text editor to operate on
|
||||
* @param viewer the viewer of the editor
|
||||
*/
|
||||
public FoldingActionGroup(final ITextEditor editor, ITextViewer viewer) {
|
||||
if (!(viewer instanceof ProjectionViewer)) {
|
||||
fToggle= null;
|
||||
fExpand= null;
|
||||
fCollapse= null;
|
||||
fExpandAll= null;
|
||||
fCollapseAll= null;
|
||||
fRestoreDefaults= null;
|
||||
fProjectionListener= null;
|
||||
return;
|
||||
}
|
||||
|
||||
fViewer= (ProjectionViewer) viewer;
|
||||
|
||||
fProjectionListener= new IProjectionListener() {
|
||||
public void projectionEnabled() {
|
||||
update();
|
||||
}
|
||||
public void projectionDisabled() {
|
||||
update();
|
||||
}
|
||||
};
|
||||
|
||||
fViewer.addProjectionListener(fProjectionListener);
|
||||
|
||||
fToggle= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", editor, ProjectionViewer.TOGGLE, true); //$NON-NLS-1$
|
||||
fToggle.setActionDefinitionId(IFoldingCommandIds.FOLDING_TOGGLE);
|
||||
editor.setAction("FoldingToggle", fToggle); //$NON-NLS-1$
|
||||
|
||||
fExpandAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.ExpandAll.", editor, ProjectionViewer.EXPAND_ALL, true); //$NON-NLS-1$
|
||||
fExpandAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND_ALL);
|
||||
editor.setAction("FoldingExpandAll", fExpandAll); //$NON-NLS-1$
|
||||
|
||||
fCollapseAll= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.CollapseAll.", editor, ProjectionViewer.COLLAPSE_ALL, true); //$NON-NLS-1$
|
||||
fCollapseAll.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE_ALL);
|
||||
editor.setAction("FoldingCollapseAll", fCollapseAll); //$NON-NLS-1$
|
||||
|
||||
fExpand= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Expand.", editor, ProjectionViewer.EXPAND, true); //$NON-NLS-1$
|
||||
fExpand.setActionDefinitionId(IFoldingCommandIds.FOLDING_EXPAND);
|
||||
editor.setAction("FoldingExpand", fExpand); //$NON-NLS-1$
|
||||
|
||||
fCollapse= new TextOperationAction(FoldingMessages.getResourceBundle(), "Projection.Collapse.", editor, ProjectionViewer.COLLAPSE, true); //$NON-NLS-1$
|
||||
fCollapse.setActionDefinitionId(IFoldingCommandIds.FOLDING_COLLAPSE);
|
||||
editor.setAction("FoldingCollapse", fCollapse); //$NON-NLS-1$
|
||||
|
||||
fRestoreDefaults= new FoldingAction(FoldingMessages.getResourceBundle(), "Projection.Restore.") { //$NON-NLS-1$
|
||||
@Override
|
||||
public void run() {
|
||||
if (editor instanceof MakefileEditor) {
|
||||
MakefileEditor makefileEditor= (MakefileEditor) editor;
|
||||
makefileEditor.resetProjection();
|
||||
}
|
||||
}
|
||||
};
|
||||
fRestoreDefaults.setActionDefinitionId(IFoldingCommandIds.FOLDING_RESTORE);
|
||||
editor.setAction("FoldingRestore", fRestoreDefaults); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns <code>true</code> if the group is enabled.
|
||||
* <pre>
|
||||
* Invariant: isEnabled() <=> fViewer and all actions are != null.
|
||||
* </pre>
|
||||
*
|
||||
* @return <code>true</code> if the group is enabled
|
||||
*/
|
||||
protected boolean isEnabled() {
|
||||
return fViewer != null;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.actions.ActionGroup#dispose()
|
||||
*/
|
||||
@Override
|
||||
public void dispose() {
|
||||
if (isEnabled()) {
|
||||
fViewer.removeProjectionListener(fProjectionListener);
|
||||
fViewer= null;
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the actions.
|
||||
*/
|
||||
protected void update() {
|
||||
if (isEnabled()) {
|
||||
fToggle.update();
|
||||
fToggle.setChecked(fViewer.isProjectionMode());
|
||||
fExpand.update();
|
||||
fExpandAll.update();
|
||||
fCollapse.update();
|
||||
fCollapseAll.update();
|
||||
fRestoreDefaults.update();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fills the menu with all folding actions.
|
||||
*
|
||||
* @param manager the menu manager for the folding submenu
|
||||
*/
|
||||
public void fillMenu(IMenuManager manager) {
|
||||
if (isEnabled()) {
|
||||
update();
|
||||
manager.add(fToggle);
|
||||
manager.add(fExpandAll);
|
||||
manager.add(fExpand);
|
||||
manager.add(fCollapse);
|
||||
manager.add(fCollapseAll);
|
||||
manager.add(fRestoreDefaults);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.actions.ActionGroup#updateActionBars()
|
||||
*/
|
||||
@Override
|
||||
public void updateActionBars() {
|
||||
update();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Patrick Hofer - Bug 326265
|
||||
*******************************************************************************/
|
||||
|
||||
// this file is based on org.eclipse.cdt.internal.ui.actions.FoldingMessages
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.actions;
|
||||
|
||||
import com.ibm.icu.text.MessageFormat;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Class that gives access to the folding messages resource bundle.
|
||||
*/
|
||||
public class FoldingMessages {
|
||||
|
||||
private static final String BUNDLE_NAME= "org.eclipse.cdt.make.internal.ui.actions.FoldingMessages"; //$NON-NLS-1$
|
||||
|
||||
private static final ResourceBundle RESOURCE_BUNDLE= ResourceBundle.getBundle(BUNDLE_NAME);
|
||||
|
||||
private FoldingMessages() {
|
||||
// no instance
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource string associated with the given key in the resource bundle. If there isn't
|
||||
* any value under the given key, the key is returned.
|
||||
*
|
||||
* @param key the resource key
|
||||
* @return the string
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
try {
|
||||
return RESOURCE_BUNDLE.getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the resource bundle managed by the receiver.
|
||||
*
|
||||
* @return the resource bundle
|
||||
*/
|
||||
public static ResourceBundle getResourceBundle() {
|
||||
return RESOURCE_BUNDLE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted resource string associated with the given key in the resource bundle.
|
||||
* <code>MessageFormat</code> is used to format the message. If there isn't any value
|
||||
* under the given key, the key is returned.
|
||||
*
|
||||
* @param key the resource key
|
||||
* @param arg the message argument
|
||||
* @return the string
|
||||
*/
|
||||
public static String getFormattedString(String key, Object arg) {
|
||||
return getFormattedString(key, new Object[] { arg });
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted resource string associated with the given key in the resource bundle.
|
||||
* <code>MessageFormat</code> is used to format the message. If there isn't any value
|
||||
* under the given key, the key is returned.
|
||||
*
|
||||
* @param key the resource key
|
||||
* @param args the message arguments
|
||||
* @return the string
|
||||
*/
|
||||
public static String getFormattedString(String key, Object[] args) {
|
||||
return MessageFormat.format(getString(key), args);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2005, 2010 IBM Corporation and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# IBM Corporation - initial API and implementation
|
||||
# Patrick Hofer - Bug 326265
|
||||
###############################################################################
|
||||
Projection.Toggle.label= &Enable Folding
|
||||
Projection.Toggle.tooltip= Toggles Folding
|
||||
Projection.Toggle.description= Toggles folding for the current editor
|
||||
Projection.Toggle.image=
|
||||
|
||||
Projection.ExpandAll.label= Expand &All
|
||||
Projection.ExpandAll.tooltip= Expands All Collapsed Regions
|
||||
Projection.ExpandAll.description= Expands any collapsed regions in the current editor
|
||||
Projection.ExpandAll.image=
|
||||
|
||||
Projection.Expand.label= E&xpand
|
||||
Projection.Expand.tooltip= Expands the Current Collapsed Region
|
||||
Projection.Expand.description= Expands the collapsed region at the current selection
|
||||
Projection.Expand.image=
|
||||
|
||||
Projection.CollapseAll.label= Collapse A&ll
|
||||
Projection.CollapseAll.tooltip= Collapses All Expanded Regions
|
||||
Projection.CollapseAll.description= Collapse any expanded regions in the current editor
|
||||
Projection.CollapseAll.image=
|
||||
|
||||
Projection.Collapse.label= Colla&pse
|
||||
Projection.Collapse.tooltip= Collapses the Current Region
|
||||
Projection.Collapse.description= Collapses the Current Region
|
||||
Projection.Collapse.image=
|
||||
|
||||
Projection.Restore.label= &Reset Structure
|
||||
Projection.Restore.tooltip= Restore the Original Folding Structure
|
||||
Projection.Restore.description= Restores the original folding structure
|
||||
Projection.Restore.image=
|
|
@ -9,6 +9,7 @@
|
|||
* QNX Software Systems - Initial API and implementation
|
||||
* Anton Leherbauer (Wind River Systems)
|
||||
* IBM Corporation
|
||||
* Patrick Hofer - Bug 326265
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
|
@ -18,10 +19,12 @@ import org.eclipse.cdt.make.core.makefile.IDirective;
|
|||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.cdt.make.internal.ui.preferences.MakefileEditorPreferenceConstants;
|
||||
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileWordDetector;
|
||||
import org.eclipse.cdt.make.internal.ui.actions.FoldingActionGroup;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.text.FindReplaceDocumentAdapter;
|
||||
|
@ -62,6 +65,12 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
ProjectionMakefileUpdater fProjectionMakefileUpdater;
|
||||
private FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
|
||||
|
||||
/**
|
||||
* The action group for folding.
|
||||
* @since 7.1
|
||||
*/
|
||||
private FoldingActionGroup fFoldingGroup;
|
||||
|
||||
/**
|
||||
* Reconciling listeners.
|
||||
* @since 3.0
|
||||
|
@ -119,6 +128,26 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
boolean isFoldingEnabled() {
|
||||
return MakeUIPlugin.getDefault().getPreferenceStore().getBoolean(MakefileEditorPreferenceConstants.EDITOR_FOLDING_ENABLED);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#rulerContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
|
||||
*/
|
||||
@Override
|
||||
protected void rulerContextMenuAboutToShow(IMenuManager menu) {
|
||||
super.rulerContextMenuAboutToShow(menu);
|
||||
IMenuManager foldingMenu= new MenuManager(MakefileEditorMessages.MakefileEditor_menu_folding, "projection"); //$NON-NLS-1$
|
||||
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, foldingMenu);
|
||||
|
||||
IAction action= getAction("FoldingToggle"); //$NON-NLS-1$
|
||||
foldingMenu.add(action);
|
||||
action= getAction("FoldingExpandAll"); //$NON-NLS-1$
|
||||
foldingMenu.add(action);
|
||||
action= getAction("FoldingCollapseAll"); //$NON-NLS-1$
|
||||
foldingMenu.add(action);
|
||||
action= getAction("FoldingRestore"); //$NON-NLS-1$
|
||||
foldingMenu.add(action);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IWorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
|
||||
|
@ -158,6 +187,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
/* (non-Javadoc)
|
||||
* Method declared on IAdaptable
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Object getAdapter(Class key) {
|
||||
if (ProjectionAnnotationModel.class.equals(key)) {
|
||||
|
@ -216,6 +246,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
setAction("OpenDeclarationAction", a); //$NON-NLS-1$
|
||||
markAsStateDependentAction("OpenDeclarationAction", true); //$NON-NLS-1$
|
||||
|
||||
fFoldingGroup = new FoldingActionGroup(this, getSourceViewer());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -347,6 +378,15 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
((IReconcilingParticipant)listeners[i]).reconciled();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the folding action group, or <code>null</code> if there is none.
|
||||
*
|
||||
* @return the folding action group, or <code>null</code> if there is none
|
||||
*/
|
||||
protected FoldingActionGroup getFoldingActionGroup() {
|
||||
return fFoldingGroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#performRevert()
|
||||
|
@ -377,6 +417,17 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets the foldings structure according to the folding
|
||||
* preferences.
|
||||
*
|
||||
* @since 7.1
|
||||
*/
|
||||
public void resetProjection() {
|
||||
if (fProjectionMakefileUpdater != null) {
|
||||
fProjectionMakefileUpdater.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.texteditor.AbstractTextEditor#handlePreferenceStoreChanged(org.eclipse.jface.util.PropertyChangeEvent)
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2010 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
* Patrick Hofer - Bug 326265
|
||||
*******************************************************************************/
|
||||
|
||||
// this file is based on org.eclipse.cdt.internal.ui.editor.CEditorMessages
|
||||
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public final class MakefileEditorMessages extends NLS {
|
||||
|
||||
public static String MakefileEditor_menu_folding;
|
||||
|
||||
static {
|
||||
NLS.initializeMessages(MakefileEditorMessages.class.getName(), MakefileEditorMessages.class);
|
||||
}
|
||||
|
||||
// Do not instantiate
|
||||
private MakefileEditorMessages() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#########################################
|
||||
# Copyright (c) 2010 Eclipse CDT Project and others.
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the Eclipse Public License v1.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# http://www.eclipse.org/legal/epl-v10.html
|
||||
#
|
||||
# Contributors:
|
||||
# Patrick Hofer - initial API and implementation
|
||||
#########################################
|
||||
|
||||
MakefileEditor_menu_folding=F&olding
|
Loading…
Add table
Reference in a new issue