mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 15:09:39 +07:00
IDEA-337454 bulk fireShortcutChanged
GitOrigin-RevId: d8f89e559d9059bcf9b7da47e322e9054af0bc5b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
6adf79415d
commit
78c093ab1b
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.externalSystem.service.project.manage;
|
||||
|
||||
import com.intellij.openapi.Disposable;
|
||||
@@ -14,6 +14,7 @@ import com.intellij.openapi.keymap.KeymapUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.containers.DisposableWrapperList;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -41,7 +42,7 @@ public class ExternalSystemShortcutsManager implements Disposable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shortcutChanged(@NotNull Keymap keymap, @NotNull String actionId) {
|
||||
public void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
fireShortcutsUpdated();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -28,11 +28,13 @@ import com.intellij.util.FontUtil;
|
||||
import com.intellij.util.JavaCoroutines;
|
||||
import kotlin.Unit;
|
||||
import kotlin.coroutines.Continuation;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.intellij.openapi.keymap.KeymapUtil.getActiveKeymapShortcuts;
|
||||
@@ -129,8 +131,8 @@ public class RunAnythingAction extends AnAction implements CustomComponentAction
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shortcutChanged(@NotNull Keymap keymap, @NotNull String actionId) {
|
||||
if (RUN_ANYTHING_ACTION_ID.equals(actionId)) {
|
||||
public void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
if (actionIds.contains(RUN_ANYTHING_ACTION_ID)) {
|
||||
updateShortcut(KeymapManager.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.openapi.keymap;
|
||||
|
||||
import com.intellij.util.messages.Topic;
|
||||
@@ -6,6 +6,8 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface KeymapManagerListener {
|
||||
@Topic.AppLevel
|
||||
Topic<KeymapManagerListener> TOPIC = new Topic<>(KeymapManagerListener.class, Topic.BroadcastDirection.NONE);
|
||||
@@ -19,10 +21,26 @@ public interface KeymapManagerListener {
|
||||
default void activeKeymapChanged(@Nullable Keymap keymap) {
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link #shortcutsChanged(Keymap, Collection, boolean)}
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@Deprecated
|
||||
default void shortcutChanged(@NotNull Keymap keymap, @NonNls @NotNull String actionId) {
|
||||
}
|
||||
|
||||
default void shortcutChanged(@NotNull Keymap keymap, @NonNls @NotNull String actionId, boolean fromSettings) {
|
||||
/**
|
||||
* @deprecated Use {@link #shortcutsChanged(Keymap, Collection, boolean)}
|
||||
*/
|
||||
@SuppressWarnings("DeprecatedIsStillUsed")
|
||||
@Deprecated
|
||||
default void shortcutChanged(@NotNull Keymap keymap, @NonNls @NotNull String actionId, @SuppressWarnings("unused") boolean fromSettings) {
|
||||
shortcutChanged(keymap, actionId);
|
||||
}
|
||||
|
||||
default void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
for (String actionId : actionIds) {
|
||||
shortcutChanged(keymap, actionId, fromSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,12 +12,14 @@ import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.NlsSafe;
|
||||
import com.intellij.util.ui.update.Activatable;
|
||||
import com.intellij.util.ui.update.UiNotifyConnector;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.lang.ref.Reference;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Collection;
|
||||
|
||||
public final class ShadowAction {
|
||||
private final AnAction myAction;
|
||||
@@ -86,8 +88,8 @@ public final class ShadowAction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shortcutChanged(@NotNull Keymap keymap, @NotNull String actionId) {
|
||||
if (myActionId == null || actionId.equals(myActionId)) {
|
||||
public void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
if (myActionId == null || actionIds.contains(myActionId)) {
|
||||
rebound();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.ui.text
|
||||
|
||||
import com.intellij.ide.ui.text.paragraph.TextParagraph
|
||||
@@ -10,6 +10,7 @@ import com.intellij.openapi.keymap.Keymap
|
||||
import com.intellij.openapi.keymap.KeymapManagerListener
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.annotations.ApiStatus
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.Cursor
|
||||
import java.awt.Dimension
|
||||
import java.awt.Point
|
||||
@@ -71,7 +72,7 @@ open class StyledTextPane : JTextPane(), Disposable {
|
||||
redraw()
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String) {
|
||||
override fun shortcutsChanged(keymap: Keymap, actionIds: @NonNls MutableCollection<String>, fromSettings: Boolean) {
|
||||
redraw()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.internal.inspector
|
||||
|
||||
import com.intellij.ide.IdeEventQueue
|
||||
@@ -15,6 +15,7 @@ import com.intellij.openapi.keymap.impl.ui.MouseShortcutPanel
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.wm.IdeFocusManager
|
||||
import com.intellij.util.ui.UIUtil
|
||||
import org.jetbrains.annotations.NonNls
|
||||
import java.awt.AWTEvent
|
||||
import java.awt.Component
|
||||
import java.awt.event.MouseEvent
|
||||
@@ -31,8 +32,8 @@ abstract class UiMouseAction(val uiActionId: String) : DumbAwareAction() {
|
||||
updateMouseShortcuts()
|
||||
}
|
||||
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String) {
|
||||
if (uiActionId == actionId) {
|
||||
override fun shortcutsChanged(keymap: Keymap, actionIds: @NonNls MutableCollection<String>, fromSettings: Boolean) {
|
||||
if (actionIds.contains(uiActionId)) {
|
||||
updateMouseShortcuts()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,20 @@ import com.intellij.openapi.diagnostic.logger
|
||||
import com.intellij.openapi.keymap.Keymap
|
||||
import com.intellij.openapi.keymap.KeymapManagerListener
|
||||
import org.jetbrains.annotations.ApiStatus.Internal
|
||||
import org.jetbrains.annotations.NonNls
|
||||
|
||||
private val LOG = logger<KeymapFlagsStorage>()
|
||||
|
||||
private class KeymapFlagsStorageListener : KeymapManagerListener {
|
||||
override fun shortcutChanged(keymap: Keymap, actionId: String, fromSettings: Boolean) {
|
||||
service<KeymapFlagsStorage>().removeOutdatedFlags(keymap, actionId, fromSettings)
|
||||
override fun shortcutsChanged(keymap: Keymap, actionIds: @NonNls MutableCollection<String>, fromSettings: Boolean) {
|
||||
if (!fromSettings) {
|
||||
return
|
||||
}
|
||||
|
||||
val storage = service<KeymapFlagsStorage>()
|
||||
for (actionId in actionIds) {
|
||||
storage.removeOutdatedFlags(keymap, actionId, fromSettings)
|
||||
}
|
||||
}
|
||||
|
||||
override fun keymapRemoved(keymap: Keymap) {
|
||||
@@ -63,9 +71,7 @@ internal class KeymapFlagsStorage : SimplePersistentStateComponent<KeymapFlagsSt
|
||||
}
|
||||
|
||||
internal fun removeOutdatedFlags(keymap: Keymap, actionId: String, fromSettings: Boolean) {
|
||||
if (!fromSettings) {
|
||||
return
|
||||
}
|
||||
assert(fromSettings)
|
||||
|
||||
val currentShortcuts = keymap.getShortcuts(actionId).map { it.toString() }
|
||||
|
||||
|
||||
@@ -217,6 +217,16 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
fromSettings: Boolean,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
actionBinding: (String) -> String?) {
|
||||
doAddShortcut(actionBinding = actionBinding, actionId = actionId, actionIdToShortcuts = actionIdToShortcuts, shortcut = shortcut)
|
||||
|
||||
cleanShortcutsCache()
|
||||
fireShortcutChanged(actionIds = java.util.List.of(actionId), fromSettings = fromSettings)
|
||||
}
|
||||
|
||||
private fun doAddShortcut(actionBinding: (String) -> String?,
|
||||
actionId: String,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
shortcut: Shortcut) {
|
||||
val boundShortcuts = actionBinding(actionId)?.let { actionIdToShortcuts.get(it) }
|
||||
actionIdToShortcuts.compute(actionId) { id, list ->
|
||||
var result = list ?: boundShortcuts ?: getParentShortcuts(id, actionBinding)
|
||||
@@ -234,9 +244,6 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
}
|
||||
if (areShortcutsEqualToParent(result, id, actionBinding)) null else result
|
||||
}
|
||||
|
||||
cleanShortcutsCache()
|
||||
fireShortcutChanged(actionId, fromSettings)
|
||||
}
|
||||
|
||||
private fun cleanShortcutsCache() {
|
||||
@@ -247,18 +254,22 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
}
|
||||
|
||||
final override fun removeAllActionShortcuts(actionId: String) {
|
||||
return removeAllActionShortcuts(actionId, actionIdToShortcuts.value, ActionManagerEx.getInstanceEx()::getActionBinding)
|
||||
removeAllActionShortcuts(actionId = actionId,
|
||||
actionIdToShortcuts = actionIdToShortcuts.value,
|
||||
actionBinding = ActionManagerEx.getInstanceEx()::getActionBinding)
|
||||
|
||||
cleanShortcutsCache()
|
||||
fireShortcutChanged(actionIds = java.util.List.of(actionId), fromSettings = false)
|
||||
}
|
||||
|
||||
private fun removeAllActionShortcuts(actionId: String,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
actionBinding: (String) -> String?) {
|
||||
for (shortcut in getShortcutList(actionId = actionId, actionIdToShortcuts = actionIdToShortcuts, actionBinding = actionBinding)) {
|
||||
removeShortcut(actionId = actionId,
|
||||
toDelete = shortcut,
|
||||
fromSettings = false,
|
||||
actionBinding = actionBinding,
|
||||
actionIdToShortcuts = actionIdToShortcuts)
|
||||
doRemoveShortcut(actionBinding = actionBinding,
|
||||
actionId = actionId,
|
||||
actionIdToShortcuts = actionIdToShortcuts,
|
||||
toDelete = shortcut)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -277,27 +288,34 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
private fun doInitShortcuts(operations: List<KeymapShortcutOperation>,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
actionBinding: (String) -> String?) {
|
||||
val changedShortcuts = mutableListOf<String>()
|
||||
for (operation in operations) {
|
||||
when (operation) {
|
||||
is RemoveShortcutOperation -> {
|
||||
removeShortcut(actionId = operation.actionId,
|
||||
toDelete = operation.shortcut,
|
||||
fromSettings = false,
|
||||
actionIdToShortcuts = actionIdToShortcuts,
|
||||
actionBinding = actionBinding)
|
||||
doRemoveShortcut(actionId = operation.actionId,
|
||||
toDelete = operation.shortcut,
|
||||
actionIdToShortcuts = actionIdToShortcuts,
|
||||
actionBinding = actionBinding)
|
||||
changedShortcuts.add(operation.actionId)
|
||||
}
|
||||
is RemoveAllShortcutsOperation -> {
|
||||
removeAllActionShortcuts(actionId = operation.actionId, actionIdToShortcuts = actionIdToShortcuts, actionBinding = actionBinding)
|
||||
changedShortcuts.add(operation.actionId)
|
||||
}
|
||||
is AddShortcutOperation -> {
|
||||
addShortcut(actionId = operation.actionId,
|
||||
shortcut = operation.shortcut,
|
||||
fromSettings = false,
|
||||
actionIdToShortcuts = actionIdToShortcuts,
|
||||
actionBinding = actionBinding)
|
||||
doAddShortcut(actionId = operation.actionId,
|
||||
shortcut = operation.shortcut,
|
||||
actionIdToShortcuts = actionIdToShortcuts,
|
||||
actionBinding = actionBinding)
|
||||
changedShortcuts.add(operation.actionId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanShortcutsCache()
|
||||
if (changedShortcuts.isNotEmpty()) {
|
||||
fireShortcutChanged(actionIds = changedShortcuts, fromSettings = false)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun removeShortcutFromSettings(actionId: String, toDelete: Shortcut) {
|
||||
@@ -313,11 +331,21 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
fromSettings: Boolean,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
actionBinding: (String) -> String?) {
|
||||
doRemoveShortcut(actionBinding = actionBinding, actionId = actionId, actionIdToShortcuts = actionIdToShortcuts, toDelete = toDelete)
|
||||
|
||||
cleanShortcutsCache()
|
||||
fireShortcutChanged(actionIds = java.util.List.of(actionId), fromSettings = fromSettings)
|
||||
}
|
||||
|
||||
private fun doRemoveShortcut(actionBinding: (String) -> String?,
|
||||
actionId: String,
|
||||
actionIdToShortcuts: MutableMap<String, List<Shortcut>>,
|
||||
toDelete: Shortcut) {
|
||||
val fromBinding = actionBinding(actionId)?.let { actionIdToShortcuts.get(it) }
|
||||
actionIdToShortcuts.compute(actionId) { id, list ->
|
||||
when {
|
||||
list == null -> {
|
||||
val inherited = fromBinding ?: getParentShortcuts(id, actionBinding)
|
||||
val inherited = fromBinding ?: getParentShortcuts(id, actionBinding)
|
||||
if (inherited.contains(toDelete)) inherited - toDelete else null
|
||||
}
|
||||
!list.contains(toDelete) -> list
|
||||
@@ -328,9 +356,6 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cleanShortcutsCache()
|
||||
fireShortcutChanged(actionId = actionId, fromSettings = fromSettings)
|
||||
}
|
||||
|
||||
private fun areShortcutsEqualToParent(shortcuts: List<Shortcut>, actionId: String, actionBinding: (String) -> String?): Boolean {
|
||||
@@ -744,8 +769,9 @@ open class KeymapImpl @JvmOverloads constructor(@field:Volatile private var data
|
||||
|
||||
protected open fun convertShortcut(shortcut: Shortcut): Shortcut = shortcut
|
||||
|
||||
private fun fireShortcutChanged(actionId: String, fromSettings: Boolean) {
|
||||
ApplicationManager.getApplication().messageBus.syncPublisher(KeymapManagerListener.TOPIC).shortcutChanged(this, actionId, fromSettings)
|
||||
private fun fireShortcutChanged(actionIds: List<String>, fromSettings: Boolean) {
|
||||
ApplicationManager.getApplication().messageBus.syncPublisher(KeymapManagerListener.TOPIC)
|
||||
.shortcutsChanged(this, actionIds, fromSettings)
|
||||
}
|
||||
|
||||
override fun toString(): String = presentableName
|
||||
|
||||
@@ -180,7 +180,7 @@ public final class AntExplorer extends SimpleToolWindowPanel implements DataProv
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shortcutChanged(@NotNull Keymap keymap, @NotNull String actionId) {
|
||||
public void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
treeModel.invalidateAsync();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -17,6 +17,7 @@ import com.intellij.util.containers.DisposableWrapperList;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
@@ -29,10 +30,7 @@ import org.jetbrains.idea.maven.utils.MavenMergingUpdateQueue;
|
||||
import org.jetbrains.idea.maven.utils.MavenUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
public final class MavenShortcutsManager implements Disposable {
|
||||
@@ -79,7 +77,7 @@ public final class MavenShortcutsManager implements Disposable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shortcutChanged(@NotNull Keymap keymap, @NotNull String actionId) {
|
||||
public void shortcutsChanged(@NotNull Keymap keymap, @NonNls @NotNull Collection<String> actionIds, boolean fromSettings) {
|
||||
fireShortcutsUpdated();
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user