diff options
9 files changed, 130 insertions, 4 deletions
diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIPreferences.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIPreferences.java new file mode 100644 index 0000000000..f3626b991b --- /dev/null +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIPreferences.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.gitflow.ui.internal; + +/** + * Preferences used by the Gitflow UI plug-in. + * <p> + * All plug-in preferences shall be referenced by a constant in this class. + */ +public class UIPreferences { + /** */ + public final static String FEATURE_FINISH_SQUASH = "feature_finish_squash"; //$NON-NLS-1$ + + /** */ + public final static String FEATURE_FINISH_KEEP_BRANCH = "feature_finish_keep_branch"; //$NON-NLS-1$ +} diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java index 06ad294776..3357471227 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/UIText.java @@ -217,6 +217,9 @@ public class UIText extends NLS { public static String FinishFeatureDialog_keepBranch; /** */ + public static String FinishFeatureDialog_saveAsDefault; + + /** */ public static String FinishFeatureDialog_squashCheck; /** */ diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/FinishFeatureDialog.java b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/FinishFeatureDialog.java index 793d74fec2..ddd88429a5 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/FinishFeatureDialog.java +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/dialogs/FinishFeatureDialog.java @@ -8,9 +8,17 @@ *******************************************************************************/ package org.eclipse.egit.gitflow.ui.internal.dialogs; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_KEEP_BRANCH; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_SQUASH; + +import org.eclipse.egit.gitflow.ui.Activator; import org.eclipse.egit.gitflow.ui.internal.UIText; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IMessageProvider; import org.eclipse.jface.dialogs.TitleAreaDialog; +import org.eclipse.jface.layout.GridDataFactory; +import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; @@ -36,6 +44,8 @@ public class FinishFeatureDialog extends TitleAreaDialog { private String featureBranch; + private Button rememberOptionsButton; + /** * @param parentShell * @param featureBranch @@ -68,13 +78,49 @@ public class FinishFeatureDialog extends TitleAreaDialog { keepBranchButton = new Button(container, SWT.CHECK); keepBranchButton.setText(UIText.FinishFeatureDialog_keepBranch); + restoreInput(); + return area; } + private void restoreInput() { + IPreferenceStore prefStore = Activator + .getDefault() + .getPreferenceStore(); + squashButton.setSelection(prefStore.getBoolean(FEATURE_FINISH_SQUASH)); + keepBranchButton.setSelection(prefStore.getBoolean(FEATURE_FINISH_KEEP_BRANCH)); + } + @Override protected Control createButtonBar(Composite parent) { - // TODO: we should have options to persist the selected configuration - return super.createButtonBar(parent); + final Composite customButtonBar = new Composite(parent, SWT.NONE); + + int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); + GridLayoutFactory.swtDefaults().numColumns(2).equalWidth(false) + .spacing(horizontalSpacing, 0).applyTo(customButtonBar); + + GridDataFactory.swtDefaults().grab(true, false) + .align(SWT.FILL, SWT.BOTTOM).applyTo(customButtonBar); + + customButtonBar.setFont(parent.getFont()); + + rememberOptionsButton = new Button(customButtonBar, SWT.CHECK); + rememberOptionsButton.setText(UIText.FinishFeatureDialog_saveAsDefault); + + // TODO: Checkbox "Don't ask again" + + int horizontlIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); + GridDataFactory.swtDefaults().grab(true, true) + .align(SWT.FILL, SWT.CENTER).indent(horizontlIndent, 0) + .applyTo(rememberOptionsButton); + + // add the dialog's button bar to the right + final Control buttonControl = super.createButtonBar(customButtonBar); + GridDataFactory.swtDefaults().grab(true, false) + .align(SWT.RIGHT, SWT.CENTER).applyTo(buttonControl); + + + return customButtonBar; } @Override @@ -89,7 +135,16 @@ public class FinishFeatureDialog extends TitleAreaDialog { private void saveInput() { this.squash = squashButton.getSelection(); + this.keepBranch = keepBranchButton.getSelection(); + if (rememberOptionsButton.getSelection()) { + IPreferenceStore preferenceStore = Activator + .getDefault() + .getPreferenceStore(); + preferenceStore.setValue(FEATURE_FINISH_SQUASH, squashButton.getSelection()); + preferenceStore.setValue(FEATURE_FINISH_KEEP_BRANCH, keepBranchButton.getSelection()); + } + } @Override @@ -111,4 +166,4 @@ public class FinishFeatureDialog extends TitleAreaDialog { public boolean isKeepBranch() { return keepBranch; } -}
\ No newline at end of file +} diff --git a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties index b02599cbab..3ad67dafa2 100644 --- a/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties +++ b/org.eclipse.egit.gitflow.ui/src/org/eclipse/egit/gitflow/ui/internal/uitext.properties @@ -69,10 +69,11 @@ NameValidator_nameAlreadyExists=Name '%s' already exists FeatureCheckoutHandler_cleanupDialog_title=Cannot Rebase Repository ''{0}'' FeatureCheckoutHandler_cleanupDialog_text=You have uncommitted changes. Either commit the changes, stash the changes, or discard the changes by resetting the current branch. FinishFeatureDialog_keepBranch=&Keep branch - do not delete branch after finishing the feature +FinishFeatureDialog_saveAsDefault=Save as &default FinishFeatureDialog_squashCheck=&Squash - produce a single commit from the changes in this feature FinishFeatureDialog_title=Feature finish options FinishFeatureDialog_setParameterForFinishing=Set options for finishing {0}. ReleaseFinishOperation_unexpectedConflictsReleaseAborted=Unexpected conflicts while merging to {0}. Finish release aborted. HotfixFinishOperation_unexpectedConflictsHotfixAborted=Unexpected conflicts while merging to {0}. Finish hotfix aborted. UIIcons_errorDeterminingIconBase=Can't determine icon base. -UIIcons_errorLoadingPluginImage=Can''t load plugin image ''{0}''.
\ No newline at end of file +UIIcons_errorLoadingPluginImage=Can''t load plugin image ''{0}''. diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java index 1377d4008f..a7bf42e2f0 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractFeatureFinishHandlerTest.java @@ -44,6 +44,7 @@ public abstract class AbstractFeatureFinishHandlerTest extends AbstractGitflowHa } }); selectOptions(); + bot.checkBox(UIText.FinishFeatureDialog_saveAsDefault).click(); bot.button("OK").click(); preFinish(); bot.waitUntil(Conditions.waitForJobs(JobFamilies.GITFLOW_FAMILY, "Git flow jobs")); diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java index a52e8af58c..c6bee24e0d 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/AbstractGitflowHandlerTest.java @@ -8,6 +8,8 @@ *******************************************************************************/ package org.eclipse.egit.ui.gitflow; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_KEEP_BRANCH; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_SQUASH; import static org.eclipse.jgit.lib.Constants.R_HEADS; import java.io.File; @@ -17,8 +19,10 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.egit.gitflow.GitFlowRepository; import org.eclipse.egit.gitflow.op.FeatureCheckoutOperation; import org.eclipse.egit.gitflow.op.FeatureStartOperation; +import org.eclipse.egit.gitflow.ui.Activator; import org.eclipse.egit.ui.common.LocalRepositoryTestCase; import org.eclipse.egit.ui.test.TestUtil; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.AbortedByHookException; @@ -49,6 +53,15 @@ public abstract class AbstractGitflowHandlerTest extends LocalRepositoryTestCase public void setup() throws Exception { File repositoryFile = createProjectAndCommitToRepository(); repository = lookupRepository(repositoryFile); + + resetPreferences(); + } + + private void resetPreferences() { + IPreferenceStore prefStore = Activator.getDefault() + .getPreferenceStore(); + prefStore.setValue(FEATURE_FINISH_SQUASH, false); + prefStore.setValue(FEATURE_FINISH_KEEP_BRANCH, false); } protected RevCommit setContentAddAndCommit(String newContent) throws Exception, GitAPIException, NoHeadException, diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishKeepBranchHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishKeepBranchHandlerTest.java index 790d7d5378..ce55a26b42 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishKeepBranchHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishKeepBranchHandlerTest.java @@ -8,11 +8,17 @@ *******************************************************************************/ package org.eclipse.egit.ui.gitflow; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_KEEP_BRANCH; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_SQUASH; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import org.eclipse.egit.gitflow.GitFlowRepository; +import org.eclipse.egit.gitflow.ui.Activator; import org.eclipse.egit.gitflow.ui.internal.UIText; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Test; @@ -45,6 +51,11 @@ public class FeatureFinishKeepBranchHandlerTest extends assertEquals(developHead, featureBranchCommit); assertNotNull(findBranch(gfRepo.getConfig().getFeatureBranchName(FEATURE_NAME))); + + IPreferenceStore prefStore = Activator.getDefault() + .getPreferenceStore(); + assertFalse(prefStore.getBoolean(FEATURE_FINISH_SQUASH)); + assertTrue(prefStore.getBoolean(FEATURE_FINISH_KEEP_BRANCH)); } @Override diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishSquashHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishSquashHandlerTest.java index 01e2a138a8..5393b84b66 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishSquashHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureFinishSquashHandlerTest.java @@ -8,7 +8,10 @@ *******************************************************************************/ package org.eclipse.egit.ui.gitflow; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_KEEP_BRANCH; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_SQUASH; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -16,7 +19,9 @@ import java.io.IOException; import java.util.Iterator; import org.eclipse.egit.gitflow.GitFlowRepository; +import org.eclipse.egit.gitflow.ui.Activator; import org.eclipse.egit.gitflow.ui.internal.UIText; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.NoHeadException; @@ -64,6 +69,11 @@ public class FeatureFinishSquashHandlerTest extends assertTrue(developHead.getFullMessage().startsWith( SQUASHED_COMMENT_SUMMARY)); + + IPreferenceStore prefStore = Activator.getDefault() + .getPreferenceStore(); + assertTrue(prefStore.getBoolean(FEATURE_FINISH_SQUASH)); + assertFalse(prefStore.getBoolean(FEATURE_FINISH_KEEP_BRANCH)); } private int countCommits() throws GitAPIException, NoHeadException, diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureStartFinishHandlerTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureStartFinishHandlerTest.java index 4583be24ea..d3f145ca56 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureStartFinishHandlerTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/gitflow/FeatureStartFinishHandlerTest.java @@ -8,10 +8,15 @@ *******************************************************************************/ package org.eclipse.egit.ui.gitflow; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_KEEP_BRANCH; +import static org.eclipse.egit.gitflow.ui.internal.UIPreferences.FEATURE_FINISH_SQUASH; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import org.eclipse.egit.gitflow.GitFlowRepository; +import org.eclipse.egit.gitflow.ui.Activator; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; import org.junit.Test; @@ -43,6 +48,11 @@ public class FeatureStartFinishHandlerTest extends AbstractFeatureFinishHandlerT assertEquals(developHead, featureBranchCommit); assertNull(findBranch(gfRepo.getConfig().getFeatureBranchName(FEATURE_NAME))); + + IPreferenceStore prefStore = Activator.getDefault() + .getPreferenceStore(); + assertFalse(prefStore.getBoolean(FEATURE_FINISH_SQUASH)); + assertFalse(prefStore.getBoolean(FEATURE_FINISH_KEEP_BRANCH)); } @Override |