public RubberduckParserState(IVBE vbe, IDeclarationFinderFactory declarationFinderFactory) { if (vbe == null) { throw new ArgumentNullException(nameof(vbe)); } if (declarationFinderFactory == null) { throw new ArgumentNullException(nameof(declarationFinderFactory)); } _vbe = vbe; _declarationFinderFactory = declarationFinderFactory; var values = Enum.GetValues(typeof(ParserState)); foreach (var value in values) { States.Add((ParserState)value); } _hostApp = _vbe.HostApplication(); AddEventHandlers(); IsEnabled = true; RefreshFinder(_hostApp); }
private string OptionCompareStatement() { using (var hostApp = _vbe.HostApplication()) { return(hostApp?.ApplicationName == "Access" ? "Option Compare Database" : null); } }
private void Run(IEnumerable <Declaration> members) { if (_hostApplication == null) { _hostApplication = _vbe.HostApplication(); } foreach (var member in members) { _hostApplication.Run(member); } }
protected override bool EvaluateCanExecute(object parameter) { if (!base.EvaluateCanExecute(parameter) || !(parameter is CodeExplorerItemViewModel node)) { return(false); } try { var declaration = node.Declaration; if (declaration == null) { return(false); } var qualifiedModuleName = declaration.QualifiedModuleName; // ReSharper disable once SwitchStatementMissingSomeCases switch (declaration.DeclarationType) { case DeclarationType.ClassModule: return(_projectsProvider.Component(qualifiedModuleName).HasDesigner); case DeclarationType.Document: using (var app = _vbe.HostApplication()) { return(app?.CanOpenDocumentDesigner(qualifiedModuleName) ?? false); } default: return(false); } } catch (COMException) { // thrown when the component reference is stale return(false); } }
public TestCodeGenerator( IVBE vbe, RubberduckParserState state, IMessageBox messageBox, IVBEInteraction interaction, IConfigProvider <UnitTestSettings> settings, IIndenter indenter, ICompilationArgumentsProvider argumentsProvider) { _isAccess = "AccessApp".Equals(vbe?.HostApplication()?.GetType().Name); _state = state; _messageBox = messageBox; _interaction = interaction; _settings = settings; _indenter = indenter; _argumentsProvider = argumentsProvider; }
private void SetName() { _name = Declaration?.IdentifierName ?? string.Empty; if (Declaration is null) { return; } var qualifiedModuleName = Declaration.QualifiedName.QualifiedModuleName; try { switch (qualifiedModuleName.ComponentType) { case ComponentType.Document: using (var app = _vbe?.HostApplication()) { var document = app?.GetDocument(qualifiedModuleName); if (document != null) { var parenthesized = document.DocumentName ?? string.Empty; _name = string.IsNullOrEmpty(parenthesized) ? _name : $"{_name} ({parenthesized})"; } } break; case ComponentType.ResFile: _name = string.IsNullOrEmpty(_name) ? CodeExplorerUI.CodeExplorer_ResourceFileText : $"{CodeExplorerUI.CodeExplorer_ResourceFileText} ({Path.GetFileName(_name)})"; break; case ComponentType.RelatedDocument: _name = string.IsNullOrEmpty(_name) ? string.Empty : Path.GetFileName(_name); break; } } catch (Exception ex) { Logger.Trace(ex); } OnNameChanged(); }
public RubberduckParserState(IVBE vbe, IProjectsRepository projectRepository, IDeclarationFinderFactory declarationFinderFactory, IVbeEvents vbeEvents) { _vbe = vbe ?? throw new ArgumentNullException(nameof(vbe)); _projectRepository = projectRepository ?? throw new ArgumentException(nameof(projectRepository)); _declarationFinderFactory = declarationFinderFactory ?? throw new ArgumentNullException(nameof(declarationFinderFactory)); _vbeEvents = vbeEvents ?? throw new ArgumentNullException(nameof(vbeEvents)); var values = Enum.GetValues(typeof(ParserState)); foreach (var value in values) { States.Add((ParserState)value); } _hostApp = _vbe.HostApplication(); AddEventHandlers(); IsEnabled = true; RefreshFinder(_hostApp); }
private void Run(IEnumerable <Declaration> members) { if (_hostApplication == null) { _hostApplication = _vbe.HostApplication(); } foreach (var member in members) { try { _hostApplication.Run(member); } catch (COMException ex) { Logger.Error(ex, "Unexpected COM exception while running tests.", member?.QualifiedName); } } }
public void AddComponent(CodeExplorerItemViewModel node, string moduleText) { var nodeProject = GetDeclaration(node)?.Project; if (node != null && nodeProject == null) { return; //The project is not available. } string optionCompare; using (var hostApp = _vbe.HostApplication()) { optionCompare = hostApp?.ApplicationName == "Access" ? "Option Compare Database" : string.Empty; } using (var components = node != null ? nodeProject.VBComponents : ComponentsCollectionFromActiveProject()) { var folderAnnotation = $"'@Folder(\"{GetFolder(node)}\")"; var fileName = CreateTempTextFile(moduleText); using (var newComponent = components.Import(fileName)) { using (var codeModule = newComponent.CodeModule) { if (optionCompare.Length > 0) { codeModule.InsertLines(1, optionCompare); } if (folderAnnotation.Length > 0) { codeModule.InsertLines(1, folderAnnotation); } codeModule.CodePane.Show(); } } File.Delete(fileName); } }
public ParseCoordinator( IVBE vbe, RubberduckParserState state, IAttributeParser attributeParser, Func <IVBAPreprocessor> preprocessorFactory, IEnumerable <ICustomDeclarationLoader> customDeclarationLoaders, bool isTestScope = false, string serializedDeclarationsPath = null) { _vbe = vbe; _state = state; _attributeParser = attributeParser; _preprocessorFactory = preprocessorFactory; _customDeclarationLoaders = customDeclarationLoaders; _isTestScope = isTestScope; _serializedDeclarationsPath = serializedDeclarationsPath ?? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "declarations"); _hostApp = _vbe.HostApplication(); state.ParseRequest += ReparseRequested; }
public TestMethod(Declaration declaration, IVBE vbe) { _declaration = declaration; _hostApp = vbe.HostApplication(); }
public CodeExplorerComponentViewModel(CodeExplorerItemViewModel parent, Declaration declaration, IEnumerable <Declaration> declarations, IProjectsProvider projectsProvider, IVBE vbe) { Parent = parent; Declaration = declaration; _projectsProvider = projectsProvider; _vbe = vbe; _icon = Icons.ContainsKey(DeclarationType) ? Icons[DeclarationType] : GetImageSource(CodeExplorerUI.status_offline); Items = declarations.GroupBy(item => item.Scope).SelectMany(grouping => grouping.Where(item => item.ParentDeclaration != null && item.ParentScope == declaration.Scope && MemberTypes.Contains(item.DeclarationType)) .OrderBy(item => item.QualifiedSelection.Selection.StartLine) .Select(item => new CodeExplorerMemberViewModel(this, item, grouping))) .ToList <CodeExplorerItemViewModel>(); _name = DeclarationType == DeclarationType.ResFile && string.IsNullOrEmpty(Declaration.IdentifierName) ? CodeExplorerUI.CodeExplorer_ResourceFileText : Declaration.IdentifierName; var qualifiedModuleName = declaration.QualifiedName.QualifiedModuleName; try { switch (qualifiedModuleName.ComponentType) { case ComponentType.Document: var parenthesizedName = string.Empty; var state = DocumentState.Inaccessible; using (var app = _vbe.HostApplication()) { if (app != null) { var document = app.GetDocument(qualifiedModuleName); parenthesizedName = document?.DocumentName ?? string.Empty; state = document?.State ?? DocumentState.Inaccessible; } } if (state == DocumentState.DesignView && ContainsBuiltinDocumentPropertiesProperty()) { CodeExplorerItemViewModel node = this; while (node.Parent != null) { node = node.Parent; } ((CodeExplorerProjectViewModel)node).SetParenthesizedName(parenthesizedName); } else { if (!string.IsNullOrWhiteSpace(parenthesizedName)) { _name += " (" + parenthesizedName + ")"; } } break; case ComponentType.ResFile: var fileName = Declaration.IdentifierName.Split('\\').Last(); _name = $"{CodeExplorerUI.CodeExplorer_ResourceFileText} ({fileName})"; break; case ComponentType.RelatedDocument: _name = $"({Declaration.IdentifierName.Split('\\').Last()})"; break; default: _name = Declaration.IdentifierName; break; } } catch { // gotcha! (this means that the property either doesn't exist or we weren't able to get it for some reason) } }