diff options
author | Thomas Wolf | 2017-08-02 15:11:39 +0000 |
---|---|---|
committer | Thomas Wolf | 2017-10-16 21:10:51 +0000 |
commit | 13b5efff3948958059e5f4163855b43bb3aeefb8 (patch) | |
tree | dbd1e4126b5b5df8f48c4e10eb98e2ffec77fe21 | |
parent | a0e6c966acaa71713e0557a7a172c75b2197c9f6 (diff) | |
download | egit-13b5efff3948958059e5f4163855b43bb3aeefb8.tar.gz egit-13b5efff3948958059e5f4163855b43bb3aeefb8.tar.xz egit-13b5efff3948958059e5f4163855b43bb3aeefb8.zip |
Extensible context menu in the rebase interactive view
A double click on a plan item already opened the commit in the commit
viewer. Now add the corresponding action to the view's context menu
so that this functionality is easier to discover.
This also is a nice example of how the new IRepositoryCommit interface
simplifies command management: we just define a new menu contribution
for that context menu, *re-using* the existing handler from the
history view. The new contribution uses its own label since the
accelerator is changed.
Adapt the visibleWhen expressions of the rebase sub-menu items for
the "Team" sub-menu to avoid they appear in the rebase interactive
view.
Moving the existing handler from the "internal.history" package to a
more general place is for now left for a future clean-up commit, as
are more handler unifications and eventually unifying all these
"AbstractXYZHandler" classes that all offer operations to get a
repository and commits from a selection, but that all do it in
slightly different and sometimes even view-specific ways.
Bug: 498012
Change-Id: I9ae5e709e24bfe3cc938f575df9685d3cfc884bc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.egit.ui/plugin.properties | 4 | ||||
-rw-r--r-- | org.eclipse.egit.ui/plugin.xml | 58 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java | 40 |
3 files changed, 78 insertions, 24 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties index 8dc5f9ffaf..bcced27c77 100644 --- a/org.eclipse.egit.ui/plugin.properties +++ b/org.eclipse.egit.ui/plugin.properties @@ -454,4 +454,6 @@ HistoryResetQuickDiffHeadParent.label=Reset Baseline to &Previous Revision (HEAD HistoryResetSoft.label=&Soft (HEAD Only) HistoryRevert.label=&Revert Commit HistoryShowBlame.label=&Show Revision Information -HistoryShowVersions.label=&Open
\ No newline at end of file +HistoryShowVersions.label=&Open + +RebaseInteractiveOpenInCommitViewer.label=&Open in Commit Viewer diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index a200bf1ea9..cab0ca8a0d 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -3492,6 +3492,16 @@ </command> </menuContribution> <menuContribution + allPopups="false" + locationURI="popup:org.eclipse.egit.ui.InteractiveRebaseView?after=additions"> + <command + commandId="org.eclipse.egit.ui.history.OpenInCommitViewerCommand" + label="%RebaseInteractiveOpenInCommitViewer.label" + style="push"> + <visibleWhen checkEnabled="true" /> + </command> + </menuContribution> + <menuContribution locationURI="popup:org.eclipse.egit.ui.internal.reflogview.popup"> <command commandId="org.eclipse.egit.ui.internal.reflog.CheckoutCommand" @@ -5269,17 +5279,59 @@ <command commandId="org.eclipse.egit.ui.AbortRebase" style="push"> - <visibleWhen checkEnabled="true" /> + <visibleWhen> + <or> + <with variable="activeMenuSelection"> + <count value="1" /> + <iterate> + <instanceof value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode" /> + <test property="GitRepository.canAbortRebase" /> + </iterate> + </with> + <test + property="GitSelection.projectsSingleRepository" + args="canAbortRebase"> + </test> + </or> + </visibleWhen> </command> <command commandId="org.eclipse.egit.ui.ContinueRebase" style="push"> - <visibleWhen checkEnabled="true" /> + <visibleWhen> + <or> + <with variable="activeMenuSelection"> + <count value="1" /> + <iterate> + <instanceof value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode" /> + <test property="GitRepository.canContinueRebase" /> + </iterate> + </with> + <test + property="GitSelection.projectsSingleRepository" + args="canContinueRebase"> + </test> + </or> + </visibleWhen> </command> <command commandId="org.eclipse.egit.ui.SkipRebase" style="push"> - <visibleWhen checkEnabled="true" /> + <visibleWhen> + <or> + <with variable="activeMenuSelection"> + <count value="1" /> + <iterate> + <instanceof value="org.eclipse.egit.ui.internal.repository.tree.RepositoryNode" /> + <test property="GitRepository.canAbortRebase" /> + </iterate> + </with> + <test + property="GitSelection.projectsSingleRepository" + args="canAbortRebase"> + </test> + </or> + </visibleWhen> </command> </menu> <command diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java index cb14c20966..bf5318eca5 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java @@ -50,10 +50,9 @@ import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; import org.eclipse.egit.ui.internal.selection.RepositorySelectionProvider; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuListener; -import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.action.Separator; import org.eclipse.jface.bindings.keys.SWTKeySupport; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; @@ -99,6 +98,7 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.ToolBar; @@ -112,6 +112,7 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.ISelectionService; import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchActionConstants; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartSite; import org.eclipse.ui.PartInitException; @@ -406,7 +407,6 @@ public class RebaseInteractiveView extends ViewPart implements getSite().setSelectionProvider(new RepositorySelectionProvider( planTreeViewer, () -> currentRepository)); - } private void createCommandToolBar(Form theForm, FormToolkit toolkit) { @@ -1018,25 +1018,25 @@ public class RebaseInteractiveView extends ViewPart implements createContextMenuItems(planViewer); MenuManager manager = new MenuManager(); - manager.addMenuListener(new IMenuListener() { - @Override - public void menuAboutToShow(IMenuManager menuManager) { - boolean selectionNotEmpty = !planViewer.getSelection() - .isEmpty(); - boolean rebaseNotStarted = !currentPlan - .hasRebaseBeenStartedYet(); - boolean menuEnabled = selectionNotEmpty && rebaseNotStarted; - for (PlanContextMenuAction item : contextMenuItems) - item.setEnabled(menuEnabled); + Control c = planViewer.getControl(); + manager.setRemoveAllWhenShown(true); + manager.addMenuListener(m -> { + c.setFocus(); + boolean selectionNotEmpty = !planViewer.getSelection().isEmpty(); + boolean rebaseNotStarted = currentPlan != null + && !currentPlan.hasRebaseBeenStartedYet(); + boolean menuEnabled = selectionNotEmpty && rebaseNotStarted; + if (menuEnabled) { + for (PlanContextMenuAction item : contextMenuItems) { + m.add(item); + } } + m.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); }); - - for (PlanContextMenuAction item : contextMenuItems) - manager.add(item); - - Menu menu = manager.createContextMenu(planViewer.getControl()); - planViewer.getControl().setMenu(menu); - planViewer.getControl().addKeyListener(new ContextMenuKeyListener()); + Menu menu = manager.createContextMenu(c); + c.setMenu(menu); + c.addKeyListener(new ContextMenuKeyListener()); + getSite().registerContextMenu(manager, planTreeViewer); } private void createContextMenuItems(final TreeViewer planViewer) { |