📄 verbpopupmenu.java
字号:
/*
* Copyright (c) 2007 Software Wizards Pty Ltd, Victoria, Australia.
* mailto:enquires@swz.com.au. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted. See the GNU General Public License
* for more details.
*
* Redistribution of the SWTtoCOM software is not permitted as part of any
* commercial product. Licensing terms for such distribution may be
* obtained from the copyright holder.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
package au.com.swz.swttocom.example.win32explorer.views;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IMenuListener;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.swt.ole.win32.Variant;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.part.DrillDownAdapter;
import au.com.swz.swttocom.example.win32explorer.shell.FolderItem;
import au.com.swz.swttocom.example.win32explorer.shell.FolderItemVerb;
import au.com.swz.swttocom.example.win32explorer.shell.FolderItemVerbs;
public class VerbPopupMenu implements IMenuListener {
private TreeViewer viewer;
private DrillDownAdapter drillDownAdapter;
VerbPopupMenu(TreeViewer viewer, DrillDownAdapter drillDownAdapter) {
this.viewer = viewer;
this.drillDownAdapter = drillDownAdapter;
}
public void menuAboutToShow(IMenuManager manager) {
ISelection selection = viewer.getSelection();
Object obj = ((IStructuredSelection)selection).getFirstElement();
if (obj instanceof AbstractTreeObject) {
FolderItem folderItem = ((AbstractTreeObject)obj).getFolderItem();
FolderItemVerbs verbs = folderItem.verbs();
if (verbs != null) {
int verbCount = verbs.getCount();
for (int i=0; i<verbCount; i++ ) {
FolderItemVerb verb = verbs.item(new Variant(i));
String verbName = verb.getName();
if ((verbName == null) || (verbName.trim().length() <= 0)) {
manager.add(new Separator());
} else {
manager.add(new VerbAction(verbName, verb));
}
}
}
}
manager.add(new Separator());
if (drillDownAdapter != null) {
drillDownAdapter.addNavigationActions(manager);
}
// Other plug-ins can contribute there actions here
manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
}
private static class VerbAction extends Action {
private FolderItemVerb verb;
VerbAction(String name, FolderItemVerb verb) {
this.verb = verb;
setText(name);
}
public void run() {
verb.doIt();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -