P4 local changes refactoring. (2)
authorunknown <Irina.Chernushina@.Labs.IntelliJ.Net>
Fri, 23 Oct 2009 14:32:58 +0000 (18:32 +0400)
committerunknown <Irina.Chernushina@.Labs.IntelliJ.Net>
Fri, 23 Oct 2009 14:32:58 +0000 (18:32 +0400)
platform/vcs-api/src/com/intellij/openapi/vcs/changes/ChangeListManagerGate.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ChangeListWorker.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/local/AddList.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/pending/MockChangeListManagerGate.java

index 05e7e7ee94b7e1c4b0819127ac5601bf3e90b0b1..7a57e0206b18615b7f363bf6a14b7e3dd12c9df1 100644 (file)
@@ -36,5 +36,5 @@ public interface ChangeListManagerGate {
   void editName(final String oldName, final String newName);
   // must be allowed only for perforce change synchronizer, not during normal update
   void moveChanges(final String toList, final Collection<Change> changes);
-  void deleteIfEmpty(final String name);
+  void setListsToDisappear(final Collection<String> names);
 }
index a012c477b30647f5fffbe8efa876c01a89910f90..73397442fa3e7702c38ba61d154f33ef6d1eaf64 100644 (file)
@@ -47,6 +47,7 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
 
   private ChangeListsIndexes myIdx;
   private final ChangesDelta myDelta;
+  private final List<String> myListsToDisappear;
 
   public ChangeListWorker(final Project project, final PlusMinus<Pair<String, AbstractVcs>> deltaListener) {
     myProject = project;
@@ -56,6 +57,7 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
     mySwitchedHolder = new SwitchedFileHolder(project, FileHolder.HolderType.SWITCHED);
 
     myDelta = new ChangesDelta(project, deltaListener);
+    myListsToDisappear = new LinkedList<String>();
   }
 
   private ChangeListWorker(final ChangeListWorker worker) {
@@ -65,6 +67,7 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
     myLocallyDeleted = worker.myLocallyDeleted.copy();
     mySwitchedHolder = (SwitchedFileHolder) worker.mySwitchedHolder.copy();
     myDelta = worker.myDelta;
+    myListsToDisappear = new LinkedList<String>(worker.myListsToDisappear);
     
     LocalChangeList defaultList = null;
     for (LocalChangeList changeList : worker.myMap.values()) {
@@ -97,6 +100,9 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
     myMap.clear();
     myMap.putAll(worker.myMap);
     myDefault = worker.myDefault;
+
+    myListsToDisappear.clear();
+    myListsToDisappear.addAll(worker.myListsToDisappear);
     
     myDelta.step(myIdx, worker.myIdx);
     myIdx = new ChangeListsIndexes(worker.myIdx);
@@ -362,6 +368,14 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
       dispatcher.changeListChanged(changeList);
     }
     mySwitchedHolder.calculateChildren();
+
+    for (String name : myListsToDisappear) {
+      final LocalChangeList changeList = myMap.get(name);
+      if (changeList.getChanges().isEmpty()) {
+        removeChangeList(name);
+      }
+    }
+    myListsToDisappear.clear();
   }
 
   public List<LocalChangeList> getListsCopy() {
@@ -637,6 +651,10 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
     return changes;
   }
 
+  void setListsToDisappear(final Collection<String> names) {
+    myListsToDisappear.addAll(names);
+  }
+
   ChangeListManagerGate createSelfGate() {
     return new MyGate(this);
   }
@@ -682,11 +700,8 @@ public class ChangeListWorker implements ChangeListsWriteOperations {
       myWorker.moveChangesTo(toList, changes.toArray(new Change[changes.size()]));
     }
 
-    public void deleteIfEmpty(String name) {
-      final LocalChangeList list = myWorker.getCopyByName(name);
-      if ((list != null) && (list.getChanges().isEmpty()) && (! list.isDefault())) {
-        myWorker.removeChangeList(name);
-      }
+    public void setListsToDisappear(final Collection<String> names) {
+      myWorker.setListsToDisappear(names);
     }
   }
 }
index 728616a8d165259c8e723d473fed967b0a213220..81e03e949270e820ddd665218195ea682e17f3e1 100644 (file)
@@ -31,7 +31,11 @@ public class AddList implements ChangeListCommand {
   }
 
   public void apply(final ChangeListWorker worker) {
-    myNewListCopy = worker.addChangeList(myName, myComment);
+    if (! worker.findListByName(myName)) {
+      myNewListCopy = worker.addChangeList(myName, myComment);
+    } else {
+      worker.editComment(myName, myComment);
+    }
   }
 
   public void doNotify(final EventDispatcher<ChangeListListener> dispatcher) {
index c552ddb54c66ce9294a48504d34414ca3794693f..43366b4fff16b4f7f6b75c32852ab5a2c2c0bbb1 100644 (file)
@@ -65,10 +65,6 @@ public class MockChangeListManagerGate implements ChangeListManagerGate {
     }
   }
 
-  public void deleteIfEmpty(String name) {
-    final LocalChangeList changeList = myManager.findChangeList(name);
-    if ((changeList != null) && (changeList.getChanges().isEmpty())) {
-      myManager.removeChangeList(name);
-    }
+  public void setListsToDisappear(Collection<String> names) {
   }
 }