From dab52f5ff80e48c32ba91b81931994667f2f2101 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 24 Jun 2015 18:48:00 +0400 Subject: [PATCH] Create patch additional component panel optimized * unused dvcsUsed variable and appropriate for-statement removed; * cache additionalUIPanel instead of double creation; * new patch dialog creation become 2 times faster when called from commitChanges dialog --- .../patch/CreatePatchCommitExecutor.java | 39 +++++++------------ .../patch/CreatePatchConfigurationPanel.java | 4 +- .../changes/ui/CommitChangeListDialog.java | 5 ++- .../openapi/vcs/changes/ui/SessionDialog.java | 11 +++++- 4 files changed, 28 insertions(+), 31 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java index 4e2d89ac752c..7c9a1bfaf5f9 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchCommitExecutor.java @@ -29,14 +29,15 @@ import com.intellij.openapi.diff.impl.patch.IdeaTextPatchBuilder; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; -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.vcs.*; +import com.intellij.openapi.util.*; +import com.intellij.openapi.vcs.FilePath; +import com.intellij.openapi.vcs.VcsApplicationSettings; +import com.intellij.openapi.vcs.VcsBundle; +import com.intellij.openapi.vcs.VcsConfiguration; import com.intellij.openapi.vcs.changes.*; import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager; import com.intellij.util.WaitForProgressToShow; +import com.intellij.util.containers.ContainerUtil; import org.jdom.Element; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NonNls; @@ -54,7 +55,7 @@ import java.util.List; */ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements ProjectComponent, JDOMExternalizable { private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.patch.CreatePatchCommitExecutor"); - + private final Project myProject; private final ChangeListManager myChangeListManager; @@ -139,24 +140,13 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr myPanel.setFileName(ShelveChangesManager.suggestPatchName(myProject, commitMessage, new File(PATCH_PATH), null)); myPanel.setReversePatch(false); - boolean dvcsIsUsed = false; - - if (ProjectLevelVcsManager.getInstance(myProject).dvcsUsedInProject()) { - for (Change change : changes) { - final AbstractVcs vcs = ChangesUtil.getVcsForChange(change, myProject); - if (vcs != null && VcsType.distributed.equals(vcs.getType())) { - dvcsIsUsed = true; - break; - } + myPanel.setChanges(ContainerUtil.filter(changes, new Condition() { + @Override + public boolean value(Change change) { + return change.getBeforeRevision() != null && change.getAfterRevision() != null; } - } - final List modified = new ArrayList(); - for (Change change : changes) { - if (change.getBeforeRevision() == null || change.getAfterRevision() == null) continue; - modified.add(change); - } - myPanel.setChanges(modified); - myPanel.showTextStoreOption(dvcsIsUsed); + })); + myPanel.showTextStoreOption(); return myPanel.getPanel(); } @@ -258,7 +248,8 @@ public class CreatePatchCommitExecutor extends LocalCommitExecutor implements Pr LOG.info(ex); WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() { public void run() { - Messages.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", ex.getMessage()), CommonBundle.getErrorTitle()); + Messages.showErrorDialog(myProject, VcsBundle.message("create.patch.error.title", ex.getMessage()), + CommonBundle.getErrorTitle()); } }, null, myProject); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java index c398b5fbd62c..131d7e707661 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/patch/CreatePatchConfigurationPanel.java @@ -66,7 +66,6 @@ public class CreatePatchConfigurationPanel { private JCheckBox myIncludeBaseRevisionTextCheckBox; private Consumer myOkEnabledListener; private final Project myProject; - private boolean myDvcsIsUsed; private List myChanges; private Collection myIncludedChanges; private SelectFilesToAddTextsToPatchPanel mySelectFilesToAddTextsToPatchPanel; @@ -173,8 +172,7 @@ public class CreatePatchConfigurationPanel { myPanelWithSelectedFiles.add(myHideableTitledPanel, BorderLayout.CENTER); } - public void showTextStoreOption(final boolean dvcsIsUsed) { - myDvcsIsUsed = dvcsIsUsed; + public void showTextStoreOption() { if (myChanges.size() > 0) { myIncludeBaseRevisionTextCheckBox.setVisible(true); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index d83564e213ed..759a97426dad 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -653,12 +653,13 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj return; } boolean isOK = true; - if (SessionDialog.createConfigurationUI(session, getIncludedChanges(), getCommitMessage())!= null) { + final JComponent configurationUI = SessionDialog.createConfigurationUI(session, getIncludedChanges(), getCommitMessage()); + if (configurationUI != null) { DialogWrapper sessionDialog = new SessionDialog(commitExecutor.getActionText(), getProject(), session, getIncludedChanges(), - getCommitMessage()); + getCommitMessage(), configurationUI); isOK = sessionDialog.showAndGet(); } if (isOK) { diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/SessionDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/SessionDialog.java index fccbcf69af90..42a336e80999 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/SessionDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/SessionDialog.java @@ -41,17 +41,24 @@ public class SessionDialog extends DialogWrapper { public SessionDialog(String title, Project project, CommitSession session, List changes, - String commitMessage) { + String commitMessage, @Nullable JComponent configurationComponent) { super(project, true); mySession = session; myChanges = changes; myCommitMessage = commitMessage; - myConfigurationComponent = createConfigurationUI(mySession, myChanges, myCommitMessage); + myConfigurationComponent = + configurationComponent == null ? createConfigurationUI(mySession, myChanges, myCommitMessage) : configurationComponent; setTitle(CommitChangeListDialog.trimEllipsis(title)); init(); updateButtons(); } + public SessionDialog(String title, Project project, + CommitSession session, List changes, + String commitMessage) { + this(title, project, session, changes, commitMessage, null); + } + public static JComponent createConfigurationUI(final CommitSession session, final List changes, final String commitMessage) { try { return session.getAdditionalConfigurationUI(changes, commitMessage);