private bool TryExport(QualifiedModuleName qualifiedModuleName)
        {
            var component = _projectsRepository.Component(qualifiedModuleName);

            if (component is null)
            {
                return(false); // Edge-case, component already gone.
            }

            if (_vbe.Kind == VBEKind.Standalone && component.IsSaved)
            {
                return(true); // File already up-to-date
            }

            // "Do you want to export '{qualifiedModuleName.Name}' before removing?" (localized)
            var message = string.Format(CodeExplorerUI.ExportBeforeRemove_Prompt, qualifiedModuleName.Name);

            switch (_messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes))
            {
            case ConfirmationOutcome.No:
                // User elected to remove without export, return success.
                return(true);

            case ConfirmationOutcome.Yes:
                if (_exportCommand.PromptFileNameAndExport(qualifiedModuleName))
                {
                    // Export complete
                    return(true);
                }
                break;
            }

            return(false); // Save dialog cancelled or export failed (failures will have already been displayed and logged by this point)
        }
示例#2
0
        protected override void OnExecute(object parameter)
        {
            var message = string.Format(CodeExplorerUI.ExportBeforeRemove_Prompt, ((CodeExplorerComponentViewModel)parameter).Name);
            var result  = _messageBox.Confirm(message, CodeExplorerUI.ExportBeforeRemove_Caption, ConfirmationOutcome.Yes);

            if (result == ConfirmationOutcome.Cancel)
            {
                return;
            }

            if (result == ConfirmationOutcome.Yes && !ExportFile((CodeExplorerComponentViewModel)parameter))
            {
                return;
            }

            // No file export or file successfully exported--now remove it

            // I know this will never be null because of the CanExecute
            var declaration         = ((CodeExplorerComponentViewModel)parameter).Declaration;
            var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName;
            var components          = _projectsProvider.ComponentsCollection(qualifiedModuleName.ProjectId);

            components?.Remove(_projectsProvider.Component(qualifiedModuleName));
        }