void FileServiceFileRemoving(object sender, FileCancelEventArgs e) { if (!e.Cancel) { this.CheckForDesignerCodeFileDeletion(e); } }
void FileServiceFileRemoving(object sender, FileCancelEventArgs e) { if (FileUtility.IsEqualFileName(e.FileName, file.FileName) || FileUtility.IsBaseDirectory(e.FileName, file.FileName)) { this.WorkbenchWindow.CloseWindow(true); } }
void FileServiceFileRemoving(object sender, FileCancelEventArgs e) { if (!e.Cancel) { if (WorkbenchSingleton.InvokeRequired) { WorkbenchSingleton.SafeThreadAsyncCall(this.CheckForDesignerCodeFileDeletion, e); } else { this.CheckForDesignerCodeFileDeletion(e); } } }
void CheckForDesignerCodeFileDeletion(FileCancelEventArgs e) { OpenedFile file; if (e.IsDirectory) { file = this.Files.SingleOrDefault( f => FileUtility.IsBaseDirectory(e.FileName, f.FileName) ); } else { file = this.Files.SingleOrDefault( f => FileUtility.IsEqualFileName(f.FileName, e.FileName) ); } if (file == null || file == this.PrimaryFile) { return; } LoggingService.Info("Forms designer: Handling deletion of open designer code file '" + file.FileName + "'"); if (file == this.sourceCodeStorage.DesignerCodeFile) { this.UnloadDesigner(); this.sourceCodeStorage.DesignerCodeFile = null; } // When any of our designer code files is deleted, // remove the file from the file list so that // the primary view is not closed because of this event. this.Files.Remove(file); this.sourceCodeStorage.RemoveFile(file); }
void FileRemoving(object sender, FileCancelEventArgs e) { if (e.Cancel) { return; } string fullName = Path.GetFullPath(e.FileName); if (!CanBeVersionControlledFile(fullName)) { return; } if (e.IsDirectory) { // show "cannot delete directories" message even if // AutomaticallyDeleteFiles (see below) is off! using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); try { Status status = client.SingleStatus(fullName); switch (status.TextStatus) { case StatusKind.None: case StatusKind.Unversioned: case StatusKind.Ignored: break; default: // must be done using the subversion client, even if // AutomaticallyDeleteFiles is off, because we don't want to corrupt the // working copy e.OperationAlreadyDone = true; try { client.Delete(new string[] { fullName }, false); } catch (SvnClientException ex) { LoggingService.Warn("SVN Error" + ex); LoggingService.Warn(ex); if (ex.IsKnownError(KnownError.CannotDeleteFileWithLocalModifications) || ex.IsKnownError(KnownError.CannotDeleteFileNotUnderVersionControl)) { if (MessageService.ShowCustomDialog("${res:AddIns.Subversion.DeleteDirectory}", StringParser.Parse("${res:AddIns.Subversion.ErrorDelete}:\n", new StringTagPair("File", fullName)) + ex.Message, 0, 1, "${res:AddIns.Subversion.ForceDelete}", "${res:Global.CancelButtonText}") == 0) { try { client.Delete(new string[] { fullName }, true); } catch (SvnClientException ex2) { e.Cancel = true; MessageService.ShowError(ex2.Message); } } else { e.Cancel = true; } } else { e.Cancel = true; MessageService.ShowError(ex.Message); } } break; } } catch (SvnClientException ex3) { e.Cancel = true; MessageService.ShowError(ex3.Message); } } return; } // not a directory, but a file: if (!AddInOptions.AutomaticallyDeleteFiles) { return; } try { using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); Status status = client.SingleStatus(fullName); switch (status.TextStatus) { case StatusKind.None: case StatusKind.Unversioned: case StatusKind.Ignored: case StatusKind.Deleted: return; // nothing to do case StatusKind.Normal: // remove without problem break; case StatusKind.Modified: case StatusKind.Replaced: if (MessageService.AskQuestion("${res:AddIns.Subversion.RevertLocalModifications}")) { // modified files cannot be deleted, so we need to revert the changes first client.Revert(new string[] { fullName }, e.IsDirectory ? Recurse.Full : Recurse.None); } else { e.Cancel = true; return; } break; case StatusKind.Added: if (status.Copied) { if (!MessageService.AskQuestion("${res:AddIns.Subversion.RemoveMovedFile}")) { e.Cancel = true; return; } } client.Revert(new string[] { fullName }, e.IsDirectory ? Recurse.Full : Recurse.None); return; default: MessageService.ShowErrorFormatted("${res:AddIns.Subversion.CannotRemoveError}", status.TextStatus.ToString()); e.Cancel = true; return; } e.OperationAlreadyDone = true; client.Delete(new string [] { fullName }, true); } } catch (Exception ex) { MessageService.ShowError("File removed exception: " + ex); } }
void CheckForDesignerCodeFileDeletion(FileCancelEventArgs e) { OpenedFile file; if (e.IsDirectory) { file = this.Files.SingleOrDefault( f => FileUtility.IsBaseDirectory(e.FileName, f.FileName) ); } else { file = this.Files.SingleOrDefault( f => FileUtility.IsEqualFileName(f.FileName, e.FileName) ); } if (file == null || file == this.PrimaryFile) return; LoggingService.Info("Forms designer: Handling deletion of open designer code file '" + file.FileName + "'"); if (file == this.sourceCodeStorage.DesignerCodeFile) { this.UnloadDesigner(); this.sourceCodeStorage.DesignerCodeFile = null; } // When any of our designer code files is deleted, // remove the file from the file list so that // the primary view is not closed because of this event. this.Files.Remove(file); this.sourceCodeStorage.RemoveFile(file); }
void FileServiceFileRemoving(object sender, FileCancelEventArgs e) { if (FileUtility.IsEqualFileName(e.FileName, file.FileName) || FileUtility.IsBaseDirectory(e.FileName, file.FileName)) WorkbenchWindow.CloseWindow(true); }
public static void RemoveFile(string fileName, bool recover = false) { recover = DeleteToRecycleBin; bool isDirectory = Directory.Exists(fileName); FileCancelEventArgs eargs = new FileCancelEventArgs(fileName, isDirectory); OnFileRemoving(eargs); if (eargs.Cancel) return; if (!eargs.OperationAlreadyDone) { if (isDirectory) { try { if (Directory.Exists(fileName)) { if (recover) { foreach (var file in Directory.GetFiles(fileName)) { NativeMethods.DeleteToRecycleBin(file); } } else { foreach (var file in Directory.GetFiles(fileName)) { File.Delete(file); } } } } catch (Exception e) { //MessageService.ShowHandledException(e, "Can't remove directory " + fileName); } } else { try { if (File.Exists(fileName)) { if (DeleteToRecycleBin) NativeMethods.DeleteToRecycleBin(fileName); else File.Delete(fileName); } } catch (Exception ex) { //MessageService.ShowHandledException(e, "Can't remove file " + fileName); } } } OnFileRemoved(new FileEventArgs(fileName, isDirectory)); }
public static void RemoveDirectory(string fileName, bool recover = false) { recover = DeleteToRecycleBin; FileCancelEventArgs eargs = new FileCancelEventArgs(fileName, true); OnFileRemoving(eargs); if (eargs.Cancel) return; if (!eargs.OperationAlreadyDone) { try { if (Directory.Exists(fileName)) { if (recover) NativeMethods.DeleteToRecycleBin(fileName); else Directory.Delete(fileName, true); } } catch (Exception ex) { //MessageService.ShowHandledException(e, "Can't remove directory " + fileName); } } OnFileRemoved(new FileEventArgs(fileName, true)); }
/// <summary> /// Fires the event handlers for a file being created. /// </summary> /// <param name="fileName">The name of the file being created. This should be a fully qualified path.</param> /// <param name="isDirectory">Set to true if this is a directory</param> public static bool FireFileReplacing(string fileName, bool isDirectory) { FileCancelEventArgs e = new FileCancelEventArgs(fileName, isDirectory); if (FileReplacing != null) { FileReplacing(null, e); } return !e.Cancel; }
static void OnFileRemoving(FileCancelEventArgs e) { if (FileRemoving != null) { FileRemoving(null, e); } }
void FileRemoving(object sender, FileCancelEventArgs e) { if (e.Cancel) return; string fullName = Path.GetFullPath(e.FileName); if (!CanBeVersionControlledFile(fullName)) return; if (e.IsDirectory) { // show "cannot delete directories" message even if // AutomaticallyDeleteFiles (see below) is off! using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); try { Status status = client.SingleStatus(fullName); switch (status.TextStatus) { case StatusKind.None: case StatusKind.Unversioned: case StatusKind.Ignored: break; default: // must be done using the subversion client, even if // AutomaticallyDeleteFiles is off, because we don't want to corrupt the // working copy e.OperationAlreadyDone = true; try { client.Delete(new string[] { fullName }, false); } catch (SvnClientException ex) { LoggingService.Warn("SVN Error" + ex); LoggingService.Warn(ex); if (ex.IsKnownError(KnownError.CannotDeleteFileWithLocalModifications) || ex.IsKnownError(KnownError.CannotDeleteFileNotUnderVersionControl)) { if (MessageService.ShowCustomDialog("${res:AddIns.Subversion.DeleteDirectory}", StringParser.Parse("${res:AddIns.Subversion.ErrorDelete}:\n", new StringTagPair("File", fullName)) + ex.Message, 0, 1, "${res:AddIns.Subversion.ForceDelete}", "${res:Global.CancelButtonText}") == 0) { try { client.Delete(new string[] { fullName }, true); } catch (SvnClientException ex2) { e.Cancel = true; MessageService.ShowError(ex2.Message); } } else { e.Cancel = true; } } else { e.Cancel = true; MessageService.ShowError(ex.Message); } } break; } } catch (SvnClientException ex3) { e.Cancel = true; MessageService.ShowError(ex3.Message); } } return; } // not a directory, but a file: if (!AddInOptions.AutomaticallyDeleteFiles) return; try { using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); Status status = client.SingleStatus(fullName); switch (status.TextStatus) { case StatusKind.None: case StatusKind.Unversioned: case StatusKind.Ignored: case StatusKind.Deleted: return; // nothing to do case StatusKind.Normal: // remove without problem break; case StatusKind.Modified: case StatusKind.Replaced: if (MessageService.AskQuestion("${res:AddIns.Subversion.RevertLocalModifications}")) { // modified files cannot be deleted, so we need to revert the changes first client.Revert(new string[] { fullName }, e.IsDirectory ? Recurse.Full : Recurse.None); } else { e.Cancel = true; return; } break; case StatusKind.Added: if (status.Copied) { if (!MessageService.AskQuestion("${res:AddIns.Subversion.RemoveMovedFile}")) { e.Cancel = true; return; } } client.Revert(new string[] { fullName }, e.IsDirectory ? Recurse.Full : Recurse.None); return; default: MessageService.ShowErrorFormatted("${res:AddIns.Subversion.CannotRemoveError}", status.TextStatus.ToString()); e.Cancel = true; return; } e.OperationAlreadyDone = true; client.Delete(new string [] { fullName }, true); } } catch (Exception ex) { MessageService.ShowError("File removed exception: " + ex); } }