Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java9
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/OpenWorkingFileAction.java149
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties4
4 files changed, 189 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 36935a571c..03c90d190a 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
@@ -3050,6 +3050,15 @@ public class UIText extends NLS {
public static String NonDeletedFilesTree_ResourcePathsButton;
/** */
+ public static String OpenWorkingFileAction_text;
+
+ /** */
+ public static String OpenWorkingFileAction_tooltip;
+
+ /** */
+ public static String OpenWorkingFileAction_openWorkingFileShellTitle;
+
+ /** */
public static String RemoteConnectionPreferencePage_TimeoutLabel;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java
index a939d35e74..5e038aac41 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/GitActionContributor.java
@@ -22,13 +22,18 @@ import static org.eclipse.ui.menus.CommandContributionItem.STYLE_PUSH;
import org.eclipse.core.expressions.IEvaluationContext;
import org.eclipse.egit.ui.internal.synchronize.action.ExpandAllModelAction;
+import org.eclipse.egit.ui.internal.synchronize.action.OpenWorkingFileAction;
import org.eclipse.egit.ui.internal.synchronize.model.GitModelObject;
import org.eclipse.egit.ui.internal.synchronize.model.SupportedContextActionsHelper;
+import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration;
+import org.eclipse.team.ui.synchronize.ISynchronizePageSite;
+import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant;
import org.eclipse.team.ui.synchronize.ModelSynchronizeParticipantActionGroup;
import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.handlers.IHandlerService;
@@ -39,6 +44,8 @@ class GitActionContributor extends ModelSynchronizeParticipantActionGroup {
private static final String GIT_ACTIONS = "gitActions"; //$NON-NLS-1$
+ private OpenWorkingFileAction openWorkingFileAction;
+
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = (IStructuredSelection) getContext()
.getSelection();
@@ -53,6 +60,18 @@ class GitActionContributor extends ModelSynchronizeParticipantActionGroup {
menu.appendToGroup(GIT_ACTIONS, createItem(ADD_TO_INDEX));
menu.appendToGroup(GIT_ACTIONS, createItem(IGNORE_ACTION));
}
+
+ IContributionItem fileGroup = findGroup(menu,
+ ISynchronizePageConfiguration.FILE_GROUP);
+
+ if (fileGroup != null) {
+ ModelSynchronizeParticipant msp =
+ ((ModelSynchronizeParticipant) getConfiguration()
+ .getParticipant());
+
+ if (msp.hasCompareInputFor(element))
+ menu.appendToGroup(fileGroup.getId(), openWorkingFileAction);
+ }
}
}
@@ -93,6 +112,14 @@ class GitActionContributor extends ModelSynchronizeParticipantActionGroup {
GitActionContributor_ExpandAll, configuration);
expandAllAction.setImageDescriptor(EXPAND_ALL);
appendToGroup(P_TOOLBAR_MENU, NAVIGATE_GROUP, expandAllAction);
+
+ ISynchronizePageSite site = configuration.getSite();
+ IWorkbenchSite ws = site.getWorkbenchSite();
+ openWorkingFileAction = new OpenWorkingFileAction(ws.getWorkbenchWindow()
+ .getActivePage());
+
+ site.getSelectionProvider().addSelectionChangedListener(
+ openWorkingFileAction);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/OpenWorkingFileAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/OpenWorkingFileAction.java
new file mode 100644
index 0000000000..1203a80fb1
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/synchronize/action/OpenWorkingFileAction.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * Copyright (C) 2011, Greg Amerson <gregory.amerson@liferay.com>
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.synchronize.action;
+
+import java.io.File;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.egit.ui.UIText;
+import org.eclipse.egit.ui.internal.synchronize.model.GitModelObject;
+import org.eclipse.jface.dialogs.ErrorDialog;
+import org.eclipse.jface.util.OpenStrategy;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorDescriptor;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.actions.SelectionListenerAction;
+import org.eclipse.ui.ide.IDE;
+
+/**
+ * Action for opening an editor on the currently selected git working file.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @noextend This class is not intended to be subclassed by clients.
+ */
+public class OpenWorkingFileAction extends SelectionListenerAction {
+
+ /**
+ * The workbench page to open the editor in.
+ */
+ private IWorkbenchPage workbenchPage;
+
+ /**
+ * Creates a new action that will open editors on the selected working file
+ * resources.
+ *
+ * @param page
+ * the workbench page in which to open the editor
+ */
+ public OpenWorkingFileAction(IWorkbenchPage page) {
+ super(null);
+ setText(UIText.OpenWorkingFileAction_text);
+ setToolTipText(UIText.OpenWorkingFileAction_tooltip);
+ this.workbenchPage = page;
+ }
+
+ /**
+ * Return the workbench page to open the editor in.
+ *
+ * @return the workbench page to open the editor in
+ */
+ protected IWorkbenchPage getWorkbenchPage() {
+ return workbenchPage;
+ }
+
+ /**
+ * Opens a editor on the given file resource.
+ *
+ * @param file
+ * the workspace file
+ */
+ protected void openWorkspaceFile(IFile file) {
+ try {
+ boolean activate = OpenStrategy.activateOnOpen();
+ IDE.openEditor(getWorkbenchPage(), file, activate);
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getWorkbenchPage().getWorkbenchWindow()
+ .getShell(),
+ UIText.OpenWorkingFileAction_openWorkingFileShellTitle, e
+ .getMessage(), e.getStatus());
+ }
+ }
+
+ /**
+ * Opens external file, the editor that is used is based on best guess from
+ * file name.
+ *
+ * @param file
+ * the external file
+ */
+ protected void openExternalFile(File file) {
+ try {
+ boolean activate = OpenStrategy.activateOnOpen();
+ IEditorDescriptor desc = IDE.getEditorDescriptor(file.getName());
+ IDE.openEditor(getWorkbenchPage(), file.toURI(), desc.getId(),
+ activate);
+ } catch (PartInitException e) {
+ ErrorDialog.openError(getWorkbenchPage().getWorkbenchWindow()
+ .getShell(),
+ UIText.OpenWorkingFileAction_openWorkingFileShellTitle, e
+ .getMessage(), e.getStatus());
+ }
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IAction.
+ */
+ public void run() {
+ IStructuredSelection selection = getStructuredSelection();
+
+ IResource resource = getExistingResource(selection);
+
+ if (resource instanceof IFile)
+ openWorkspaceFile((IFile) resource);
+ else {
+ Object element = selection.getFirstElement();
+
+ if (element instanceof GitModelObject) {
+ IPath location = ((GitModelObject) element).getLocation();
+
+ if (location != null && location.toFile().exists())
+ openExternalFile(location.toFile());
+ }
+ }
+ }
+
+ private IResource getExistingResource(IStructuredSelection selection) {
+ Object element = selection.getFirstElement();
+
+ if (element instanceof IAdaptable) {
+ IResource resource = (IResource) ((IAdaptable) element)
+ .getAdapter(IResource.class);
+
+ if (resource != null && resource.exists())
+ return resource;
+ }
+
+ return null;
+ }
+
+ /**
+ * Enable the action only if the selection contains IFiles
+ */
+ protected boolean updateSelection(IStructuredSelection selection) {
+ return super.updateSelection(selection)
+ && selectionIsOfType(IResource.FILE);
+ }
+}
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 7fc489b8fb..34ee470cd8 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
@@ -1188,3 +1188,7 @@ SimpleFetchRefSpecWizard_WizardTitle=Adding a RefSpec for push
SimplePushActionHandler_NothingToPushDialogMessage=Can not push anything: the currently checked-out branch is based on a local branch
SimplePushActionHandler_NothingToPushDialogTitle=Nothing to push
GitActionContributor_ExpandAll=Expand All
+
+OpenWorkingFileAction_text=&Open
+OpenWorkingFileAction_toolTip=Open Working File
+OpenWorkingFileAction_openWorkingFileShellTitle=Problems Opening Working File

Back to the top