hide some non-applicable keymaps 5

GitOrigin-RevId: 0ff14cd77e4ff3ec2fe225c2fc37e53abd9b5e09
This commit is contained in:
Gregory.Shrago
2019-09-30 16:34:17 +00:00
committed by intellij-monorepo-bot
parent e28222ad16
commit dc86e49dd0
@@ -19,9 +19,9 @@
*/
package com.intellij.openapi.keymap.impl;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManagerCore;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import org.jetbrains.annotations.ApiStatus;
@@ -44,17 +44,19 @@ public class DefaultBundledKeymaps implements BundledKeymapProvider {
String os = SystemInfo.isMac ? "macos" :
SystemInfo.isWindows ? "windows" :
SystemInfo.isLinux ? "linux" : "other";
PluginId coreId = PluginId.getId(PluginManagerCore.CORE_PLUGIN_ID);
boolean headless = ApplicationManager.getApplication().isHeadlessEnvironment();
for (BundledKeymapBean bean : BundledKeymapBean.EP_NAME.getExtensionList()) {
IdeaPluginDescriptor plugin = bean.getPluginId() == null ? null : PluginManagerCore.getPlugin(bean.getPluginId());
String keymapName = FileUtil.getNameWithoutExtension(bean.file);
if (bean.file.contains("$OS$")) {
// add all OS-specific
result.add(bean.file.replace("$OS$", os));
}
else if (headless ||
!coreId.equals(bean.getPluginId()) ||
!isBundledKeymapHidden(FileUtil.getNameWithoutExtension(bean.file))) {
// filter out bundled keymaps for other systems, but allow them via plugins
plugin != null && !plugin.isBundled() && !isBundledMacOSKeymap(keymapName) ||
!isBundledKeymapHidden(keymapName)) {
// filter out bundled keymaps for other systems, but allow them via non-bundled plugins
// also skip non-bundled known macOS keymaps on non-macOS systems
result.add(bean.file);
}
}
@@ -67,6 +69,11 @@ public class DefaultBundledKeymaps implements BundledKeymapProvider {
"Default for GNOME".equals(keymapName) ||
"Default for KDE".equals(keymapName)) return true;
}
if (isBundledMacOSKeymap(keymapName)) return true;
return false;
}
private static boolean isBundledMacOSKeymap(@Nullable String keymapName) {
if (!SystemInfo.isMac) {
if ("Mac OS X".equals(keymapName) ||
"Mac OS X 10.5+".equals(keymapName) ||