diff options
author | Vadim Dmitriev | 2014-08-15 20:35:07 +0000 |
---|---|---|
committer | Robin Stocker | 2014-08-26 13:13:06 +0000 |
commit | a8f27c54f8c49dce09321c4ae85a48fcdc5682e4 (patch) | |
tree | d44961f9f82d42fe6855a4eb9ea88a5c2293bfd2 | |
parent | a23ad64265176f47fb8a58e438462c15c721889a (diff) | |
download | egit-a8f27c54f8c49dce09321c4ae85a48fcdc5682e4.tar.gz egit-a8f27c54f8c49dce09321c4ae85a48fcdc5682e4.tar.xz egit-a8f27c54f8c49dce09321c4ae85a48fcdc5682e4.zip |
Interactive rebase view context menu for plan modification
Changeset table on the interactive rebase view now has context menu to
set rebasing plan for the selected rows.
Bug: 441891
Change-Id: I38448abbfd8d104b281aaf69cdf06702a41c3836
Signed-off-by: Vadim Dmitriev <dmgloss@mail.ru>
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/PlanContextMenuAction.java | 50 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/RebaseInteractiveView.java | 60 |
2 files changed, 108 insertions, 2 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/PlanContextMenuAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/PlanContextMenuAction.java new file mode 100644 index 0000000000..d8837110a7 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/rebase/PlanContextMenuAction.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2014 Vadim Dmitriev and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Vadim Dmitriev - initial implementation + *******************************************************************************/ +package org.eclipse.egit.ui.internal.rebase; + +import org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan; +import org.eclipse.egit.core.internal.rebase.RebaseInteractivePlan.PlanElement; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; + +class PlanContextMenuAction extends Action { + + private RebaseInteractivePlan.ElementAction action; + private TreeViewer planViewer; + private RebaseInteractiveStepActionToolBarProvider actionToolbarProvider; + + public PlanContextMenuAction(String text, ImageDescriptor image, + RebaseInteractivePlan.ElementAction action, TreeViewer planViewer, + RebaseInteractiveStepActionToolBarProvider actionToolbarProvider) { + super(text, image); + this.action = action; + this.planViewer = planViewer; + this.actionToolbarProvider = actionToolbarProvider; + } + + @Override + public void run() { + ISelection selection = planViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + IStructuredSelection structuredSelection = (IStructuredSelection) selection; + for (Object selectedRow : structuredSelection.toList()) { + if (selectedRow instanceof PlanElement) { + PlanElement planElement = (PlanElement) selectedRow; + planElement.setPlanElementAction(action); + } + } + actionToolbarProvider.mapActionItemsToSelection(selection); + } + } +}
\ No newline at end of file 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 eeb79b1944..c6c5436c48 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 @@ -11,7 +11,9 @@ package org.eclipse.egit.ui.internal.rebase; import java.io.IOException; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.resources.IResource; @@ -36,6 +38,9 @@ import org.eclipse.egit.ui.internal.commit.CommitEditor; import org.eclipse.egit.ui.internal.commit.RepositoryCommit; import org.eclipse.egit.ui.internal.repository.RepositoriesView; import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.layout.GridDataFactory; import org.eclipse.jface.layout.GridLayoutFactory; import org.eclipse.jface.resource.JFaceResources; @@ -73,6 +78,7 @@ import org.eclipse.swt.graphics.Font; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.layout.RowLayout; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.ToolBar; import org.eclipse.swt.widgets.ToolItem; import org.eclipse.swt.widgets.Tree; @@ -135,6 +141,8 @@ public class RebaseInteractiveView extends ViewPart implements /** these columns are dynamically resized to fit their contents */ private TreeViewerColumn[] dynamicColumns; + private List<PlanContextMenuAction> contextMenuItems; + /** * View for handling interactive rebase */ @@ -764,8 +772,56 @@ public class RebaseInteractiveView extends ViewPart implements } } - private void createPopupMenu(TreeViewer planViewer) { - // TODO create popup menu + private void createPopupMenu(final TreeViewer planViewer) { + createContextMenuItems(planViewer); + + MenuManager manager = new MenuManager(); + manager.addMenuListener(new IMenuListener() { + 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); + } + }); + + for (PlanContextMenuAction item : contextMenuItems) + manager.add(item); + + Menu menu = manager.createContextMenu(planViewer.getControl()); + planViewer.getControl().setMenu(menu); + } + + private void createContextMenuItems(final TreeViewer planViewer) { + contextMenuItems = new ArrayList<PlanContextMenuAction>(); + + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_PickText, + UIIcons.CHERRY_PICK, RebaseInteractivePlan.ElementAction.PICK, + planViewer, actionToolBarProvider)); + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_SkipText, + UIIcons.REBASE_SKIP, RebaseInteractivePlan.ElementAction.SKIP, + planViewer, actionToolBarProvider)); + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_EditText, + UIIcons.EDITCONFIG, RebaseInteractivePlan.ElementAction.EDIT, + planViewer, actionToolBarProvider)); + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_SquashText, + UIIcons.SQUASH, RebaseInteractivePlan.ElementAction.SQUASH, + planViewer, actionToolBarProvider)); + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_FixupText, + UIIcons.FIXUP, RebaseInteractivePlan.ElementAction.FIXUP, + planViewer, actionToolBarProvider)); + contextMenuItems.add(new PlanContextMenuAction( + UIText.RebaseInteractiveStepActionToolBarProvider_RewordText, + UIIcons.REWORD, RebaseInteractivePlan.ElementAction.REWORD, + planViewer, actionToolBarProvider)); } private static GitDateFormatter getNewDateFormatter() { |