FUS: migrate "ui.mnemonic" to the new API (IDEA-268269)

GitOrigin-RevId: 9aab532e4b002816082e2ec362408d727db87fd4
This commit is contained in:
Anastasia Ivanova
2022-01-13 05:10:31 +00:00
committed by intellij-monorepo-bot
parent 2803a0adf2
commit ccb5fbc907
3 changed files with 45 additions and 19 deletions
@@ -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) {
@@ -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)
}
}
}
}
}
@@ -774,7 +774,7 @@
<statistics.counterUsagesCollector implementationClass="com.intellij.ide.lightEdit.LightEditFeatureUsagesUtil"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.internal.statistic.collectors.fus.TypingEventsLogger"/>
<statistics.counterUsagesCollector groupId="ui.mnemonic" version="1"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.ide.MnemonicUsageCollector"/>
<statistics.counterUsagesCollector groupId="event.log" version="57"/>
<statistics.counterUsagesCollector implementationClass="com.intellij.diagnostic.IdeHeartbeatEventReporter$UILatencyLogger"/>