/// <summary> /// Supress renaming pjoject or solution files (bug #1347) /// </summary> void FileService_FileRenaming(object sender, FileRenamingEventArgs e) { if (e.SourceFile.ToLower().Contains("zebCtlNTAddIn.".ToLower())) { e.Cancel = true; } }
private void OnFileCopying(FileRenamingEventArgs e) { if (FileCopying != null) { FileCopying(this, e); } }
void FileRenaming(object sender, FileRenamingEventArgs e) { if (e.Cancel) { return; } if (!AddInOptions.AutomaticallyRenameFiles) { return; } string fullSource = Path.GetFullPath(e.SourceFile); if (!CanBeVersionControlledFile(fullSource)) { return; } if (!FileHelpers.CheckRenameOrReplacePossible(e)) { e.Cancel = true; return; } try { using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); Status status = client.SingleStatus(fullSource); switch (status.TextStatus) { case StatusKind.Unversioned: case StatusKind.None: case StatusKind.Ignored: return; // nothing to do case StatusKind.Normal: case StatusKind.Modified: case StatusKind.Replaced: case StatusKind.Added: // rename without problem break; default: MessageService.ShowErrorFormatted("${res:AddIns.Subversion.CannotMoveError}", status.TextStatus.ToString()); e.Cancel = true; return; } e.OperationAlreadyDone = true; client.Move(fullSource, Path.GetFullPath(e.TargetFile), true ); } } catch (Exception ex) { MessageService.ShowError("File renamed exception: " + ex); } }
/// <summary> /// Renames or moves a file, raising the appropriate events. This method may show message boxes. /// </summary> public bool RenameFile(string oldName, string newName, bool isDirectory) { if (string.Equals(FileUtility.NormalizePath(oldName), FileUtility.NormalizePath(newName), StringComparison.Ordinal)) { return(false); } // FileChangeWatcher.DisableAllChangeWatchers(); try { var eargs = new FileRenamingEventArgs(oldName, newName, isDirectory); OnFileRenaming(eargs); if (eargs.Cancel) { return(false); } if (!eargs.OperationAlreadyDone) { try { if (isDirectory) { Directory.Move(oldName, newName); } else { File.Move(oldName, newName); } } catch (Exception e) { if (isDirectory) { MessageService.ShowHandledException(e, "Can't rename directory " + oldName); } else { MessageService.ShowHandledException(e, "Can't rename file " + oldName); } return(false); } } OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory)); return(true); } finally { // FileChangeWatcher.EnableAllChangeWatchers(); } }
/// <summary> /// Copies a file, raising the appropriate events. This method may show message boxes. /// </summary> public bool CopyFile(string oldName, string newName, bool isDirectory, bool overwrite) { if (FileUtility.IsEqualFileName(oldName, newName)) { return(false); } var eargs = new FileRenamingEventArgs(oldName, newName, isDirectory); OnFileCopying(eargs); if (eargs.Cancel) { return(false); } if (!eargs.OperationAlreadyDone) { try { if (FileHelpers.CheckRenameOrReplacePossible(eargs, overwrite)) { if (isDirectory) { FileUtility.DeepCopy(oldName, newName, overwrite); } else { File.Copy(oldName, newName, overwrite); } } } catch (Exception e) { if (isDirectory) { MessageService.ShowHandledException(e, "Can't copy directory " + oldName); } else { MessageService.ShowHandledException(e, "Can't copy file " + oldName); } return(false); } } OnFileCopied(new FileRenameEventArgs(oldName, newName, isDirectory)); return(true); }
private static void OnFileRenaming(FileRenamingEventArgs e) { if (FileRenaming != null) { FileRenaming(null, e); } }
public static bool RenameFile(string oldName, string newName, bool isDirectory) { if (FileUtility.IsEqualFileName(oldName, newName)) { return false; } FileRenamingEventArgs e = new FileRenamingEventArgs(oldName, newName, isDirectory); OnFileRenaming(e); if (e.Cancel) { return false; } if (!e.OperationAlreadyDone) { try { if (isDirectory && Directory.Exists(oldName)) { if (Directory.Exists(newName)) { MessageService.ShowMessage(SkyMap.Net.Core.StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}")); return false; } Directory.Move(oldName, newName); } else if (File.Exists(oldName)) { if (File.Exists(newName)) { MessageService.ShowMessage(SkyMap.Net.Core.StringParser.Parse("${res:Gui.ProjectBrowser.FileInUseError}")); return false; } File.Move(oldName, newName); } } catch (Exception exception) { if (isDirectory) { MessageService.ShowError(exception, "Can't rename directory " + oldName); } else { MessageService.ShowError(exception, "Can't rename file " + oldName); } return false; } } OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory)); return true; }
/// <summary> /// Renames or moves a file, raising the appropriate events. This method may show message boxes. /// </summary> public static bool RenameFile(string oldName, string newName, bool isDirectory) { if (IsEqualFileName(oldName, newName)) return false; // FileChangeWatcher.DisableAllChangeWatchers(); try { FileRenamingEventArgs eargs = new FileRenamingEventArgs(oldName, newName, isDirectory); OnFileRenaming(eargs); if (eargs.Cancel) return false; if (!eargs.OperationAlreadyDone) { try { if (isDirectory && Directory.Exists(oldName)) { if (Directory.Exists(newName)) { return false; } Directory.Move(oldName, newName); } else if (File.Exists(oldName)) { if (File.Exists(newName)) { return false; } File.Move(oldName, newName); } } catch (Exception ex) { if (isDirectory) { //MessageService.ShowHandledException(e, "Can't rename directory " + oldName); } else { //MessageService.ShowHandledException(e, "Can't rename file " + oldName); } return false; } } OnFileRenamed(new FileRenameEventArgs(oldName, newName, isDirectory)); return true; } finally { // FileChangeWatcher.EnableAllChangeWatchers(); } }
/// <summary> /// Copies a file, raising the appropriate events. This method may show message boxes. /// </summary> public static bool CopyFile(string oldName, string newName, bool overwrite) { if (IsEqualFileName(oldName, newName)) return false; bool isDirectory = Directory.Exists(oldName); FileRenamingEventArgs eargs = new FileRenamingEventArgs(oldName, newName, isDirectory); OnFileCopying(eargs); if (eargs.Cancel) return false; if (!eargs.OperationAlreadyDone) { try { if (isDirectory && Directory.Exists(oldName)) { if (!overwrite && Directory.Exists(newName)) { return false; } DeepCopy(oldName, newName, overwrite); } else if (File.Exists(oldName)) { if (!overwrite && File.Exists(newName)) { return false; } File.Copy(oldName, newName, overwrite); } } catch (Exception ex) { if (isDirectory) { //MessageService.ShowHandledException(e, "Can't copy directory " + oldName); } else { //MessageService.ShowHandledException(e, "Can't copy file " + oldName); } return false; } } OnFileCopied(new FileRenameEventArgs(oldName, newName, isDirectory)); return true; }
void FileRenaming(object sender, FileRenamingEventArgs e) { if (e.Cancel) return; if (!AddInOptions.AutomaticallyRenameFiles) return; string fullSource = Path.GetFullPath(e.SourceFile); if (!CanBeVersionControlledFile(fullSource)) return; if (!FileHelpers.CheckRenameOrReplacePossible(e)) { e.Cancel = true; return; } try { using (SvnClientWrapper client = new SvnClientWrapper()) { SvnMessageView.HandleNotifications(client); Status status = client.SingleStatus(fullSource); switch (status.TextStatus) { case StatusKind.Unversioned: case StatusKind.None: case StatusKind.Ignored: return; // nothing to do case StatusKind.Normal: case StatusKind.Modified: case StatusKind.Replaced: case StatusKind.Added: // rename without problem break; default: MessageService.ShowErrorFormatted("${res:AddIns.Subversion.CannotMoveError}", status.TextStatus.ToString()); e.Cancel = true; return; } e.OperationAlreadyDone = true; client.Move(fullSource, Path.GetFullPath(e.TargetFile), true ); } } catch (Exception ex) { MessageService.ShowError("File renamed exception: " + ex); } }