diff options
author | Matthias Sohn | 2014-01-26 00:14:17 +0000 |
---|---|---|
committer | Robin Stocker | 2014-02-01 15:44:02 +0000 |
commit | ad57d00fe75be5a7288ad0656dfedd1ee7e20be5 (patch) | |
tree | 5a6e6a9a8ed2a22980e2c98c3c098869887aada4 | |
parent | 08398318ddf2af9a8f3b13158bc8795bf3b77eb7 (diff) | |
download | egit-ad57d00fe75be5a7288ad0656dfedd1ee7e20be5.tar.gz egit-ad57d00fe75be5a7288ad0656dfedd1ee7e20be5.tar.xz egit-ad57d00fe75be5a7288ad0656dfedd1ee7e20be5.zip |
Allow to create configuration entries containing dots
This allows to e.g. persist a configuration entry
[branch "2.0.0/master"]
foo = bar
by specifying key "branch.2.0.0/master.foo" and value "bar".
Bug: 382931
Change-Id: I773980334771b3abef3c9beafbb9813627a79a65
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Signed-off-by: Robin Stocker <robin@nibor.org>
4 files changed, 40 insertions, 9 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java index 2b55a4bf6a..988179ba60 100644 --- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java +++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/prefpages/configuration/GlobalConfigurationPageTest.java @@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Set; import org.eclipse.egit.ui.common.EGitTestCase; import org.eclipse.egit.ui.internal.UIText; @@ -237,13 +238,37 @@ public class GlobalConfigurationPageTest { // ok: two dots assertTrue(addDialog.bot().button(IDialogConstants.OK_LABEL) .isEnabled()); + } + + @Test + public void testSubsectionWithDot() throws Exception { + preferencePage.bot() + .button(UIText.ConfigurationEditorComponent_AddButton).click(); + SWTBotShell addDialog = bot + .shell(UIText.AddConfigEntryDialog_AddConfigTitle); + addDialog.activate(); + + // subsection containing a dot + String subsection = TESTSUBSECTION + "." + TESTNAME; addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_KeyLabel) - .setText( - TESTSECTION + "." + TESTSUBSECTION + "." + TESTNAME - + "." + TESTNAME); - // too many dots - assertTrue(!addDialog.bot().button(IDialogConstants.OK_LABEL) + .setText(TESTSECTION + "." + subsection + "." + TESTNAME); + addDialog.bot().textWithLabel(UIText.AddConfigEntryDialog_ValueLabel) + .setText("true"); + assertTrue(addDialog.bot().button(IDialogConstants.OK_LABEL) .isEnabled()); + + // close the dialog + addDialog.bot().button(IDialogConstants.OK_LABEL).click(); + // close the editor + preferencePage.bot().button(IDialogConstants.OK_LABEL).click(); + + config.load(); + assertTrue("Missing section", config.getSections() + .contains(TESTSECTION)); + Set<String> subsections = config.getSubsections(TESTSECTION); + assertTrue("Missing subsection", subsections.contains(subsection)); + assertEquals("Wrong value", "true", + config.getString(TESTSECTION, subsection, TESTNAME)); addDialog.close(); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/AddConfigEntryDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/AddConfigEntryDialog.java index 0fea54775a..bcbf157941 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/AddConfigEntryDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/AddConfigEntryDialog.java @@ -106,7 +106,7 @@ public class AddConfigEntryDialog extends TitleAreaDialog { return; } StringTokenizer st = new StringTokenizer(keyText.getText(), "."); //$NON-NLS-1$ - if (st.countTokens() < 2 || st.countTokens() > 3) { + if (st.countTokens() < 2) { setErrorMessage(UIText.AddConfigEntryDialog_KeyComponentsMessage); hasError = true; return; diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java index 016c309428..1f41c3c7f4 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/ConfigurationEditorComponent.java @@ -398,9 +398,15 @@ public class ConfigurationEditorComponent { else entry.addValue(dlg.getValue()); markDirty(); - } else if (st.countTokens() == 3) { + } else if (st.countTokens() > 2) { + int n = st.countTokens(); String sectionName = st.nextToken(); - String subSectionName = st.nextToken(); + StringBuilder b = new StringBuilder(st.nextToken()); + for (int i = 0; i < n - 3; i++) { + b.append(DOT); + b.append(st.nextToken()); + } + String subSectionName = b.toString(); String entryName = st.nextToken(); Entry entry = ((GitConfig) tv.getInput()).getEntry( sectionName, subSectionName, entryName); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties index 4538965f08..1a63bad7d9 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties @@ -32,7 +32,7 @@ AddConfigEntryDialog_AddConfigTitle=Add a configuration entry AddConfigEntryDialog_ConfigKeyTooltip=Use "." to separate section/subsection/name, e.g. "core.bare", "remote.origin.url" AddConfigEntryDialog_DialogMessage=Please enter a key, e.g. "user.name" and a value AddConfigEntryDialog_EnterValueMessage=Please enter a value -AddConfigEntryDialog_KeyComponentsMessage=The key must have two or three components separated by "." +AddConfigEntryDialog_KeyComponentsMessage=The key must have two or more components separated by "." AddConfigEntryDialog_KeyLabel=&Key AddConfigEntryDialog_MustEnterKeyMessage=Please enter a key AddConfigEntryDialog_ValueLabel=&Value |