mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
Removes unused WorkingSetFilterActions, they are provided by the platform nowadays.
This commit is contained in:
parent
de97370998
commit
12e256794c
7 changed files with 0 additions and 742 deletions
|
@ -1,43 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.internal.ui.workingsets.WorkingSetMessages;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Clears the selected working set in the action group's view.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class ClearWorkingSetAction extends Action {
|
||||
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public ClearWorkingSetAction(WorkingSetFilterActionGroup actionGroup) {
|
||||
super(WorkingSetMessages.getString("ClearWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("ClearWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
setEnabled(actionGroup.getWorkingSet() != null);
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ICHelpContextIds.CLEAR_WORKING_SET_ACTION);
|
||||
fActionGroup= actionGroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
fActionGroup.setWorkingSet(null, true);
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.jface.wizard.WizardDialog;
|
||||
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.IWorkingSetEditWizard;
|
||||
|
||||
|
||||
/**
|
||||
* Displays an IWorkingSetEditWizard for editing a working set.
|
||||
*
|
||||
* @since 2.1
|
||||
*/
|
||||
public class EditWorkingSetAction extends Action {
|
||||
private Shell fShell;
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public EditWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
|
||||
super(WorkingSetMessages.getString("EditWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("EditWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
setEnabled(actionGroup.getWorkingSet() != null);
|
||||
fShell= shell;
|
||||
fActionGroup= actionGroup;
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ICHelpContextIds.EDIT_WORKING_SET_ACTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
if (fShell == null)
|
||||
fShell= CUIPlugin.getActiveWorkbenchShell();
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
IWorkingSet workingSet= fActionGroup.getWorkingSet();
|
||||
if (workingSet == null) {
|
||||
setEnabled(false);
|
||||
return;
|
||||
}
|
||||
IWorkingSetEditWizard wizard= manager.createWorkingSetEditWizard(workingSet);
|
||||
if (wizard == null) {
|
||||
String title= WorkingSetMessages.getString("EditWorkingSetAction.nowizard.title"); //$NON-NLS-1$
|
||||
String message= WorkingSetMessages.getString("EditWorkingSetAction.nowizard.message"); //$NON-NLS-1$
|
||||
MessageDialog.openError(fShell, title, message);
|
||||
return;
|
||||
}
|
||||
WizardDialog dialog= new WizardDialog(fShell, wizard);
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK)
|
||||
fActionGroup.setWorkingSet(wizard.getSelection(), true);
|
||||
}
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.IWorkingSetSelectionDialog;
|
||||
|
||||
/**
|
||||
* Displays an IWorkingSetSelectionDialog and sets the selected
|
||||
* working set in the action group's view.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class SelectWorkingSetAction extends Action {
|
||||
private Shell fShell;
|
||||
private WorkingSetFilterActionGroup fActionGroup;
|
||||
|
||||
public SelectWorkingSetAction(WorkingSetFilterActionGroup actionGroup, Shell shell) {
|
||||
super(WorkingSetMessages.getString("SelectWorkingSetAction.text")); //$NON-NLS-1$
|
||||
Assert.isNotNull(actionGroup);
|
||||
setToolTipText(WorkingSetMessages.getString("SelectWorkingSetAction.toolTip")); //$NON-NLS-1$
|
||||
|
||||
fShell= shell;
|
||||
fActionGroup= actionGroup;
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(this, ICHelpContextIds.SELECT_WORKING_SET_ACTION);
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from Action
|
||||
*/
|
||||
public void run() {
|
||||
if (fShell == null)
|
||||
fShell= CUIPlugin.getActiveWorkbenchShell();
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
IWorkingSetSelectionDialog dialog= manager.createWorkingSetSelectionDialog(fShell, false);
|
||||
IWorkingSet workingSet= fActionGroup.getWorkingSet();
|
||||
if (workingSet != null)
|
||||
dialog.setSelection(new IWorkingSet[]{workingSet});
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
IWorkingSet[] result= dialog.getSelection();
|
||||
if (result != null && result.length > 0) {
|
||||
fActionGroup.setWorkingSet(result[0], true);
|
||||
manager.addRecentWorkingSet(result[0]);
|
||||
}
|
||||
else
|
||||
fActionGroup.setWorkingSet(null, true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,205 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IPathEntryContainer;
|
||||
import org.eclipse.cdt.core.model.ISourceRoot;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.internal.corext.util.CModelUtil;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.IStorage;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
|
||||
/**
|
||||
* Working set filter for Java viewers.
|
||||
*/
|
||||
public class WorkingSetFilter extends ViewerFilter {
|
||||
private IWorkingSet fWorkingSet= null;
|
||||
private IAdaptable[] fCachedWorkingSet= null;
|
||||
|
||||
/**
|
||||
* Returns the working set which is used by this filter.
|
||||
*
|
||||
* @return the working set
|
||||
*/
|
||||
public IWorkingSet getWorkingSet() {
|
||||
return fWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this filter's working set.
|
||||
*
|
||||
* @param workingSet the working set
|
||||
*/
|
||||
public void setWorkingSet(IWorkingSet workingSet) {
|
||||
fWorkingSet= workingSet;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ViewerFilter.
|
||||
*/
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (fWorkingSet == null)
|
||||
return true;
|
||||
|
||||
if (element instanceof ICElement)
|
||||
return isEnclosing((ICElement)element);
|
||||
|
||||
if (element instanceof IResource)
|
||||
return isEnclosing(((IResource)element).getFullPath());
|
||||
|
||||
if (element instanceof IPathEntryContainer) {
|
||||
return isEnclosing((IPathEntryContainer)element);
|
||||
}
|
||||
|
||||
if (element instanceof IAdaptable) {
|
||||
IAdaptable adaptable= (IAdaptable)element;
|
||||
ICElement je= (ICElement)adaptable.getAdapter(ICElement.class);
|
||||
if (je != null)
|
||||
return isEnclosing(je);
|
||||
|
||||
IResource resource= (IResource)adaptable.getAdapter(IResource.class);
|
||||
if (resource != null)
|
||||
return isEnclosing(resource.getFullPath());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IPathEntryContainer container) {
|
||||
// check whether the containing packagefragment root is enclosed
|
||||
return isEnclosing(container.getPath());
|
||||
// IPathEntry[] entries = container.getPathEntries();
|
||||
// if (entries != null && entries.length > 0) {
|
||||
// return isEnclosing(entries[0].getPath());
|
||||
// }
|
||||
// return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ViewerFilter
|
||||
*/
|
||||
public Object[] filter(Viewer viewer, Object parent, Object[] elements) {
|
||||
Object[] result= null;
|
||||
if (fWorkingSet != null)
|
||||
fCachedWorkingSet= fWorkingSet.getElements();
|
||||
try {
|
||||
result= super.filter(viewer, parent, elements);
|
||||
} finally {
|
||||
fCachedWorkingSet= null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IPath elementPath) {
|
||||
if (elementPath == null)
|
||||
return false;
|
||||
|
||||
IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
|
||||
if (cachedWorkingSet == null)
|
||||
cachedWorkingSet= fWorkingSet.getElements();
|
||||
|
||||
int length= cachedWorkingSet.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
if (isEnclosing(cachedWorkingSet[i], elementPath))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEnclosing(ICElement element) {
|
||||
IAdaptable[] cachedWorkingSet= fCachedWorkingSet;
|
||||
if (cachedWorkingSet == null)
|
||||
cachedWorkingSet= fWorkingSet.getElements();
|
||||
|
||||
boolean isElementPathComputed= false;
|
||||
IPath elementPath= null; // will be lazy computed if needed
|
||||
|
||||
int length= cachedWorkingSet.length;
|
||||
for (int i= 0; i < length; i++) {
|
||||
ICElement scopeElement= (ICElement)cachedWorkingSet[i].getAdapter(ICElement.class);
|
||||
if (scopeElement != null) {
|
||||
// compare Java elements
|
||||
ICElement searchedElement= element;
|
||||
while (scopeElement != null && searchedElement != null) {
|
||||
if (searchedElement.equals(scopeElement)) {
|
||||
return true;
|
||||
}
|
||||
if (scopeElement instanceof ICProject && searchedElement instanceof ISourceRoot) {
|
||||
// ISourceRoot pkgRoot= (ISourceRoot)searchedElement;
|
||||
// if (pkgRoot.isExternal() && pkgRoot.isArchive()) {
|
||||
// if (((ICProject)scopeElement).isOnClasspath(searchedElement))
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
searchedElement= searchedElement.getParent();
|
||||
if (searchedElement != null && searchedElement.getElementType() == ICElement.C_UNIT) {
|
||||
ITranslationUnit cu= (ITranslationUnit)searchedElement;
|
||||
cu= CModelUtil.toOriginal(cu);
|
||||
}
|
||||
}
|
||||
while (scopeElement != null && element != null) {
|
||||
if (element.equals(scopeElement))
|
||||
return true;
|
||||
scopeElement= scopeElement.getParent();
|
||||
}
|
||||
} else {
|
||||
// compare resource paths
|
||||
if (!isElementPathComputed) {
|
||||
IResource elementResource= (IResource)element.getAdapter(IResource.class);
|
||||
if (elementResource != null)
|
||||
elementPath= elementResource.getFullPath();
|
||||
}
|
||||
if (isEnclosing(cachedWorkingSet[i], elementPath))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isEnclosing(IAdaptable element, IPath path) {
|
||||
if (path == null)
|
||||
return false;
|
||||
|
||||
IPath elementPath= null;
|
||||
|
||||
IResource elementResource= (IResource)element.getAdapter(IResource.class);
|
||||
if (elementResource != null)
|
||||
elementPath= elementResource.getFullPath();
|
||||
|
||||
if (elementPath == null) {
|
||||
ICElement cElement= (ICElement)element.getAdapter(ICElement.class);
|
||||
if (cElement != null)
|
||||
elementPath= cElement.getPath();
|
||||
}
|
||||
|
||||
if (elementPath == null && element instanceof IStorage)
|
||||
elementPath= ((IStorage)element).getFullPath();
|
||||
|
||||
if (elementPath == null)
|
||||
return false;
|
||||
|
||||
if (elementPath.isPrefixOf(path))
|
||||
return true;
|
||||
|
||||
if (path.isPrefixOf(elementPath))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,256 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
import org.eclipse.jface.action.IContributionItem;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||
import org.eclipse.jface.util.PropertyChangeEvent;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.IMemento;
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
|
||||
/**
|
||||
* Working set filter actions (set / clear)
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class WorkingSetFilterActionGroup extends ActionGroup {
|
||||
|
||||
private static final String TAG_WORKING_SET_NAME= "workingSetName"; //$NON-NLS-1$
|
||||
private static final String SEPARATOR_ID= "workingSetGroupSeparator"; //$NON-NLS-1$
|
||||
|
||||
private WorkingSetFilter fWorkingSetFilter;
|
||||
|
||||
private IWorkingSet fWorkingSet= null;
|
||||
|
||||
private ClearWorkingSetAction fClearWorkingSetAction;
|
||||
private SelectWorkingSetAction fSelectWorkingSetAction;
|
||||
private EditWorkingSetAction fEditWorkingSetAction;
|
||||
|
||||
private IPropertyChangeListener fWorkingSetListener;
|
||||
|
||||
private IPropertyChangeListener fChangeListener;
|
||||
|
||||
private int fLRUMenuCount;
|
||||
private IMenuManager fMenuManager;
|
||||
private IMenuListener fMenuListener;
|
||||
|
||||
public WorkingSetFilterActionGroup(String viewId, Shell shell, IPropertyChangeListener changeListener) {
|
||||
Assert.isNotNull(viewId);
|
||||
Assert.isNotNull(shell);
|
||||
Assert.isNotNull(changeListener);
|
||||
|
||||
fChangeListener= changeListener;
|
||||
fClearWorkingSetAction= new ClearWorkingSetAction(this);
|
||||
fSelectWorkingSetAction= new SelectWorkingSetAction(this, shell);
|
||||
fEditWorkingSetAction= new EditWorkingSetAction(this, shell);
|
||||
|
||||
fWorkingSetListener= new IPropertyChangeListener() {
|
||||
public void propertyChange(PropertyChangeEvent event) {
|
||||
doPropertyChange(event);
|
||||
}
|
||||
};
|
||||
|
||||
fWorkingSetFilter= new WorkingSetFilter();
|
||||
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
manager.addPropertyChangeListener(fWorkingSetListener);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether the current working set filters the given element
|
||||
*
|
||||
* @param parent the parent
|
||||
* @param object the elemnt to test
|
||||
* @return the working set
|
||||
*/
|
||||
public boolean isFiltered(Object parent, Object object) {
|
||||
if (fWorkingSetFilter == null)
|
||||
return false;
|
||||
return !fWorkingSetFilter.select(null, parent, object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the working set which is used by the filter.
|
||||
*
|
||||
* @return the working set
|
||||
*/
|
||||
public IWorkingSet getWorkingSet() {
|
||||
return fWorkingSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets this filter's working set.
|
||||
*
|
||||
* @param workingSet the working set
|
||||
* @param refreshViewer Indiactes if the viewer should be refreshed.
|
||||
*/
|
||||
public void setWorkingSet(IWorkingSet workingSet, boolean refreshViewer) {
|
||||
// Update action
|
||||
fClearWorkingSetAction.setEnabled(workingSet != null);
|
||||
fEditWorkingSetAction.setEnabled(workingSet != null);
|
||||
|
||||
fWorkingSet= workingSet;
|
||||
|
||||
fWorkingSetFilter.setWorkingSet(workingSet);
|
||||
if (refreshViewer) {
|
||||
fChangeListener.propertyChange(new PropertyChangeEvent(this, IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE, null, workingSet));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the state of the filter actions in a memento.
|
||||
*
|
||||
* @param memento the memento
|
||||
*/
|
||||
public void saveState(IMemento memento) {
|
||||
String workingSetName= ""; //$NON-NLS-1$
|
||||
if (fWorkingSet != null)
|
||||
workingSetName= fWorkingSet.getName();
|
||||
memento.putString(TAG_WORKING_SET_NAME, workingSetName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the state of the filter actions from a memento.
|
||||
* <p>
|
||||
* Note: This method does not refresh the viewer.
|
||||
* </p>
|
||||
* @param memento
|
||||
*/
|
||||
public void restoreState(IMemento memento) {
|
||||
String workingSetName= memento.getString(TAG_WORKING_SET_NAME);
|
||||
IWorkingSet ws= PlatformUI.getWorkbench().getWorkingSetManager().getWorkingSet(workingSetName);
|
||||
setWorkingSet(ws, false);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ActionGroup#fillActionBars(IActionBars)
|
||||
*/
|
||||
public void fillActionBars(IActionBars actionBars) {
|
||||
contributeToToolBar(actionBars.getToolBarManager());
|
||||
contributeToMenu(actionBars.getMenuManager());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filter actions to the tool bar
|
||||
*
|
||||
* @param tbm the tool bar manager
|
||||
*/
|
||||
public void contributeToToolBar(IToolBarManager tbm) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the filter actions to the menu
|
||||
*
|
||||
* @param mm the menu manager
|
||||
*/
|
||||
public void contributeToMenu(IMenuManager mm) {
|
||||
mm.add(fSelectWorkingSetAction);
|
||||
mm.add(fClearWorkingSetAction);
|
||||
mm.add(fEditWorkingSetAction);
|
||||
mm.add(new Separator());
|
||||
mm.add(new Separator(SEPARATOR_ID));
|
||||
addLRUWorkingSetActions(mm);
|
||||
|
||||
fMenuManager= mm;
|
||||
fMenuListener= new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
removePreviousLRUWorkingSetActions(manager);
|
||||
addLRUWorkingSetActions(manager);
|
||||
}
|
||||
};
|
||||
fMenuManager.addMenuListener(fMenuListener);
|
||||
}
|
||||
|
||||
void removePreviousLRUWorkingSetActions(IMenuManager mm) {
|
||||
for (int i= 1; i <= fLRUMenuCount; i++)
|
||||
mm.remove(WorkingSetMenuContributionItem.getId(i));
|
||||
}
|
||||
|
||||
void addLRUWorkingSetActions(IMenuManager mm) {
|
||||
IWorkingSet[] workingSets= PlatformUI.getWorkbench().getWorkingSetManager().getRecentWorkingSets();
|
||||
List sortedWorkingSets= Arrays.asList(workingSets);
|
||||
Collections.sort(sortedWorkingSets, new WorkingSetComparator());
|
||||
|
||||
Iterator iter= sortedWorkingSets.iterator();
|
||||
int i= 0;
|
||||
while (iter.hasNext()) {
|
||||
IWorkingSet workingSet= (IWorkingSet)iter.next();
|
||||
if (workingSet != null) {
|
||||
IContributionItem item= new WorkingSetMenuContributionItem(++i, this, workingSet);
|
||||
mm.insertBefore(SEPARATOR_ID, item);
|
||||
}
|
||||
}
|
||||
fLRUMenuCount= i;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ActionGroup#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fMenuManager != null)
|
||||
fMenuManager.removeMenuListener(fMenuListener);
|
||||
|
||||
if (fWorkingSetListener != null) {
|
||||
PlatformUI.getWorkbench().getWorkingSetManager().removePropertyChangeListener(fWorkingSetListener);
|
||||
fWorkingSetListener= null;
|
||||
}
|
||||
fChangeListener= null; // clear the reference to the viewer
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Returns viewer filter always confugured with the current working set.
|
||||
*/
|
||||
public ViewerFilter getWorkingSetFilter() {
|
||||
return fWorkingSetFilter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by the working set change listener
|
||||
*/
|
||||
void doPropertyChange(PropertyChangeEvent event) {
|
||||
String property= event.getProperty();
|
||||
if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property)) {
|
||||
fChangeListener.propertyChange(event);
|
||||
} else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property)) {
|
||||
IWorkingSet newWorkingSet= (IWorkingSet) event.getNewValue();
|
||||
if (newWorkingSet.equals(fWorkingSet)) {
|
||||
fChangeListener.propertyChange(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2006 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.eclipse.cdt.internal.ui.workingsets;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.MenuItem;
|
||||
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.jface.util.Assert;
|
||||
|
||||
import org.eclipse.ui.IWorkingSet;
|
||||
import org.eclipse.ui.IWorkingSetManager;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
/**
|
||||
* Menu contribution item which shows and lets select a working set.
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class WorkingSetMenuContributionItem extends ContributionItem {
|
||||
|
||||
private int fId;
|
||||
IWorkingSet fWorkingSet;
|
||||
WorkingSetFilterActionGroup fActionGroup;
|
||||
private Image fImage;
|
||||
|
||||
/**
|
||||
* Constructor for WorkingSetMenuContributionItem.
|
||||
*
|
||||
* @param id the id
|
||||
* @param actionGroup the action group
|
||||
* @param workingSet the working set
|
||||
*/
|
||||
public WorkingSetMenuContributionItem(int id, WorkingSetFilterActionGroup actionGroup, IWorkingSet workingSet) {
|
||||
super(getId(id));
|
||||
Assert.isNotNull(actionGroup);
|
||||
Assert.isNotNull(workingSet);
|
||||
fId= id;
|
||||
fActionGroup= actionGroup;
|
||||
fWorkingSet= workingSet;
|
||||
}
|
||||
|
||||
/*
|
||||
* Overrides method from ContributionItem.
|
||||
*/
|
||||
public void fill(Menu menu, int index) {
|
||||
MenuItem mi= new MenuItem(menu, SWT.RADIO, index);
|
||||
mi.setText("&" + fId + " " + fWorkingSet.getName()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
if (fImage == null)
|
||||
fImage= fWorkingSet.getImage().createImage();
|
||||
mi.setImage(fImage);
|
||||
mi.setSelection(fWorkingSet.equals(fActionGroup.getWorkingSet()));
|
||||
mi.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
IWorkingSetManager manager= PlatformUI.getWorkbench().getWorkingSetManager();
|
||||
fActionGroup.setWorkingSet(fWorkingSet, true);
|
||||
manager.addRecentWorkingSet(fWorkingSet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.action.ContributionItem#dispose()
|
||||
* @since 3.0
|
||||
*/
|
||||
public void dispose() {
|
||||
if (fImage != null && !fImage.isDisposed())
|
||||
fImage.dispose();
|
||||
fImage= null;
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.action.IContributionItem#isDynamic()
|
||||
*/
|
||||
public boolean isDynamic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
static String getId(int id) {
|
||||
return WorkingSetMenuContributionItem.class.getName() + "." + id; //$NON-NLS-1$
|
||||
}
|
||||
}
|
|
@ -21,11 +21,7 @@ CElementWorkingSetPage.warning.nameWhitespace= The name must not have leading or
|
|||
CElementWorkingSetPage.projectClosedDialog.message= A closed project can not be modified
|
||||
CElementWorkingSetPage.projectClosedDialog.title= Working Set Change
|
||||
|
||||
SelectWorkingSetAction.text= Select &Working Set...
|
||||
SelectWorkingSetAction.toolTip= Select a working set
|
||||
EditWorkingSetAction.text= &Edit Active Working Set...
|
||||
EditWorkingSetAction.toolTip= Edit the active working set
|
||||
EditWorkingSetAction.nowizard.title= Edit Working Set
|
||||
EditWorkingSetAction.nowizard.message= Can not edit the active working set.
|
||||
ClearWorkingSetAction.text= Deselect Wor&king Set
|
||||
ClearWorkingSetAction.toolTip= Deselect the active working set
|
||||
|
|
Loading…
Add table
Reference in a new issue