public static AlertButton AskQuestion (QuestionMessage message)
		{
			return messageService.GenericAlert (message);
		}
Example #2
0
		public bool AddFilesToSolutionFolder (SolutionFolder folder, string[] files)
		{
			QuestionMessage msg = new QuestionMessage ();
			AlertButton keepButton = new AlertButton (GettextCatalog.GetString ("Keep file path"));
			msg.Buttons.Add (keepButton);
			msg.Buttons.Add (AlertButton.Copy);
			msg.Buttons.Add (AlertButton.Move);
			msg.Buttons.Add (AlertButton.Cancel);
			msg.AllowApplyToAll = true;
			
			bool someAdded = false;
			
			foreach (string file in files) {
				FilePath fp = file;
				FilePath dest = folder.BaseDirectory.Combine (fp.FileName);
				
				if (folder.IsRoot) {
					// Don't allow adding files to the root folder. VS doesn't allow it
					// If there is no existing folder, create one
					var itemsFolder = (SolutionFolder) folder.Items.Where (item => item.Name == "Solution Items").FirstOrDefault ();
					if (itemsFolder == null) {
						itemsFolder = new SolutionFolder ();
						itemsFolder.Name = "Solution Items";
						folder.AddItem (itemsFolder);
					}
					folder = itemsFolder;
				}
				
				if (!fp.IsChildPathOf (folder.BaseDirectory)) {
					msg.Text = GettextCatalog.GetString ("The file {0} is outside the folder directory. What do you want to do?", fp.FileName);
					AlertButton res = MessageService.AskQuestion (msg);
					if (res == AlertButton.Cancel)
						return someAdded;
					if (res == AlertButton.Copy) {
						FileService.CopyFile (file, dest);
						fp = dest;
					} else if (res == AlertButton.Move) {
						FileService.MoveFile (file, dest);
						fp = dest;
					}
				}
				folder.Files.Add (fp);
				someAdded = true;
			}
			return someAdded;
		}
Example #3
0
 public static AlertButton AskQuestion(QuestionMessage message)
 {
     return(messageService.GenericAlert(null, message));
 }
		bool? MoveCopyFile (string filename, string targetFilename, bool move, QuestionMessage confirm)
		{
			if (filename != targetFilename) {
				if (File.Exists (targetFilename)) {
					confirm.Text = GettextCatalog.GetString ("The file '{0}' already exists. Do you want to replace it?",
						targetFilename);
					AlertButton result = MessageService.AskQuestion (confirm);
					if (result == AlertButton.Cancel)
						return null;
					else if (result != AlertButton.OverwriteFile)
						return false;
				}
				FileService.CopyFile (filename, targetFilename);
				if (move)
					FileService.DeleteFile (filename);
			}
			return true;
		}
		/// <summary>
		/// Adds files to a project, potentially asking the user whether to move, copy or link the files.
		/// </summary>
		public IList<ProjectFile> AddFilesToProject (Project project, FilePath[] files, FilePath[] targetPaths,
			string buildAction)
		{
			Debug.Assert (project != null);
			Debug.Assert (files != null);
			Debug.Assert (targetPaths != null);
			Debug.Assert (files.Length == targetPaths.Length);
			
			AddAction action = AddAction.Copy;
			bool applyToAll = true;
			bool dialogShown = false;
			bool supportsLinking = !(project is MonoDevelop.Projects.SharedAssetsProjects.SharedAssetsProject);

			var confirmReplaceFileMessage = new QuestionMessage ();
			if (files.Length > 1) {
				confirmReplaceFileMessage.AllowApplyToAll = true;
				confirmReplaceFileMessage.Buttons.Add (new AlertButton (GettextCatalog.GetString ("Skip")));
			}
			confirmReplaceFileMessage.Buttons.Add (AlertButton.Cancel);
			confirmReplaceFileMessage.Buttons.Add (AlertButton.OverwriteFile);
			confirmReplaceFileMessage.DefaultButton = confirmReplaceFileMessage.Buttons.Count - 1;
			
			ProgressMonitor monitor = null;
			
			if (files.Length > 10) {
				monitor = new MessageDialogProgressMonitor (true);
				monitor.BeginTask (GettextCatalog.GetString("Adding files..."), files.Length);
			}
			
			var newFileList = new List<ProjectFile> ();
			
			//project.AddFile (string) does linear search for duplicate file, so instead we use this HashSet and 
			//and add the ProjectFiles directly. With large project and many files, this should really help perf.
			//Also, this is a better check because we handle vpaths and links.
			//FIXME: it would be really nice if project.Files maintained these hashmaps
			var vpathsInProject = new Dictionary<FilePath, ProjectFile> ();
			var filesInProject = new Dictionary<FilePath,ProjectFile> ();
			foreach (var pf in project.Files) {
				filesInProject [pf.FilePath] = pf;
				vpathsInProject [pf.ProjectVirtualPath] = pf;
			}

			using (monitor)
			{
				for (int i = 0; i < files.Length; i++) {
					FilePath file = files[i];
					
					if (monitor != null) {
						monitor.Log.WriteLine (file);
						monitor.Step (1);
					}
					
					if (FileService.IsDirectory (file)) {
						//FIXME: warning about skipping?
						newFileList.Add (null);
						continue;
					}
					
					FilePath targetPath = targetPaths[i].CanonicalPath;
					Debug.Assert (targetPath.IsChildPathOf (project.BaseDirectory));

					ProjectFile vfile;
					var vpath = targetPath.ToRelative (project.BaseDirectory);
					if (vpathsInProject.TryGetValue (vpath, out vfile)) {
						if (vfile.IsLink) {
							MessageService.ShowWarning (GettextCatalog.GetString (
								"There is already a link in the project with the name '{0}'", vpath));
							continue;
						} else if (vfile.FilePath == file) {
							// File already exists in project.
							continue;
						}
					}
					
					string fileBuildAction = buildAction;
					if (string.IsNullOrEmpty (buildAction))
						fileBuildAction = project.GetDefaultBuildAction (targetPath);
					
					//files in the target directory get added directly in their current location without moving/copying
					if (file.CanonicalPath == targetPath) {
						if (vfile != null)
							ShowFileExistsInProjectMessage (vpath);
						else
							AddFileToFolder (newFileList, vpathsInProject, filesInProject, file, fileBuildAction);
						continue;
					}
					
					//for files outside the project directory, we ask the user whether to move, copy or link
					
					AddExternalFileDialog addExternalDialog = null;
					
					if (!dialogShown || !applyToAll) {
						addExternalDialog = new AddExternalFileDialog (file);
						if (!supportsLinking)
							addExternalDialog.DisableLinkOption ();
						if (files.Length > 1) {
							addExternalDialog.ApplyToAll = applyToAll;
							addExternalDialog.ShowApplyAll = true;
						}
						if (file.IsChildPathOf (targetPath.ParentDirectory))
							addExternalDialog.ShowKeepOption (file.ParentDirectory.ToRelative (targetPath.ParentDirectory));
						else {
							if (action == AddAction.Keep)
								action = AddAction.Copy;
							addExternalDialog.SelectedAction = action;
						}
					}
					
					try {
						if (!dialogShown || !applyToAll) {
							int response = MessageService.RunCustomDialog (addExternalDialog);
							// A dialog emits DeleteEvent rather than Cancel in response to Escape being pressed
							if (response == (int) Gtk.ResponseType.Cancel || response == (int) Gtk.ResponseType.DeleteEvent) {
								project.Files.AddRange (newFileList.Where (f => f != null));
								return newFileList;
							}
							action = addExternalDialog.SelectedAction;
							applyToAll = addExternalDialog.ApplyToAll;
							dialogShown = true;
						}
						
						if (action == AddAction.Keep) {
							if (vfile != null)
								ShowFileExistsInProjectMessage (vpath);
							else
								AddFileToFolder (newFileList, vpathsInProject, filesInProject, file, fileBuildAction);
							continue;
						}
						
						if (action == AddAction.Link) {
							if (vfile != null) {
								ShowFileExistsInProjectMessage (vpath);
								continue;
							}
							ProjectFile pf = new ProjectFile (file, fileBuildAction) {
								Link = vpath
							};
							vpathsInProject [pf.ProjectVirtualPath] = pf;
							filesInProject [pf.FilePath] = pf;
							newFileList.Add (pf);
							continue;
						}
						
						try {
							if (!Directory.Exists (targetPath.ParentDirectory))
								FileService.CreateDirectory (targetPath.ParentDirectory);

							bool? result = MoveCopyFile (file, targetPath, action == AddAction.Move, confirmReplaceFileMessage);
							if (result == true) {
								if (vfile == null) {
									var pf = new ProjectFile (targetPath, fileBuildAction);
									vpathsInProject [pf.ProjectVirtualPath] = pf;
									filesInProject [pf.FilePath] = pf;
									newFileList.Add (pf);
								}
							} else if (result == null) {
								project.Files.AddRange (newFileList.Where (f => f != null));
								return newFileList;
							} else {
								newFileList.Add (null);
							}
						}
						catch (Exception ex) {
							MessageService.ShowError (GettextCatalog.GetString (
								"An error occurred while attempt to move/copy that file. Please check your permissions."), ex);
							newFileList.Add (null);
						}
					} finally {
						if (addExternalDialog != null) {
							addExternalDialog.Destroy ();
							addExternalDialog.Dispose ();
						}
					}
				}
			}
			project.Files.AddRange (newFileList.Where (f => f != null));
			return newFileList;
		}
Example #6
0
 public static AlertButton AskQuestion(Window parent, QuestionMessage message)
 {
     return(messageService.GenericAlert(parent, message));
 }
		internal static bool CheckUserSettings()
		{
			var hasRefactoringSettings = IdeApp.ProjectOperations.CurrentSelectedSolution == null ||
				IdeApp.ProjectOperations.CurrentSelectedSolution.UserProperties.HasValue (EnableRefactorings);
			if (!hasRefactoringSettings) {
				var useRefactoringsButton     = new AlertButton (GettextCatalog.GetString("Use refactorings on this solution"));
				var text = GettextCatalog.GetString (
@"WARNING: The Xamarin Studio refactoring operations do not yet support C# 6.

You may continue to use refactoring operations with C# 6, however you should check the results carefully to make sure that
they have not made incorrect changes to your code. In particular, the ""?."" null propagating dereference will be changed
to ""."", a simple dereference, which can cause unexpected NullReferenceExceptions at runtime.
");
				var message = new QuestionMessage (text);
				message.Buttons.Add (useRefactoringsButton);
				message.Buttons.Add (AlertButton.Cancel);
				message.Icon = Gtk.Stock.DialogWarning;
				message.DefaultButton = 2;

				var result = MessageService.AskQuestion (message);
				if (result == AlertButton.Cancel)
					return false;
				ShowFixes = result == useRefactoringsButton;
			}
			return ShowFixes;
		}