private void RemoveDeleteListItem(object arg) { // Last chance to avoid deleting a file from MyDeltaFiles - remove it from the list. if (arg != null && (int)arg > -1) { FileDescriptorModel fdv = (FileDescriptorModel)MyDeltaFilesView.CurrentItem; if (fdv != null) { // Remove only from Delta list, leave the rest of collections/lists alone... MyDeltaFiles.Remove(fdv); MyDeltaFilesView.MoveCurrentTo(null); OnPropertyRaised("MyDeltaFilesNo"); OnPropertyRaised("MyRejectionRatio"); } } }
private void RemoveRawItem(object arg) { if (arg != null && (int)arg > -1) { // MyRawFolderFiles.RemoveAt((int)arg); Can't do this... // In order for us to properly remove Collection item, we have to precisely know, // what item is at this index of View (View may be filtered, thus index will be different) // FileDescriptorModel fdv = MyRawGridView.Cast<FileDescriptorModel>().ToArray()[(int)arg]; Although it works, this seems too complicated FileDescriptorModel fdv = (FileDescriptorModel)MyRawGridView.CurrentItem; if (fdv != null) { MyRawFolderFiles.Remove(fdv); MyRawFolderListing.FileList.Remove(fdv); MyRawGridView.MoveCurrentTo(null); OnPropertyRaised("MyRawFolderFilesNo"); OnPropertyRaised("MyRawFilesNo"); OnPropertyRaised("MyRawFilesShownNo"); } } }
private void DeleteSingleDeltaFile(FileDescriptorModel fd) { // Try to delete file, checking for potential IO exceptions: // - if successful, delete this entry from both lists, increment DeletedFilesNo and continue the loop // - if not successful continue the loop leaving the list as is (perhaps for repeated deleting) try { if (File.Exists(fd.FilePath)) { if (RSSettingsModel.Instance.RecycleBinSetting) { // Move the file to Recycle Bin (watch exceptions if they are the same as from File.Delete()) FileSystem.DeleteFile(fd.FilePath, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } else { File.Delete(fd.FilePath); } } else { MessageBox.Show($"File { fd.FullName } do not exist.", "Warning!", MessageBoxButton.OK, MessageBoxImage.Warning); } } catch (IOException) { // The file could not be deleted, possibly due to the lock or some other IO problem MessageBox.Show($"Could not delete file: { fd.FullName } .\nFile may be locked. Hit OK to continue.", "Error!", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception ex) { // Obsługa exception rzucanego przez dialog pochodny (Error) dla dialogu FileSystem.DeleteFile - jeśli naciśnięto Cancel. Działa jak Skip... // Microsoft nie dokumentuje jakiego typu to jest Exception, stąd łapane i wyświetlane są wszystkie. Do użytkownika należy decyzja, czy program zterminuje, czy pozwoli dalej działać MessageBoxResult result = MessageBox.Show($"Could not delete file: { fd.FullName } .\nException data: { ex.Message }.\nHit OK to Continue, Cancel to terminate App.", "Error!", MessageBoxButton.OKCancel, MessageBoxImage.Error); if (result == MessageBoxResult.Cancel) { Application.Current.Shutdown(); return; } } }