From dda9d7dbb1d08e28a33d774d1383c2b2d792039f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 5 Nov 2013 12:22:55 +0100 Subject: [PATCH] =?UTF-8?q?CR-IC-2999=20simplify=20API=20chooseFile=20?= =?UTF-8?q?=E2=80=94=20use=20native=20Mac=20OS=20X=20file=20chooser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/InspectionToolsConfigurable.java | 34 ++++++++----------- .../fileChooser/ChooseFileHandler.java | 31 ----------------- .../openapi/fileChooser/FileChooser.java | 14 ++------ .../plugins/InstalledPluginsManagerMain.java | 4 +-- 4 files changed, 20 insertions(+), 63 deletions(-) delete mode 100644 platform/platform-api/src/com/intellij/openapi/fileChooser/ChooseFileHandler.java diff --git a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java index 0e36f2874c70..b6b66e96d5ab 100644 --- a/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java +++ b/platform/lang-impl/src/com/intellij/profile/codeInspection/ui/InspectionToolsConfigurable.java @@ -24,6 +24,7 @@ package com.intellij.profile.codeInspection.ui; import com.intellij.codeInsight.daemon.impl.HighlightInfoType; import com.intellij.codeInsight.daemon.impl.SeverityRegistrar; +import com.intellij.codeInspection.InspectionManager; import com.intellij.codeInspection.ModifiableModel; import com.intellij.codeInspection.ex.InspectionManagerEx; import com.intellij.codeInspection.ex.InspectionProfileImpl; @@ -42,24 +43,21 @@ import com.intellij.openapi.options.Configurable; import com.intellij.openapi.options.ConfigurationException; import com.intellij.openapi.options.SearchableConfigurable; import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.profile.Profile; import com.intellij.profile.ProfileManager; import com.intellij.profile.codeInspection.InspectionProfileManager; -import com.intellij.profile.codeInspection.InspectionProfileManagerImpl; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; import com.intellij.ui.ListCellRendererWrapper; import com.intellij.ui.components.JBScrollPane; import com.intellij.util.Alarm; import com.intellij.util.Consumer; import com.intellij.util.SystemProperties; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.HashMap; import org.jdom.Document; import org.jdom.Element; @@ -103,7 +101,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple public InspectionToolsConfigurable(@NotNull final InspectionProjectProfileManager projectProfileManager, InspectionProfileManager profileManager) { - ((InspectionManagerEx)InspectionManagerEx.getInstance(projectProfileManager.getProject())).buildInspectionSearchIndexIfNecessary(); + ((InspectionManagerEx)InspectionManager.getInstance(projectProfileManager.getProject())).buildInspectionSearchIndexIfNecessary(); myAddButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -139,17 +137,16 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple } }; descriptor.setDescription("Choose profile file"); - FileChooser.chooseFiles(descriptor, project, myWholePanel, null, new Consumer>() { + FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer() { @Override - public void consume(List files) { - final VirtualFile file = ContainerUtil.getFirstItem(files); + public void consume(VirtualFile file) { if (file == null) return; InspectionProfileImpl profile = new InspectionProfileImpl("TempProfile", InspectionToolRegistrar.getInstance(), myProfileManager); try { - Element rootElement = JDOMUtil.loadDocument(VfsUtil.virtualToIoFile(file)).getRootElement(); + Element rootElement = JDOMUtil.loadDocument(VfsUtilCore.virtualToIoFile(file)).getRootElement(); if (Comparing.strEqual(rootElement.getName(), "component")) {//import right from .idea/inspectProfiles/xxx.xml - rootElement = (Element)rootElement.getChildren().get(0); + rootElement = rootElement.getChildren().get(0); } final Set levels = new HashSet(); for (Object o : rootElement.getChildren("inspection_tool")) { @@ -161,7 +158,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple } for (Iterator iterator = levels.iterator(); iterator.hasNext(); ) { String level = iterator.next(); - if (((InspectionProfileManagerImpl)myProfileManager).getOwnSeverityRegistrar().getSeverity(level) != null) { + if (myProfileManager.getOwnSeverityRegistrar().getSeverity(level) != null) { iterator.remove(); } } @@ -169,13 +166,13 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple if (Messages.showYesNoDialog(myWholePanel, "Undefined severities detected: " + StringUtil.join(levels, ", ") + ". Do you want to create them?", "Warning", Messages.getWarningIcon()) == - DialogWrapper.OK_EXIT_CODE) { + Messages.YES) { for (String level : levels) { final TextAttributes textAttributes = CodeInsightColors.WARNINGS_ATTRIBUTES.getDefaultAttributes(); HighlightInfoType.HighlightInfoTypeImpl info = new HighlightInfoType.HighlightInfoTypeImpl(new HighlightSeverity(level, 50), com.intellij.openapi.editor.colors .TextAttributesKey.createTextAttributesKey(level)); - ((InspectionProfileManagerImpl)myProfileManager).getOwnSeverityRegistrar() + myProfileManager.getOwnSeverityRegistrar() .registerSeverity(new SeverityRegistrar.SeverityBasedTextAttributes(textAttributes.clone(), info), textAttributes.getErrorStripeColor()); } @@ -188,7 +185,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple if (Messages.showOkCancelDialog(myWholePanel, "Profile with name \'" + profile.getName() + "\' already exists. Do you want to overwrite it?", "Warning", - Messages.getInformationIcon()) != DialogWrapper.OK_EXIT_CODE) return; + Messages.getInformationIcon()) != Messages.OK) return; } final ModifiableModel model = profile.getModifiableModel(); model.setModified(true); @@ -215,11 +212,9 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple public void actionPerformed(ActionEvent e) { final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor(); descriptor.setDescription("Choose directory to store profile file"); - FileChooser.chooseFiles(descriptor, project, myWholePanel, null, new Consumer>() { + FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer() { @Override - public void consume(List files) { - final VirtualFile file = ContainerUtil.getFirstItem(files); - if (file == null) return; + public void consume(VirtualFile file) { final Element element = new Element("inspections"); try { final SingleInspectionProfilePanel panel = getSelectedPanel(); @@ -231,7 +226,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple if (new File(filePath).isFile()) { if (Messages .showOkCancelDialog(myWholePanel, "File \'" + filePath + "\' already exist. Do you want to overwrite it?", "Warning", - Messages.getQuestionIcon()) != DialogWrapper.OK_EXIT_CODE) return; + Messages.getQuestionIcon()) != Messages.OK) return; } JDOMUtil.writeDocument(new Document(element), filePath, SystemProperties.getLineSeparator()); } @@ -274,6 +269,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple final SingleInspectionProfilePanel panel = new SingleInspectionProfilePanel(myProjectProfileManager, modelName, model); myPanel.add(modelName, panel); if (!myPanels.containsKey(getProfilePrefix(model) + modelName)) { + //noinspection unchecked ((DefaultComboBoxModel)myProfiles.getModel()).addElement(model); } putProfile(model, panel); diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/ChooseFileHandler.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/ChooseFileHandler.java deleted file mode 100644 index 1300cf52c85b..000000000000 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/ChooseFileHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.openapi.fileChooser; - -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.util.Consumer; -import org.jetbrains.annotations.NotNull; - -/** - * You can use {@link Consumer}, but this class allows you to avoid null-check of passed file ({@link #cancelled()}) will be called in this case. - */ -public abstract class ChooseFileHandler implements Consumer { - protected void cancelled() { - } - - @Override - public abstract void consume(@NotNull VirtualFile file); -} \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooser.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooser.java index 35c5bed22b2c..65fdf5088dd6 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooser.java +++ b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooser.java @@ -245,7 +245,7 @@ public class FileChooser { * @param descriptor file chooser descriptor * @param project project * @param toSelect file to preselect - * @param callback callback will be invoked after user have closed dialog, see {@link com.intellij.openapi.fileChooser.ChooseFileHandler} + * @param callback callback will be invoked after user have selected file * @since 13 */ public static void chooseFile(@NotNull final FileChooserDescriptor descriptor, @@ -263,7 +263,7 @@ public class FileChooser { * @param project project * @param parent parent component * @param toSelect file to preselect - * @param callback callback will be invoked after user have closed dialog, see {@link com.intellij.openapi.fileChooser.ChooseFileHandler} + * @param callback callback will be invoked after user have selected file * @since 13 */ public static void chooseFile(@NotNull final FileChooserDescriptor descriptor, @@ -275,15 +275,7 @@ public class FileChooser { chooseFiles(descriptor, project, parent, toSelect, new Consumer>() { @Override public void consume(List files) { - if (files.isEmpty()) { - if (callback instanceof ChooseFileHandler) { - ((ChooseFileHandler)callback).cancelled(); - } - else { - callback.consume(null); - } - } - else { + if (!files.isEmpty()) { callback.consume(files.get(0)); } } diff --git a/platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsManagerMain.java b/platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsManagerMain.java index a50e33a48509..7e2f49951b2d 100644 --- a/platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsManagerMain.java +++ b/platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsManagerMain.java @@ -21,7 +21,6 @@ import com.intellij.ide.startup.StartupActionScriptManager; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.extensions.PluginId; -import com.intellij.openapi.fileChooser.ChooseFileHandler; import com.intellij.openapi.fileChooser.FileChooser; import com.intellij.openapi.fileChooser.FileChooserDescriptor; import com.intellij.openapi.options.ex.SingleConfigurableEditor; @@ -37,6 +36,7 @@ import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.SimpleTextAttributes; import com.intellij.util.ArrayUtilRt; +import com.intellij.util.Consumer; import com.intellij.util.Function; import com.intellij.util.ui.StatusText; import org.jetbrains.annotations.NotNull; @@ -84,7 +84,7 @@ public class InstalledPluginsManagerMain extends PluginManagerMain { }; descriptor.setTitle("Choose Plugin File"); descriptor.setDescription("JAR and ZIP archives are accepted"); - FileChooser.chooseFile(descriptor, null, myActionsPanel, null, new ChooseFileHandler() { + FileChooser.chooseFile(descriptor, null, myActionsPanel, null, new Consumer() { @Override public void consume(@NotNull VirtualFile virtualFile) { final File file = VfsUtilCore.virtualToIoFile(virtualFile);