Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDani Megert2012-09-10 22:06:59 +0000
committerMatthias Sohn2012-09-10 22:06:59 +0000
commitf6d0474bba2c3f8c1bd0a92ea77d43abc40c54a6 (patch)
treeaff32a9f6d31dd68936d5ac9689a17d41a54b98a
parent4a87652bde4f88327288a9cc02f3f4951fdf3aab (diff)
downloadegit-f6d0474bba2c3f8c1bd0a92ea77d43abc40c54a6.tar.gz
egit-f6d0474bba2c3f8c1bd0a92ea77d43abc40c54a6.tar.xz
egit-f6d0474bba2c3f8c1bd0a92ea77d43abc40c54a6.zip
Use the editor input from the given context
Bug: 387633 Change-Id: Ic43c820697c103ddbfd65494dddb7706c6210386 Signed-off-by: Dani Megert <Daniel_Megert@ch.ibm.com> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractRebaseCommandHandler.java19
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractSharedCommandHandler.java36
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java4
3 files changed, 44 insertions, 15 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractRebaseCommandHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractRebaseCommandHandler.java
index a47db1a7d1..4e44edcbb3 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractRebaseCommandHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractRebaseCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
+ * Copyright (c) 2010, 2012 SAP AG 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
@@ -29,6 +29,7 @@ import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ISources;
import org.eclipse.ui.PlatformUI;
@@ -111,4 +112,20 @@ public abstract class AbstractRebaseCommandHandler extends AbstractSharedCommand
selection = ctx.getVariable(ISources.ACTIVE_CURRENT_SELECTION_NAME);
return selection;
}
+
+ /**
+ * Extracts the editor input from the given context.
+ *
+ * @param ctx the context
+ * @return the editor input for the given context or <code>null</code> if not available
+ * @since 2.1
+ */
+ protected IEditorInput getActiveEditorInput(IEvaluationContext ctx) {
+ Object editorInput = ctx.getVariable(ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (editorInput instanceof IEditorInput)
+ return (IEditorInput) editorInput;
+
+ return null;
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractSharedCommandHandler.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractSharedCommandHandler.java
index 5883e2eefe..cb61d867d7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractSharedCommandHandler.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/AbstractSharedCommandHandler.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
+ * Copyright (c) 2010, 2012 SAP AG 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
@@ -26,8 +26,7 @@ import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.ISources;
import org.eclipse.ui.handlers.HandlerUtil;
/**
@@ -35,7 +34,6 @@ import org.eclipse.ui.handlers.HandlerUtil;
*/
public abstract class AbstractSharedCommandHandler extends AbstractHandler {
- private static final IWorkbench WORKBENCH = PlatformUI.getWorkbench();
/**
* @param event
@@ -45,17 +43,19 @@ public abstract class AbstractSharedCommandHandler extends AbstractHandler {
*/
public static Repository getRepository(ExecutionEvent event) {
ISelection selection = HandlerUtil.getCurrentSelection(event);
- return getRepository(selection);
+ IEditorInput editorInput = getActiveEditorInput(event);
+ return getRepository(selection, editorInput);
}
/**
* Get repository from selection
*
- * @param selection
+ * @param selection the selection or <code>null</code> if not available
+ * @param editorInput the editor input to be used in case of a text selection or <code>null</code> if not available
* @return a {@link Repository} if all elements in the current selection map
* to the same {@link Repository}, otherwise null
*/
- protected static Repository getRepository(ISelection selection) {
+ protected static Repository getRepository(ISelection selection, IEditorInput editorInput) {
if (selection == null || selection.isEmpty())
return null;
if (selection instanceof IStructuredSelection) {
@@ -91,12 +91,9 @@ public abstract class AbstractSharedCommandHandler extends AbstractHandler {
}
return result;
}
- if (selection instanceof TextSelection) {
- IEditorInput activeEditor = WORKBENCH.getActiveWorkbenchWindow()
- .getActivePage().getActiveEditor().getEditorInput();
- IResource resource = (IResource) activeEditor
+ if (selection instanceof TextSelection && editorInput != null) {
+ IResource resource = (IResource) editorInput
.getAdapter(IResource.class);
-
if (resource != null) {
RepositoryMapping mapping = RepositoryMapping
.getMapping(resource);
@@ -133,4 +130,19 @@ public abstract class AbstractSharedCommandHandler extends AbstractHandler {
return HandlerUtil.getActiveShell(event);
}
+ /**
+ * Return the input of the active editor.
+ * <strong>Note:</strong> Copied from org.eclipse.ui.handlers.HandlerUtil.getActiveEditorInput(ExecutionEvent) for compatibility reasons.
+ *
+ * @param event
+ * The execution event that contains the application context
+ * @return the input of the active editor, or <code>null</code>.
+ */
+ private static IEditorInput getActiveEditorInput(ExecutionEvent event) {
+ Object o = HandlerUtil.getVariable(event, ISources.ACTIVE_EDITOR_INPUT_NAME);
+ if (o instanceof IEditorInput)
+ return (IEditorInput) o;
+ return null;
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java
index d7a5d39306..148636e380 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/shared/RebaseCurrentRefCommand.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
+ * Copyright (c) 2010, 2012 SAP AG 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
@@ -91,7 +91,7 @@ public class RebaseCurrentRefCommand extends AbstractRebaseCommandHandler {
IEvaluationContext ctx = (IEvaluationContext) evaluationContext;
Object selection = getSelection(ctx);
if (selection instanceof ISelection) {
- Repository repo = getRepository((ISelection) selection);
+ Repository repo = getRepository((ISelection) selection, getActiveEditorInput(ctx));
if (repo != null) {
boolean isSafe = repo.getRepositoryState() == RepositoryState.SAFE;
setBaseEnabled(isSafe && hasHead(repo));

Back to the top