public void ValidateTitle()
{
if (_model.CurrentFileNameWithExtension == null) return;
// If the new title is invalid (e.g. blank, only spaces)
if (_view.TitleText.Trim().Length == 0)
{
MessageBox.Show(@"Title cannot be blank or just spaces.");
_view.TitleText = _model.CurrentFileName;
return;
}
// If the text has changed.
if (_view.TitleText.Equals(_model.CurrentFileName)) return;
// Since the title is valid and changed, we rename it.
int index = FindItem(_model.CurrentFileNameWithExtension);
try
{
RenameFile(_model.CurrentFileName, _view.TitleText);
}
catch (IOException ex)
{
Console.WriteLine(ex.Message);
MessageBox.Show(ex.Message, @"Error");
_view.TitleText = _model.CurrentFileName;
return;
}
RefreshDirectory();
_view.Files[index].Selected = true;
}