From 91800efa6813a8654e4b3626f1890593442ad8ce Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Mon, 6 Mar 2017 14:49:54 +0300 Subject: [PATCH 1/2] [shelf]: disable custom Shelf dir for default project, update actions * (IDEA-168865) update okActions before dialog shown; * (IDEA-168866) make cancel default button; * disable 'Change Shelves Location' button for Default project settings; * cleanUp; --- .../ShelfProjectConfigurationPanel.java | 11 +++++--- .../ShelfStorageConfigurationDialog.java | 28 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfProjectConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfProjectConfigurationPanel.java index 31c22625cb00..7d619238498c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfProjectConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfProjectConfigurationPanel.java @@ -41,7 +41,8 @@ import static java.awt.GridBagConstraints.NONE; import static java.awt.GridBagConstraints.NORTHWEST; public class ShelfProjectConfigurationPanel extends JPanel { - @NotNull private static final String CURRENT_LOCATION_HINT = "Current location: "; + @NotNull private static final String CURRENT_LOCATION_HINT = "Current location is "; + @NotNull private static final String DEFAULT_LOCATION_HINT = "Default location is "; @NotNull private final VcsConfiguration myVcsConfiguration; @NotNull private final Project myProject; @NotNull private final JBCheckBox myBaseRevisionTexts; @@ -73,6 +74,7 @@ public class ShelfProjectConfigurationPanel extends JPanel { JPanel shelfConfigurablePanel = new JPanel(new BorderLayout(DEFAULT_HGAP, DEFAULT_VGAP)); JButton shelfConfigurableButton = new JButton("Change Shelves Location"); + shelfConfigurableButton.setEnabled(!myProject.isDefault()); shelfConfigurableButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -89,10 +91,11 @@ public class ShelfProjectConfigurationPanel extends JPanel { } private void updateLabelInfo() { - myInfoLabel.setText(CURRENT_LOCATION_HINT + (myVcsConfiguration.USE_CUSTOM_SHELF_PATH ? toSystemDependentName( - assertNotNull(myVcsConfiguration.CUSTOM_SHELF_PATH)) : getDefaultShelfPresentationPath(myProject))); + myInfoLabel.setText((myProject.isDefault() ? DEFAULT_LOCATION_HINT : CURRENT_LOCATION_HINT) + + (myVcsConfiguration.USE_CUSTOM_SHELF_PATH ? toSystemDependentName( + assertNotNull(myVcsConfiguration.CUSTOM_SHELF_PATH)) : getDefaultShelfPresentationPath(myProject))); } - + /** * System dependent path to default shelf dir */ diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfStorageConfigurationDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfStorageConfigurationDialog.java index a18252a444e0..3800431ad931 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfStorageConfigurationDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/configurable/ShelfStorageConfigurationDialog.java @@ -69,6 +69,9 @@ public class ShelfStorageConfigurationDialog extends DialogWrapper { myMoveShelvesCheckBox = new JBCheckBox(VcsBundle.message("vcs.shelf.move.text")); setOKButtonText("_Change Location"); initComponents(); + updateOkAction(); + getOKAction().putValue(DEFAULT_ACTION, null); + getCancelAction().putValue(DEFAULT_ACTION, Boolean.TRUE); init(); initValidation(); } @@ -87,7 +90,8 @@ public class ShelfStorageConfigurationDialog extends DialogWrapper { myUseCustomShelfDirectory.setSelected(myVcsConfiguration.USE_CUSTOM_SHELF_PATH); myMoveShelvesCheckBox.setSelected(myVcsConfiguration.MOVE_SHELVES); myShelfDirectoryPath - .setText(FileUtil.toSystemDependentName(chooseNotNull(myVcsConfiguration.CUSTOM_SHELF_PATH, getDefaultShelfPresentationPath(myProject)))); + .setText( + FileUtil.toSystemDependentName(chooseNotNull(myVcsConfiguration.CUSTOM_SHELF_PATH, getDefaultShelfPresentationPath(myProject)))); setEnabledCustomShelfDirectoryComponents(myUseCustomShelfDirectory.isSelected()); myUseCustomShelfDirectory.addChangeListener(e -> setEnabledCustomShelfDirectoryComponents(myUseCustomShelfDirectory.isSelected())); } @@ -95,9 +99,6 @@ public class ShelfStorageConfigurationDialog extends DialogWrapper { private void setEnabledCustomShelfDirectoryComponents(boolean enabled) { myShelfDirectoryPath.setEnabled(enabled); myShelfDirectoryPath.setEditable(enabled); - if (enabled && myProject.isDefault() && myVcsConfiguration.CUSTOM_SHELF_PATH == null) { - myShelfDirectoryPath.setText(""); - } } @Nullable @@ -162,17 +163,15 @@ public class ShelfStorageConfigurationDialog extends DialogWrapper { myVcsConfiguration.USE_CUSTOM_SHELF_PATH = nowCustom; myVcsConfiguration.CUSTOM_SHELF_PATH = customPath; myVcsConfiguration.MOVE_SHELVES = myMoveShelvesCheckBox.isSelected(); - if (!myProject.isDefault()) { - File fromFile = new File(wasCustom ? prevPath : getDefaultShelfPath(myProject)); - File toFile = new File(nowCustom ? customPath : getDefaultShelfPath(myProject)); - - if (!FileUtil.filesEqual(fromFile, toFile)) { - myProject.save(); - if (wasCustom) { - ApplicationManager.getApplication().saveSettings(); - } - ShelveChangesManager.getInstance(myProject).checkAndMigrateUnderProgress(fromFile, toFile, wasCustom); + File fromFile = new File(wasCustom ? prevPath : getDefaultShelfPath(myProject)); + File toFile = new File(nowCustom ? customPath : getDefaultShelfPath(myProject)); + + if (!FileUtil.filesEqual(fromFile, toFile)) { + myProject.save(); + if (wasCustom) { + ApplicationManager.getApplication().saveSettings(); } + ShelveChangesManager.getInstance(myProject).checkAndMigrateUnderProgress(fromFile, toFile, wasCustom); } super.doOKAction(); } @@ -214,7 +213,6 @@ public class ShelfStorageConfigurationDialog extends DialogWrapper { private boolean isModified() { if (myVcsConfiguration.USE_CUSTOM_SHELF_PATH != myUseCustomShelfDirectory.isSelected()) return true; - if (myVcsConfiguration.MOVE_SHELVES != myMoveShelvesCheckBox.isSelected()) return true; return myUseCustomShelfDirectory.isSelected() && !StringUtil.equals(myVcsConfiguration.CUSTOM_SHELF_PATH, myShelfDirectoryPath.getText()); } From 6b01109910082e4fc21056ea86c0fb9f52d8e222 Mon Sep 17 00:00:00 2001 From: Rustam Vishnyakov Date: Mon, 6 Mar 2017 15:24:06 +0300 Subject: [PATCH 2/2] Import/export Intellij IDEA color schemes from schemes menu --- .../editor/colors/EditorColorsManager.java | 2 + .../colors/impl/AbstractColorsScheme.java | 4 ++ .../codeStyle/CodeStyleSchemesActions.java | 53 -------------- .../options/colors/ColorAndFontOptions.java | 13 ++-- .../options/colors/ColorSchemeActions.java | 19 +++-- .../options/colors/ColorSchemeExporter.java | 30 ++++++++ .../options/colors/ColorSchemeImporter.java | 71 +++++++++++++++++++ .../schemes/AbstractSchemeActions.java | 55 +++++++++++++- .../codeStyle/CodeStyleSchemeXmlImporter.java | 3 +- .../codeStyle/CodeStyleSettingsLoader.java | 38 +--------- .../colors/impl/EditorColorsManagerImpl.java | 2 +- .../openapi/options/SchemeImportUtil.java | 33 ++++++++- .../src/messages/ApplicationBundle.properties | 2 +- .../src/META-INF/LangExtensions.xml | 8 +++ 14 files changed, 225 insertions(+), 108 deletions(-) create mode 100644 platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeExporter.java create mode 100644 platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeImporter.java diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsManager.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsManager.java index dd0cdbb00fc1..7068d03bcc27 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsManager.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/colors/EditorColorsManager.java @@ -29,6 +29,8 @@ public abstract class EditorColorsManager { @NonNls public static final String DEFAULT_SCHEME_NAME = "Default"; + @NonNls public static final String COLOR_SCHEME_FILE_EXTENSION = ".icls"; + public static EditorColorsManager getInstance() { return ServiceManager.getService(EditorColorsManager.class); } diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java index 561e7782c715..8350f2fd9e08 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/AbstractColorsScheme.java @@ -903,6 +903,10 @@ public abstract class AbstractColorsScheme implements EditorColorsScheme, Serial return null; } + public EditorColorsScheme getParentScheme() { + return myParentScheme; + } + @NotNull @Override public Element writeScheme() { diff --git a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesActions.java b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesActions.java index f7f57eadcfdc..4f9ed8db0a21 100644 --- a/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesActions.java +++ b/platform/lang-impl/src/com/intellij/application/options/codeStyle/CodeStyleSchemesActions.java @@ -20,10 +20,6 @@ import com.intellij.application.options.schemes.AbstractSchemeActions; import com.intellij.application.options.schemes.AbstractSchemesPanel; import com.intellij.application.options.schemes.SchemeNameGenerator; import com.intellij.openapi.application.ApplicationBundle; -import com.intellij.openapi.application.WriteAction; -import com.intellij.openapi.fileChooser.FileChooserFactory; -import com.intellij.openapi.fileChooser.FileSaverDescriptor; -import com.intellij.openapi.fileChooser.FileSaverDialog; import com.intellij.openapi.options.*; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectUtil; @@ -31,13 +27,10 @@ import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileWrapper; import com.intellij.psi.codeStyle.CodeStyleScheme; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.OutputStream; - abstract class CodeStyleSchemesActions extends AbstractSchemeActions { private final static String SHARED_IMPORT_SOURCE = ApplicationBundle.message("import.scheme.shared"); @@ -181,52 +174,6 @@ abstract class CodeStyleSchemesActions extends AbstractSchemeActions exporter = SchemeExporterEP.getExporter(exporterName, CodeStyleScheme.class); - if (exporter != null) { - String ext = exporter.getExtension(); - FileSaverDialog saver = - FileChooserFactory.getInstance() - .createSaveFileDialog(new FileSaverDescriptor( - ApplicationBundle.message("scheme.exporter.ui.file.chooser.title"), - ApplicationBundle.message("scheme.exporter.ui.file.chooser.message"), - ext), getSchemesPanel()); - VirtualFileWrapper target = saver.save(null, scheme.getName() + "." + ext); - if (target != null) { - VirtualFile targetFile = target.getVirtualFile(true); - String message; - MessageType messageType; - if (targetFile != null) { - try { - WriteAction.run(() -> { - OutputStream outputStream = targetFile.getOutputStream(this); - try { - exporter.exportScheme(scheme, outputStream); - } - finally { - outputStream.close(); - } - }); - message = ApplicationBundle - .message("scheme.exporter.ui.code.style.exported.message", scheme.getName(), targetFile.getPresentableUrl()); - messageType = MessageType.INFO; - } - catch (Exception e) { - message = ApplicationBundle.message("scheme.exporter.ui.export.failed", e.getMessage()); - messageType = MessageType.ERROR; - } - } - else { - message = ApplicationBundle.message("scheme.exporter.ui.cannot.write.message"); - messageType = MessageType.ERROR; - } - getSchemesPanel().showStatus(message, messageType); - } - } - } - @NotNull @Override protected CodeStyleSchemesModel getModel() { diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java index 215a15ffa8d4..f11a7fb528d6 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java @@ -227,7 +227,7 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract public boolean saveSchemeAs(@NotNull EditorColorsScheme editorScheme, @NotNull String name) { if (editorScheme instanceof MyColorScheme) { MyColorScheme scheme = (MyColorScheme)editorScheme; - EditorColorsScheme clone = (EditorColorsScheme)scheme.getOriginalScheme().clone(); + EditorColorsScheme clone = (EditorColorsScheme)scheme.getParentScheme().clone(); scheme.apply(clone); if (clone instanceof AbstractColorsScheme) { ((AbstractColorsScheme)clone).setSaveNeeded(true); @@ -304,13 +304,13 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract List result = new ArrayList<>(mySchemes.values().size()); boolean activeSchemeModified = false; - EditorColorsScheme activeOriginalScheme = mySelectedScheme.getOriginalScheme(); + EditorColorsScheme activeOriginalScheme = mySelectedScheme.getParentScheme(); for (MyColorScheme scheme : mySchemes.values()) { boolean isModified = scheme.apply(); - if (isModified && !activeSchemeModified && activeOriginalScheme == scheme.getOriginalScheme()) { + if (isModified && !activeSchemeModified && activeOriginalScheme == scheme.getParentScheme()) { activeSchemeModified = true; } - result.add(scheme.getOriginalScheme()); + result.add(scheme.getParentScheme()); } // refresh only if scheme is not switched @@ -1194,11 +1194,6 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract return null; } - @NotNull - public EditorColorsScheme getOriginalScheme() { - return myParentScheme; - } - public void setIsNew() { myIsNew = true; } diff --git a/platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeActions.java b/platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeActions.java index ca8ac9192ae1..b3420ab56a34 100644 --- a/platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeActions.java +++ b/platform/lang-impl/src/com/intellij/application/options/colors/ColorSchemeActions.java @@ -21,13 +21,11 @@ import com.intellij.application.options.schemes.SchemeNameGenerator; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.impl.AbstractColorsScheme; +import com.intellij.openapi.editor.colors.impl.DefaultColorsScheme; import com.intellij.openapi.editor.colors.impl.EditorColorsSchemeImpl; import com.intellij.openapi.editor.colors.impl.EmptyColorScheme; import com.intellij.openapi.extensions.Extensions; -import com.intellij.openapi.options.SchemeImportException; -import com.intellij.openapi.options.SchemeImportUtil; -import com.intellij.openapi.options.SchemeImporter; -import com.intellij.openapi.options.SchemeImporterEP; +import com.intellij.openapi.options.*; import com.intellij.openapi.project.DefaultProjectFactory; import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; @@ -115,7 +113,18 @@ public abstract class ColorSchemeActions extends AbstractSchemeActions { + + private final static String[] FILE_EXTENSIONS = + new String[] {EditorColorsManager.COLOR_SCHEME_FILE_EXTENSION.substring(1)}; + + @NotNull + @Override + public String[] getSourceExtensions() { + return FILE_EXTENSIONS; + } + + @Nullable + @Override + public EditorColorsScheme importScheme(@NotNull Project project, + @NotNull VirtualFile selectedFile, + @NotNull EditorColorsScheme currentScheme, + @NotNull SchemeFactory schemeFactory) throws SchemeImportException { + Element root = SchemeImportUtil.loadSchemeDom(selectedFile); + String name = getSchemeName(root); + EditorColorsScheme scheme = schemeFactory.createNewScheme(name); + String preferredName = scheme.getName(); + scheme.readExternal(root); + scheme.setName(preferredName); + return scheme; + } + + private static String getSchemeName(@NotNull Element root) throws SchemeImportException { + String name = root.getAttributeValue("name"); + if (name == null) throw new SchemeImportException("Scheme 'name' attribute is missing."); + return name; + } + + + @Nullable + @Override + public String getAdditionalImportInfo(@NotNull EditorColorsScheme scheme) { + return null; + } +} diff --git a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java index 3b9b2cd74296..071957aad6d6 100644 --- a/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java +++ b/platform/lang-impl/src/com/intellij/application/options/schemes/AbstractSchemeActions.java @@ -17,13 +17,21 @@ package com.intellij.application.options.schemes; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ApplicationBundle; +import com.intellij.openapi.application.WriteAction; +import com.intellij.openapi.fileChooser.FileChooserFactory; +import com.intellij.openapi.fileChooser.FileSaverDescriptor; +import com.intellij.openapi.fileChooser.FileSaverDialog; import com.intellij.openapi.options.*; import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.ui.MessageType; import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileWrapper; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.io.OutputStream; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -369,7 +377,52 @@ public abstract class AbstractSchemeActions { * @see SchemeExporter * @see SchemeExporterEP */ - protected abstract void exportScheme(@NotNull T scheme, @NotNull String exporterName); + protected void exportScheme(@NotNull T scheme, @NotNull String exporterName) { + SchemeExporter exporter = SchemeExporterEP.getExporter(exporterName, getSchemeType()); + if (exporter != null) { + String ext = exporter.getExtension(); + FileSaverDialog saver = + FileChooserFactory.getInstance() + .createSaveFileDialog(new FileSaverDescriptor( + ApplicationBundle.message("scheme.exporter.ui.file.chooser.title"), + ApplicationBundle.message("scheme.exporter.ui.file.chooser.message"), + ext), getSchemesPanel()); + VirtualFileWrapper target = saver.save(null, SchemeManager.getDisplayName(scheme) + "." + ext); + if (target != null) { + VirtualFile targetFile = target.getVirtualFile(true); + String message; + MessageType messageType; + if (targetFile != null) { + try { + WriteAction.run(() -> { + OutputStream outputStream = targetFile.getOutputStream(this); + try { + exporter.exportScheme(scheme, outputStream); + } + finally { + outputStream.close(); + } + }); + message = ApplicationBundle + .message("scheme.exporter.ui.scheme.exported.message", + scheme.getName(), + getSchemesPanel().getSchemeTypeName(), + targetFile.getPresentableUrl()); + messageType = MessageType.INFO; + } + catch (Exception e) { + message = ApplicationBundle.message("scheme.exporter.ui.export.failed", e.getMessage()); + messageType = MessageType.ERROR; + } + } + else { + message = ApplicationBundle.message("scheme.exporter.ui.cannot.write.message"); + messageType = MessageType.ERROR; + } + getSchemesPanel().showStatus(message, messageType); + } + } + } /** * Make necessary configurable updates when another scheme has been selected. diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java index b9a48f6b464c..db6b2def8b9a 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSchemeXmlImporter.java @@ -20,6 +20,7 @@ import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.options.SchemeFactory; import com.intellij.openapi.options.SchemeImportException; +import com.intellij.openapi.options.SchemeImportUtil; import com.intellij.openapi.options.SchemeImporter; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Pair; @@ -49,7 +50,7 @@ public class CodeStyleSchemeXmlImporter extends CodeStyleSettingsLoader implemen @NotNull VirtualFile selectedFile, @NotNull CodeStyleScheme currentScheme, @NotNull SchemeFactory schemeFactory) throws SchemeImportException { - Element rootElement = loadSchemeDom(selectedFile); + Element rootElement = SchemeImportUtil.loadSchemeDom(selectedFile); Element schemeRoot = getSchemeRoot(rootElement); final Pair importPair = !ApplicationManager.getApplication().isUnitTestMode() ? diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java index ca137f3d4fbf..7e15d41fd691 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/codeStyle/CodeStyleSettingsLoader.java @@ -17,56 +17,22 @@ package com.intellij.psi.impl.source.codeStyle; import com.intellij.openapi.application.ApplicationBundle; import com.intellij.openapi.options.SchemeImportException; +import com.intellij.openapi.options.SchemeImportUtil; import com.intellij.openapi.util.InvalidDataException; -import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.codeStyle.CodeStyleSettings; -import org.jdom.Document; import org.jdom.Element; -import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; -import java.io.IOException; -import java.io.InputStream; - public class CodeStyleSettingsLoader { public CodeStyleSettings loadSettings(@NotNull VirtualFile file) throws SchemeImportException { - Element rootElement = loadSchemeDom(file); + Element rootElement = SchemeImportUtil.loadSchemeDom(file); CodeStyleSettings settings = new CodeStyleSettings(); loadSettings(rootElement, settings); return settings; } - @NotNull - protected static Element loadSchemeDom(@NotNull VirtualFile file) throws SchemeImportException { - InputStream inputStream = null; - try { - inputStream = file.getInputStream(); - final Document document = JDOMUtil.loadDocument(inputStream); - final Element root = document.getRootElement(); - inputStream.close(); - return root; - } - catch (IOException | JDOMException e) { - throw new SchemeImportException(getErrorMessage(e, file)); - } - finally { - if (inputStream != null) { - try { - inputStream.close(); - } - catch (IOException e) { - // ignore - } - } - } - } - - private static String getErrorMessage(@NotNull Exception e, @NotNull VirtualFile file) { - return "Can't read from" + file.getName() + ", " + e.getMessage(); - } - protected void loadSettings(@NotNull Element rootElement, @NotNull CodeStyleSettings settings) throws SchemeImportException { try { settings.readExternal(rootElement); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java index a83dbe01ee11..bc0128f710e7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/colors/impl/EditorColorsManagerImpl.java @@ -113,7 +113,7 @@ public class EditorColorsManagerImpl extends EditorColorsManager implements Pers @NonNls @Override public String getSchemeExtension() { - return ".icls"; + return COLOR_SCHEME_FILE_EXTENSION; } @Override diff --git a/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java b/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java index 56ec22b91606..553bb0864da7 100644 --- a/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java +++ b/platform/platform-impl/src/com/intellij/openapi/options/SchemeImportUtil.java @@ -19,11 +19,17 @@ import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.fileChooser.FileChooserDialog; import com.intellij.openapi.fileChooser.FileChooserFactory; import com.intellij.openapi.fileChooser.FileElement; +import com.intellij.openapi.util.JDOMUtil; import com.intellij.openapi.vfs.VirtualFile; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.awt.*; +import java.io.IOException; +import java.io.InputStream; import java.util.Arrays; import java.util.HashSet; import java.util.Set; @@ -67,5 +73,30 @@ public class SchemeImportUtil { virtualFiles[0].refresh(false, false); return virtualFiles[0]; } - + + @NotNull + public static Element loadSchemeDom(@NotNull VirtualFile file) throws SchemeImportException { + InputStream inputStream = null; + try { + inputStream = file.getInputStream(); + final Document document = JDOMUtil.loadDocument(inputStream); + final Element root = document.getRootElement(); + inputStream.close(); + return root; + } + catch (IOException | JDOMException e) { + throw new SchemeImportException("Can't read from" + file.getName() + ", " + e.getMessage()); + } + finally { + if (inputStream != null) { + try { + inputStream.close(); + } + catch (IOException e) { + // ignore + } + } + } + } + } diff --git a/platform/platform-resources-en/src/messages/ApplicationBundle.properties b/platform/platform-resources-en/src/messages/ApplicationBundle.properties index 405818f76add..d4a3e3386ecd 100644 --- a/platform/platform-resources-en/src/messages/ApplicationBundle.properties +++ b/platform/platform-resources-en/src/messages/ApplicationBundle.properties @@ -520,7 +520,7 @@ message.code.style.scheme.import.failure={0} import failed with error message: { scheme.exporter.ui.export.as.title=Export As scheme.exporter.ui.file.chooser.title=Target File scheme.exporter.ui.file.chooser.message=Export to -scheme.exporter.ui.code.style.exported.message={0} code style scheme was exported to {1} +scheme.exporter.ui.scheme.exported.message={0} {1} was exported to {2} scheme.exporter.ui.cannot.write.message=Cannot write to selected file/location. scheme.exporter.ui.export.failed=Export failed: {0} diff --git a/platform/platform-resources/src/META-INF/LangExtensions.xml b/platform/platform-resources/src/META-INF/LangExtensions.xml index 3222057a6ccb..c3ee99aa252e 100644 --- a/platform/platform-resources/src/META-INF/LangExtensions.xml +++ b/platform/platform-resources/src/META-INF/LangExtensions.xml @@ -984,10 +984,18 @@ name="Intellij IDEA code style XML" schemeClass="com.intellij.psi.codeStyle.CodeStyleScheme" implementationClass="com.intellij.application.options.schemes.SerializableSchemeExporter"/> + +