mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
BundledKeymapProvider should be able to override default load logic
This commit is contained in:
+11
@@ -16,9 +16,14 @@
|
||||
package com.intellij.openapi.keymap.impl;
|
||||
|
||||
import com.intellij.openapi.extensions.ExtensionPointName;
|
||||
import com.intellij.util.io.URLUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
* Name file as "Your scheme name.xml" and put it to keymaps.
|
||||
@@ -29,4 +34,10 @@ public interface BundledKeymapProvider {
|
||||
|
||||
@NotNull
|
||||
List<String> getKeymapFileNames();
|
||||
|
||||
default <R> R load(@NotNull String key, @NotNull Function<InputStream, R> consumer) throws IOException {
|
||||
try (InputStream stream = URLUtil.openResourceStream(new URL("file:///keymaps/" + key))) {
|
||||
return consumer.apply(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
import gnu.trove.THashMap
|
||||
import org.jdom.Element
|
||||
import java.net.URL
|
||||
import java.util.*
|
||||
|
||||
private val LOG = Logger.getInstance("#com.intellij.openapi.keymap.impl.DefaultKeymap")
|
||||
@@ -65,9 +64,7 @@ open class DefaultKeymap {
|
||||
|
||||
LOG.catchAndLog {
|
||||
loadKeymapsFromElement(object: SchemeDataHolder<KeymapImpl> {
|
||||
override fun read(): Element {
|
||||
return JDOMUtil.loadResourceDocument(URL("file:///keymaps/$key")).rootElement
|
||||
}
|
||||
override fun read() = provider.load(key) { JDOMUtil.load(it) }
|
||||
|
||||
override fun updateDigest(scheme: KeymapImpl) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user