Example #1
0
        public void CloseWorkspaceItem(WorkspaceItem item, bool isForceClose = false)
        {
            if (item == null)
            {
                return;
            }
            IProgressMonitor consoleProgressMonitor = Services.ProgressMonitors.GetConsoleProgressMonitor(false);

            item.Save(consoleProgressMonitor);
            foreach (Document document in Services.Workbench.Documents.ToArray <Document>())
            {
                document.Close(isForceClose);
            }
            SolutionLockHandler.Instance.ReleaseLock();
            this.Items.Remove(item);
            item.Dispose();
        }
Example #2
0
		public void CloseWorkspaceItem (WorkspaceItem item, bool closeItemFiles = true)
		{
			if (!Items.Contains (item))
				throw new InvalidOperationException ("Only top level items can be closed.");

			if (Items.Count == 1 && closeItemFiles) {
				// There is only one item, close the whole workspace
				Close (true, closeItemFiles);
				return;
			}

			if (RequestItemUnload (item)) {
				if (closeItemFiles) {
					var projects = item.GetAllItems<Project> ();
					foreach (Document doc in IdeApp.Workbench.Documents.Where (d => d.Project != null && projects.Contains (d.Project)).ToArray ()) {
						if (!doc.Close ())
							return;
					}
				}
				Items.Remove (item);
				item.Dispose ();
			}
		}
Example #3
0
		async Task<bool> BackgroundLoadWorkspace (ProgressMonitor monitor, FilePath file, bool loadPreferences, bool reloading, ITimeTracker timer)
		{
			WorkspaceItem item = null;

			try {
				if (reloading)
					SetReloading (true);

				if (!File.Exists (file)) {
					monitor.ReportError (GettextCatalog.GetString ("File not found: {0}", file), null);
					return false;
				}

				if (!Services.ProjectService.IsWorkspaceItemFile (file)) {
					if (!Services.ProjectService.IsSolutionItemFile (file)) {
						monitor.ReportError (GettextCatalog.GetString ("File is not a project or solution: {0}", file), null);
						return false;
					}

					// It is a project, not a solution. Try to create a dummy solution and add the project to it
					
					timer.Trace ("Getting wrapper solution");
					item = await IdeApp.Services.ProjectService.GetWrapperSolution (monitor, file);
				}
				
				if (item == null) {
					timer.Trace ("Reading item");
					item = await Services.ProjectService.ReadWorkspaceItem (monitor, file);
					if (monitor.CancellationToken.IsCancellationRequested)
						return false;
				}

				timer.Trace ("Registering to recent list");
				DesktopService.RecentFiles.AddProject (item.FileName, item.Name);
				
			} catch (Exception ex) {
				LoggingService.LogError ("Load operation failed", ex);
				monitor.ReportError ("Load operation failed.", ex);
				
				if (item != null)
					item.Dispose ();
				return false;
			} finally {
				if (reloading)
					SetReloading (false);
			}

			using (monitor) {
				// Add the item in the GUI thread. It is not safe to do it in the background thread.
				if (!monitor.CancellationToken.IsCancellationRequested) {
					item.SetShared ();
					Items.Add (item);
				}
				else {
					item.Dispose ();
					return false;
				}
				if (IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem == null)
					IdeApp.ProjectOperations.CurrentSelectedWorkspaceItem = GetAllSolutions ().FirstOrDefault ();
				if (Items.Count == 1 && loadPreferences) {
					timer.Trace ("Restoring workspace preferences");
					await RestoreWorkspacePreferences (item);
				}
				timer.Trace ("Reattaching documents");
				ReattachDocumentProjects (null);
				monitor.ReportSuccess (GettextCatalog.GetString ("Solution loaded."));

				timer.Trace ("Reattaching documents");
				ReattachDocumentProjects (null);
				monitor.ReportSuccess (GettextCatalog.GetString ("Solution loaded."));
			}
			return true;
		}
Example #4
0
		public Task<WorkspaceItem> ReloadItem (ProgressMonitor monitor, WorkspaceItem item)
		{
			return Runtime.RunInMainThread (async delegate {
				if (Items.IndexOf (item) == -1)
					throw new InvalidOperationException ("Item '" + item.Name + "' does not belong to workspace '" + Name + "'");

				// Load the new item
				
				WorkspaceItem newItem;
				try {
					newItem = await Services.ProjectService.ReadWorkspaceItem (monitor, item.FileName);
				} catch (Exception ex) {
					UnknownWorkspaceItem e = new UnknownWorkspaceItem ();
					e.LoadError = ex.Message;
					e.FileName = item.FileName;
					newItem = e;
				}
				
				// Replace in the file list
				Items.Replace (item, newItem);
				
				NotifyModified ();
				NotifyItemRemoved (new WorkspaceItemChangeEventArgs (item, true));
				NotifyItemAdded (new WorkspaceItemChangeEventArgs (newItem, true));
				
				item.Dispose ();
				return newItem;
			});
		}