mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
CR-IC-2999 simplify API chooseFile — use native Mac OS X file chooser
This commit is contained in:
+15
-19
@@ -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<List<VirtualFile>>() {
|
||||
FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() {
|
||||
@Override
|
||||
public void consume(List<VirtualFile> 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<String> levels = new HashSet<String>();
|
||||
for (Object o : rootElement.getChildren("inspection_tool")) {
|
||||
@@ -161,7 +158,7 @@ public abstract class InspectionToolsConfigurable extends BaseConfigurable imple
|
||||
}
|
||||
for (Iterator<String> 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<List<VirtualFile>>() {
|
||||
FileChooser.chooseFile(descriptor, project, myWholePanel, null, new Consumer<VirtualFile>() {
|
||||
@Override
|
||||
public void consume(List<VirtualFile> 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);
|
||||
|
||||
@@ -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<VirtualFile>}, 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<VirtualFile> {
|
||||
protected void cancelled() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void consume(@NotNull VirtualFile file);
|
||||
}
|
||||
@@ -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<List<VirtualFile>>() {
|
||||
@Override
|
||||
public void consume(List<VirtualFile> files) {
|
||||
if (files.isEmpty()) {
|
||||
if (callback instanceof ChooseFileHandler) {
|
||||
((ChooseFileHandler)callback).cancelled();
|
||||
}
|
||||
else {
|
||||
callback.consume(null);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!files.isEmpty()) {
|
||||
callback.consume(files.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -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<VirtualFile>() {
|
||||
@Override
|
||||
public void consume(@NotNull VirtualFile virtualFile) {
|
||||
final File file = VfsUtilCore.virtualToIoFile(virtualFile);
|
||||
|
||||
Reference in New Issue
Block a user