Fixed validation of inputs in create project dialog

This commit is contained in:
Tiberiu Chibici 2014-08-16 14:02:18 +03:00
parent 1e6ba1375f
commit bedc107bb1
2 changed files with 22 additions and 4 deletions

View File

@ -21,5 +21,23 @@ namespace RainmeterStudio.Core.Utils
return true;
}
/// <summary>
/// Validates a file name
/// </summary>
/// <param name="name">Name of file</param>
/// <returns></returns>
public static bool IsFileNameValid(string name)
{
// No name is not a valid name
if (String.IsNullOrEmpty(name))
return false;
// Check for invalid characters
if (Path.GetInvalidFileNameChars().Intersect(name).Any())
return false;
return true;
}
}
}

View File

@ -113,9 +113,7 @@ namespace RainmeterStudio.UI.Dialogs
// Populate controls
listTemplates.ItemsSource = projectController.ProjectTemplates.OrderBy(x => x.DisplayText);
textLocation.ItemsSource = GetRecentLocations().OrderBy(x => x);
textLocation.Text = GetLocation();
Validate();
@ -145,8 +143,10 @@ namespace RainmeterStudio.UI.Dialogs
private void Validate()
{
bool res = true;
res &= (listTemplates.SelectedItem != null);
res &= (listTemplates.SelectedItem != null);
res &= PathHelper.IsFileNameValid(textName.Text);
res &= PathHelper.IsPathValid(textLocation.Text);
buttonCreate.IsEnabled = res;
}