From ccb5fbc9073b13a6704c9dabfaae2e5388722683 Mon Sep 17 00:00:00 2001 From: Anastasia Ivanova Date: Mon, 10 Jan 2022 22:15:12 +0700 Subject: [PATCH] FUS: migrate "ui.mnemonic" to the new API (IDEA-268269) GitOrigin-RevId: 9aab532e4b002816082e2ec362408d727db87fd4 --- .../src/com/intellij/ide/IdeEventQueue.java | 19 +------- .../intellij/ide/MnemonicUsageCollector.kt | 43 +++++++++++++++++++ .../src/META-INF/PlatformExtensions.xml | 2 +- 3 files changed, 45 insertions(+), 19 deletions(-) create mode 100644 platform/platform-impl/src/com/intellij/ide/MnemonicUsageCollector.kt diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index f61b610a0d57..bfc96962ad85 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -876,24 +876,7 @@ public final class IdeEventQueue extends EventQueue { super.dispatchEvent(e); // collect mnemonics statistics only if key event was processed above if (!consumed && ke.isConsumed() && KeyEvent.KEY_PRESSED == ke.getID()) { - int code = ke.getKeyCode(); - if (KeyEvent.VK_0 <= code && code <= KeyEvent.VK_Z) { - int modifiers = ke.getModifiersEx(); - FeatureUsageData data = null; - if (modifiers == InputEvent.ALT_DOWN_MASK) { - if (IdeKeyEventDispatcher.hasMnemonicInWindow(ke.getComponent(), ke)) { - data = new FeatureUsageData().addData("type", SystemInfoRt.isMac ? "mac.alt.based" : "regular"); - } - } - else if (SystemInfoRt.isMac && modifiers == (InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) { - if (IdeKeyEventDispatcher.hasMnemonicInWindow(ke.getComponent(), ke)) { - data = new FeatureUsageData().addData("type", "mac.regular"); - } - } - if (data != null) { - FUCounterUsageLogger.getInstance().logEvent("ui.mnemonic", "mnemonic.used", data); - } - } + MnemonicUsageCollector.logMnemonicUsed(ke); } } catch (Throwable t) { diff --git a/platform/platform-impl/src/com/intellij/ide/MnemonicUsageCollector.kt b/platform/platform-impl/src/com/intellij/ide/MnemonicUsageCollector.kt new file mode 100644 index 000000000000..b819b7339498 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ide/MnemonicUsageCollector.kt @@ -0,0 +1,43 @@ +// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.ide + +import com.intellij.internal.statistic.eventLog.EventLogGroup +import com.intellij.internal.statistic.eventLog.events.EventFields +import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector +import com.intellij.openapi.keymap.impl.IdeKeyEventDispatcher +import com.intellij.openapi.util.SystemInfoRt +import java.awt.event.InputEvent +import java.awt.event.KeyEvent + +class MnemonicUsageCollector: CounterUsagesCollector() { + override fun getGroup(): EventLogGroup = GROUP + + companion object { + private val GROUP = EventLogGroup("ui.mnemonic", 2) + private val MNEMONIC_USED = GROUP.registerEvent("mnemonic.used", + EventFields.String("type", listOf("mac.alt.based", "regular", "mac.regular"))) + + @JvmStatic + fun logMnemonicUsed(ke: KeyEvent?) { + if (ke == null) return + val code = ke.keyCode + if (KeyEvent.VK_0 <= code && code <= KeyEvent.VK_Z) { + val modifiers = ke.modifiersEx + var type: String? = null + if (modifiers == InputEvent.ALT_DOWN_MASK) { + if (IdeKeyEventDispatcher.hasMnemonicInWindow(ke.component, ke)) { + type = if (SystemInfoRt.isMac) "mac.alt.based" else "regular" + } + } + else if (SystemInfoRt.isMac && modifiers == InputEvent.ALT_DOWN_MASK or InputEvent.CTRL_DOWN_MASK) { + if (IdeKeyEventDispatcher.hasMnemonicInWindow(ke.component, ke)) { + type = "mac.regular" + } + } + if (type != null) { + MNEMONIC_USED.log(type) + } + } + } + } +} \ No newline at end of file diff --git a/platform/platform-resources/src/META-INF/PlatformExtensions.xml b/platform/platform-resources/src/META-INF/PlatformExtensions.xml index 3deb7afbc7b3..c7eef1e8d072 100644 --- a/platform/platform-resources/src/META-INF/PlatformExtensions.xml +++ b/platform/platform-resources/src/META-INF/PlatformExtensions.xml @@ -774,7 +774,7 @@ - +