RUBY-22706 provide ability to import scheme file from ide resources rather than from disk

This commit is contained in:
Dmitry.Krasilschikov
2018-10-24 13:46:57 +03:00
parent 72607096d0
commit e6686754f3
2 changed files with 25 additions and 5 deletions
@@ -54,8 +54,11 @@ public abstract class ColorSchemeActions extends AbstractSchemeActions<EditorCol
}
final SchemeImporter<EditorColorsScheme> importer = SchemeImporterEP.getImporter(importerName, EditorColorsScheme.class);
if (importer != null) {
VirtualFile importSource =
SchemeImportUtil.selectImportSource(importer.getSourceExtensions(), getSchemesPanel(), null, "Choose " + importerName);
VirtualFile importSource = importer.getImportFile();
if (importSource == null) {
importSource =
SchemeImportUtil.selectImportSource(importer.getSourceExtensions(), getSchemesPanel(), null, "Choose " + importerName);
}
if (importSource != null) {
if ("jar".equals(importSource.getExtension())) {
importFromJar(getSchemesPanel().getToolbar(), importer, importSource);
@@ -83,9 +86,7 @@ public abstract class ColorSchemeActions extends AbstractSchemeActions<EditorCol
if (imported != null) {
getOptions().addImportedScheme(imported);
getSchemesPanel()
.showStatus(
ApplicationBundle.message("settings.editor.scheme.import.success", importSource.getPresentableUrl(), imported.getName()),
MessageType.INFO);
.showStatus(importer.getAfterImportMessage(importSource.getPresentableUrl(), imported.getName()), MessageType.INFO);
}
}
catch (SchemeImportException e) {
@@ -1,5 +1,6 @@
package com.intellij.openapi.options;
import com.intellij.openapi.application.ApplicationBundle;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
@@ -44,4 +45,22 @@ public interface SchemeImporter <T extends Scheme> {
default String getAdditionalImportInfo(@NotNull T scheme) {
return null;
}
/**
* @return File to import scheme. If it's {@code null} than file chooser is shown.
*/
@Nullable
default VirtualFile getImportFile() {
return null;
}
/**
* @return Message to be shown after successful importing
* @param presentableUrl Url of file that has been imported
* @param newSchemeName New created scheme name
*/
@NotNull
default String getAfterImportMessage(@NotNull String presentableUrl, @NotNull String newSchemeName) {
return ApplicationBundle.message("settings.editor.scheme.import.success", presentableUrl, newSchemeName);
}
}