support for double shortcuts in shortcuts collector

This commit is contained in:
Konstantin Bulenkov
2017-06-06 00:12:30 +02:00
parent e43bd12944
commit fb700a78cb
2 changed files with 23 additions and 6 deletions
@@ -59,19 +59,34 @@ public class ShortcutsCollector implements PersistentStateComponent<ShortcutsCol
}
public static void record(AnActionEvent event) {
_record(event, false);
}
public static void recordDoubleShortcut(AnActionEvent event) {
_record(event, true);
}
private static void _record(AnActionEvent event, boolean isDoubleShortcut) {
InputEvent e = event.getInputEvent();
if (e instanceof KeyEvent) {
KeyboardShortcut shortcut = new KeyboardShortcut(KeyStroke.getKeyStrokeForEvent((KeyEvent)e), null);
String key = KeymapUtil.getShortcutText(shortcut);
ShortcutsCollector collector = getInstance();
if (collector == null) return; //no shortcuts stats for the IDE
Map<String, Integer> values = collector.getState().myValues;
values.put(key, ContainerUtil.getOrElse(values, key, 0) + 1);
if (isDoubleShortcut) {
key = SystemInfo.isMac ? key + key : key + "+" + key;
}
incValue(key);
}
}
private static void incValue(String key) {
ShortcutsCollector collector = getInstance();
if (collector == null) return; //no shortcuts stats for the IDE
Map<String, Integer> values = collector.getState().myValues;
values.put(key, ContainerUtil.getOrElse(values, key, 0) + 1);
}
private static ShortcutsCollector getInstance() {
return ServiceManager.getService(ShortcutsCollector.class);
@@ -17,6 +17,7 @@ package com.intellij.openapi.keymap.impl;
import com.intellij.ide.DataManager;
import com.intellij.ide.IdeEventQueue;
import com.intellij.internal.statistic.ShortcutsCollector;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
@@ -260,6 +261,7 @@ public class ModifierKeyDoubleClickHandler implements Disposable, ApplicationCom
myActionManagerEx.fireBeforeActionPerformed(action, anActionEvent.getDataContext(), anActionEvent);
action.actionPerformed(anActionEvent);
myActionManagerEx.fireAfterActionPerformed(action, anActionEvent.getDataContext(), anActionEvent);
ShortcutsCollector.recordDoubleShortcut(anActionEvent);
return true;
}
finally {