public void PerformDelete()
{
ProjectItemViewModel selected = SelectedItem;
if (selected == null)
{
return;
}
if (selected.Type == ProjectItemType.Reference)
{
PerformRemoveReference();
return;
}
if (selected.Type != ProjectItemType.Blueprints && selected.Type != ProjectItemType.Folder && selected.Type != ProjectItemType.File)
{
return;
}
string message = String.Format("'{0}' will be deleted permanantly?", selected.Name);
var result = MessageBox.ShowQuestion(message);
if (result == System.Windows.MessageBoxResult.Yes)
{
bool success = false;
try
{
switch (selected.Type)
{
case ProjectItemType.Blueprints:
case ProjectItemType.Folder:
Directory.Delete(selected.Path, true);
break;
case ProjectItemType.File:
File.Delete(selected.Path);
break;
}
success = true;
}
catch (Exception ex)
{
MessageBox.ShowError("Unable to delete the selected item", ex);
}
finally
{
if (success)
{
selected.Remove();
SaveProject();
RaiseFileDeleted(selected);
}
}
}
}