我正在尝试从菜单栏中捕获用户选择,例如,如果用户在菜单中按下文件,我的插件将打印“按下文件”。我想出了如何收听 IselectionService 的视图选择,但仍然不知道如何使用主菜单栏(或工具栏)来做到这一点。
感谢帮助
更多细节 :
我将更准确地解释我的问题:
我想捕获顶级菜单操作和工具栏,问题是我真的不知道如何创建和附加侦听器。
这是ISelectionListener
插件的。
我的目的是收听工作台的顶级菜单选择和工具栏。
感谢帮助
// the listener we register with the selection service
private ISelectionListener listener = new ISelectionListener() {
public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) {
// we ignore our own selections
if (sourcepart != SelectionView.this) {
showSelection(sourcepart, selection);
}
}
};
...
...
public void createPartControl(Composite parent) {
...
getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener);
PS:我发现的关于菜单监听器的大部分内容都是我创建的某些视图或窗口的 SWT 内容,这不是我的意思,我需要监听 eclipse 工作台中的主顶级菜单和工具栏。