IDEA-42207: Ability to specify change list in the "Clear Read-only Status" dialog
authorDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Tue, 10 Jan 2012 15:53:51 +0000 (19:53 +0400)
committerDmitry Avdeev <Dmitry.Avdeev@jetbrains.com>
Wed, 11 Jan 2012 06:57:05 +0000 (10:57 +0400)
platform/platform-api/src/com/intellij/util/ui/OptionsDialog.java
platform/platform-impl/src/com/intellij/openapi/vcs/readOnlyHandler/HandleType.java
platform/platform-impl/src/com/intellij/openapi/vcs/readOnlyHandler/ReadOnlyStatusDialog.form
platform/platform-impl/src/com/intellij/openapi/vcs/readOnlyHandler/ReadOnlyStatusDialog.java
platform/platform-impl/src/com/intellij/openapi/vcs/readOnlyHandler/ReadonlyStatusHandlerImpl.java
platform/vcs-impl/src/com/intellij/openapi/vcs/readOnlyHandler/VcsHandleType.java

index 00d79f3d1f242ee8507408aa4809a9b4fcfeef19..76425e774f1650c2a7c94d07e7bbffa79a4f9eac 100644 (file)
@@ -19,15 +19,11 @@ import com.intellij.CommonBundle;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 
-import javax.swing.*;
 import java.awt.*;
 
 /**
  * author: lesya
- * 
- * @deprecated use one of {@link com.intellij.openapi.ui.Messages} methods instead.
  */
-@Deprecated
 public abstract class OptionsDialog extends DialogWrapper  {
 
   protected final Project myProject;
@@ -78,10 +74,6 @@ public abstract class OptionsDialog extends DialogWrapper  {
     setDoNotAskOption(new MyDoNotAsk());
   }
 
-  public static JPanel addDoNotShowCheckBox(JComponent southPanel, JCheckBox checkBox) {
-    return DialogWrapper.addDoNotShowCheckBox(southPanel, checkBox);
-  }
-
   public static boolean shiftIsPressed(int inputEventModifiers) {
     return (inputEventModifiers & Event.SHIFT_MASK) != 0;
   }
index 59cf6ec31634eb4cb813c3591a8299977737b8d1..b89d231716ab026ba1a4f3b96591ec8e0d9d7efb 100644 (file)
  */
 package com.intellij.openapi.vcs.readOnlyHandler;
 
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.vcs.VcsBundle;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.util.io.ReadOnlyAttributeUtil;
+import org.jetbrains.annotations.Nullable;
 
-import java.util.Collection;
 import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
 
 public abstract class HandleType {
   private final String myName;
   private final boolean myUseVcs;
 
   public static final HandleType USE_FILE_SYSTEM = new HandleType(VcsBundle.message("handle.ro.file.status.type.using.file.system"), false) {
-    public void processFiles(final Collection<VirtualFile> virtualFiles) {
+    public void processFiles(final Collection<VirtualFile> virtualFiles, String changelist) {
       ApplicationManager.getApplication().runWriteAction(new Runnable() {
         public void run() {
           try {
@@ -77,5 +80,14 @@ public abstract class HandleType {
     return result;
   }
 
-  public abstract void processFiles(final Collection<VirtualFile> virtualFiles);
+  public abstract void processFiles(final Collection<VirtualFile> virtualFiles, @Nullable String changelist);
+  
+  public List<String> getChangelists() {
+    return Collections.emptyList();
+  }
+  
+  @Nullable
+  public String getDefaultChangelist() {
+    return null;
+  }
 }
index b9593b95b5331b7b0bbf586f143b4951e5997336..d68194fa151dc801740d603674929e86425e6ccf 100644 (file)
@@ -3,7 +3,7 @@
   <grid id="27dc6" binding="myTopPanel" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
     <margin top="0" left="0" bottom="0" right="0"/>
     <constraints>
-      <xy x="20" y="20" width="500" height="400"/>
+      <xy x="20" y="20" width="443" height="400"/>
     </constraints>
     <properties/>
     <border type="none"/>
@@ -21,7 +21,7 @@
           </component>
         </children>
       </scrollpane>
-      <grid id="6f039" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
+      <grid id="6f039" layout-manager="GridLayoutManager" row-count="2" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
         <margin top="0" left="0" bottom="0" right="0"/>
         <constraints>
           <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
@@ -31,7 +31,9 @@
         <children>
           <component id="e80fa" class="javax.swing.JRadioButton" binding="myUsingFileSystemRadioButton" default-binding="true">
             <constraints>
-              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+              <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
+                <preferred-size width="175" height="22"/>
+              </grid>
             </constraints>
             <properties>
               <text value="Using &amp;file system"/>
           </component>
           <component id="72145" class="javax.swing.JRadioButton" binding="myUsingVcsRadioButton" default-binding="true">
             <constraints>
-              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
+              <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false">
+                <preferred-size width="175" height="22"/>
+              </grid>
             </constraints>
             <properties>
               <text value="Using &amp;version control integration"/>
             </properties>
           </component>
+          <component id="440b" class="javax.swing.JComboBox" binding="myChangelist">
+            <constraints>
+              <grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
+            </constraints>
+            <properties/>
+          </component>
+          <component id="9c196" class="com.intellij.ui.components.JBLabel">
+            <constraints>
+              <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="0" indent="0" use-parent-layout="false">
+                <preferred-size width="34" height="14"/>
+              </grid>
+            </constraints>
+            <properties>
+              <horizontalAlignment value="11"/>
+              <labelFor value="440b"/>
+              <text value="   Change &amp;list:"/>
+            </properties>
+          </component>
         </children>
       </grid>
     </children>
index 6c5c7c6f102a5b55a777a83611f10c13937765a2..5de2249cbb273d71b7c3e70ffa7d18bdd0b412ea 100644 (file)
@@ -1,32 +1,55 @@
 
 package com.intellij.openapi.vcs.readOnlyHandler;
 
-import com.intellij.openapi.vfs.ReadonlyStatusHandler;
-import com.intellij.util.ui.OptionsDialog;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.registry.Registry;
 import com.intellij.openapi.vcs.VcsBundle;
-import org.jetbrains.annotations.Nullable;
+import com.intellij.openapi.vfs.ReadonlyStatusHandler;
+import com.intellij.ui.CollectionComboBoxModel;
+import com.intellij.ui.HtmlListCellRenderer;
+import com.intellij.ui.SimpleTextAttributes;
+import com.intellij.util.ui.OptionsDialog;
+import com.intellij.util.ui.UIUtil;
 import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.Nullable;
 
 import javax.swing.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.List;
 
 /**
  * @author yole
  */
 public class ReadOnlyStatusDialog extends OptionsDialog {
+
+  static final SimpleTextAttributes BOLD_ATTRIBUTES = new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getListForeground());
+  static final SimpleTextAttributes SELECTED_BOLD_ATTRIBUTES =
+    new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, UIUtil.getListSelectionForeground());
+
   private JPanel myTopPanel;
   private JList myFileList;
   private JRadioButton myUsingFileSystemRadioButton;
   private JRadioButton myUsingVcsRadioButton;
+  private JComboBox myChangelist;
   private FileInfo[] myFiles;
 
   public ReadOnlyStatusDialog(Project project, final FileInfo[] files) {
     super(project);
     myFiles = files;
     initFileList();
+
+    ActionListener listener = new ActionListener() {
+      @Override
+      public void actionPerformed(ActionEvent e) {
+        myChangelist.setEnabled(myUsingVcsRadioButton.isSelected());
+      }
+    };
+    myUsingVcsRadioButton.addActionListener(listener);
+    myUsingFileSystemRadioButton.addActionListener(listener);
+    
     if (myUsingVcsRadioButton.isEnabled()) {
       myUsingVcsRadioButton.setSelected(true);
     }
@@ -59,10 +82,27 @@ public class ReadOnlyStatusDialog extends OptionsDialog {
     for(FileInfo info: myFiles) {
       if (info.hasVersionControl()) {
         hasVcs = true;
+        HandleType handleType = info.getSelectedHandleType();
+        List<String> changelists = handleType.getChangelists();
+        final String defaultChangelist = handleType.getDefaultChangelist();
+        myChangelist.setModel(new CollectionComboBoxModel(changelists, defaultChangelist));
+
+        myChangelist.setRenderer(new HtmlListCellRenderer<String>(myChangelist.getRenderer()) {
+          @Override
+          protected void doCustomize(JList list, String value, int index, boolean selected, boolean hasFocus) {
+            if (value.equals(defaultChangelist)) {
+              append(value, selected ? SELECTED_BOLD_ATTRIBUTES : BOLD_ATTRIBUTES);
+            }
+            else {
+              append(value, selected ? SimpleTextAttributes.SELECTED_SIMPLE_CELL_ATTRIBUTES : SimpleTextAttributes.SIMPLE_CELL_ATTRIBUTES);
+            }
+          }
+        }); 
+        
         break;
       }
     }
-    myUsingVcsRadioButton.setEnabled(hasVcs);    
+    myUsingVcsRadioButton.setEnabled(hasVcs);
   }
 
   protected boolean isToBeShown() {
@@ -102,7 +142,8 @@ public class ReadOnlyStatusDialog extends OptionsDialog {
 
     ArrayList<FileInfo> files = new ArrayList<FileInfo>();
     Collections.addAll(files, myFiles);
-    ReadonlyStatusHandlerImpl.processFiles(files);
+    String changelist = (String)myChangelist.getSelectedItem();
+    ReadonlyStatusHandlerImpl.processFiles(files, changelist);
 
     if (files.isEmpty()) {
       super.doOKAction();
index 1147457f8939a176058a1a9a38116f981e8d7bbe..1d7984b5fc046925ed1397f6dce08406b604b89f 100644 (file)
@@ -30,6 +30,7 @@ import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
 import gnu.trove.THashSet;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.*;
 
@@ -102,7 +103,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
       new ReadOnlyStatusDialog(myProject, fileInfos).show();
     }
     else {
-      processFiles(new ArrayList<FileInfo>(Arrays.asList(fileInfos))); // the collection passed is modified
+      processFiles(new ArrayList<FileInfo>(Arrays.asList(fileInfos)), null); // the collection passed is modified
     }
     IdeEventQueue.getInstance().setEventCount(savedEventCount);
     return createResultStatus(files);
@@ -131,7 +132,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
     return fileInfos.toArray(new FileInfo[fileInfos.size()]);
   }
 
-  public static void processFiles(final List<FileInfo> fileInfos) {
+  public static void processFiles(final List<FileInfo> fileInfos, @Nullable String changelist) {
     FileInfo[] copy = fileInfos.toArray(new FileInfo[fileInfos.size()]);
     MultiValuesMap<HandleType, VirtualFile> handleTypeToFile = new MultiValuesMap<HandleType, VirtualFile>();
     for (FileInfo fileInfo : copy) {
@@ -139,7 +140,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
     }
 
     for (HandleType handleType : handleTypeToFile.keySet()) {
-      handleType.processFiles(handleTypeToFile.get(handleType));
+      handleType.processFiles(handleTypeToFile.get(handleType), changelist == null ? handleType.getDefaultChangelist() : changelist);
     }
 
     for (FileInfo fileInfo : copy) {
@@ -169,7 +170,7 @@ public class ReadonlyStatusHandlerImpl extends ReadonlyStatusHandler implements
     @NotNull
     public String getReadonlyFilesMessage() {
       if (hasReadonlyFiles()) {
-        StringBuffer buf = new StringBuffer();
+        StringBuilder buf = new StringBuilder();
         if (myReadonlyFiles.length > 1) {
           for (VirtualFile file : myReadonlyFiles) {
             buf.append('\n');
index b65155584b16b5a75270887e37e23c577849dd9b..e92d6fe552c835be63a1b1998574320233b8afd3 100644 (file)
  */
 package com.intellij.openapi.vcs.readOnlyHandler;
 
+import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.openapi.application.ModalityState;
+import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.vcs.AbstractVcs;
+import com.intellij.openapi.vcs.EditFileProvider;
 import com.intellij.openapi.vcs.VcsBundle;
 import com.intellij.openapi.vcs.VcsException;
+import com.intellij.openapi.vcs.changes.Change;
+import com.intellij.openapi.vcs.changes.ChangeListManager;
+import com.intellij.openapi.vcs.changes.InvokeAfterUpdateMode;
+import com.intellij.openapi.vcs.changes.LocalChangeList;
 import com.intellij.openapi.vfs.VfsUtil;
 import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.ui.Messages;
-import com.intellij.openapi.application.ApplicationManager;
+import com.intellij.util.Function;
+import com.intellij.util.NullableFunction;
+import com.intellij.util.containers.ContainerUtil;
+import org.jetbrains.annotations.Nullable;
 
 import java.util.Collection;
+import java.util.List;
 
 /**
  * @author yole
  */
 public class VcsHandleType extends HandleType {
+  private static final Function<LocalChangeList,String> FUNCTION = new Function<LocalChangeList, String>() {
+    @Override
+    public String fun(LocalChangeList list) {
+      return list.getName();
+    }
+  };
   private final AbstractVcs myVcs;
+  private final ChangeListManager myChangeListManager;
+  private final Function<VirtualFile,Change> myChangeFunction;
 
   public VcsHandleType(AbstractVcs vcs) {
     super(VcsBundle.message("handle.ro.file.status.type.using.vcs", vcs.getDisplayName()), true);
     myVcs = vcs;
+    myChangeListManager = ChangeListManager.getInstance(myVcs.getProject());
+    myChangeFunction = new NullableFunction<VirtualFile, Change>() {
+      @Override
+      public Change fun(VirtualFile file) {
+        return myChangeListManager.getChange(file);
+      }
+    };
   }
 
-  public void processFiles(final Collection<VirtualFile> files) {
+  public void processFiles(final Collection<VirtualFile> files, @Nullable final String changelist) {
     try {
-      myVcs.getEditFileProvider().editFiles(VfsUtil.toVirtualFileArray(files));
+      EditFileProvider provider = myVcs.getEditFileProvider();
+      assert provider != null;
+      provider.editFiles(VfsUtil.toVirtualFileArray(files));
     }
     catch (VcsException e) {
       Messages.showErrorDialog(VcsBundle.message("message.text.cannot.edit.file", e.getLocalizedMessage()),
@@ -49,8 +77,29 @@ public class VcsHandleType extends HandleType {
         for (final VirtualFile file : files) {
           file.refresh(false, false);
         }
-
       }
     });
+    if (changelist != null) {
+      myChangeListManager.invokeAfterUpdate(new Runnable() {
+        @Override
+        public void run() {
+          LocalChangeList list = myChangeListManager.findChangeList(changelist);
+          if (list != null) {
+            List<Change> changes = ContainerUtil.mapNotNull(files, myChangeFunction);
+            myChangeListManager.moveChangesTo(list, changes.toArray(new Change[changes.size()]));
+          }
+        }
+      }, InvokeAfterUpdateMode.SILENT, "", ModalityState.NON_MODAL);
+    }
+  }
+
+  @Override
+  public List<String> getChangelists() {
+    return ContainerUtil.map(myChangeListManager.getChangeLists(), FUNCTION);
+  }
+
+  @Override
+  public String getDefaultChangelist() {
+    return myChangeListManager.getDefaultListName();
   }
 }
\ No newline at end of file