1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-21 16:05:25 +02:00

Fix bugs with validating configuration names

This commit is contained in:
Leo Treggiari 2005-09-09 02:33:49 +00:00
parent d616526e79
commit 8a7ca5b2aa
2 changed files with 26 additions and 7 deletions

View file

@ -469,6 +469,10 @@ public class NewConfigurationDialog extends StatusDialog {
* @return <I>true</i> is the name is a valid directory name with no whitespaces * @return <I>true</i> is the name is a valid directory name with no whitespaces
*/ */
private boolean validateName(String name) { private boolean validateName(String name) {
// Names must be at least one character in length
if (name.trim().length() == 0)
return false;
// Iterate over the name checking for bad characters // Iterate over the name checking for bad characters
char[] chars = name.toCharArray(); char[] chars = name.toCharArray();
// No whitespaces at the start of a name // No whitespaces at the start of a name
@ -503,14 +507,18 @@ public class NewConfigurationDialog extends StatusDialog {
private void validateState() { private void validateState() {
StatusInfo status= new StatusInfo(); StatusInfo status= new StatusInfo();
String currentName = configName.getText(); String currentName = configName.getText();
int nameLength = currentName.length(); // Trim trailing whitespace
// Make sure the name is not a duplicate while (currentName.length() > 0 && Character.isWhitespace(currentName.charAt(currentName.length()-1))) {
if (nameLength == 0) { currentName = currentName.substring(0, currentName.length()-1);
// Not an error }
// Make sure that the name is at least one character in length
if (currentName.length() == 0) {
// No error message, but cannot select OK
status.setError(""); //$NON-NLS-1$ status.setError(""); //$NON-NLS-1$
} else if(clone ? definedConfigs.length == 0 : defaultConfigs.length == 0) { } else if(clone ? definedConfigs.length == 0 : defaultConfigs.length == 0) {
// Not an error // Not an error
status.setError(""); //$NON-NLS-1$ status.setError(""); //$NON-NLS-1$
// Make sure the name is not a duplicate
} else if (isDuplicateName(currentName)) { } else if (isDuplicateName(currentName)) {
status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName)); status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName));
} else if (isSimilarName(currentName)) { } else if (isSimilarName(currentName)) {

View file

@ -248,6 +248,10 @@ public class RenameConfigurationDialog extends StatusDialog {
* @return <I>true</i> is the name is a valid directory name with no whitespaces * @return <I>true</i> is the name is a valid directory name with no whitespaces
*/ */
private boolean validateName(String name) { private boolean validateName(String name) {
// Names must be at least one character in length
if (name.trim().length() == 0)
return false;
// Iterate over the name checking for bad characters // Iterate over the name checking for bad characters
char[] chars = name.toCharArray(); char[] chars = name.toCharArray();
// No whitespaces at the start of a name // No whitespaces at the start of a name
@ -282,9 +286,16 @@ public class RenameConfigurationDialog extends StatusDialog {
private void validateState() { private void validateState() {
StatusInfo status= new StatusInfo(); StatusInfo status= new StatusInfo();
String currentName = configName.getText(); String currentName = configName.getText();
int nameLength = currentName.length(); // Trim trailing whitespace
// Make sure the name is not a duplicate while (currentName.length() > 0 && Character.isWhitespace(currentName.charAt(currentName.length()-1))) {
if (isDuplicateName(currentName)) { currentName = currentName.substring(0, currentName.length()-1);
}
// Make sure that the name is at least one character in length
if (currentName.length() == 0) {
// No error message, but cannot select OK
status.setError(""); //$NON-NLS-1$
// Make sure the name is not a duplicate
} else if (isDuplicateName(currentName)) {
status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName)); status.setError(ManagedBuilderUIMessages.getFormattedString(DUPLICATE, currentName));
} else if (isSimilarName(currentName)) { } else if (isSimilarName(currentName)) {
status.setError(ManagedBuilderUIMessages.getFormattedString(CASE, currentName)); status.setError(ManagedBuilderUIMessages.getFormattedString(CASE, currentName));