TreeComboBox + NativeMacFileChooserDialog in slide mode for any heavy dialog
authorAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 17 Aug 2010 14:41:38 +0000 (18:41 +0400)
committerAlexey Pegov <alexey.pegov@jetbrains.com>
Tue, 17 Aug 2010 14:41:38 +0000 (18:41 +0400)
platform/platform-api/src/com/intellij/openapi/ui/ComponentWithBrowseButton.java
platform/platform-api/src/com/intellij/openapi/ui/TreeComboBox.java
platform/platform-impl/src/com/intellij/openapi/project/ex/ProjectEx.java
platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectImpl.java
platform/platform-impl/src/com/intellij/ui/mac/MacFileChooserDialogImpl.java
platform/platform-resources/src/idea/PlatformActions.xml
resources/src/idea/IdeaActions.xml

index 9e7943e7a8d33e85c3b14e91b2ccc1dd3efbae51..cf50b004d23eaa7b045a6db6d894a5602a20bbad 100644 (file)
@@ -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<Comp extends JComponent> 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<VirtualFile[]>() {
+        @Override
+        public void consume(VirtualFile[] virtualFiles) {
+          if (virtualFiles != null && virtualFiles.length > 0) {
+            onFileChoosen(virtualFiles[0]);
+          }
+        }
+      });
     }
 
     @Nullable
@@ -233,14 +239,6 @@ public class ComponentWithBrowseButton<Comp extends JComponent> 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() {
index 1339698cb73b4fabd2e2c840f5e451fba2cddcee..8e79587d20648de3746e8c40b274880069483a58 100644 (file)
@@ -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");
 
index 21bc05e604374f5e73366b1731ba38af023bf5f8..0787795beda1d49199ec557d962530ee438ebf41 100644 (file)
@@ -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<ProjectSaved> TOPIC = Topic.create("SaveProjectTopic", ProjectSaved.class, Topic.BroadcastDirection.NONE);
+    void saved(@NotNull final Project project);
+  }
 
   @NotNull
   IProjectStore getStateStore();
index 542c37501cca78b33398355042e421182a5a8ebc..7d4fd37606feacea6d01993b5076df5e5b227df4 100644 (file)
@@ -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);
       }
     }
   }
index cd29df86201383c7e166e28b9d93d2903bcae012..2ca398b2b819ac12e20825f0f39901f2cae6a804 100644 (file)
@@ -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) {
index 5f89db231ef478ca69d4ffb44fb29e725500fae1..3c5b8ce9c23b501a7debc6674d7ab1152a48c091 100644 (file)
               text="Add Test Notification"/>
       <action id="TestMessageBoxAction" internal="true" class="com.intellij.diagnostic.TestMessageBoxAction" text="Show Test Dialog"/>
       <separator/>
+      <action id="FocusDebugger" internal="true" class="com.intellij.internal.focus.FocusDebuggerAction" text="Start Focus Debugger"/>
+      <action id="UiInspector" internal="true" class="com.intellij.internal.inspector.UiInspectorAction" text="UI Inspector"/>
+      <separator/>
       <reference ref="MaintenanceGroup"/>
-      
+
       <add-to-group group-id="ToolsMenu" anchor="last"/>
     </group>
 
index c34d1bd9065784ce56fc822a2a006c4642ab8be8..6e9373e393e893e8f174b6d32ca16aa513c47760 100644 (file)
       <separator/>
       <action id="GenerateVisitorByHierarchy" internal="true" class="com.intellij.internal.GenerateVisitorByHierarchyAction" text="Generate Hierarchy Visitor"/>
       <separator/>
-      <action id="FocusDebugger" internal="true" class="com.intellij.internal.focus.FocusDebuggerAction" text="Start Focus Debugger"/>
-      <action id="UiInspector" internal="true" class="com.intellij.internal.inspector.UiInspectorAction" text="UI Inspector"/>
-      <separator/>
       <action id="DumpLookupElementWeights" internal="true" class="com.intellij.internal.DumpLookupElementWeights" text="Dump lookup element weights"/>
       <action id="CheckVfsSanity" internal="true" class="com.intellij.openapi.vfs.newvfs.persistent.CheckSanityAction" text="Check VFS sanity"/>