Exemplo n.º 1
0
        private bool Remove(bool removeFromStorage, bool showPrompt)
        {
            if (!_canRemove || (removeFromStorage && !_canDelete))
            {
                // Prevent the environment from being deleted or removed if not
                // supported.
                throw new NotSupportedException();
            }

            if (_factory != null && _interpreterService.IsInterpreterLocked(_factory, InstallPackageLockMoniker))
            {
                // Prevent the environment from being deleted while installing.
                // This situation should not occur through the UI, but might be
                // invocable through DTE.
                return(false);
            }

            if (showPrompt && !Utilities.IsInAutomationFunction(ProjectMgr.Site))
            {
                string message = !removeFromStorage?
                                 Strings.EnvironmentRemoveConfirmation.FormatUI(Caption) :
                                     _factory == null?
                                     Strings.EnvironmentDeleteConfirmation_NoPath.FormatUI(Caption) :
                                         Strings.EnvironmentDeleteConfirmation.FormatUI(Caption, _factory.Configuration.PrefixPath);

                int res = VsShellUtilities.ShowMessageBox(
                    ProjectMgr.Site,
                    string.Empty,
                    message,
                    OLEMSGICON.OLEMSGICON_WARNING,
                    OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                if (res != 1)
                {
                    return(false);
                }
            }

            //Make sure we can edit the project file
            if (!ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            if (!string.IsNullOrEmpty(_absentId))
            {
                Debug.Assert(!removeFromStorage, "Cannot remove absent environment from storage");
                ProjectMgr.RemoveInterpreterFactory(_absentId);
                return(true);
            }

            if (_factory == null)
            {
                Debug.Fail("Attempted to remove null factory from project");
                return(true);
            }

            ProjectMgr.RemoveInterpreter(_factory, !_isReference && removeFromStorage && _canDelete);
            return(true);
        }
Exemplo n.º 2
0
        private void Remove(bool removeFromStorage, bool showPrompt)
        {
            if (!_canRemove || (removeFromStorage && !_canDelete))
            {
                // Prevent the environment from being deleted or removed if not
                // supported.
                throw new NotSupportedException();
            }

            var service = _interpreterService as IInterpreterOptionsService2;

            if (service != null && service.IsInterpreterLocked(_factory, InstallPackageLockMoniker))
            {
                // Prevent the environment from being deleted while installing.
                // This situation should not occur through the UI, but might be
                // invocable through DTE.
                return;
            }

            if (showPrompt && !Utilities.IsInAutomationFunction(ProjectMgr.Site))
            {
                string message = (removeFromStorage ?
                                  Strings.EnvironmentDeleteConfirmation :
                                  Strings.EnvironmentRemoveConfirmation
                                  ).FormatUI(
                    Caption,
                    _factory.Configuration.PrefixPath
                    );
                int res = VsShellUtilities.ShowMessageBox(
                    ProjectMgr.Site,
                    string.Empty,
                    message,
                    OLEMSGICON.OLEMSGICON_WARNING,
                    OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                if (res != 1)
                {
                    return;
                }
            }

            //Make sure we can edit the project file
            if (!ProjectMgr.QueryEditProjectFile(false))
            {
                throw Marshal.GetExceptionForHR(VSConstants.OLE_E_PROMPTSAVECANCELLED);
            }

            ProjectMgr.RemoveInterpreter(_factory, !_isReference && removeFromStorage && _canDelete);
        }