From 518722db46ca15dee3ea35a0a80fa6f15a032d9f Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Wed, 14 Jan 2015 14:43:14 +0300 Subject: [PATCH] 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);