下面列出了org.eclipse.ui.actions.OpenWithMenu#org.eclipse.search.ui.IContextMenuConstants 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void fillContextMenu(IMenuManager menu) {
super.fillContextMenu(menu);
IMenuManager incomingMenu = menu;
IMenuManager declarationsMenu = new MenuManager(Messages.DeclarationsSearchGroup_Declarations, IContextMenuConstants.GROUP_SEARCH);
if (editor != null){
menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, declarationsMenu);
} else {
incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, declarationsMenu);
}
incomingMenu = declarationsMenu;
incomingMenu.add(findDeclarationsAction);
incomingMenu.add(findDeclarationsProjectAction);
}
@Override
public void fillContextMenu(IMenuManager menu) {
super.fillContextMenu(menu);
IMenuManager incomingMenu = menu;
IMenuManager declarationsMenu = new MenuManager(Messages.ReferencesSearchGroup_References, IContextMenuConstants.GROUP_SEARCH);
if (editor != null){
menu.appendToGroup(ITextEditorActionConstants.GROUP_FIND, declarationsMenu);
} else {
incomingMenu.appendToGroup(IContextMenuConstants.GROUP_SEARCH, declarationsMenu);
}
incomingMenu = declarationsMenu;
incomingMenu.add(findReferencesAction);
incomingMenu.add(findReferencesProjectAction);
}
private void addOpenWithMenu(IMenuManager menu) {
ISelection selection= getContext().getSelection();
if (selection.isEmpty() || !(selection instanceof IStructuredSelection))
return;
IStructuredSelection ss= (IStructuredSelection)selection;
if (ss.size() != 1)
return;
Object o= ss.getFirstElement();
if (!(o instanceof IAdaptable))
return;
IAdaptable element= (IAdaptable)o;
Object resource= element.getAdapter(IResource.class);
if (!(resource instanceof IFile))
return;
// Create a menu.
IMenuManager submenu= new MenuManager("Open With");
submenu.add(new OpenWithMenu(fSite.getPage(), (IFile) resource));
// Add the submenu.
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
}
@Override
public void init(IPageSite site) {
super.init(site);
IMenuManager menuManager = site.getActionBars().getMenuManager();
menuManager.insertBefore(IContextMenuConstants.GROUP_PROPERTIES, new Separator(GROUP_FILTERING));
fActionGroup.fillActionBars(site.getActionBars());
menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new Action(SearchMessages.JavaSearchResultPage_preferences_label) {
@Override
public void run() {
String pageId= "org.eclipse.search.preferences.SearchPreferencePage"; //$NON-NLS-1$
String[] displayedPages= { pageId,
"org.eclipse.ui.editors.preferencePages.Annotations", //$NON-NLS-1$
"org.eclipse.ui.preferencePages.ColorsAndFonts" //$NON-NLS-1$
};
PreferencesUtil.createPreferenceDialogOn(JavaPlugin.getActiveWorkbenchShell(), pageId, displayedPages, null).open();
}
});
}
private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
if (selection == null) {
return;
}
fOpenAction.selectionChanged(selection);
if (fOpenAction.isEnabled()) {
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction);
}
if (selection.size() != 1) {
return;
}
Object o = selection.getFirstElement();
if (!(o instanceof IAdaptable)) {
return;
}
// Create menu
IMenuManager submenu = new MenuManager("Open Wit&h");
submenu.add(new OpenWithMenu(fPage, (IAdaptable) o));
// Add the submenu.
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
}
@Override
protected void fillContextMenu(IMenuManager mgr) {
super.fillContextMenu(mgr);
addSortActions(mgr);
fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
fActionGroup.fillContextMenu(mgr);
AbstractPythonSearchQuery query = (AbstractPythonSearchQuery) getInput().getQuery();
if (query.getSearchString().length() > 0) {
IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
if (!selection.isEmpty()) {
ReplaceAction replaceSelection = new ReplaceAction(getSite().getShell(),
getInput(), selection.toArray(), true);
replaceSelection.setText(SearchMessages.ReplaceAction_label_selected);
mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection);
}
ReplaceAction replaceAll = new ReplaceAction(getSite().getShell(), getInput(),
null, true);
replaceAll.setText(SearchMessages.ReplaceAction_label_all);
mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);
}
}
private void addOpenWithMenu(IMenuManager menu, IStructuredSelection selection) {
if (selection == null) {
return;
}
fOpenAction.selectionChanged(selection);
if (fOpenAction.isEnabled()) {
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, fOpenAction);
}
if (selection.size() != 1) {
return;
}
Object o = selection.getFirstElement();
if (!(o instanceof IAdaptable)) {
return;
}
// Create menu
IMenuManager submenu = new MenuManager(SearchMessages.OpenWithMenu_label);
submenu.add(new OpenWithMenu(fPage, (IAdaptable) o));
// Add the submenu.
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, submenu);
}
protected void fillToolbar(IToolBarManager tbm) {
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, showNextAction);
tbm.appendToGroup(IContextMenuConstants.GROUP_SHOW, showPreviousAction);
IActionBars actionBars = getSite().getActionBars();
if (actionBars != null) {
actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), showNextAction);
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), showPreviousAction);
}
tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, expandAllAction);
tbm.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, collapseAllAction);
}
private void addSortActions(IMenuManager mgr) {
if (getLayout() != FLAG_LAYOUT_FLAT)
return;
MenuManager sortMenu= new MenuManager(SearchMessages.FileSearchPage_sort_by_label);
sortMenu.add(fSortByNameAction);
sortMenu.add(fSortByPathAction);
fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
}
@Override
protected void fillContextMenu(IMenuManager mgr) {
super.fillContextMenu(mgr);
addSortActions(mgr);
mgr.appendToGroup(IContextMenuConstants.GROUP_EDIT, getCopyQualifiedNameAction());
fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
fActionGroup.fillContextMenu(mgr);
}
private void addSortActions(IMenuManager mgr) {
if (getLayout() != FLAG_LAYOUT_FLAT)
return;
MenuManager sortMenu= new MenuManager(SearchMessages.JavaSearchResultPage_sortBylabel);
sortMenu.add(fSortByNameAction);
sortMenu.add(fSortByPathAction);
sortMenu.add(fSortByParentName);
fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
fSortByParentName.setChecked(fCurrentSortOrder == fSortByParentName.getSortOrder());
mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
}
private void addGroupActions(IToolBarManager mgr) {
mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, new Separator(GROUP_GROUPING));
mgr.appendToGroup(GROUP_GROUPING, fGroupProjectAction);
mgr.appendToGroup(GROUP_GROUPING, fGroupPackageAction);
mgr.appendToGroup(GROUP_GROUPING, fGroupFileAction);
mgr.appendToGroup(GROUP_GROUPING, fGroupTypeAction);
updateGroupingActions();
}
@Override
public void fillContextMenu(IMenuManager menu) {
// view must exist if we create a context menu for it.
ISelection selection = getContext().getSelection();
if (selection instanceof IStructuredSelection) {
addOpenWithMenu(menu, (IStructuredSelection) selection);
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled()
&& fOpenPropertiesDialog.isApplicableForSelection((IStructuredSelection) selection)) {
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
}
}
}
@Override
protected void fillContextMenu(IMenuManager mgr) {
super.fillContextMenu(mgr);
fActionGroup.setContext(new ActionContext(getSite().getSelectionProvider().getSelection()));
fActionGroup.fillContextMenu(mgr);
AbstractSearchIndexQuery query = (AbstractSearchIndexQuery) getInput().getQuery();
if (query.getSearchString().length() > 0) {
IStructuredSelection selection = (IStructuredSelection) getViewer().getSelection();
if (!selection.isEmpty()) {
ReplaceAction replaceSelection = new ReplaceAction(getSite().getShell(), getInput(),
selection.toArray(), true);
replaceSelection.setText(SearchMessages.ReplaceAction_label_selected);
mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceSelection);
}
ICallback<Boolean, Match> skipMatch = new ICallback<Boolean, Match>() {
@Override
public Boolean call(Match match) {
StructuredViewer viewer = getViewer();
ViewerFilter[] filters = viewer.getFilters();
if (filters == null || filters.length == 0) {
return false;
}
for (ViewerFilter viewerFilter : filters) {
if (viewerFilter instanceof AbstractSearchResultsViewerFilter) {
AbstractSearchResultsViewerFilter searchResultsViewerFilter = (AbstractSearchResultsViewerFilter) viewerFilter;
if (searchResultsViewerFilter.isLeafMatch(viewer, match)) {
return false;
}
}
}
return true;
}
};
ReplaceAction replaceAll = new ReplaceAction(getSite().getShell(), getInput(), null, true, skipMatch);
replaceAll.setText(SearchMessages.ReplaceAction_label_all);
mgr.appendToGroup(IContextMenuConstants.GROUP_REORGANIZE, replaceAll);
}
}
@Override
protected void fillToolbar(IToolBarManager tbm) {
super.fillToolbar(tbm);
for (Action a : fGroupByActions) {
String id = IContextMenuConstants.GROUP_PROPERTIES + "." + a.hashCode();
a.setId(id);
tbm.add(a);
}
}
private void addSortActions(IMenuManager mgr) {
if (getLayout() != FLAG_LAYOUT_FLAT) {
return;
}
MenuManager sortMenu = new MenuManager(SearchMessages.FileSearchPage_sort_by_label);
sortMenu.add(fSortByNameAction);
sortMenu.add(fSortByPathAction);
fSortByNameAction.setChecked(fCurrentSortOrder == fSortByNameAction.getSortOrder());
fSortByPathAction.setChecked(fCurrentSortOrder == fSortByPathAction.getSortOrder());
mgr.appendToGroup(IContextMenuConstants.GROUP_VIEWER_SETUP, sortMenu);
}
@Override
public void fillContextMenu(IMenuManager menu) {
// view must exist if we create a context menu for it.
ISelection selection = getContext().getSelection();
if (selection instanceof IStructuredSelection) {
addOpenWithMenu(menu, (IStructuredSelection) selection);
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled()
&& fOpenPropertiesDialog.isApplicableForSelection((IStructuredSelection) selection)) {
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
}
}
}
private void appendToGroup(IMenuManager menu, IAction action) {
if (action.isEnabled())
menu.appendToGroup(IContextMenuConstants.GROUP_OPEN, action);
}
public void init(IPageSite site) {
super.init(site);
IMenuManager menuManager = site.getActionBars().getMenuManager();
menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new OpenSearchPreferencesAction());
}
@Override
public void init(IPageSite site) {
super.init(site);
IMenuManager menuManager = site.getActionBars().getMenuManager();
menuManager.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, new OpenSearchPreferencesAction());
}