From ec0443f6563ae0abf0c77456fae4b59bde778c3c Mon Sep 17 00:00:00 2001 From: Mykola Donin Date: Thu, 17 Feb 2022 19:07:15 +0200 Subject: [PATCH 1/3] 1002: Sorting context actions. --- resources/META-INF/plugin.xml | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 03732dc1f..ceb85f271 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -59,22 +59,22 @@ - - - - + + + - - - - - - - + + + + + + + + From 101413bf4b68a8dbba81b665e991d71dfa0bb74b Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Feb 2022 13:01:03 +0200 Subject: [PATCH 2/3] 1002: Added programming sorting --- resources/META-INF/plugin.xml | 2 +- .../actions/groups/ContextActionsGroup.java | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index ceb85f271..a1fbfdee1 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -56,7 +56,7 @@ - + diff --git a/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java b/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java new file mode 100644 index 000000000..4ea30e237 --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java @@ -0,0 +1,51 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.groups; + +import com.intellij.ide.actions.NonEmptyActionGroup; +import com.intellij.openapi.actionSystem.AnAction; +import com.intellij.openapi.actionSystem.AnActionEvent; +import java.util.Arrays; +import java.util.Comparator; +import java.util.LinkedList; +import java.util.List; +import org.jetbrains.annotations.NotNull; + +public class ContextActionsGroup extends NonEmptyActionGroup { + + public ContextActionsGroup() { + super(); + } + + @Override + public void update(final @NotNull AnActionEvent event) { + if (getChildrenCount() > 0) { + final AnAction[] actions = getChildren(event); + final List originalActionList = new LinkedList<>(Arrays.asList(actions)); + final List sortedActionList = new LinkedList<>(Arrays.asList(actions)); + sortedActionList.sort(new ContextActionsComparator()); + + if (!originalActionList.equals(sortedActionList)) { + removeAll(); + addAll(sortedActionList.toArray(new AnAction[0])); + } + } + + super.update(event); + } + + private static class ContextActionsComparator implements Comparator { + + @Override + public int compare(final AnAction action1, final AnAction action2) { + if (action1.getTemplateText() == null || action2.getTemplateText() == null) { + return 0; + } + + return action1.getTemplateText().compareTo(action2.getTemplateText()); + } + } +} From 6dda8bccd23c57a580ac6e0c18af23f8bf38f444 Mon Sep 17 00:00:00 2001 From: bohdan-harniuk Date: Fri, 18 Feb 2022 13:02:03 +0200 Subject: [PATCH 3/3] 1002: Removed unnecessary constructor --- .../magento2plugin/actions/groups/ContextActionsGroup.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java b/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java index 4ea30e237..f0045b7db 100644 --- a/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java +++ b/src/com/magento/idea/magento2plugin/actions/groups/ContextActionsGroup.java @@ -16,10 +16,6 @@ public class ContextActionsGroup extends NonEmptyActionGroup { - public ContextActionsGroup() { - super(); - } - @Override public void update(final @NotNull AnActionEvent event) { if (getChildrenCount() > 0) {