public void FindAllReferences(Declaration declaration) { if (_state.Status != ParserState.Ready) { return; } var viewModel = CreateViewModel(declaration); if (!viewModel.SearchResults.Any()) { _messageBox.NotifyWarn(string.Format(RubberduckUI.AllReferences_NoneFound, declaration.IdentifierName), RubberduckUI.Rubberduck); return; } if (viewModel.SearchResults.Count == 1) { _navigateCommand.Execute(viewModel.SearchResults.Single().GetNavigationArgs()); return; } _viewModel.AddTab(viewModel); _viewModel.SelectedTab = viewModel; try { var presenter = _presenterService.Presenter(_viewModel); presenter.Show(); } catch (Exception e) { _logger.Error(e); } }
public void NotifyRewriteFailed(RewriteSessionState sessionState) { var message = RewriteFailureMessage(sessionState); var caption = Resources.RubberduckUI.MemberAttributeRecoveryFailureCaption; _messageBox.NotifyWarn(message, caption); }
private bool IsValidParamOrder() { var indexOfFirstOptionalParam = _model.Parameters.FindIndex(param => param.IsOptional); if (indexOfFirstOptionalParam >= 0) { for (var index = indexOfFirstOptionalParam + 1; index < _model.Parameters.Count; index++) { if (!_model.Parameters.ElementAt(index).IsOptional) { _messageBox.NotifyWarn(RubberduckUI.ReorderPresenter_OptionalParametersMustBeLastError, RubberduckUI.ReorderParamsDialog_TitleText); return(false); } } } var indexOfParamArray = _model.Parameters.FindIndex(param => param.IsParamArray); if (indexOfParamArray < 0 || indexOfParamArray == _model.Parameters.Count - 1) { return(true); } _messageBox.NotifyWarn(RubberduckUI.ReorderPresenter_ParamArrayError, RubberduckUI.ReorderParamsDialog_TitleText); return(false); }
//TODO: Gather all conflicts and report them in one error dialog instead of reporting them one at a time. private void NotifyUserAboutAbortDueToUnsupportedFileExtensions(IEnumerable <string> fileNames) { var firstUnsupportedFile = fileNames.First(filename => !ImportableExtensions.Contains(Path.GetExtension(filename))); var unsupportedFileName = Path.GetFileName(firstUnsupportedFile); var message = string.Format(RubberduckUI.ImportCommand_UnsupportedFileExtensions, unsupportedFileName); MessageBox.NotifyWarn(message, DialogsTitle); }
public void Refactor() { var activeSelection = _selectionService.ActiveSelection(); if (!activeSelection.HasValue) { _messageBox.NotifyWarn(RubberduckUI.ImplementInterface_InvalidSelectionMessage, RubberduckUI.ImplementInterface_Caption); return; } Refactor(activeSelection.Value); }
public void Refactor() { var activeSelection = _selectionService.ActiveSelection(); if (!activeSelection.HasValue) { _messageBox.NotifyWarn(RubberduckUI.MoveCloserToUsage_InvalidSelection, RubberduckUI.MoveCloserToUsage_Caption); return; } Refactor(activeSelection.Value); }
public void Refactor() { var selection = _vbe.GetActiveSelection(); if (!selection.HasValue) { _messageBox.NotifyWarn(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceParameter_Caption); return; } Refactor(selection.Value); }
public void Refactor() { var activeSelection = _selectionService.ActiveSelection(); if (!activeSelection.HasValue) { _messageBox.NotifyWarn(RubberduckUI.PromoteVariable_InvalidSelection, RubberduckUI.IntroduceField_Caption); return; } Refactor(activeSelection.Value); }
public void Refactor() { var qualifiedSelection = _vbe.GetActiveSelection(); if (qualifiedSelection != null) { Refactor(_declarations.FindVariable(qualifiedSelection.Value)); } else { _messageBox.NotifyWarn(RubberduckUI.MoveCloserToUsage_InvalidSelection, RubberduckUI.MoveCloserToUsage_Caption); } }
protected override void OnExecute(object parameter) { if (parameter is null) { return; } if (!(parameter is ValueTuple <string, ICodeExplorerNode> data)) { return; } var(templateName, node) = data; if (string.IsNullOrWhiteSpace(templateName) || !(node is CodeExplorerItemViewModel model)) { return; } var template = GetTemplate(templateName); var moduleText = template.Read(); if (string.IsNullOrWhiteSpace(moduleText)) { _messageBox.NotifyWarn(string.Format(Resources.Templates.Menu_Warning_CannotFindTemplate_Message, template.Caption, template.Name + Template.TemplateExtension), Resources.Templates.Menu_Warning_CannotFindTemplate_Caption); return; } _addComponentService.AddComponentWithAttributes(model, ComponentType, moduleText); }
public void NotifyQuickFixExecutionFailure(RewriteSessionState sessionState) { var message = FailureMessage(sessionState); var caption = Resources.Inspections.QuickFixes.ApplyQuickFixFailedCaption; _messageBox.NotifyWarn(message, caption); }
public override RemoveParametersModel Show() { if (Model.TargetDeclaration == null) { return(null); } if (Model.IsInterfaceMemberRefactoring && !UserConfirmsInterfaceTarget(Model)) { throw new RefactoringAbortedException(); } switch (Model.Parameters.Count) { case 0: var message = string.Format(RubberduckUI.RemovePresenter_NoParametersError, Model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.RemoveParamsDialog_TitleText); return(null); case 1: Model.RemoveParameters = Model.Parameters; return(Model); default: return(base.Show()); } }
public ReorderParametersModel Show() { if (_model.TargetDeclaration == null) { return(null); } if (_model.Parameters.Count < 2) { var message = string.Format(RubberduckUI.ReorderPresenter_LessThanTwoParametersError, _model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.ReorderParamsDialog_TitleText); return(null); } _view.ViewModel.Parameters = new ObservableCollection <Parameter>(_model.Parameters); _view.ShowDialog(); if (_view.DialogResult != DialogResult.OK) { return(null); } _model.Parameters = _view.ViewModel.Parameters.ToList(); return(_model); }
public RemoveParametersModel Show() { if (_model.TargetDeclaration == null) { return(null); } if (_model.Parameters.Count == 0) { var message = string.Format(RubberduckUI.RemovePresenter_NoParametersError, _model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.RemoveParamsDialog_TitleText); return(null); } if (_model.Parameters.Count == 1) { return(_model); } _view.ViewModel.Parameters = _model.Parameters.Select(p => p.ToViewModel()).ToList(); _view.ShowDialog(); if (_view.DialogResult != DialogResult.OK) { return(null); } _model.RemoveParameters = _view.ViewModel.Parameters.Where(m => m.IsRemoved).Select(vm => vm.ToModel()).ToList(); return(_model); }
public ReferenceModel TryAddReference(IVBProject project, string path) { using (var references = project.References) { try { using (var reference = references.AddFromFile(path)) { return(reference is null ? null : new ReferenceModel(reference, references.Count) { IsRecent = true }); } } catch (COMException ex) { _messageBox.NotifyWarn(ex.Message, RubberduckUI.References_AddFailedCaption); } return(null); } }
public void Refactor() { QualifiedSelection?qualifiedSelection; using (var activePane = _vbe.ActiveCodePane) { if (activePane == null || activePane.IsWrappingNullReference) { _messageBox.NotifyWarn(RubberduckUI.ImplementInterface_InvalidSelectionMessage, RubberduckUI.ImplementInterface_Caption); return; } qualifiedSelection = activePane.GetQualifiedSelection(); if (!qualifiedSelection.HasValue) { _messageBox.NotifyWarn(RubberduckUI.ImplementInterface_InvalidSelectionMessage, RubberduckUI.ImplementInterface_Caption); return; } } Refactor(qualifiedSelection.Value); }
public bool RemoveComponent(QualifiedModuleName qualifiedModuleName, bool promptToExport = true) { if (promptToExport && !TryExport(qualifiedModuleName)) { return(false); } // No file export or file successfully exported--now remove it try { _projectsRepository.RemoveComponent(qualifiedModuleName); } catch (Exception ex) { _messageBox.NotifyWarn(ex.Message, string.Format(CodeExplorerUI.RemoveError_Caption, qualifiedModuleName.ComponentName)); return(false); } return(true); }
protected override void OnExecute(object parameter) { if (_state.Status != ParserState.Ready) { return; } var declaration = FindTarget(parameter); if (declaration == null) { return; } var viewModel = CreateViewModel(declaration); if (!viewModel.SearchResults.Any()) { _messageBox.NotifyWarn(string.Format(RubberduckUI.AllReferences_NoneFound, declaration.IdentifierName), RubberduckUI.Rubberduck); return; } if (viewModel.SearchResults.Count == 1) { _navigateCommand.Execute(viewModel.SearchResults.Single().GetNavigationArgs()); return; } _viewModel.AddTab(viewModel); _viewModel.SelectedTab = viewModel; try { var presenter = _presenterService.Presenter(_viewModel); presenter.Show(); } catch (Exception e) { Console.WriteLine(e); } }
private bool Confirm(string identifier, int referencesFound) { const int threshold = 1000; if (referencesFound == 0) { _messageBox.NotifyWarn( string.Format(RubberduckUI.AllReferences_NoneFoundReference, identifier), RubberduckUI.Rubberduck); return(false); } if (referencesFound > threshold) { return(_messageBox.ConfirmYesNo( string.Format(RubberduckUI.AllReferences_PerformanceWarning, identifier, referencesFound), RubberduckUI.PerformanceWarningCaption)); } return(true); }
private void ApplyCultureConfig() { _config = _configService.Read(); var currentCulture = Resources.RubberduckUI.Culture; try { CultureManager.UICulture = CultureInfo.GetCultureInfo(_config.UserSettings.GeneralSettings.Language.Code); LocalizeResources(CultureManager.UICulture); _appMenus.Localize(); } catch (CultureNotFoundException exception) { Logger.Error(exception, "Error Setting Culture for Rubberduck"); // not accessing resources here, because setting resource culture literally just failed. _messageBox.NotifyWarn(exception.Message, "Rubberduck"); _config.UserSettings.GeneralSettings.Language.Code = currentCulture.Name; _configService.Save(_config); } }
public override ReorderParametersModel Show() { if (Model.TargetDeclaration == null) { return(null); } if (Model.IsInterfaceMemberRefactoring && !UserConfirmsInterfaceTarget(Model)) { throw new RefactoringAbortedException(); } if (Model.Parameters.Count < 2) { var message = string.Format(RubberduckUI.ReorderPresenter_LessThanTwoParametersError, Model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.ReorderParamsDialog_TitleText); return(null); } return(base.Show()); }
public override ReorderParametersModel Show() { if (Model.TargetDeclaration == null) { return(null); } if (Model.Parameters.Count < 2) { var message = string.Format(RubberduckUI.ReorderPresenter_LessThanTwoParametersError, Model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.ReorderParamsDialog_TitleText); return(null); } base.Show(); if (DialogResult != RefactoringDialogResult.Execute) { return(null); } return(Model); }
public override RemoveParametersModel Show() { if (Model.TargetDeclaration == null) { return(null); } switch (Model.Parameters.Count) { case 0: var message = string.Format(RubberduckUI.RemovePresenter_NoParametersError, Model.TargetDeclaration.IdentifierName); _messageBox.NotifyWarn(message, RubberduckUI.RemoveParamsDialog_TitleText); return(null); case 1: Model.RemoveParameters = Model.Parameters; return(Model); default: base.Show(); return(DialogResult != RefactoringDialogResult.Execute ? null : Model); } }
protected override void OnExecute(object parameter) { if (!(parameter is CodeExplorerComponentViewModel node) || node.Declaration is null) { return; } var qualifiedModuleName = node.Declaration.QualifiedModuleName; var component = _projectsProvider.Component(qualifiedModuleName); if (component is null) { return; } // "{qualifiedModuleName.Name} will be permanently deleted. Continue?" (localized) var message = string.Format(Resources.CodeExplorer.CodeExplorerUI.ConfirmBeforeDelete_Prompt, qualifiedModuleName.Name); if (!_messageBox.ConfirmYesNo(message, Resources.CodeExplorer.CodeExplorerUI.ConfirmBeforeDelete_Caption)) { return; } // Have to build the file list *before* removing the component! var files = new List <string>(); for (short i = 1; i <= component.FileCount; i++) { var fileName = component.GetFileName(i); if (fileName != null) // Unsaved components have a null filename for some reason { files.Add(component.GetFileName(i)); } } if (!_removeCommand.RemoveComponent(qualifiedModuleName, false)) { return; // Remove was cancelled or failed } var failedDeletions = new List <string>(); foreach (var file in files) { try { File.Delete(file); } catch (Exception exception) { Logger.Warn(exception, "Failed to delete file"); failedDeletions.Add(file); } } // Let the user know if there are any component files left on disk if (failedDeletions.Any()) { // "The following files could not be deleted: {fileDeletions}" (localized) message = string.Format(Resources.CodeExplorer.CodeExplorerUI.DeleteFailed_Message, string.Join(Environment.NewLine, failedDeletions)); _messageBox.NotifyWarn(message, Resources.CodeExplorer.CodeExplorerUI.DeleteFailed_Caption); } }
public void Notify(RefactoringException exception) { var message = $"{Resources.RubberduckUI.RefactoringFailure_BaseMessage}{Environment.NewLine}{Environment.NewLine}{Message(exception)}"; _messageBox.NotifyWarn(message, Caption); }