From f501189a4f9da9dc6a8eaa8bccbc87db22d363d3 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 14 Jan 2015 13:28:10 +0300 Subject: [PATCH 1/4] fix commit message test for not utf8 encoding --- plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java b/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java index 009f90c9a58a..cfc649cd6913 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/HgEncodingTest.java @@ -24,7 +24,9 @@ import org.zmlx.hg4idea.command.HgLogCommand; import org.zmlx.hg4idea.execution.HgCommandException; import org.zmlx.hg4idea.repo.HgRepository; import org.zmlx.hg4idea.repo.HgRepositoryImpl; +import org.zmlx.hg4idea.util.HgEncodingUtil; +import java.nio.charset.Charset; import java.util.List; import static com.intellij.openapi.vcs.Executor.cd; @@ -49,6 +51,7 @@ public class HgEncodingTest extends HgPlatformTest { cd(myRepository); String fileName = "file.txt"; echo(fileName, "lalala"); + Charset charset = HgEncodingUtil.getDefaultCharset(myProject); String comment = "öäüß"; HgRepository hgRepo = HgRepositoryImpl.getInstance(myRepository, myProject, myProject); HgCommitCommand commitCommand = new HgCommitCommand(myProject, hgRepo, comment); @@ -59,6 +62,6 @@ public class HgEncodingTest extends HgPlatformTest { assert file != null; List revisions = logCommand.execute(new HgFile(myProject, file), 1, false); HgFileRevision rev = revisions.get(0); - assertEquals(comment, rev.getCommitMessage()); + assertEquals(new String(comment.getBytes(charset)), rev.getCommitMessage()); } } From 3419a30f6842ca755b559b9b29d110f17cdc40c8 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 14 Jan 2015 13:44:36 +0300 Subject: [PATCH 2/4] style: remove unnecessary field --- .../dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java index 2e811916c8e5..b2314fe9bee6 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java @@ -36,7 +36,6 @@ public class VcsPushDialog extends DialogWrapper { private static final String ID = "Vcs.Push.Dialog"; - @NotNull private final Project myProject; private final PushLog myListPanel; private final PushController myController; private final Map myAdditionalPanels; @@ -48,7 +47,6 @@ public class VcsPushDialog extends DialogWrapper { @NotNull List selectedRepositories, @Nullable Repository currentRepo) { super(project); - myProject = project; myController = new PushController(project, this, selectedRepositories, currentRepo); myAdditionalPanels = myController.createAdditionalPanels(); myListPanel = myController.getPushPanelLog(); From 518722db46ca15dee3ea35a0a80fa6f15a032d9f Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 14 Jan 2015 14:43:14 +0300 Subject: [PATCH 3/4] refactoring * separated disableOkActions created for start edit property change event; * clarifying comment added; * enableOkActions method renamed to updateOkActions with appropriate logic moved inside --- .../intellij/dvcs/push/PushController.java | 10 +++++++--- .../intellij/dvcs/push/ui/VcsPushDialog.java | 20 ++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java index 78f22616b1bd..390f7588e3a4 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java @@ -88,8 +88,12 @@ public class PushController implements Disposable { myPushLog.getTree().addPropertyChangeListener(PushLogTreeUtil.EDIT_MODE_PROP, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { + // when user starts edit we need to force disable ok actions, because tree.isEditing() still false; + // after editing completed okActions will be enabled automatically by dialog validation Boolean isEditMode = (Boolean)evt.getNewValue(); - myDialog.enableOkActions(!isEditMode && isPushAllowed()); + if (isEditMode) { + myDialog.disableOkActions(); + } } }); startLoadingCommits(); @@ -234,7 +238,7 @@ public class PushController implements Disposable { @Override public void onSelectionChanged(boolean isSelected) { - myDialog.enableOkActions(isPushAllowed()); + myDialog.updateOkActions(); if (isSelected) { boolean forceLoad = myExcludedRepositoryRoots.remove(model.getRepository().getRoot().getPath()); if (!model.hasCommitInfo() && (forceLoad || !model.getSupport().shouldRequestIncomingChangesForNotCheckedRepositories())) { @@ -399,7 +403,7 @@ public class PushController implements Disposable { if (shouldBeSelected) { // never remove selection; initially all checkboxes are not selected node.setChecked(true); } - myDialog.enableOkActions(isPushAllowed()); + myDialog.updateOkActions(); } }); } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java index b2314fe9bee6..0dae18f857a1 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java @@ -52,7 +52,7 @@ public class VcsPushDialog extends DialogWrapper { myListPanel = myController.getPushPanelLog(); init(); - enableOkActions(myController.isPushAllowed()); + updateOkActions(); setOKButtonText("Push"); setOKButtonMnemonic('P'); setTitle("Push Commits"); @@ -78,7 +78,7 @@ public class VcsPushDialog extends DialogWrapper { @Nullable @Override protected ValidationInfo doValidate() { - enableOkActions(myController.isPushAllowed()); + updateOkActions(); return null; } @@ -101,6 +101,10 @@ public class VcsPushDialog extends DialogWrapper { return actions.toArray(new Action[actions.size()]); } + private boolean canPush() { + return myController.isPushAllowed(); + } + private boolean canForcePush() { return myController.isForcePushEnabled() && myController.getProhibitedTarget() == null; } @@ -121,11 +125,13 @@ public class VcsPushDialog extends DialogWrapper { protected String getHelpId() { return ID; } - public void enableOkActions(boolean isEnabled) { - myPushAction.setEnabled(isEnabled); + + public void updateOkActions() { + boolean canPush = canPush(); + myPushAction.setEnabled(canPush); if (myForcePushAction != null) { boolean canForcePush = canForcePush(); - myForcePushAction.setEnabled(isEnabled && canForcePush); + myForcePushAction.setEnabled(canPush && canForcePush); String tooltip = null; if (!canForcePush) { PushTarget target = myController.getProhibitedTarget(); @@ -137,6 +143,10 @@ public class VcsPushDialog extends DialogWrapper { } } + public void disableOkActions() { + myPushAction.setEnabled(false); + } + @Nullable public VcsPushOptionValue getAdditionalOptionValue(@NotNull PushSupport support) { VcsPushOptionsPanel panel = myAdditionalPanels.get(support); From 901b6f8c2a8c836a12a6a8556bfe89d15d6f033b Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 14 Jan 2015 14:49:11 +0300 Subject: [PATCH 4/4] IDEA-135126 Allow force push if there are no commits to push --- .../src/com/intellij/dvcs/push/PushController.java | 8 ++++---- .../src/com/intellij/dvcs/push/ui/VcsPushDialog.java | 9 ++++----- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java index 390f7588e3a4..c35f94c047b6 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java @@ -281,21 +281,21 @@ public class PushController implements Disposable { return names; } - public boolean isPushAllowed() { + public boolean isPushAllowed(final boolean force) { JTree tree = myPushLog.getTree(); return !tree.isEditing() && ContainerUtil.exists(myPushSupports, new Condition>() { @Override public boolean value(PushSupport support) { - return isPushAllowed(support); + return isPushAllowed(support, force); } }); } - private boolean isPushAllowed(@NotNull PushSupport pushSupport) { + private boolean isPushAllowed(@NotNull PushSupport pushSupport, boolean force) { Collection nodes = getNodesForSupport(pushSupport); if (hasSomethingToPush(nodes)) return true; - if (hasCheckedNodesWithContent(nodes, myDialog.getAdditionalOptionValue(pushSupport) != null)) { + if (hasCheckedNodesWithContent(nodes, force || myDialog.getAdditionalOptionValue(pushSupport) != null)) { return !pushSupport.getRepositoryManager().isSyncEnabled() || allNodesAreLoaded(nodes); } return false; diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java index 0dae18f857a1..7dbe1b20096e 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/VcsPushDialog.java @@ -102,11 +102,11 @@ public class VcsPushDialog extends DialogWrapper { } private boolean canPush() { - return myController.isPushAllowed(); + return myController.isPushAllowed(false); } private boolean canForcePush() { - return myController.isForcePushEnabled() && myController.getProhibitedTarget() == null; + return myController.isForcePushEnabled() && myController.getProhibitedTarget() == null && myController.isPushAllowed(true); } @Nullable @@ -127,11 +127,10 @@ public class VcsPushDialog extends DialogWrapper { } public void updateOkActions() { - boolean canPush = canPush(); - myPushAction.setEnabled(canPush); + myPushAction.setEnabled(canPush()); if (myForcePushAction != null) { boolean canForcePush = canForcePush(); - myForcePushAction.setEnabled(canPush && canForcePush); + myForcePushAction.setEnabled(canForcePush); String tooltip = null; if (!canForcePush) { PushTarget target = myController.getProhibitedTarget();