(DeleteItemExec): multiple files deletion.

This commit is contained in:
morkt 2014-08-02 01:06:04 +04:00
parent 13674f2e11
commit 407d394c2c
4 changed files with 110 additions and 13 deletions

View File

@ -650,13 +650,12 @@ namespace GARbro.GUI
/// </summary>
private void OpenItemExec (object control, ExecutedRoutedEventArgs e)
{
EntryViewModel entry = CurrentDirectory.SelectedItem as EntryViewModel;
if (null == entry)
{
EntryViewModel entry = null;
var lvi = e.OriginalSource as ListViewItem;
if (lvi != null)
entry = lvi.Content as EntryViewModel;
}
if (null == entry)
entry = CurrentDirectory.SelectedItem as EntryViewModel;
if (null == entry)
return;
@ -784,20 +783,49 @@ namespace GARbro.GUI
/// </summary>
private void DeleteItemExec (object sender, ExecutedRoutedEventArgs e)
{
var entry = CurrentDirectory.SelectedItem as EntryViewModel;
if (entry == null)
var items = CurrentDirectory.SelectedItems.Cast<EntryViewModel>().Where (f => !f.IsDirectory);
if (!items.Any())
return;
this.IsEnabled = false;
try
{
m_app.ResetCache();
string item_name = Path.Combine (CurrentPath, entry.Name);
if (!items.Skip (1).Any()) // items.Count() == 1
{
string item_name = Path.Combine (CurrentPath, items.First().Name);
Trace.WriteLine (item_name, "DeleteItemExec");
FileSystem.DeleteFile (item_name, UIOption.AllDialogs, RecycleOption.SendToRecycleBin);
DeleteItem (lv_GetCurrentContainer());
SetStatusText (string.Format(guiStrings.MsgDeletedItem, item_name));
}
else
{
var rc = MessageBox.Show (this, guiStrings.MsgConfirmDeleteFiles, guiStrings.TextDeleteFiles,
MessageBoxButton.YesNo, MessageBoxImage.Question);
if (MessageBoxResult.Yes != rc)
return;
int count = 0;
StopWatchDirectoryChanges ();
try
{
Trace.WriteLine (string.Format ("deleting multiple files in {0}", CurrentPath), "DeleteItemExec");
foreach (var entry in items)
{
string item_name = Path.Combine (CurrentPath, entry.Name);
FileSystem.DeleteFile (item_name);
++count;
}
}
catch
{
ResumeWatchDirectoryChanges();
throw;
}
RefreshView();
SetStatusText (Localization.Format ("MsgDeletedItems", count));
}
}
catch (OperationCanceledException)
{
}
@ -964,6 +992,11 @@ namespace GARbro.GUI
}
}
}
private void CanExecuteFitWindow (object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = PreviewPane.Source != null;
}
}
/// <summary>
@ -1059,5 +1092,6 @@ namespace GARbro.GUI
public static readonly RoutedCommand ExploreItem = new RoutedCommand();
public static readonly RoutedCommand Refresh = new RoutedCommand();
public static readonly RoutedCommand Browse = new RoutedCommand();
public static readonly RoutedCommand FitWindow = new RoutedCommand();
}
}

View File

@ -366,6 +366,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Are you sure you want to delete these files?.
/// </summary>
public static string MsgConfirmDeleteFiles {
get {
return ResourceManager.GetString("MsgConfirmDeleteFiles", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Creating archive {0}.
/// </summary>
@ -384,6 +393,24 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Deleted {0} file.
/// </summary>
public static string MsgDeletedItems1 {
get {
return ResourceManager.GetString("MsgDeletedItems1", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Deleted {0} files.
/// </summary>
public static string MsgDeletedItems2 {
get {
return ResourceManager.GetString("MsgDeletedItems2", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to directory not found.
/// </summary>
@ -657,6 +684,15 @@ namespace GARbro.GUI.Strings {
}
}
/// <summary>
/// Looks up a localized string similar to Delete files.
/// </summary>
public static string TextDeleteFiles {
get {
return ResourceManager.GetString("TextDeleteFiles", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Text encoding.
/// </summary>

View File

@ -351,4 +351,16 @@ Overwrite?</value>
<data name="MsgFiles2" xml:space="preserve">
<value>{0} files</value>
</data>
<data name="MsgConfirmDeleteFiles" xml:space="preserve">
<value>Are you sure you want to delete these files?</value>
</data>
<data name="TextDeleteFiles" xml:space="preserve">
<value>Delete files</value>
</data>
<data name="MsgDeletedItems1" xml:space="preserve">
<value>Deleted {0} file</value>
</data>
<data name="MsgDeletedItems2" xml:space="preserve">
<value>Deleted {0} files</value>
</data>
</root>

View File

@ -366,4 +366,19 @@
<data name="MsgFiles3" xml:space="preserve">
<value>{0} файлов</value>
</data>
<data name="MsgConfirmDeleteFiles" xml:space="preserve">
<value>Вы действительно хотите удалить эти файлы?</value>
</data>
<data name="TextDeleteFiles" xml:space="preserve">
<value>Удалить файлы</value>
</data>
<data name="MsgDeletedItems1" xml:space="preserve">
<value>Удалён {0} файл</value>
</data>
<data name="MsgDeletedItems2" xml:space="preserve">
<value>Удалено {0} файла</value>
</data>
<data name="MsgDeletedItems3" xml:space="preserve">
<value>Удалено {0} файлов</value>
</data>
</root>