improve ActionsWithInvalidTemplatePresentationTest

And fix all the newly reported actions.

GitOrigin-RevId: 7e386afd5de679b52c47f9500becb5aa7cc6fec8
This commit is contained in:
Gregory.Shrago
2024-03-20 22:53:26 +04:00
committed by intellij-monorepo-bot
parent 337fc4832f
commit ffd217e2bf
8 changed files with 73 additions and 48 deletions

View File

@@ -37,7 +37,6 @@ action.settings.description.mac=Edit application preferences
action.settings.path=File | Settings
action.settings.path.mac=Preferences
action.settings.path.macOS.ventura=Settings
action.settings.path.template.text=Copy {0} Path
action.appmenu.services=Services
action.appmenu.hide_ide=Hide

View File

@@ -1,7 +1,6 @@
// 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.
package com.intellij.ide.actions;
import com.intellij.idea.ActionsBundle;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.DumbAwareAction;
@@ -11,8 +10,7 @@ import com.intellij.ui.mac.foundation.ID;
import org.jetbrains.annotations.NotNull;
final class MacEmojiAndSymbolsInputAction extends DumbAwareAction {
public MacEmojiAndSymbolsInputAction() {
getTemplatePresentation().setText(ActionsBundle.message("EmojiAndSymbols.text"), false);
MacEmojiAndSymbolsInputAction() {
setEnabledInModalContext(true);
}

View File

@@ -8,11 +8,10 @@ import com.intellij.ide.ui.search.SearchableOptionsRegistrar
import com.intellij.idea.ActionsBundle
import com.intellij.openapi.actionSystem.ActionManager
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.PlatformCoreDataKeys.CONTEXT_COMPONENT
import com.intellij.openapi.ide.CopyPasteManager
import com.intellij.openapi.project.DumbAware
import com.intellij.openapi.project.DumbAwareAction
import com.intellij.openapi.util.NlsActions
import com.intellij.ui.ComponentUtil
import com.intellij.ui.tabs.JBTabs
@@ -26,10 +25,7 @@ import java.util.function.Supplier
import javax.swing.*
import javax.swing.border.TitledBorder
private val pathActionName: String
get() = CommonBundle.message("action.settings.path.template.text", CommonBundle.settingsTitle())
internal class CopySettingsPathAction : AnAction(pathActionName, ActionsBundle.message("action.CopySettingsPath.description"), null), DumbAware {
internal class CopySettingsPathAction : DumbAwareAction() {
init {
isEnabledInModalContext = true
}
@@ -38,7 +34,7 @@ internal class CopySettingsPathAction : AnAction(pathActionName, ActionsBundle.m
@JvmStatic
fun createSwingActions(supplier: Supplier<Collection<String>>): List<Action> {
return listOf(
createSwingAction("CopySettingsPath", pathActionName) { copy(supplier.get()) },
createSwingAction("CopySettingsPath", getActionText()) { copy(supplier.get()) },
// disable until REST API is not able to delegate to proper IDE
//createSwingAction(null, "Copy ${CommonBundle.settingsTitle()} Link") {
// copyLink(supplier, isHttp = true)
@@ -61,11 +57,15 @@ internal class CopySettingsPathAction : AnAction(pathActionName, ActionsBundle.m
}
return TextTransferable(sb)
}
private fun getActionText() =
ActionsBundle.message("action.CopySettingsPath.text.template", CommonBundle.settingsTitle())
}
override fun update(event: AnActionEvent) {
val component = event.getData(CONTEXT_COMPONENT)
val editor = ComponentUtil.getParentOfType(SettingsEditor::class.java, component)
event.presentation.text = getActionText()
event.presentation.isEnabledAndVisible = editor != null
}

View File

@@ -412,6 +412,8 @@ action.CopyPaths.text=C_opy Paths
action.CopyPaths.description=Copy paths corresponding to selected files or directories to clipboard
action.CopyReference.text=Cop_y Reference
action.CopyReference.description=Copy reference to selected class, method or function, or a relative path to selected file
action.CopySettingsPath.text=Copy Option Path
action.CopySettingsPath.text.template=Copy {0} Path
action.CopySettingsPath.description=Copy relative path to selected configurable option
action.CopyAsRichText.text=Copy as Rich Text
action.CopyAsRichText.description=Copy selection to clipboard as rich text (in RTF and HTML formats)
@@ -1018,6 +1020,7 @@ action.EmmetPreview.description=Show preview for emmet abbreviation
action.SurroundWithEmmet.text=Surround with Emmet
action.SurroundWithEmmet.description=Surround selected code with Emmet abbreviation
group.Emmet.text=Emmet
group.OpenInBrowserEditorContextBarGroupAction.text=Open In...
group.OpenInBrowserEditorContextBarGroupAction.description=Open In...
action.OpenInBrowser.text=Open in default _browser
action.OpenInBrowser.description=Open selected file in default browser
@@ -1911,7 +1914,8 @@ action.Console.History.Browse.text=Browse Query History
action.Console.History.Browse.description=Browse query history
action.OpenInAssociatedApplication.text=Open In Associated Application
action.OpenInAssociatedApplication.description=Open in associated application
action.RevealIn.description=Highlights the file in platform's file manager
action.RevealIn.text=Show in File Manager
action.RevealIn.description=Highlights the file in OS file manager
action.RevealIn.name.mac=Reveal in Finder
action.RevealIn.name.other=Show in {0}
show.log.in.action.text=Show Log in {0}
@@ -2294,7 +2298,7 @@ action.CopySourceRootPath.text=Path From Source Root
action.CopyTBXReference.text=Toolbox URL
action.CopyFileName.text=File Name
EmojiAndSymbols.text=Emoji \\& Symbols
action.EmojiAndSymbols.text=Emoji \\&\\& Symbols
action.ToggleFocusMode.text=Highlight Only Current Declaration
group.ListActions.text=List Actions
@@ -2792,6 +2796,7 @@ action.TopStripeUnPinButton.text=Unpin
group.Documentation.Navigation.text=Quick Documentation Navigation
action.AddBreakpoint.text=Add Breakpoint
action.AddConditionalBreakpoint.text=Add Conditional Breakpoint...
group.XDebugger.Attach.Dialog.Settings.text=Attach dialog settings
action.XDebugger.Show.Breakpoints.Over.Line.Numbers.text=Breakpoints Over Line Numbers

View File

@@ -6,28 +6,40 @@ import com.intellij.openapi.actionSystem.ActionStub;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.actionSystem.impl.ActionManagerImpl;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.junit5.DynamicTests;
import com.intellij.testFramework.junit5.NamedFailure;
import com.intellij.testFramework.junit5.TestApplication;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.TestMethodOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
public class ActionsWithInvalidTemplatePresentationTest extends LightPlatformTestCase {
private static final List<String> KNOWN_FALSE_POSITIVES = Arrays.asList(
@TestMethodOrder(MethodOrderer.MethodName.class)
@TestApplication
public class ActionsWithInvalidTemplatePresentationTest {
// TODO fix and remove the field
private static final List<String> ACTIONS_TO_FIX = Arrays.asList(
"InsertRubyInjection",
"InsertRubyInjectionWithoutOutput"
);
public void testActionsPresentations() {
@TestFactory
public List<DynamicTest> testActionsPresentations() {
ActionManagerImpl actionManager = (ActionManagerImpl)ActionManager.getInstance();
List<String> failed = new ArrayList<>();
List<NamedFailure> failures = new ArrayList<>();
for (Iterator<AnAction> it = actionManager.actions(true).iterator(); it.hasNext(); ) {
AnAction action = it.next();
String id = actionManager.getId(action);
if (KNOWN_FALSE_POSITIVES.contains(id)) {
if (ACTIONS_TO_FIX.contains(id)) {
continue;
}
@@ -35,19 +47,42 @@ public class ActionsWithInvalidTemplatePresentationTest extends LightPlatformTes
String text = presentation.getText();
String description = presentation.getDescription();
if (!isValidText(text) || !isValidText(description)) {
Object aClass = action instanceof ActionStub ? "class "+((ActionStub)action).getClassName() : action.getClass();
failed.add(id + "; " + aClass + "; text: '" + text + "'; description: '" + description + "'\n");
if (hasTemplates(text) || hasTemplates(description)) {
failures.add(newFailure(action, id, text, description, "string template markup"));
}
if (hasHtmlTags(text) || hasHtmlTags(description)) {
failures.add(newFailure(action, id, text, description, "HTML markup"));
}
if (StringUtil.isEmptyOrSpaces(text) && !StringUtil.isEmptyOrSpaces(description)) {
failures.add(newFailure(action, id, text, description, "empty text but description is ok"));
}
}
System.err.println(failed);
assertEmpty("The following actions might have invalid template presentation:\n", failed);
return DynamicTests.asDynamicTests(failures, "incorrect project settings");
}
private static boolean isValidText(@Nullable String text) {
if (text == null) return true;
if (text.contains("{")) return false; // MessageFormat template
if (text.contains("<")) return false; // HTML
return true;
private static @NotNull NamedFailure newFailure(@NotNull AnAction action,
@NotNull String id,
@Nullable String text,
@Nullable String description,
@NotNull String comment) {
Object aClass = action instanceof ActionStub ? "class " + ((ActionStub)action).getClassName() : action.getClass();
String message = id + "; " + aClass + "; text: '" + text + "'; description: '" + description + "'";
return new NamedFailure("Action '" + id + "': " + comment, message);
}
/**
* Potential MessageFormat template
*/
private static boolean hasTemplates(@Nullable String text) {
return text != null && text.contains("{");
}
/**
* Potential HTML
*/
private static boolean hasHtmlTags(@Nullable String text) {
return text != null && text.contains("<");
}
}

View File

@@ -1,5 +1,6 @@
action.open.trace.directory.in.file.manager.text=Open Directory in File Manager
action.toggle.build.tracing.text=Toggle Build Tracing
action.toggle.tracing.action.text=Toggle tracing
action.toggle.tracing.action.description=Toggle tracing
build.tracing.group=Build tracing
notification.content.tracing.file.was.created=Tracing file was created

View File

@@ -317,7 +317,5 @@ notification.group.debugger.messages=Debugger messages
debugger.frame.list.help.title=Reset Frame
debugger.frame.list.help.description=Go back to the previous frame. This will reset local variables, but the global state will not be changed.
XDebugger.Attach.Dialog.Settings.text=Attach dialog settings
action.TurnOffDfaAssist.text=Turn Off Data Flow Assist for This Session
action.TurnOffDfaAssist.description=Switch off data flow\u2013aided debugging for this session

View File

@@ -2,27 +2,16 @@
package com.intellij.xdebugger.impl.ui.attach.dialog
import com.intellij.icons.AllIcons
import com.intellij.openapi.actionSystem.ActionUpdateThread
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.DefaultActionGroup
import com.intellij.ide.actions.NonEmptyActionGroup
import com.intellij.openapi.actionSystem.RightAlignedToolbarAction
import com.intellij.openapi.actionSystem.ex.TooltipDescriptionProvider
import com.intellij.openapi.project.DumbAware
import com.intellij.ui.ExperimentalUI
import com.intellij.xdebugger.XDebuggerBundle
class AttachDialogSettings : DefaultActionGroup(
null,
XDebuggerBundle.message(
"XDebugger.Attach.Dialog.Settings.text"),
if (ExperimentalUI.isNewUI())
AllIcons.Actions.More
else
AllIcons.General.GearPlain), RightAlignedToolbarAction, TooltipDescriptionProvider, DumbAware {
override fun update(e: AnActionEvent) {
e.presentation.isEnabledAndVisible = getChildren(e).any()
class AttachDialogSettings : NonEmptyActionGroup(), RightAlignedToolbarAction, TooltipDescriptionProvider, DumbAware {
init {
templatePresentation.icon =
if (ExperimentalUI.isNewUI()) AllIcons.Actions.More
else AllIcons.General.GearPlain
}
override fun getActionUpdateThread(): ActionUpdateThread = ActionUpdateThread.BGT
}