From 61e94d85329d5e8d5255b12c733c191f644a98a2 Mon Sep 17 00:00:00 2001 From: Alexey Pegov Date: Tue, 17 Aug 2010 18:41:38 +0400 Subject: [PATCH] TreeComboBox + NativeMacFileChooserDialog in slide mode for any heavy dialog --- .../openapi/ui/ComponentWithBrowseButton.java | 22 +++++++++---------- .../com/intellij/openapi/ui/TreeComboBox.java | 10 ++++++--- .../openapi/project/ex/ProjectEx.java | 5 +++++ .../openapi/project/impl/ProjectImpl.java | 2 +- .../ui/mac/MacFileChooserDialogImpl.java | 15 ++++++++++--- .../src/idea/PlatformActions.xml | 5 ++++- resources/src/idea/IdeaActions.xml | 3 --- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java index 9e7943e7a8d3..cf50b004d23e 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java @@ -30,6 +30,7 @@ import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.UIBundle; +import com.intellij.util.Consumer; import com.intellij.util.ui.update.LazyUiDisposable; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -204,10 +205,15 @@ public class ComponentWithBrowseButton extends JPanel i fileChooserDescriptor.setDescription(myDescription); } VirtualFile initialFile = getInitialFile(); - VirtualFile[] files = doChoose(fileChooserDescriptor, initialFile); - if (files != null && files.length != 0) { - onFileChoosen(files[0]); - } + + FileChooser.chooseFilesWithSlideEffect(fileChooserDescriptor, myProject, initialFile, new Consumer() { + @Override + public void consume(VirtualFile[] virtualFiles) { + if (virtualFiles != null && virtualFiles.length > 0) { + onFileChoosen(virtualFiles[0]); + } + } + }); } @Nullable @@ -233,14 +239,6 @@ public class ComponentWithBrowseButton extends JPanel i myAccessor.setText(myTextComponent.getChildComponent(), chosenFile.getPresentableUrl()); } - private VirtualFile[] doChoose(FileChooserDescriptor fileChooserDescriptor, VirtualFile initialFile) { - if (myProject == null) { - return FileChooser.chooseFiles(myTextComponent, fileChooserDescriptor, initialFile); - } - else { - return FileChooser.chooseFiles(myProject, fileChooserDescriptor, initialFile); - } - } } public final void requestFocus() { diff --git a/platform/platform-api/src/com/intellij/openapi/ui/TreeComboBox.java b/platform/platform-api/src/com/intellij/openapi/ui/TreeComboBox.java index 1339698cb73b..8e79587d2064 100644 --- a/platform/platform-api/src/com/intellij/openapi/ui/TreeComboBox.java +++ b/platform/platform-api/src/com/intellij/openapi/ui/TreeComboBox.java @@ -24,7 +24,6 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import javax.swing.border.Border; -import javax.swing.tree.DefaultTreeCellRenderer; import javax.swing.tree.TreeModel; import javax.swing.tree.TreePath; import java.awt.*; @@ -36,14 +35,19 @@ import java.util.Enumeration; */ public class TreeComboBox extends JComboBox { final static int INDENT = UIManager.getInt("Tree.leftChildIndent"); + private TreeModel myTreeModel; public TreeComboBox(@NotNull final TreeModel model) { - setModel(new TreeModelWrapper(model)); + myTreeModel = model; + setModel(new TreeModelWrapper(myTreeModel)); setRenderer(new TreeListCellRenderer(this, model)); - setSelectedIndex(0); if (SystemInfo.isMac) setMaximumRowCount(25); } + public TreeModel getTreeModel() { + return myTreeModel; + } + private static class TreeListCellRenderer extends JLabel implements ListCellRenderer { private static final Border SELECTION_PAINTER = (Border)UIManager.get("MenuItem.selectedBackgroundPainter"); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java index 21bc05e60437..0787795beda1 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java @@ -17,9 +17,14 @@ package com.intellij.openapi.project.ex; import com.intellij.openapi.components.impl.stores.IProjectStore; import com.intellij.openapi.project.Project; +import com.intellij.util.messages.Topic; import org.jetbrains.annotations.NotNull; public interface ProjectEx extends Project { + interface ProjectSaved { + Topic TOPIC = Topic.create("SaveProjectTopic", ProjectSaved.class, Topic.BroadcastDirection.NONE); + void saved(@NotNull final Project project); + } @NotNull IProjectStore getStateStore(); diff --git a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java index 542c37501cca..7d4fd37606fe 100644 --- a/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java @@ -55,7 +55,6 @@ import org.picocontainer.defaults.CachingComponentAdapter; import org.picocontainer.defaults.ConstructorInjectionComponentAdapter; import java.io.IOException; -import java.text.MessageFormat; import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; @@ -267,6 +266,7 @@ public class ProjectImpl extends ComponentManagerImpl implements ProjectEx { LOG.info("Error saving project", e); } finally { mySavingInProgress.set(false); + ApplicationManager.getApplication().getMessageBus().syncPublisher(ProjectSaved.TOPIC).saved(this); } } } diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java b/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java index cd29df862013..2ca398b2b819 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java @@ -115,8 +115,14 @@ public class MacFileChooserDialogImpl implements MacFileChooserDialog { if (mySheetCallback != null) { final Window activeWindow = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - if (activeWindow != null && activeWindow instanceof Frame) { - final String frameTitle = ((Frame)activeWindow).getTitle(); + if (activeWindow != null) { + String activeWindowTitle = null; + if (activeWindow instanceof Frame) { + activeWindowTitle = ((Frame)activeWindow).getTitle(); + } else if (activeWindow instanceof JDialog) { + activeWindowTitle = ((JDialog)activeWindow).getTitle(); + } + if (activeWindowTitle == null || activeWindowTitle.length() == 0) return; final ID sharedApplication = invoke("NSApplication", "sharedApplication"); final ID windows = invoke(sharedApplication, "windows"); @@ -130,7 +136,10 @@ public class MacFileChooserDialogImpl implements MacFileChooserDialog { final ID windowTitle = invoke(window, "title"); final String titleString = Foundation.toStringViaUTF8(windowTitle); - if (titleString.equals(frameTitle)) focusedWindow = window; + if (titleString.equals(activeWindowTitle)) { + focusedWindow = window; + break; + } } if (focusedWindow != null) { diff --git a/platform/platform-resources/src/idea/PlatformActions.xml b/platform/platform-resources/src/idea/PlatformActions.xml index 5f89db231ef4..3c5b8ce9c23b 100644 --- a/platform/platform-resources/src/idea/PlatformActions.xml +++ b/platform/platform-resources/src/idea/PlatformActions.xml @@ -430,8 +430,11 @@ text="Add Test Notification"/> + + + - + diff --git a/resources/src/idea/IdeaActions.xml b/resources/src/idea/IdeaActions.xml index c34d1bd90657..6e9373e393e8 100644 --- a/resources/src/idea/IdeaActions.xml +++ b/resources/src/idea/IdeaActions.xml @@ -255,9 +255,6 @@ - - -