Exemplo n.º 1
0
 static void OnFileRemoving(FileCancelEventArgs e)
 {
     if (FileRemoving != null)
     {
         FileRemoving(null, e);
     }
 }
Exemplo n.º 2
0
        public static bool FireFileReplacing(string fileName, bool isDirectory)
        {
            FileCancelEventArgs e = new FileCancelEventArgs(fileName, isDirectory);

            if (FileReplacing != null)
            {
                FileReplacing(null, e);
            }
            return(!e.Cancel);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a file, raising the appropriate events. This method may show message boxes.
        /// </summary>
        public static void RemoveFile(string fileName, bool isDirectory)
        {
            FileCancelEventArgs eargs = new FileCancelEventArgs(fileName, isDirectory);

            OnFileRemoving(eargs);
            if (eargs.Cancel)
            {
                return;
            }
            if (!eargs.OperationAlreadyDone)
            {
                if (isDirectory)
                {
                    try {
                        if (Directory.Exists(fileName))
                        {
                            if (DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                Directory.Delete(fileName, true);
                            }
                        }
                    } catch (Exception e) {
                        MessageService.ShowError(e, "Can't remove directory " + fileName);
//					return;
                    }
                }
                else
                {
                    try {
                        if (File.Exists(fileName))
                        {
                            if (DeleteToRecycleBin)
                            {
                                NativeMethods.DeleteToRecycleBin(fileName);
                            }
                            else
                            {
                                File.Delete(fileName);
                            }
                        }
                    } catch (Exception e) {
                        MessageService.ShowError(e, "Can't remove file " + fileName);
//					return;
                    }
                }
            }
            OnFileRemoved(new FileEventArgs(fileName, isDirectory));
        }
		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);
					
					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 string[,] { { "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;
					}
				}
				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 (!e.Cancel) {
				if (WorkbenchSingleton.InvokeRequired) {
					WorkbenchSingleton.SafeThreadAsyncCall(this.CheckForDesignerCodeFileDeletion, e);
				} else {
					this.CheckForDesignerCodeFileDeletion(e);
				}
			}
		}
Exemplo n.º 7
0
		/// <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;
		}
Exemplo n.º 8
0
		static void OnFileRemoving(FileCancelEventArgs e)
		{
			if (FileRemoving != null) {
				FileRemoving(null, e);
			}
		}
Exemplo n.º 9
0
		/// <summary>
		/// Removes a file, raising the appropriate events. This method may show message boxes.
		/// </summary>
		public static void RemoveFile(string fileName, bool isDirectory)
		{
			FileCancelEventArgs eargs = new FileCancelEventArgs(fileName, isDirectory);
			OnFileRemoving(eargs);
			if (eargs.Cancel)
				return;
			if (!eargs.OperationAlreadyDone) {
				if (isDirectory) {
					try {
						if (Directory.Exists(fileName)) {
							if (DeleteToRecycleBin)
								NativeMethods.DeleteToRecycleBin(fileName);
							else
								Directory.Delete(fileName, true);
						}
					} 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 e) {
						MessageService.ShowHandledException(e, "Can't remove file " + fileName);
					}
				}
			}
			OnFileRemoved(new FileEventArgs(fileName, isDirectory));
		}
Exemplo n.º 10
0
		void FileServiceFileRemoving(object sender, FileCancelEventArgs e)
		{
			if (FileUtility.IsEqualFileName(e.FileName, file.FileName) || 
			    FileUtility.IsBaseDirectory(e.FileName, file.FileName))
				this.WorkbenchWindow.CloseWindow(true);
		}