diff options
Diffstat (limited to 'main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs')
-rw-r--r-- | main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs | 56 |
1 files changed, 33 insertions, 23 deletions
diff --git a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs index 8c3540eacd..be0378ce09 100644 --- a/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs +++ b/main/src/addins/MonoDevelop.PackageManagement/MonoDevelop.PackageManagement.Commands/PackagesCommandHandler.cs @@ -56,38 +56,34 @@ namespace MonoDevelop.PackageManagement.Commands protected DotNetProject GetSelectedDotNetProject ()
{
- return IdeApp.ProjectOperations.CurrentSelectedProject as DotNetProject;
- }
-
- protected bool SelectedDotNetProjectHasPackages ()
- {
- DotNetProject project = GetSelectedDotNetProject ();
- return (project != null) && project.HasPackages ();
+ return CurrentSelectedProject as DotNetProject;
}
protected bool IsDotNetSolutionSelected ()
{
- return IdeApp.ProjectOperations.CurrentSelectedSolution != null;
+ return CurrentSelectedSolution != null;
}
- protected bool SelectedDotNetSolutionHasPackages ()
- {
- Solution solution = IdeApp.ProjectOperations.CurrentSelectedSolution;
- if (solution == null) {
- return false;
+ protected bool CanRestoreSelectedDotNetProjectOrSolution () + { + if (IsDotNetProjectSelected ()) {
+ return CanRestorePackagesForSelectedDotNetProject ();
+ } else if (IsDotNetSolutionSelected ()) {
+ return CanRestorePackagesForSelectedSolution ();
}
+ return false;
+ }
- return solution.HasAnyProjectWithPackages ();
+ protected bool CanRestorePackagesForSelectedDotNetProject ()
+ { + DotNetProject project = GetSelectedDotNetProject ();
+ return project?.CanRestorePackages () == true;
}
- protected bool SelectedDotNetProjectOrSolutionHasPackages ()
+ bool CanRestorePackagesForSelectedSolution ()
{
- if (IsDotNetProjectSelected ()) {
- return SelectedDotNetProjectHasPackages ();
- } else if (IsDotNetSolutionSelected ()) {
- return SelectedDotNetSolutionHasPackages ();
- }
- return false;
+ Solution solution = CurrentSelectedSolution;
+ return solution?.CanRestorePackages () == true;
}
protected Solution GetSelectedSolution ()
@@ -96,7 +92,7 @@ namespace MonoDevelop.PackageManagement.Commands if (project != null) {
return project.ParentSolution;
}
- return IdeApp.ProjectOperations.CurrentSelectedSolution;
+ return CurrentSelectedSolution;
}
protected bool CanUpdatePackagesForSelectedDotNetProject () @@ -107,7 +103,7 @@ namespace MonoDevelop.PackageManagement.Commands bool CanUpdatePackagesForSelectedDotNetSolution ()
{
- Solution solution = IdeApp.ProjectOperations.CurrentSelectedSolution;
+ Solution solution = CurrentSelectedSolution;
return solution?.CanUpdatePackages () == true;
} @@ -120,5 +116,19 @@ namespace MonoDevelop.PackageManagement.Commands }
return false;
}
+
+ /// <summary> + /// Used by unit tests to avoid having to initialize the IDE workspace. + /// </summary>
+ protected virtual Solution CurrentSelectedSolution {
+ get { return IdeApp.ProjectOperations.CurrentSelectedSolution; }
+ } + + /// <summary> + /// Used by unit tests to avoid having to initialize the IDE workspace. + /// </summary> + protected virtual Project CurrentSelectedProject {
+ get { return IdeApp.ProjectOperations.CurrentSelectedProject; }
+ }
}
}
|