summaryrefslogtreecommitdiff
path: root/platform/editor-ui-api/src/com/intellij/openapi
diff options
context:
space:
mode:
Diffstat (limited to 'platform/editor-ui-api/src/com/intellij/openapi')
-rw-r--r--platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java6
-rw-r--r--platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java37
-rw-r--r--platform/editor-ui-api/src/com/intellij/openapi/actionSystem/CommonDataKeys.java12
-rw-r--r--platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataContextWrapper.java51
-rw-r--r--platform/editor-ui-api/src/com/intellij/openapi/actionSystem/RightAlignedToolbarAction.java22
5 files changed, 110 insertions, 18 deletions
diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java
index 1d1540910539..42da54a61d72 100644
--- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java
+++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnAction.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -297,6 +297,10 @@ public abstract class AnAction implements PossiblyDumbAware {
return myIsDefaultIcon;
}
+ /**
+ * Enables automatic detection of injected fragments in editor. Values in DataContext, passed to the action, like EDITOR, PSI_FILE
+ * will refer to an injected fragment, if caret is currently positioned on it.
+ */
public void setInjectedContext(boolean worksInInjected) {
myWorksInInjected = worksInInjected;
}
diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java
index 5202aa291224..94dcccb71778 100644
--- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java
+++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/AnActionEvent.java
@@ -37,7 +37,7 @@ import java.util.Map;
public class AnActionEvent implements PlaceProvider<String> {
private final InputEvent myInputEvent;
- private final ActionManager myActionManager;
+ @NotNull private final ActionManager myActionManager;
@NotNull private final DataContext myDataContext;
@NotNull private final String myPlace;
@NotNull private final Presentation myPresentation;
@@ -49,12 +49,14 @@ public class AnActionEvent implements PlaceProvider<String> {
/**
* @throws IllegalArgumentException if <code>dataContext</code> is <code>null</code> or
* <code>place</code> is <code>null</code> or <code>presentation</code> is <code>null</code>
+ *
+ * @see ActionManager#getInstance()
*/
public AnActionEvent(InputEvent inputEvent,
@NotNull DataContext dataContext,
@NotNull @NonNls String place,
@NotNull Presentation presentation,
- ActionManager actionManager,
+ @NotNull ActionManager actionManager,
@JdkConstants.InputEventMask int modifiers) {
// TODO[vova,anton] make this constructor package local. No one is allowed to create AnActionEvents
myInputEvent = inputEvent;
@@ -69,7 +71,7 @@ public class AnActionEvent implements PlaceProvider<String> {
public static AnActionEvent createFromInputEvent(@NotNull AnAction action, InputEvent event, @NotNull String place) {
DataContext context = event == null ? DataManager.getInstance().getDataContext() : DataManager.getInstance().getDataContext(event.getComponent());
int modifiers = event == null ? 0 : event.getModifiers();
- return new AnActionEvent(
+ AnActionEvent anActionEvent = new AnActionEvent(
event,
context,
place,
@@ -77,6 +79,8 @@ public class AnActionEvent implements PlaceProvider<String> {
ActionManager.getInstance(),
modifiers
);
+ anActionEvent.setInjectedContext(action.isInInjectedContext());
+ return anActionEvent;
}
/**
@@ -113,6 +117,18 @@ public class AnActionEvent implements PlaceProvider<String> {
return StringUtil.trimStart(dataId, ourInjectedPrefix);
}
+ public static DataContext getInjectedDataContext(final DataContext context) {
+ return new DataContextWrapper(context) {
+ @Nullable
+ @Override
+ public Object getData(@NonNls String dataId) {
+ Object injected = super.getData(injectedId(dataId));
+ if (injected != null) return injected;
+ return super.getData(dataId);
+ }
+ };
+ }
+
/**
* Returns the context which allows to retrieve information about the state of IDEA related to
* the action invocation (active editor, selection and so on).
@@ -121,18 +137,7 @@ public class AnActionEvent implements PlaceProvider<String> {
*/
@NotNull
public DataContext getDataContext() {
- if (!myWorksInInjected) {
- return myDataContext;
- }
- return new DataContext() {
- @Override
- @Nullable
- public Object getData(@NonNls String dataId) {
- Object injected = myDataContext.getData(injectedId(dataId));
- if (injected != null) return injected;
- return myDataContext.getData(dataId);
- }
- };
+ return myWorksInInjected ? getInjectedDataContext(myDataContext) : myDataContext;
}
@Nullable
@@ -203,9 +208,11 @@ public class AnActionEvent implements PlaceProvider<String> {
return myModifiers;
}
+ @NotNull
public ActionManager getActionManager() {
return myActionManager;
}
+
public void setInjectedContext(boolean worksInInjected) {
myWorksInInjected = worksInInjected;
}
diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/CommonDataKeys.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/CommonDataKeys.java
index cb7449a2c914..edde5ca34f8c 100644
--- a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/CommonDataKeys.java
+++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/CommonDataKeys.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.actionSystem;
+import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
@@ -25,7 +26,14 @@ import com.intellij.psi.PsiFile;
public class CommonDataKeys {
public static final DataKey<Project> PROJECT = DataKey.create("project");
public static final DataKey<Editor> EDITOR = DataKey.create("editor");
-
+ /**
+ * This key can be used to obtain reference to host editor instance, in case {@link #EDITOR} key is referring to an injected editor.
+ */
+ public static final DataKey<Editor> HOST_EDITOR = DataKey.create("host.editor");
+ /**
+ * A key to retrieve caret instance (in host or injected editor, depending on context).
+ */
+ public static final DataKey<Caret> CARET = DataKey.create("caret");
/**
* Returns com.intellij.openapi.editor.Editor even if focus currently is in find bar
*/
diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataContextWrapper.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataContextWrapper.java
new file mode 100644
index 000000000000..091153d67cc5
--- /dev/null
+++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/DataContextWrapper.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.actionSystem;
+
+import com.intellij.openapi.util.Key;
+import com.intellij.openapi.util.UserDataHolder;
+import com.intellij.openapi.util.UserDataHolderBase;
+import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+// We implement UserDataHolder to support DataManager.saveInDataContext/loadFromDataContext methods
+public class DataContextWrapper implements DataContext, UserDataHolder {
+ private final DataContext myDelegate;
+ private final UserDataHolder myDataHolder;
+
+ public DataContextWrapper(@NotNull DataContext delegate) {
+ myDelegate = delegate;
+ myDataHolder = delegate instanceof UserDataHolder ? (UserDataHolder) delegate : new UserDataHolderBase();
+ }
+
+ @Nullable
+ @Override
+ public Object getData(@NonNls String dataId) {
+ return myDelegate.getData(dataId);
+ }
+
+ @Nullable
+ @Override
+ public <T> T getUserData(@NotNull Key<T> key) {
+ return myDataHolder.getUserData(key);
+ }
+
+ @Override
+ public <T> void putUserData(@NotNull Key<T> key, @Nullable T value) {
+ myDataHolder.putUserData(key, value);
+ }
+}
diff --git a/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/RightAlignedToolbarAction.java b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/RightAlignedToolbarAction.java
new file mode 100644
index 000000000000..d977bfa1e1f9
--- /dev/null
+++ b/platform/editor-ui-api/src/com/intellij/openapi/actionSystem/RightAlignedToolbarAction.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2000-2014 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.openapi.actionSystem;
+
+/**
+ * @author Konstantin Bulenkov
+ */
+public interface RightAlignedToolbarAction {
+}