use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method createPartControl.
/**
* The <code>AbstractTextEditor</code> implementation of this
* <code>IWorkbenchPart</code> method creates the vertical ruler and
* source viewer.
* <p>
* Subclasses may extend this method. Besides extending this method, the
* behavior of <code>createPartControl</code> may be customized by
* calling, extending or replacing the following methods: <br>
* Subclasses may supply customized implementations for some members using
* the following methods before <code>createPartControl</code> is invoked:
* <ul>
* <li>
* {@linkplain #setSourceViewerConfiguration(SourceViewerConfiguration) setSourceViewerConfiguration}
* to supply a custom source viewer configuration,</li>
* <li>{@linkplain #setRangeIndicator(Annotation) setRangeIndicator} to
* provide a range indicator,</li>
* <li>{@linkplain #setHelpContextId(String) setHelpContextId} to provide a
* help context id,</li>
* <li>{@linkplain #setEditorContextMenuId(String) setEditorContextMenuId}
* to set a custom context menu id,</li>
* <li>{@linkplain #setRulerContextMenuId(String) setRulerContextMenuId} to
* set a custom ruler context menu id.</li>
* </ul>
* <br>
* Subclasses may replace the following methods called from within
* <code>createPartControl</code>:
* <ul>
* <li>{@linkplain #createVerticalRuler() createVerticalRuler} to supply a
* custom vertical ruler,</li>
* <li>{@linkplain #createSourceViewer(Composite, IVerticalRuler, int) createSourceViewer}
* to supply a custom source viewer,</li>
* <li>{@linkplain #getSelectionProvider() getSelectionProvider} to supply
* a custom selection provider.</li>
* </ul>
* <br>
* Subclasses may extend the following methods called from within
* <code>createPartControl</code>:
* <ul>
* <li>
* {@linkplain #initializeViewerColors(ISourceViewer) initializeViewerColors}
* to customize the viewer color scheme (may also be replaced),</li>
* <li>
* {@linkplain #initializeDragAndDrop(ISourceViewer) initializeDragAndDrop}
* to customize drag and drop (may also be replaced),</li>
* <li>{@linkplain #createNavigationActions() createNavigationActions} to
* add navigation actions,</li>
* <li>{@linkplain #createActions() createActions} to add text editor
* actions.</li>
* </ul>
* </p>
*
* @param parent the parent composite
*/
@Override
public void createPartControl(Composite parent) {
fVerticalRuler = createVerticalRuler();
int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
fSourceViewer = createSourceViewer(parent, fVerticalRuler, styles);
if (fConfiguration == null)
fConfiguration = new SourceViewerConfiguration();
fSourceViewer.configure(fConfiguration);
if (fSourceViewer instanceof ISourceViewerExtension4)
fKeyBindingSupportForContentAssistant = new KeyBindingSupportForAssistant(((ISourceViewerExtension4) fSourceViewer));
if (fSourceViewer instanceof ISourceViewerExtension3) {
IQuickAssistAssistant assistant = ((ISourceViewerExtension3) fSourceViewer).getQuickAssistAssistant();
if (assistant != null)
fKeyBindingSupportForQuickAssistant = new KeyBindingSupportForAssistant(assistant);
}
if (fRangeIndicator != null)
fSourceViewer.setRangeIndicator(fRangeIndicator);
fSourceViewer.addTextListener(fTextListener);
fSourceViewer.addTextInputListener(fTextListener);
getSelectionProvider().addSelectionChangedListener(getSelectionChangedListener());
initializeViewerFont(fSourceViewer);
initializeViewerColors(fSourceViewer);
initializeFindScopeColor(fSourceViewer);
initializeDragAndDrop(fSourceViewer);
StyledText styledText = fSourceViewer.getTextWidget();
styledText.addMouseListener(getCursorListener());
styledText.addKeyListener(getCursorListener());
// Disable orientation switching until we fully support it.
styledText.addListener(SWT.OrientationChange, new Listener() {
@Override
public void handleEvent(Event event) {
event.doit = false;
}
});
if (getHelpContextId() != null)
PlatformUI.getWorkbench().getHelpSystem().setHelp(styledText, getHelpContextId());
String id = fEditorContextMenuId != null ? fEditorContextMenuId : DEFAULT_EDITOR_CONTEXT_MENU_ID;
MenuManager manager = new MenuManager(id, id);
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(getContextMenuListener());
fTextContextMenu = manager.createContextMenu(styledText);
styledText.setMenu(fTextContextMenu);
if (fEditorContextMenuId != null)
getEditorSite().registerContextMenu(fEditorContextMenuId, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
else if (fCompatibilityMode)
getEditorSite().registerContextMenu(DEFAULT_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
if ((fEditorContextMenuId != null && fCompatibilityMode) || fEditorContextMenuId == null) {
String partId = getEditorSite().getId();
if (partId != null)
// $NON-NLS-1$
getEditorSite().registerContextMenu(partId + ".EditorContext", manager, getSelectionProvider(), isEditorInputIncludedInContextMenu());
}
getEditorSite().registerContextMenu(COMMON_EDITOR_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if (fEditorContextMenuId == null)
fEditorContextMenuId = DEFAULT_EDITOR_CONTEXT_MENU_ID;
id = fRulerContextMenuId != null ? fRulerContextMenuId : DEFAULT_RULER_CONTEXT_MENU_ID;
manager = new MenuManager(id, id);
manager.setRemoveAllWhenShown(true);
manager.addMenuListener(getContextMenuListener());
Control rulerControl = fVerticalRuler.getControl();
fRulerContextMenu = manager.createContextMenu(rulerControl);
rulerControl.setMenu(fRulerContextMenu);
rulerControl.addMouseListener(getRulerMouseListener());
if (fRulerContextMenuId != null)
getEditorSite().registerContextMenu(fRulerContextMenuId, manager, getSelectionProvider(), false);
else if (fCompatibilityMode)
getEditorSite().registerContextMenu(DEFAULT_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if ((fRulerContextMenuId != null && fCompatibilityMode) || fRulerContextMenuId == null) {
String partId = getSite().getId();
if (partId != null)
// $NON-NLS-1$
getEditorSite().registerContextMenu(partId + ".RulerContext", manager, getSelectionProvider(), false);
}
getEditorSite().registerContextMenu(COMMON_RULER_CONTEXT_MENU_ID, manager, getSelectionProvider(), false);
if (fRulerContextMenuId == null)
fRulerContextMenuId = DEFAULT_RULER_CONTEXT_MENU_ID;
initializeZoomGestures(rulerControl, fSourceViewer);
getSite().setSelectionProvider(getSelectionProvider());
fSelectionListener = new SelectionListener();
fSelectionListener.install(getSelectionProvider());
fSelectionListener.setDocument(getDocumentProvider().getDocument(getEditorInput()));
initializeActivationCodeTrigger();
createNavigationActions();
createAccessibilityActions();
createActions();
initializeSourceViewer(getEditorInput());
/* since 3.2 - undo redo actions should be created after
* the source viewer is initialized, so that the undo manager
* can obtain its undo context from its document.
*/
createUndoRedoActions();
JFaceResources.getFontRegistry().addListener(fFontPropertyChangeListener);
IVerticalRuler ruler = getVerticalRuler();
if (ruler instanceof CompositeRuler)
updateContributedRulerColumns((CompositeRuler) ruler);
if (isWordWrapSupported()) {
setWordWrap(getInitialWordWrapStatus());
}
}
use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method editorContextMenuAboutToShow.
@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
IAction preferencesAction = getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES);
menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
menu.appendToGroup(ITextEditorActionConstants.GROUP_SAVE, new Separator(ITextEditorActionConstants.GROUP_OPEN));
IEditorInput editorInput = getEditorInput();
if ((editorInput.getAdapter(IResource.class)) instanceof IFile) {
MenuManager openWithSubMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_openWith_menu);
final IWorkbenchPage page = getEditorSite().getPage();
// XXX: Internal reference will get fixed during 3.7, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=307026
openWithSubMenu.add(new OpenWithMenu(page, editorInput) {
@Override
protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
super.openEditor(editorDescriptor, openUsingDescriptor);
ISelection selection = getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
revealInEditor(page.getActiveEditor(), ((ITextSelection) selection).getOffset(), ((ITextSelection) selection).getLength());
}
}
});
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, openWithSubMenu);
}
MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getEditorSite().getWorkbenchWindow()));
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, showInSubMenu);
}
use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method createOverviewRulerContextMenu.
/**
* Creates the context menu for the overview ruler.
* <p>
* Subclasses may extend or replace this method.
* </p>
*
* @since 3.4
*/
protected void createOverviewRulerContextMenu() {
if (fOverviewRulerContextMenuId == null)
fOverviewRulerContextMenuId = DEFAULT_OVERVIEW_RULER_CONTEXT_MENU_ID;
if (fOverviewRuler == null || fOverviewRuler.getControl() == null)
return;
MenuManager menuManager = new MenuManager(fOverviewRulerContextMenuId, fOverviewRulerContextMenuId);
menuManager.setRemoveAllWhenShown(true);
menuManager.addMenuListener(getContextMenuListener());
Menu menu = menuManager.createContextMenu(getOverviewRuler().getControl());
getOverviewRuler().getControl().setMenu(menu);
getEditorSite().registerContextMenu(fOverviewRulerContextMenuId, menuManager, getSelectionProvider(), false);
}
use of org.eclipse.jface.action.MenuManager in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method rulerContextMenuAboutToShow.
@Override
protected void rulerContextMenuAboutToShow(IMenuManager menu) {
/*
* XXX: workaround for reliable menu item ordering.
* This can be changed once the action contribution story converges,
* see http://dev.eclipse.org/viewcvs/index.cgi/~checkout~/platform-ui-home/R3_1/dynamic_teams/dynamic_teams.html#actionContributions
*/
// pre-install menus for contributions and call super
// $NON-NLS-1$
menu.add(new Separator("debug"));
menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
menu.add(new GroupMarker(ITextEditorActionConstants.GROUP_RESTORE));
// $NON-NLS-1$
menu.add(new Separator("add"));
menu.add(new Separator(ITextEditorActionConstants.GROUP_RULERS));
menu.add(new Separator(ITextEditorActionConstants.GROUP_REST));
super.rulerContextMenuAboutToShow(menu);
addRulerContributionActions(menu);
/* quick diff */
if (isEditorInputModifiable()) {
IAction quickdiffAction = getAction(ITextEditorActionConstants.QUICKDIFF_TOGGLE);
quickdiffAction.setChecked(isChangeInformationShowing());
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, quickdiffAction);
if (isChangeInformationShowing()) {
TextEditorAction revertLine = new RevertLineAction(this, true);
TextEditorAction revertSelection = new RevertSelectionAction(this, true);
TextEditorAction revertBlock = new RevertBlockAction(this, true);
TextEditorAction revertDeletion = new RestoreAction(this, true);
revertSelection.update();
revertBlock.update();
revertLine.update();
revertDeletion.update();
// only add block action if selection action is not enabled
if (revertSelection.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertSelection);
else if (revertBlock.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertBlock);
if (revertLine.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertLine);
if (revertDeletion.isEnabled())
menu.appendToGroup(ITextEditorActionConstants.GROUP_RESTORE, revertDeletion);
}
}
// revision info
if (fLineColumn != null && fLineColumn.isShowingRevisionInformation()) {
IMenuManager revisionMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_revisions_menu);
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, revisionMenu);
IAction hideRevisionInfoAction = getAction(ITextEditorActionConstants.REVISION_HIDE_INFO);
revisionMenu.add(hideRevisionInfoAction);
revisionMenu.add(new Separator());
String[] labels = { TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_date, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author, TextEditorMessages.AbstractDecoratedTextEditor_revision_colors_option_by_author_and_date };
final RenderingMode[] modes = { IRevisionRulerColumnExtension.AGE, IRevisionRulerColumnExtension.AUTHOR, IRevisionRulerColumnExtension.AUTHOR_SHADED_BY_AGE };
final IPreferenceStore uiStore = EditorsUI.getPreferenceStore();
String current = uiStore.getString(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE);
for (int i = 0; i < modes.length; i++) {
final String mode = modes[i].name();
IAction action = new Action(labels[i], IAction.AS_RADIO_BUTTON) {
@Override
public void run() {
// set preference globally, LineNumberColumn reacts on preference change
uiStore.setValue(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, mode);
}
};
action.setChecked(mode.equals(current));
revisionMenu.add(action);
}
revisionMenu.add(new Separator());
IAction action = getAction(ITextEditorActionConstants.REVISION_SHOW_AUTHOR_TOGGLE);
if (action instanceof IUpdate)
((IUpdate) action).update();
revisionMenu.add(action);
action = getAction(ITextEditorActionConstants.REVISION_SHOW_ID_TOGGLE);
if (action instanceof IUpdate)
((IUpdate) action).update();
revisionMenu.add(action);
}
IAction lineNumberAction = getAction(ITextEditorActionConstants.LINENUMBERS_TOGGLE);
lineNumberAction.setChecked(fLineColumn != null && fLineColumn.isShowingLineNumbers());
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, lineNumberAction);
IAction preferencesAction = getAction(ITextEditorActionConstants.RULER_PREFERENCES);
menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
}
use of org.eclipse.jface.action.MenuManager in project linuxtools by eclipse.
the class PerfProfileView method hookContextMenu.
private void hookContextMenu() {
// $NON-NLS-1$
MenuManager menuMgr = new MenuManager("#PopupMenu");
menuMgr.setRemoveAllWhenShown(true);
menuMgr.addMenuListener(manager -> PerfProfileView.this.fillContextMenu(manager));
Menu menu = menuMgr.createContextMenu(viewer.getControl());
viewer.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, viewer);
}
Aggregations