Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLluis Sanchez <llsan@microsoft.com>2019-02-15 20:57:44 +0300
committerLluis Sanchez <llsan@microsoft.com>2019-02-15 21:12:42 +0300
commitca94e4851759c70a3f44e6ed4d2d1f3296ed0bcf (patch)
tree5247748423d0211b13b2dbd1c219a95f8602cb34 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs
parent3f08768e1c48470d3c77365bf1225e2f48ad8fbc (diff)
Convert several IDE services into Service instances
The new IdeServices class has references to the core IDE services. Revamped the IDE initialization code. The UI loop is started earlier and that allows starting the services asynchronously. Code that previously was referencing static service classes or services available in IdeApp now reference IdeServices.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs317
1 files changed, 138 insertions, 179 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs
index a95c85d240..e20d881b26 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide/ProjectOperations.cs
@@ -1,4 +1,4 @@
-//
+//
// ProjectOperations.cs
//
// Author:
@@ -48,14 +48,18 @@ using MonoDevelop.Ide.TypeSystem;
using MonoDevelop.Projects;
using MonoDevelop.Projects.MSBuild;
using ExecutionContext = MonoDevelop.Projects.ExecutionContext;
+using MonoDevelop.Ide.Gui.Documents;
namespace MonoDevelop.Ide
{
/// <summary>
/// This is the basic interface to the workspace.
- /// </summary>
- public partial class ProjectOperations
- {
+ /// </summary>
+ [DefaultServiceImplementation]
+ public partial class ProjectOperations: Service
+ {
+ RootWorkspace workspace;
+
AsyncOperation<BuildResult> currentBuildOperation = new AsyncOperation<BuildResult> (Task.FromResult (BuildResult.CreateSuccess ()), null);
MultipleAsyncOperation currentRunOperation = MultipleAsyncOperation.CompleteMultipleOperation;
IBuildTarget currentBuildOperationOwner;
@@ -63,86 +67,77 @@ namespace MonoDevelop.Ide
SelectReferenceDialog selDialog = null;
- SolutionFolderItem currentSolutionItem = null;
- WorkspaceItem currentWorkspaceItem = null;
- object currentItem;
-
- BuildResult lastResult = new BuildResult ();
-
internal ProjectOperations ()
{
- IdeApp.Workspace.WorkspaceItemUnloaded += OnWorkspaceItemUnloaded;
- IdeApp.Workspace.ItemUnloading += IdeAppWorkspaceItemUnloading;
-
- }
+ }
+
+ protected override async Task OnInitialize (ServiceProvider serviceProvider)
+ {
+ workspace = await serviceProvider.GetService<RootWorkspace> ();
+ workspace.WorkspaceItemUnloaded += OnWorkspaceItemUnloaded;
+ workspace.ItemUnloading += IdeAppWorkspaceItemUnloading;
+ await Task.WhenAll (new Task [] {
+ serviceProvider.GetService<DocumentManager> (),
+ serviceProvider.GetService<ProgressMonitorManager> (),
+ serviceProvider.GetService<TaskService> ()
+ });
+ }
+
+ protected override Task OnDispose ()
+ {
+ workspace.WorkspaceItemUnloaded -= OnWorkspaceItemUnloaded;
+ workspace.ItemUnloading -= IdeAppWorkspaceItemUnloading;
+ return base.OnDispose ();
+ }
- [Obsolete ("This property will be removed.")]
- public BuildResult LastCompilerResult {
- get { return lastResult; }
- }
-
public Project CurrentSelectedProject {
get {
- return currentSolutionItem as Project;
+ return workspace.CurrentSelectedProject;
}
}
public Solution CurrentSelectedSolution {
get {
- return currentWorkspaceItem as Solution;
+ return workspace.CurrentSelectedSolution;
}
}
public IBuildTarget CurrentSelectedBuildTarget {
get {
- if (currentSolutionItem is IBuildTarget)
- return (IBuildTarget) currentSolutionItem;
- return currentWorkspaceItem as IBuildTarget;
+ return workspace.CurrentSelectedBuildTarget;
}
}
public WorkspaceObject CurrentSelectedObject {
get {
- return (WorkspaceObject)currentSolutionItem ?? (WorkspaceObject) currentWorkspaceItem;
+ return workspace.CurrentSelectedObject;
}
}
public WorkspaceItem CurrentSelectedWorkspaceItem {
get {
- return currentWorkspaceItem;
+ return workspace.CurrentSelectedWorkspaceItem;
}
- set {
- if (value != currentWorkspaceItem) {
- WorkspaceItem oldValue = currentWorkspaceItem;
- currentWorkspaceItem = value;
- if (oldValue is Solution || value is Solution)
- OnCurrentSelectedSolutionChanged(new SolutionEventArgs (currentWorkspaceItem as Solution));
- }
+ set {
+ workspace.CurrentSelectedWorkspaceItem = value;
}
}
public SolutionFolderItem CurrentSelectedSolutionItem {
- get {
- if (currentSolutionItem == null && CurrentSelectedSolution != null)
- return CurrentSelectedSolution.RootFolder;
- return currentSolutionItem;
+ get {
+ return workspace.CurrentSelectedSolutionItem;
}
- set {
- if (value != currentSolutionItem) {
- SolutionFolderItem oldValue = currentSolutionItem;
- currentSolutionItem = value;
- if (oldValue is Project || value is Project)
- OnCurrentProjectChanged (new ProjectEventArgs(currentSolutionItem as Project));
- }
+ set {
+ workspace.CurrentSelectedSolutionItem = value;
}
}
public object CurrentSelectedItem {
get {
- return currentItem;
+ return workspace.CurrentSelectedItem;
}
set {
- currentItem = value;
+ workspace.CurrentSelectedItem = value;
}
}
@@ -191,45 +186,12 @@ namespace MonoDevelop.Ide
if (owner == target)
return true;
else if (target is RootWorkspace)
- return ContainsTarget (owner, IdeApp.ProjectOperations.CurrentSelectedSolution);
+ return ContainsTarget (owner, IdeServices.ProjectOperations.CurrentSelectedSolution);
else if (owner is WorkspaceItem)
return ((WorkspaceItem)owner).ContainsItem (target);
return false;
}
- /*
- string GetDeclaredFile(IMember item)
- {
- if (item is IMember) {
- IMember mem = (IMember) item;
- if (mem.Region == null)
- return null;
- else if (mem.Region.FileName != null)
- return mem.Region.FileName;
- else if (mem.DeclaringType != null) {
- foreach (IType c in mem.DeclaringType.Parts) {
- if ((mem is IField && c.Fields.Contains((IField)mem)) ||
- (mem is IEvent && c.Events.Contains((IEvent)mem)) ||
- (mem is IProperty && c.Properties.Contains((IProperty)mem)) ||
- (mem is IMethod && c.Methods.Contains((IMethod)mem))) {
- return GetClassFileName(c);
- }
- }
- }
- } else if (item is IType) {
- IType cls = (IType) item;
- return GetClassFileName (cls);
- } else if (item is MonoDevelop.Projects.Parser.LocalVariable) {
- MonoDevelop.Projects.Parser.LocalVariable cls = (MonoDevelop.Projects.Parser.LocalVariable) item;
- return cls.Region.FileName;
- }
- return null;
- }
-
- public bool CanJumpToDeclaration (IMember item)
- {
- return (GetDeclaredFile(item) != null);
- }*/
-
+
public bool CanJumpToDeclaration (Microsoft.CodeAnalysis.ISymbol symbol)
{
if (symbol == null)
@@ -264,7 +226,7 @@ namespace MonoDevelop.Ide
return new MonoDevelop.Ide.FindInFiles.SearchResult (provider, position, part.Name.Length);
}
- public async void JumpTo (Microsoft.CodeAnalysis.ISymbol symbol, Microsoft.CodeAnalysis.Location location, Project project = null)
+ public async void JumpTo (Microsoft.CodeAnalysis.ISymbol symbol, Microsoft.CodeAnalysis.Location location, WorkspaceObject project = null)
{
if (location == null)
return;
@@ -276,7 +238,7 @@ namespace MonoDevelop.Ide
var metadataDllName = location.MetadataModule.Name;
if (metadataDllName == "CommonLanguageRuntimeLibrary")
metadataDllName = "corlib.dll";
- foreach (var assembly in await dn.GetReferencedAssemblies (IdeApp.Workspace.ActiveConfiguration)) {
+ foreach (var assembly in await dn.GetReferencedAssemblies (workspace.ActiveConfiguration)) {
if (assembly.FilePath.ToString ().IndexOf (metadataDllName, StringComparison.Ordinal) > 0) {
fileName = dn.GetAbsoluteChildPath (assembly.FilePath);
break;
@@ -284,11 +246,11 @@ namespace MonoDevelop.Ide
}
if (fileName == null)
return;
- var doc = await IdeApp.Workbench.OpenDocument (new FileOpenInformation (fileName, project));
+ var doc = await IdeServices.DocumentManager.OpenDocument (new FileOpenInformation (fileName, project as Project));
if (doc != null) {
doc.RunWhenLoaded (delegate {
- var handler = doc.PrimaryView.GetContent<MonoDevelop.Ide.Gui.Content.IOpenNamedElementHandler> ();
+ var handler = doc.GetContent<MonoDevelop.Ide.Gui.Content.IOpenNamedElementHandler> ();
if (handler != null)
handler.Open (symbol);
});
@@ -298,27 +260,27 @@ namespace MonoDevelop.Ide
}
var filePath = location.SourceTree.FilePath;
var offset = location.SourceSpan.Start;
- if (project?.ParentSolution != null) {
+ if (project is SolutionFolderItem item && item.ParentSolution != null) {
string projectedName;
int projectedOffset;
- if (TypeSystemService.GetWorkspace (project.ParentSolution).TryGetOriginalFileFromProjection (filePath, offset, out projectedName, out projectedOffset)) {
+ if (IdeServices.TypeSystemService.GetWorkspace (item.ParentSolution).TryGetOriginalFileFromProjection (filePath, offset, out projectedName, out projectedOffset)) {
filePath = projectedName;
offset = projectedOffset;
}
}
- await IdeApp.Workbench.OpenDocument (new FileOpenInformation (filePath, project) {
+ await IdeServices.DocumentManager.OpenDocument (new FileOpenInformation (filePath, project as Project) {
Offset = offset
});
}
- public void JumpToDeclaration (Microsoft.CodeAnalysis.ISymbol symbol, Project project = null, bool askIfMultipleLocations = true)
+ public void JumpToDeclaration (Microsoft.CodeAnalysis.ISymbol symbol, WorkspaceObject project = null, bool askIfMultipleLocations = true)
{
if (symbol == null)
throw new ArgumentNullException ("symbol");
var locations = symbol.Locations;
if (askIfMultipleLocations && locations.Length > 1) {
- using (var monitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true, true)) {
+ using (var monitor = IdeServices.ProgressMonitorManager.GetSearchProgressMonitor (true, true)) {
foreach (var part in locations) {
if (monitor.CancellationToken.IsCancellationRequested)
return;
@@ -341,7 +303,7 @@ namespace MonoDevelop.Ide
metadataDllName = "corlib.dll";
var dn = project as DotNetProject;
if (dn != null) {
- foreach (var assembly in await dn.GetReferencedAssemblies (IdeApp.Workspace.ActiveConfiguration)) {
+ foreach (var assembly in await dn.GetReferencedAssemblies (workspace.ActiveConfiguration)) {
if (assembly.FilePath.ToString ().IndexOf(metadataDllName, StringComparison.Ordinal) > 0) {
fileName = dn.GetAbsoluteChildPath (assembly.FilePath);
break;
@@ -350,10 +312,10 @@ namespace MonoDevelop.Ide
}
if (fileName == null || !File.Exists (fileName))
return;
- var doc = await IdeApp.Workbench.OpenDocument (new FileOpenInformation (fileName));
+ var doc = await IdeServices.DocumentManager.OpenDocument (new FileOpenInformation (fileName));
if (doc != null) {
doc.RunWhenLoaded (delegate {
- var handler = doc.PrimaryView.GetContent<MonoDevelop.Ide.Gui.Content.IOpenNamedElementHandler> ();
+ var handler = doc.GetContent<MonoDevelop.Ide.Gui.Content.IOpenNamedElementHandler> ();
if (handler != null)
handler.Open (documentationCommentId, openInPublicOnlyMode);
});
@@ -366,8 +328,8 @@ namespace MonoDevelop.Ide
if (item is SolutionFolderItem) {
await SaveAsync (((SolutionFolderItem)item).ParentSolution);
} else {
- await IdeApp.Workspace.SaveAsync ();
- IdeApp.Workspace.SavePreferences ();
+ await workspace.SaveAsync ();
+ workspace.SavePreferences ();
}
}
@@ -382,7 +344,7 @@ namespace MonoDevelop.Ide
try {
if (MessageService.RunCustomDialog (dlg) == (int) Gtk.ResponseType.Ok) {
- using (ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetToolOutputProgressMonitor (true)) {
+ using (ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetToolOutputProgressMonitor (true)) {
await Services.ProjectService.Export (monitor, item.FileName, dlg.TargetFolder, dlg.Format);
}
}
@@ -417,7 +379,7 @@ namespace MonoDevelop.Ide
if (!AllowSave (entry))
return;
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetSaveProgressMonitor (true);
try {
await entry.SaveAsync (monitor);
monitor.ReportSuccess (GettextCatalog.GetString ("Project saved."));
@@ -443,7 +405,7 @@ namespace MonoDevelop.Ide
if (!AllowSave (item))
return;
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetSaveProgressMonitor (true);
try {
await item.SaveAsync (monitor);
monitor.ReportSuccess (GettextCatalog.GetString ("Solution saved."));
@@ -498,7 +460,7 @@ namespace MonoDevelop.Ide
items = notSavedEntries;
}
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetSaveProgressMonitor (true);
try {
var tasks = new List<Task> ();
monitor.BeginTask (null, count);
@@ -545,7 +507,7 @@ namespace MonoDevelop.Ide
if (!AllowSave (item))
return;
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetSaveProgressMonitor (true);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetSaveProgressMonitor (true);
try {
await item.SaveAsync (monitor);
monitor.ReportSuccess (GettextCatalog.GetString ("Item saved."));
@@ -632,7 +594,7 @@ namespace MonoDevelop.Ide
var selectedProject = (SolutionItem) entry;
var optionsDialog = new ProjectOptionsDialog (IdeApp.Workbench.RootWindow, selectedProject);
- var conf = selectedProject.GetConfiguration (IdeApp.Workspace.ActiveConfiguration);
+ var conf = selectedProject.GetConfiguration (workspace.ActiveConfiguration);
optionsDialog.CurrentConfig = conf != null ? conf.Name : null;
optionsDialog.CurrentPlatform = conf != null ? conf.Platform : null;
try {
@@ -647,7 +609,7 @@ namespace MonoDevelop.Ide
}
}
await SaveAsync (selectedProject);
- IdeApp.Workspace.SavePreferences ();
+ workspace.SavePreferences ();
IdeApp.Workbench.ReparseOpenDocuments ();
}
} finally {
@@ -658,13 +620,13 @@ namespace MonoDevelop.Ide
Solution solution = (Solution) entry;
var optionsDialog = new CombineOptionsDialog (IdeApp.Workbench.RootWindow, solution);
- optionsDialog.CurrentConfig = IdeApp.Workspace.ActiveConfigurationId;
+ optionsDialog.CurrentConfig = workspace.ActiveConfigurationId;
try {
if (panelId != null)
optionsDialog.SelectPanel (panelId);
if (MessageService.RunCustomDialog (optionsDialog) == (int) Gtk.ResponseType.Ok) {
await SaveAsync (solution);
- await IdeApp.Workspace.SavePreferences (solution);
+ await workspace.SavePreferences (solution);
}
} finally {
optionsDialog.Destroy ();
@@ -684,7 +646,7 @@ namespace MonoDevelop.Ide
if (si.ParentSolution != null)
await SaveAsync (si.ParentSolution);
}
- IdeApp.Workspace.SavePreferences ();
+ workspace.SavePreferences ();
}
} finally {
optionsDialog.Destroy ();
@@ -771,7 +733,7 @@ namespace MonoDevelop.Ide
public async Task<WorkspaceItem> AddWorkspaceItem (Workspace parentWorkspace, string itemFileName)
{
- using (ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetProjectLoadProgressMonitor (true)) {
+ using (ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetProjectLoadProgressMonitor (true)) {
WorkspaceItem it = await Services.ProjectService.ReadWorkspaceItem (monitor, itemFileName);
if (it != null) {
parentWorkspace.Items.Add (it);
@@ -841,7 +803,7 @@ namespace MonoDevelop.Ide
}
if (res != null)
- await IdeApp.Workspace.SaveAsync ();
+ await workspace.SaveAsync ();
return res;
}
@@ -859,7 +821,7 @@ namespace MonoDevelop.Ide
AddingEntryToCombine (this, args);
if (args.Cancel)
return null;
- using (ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetProjectLoadProgressMonitor (true)) {
+ using (ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetProjectLoadProgressMonitor (true)) {
return await folder.AddItem (monitor, args.FileName, true);
}
}
@@ -938,7 +900,7 @@ namespace MonoDevelop.Ide
SolutionItem prj = item as SolutionItem;
if (prj == null) {
- if (MessageService.Confirm (question, AlertButton.Remove) && IdeApp.Workspace.RequestItemUnload (item))
+ if (MessageService.Confirm (question, AlertButton.Remove) && workspace.RequestItemUnload (item))
RemoveItemFromSolution (prj).Ignore();
return;
}
@@ -947,7 +909,7 @@ namespace MonoDevelop.Ide
AlertButton result = MessageService.AskQuestion (question, secondaryText,
delete, AlertButton.Cancel, AlertButton.Remove);
if (result == delete) {
- if (!IdeApp.Workspace.RequestItemUnload (prj))
+ if (!workspace.RequestItemUnload (prj))
return;
ConfirmProjectDeleteDialog dlg = new ConfirmProjectDeleteDialog (prj);
try {
@@ -978,19 +940,19 @@ namespace MonoDevelop.Ide
dlg.Dispose ();
}
}
- else if (result == AlertButton.Remove && IdeApp.Workspace.RequestItemUnload (prj)) {
+ else if (result == AlertButton.Remove && workspace.RequestItemUnload (prj)) {
RemoveItemFromSolution (prj).Ignore();
}
}
async Task RemoveItemFromSolution (SolutionFolderItem prj)
{
- foreach (var doc in IdeApp.Workbench.Documents.Where (d => d.Project == prj).ToArray ())
+ foreach (var doc in IdeServices.DocumentManager.Documents.Where (d => d.Owner == prj).ToArray ())
await doc.Close ();
Solution sol = prj.ParentSolution;
prj.ParentFolder.Items.Remove (prj);
prj.Dispose ();
- await IdeApp.ProjectOperations.SaveAsync (sol);
+ await SaveAsync (sol);
}
/// <summary>
@@ -1018,19 +980,19 @@ namespace MonoDevelop.Ide
public bool CanExecute (IBuildTarget entry)
{
- ExecutionContext context = new ExecutionContext (Runtime.ProcessService.DefaultExecutionHandler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
+ ExecutionContext context = new ExecutionContext (Runtime.ProcessService.DefaultExecutionHandler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
return CanExecute (entry, context);
}
public bool CanExecute (IBuildTarget entry, IExecutionHandler handler)
{
- ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
- return entry.CanExecute (context, IdeApp.Workspace.ActiveConfiguration);
+ ExecutionContext context = new ExecutionContext (handler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
+ return entry.CanExecute (context, workspace.ActiveConfiguration);
}
public bool CanExecute (IBuildTarget entry, ExecutionContext context)
{
- return entry.CanExecute (context, IdeApp.Workspace.ActiveConfiguration);
+ return entry.CanExecute (context, workspace.ActiveConfiguration);
}
public AsyncOperation Execute (IBuildTarget entry, bool buildBeforeExecuting = true)
@@ -1040,20 +1002,20 @@ namespace MonoDevelop.Ide
public AsyncOperation Execute (IBuildTarget entry, IExecutionHandler handler, bool buildBeforeExecuting = true)
{
- ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
+ ExecutionContext context = new ExecutionContext (handler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
return Execute (entry, context, buildBeforeExecuting);
}
public AsyncOperation Execute (IBuildTarget entry, IExecutionHandler handler, ConfigurationSelector configuration = null, RunConfiguration runConfiguration = null, bool buildBeforeExecuting = true)
{
- ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
+ ExecutionContext context = new ExecutionContext (handler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
return Execute (entry, context, configuration, runConfiguration, buildBeforeExecuting);
}
public AsyncOperation Execute (IBuildTarget entry, ExecutionContext context, bool buildBeforeExecuting = true)
{
var cs = new CancellationTokenSource ();
- return new AsyncOperation (ExecuteAsync (entry, context, cs, IdeApp.Workspace.ActiveConfiguration, null, buildBeforeExecuting), cs);
+ return new AsyncOperation (ExecuteAsync (entry, context, cs, workspace.ActiveConfiguration, null, buildBeforeExecuting), cs);
}
public AsyncOperation Execute (IBuildTarget entry, ExecutionContext context, ConfigurationSelector configuration = null, RunConfiguration runConfiguration = null, bool buildBeforeExecuting = true)
@@ -1093,7 +1055,7 @@ namespace MonoDevelop.Ide
Counters.TrackingBuildAndDeploy = true;
if (configuration == null)
- configuration = IdeApp.Workspace.ActiveConfiguration;
+ configuration = workspace.ActiveConfiguration;
var bth = context.ExecutionHandler as IConfigurableExecutionHandler;
var rt = entry as IRunTarget;
@@ -1162,7 +1124,7 @@ namespace MonoDevelop.Ide
public bool CanExecuteFile (string file, IExecutionHandler handler)
{
- ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
+ ExecutionContext context = new ExecutionContext (handler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
return CanExecuteFile (file, context);
}
@@ -1176,7 +1138,7 @@ namespace MonoDevelop.Ide
public AsyncOperation ExecuteFile (string file, IExecutionHandler handler)
{
- ExecutionContext context = new ExecutionContext (handler, IdeApp.Workbench.ProgressMonitors.ConsoleFactory, IdeApp.Workspace.ActiveExecutionTarget);
+ ExecutionContext context = new ExecutionContext (handler, IdeServices.ProgressMonitorManager.ConsoleFactory, workspace.ActiveExecutionTarget);
return ExecuteFile (file, context);
}
@@ -1199,7 +1161,7 @@ namespace MonoDevelop.Ide
ITimeTracker tt = Counters.BuildItemTimer.BeginTiming ("Cleaning " + entry.Name);
try {
var cs = new CancellationTokenSource ();
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetCleanProgressMonitor ().WithCancellationSource (cs);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetCleanProgressMonitor ().WithCancellationSource (cs);
OnStartClean (monitor, tt);
@@ -1227,7 +1189,7 @@ namespace MonoDevelop.Ide
BuildResult res = null;
try {
tt.Trace ("Cleaning item");
- res = await entry.Clean (monitor, IdeApp.Workspace.ActiveConfiguration, InitOperationContext (entry, operationContext));
+ res = await entry.Clean (monitor, workspace.ActiveConfiguration, InitOperationContext (entry, operationContext));
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Clean failed."), ex);
} finally {
@@ -1301,9 +1263,10 @@ namespace MonoDevelop.Ide
tasks [n].Owner = this;
}
- TaskService.Errors.AddRange (tasks);
- TaskService.Errors.ResetLocationList ();
- IdeApp.Workbench.ActiveLocationList = TaskService.Errors;
+ IdeServices.TaskService.Errors.AddRange (tasks);
+ IdeServices.TaskService.Errors.ResetLocationList ();
+ if (IdeApp.IsInitialized)
+ IdeApp.Workbench.ActiveLocationList = IdeServices.TaskService.Errors;
return tasks;
}
@@ -1319,11 +1282,11 @@ namespace MonoDevelop.Ide
errorsPad.BringToFront ();
break;
case BuildResultStates.OnErrors:
- if (TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error))
+ if (IdeServices.TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error))
goto case BuildResultStates.Always;
break;
case BuildResultStates.OnErrorsOrWarnings:
- if (TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error || task.Severity == TaskSeverity.Warning))
+ if (IdeServices.TaskService.Errors.Any (task => task.Severity == TaskSeverity.Error || task.Severity == TaskSeverity.Warning))
goto case BuildResultStates.Always;
break;
}
@@ -1340,7 +1303,7 @@ namespace MonoDevelop.Ide
if (currentBuildOperation != null && !currentBuildOperation.IsCompleted) return currentBuildOperation;
var cs = new CancellationTokenSource ();
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetRebuildProgressMonitor ().WithCancellationSource (cs);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetRebuildProgressMonitor ().WithCancellationSource (cs);
var t = RebuildAsync (entry, monitor, operationContext);
t = t.ContinueWith (ta => {
@@ -1639,7 +1602,7 @@ namespace MonoDevelop.Ide
var cs = new CancellationTokenSource ();
if (cancellationToken != null)
cs = CancellationTokenSource.CreateLinkedTokenSource (cs.Token, cancellationToken.Value);
- ProgressMonitor monitor = IdeApp.Workbench.ProgressMonitors.GetBuildProgressMonitor ().WithCancellationSource (cs);
+ ProgressMonitor monitor = IdeServices.ProgressMonitorManager.GetBuildProgressMonitor ().WithCancellationSource (cs);
BeginBuild (monitor, tt, false);
var t = BuildSolutionItemAsync (entry, monitor, tt, skipPrebuildCheck, operationContext);
currentBuildOperation = new AsyncOperation<BuildResult> (t, cs);
@@ -1666,7 +1629,7 @@ namespace MonoDevelop.Ide
if (skipPrebuildCheck || result.ErrorCount == 0) {
tt.Trace ("Building item");
- result = await entry.Build (monitor, IdeApp.Workspace.ActiveConfiguration, true, InitOperationContext (entry, operationContext));
+ result = await entry.Build (monitor, workspace.ActiveConfiguration, true, InitOperationContext (entry, operationContext));
}
} catch (Exception ex) {
monitor.ReportError (GettextCatalog.GetString ("Build failed."), ex);
@@ -1696,9 +1659,9 @@ namespace MonoDevelop.Ide
if (ctx.ExecutionTarget == null) {
var item = target as SolutionItem;
if (item != null)
- ctx.ExecutionTarget = IdeApp.Workspace.GetActiveExecutionTarget (item);
+ ctx.ExecutionTarget = IdeServices.Workspace.GetActiveExecutionTarget (item);
else
- ctx.ExecutionTarget = IdeApp.Workspace.ActiveExecutionTarget;
+ ctx.ExecutionTarget = IdeServices.Workspace.ActiveExecutionTarget;
}
return (T)ctx;
}
@@ -1708,8 +1671,8 @@ namespace MonoDevelop.Ide
{
var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
- foreach (var doc in IdeApp.Workbench.Documents) {
- if (doc.IsDirty && doc.Project != null) {
+ foreach (var doc in IdeServices.DocumentManager.Documents) {
+ if (doc.IsDirty && doc.Owner != null) {
if (MessageService.AskQuestion (GettextCatalog.GetString ("Save changed documents before building?"),
GettextCatalog.GetString ("Some of the open documents have unsaved changes."),
AlertButton.BuildWithoutSave, AlertButton.Save) == AlertButton.Save) {
@@ -1728,8 +1691,8 @@ namespace MonoDevelop.Ide
{
var couldNotSaveError = "The build has been aborted as the file '{0}' could not be saved";
- foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeApp.Workbench.Documents)) {
- if (doc.IsDirty && doc.Project != null) {
+ foreach (var doc in new List<MonoDevelop.Ide.Gui.Document> (IdeServices.DocumentManager.Documents)) {
+ if (doc.IsDirty && doc.Owner != null) {
await doc.Save ();
if (doc.IsDirty) {
doc.Select ();
@@ -1763,7 +1726,7 @@ namespace MonoDevelop.Ide
{
tt.Trace ("Start build event");
if (!isRebuilding) {
- MonoDevelop.Ide.Tasks.TaskService.Errors.ClearByOwner (this);
+ IdeServices.TaskService.Errors.ClearByOwner (this);
}
if (StartBuild != null) {
StartBuild (this, new BuildEventArgs (monitor, true));
@@ -1776,7 +1739,7 @@ namespace MonoDevelop.Ide
tt.Trace ("Begin reporting build result");
try {
if (result != null) {
- lastResult = result;
+ var lastResult = result;
monitor.Log.WriteLine ();
var msg = GettextCatalog.GetString (
@@ -2473,7 +2436,7 @@ namespace MonoDevelop.Ide
void OnStartClean (ProgressMonitor monitor, ITimeTracker tt)
{
tt.Trace ("Start clean event");
- TaskService.Errors.ClearByOwner (this);
+ IdeServices.TaskService.Errors.ClearByOwner (this);
if (StartClean != null) {
StartClean (this, new CleanEventArgs (monitor));
}
@@ -2504,39 +2467,39 @@ namespace MonoDevelop.Ide
void OnWorkspaceItemUnloaded (object s, WorkspaceItemEventArgs args)
{
- if (ContainsTarget (args.Item, currentSolutionItem))
+ if (ContainsTarget (args.Item, workspace.CurrentSelectedSolutionItem))
CurrentSelectedSolutionItem = null;
- if (ContainsTarget (args.Item, currentWorkspaceItem))
+ if (ContainsTarget (args.Item, CurrentSelectedWorkspaceItem))
CurrentSelectedWorkspaceItem = null;
- if ((currentItem is IBuildTarget) && ContainsTarget (args.Item, ((WorkspaceObject)currentItem)))
+ if ((CurrentSelectedItem is WorkspaceObject) && ContainsTarget (args.Item, ((WorkspaceObject)CurrentSelectedItem)))
CurrentSelectedItem = null;
}
- protected virtual void OnCurrentSelectedSolutionChanged(SolutionEventArgs e)
- {
- if (CurrentSelectedSolutionChanged != null) {
- CurrentSelectedSolutionChanged (this, e);
- }
- }
-
- protected virtual void OnCurrentProjectChanged(ProjectEventArgs e)
- {
- if (CurrentSelectedProject != null) {
- StringParserService.Properties["PROJECTNAME"] = CurrentSelectedProject.Name;
- }
- if (CurrentProjectChanged != null) {
- CurrentProjectChanged (this, e);
- }
- }
-
public event BuildEventHandler StartBuild;
public event BuildEventHandler EndBuild;
public event EventHandler BeforeStartProject;
public event CleanEventHandler StartClean;
public event CleanEventHandler EndClean;
-
- public event EventHandler<SolutionEventArgs> CurrentSelectedSolutionChanged;
- public event ProjectEventHandler CurrentProjectChanged;
+
+ public event EventHandler<SolutionEventArgs> CurrentSelectedSolutionChanged {
+ add {
+ workspace.CurrentSelectedSolutionChanged += value;
+ }
+ remove {
+ workspace.CurrentSelectedSolutionChanged -= value;
+ }
+ }
+
+ public event ProjectEventHandler CurrentProjectChanged {
+ add {
+ workspace.CurrentProjectChanged += value;
+ }
+
+ remove {
+ workspace.CurrentProjectChanged -= value;
+ }
+ }
+
public event EventHandler<ProjectCreatedEventArgs> ProjectCreated;
// Fired just before an entry is added to a combine
@@ -2619,12 +2582,10 @@ namespace MonoDevelop.Ide
public ITextDocument GetEditableTextFile (FilePath filePath)
{
- if (IdeApp.IsInitialized) {
- foreach (var doc in IdeApp.Workbench.Documents) {
- if (doc.FileName == filePath) {
- var ef = doc.Editor;
- if (ef != null) return ef;
- }
+ foreach (var doc in IdeServices.DocumentManager.Documents) {
+ if (doc.FileName == filePath) {
+ var ef = doc.Editor;
+ if (ef != null) return ef;
}
}
@@ -2665,7 +2626,7 @@ namespace MonoDevelop.Ide
{
if (filePath.IsNullOrEmpty)
throw new ArgumentNullException ("filePath");
- foreach (var doc in IdeApp.Workbench.Documents) {
+ foreach (var doc in IdeServices.DocumentManager.Documents) {
if (IsSearchedDocument (doc, filePath)) {
return doc.Editor;
}
@@ -2676,16 +2637,14 @@ namespace MonoDevelop.Ide
public ITextDocument GetTextEditorData (FilePath filePath, out bool isOpen)
{
- if (IdeApp.Workbench != null) {
- foreach (var doc in IdeApp.Workbench.Documents) {
- if (IsSearchedDocument (doc, filePath)) {
- isOpen = true;
- return doc.Editor;
- }
+ foreach (var doc in IdeServices.DocumentManager.Documents) {
+ if (IsSearchedDocument (doc, filePath)) {
+ isOpen = true;
+ return doc.Editor;
}
}
- var data = TextEditorFactory.CreateNewDocument (filePath, DesktopService.GetMimeTypeForUri(filePath));
+ var data = TextEditorFactory.CreateNewDocument (filePath, IdeServices.DesktopService.GetMimeTypeForUri(filePath));
isOpen = false;
return data;