CreatePatchCommitExecutor — do not save defaults appcode/171.731 clion/171.732 phpstorm/171.730
authorVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 4 Nov 2016 10:57:01 +0000 (11:57 +0100)
committerVladimir Krivosheev <vladimir.krivosheev@jetbrains.com>
Fri, 4 Nov 2016 10:59:22 +0000 (11:59 +0100)
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/ApplyPatchAction.java
platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java

index aa7ba1c3c9227d4e85c4b5a02f13d51af699d4ae..a83fc995217f7502dbacf33de3c11560b2f777ae 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2016 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.
@@ -43,7 +43,6 @@ import com.intellij.openapi.util.Computable;
 import com.intellij.openapi.util.Condition;
 import com.intellij.openapi.util.Getter;
 import com.intellij.openapi.util.Ref;
-import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.VcsApplicationSettings;
 import com.intellij.openapi.vcs.VcsBundle;
@@ -110,7 +109,7 @@ public class ApplyPatchAction extends DumbAwareAction {
         public void consume(VirtualFile file) {
           final VirtualFile parent = file.getParent();
           if (parent != null) {
-            settings.PATCH_STORAGE_LOCATION = FileUtil.toSystemDependentName(parent.getPath());
+            settings.PATCH_STORAGE_LOCATION = parent.getPath();
           }
           showApplyPatch(project, file);
         }
index 5980fa9d44ae24a81724e46b5320200103cf0da6..b59a8a70bdad7c6aadb8949596204f3e691eb9f1 100644 (file)
@@ -18,6 +18,7 @@ package com.intellij.openapi.vcs.changes.patch;
 
 import com.intellij.CommonBundle;
 import com.intellij.ide.actions.ShowFilePathAction;
+import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.lifecycle.PeriodicalTasksCloser;
 import com.intellij.openapi.application.ModalityState;
 import com.intellij.openapi.application.PathManager;
@@ -30,10 +31,8 @@ import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.ValidationInfo;
-import com.intellij.openapi.util.DefaultJDOMExternalizer;
-import com.intellij.openapi.util.InvalidDataException;
-import com.intellij.openapi.util.JDOMExternalizable;
-import com.intellij.openapi.util.WriteExternalException;
+import com.intellij.openapi.util.io.FileUtil;
+import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.openapi.vcs.AbstractVcs;
 import com.intellij.openapi.vcs.VcsApplicationSettings;
 import com.intellij.openapi.vcs.VcsBundle;
@@ -44,7 +43,6 @@ import com.intellij.openapi.vcs.changes.ui.SessionDialog;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.util.WaitForProgressToShow;
 import com.intellij.vcsUtil.VcsUtil;
-import org.jdom.Element;
 import org.jetbrains.annotations.Nls;
 import org.jetbrains.annotations.NonNls;
 import org.jetbrains.annotations.NotNull;
@@ -56,14 +54,13 @@ import java.util.Collection;
 import java.util.List;
 import java.util.Set;
 
-public class CreatePatchCommitExecutor extends LocalCommitExecutor implements ProjectComponent, JDOMExternalizable {
+public class CreatePatchCommitExecutor extends LocalCommitExecutor implements ProjectComponent {
   private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.patch.CreatePatchCommitExecutor");
+  private static final String VCS_PATCH_PATH_KEY = "vcs.patch.path";
 
   private final Project myProject;
   private final ChangeListManager myChangeListManager;
 
-  public String PATCH_PATH = "";
-
   public static CreatePatchCommitExecutor getInstance(Project project) {
     return PeriodicalTasksCloser.getInstance().safeGetComponent(project, CreatePatchCommitExecutor.class);
   }
@@ -114,16 +111,6 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
   public void disposeComponent() {
   }
 
-  @Override
-  public void readExternal(Element element) throws InvalidDataException {
-    DefaultJDOMExternalizer.readExternal(this, element);
-  }
-
-  @Override
-  public void writeExternal(Element element) throws WriteExternalException {
-    DefaultJDOMExternalizer.writeExternal(this, element);
-  }
-
   private class CreatePatchCommitSession implements CommitSession, CommitSessionContextAware {
     private final CreatePatchConfigurationPanel myPanel = new CreatePatchConfigurationPanel(myProject);
     private CommitContext myCommitContext;
@@ -144,14 +131,14 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
 
     @Override
     public JComponent getAdditionalConfigurationUI(final Collection<Change> changes, final String commitMessage) {
-      if (PATCH_PATH.length() == 0) {
-        VcsApplicationSettings settings = VcsApplicationSettings.getInstance();
-        PATCH_PATH = settings.PATCH_STORAGE_LOCATION;
-        if (PATCH_PATH == null) {
-          PATCH_PATH = myProject.getBaseDir() == null ? PathManager.getHomePath() : myProject.getBaseDir().getPresentableUrl();
+      String patchPath = StringUtil.nullize(PropertiesComponent.getInstance(myProject).getValue(VCS_PATCH_PATH_KEY));
+      if (patchPath == null) {
+        patchPath = VcsApplicationSettings.getInstance().PATCH_STORAGE_LOCATION;
+        if (patchPath == null) {
+          patchPath = getDefaultPatchPath();
         }
       }
-      myPanel.setFileName(ShelveChangesManager.suggestPatchName(myProject, commitMessage, new File(PATCH_PATH), null));
+      myPanel.setFileName(ShelveChangesManager.suggestPatchName(myProject, commitMessage, new File(patchPath), null));
       File commonAncestor = ChangesUtil.findCommonAncestor(changes);
       myPanel.setCommonParentPath(commonAncestor);
       Set<AbstractVcs> affectedVcses = ChangesUtil.getAffectedVcses(changes, myProject);
@@ -198,8 +185,10 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
         //noinspection ResultOfMethodCallIgnored
         file.getParentFile().mkdirs();
         VcsConfiguration.getInstance(myProject).acceptLastCreatedPatchName(file.getName());
-        PATCH_PATH = file.getParent();
-        VcsApplicationSettings.getInstance().PATCH_STORAGE_LOCATION = PATCH_PATH;
+        String patchPath = FileUtil.toSystemIndependentName(StringUtil.notNullize(file.getParent()));
+        String valueToStore = StringUtil.isEmpty(patchPath) || patchPath.equals(getDefaultPatchPath()) ? null : patchPath;
+        PropertiesComponent.getInstance(myProject).setValue(VCS_PATCH_PATH_KEY, valueToStore);
+        VcsApplicationSettings.getInstance().PATCH_STORAGE_LOCATION = valueToStore;
         final boolean reversePatch = myPanel.isReversePatch();
 
         String baseDirName = myPanel.getBaseDirName();
@@ -240,6 +229,12 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr
     }
   }
 
+  @NotNull
+  private String getDefaultPatchPath() {
+    String baseDir = myProject.getBasePath();
+    return baseDir == null ? FileUtil.toSystemIndependentName(PathManager.getHomePath()) : baseDir;
+  }
+
   private Boolean showDialog(File file) {
     String message = VcsBundle.message("create.patch.success.confirmation", file.getPath());
     String title = VcsBundle.message("create.patch.commit.action.title");