mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[rdct] Use only a map for constraints in DefaultActionGroup
GitOrigin-RevId: d576c8abf3d0258feca2f31b8605b7c2884bd9e2
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c335ed7bc1
commit
7f03fe861a
+27
-38
@@ -33,7 +33,7 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
private static final Logger LOG = Logger.getInstance(DefaultActionGroup.class);
|
||||
|
||||
private final List<AnAction> mySortedChildren = new ArrayList<>();
|
||||
private final List<Pair<AnAction, Constraints>> myPairs = new ArrayList<>();
|
||||
private final List<AnAction> myPendingActions = new ArrayList<>();
|
||||
private final HashMap<AnAction, Constraints> myConstraints = new HashMap<>();
|
||||
private int myModificationStamp;
|
||||
|
||||
@@ -207,7 +207,7 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
mySortedChildren.add(action);
|
||||
}
|
||||
else {
|
||||
myPairs.add(Pair.create(action, constraint));
|
||||
myPendingActions.add(action);
|
||||
}
|
||||
myConstraints.put(action, constraint);
|
||||
addAllToSortedList(actionManager);
|
||||
@@ -216,20 +216,17 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
}
|
||||
|
||||
public synchronized boolean containsAction(@NotNull AnAction action) {
|
||||
if (mySortedChildren.contains(action)) return true;
|
||||
for (Pair<AnAction, Constraints> pair : myPairs) {
|
||||
if (action.equals(pair.first)) return true;
|
||||
}
|
||||
return false;
|
||||
return mySortedChildren.contains(action) || myPendingActions.contains(action);
|
||||
}
|
||||
|
||||
private void addAllToSortedList(@NotNull ActionManager actionManager) {
|
||||
outer:
|
||||
while (!myPairs.isEmpty()) {
|
||||
for (int i = 0; i < myPairs.size(); i++) {
|
||||
Pair<AnAction, Constraints> pair = myPairs.get(i);
|
||||
if (addToSortedList(pair.first, pair.second, actionManager)) {
|
||||
myPairs.remove(i);
|
||||
while (!myPendingActions.isEmpty()) {
|
||||
for (int i = 0; i < myPendingActions.size(); i++) {
|
||||
AnAction pendingAction = myPendingActions.get(i);
|
||||
Constraints constraints = myConstraints.get(pendingAction);
|
||||
if (constraints != null && addToSortedList(pendingAction, constraints, actionManager)) {
|
||||
myPendingActions.remove(i);
|
||||
continue outer;
|
||||
}
|
||||
}
|
||||
@@ -284,8 +281,8 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
boolean removed = mySortedChildren.remove(action);
|
||||
removed = removed || mySortedChildren.removeIf(
|
||||
o -> o instanceof ActionStubBase && ((ActionStubBase)o).getId().equals(id));
|
||||
removed = removed || myPairs.removeIf(
|
||||
o -> o.first.equals(action) || (o.first instanceof ActionStubBase && ((ActionStubBase)o.first).getId().equals(id)));
|
||||
removed = removed || myPendingActions.removeIf(
|
||||
o -> o.equals(action) || (o instanceof ActionStubBase && ((ActionStubBase)o).getId().equals(id)));
|
||||
myConstraints.remove(action);
|
||||
if (removed) {
|
||||
incrementModificationStamp();
|
||||
@@ -297,7 +294,7 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
*/
|
||||
public final synchronized void removeAll() {
|
||||
mySortedChildren.clear();
|
||||
myPairs.clear();
|
||||
myPendingActions.clear();
|
||||
myConstraints.clear();
|
||||
incrementModificationStamp();
|
||||
}
|
||||
@@ -314,14 +311,12 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < myPairs.size(); i++) {
|
||||
Pair<AnAction, Constraints> pair = myPairs.get(i);
|
||||
if (pair.first.equals(oldAction)) {
|
||||
myPairs.set(i, Pair.create(newAction, pair.second));
|
||||
replaceConstraint(oldAction, newAction);
|
||||
incrementModificationStamp();
|
||||
return true;
|
||||
}
|
||||
int indexOld = myPendingActions.indexOf(oldAction);
|
||||
if (indexOld >= 0) {
|
||||
myPendingActions.set(indexOld, newAction);
|
||||
replaceConstraint(oldAction, newAction);
|
||||
incrementModificationStamp();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@@ -345,8 +340,8 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
mySortedChildren.clear();
|
||||
mySortedChildren.addAll(other.mySortedChildren);
|
||||
|
||||
myPairs.clear();
|
||||
myPairs.addAll(other.myPairs);
|
||||
myPendingActions.clear();
|
||||
myPendingActions.addAll(other.myPendingActions);
|
||||
|
||||
myConstraints.clear();
|
||||
myConstraints.putAll(other.myConstraints);
|
||||
@@ -427,9 +422,8 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
}
|
||||
}
|
||||
}
|
||||
for (ListIterator<Pair<AnAction, Constraints>> it = myPairs.listIterator(); it.hasNext(); ) {
|
||||
Pair<AnAction, Constraints> pair = it.next();
|
||||
AnAction action = pair.first;
|
||||
for (ListIterator<AnAction> it = myPendingActions.listIterator(); it.hasNext(); ) {
|
||||
AnAction action = it.next();
|
||||
if (action == null) {
|
||||
LOG.error("Empty pair child: " + this + ", " + getClass() + "; index=" + it.previousIndex());
|
||||
it.remove();
|
||||
@@ -437,7 +431,7 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
else if (action instanceof ActionStubBase) {
|
||||
AnAction replacement = stubMap.get((ActionStubBase)action);
|
||||
if (replacement != null) {
|
||||
it.set(Pair.create(replacement, pair.second));
|
||||
it.set(replacement);
|
||||
replaceConstraint(action, replacement);
|
||||
replace(action, replacement);
|
||||
}
|
||||
@@ -453,18 +447,18 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
* Returns the number of contained children (including separators).
|
||||
*/
|
||||
public final synchronized int getChildrenCount() {
|
||||
return mySortedChildren.size() + myPairs.size();
|
||||
return mySortedChildren.size() + myPendingActions.size();
|
||||
}
|
||||
|
||||
public final synchronized AnAction @NotNull [] getChildActionsOrStubs() {
|
||||
// Mix sorted actions and pairs
|
||||
int sortedSize = mySortedChildren.size();
|
||||
AnAction[] children = new AnAction[sortedSize + myPairs.size()];
|
||||
AnAction[] children = new AnAction[sortedSize + myPendingActions.size()];
|
||||
for (int i = 0; i < sortedSize; i++) {
|
||||
children[i] = mySortedChildren.get(i);
|
||||
}
|
||||
for (int i = 0; i < myPairs.size(); i++) {
|
||||
children[i + sortedSize] = myPairs.get(i).first;
|
||||
for (int i = 0; i < myPendingActions.size(); i++) {
|
||||
children[i + sortedSize] = myPendingActions.get(i);
|
||||
}
|
||||
return children;
|
||||
}
|
||||
@@ -507,11 +501,6 @@ public class DefaultActionGroup extends ActionGroup {
|
||||
return myConstraints.get(action);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public synchronized Map<AnAction, Constraints> getAllConstraints() {
|
||||
return new HashMap<>(myConstraints);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an action group with the specified template text.
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user