diff options
Diffstat (limited to 'platform/editor-ui-api/src/com/intellij')
8 files changed, 124 insertions, 37 deletions
diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java index e6b2553085a8..aff6216c3dba 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettings.java @@ -21,9 +21,10 @@ import com.intellij.openapi.application.Application; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.PathManager; import com.intellij.openapi.components.*; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; +import com.intellij.openapi.util.SimpleModificationTracker; import com.intellij.openapi.util.SystemInfo; +import com.intellij.util.EventDispatcher; import com.intellij.util.PlatformUtilsCore; import com.intellij.util.SystemProperties; import com.intellij.util.ui.UIUtil; @@ -36,7 +37,6 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import javax.swing.*; -import javax.swing.event.EventListenerList; import java.awt.*; import java.io.File; import java.util.Map; @@ -50,7 +50,7 @@ import static com.intellij.util.ui.UIUtil.isValidFont; file = StoragePathMacros.APP_CONFIG + "/ui.lnf.xml" )} ) -public class UISettings implements PersistentStateComponent<UISettings>, ExportableApplicationComponent { +public class UISettings extends SimpleModificationTracker implements PersistentStateComponent<UISettings>, ExportableApplicationComponent { /** Not tabbed pane. */ public static final int TABS_NONE = 0; @@ -121,10 +121,9 @@ public class UISettings implements PersistentStateComponent<UISettings>, Exporta public boolean SHOW_TABS_TOOLTIPS = true; public boolean SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true; - private final EventListenerList myListenerList; + private final EventDispatcher<UISettingsListener> myDispatcher = EventDispatcher.create(UISettingsListener.class); public UISettings() { - myListenerList = new EventListenerList(); tweakPlatformDefaults(); setSystemFontFaceAndSize(); } @@ -142,31 +141,24 @@ public class UISettings implements PersistentStateComponent<UISettings>, Exporta * @deprecated use {@link UISettings#addUISettingsListener(com.intellij.ide.ui.UISettingsListener, Disposable disposable)} instead. */ public void addUISettingsListener(UISettingsListener listener) { - myListenerList.add(UISettingsListener.class, listener); + myDispatcher.addListener(listener); } public void addUISettingsListener(@NotNull final UISettingsListener listener, @NotNull Disposable parentDisposable) { - myListenerList.add(UISettingsListener.class, listener); - Disposer.register(parentDisposable, new Disposable() { - @Override - public void dispose() { - removeUISettingsListener(listener); - } - }); + myDispatcher.addListener(listener, parentDisposable); } /** * Notifies all registered listeners that UI settings has been changed. */ public void fireUISettingsChanged() { - UISettingsListener[] listeners = myListenerList.getListeners(UISettingsListener.class); - for (UISettingsListener listener : listeners) { - listener.uiSettingsChanged(this); - } + incModificationCount(); + myDispatcher.getMulticaster().uiSettingsChanged(this); + ApplicationManager.getApplication().getMessageBus().syncPublisher(UISettingsListener.TOPIC).uiSettingsChanged(this); } public void removeUISettingsListener(UISettingsListener listener) { - myListenerList.remove(UISettingsListener.class, listener); + myDispatcher.removeListener(listener); } private void setSystemFontFaceAndSize() { diff --git a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsListener.java b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsListener.java index 035fb700e481..1dcce2c076a3 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsListener.java +++ b/platform/editor-ui-api/src/com/intellij/ide/ui/UISettingsListener.java @@ -19,8 +19,12 @@ */ package com.intellij.ide.ui; +import com.intellij.util.messages.Topic; + import java.util.EventListener; public interface UISettingsListener extends EventListener{ + Topic<UISettingsListener> TOPIC = Topic.create("UI settings", UISettingsListener.class); + void uiSettingsChanged(UISettings source); } 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 { +} diff --git a/platform/editor-ui-api/src/com/intellij/ui/switcher/QuickActionProvider.java b/platform/editor-ui-api/src/com/intellij/ui/switcher/QuickActionProvider.java index 7de29e05f281..a41abe4bc1ca 100644 --- a/platform/editor-ui-api/src/com/intellij/ui/switcher/QuickActionProvider.java +++ b/platform/editor-ui-api/src/com/intellij/ui/switcher/QuickActionProvider.java @@ -18,7 +18,6 @@ package com.intellij.ui.switcher; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.DataKey; -import javax.swing.*; import java.util.List; public interface QuickActionProvider extends QuickAccessProvider { |