|
From: Christopher W. <caw...@us...> - 2006-06-09 01:19:23
|
Update of /cvsroot/rubyeclipse/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv7890/src/org/rubypeople/rdt/internal/ui/actions Added Files: FoldingMessages.java FoldingMessages.properties FoldingActionGroup.java Log Message: Add a folding action menu to context ruler on left side of editor, and add command shortcuts for actions to manipulatae folding. Now users can collapse/expand all, comments, members, reset structure, etc. --- NEW FILE: FoldingMessages.java --- /******************************************************************************* * Copyright (c) 2000, 2005 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 *******************************************************************************/ package org.rubypeople.rdt.internal.ui.actions; import java.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.rubypeople.rdt.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 * @since 3.0 */ 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); } } --- NEW FILE: FoldingMessages.properties --- 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= Projection.CollapseComments.label= Collapse &Comments Projection.CollapseComments.tooltip= Collapses All Comments Projection.CollapseComments.description= Collapses all comments Projection.CollapseComments.image= Projection.CollapseMembers.label= Collapse &Members Projection.CollapseMembers.tooltip= Collapses All Members Projection.CollapseMembers.description= Collapses all members Projection.CollapseMembers.image= --- NEW FILE: FoldingActionGroup.java --- /******************************************************************************* * Copyright (c) 2000, 2005 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 *******************************************************************************/ package org.rubypeople.rdt.internal.ui.actions; import java.util.ResourceBundle; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.ITextOperationTarget; 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.rubypeople.rdt.internal.ui.RubyPlugin; import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor; import org.rubypeople.rdt.ui.PreferenceConstants; import org.rubypeople.rdt.ui.actions.IRubyEditorActionDefinitionIds; /** * Groups the RDT folding actions. * * @since 0.9.0 */ 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); } } /** * @since 0.9.0 */ 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 final PreferenceAction fToggle; private final TextOperationAction fExpand; private final TextOperationAction fCollapse; private final TextOperationAction fExpandAll; /* since 3.2 */ private final PreferenceAction fRestoreDefaults; private final FoldingAction fCollapseMembers; private final FoldingAction fCollapseComments; private final TextOperationAction fCollapseAll; private final IProjectionListener fProjectionListener; /** * 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; fCollapseMembers= null; fCollapseComments= null; fProjectionListener= null; return; } fViewer= (ProjectionViewer) viewer; fProjectionListener= new IProjectionListener() { public void projectionEnabled() { update(); } public void projectionDisabled() { update(); } }; fViewer.addProjectionListener(fProjectionListener); fToggle= new PreferenceAction(FoldingMessages.getResourceBundle(), "Projection.Toggle.", IAction.AS_CHECK_BOX) { //$NON-NLS-1$ public void run() { IPreferenceStore store= RubyPlugin.getDefault().getPreferenceStore(); boolean current= store.getBoolean(PreferenceConstants.EDITOR_FOLDING_ENABLED); store.setValue(PreferenceConstants.EDITOR_FOLDING_ENABLED, !current); } public void update() { ITextOperationTarget target= (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); boolean isEnabled= (target != null && target.canDoOperation(ProjectionViewer.TOGGLE)); setEnabled(isEnabled); } }; fToggle.setChecked(true); 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$ public void run() { if (editor instanceof RubyEditor) { RubyEditor javaEditor= (RubyEditor) editor; javaEditor.resetProjection(); } } }; fRestoreDefaults.setActionDefinitionId(IFoldingCommandIds.FOLDING_RESTORE); editor.setAction("FoldingRestore", fRestoreDefaults); //$NON-NLS-1$ fCollapseMembers= new FoldingAction(FoldingMessages.getResourceBundle(), "Projection.CollapseMembers.") { //$NON-NLS-1$ public void run() { if (editor instanceof RubyEditor) { RubyEditor javaEditor= (RubyEditor) editor; javaEditor.collapseMembers(); } } }; fCollapseMembers.setActionDefinitionId(IRubyEditorActionDefinitionIds.FOLDING_COLLAPSE_MEMBERS); editor.setAction("FoldingCollapseMembers", fCollapseMembers); //$NON-NLS-1$ fCollapseComments= new FoldingAction(FoldingMessages.getResourceBundle(), "Projection.CollapseComments.") { //$NON-NLS-1$ public void run() { if (editor instanceof RubyEditor) { RubyEditor javaEditor= (RubyEditor) editor; javaEditor.collapseComments(); } } }; fCollapseComments.setActionDefinitionId(IRubyEditorActionDefinitionIds.FOLDING_COLLAPSE_COMMENTS); editor.setAction("FoldingCollapseComments", fCollapseComments); //$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() */ 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(); fCollapseMembers.update(); fCollapseComments.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); manager.add(fCollapseMembers); manager.add(fCollapseComments); } } /* * @see org.eclipse.ui.actions.ActionGroup#updateActionBars() */ public void updateActionBars() { update(); } } |