diff options
author | Bernard Leach | 2011-07-02 20:13:15 -0400 |
---|---|---|
committer | Stefan Lay | 2011-07-05 12:02:56 -0400 |
commit | c0ac516062a4efee01cd432abb5d49d549542294 (patch) | |
tree | 46f2cc4119b03e2daa3ff164d1b7ed6d6484622c | |
parent | 3e9da5c05fc3333a9a51b2ff55327a3d1932a649 (diff) | |
download | egit-c0ac516062a4efee01cd432abb5d49d549542294.zip egit-c0ac516062a4efee01cd432abb5d49d549542294.tar.gz egit-c0ac516062a4efee01cd432abb5d49d549542294.tar.xz |
StagingView: add context menus to stage/unstage table view
Change-Id: I8ea3bb6bc9f28f3019196bdb6d2d46be55cacc2b
3 files changed, 114 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index a566634..91ec6d6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -3821,6 +3821,9 @@ public class UIText extends NLS { public static String StagingView_exceptionMessage; /** */ + public static String StagingView_UnstageItemMenuLabel; + + /** */ public static String SynchronizeWithMenu_custom; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java index cbd7100..ffc1e87 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java @@ -9,7 +9,10 @@ package org.eclipse.egit.ui.internal.staging; import static org.eclipse.egit.ui.internal.CommonUtils.runCommand; +import static org.eclipse.ui.ISources.ACTIVE_MENU_SELECTION_NAME; +import static org.eclipse.ui.menus.CommandContributionItem.STYLE_PUSH; +import java.io.File; import java.io.IOException; import java.text.MessageFormat; import java.util.Collection; @@ -19,6 +22,7 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; +import org.eclipse.core.expressions.IEvaluationContext; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IResourceChangeEvent; @@ -30,6 +34,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.IJobChangeEvent; import org.eclipse.core.runtime.jobs.Job; @@ -44,6 +49,7 @@ import org.eclipse.egit.ui.UIIcons; import org.eclipse.egit.ui.UIPreferences; import org.eclipse.egit.ui.UIText; import org.eclipse.egit.ui.UIUtils; +import org.eclipse.egit.ui.internal.EgitUiEditorUtils; import org.eclipse.egit.ui.internal.actions.ActionCommands; import org.eclipse.egit.ui.internal.actions.BooleanPrefAction; import org.eclipse.egit.ui.internal.commit.CommitHelper; @@ -57,6 +63,7 @@ import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridDataFactory; @@ -93,6 +100,7 @@ import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.treewalk.TreeWalk; import org.eclipse.jgit.treewalk.WorkingTreeIterator; import org.eclipse.jgit.treewalk.filter.PathFilterGroup; +import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.SashForm; import org.eclipse.swt.dnd.DND; @@ -103,8 +111,11 @@ import org.eclipse.swt.dnd.DropTargetEvent; import org.eclipse.swt.dnd.Transfer; import org.eclipse.swt.events.DisposeEvent; import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MenuDetectEvent; +import org.eclipse.swt.events.MenuDetectListener; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Text; import org.eclipse.team.core.Team; import org.eclipse.ui.IEditorInput; @@ -112,14 +123,20 @@ import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.ISelectionListener; import org.eclipse.ui.ISelectionService; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.forms.IFormColors; import org.eclipse.ui.forms.widgets.ExpandableComposite; import org.eclipse.ui.forms.widgets.Form; import org.eclipse.ui.forms.widgets.FormToolkit; import org.eclipse.ui.forms.widgets.Section; +import org.eclipse.ui.handlers.IHandlerService; +import org.eclipse.ui.menus.CommandContributionItem; +import org.eclipse.ui.menus.CommandContributionItemParameter; import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.progress.IWorkbenchSiteProgressService; @@ -475,6 +492,9 @@ public class StagingView extends ViewPart { updateSectionText(); updateToolbar(); + createPopupMenu(unstagedTableViewer); + createPopupMenu(stagedTableViewer); + final ICommitMessageComponentNotifications listener = new ICommitMessageComponentNotifications() { public void updateSignedOffToggleSelection(boolean selection) { @@ -620,6 +640,96 @@ public class StagingView extends ViewPart { } } + private void createPopupMenu(final TableViewer tableViewer) { + final MenuManager menuMgr = new MenuManager(); + Control control = tableViewer.getControl(); + control.setMenu(menuMgr.createContextMenu(control)); + control.addMenuDetectListener(new MenuDetectListener() { + public void menuDetected(MenuDetectEvent e) { + menuMgr.removeAll(); + + IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); + if (selection.isEmpty()) + return; + + menuMgr.add(new Action( + UIText.CommitFileDiffViewer_OpenWorkingTreeVersionInEditorMenuLabel) { + @Override + public void run() { + openSelectionInEditor(tableViewer.getSelection()); + } + }); + + StagingEntry stagingEntry = (StagingEntry) selection.getFirstElement(); + switch (stagingEntry.getState()) { + case ADDED: + case CHANGED: + case REMOVED: + menuMgr.add(new Action(UIText.StagingView_UnstageItemMenuLabel) { + @Override + public void run() { + unstage((IStructuredSelection) tableViewer.getSelection()); + } + }); + break; + + case CONFLICTING: + menuMgr.add(createItem(ActionCommands.MERGE_TOOL_ACTION, tableViewer)); + //$FALL-THROUGH$ + case MISSING: + case MODIFIED: + case PARTIALLY_MODIFIED: + case UNTRACKED: + default: + menuMgr.add(createItem(ActionCommands.DISCARD_CHANGES_ACTION, tableViewer)); // replace with index + menuMgr.add(createItem(ActionCommands.ADD_TO_INDEX, tableViewer)); + } + } + }); + + } + + @SuppressWarnings("unchecked") + private void openSelectionInEditor(ISelection s) { + if (s.isEmpty() || !(s instanceof IStructuredSelection)) + return; + final IStructuredSelection iss = (IStructuredSelection) s; + for (Iterator<StagingEntry> it = iss.iterator(); it.hasNext();) { + String relativePath = it.next().getPath(); + String path = new Path(currentRepository.getWorkTree() + .getAbsolutePath()).append(relativePath) + .toOSString(); + openFileInEditor(path); + } + } + + private void openFileInEditor(String filePath) { + IWorkbenchWindow window = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow(); + File file = new File(filePath); + if (!file.exists()) { + String message = NLS.bind(UIText.CommitFileDiffViewer_FileDoesNotExist, filePath); + Activator.showError(message, null); + } + IWorkbenchPage page = window.getActivePage(); + EgitUiEditorUtils.openEditor(file, page); + } + + private CommandContributionItem createItem(String itemAction, final TableViewer tableViewer) { + IWorkbench workbench = PlatformUI.getWorkbench(); + CommandContributionItemParameter itemParam = new CommandContributionItemParameter( + workbench, null, itemAction, STYLE_PUSH); + + IWorkbenchWindow activeWorkbenchWindow = workbench + .getActiveWorkbenchWindow(); + IHandlerService hsr = (IHandlerService) activeWorkbenchWindow + .getService(IHandlerService.class); + IEvaluationContext ctx = hsr.getCurrentState(); + ctx.addVariable(ACTIVE_MENU_SELECTION_NAME, tableViewer.getSelection()); + + return new CommandContributionItem(itemParam); + } + private void reactOnSelection(ISelection selection) { if (selection instanceof StructuredSelection) { StructuredSelection ssel = (StructuredSelection) selection; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 946e877..347cb45 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -1330,6 +1330,7 @@ StagingView_Refresh=Refresh StagingView_LinkSelection=Link with Editor and Selection StagingView_exceptionTitle=Refresh Error StagingView_exceptionMessage=Errors occurred while applying processing change notifications. +StagingView_UnstageItemMenuLabel=Remove from Git Index SynchronizeWithMenu_custom=&Custom... SynchronizeFetchJob_JobName=Fetching changes before synchronization launch |