combobox with browse button with path completion; recent manager to be used (IDEA...
authorAnna Kozlova <anna.kozlova@jetbrains.com>
Mon, 23 Jan 2012 16:47:52 +0000 (20:47 +0400)
committerAnna Kozlova <anna.kozlova@jetbrains.com>
Mon, 23 Jan 2012 17:03:43 +0000 (21:03 +0400)
platform/lang-impl/src/com/intellij/refactoring/copy/CopyFilesOrDirectoriesDialog.java
platform/lang-impl/src/com/intellij/refactoring/move/moveFilesOrDirectories/MoveFilesOrDirectoriesDialog.java
platform/platform-api/src/com/intellij/ui/TextFieldWithHistoryWithBrowseButton.java [new file with mode: 0644]

index 4a2be96f500aceab3ec17158c72cfb441a6f854b..41d7a8c36af06eefd38f4d4d42c4c38991272355 100644 (file)
@@ -19,18 +19,22 @@ package com.intellij.refactoring.copy;
 import com.intellij.ide.util.DirectoryUtil;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.command.CommandProcessor;
+import com.intellij.openapi.fileChooser.FileChooserDescriptor;
 import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
 import com.intellij.openapi.help.HelpManager;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
+import com.intellij.openapi.ui.TextComponentAccessor;
 import com.intellij.openapi.ui.impl.DialogWrapperPeerImpl;
 import com.intellij.psi.PsiDirectory;
 import com.intellij.psi.PsiElement;
 import com.intellij.psi.PsiFile;
 import com.intellij.psi.PsiManager;
 import com.intellij.refactoring.RefactoringBundle;
-import com.intellij.ui.*;
+import com.intellij.ui.DocumentAdapter;
+import com.intellij.ui.RecentsManager;
+import com.intellij.ui.TextFieldWithHistoryWithBrowseButton;
 import com.intellij.util.IncorrectOperationException;
 import org.jetbrains.annotations.NonNls;
 
@@ -39,10 +43,11 @@ import javax.swing.event.DocumentEvent;
 import javax.swing.event.DocumentListener;
 import java.awt.*;
 import java.io.File;
+import java.util.List;
 
 class CopyFilesOrDirectoriesDialog extends DialogWrapper{
   private JLabel myInformationLabel;
-  private EditorComboWithBrowseButton myTargetDirectoryField;
+  private TextFieldWithHistoryWithBrowseButton myTargetDirectoryField;
   private JTextField myNewNameField;
   private final Project myProject;
   private final boolean myShowDirectoryField;
@@ -95,7 +100,7 @@ class CopyFilesOrDirectoriesDialog extends DialogWrapper{
     }
 
     if (myShowDirectoryField) {
-      myTargetDirectoryField.prependItem(defaultTargetDirectory == null ? "" : defaultTargetDirectory.getVirtualFile().getPresentableUrl());
+      myTargetDirectoryField.getChildComponent().setText(defaultTargetDirectory == null ? "" : defaultTargetDirectory.getVirtualFile().getPresentableUrl());
     }
     validateOKButton();
   }
@@ -163,18 +168,24 @@ class CopyFilesOrDirectoriesDialog extends DialogWrapper{
     if (myShowDirectoryField) {
       panel.add(new JLabel(RefactoringBundle.message("copy.files.to.directory.label")), new GridBagConstraints(0,2,1,1,0,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(4,8,4,8),0,0));
 
-      myTargetDirectoryField = new EditorComboWithBrowseButton(null, "", myProject,
-                                                               RECENT_KEYS);
+      myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
+      final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
+      
+      if (recentEntries != null) {
+        myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
+      }
+      final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
       myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                                             RefactoringBundle.message("the.file.will.be.copied.to.this.directory"),
-                                                                            myProject, FileChooserDescriptorFactory.createSingleFolderDescriptor(),
-                                                                            EditorComboBox.COMPONENT_ACCESSOR);
+                                                                            myProject, descriptor,
+                                                                            TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
+      
       myTargetDirectoryField.setTextFieldPreferredWidth(60);
       panel.add(myTargetDirectoryField, new GridBagConstraints(1,2,1,1,1,0,GridBagConstraints.WEST,GridBagConstraints.HORIZONTAL,new Insets(4,0,4,8),0,0));
 
-      myTargetDirectoryField.getChildComponent().getDocument().addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
+      myTargetDirectoryField.getChildComponent().addDocumentListener(new DocumentAdapter() {
         @Override
-        public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
+        protected void textChanged(DocumentEvent e) {
           validateOKButton();
         }
       });
@@ -202,7 +213,7 @@ class CopyFilesOrDirectoriesDialog extends DialogWrapper{
     }
 
     if (myShowDirectoryField) {
-      final String targetDirectoryName = myTargetDirectoryField.getText();
+      final String targetDirectoryName = myTargetDirectoryField.getChildComponent().getText();
 
       if (targetDirectoryName.length() == 0) {
         Messages.showMessageDialog(myProject, RefactoringBundle.message("no.target.directory.specified"), RefactoringBundle.message("error.title"), Messages.getErrorIcon());
@@ -236,7 +247,7 @@ class CopyFilesOrDirectoriesDialog extends DialogWrapper{
 
   private void validateOKButton() {
     if (myShowDirectoryField) {
-      if (myTargetDirectoryField.getText().length() == 0) {
+      if (myTargetDirectoryField.getChildComponent().getText().length() == 0) {
         setOKActionEnabled(false);
         return;
       }
index 0c00a68dc00a6264ecb4edc5c47b1e96542bc0b0..395f8a5fd4cdde865edf877114f1f6535e881a8c 100644 (file)
@@ -27,7 +27,6 @@ import com.intellij.openapi.fileChooser.FileChooserFactory;
 import com.intellij.openapi.help.HelpManager;
 import com.intellij.openapi.keymap.KeymapUtil;
 import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.ComponentWithBrowseButton;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.TextComponentAccessor;
 import com.intellij.openapi.util.Disposer;
@@ -40,6 +39,8 @@ import com.intellij.refactoring.RefactoringSettings;
 import com.intellij.refactoring.util.CommonRefactoringUtil;
 import com.intellij.ui.DocumentAdapter;
 import com.intellij.ui.NonFocusableCheckBox;
+import com.intellij.ui.RecentsManager;
+import com.intellij.ui.TextFieldWithHistoryWithBrowseButton;
 import com.intellij.util.IncorrectOperationException;
 import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NonNls;
@@ -48,6 +49,7 @@ import javax.swing.*;
 import javax.swing.event.DocumentEvent;
 import java.awt.*;
 import java.io.File;
+import java.util.List;
 
 public class MoveFilesOrDirectoriesDialog extends DialogWrapper{
   @NonNls private static final String RECENT_KEYS = "MoveFile.RECENT_KEYS";
@@ -57,7 +59,7 @@ public class MoveFilesOrDirectoriesDialog extends DialogWrapper{
   }
 
   private JLabel myNameLabel;
-  private ComponentWithBrowseButton<JTextField> myTargetDirectoryField;
+  private TextFieldWithHistoryWithBrowseButton myTargetDirectoryField;
   private String myHelpID;
   private final Project myProject;
   private final Callback myCallback;
@@ -99,14 +101,18 @@ public class MoveFilesOrDirectoriesDialog extends DialogWrapper{
     panel.add(new JLabel(RefactoringBundle.message("move.files.to.directory.label")), c);
     c.insets.top = 0;
     
-    myTargetDirectoryField = new ComponentWithBrowseButton<JTextField>(new JTextField(), null);
+    myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
+    final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
+    if (recentEntries != null) {
+      myTargetDirectoryField.getChildComponent().setHistory(recentEntries);
+    }
     final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
     myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"),
                                                    RefactoringBundle.message("the.file.will.be.moved.to.this.directory"),
                                                    myProject,
                                                    descriptor,
-                                                   TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
-    final JTextField textField = myTargetDirectoryField.getChildComponent();
+                                                   TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
+    final JTextField textField = myTargetDirectoryField.getChildComponent().getTextEditor();
     FileChooserFactory.getInstance().installFileCompletion(textField, descriptor, true, getDisposable());
     myTargetDirectoryField.setTextFieldPreferredWidth(60);
     c.insets.left = 0;
@@ -180,6 +186,7 @@ public class MoveFilesOrDirectoriesDialog extends DialogWrapper{
 
   protected void doOKAction() {
     //myTargetDirectoryField.getChildComponent().addCurrentTextToHistory();
+    RecentsManager.getInstance(myProject).registerRecentEntry(RECENT_KEYS, myTargetDirectoryField.getChildComponent().getText());
     RefactoringSettings.getInstance().MOVE_SEARCH_FOR_REFERENCES_FOR_FILE = myCbSearchForReferences.isSelected();
     CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
       public void run() {
diff --git a/platform/platform-api/src/com/intellij/ui/TextFieldWithHistoryWithBrowseButton.java b/platform/platform-api/src/com/intellij/ui/TextFieldWithHistoryWithBrowseButton.java
new file mode 100644 (file)
index 0000000..9534bf0
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2000-2012 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.ui;
+
+import com.intellij.openapi.fileChooser.FileChooserDescriptor;
+import com.intellij.openapi.fileChooser.FileChooserFactory;
+import com.intellij.openapi.project.Project;
+import com.intellij.openapi.ui.ComponentWithBrowseButton;
+import com.intellij.openapi.ui.TextComponentAccessor;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * User: anna
+ */
+public class TextFieldWithHistoryWithBrowseButton extends ComponentWithBrowseButton<TextFieldWithHistory> {
+  public TextFieldWithHistoryWithBrowseButton() {
+    super(new TextFieldWithHistory(), null);
+  }
+
+  @Override
+  public void addBrowseFolderListener(@Nullable String title,
+                                      @Nullable String description,
+                                      @Nullable Project project,
+                                      FileChooserDescriptor fileChooserDescriptor,
+                                      TextComponentAccessor<TextFieldWithHistory> accessor) {
+    super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor);
+    FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
+  }
+
+  @Override
+  public void addBrowseFolderListener(@Nullable String title,
+                                      @Nullable String description,
+                                      @Nullable Project project,
+                                      FileChooserDescriptor fileChooserDescriptor,
+                                      TextComponentAccessor<TextFieldWithHistory> accessor,
+                                      boolean autoRemoveOnHide) {
+    super.addBrowseFolderListener(title, description, project, fileChooserDescriptor, accessor, autoRemoveOnHide);
+    FileChooserFactory.getInstance().installFileCompletion(getChildComponent().getTextEditor(), fileChooserDescriptor, false, project);
+  }
+}