public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr)) { Logger.LogVerbose("Find Step Definition Usages"); var textBuffer = textView.TextBuffer; var fileName = GetEditorDocumentPath(textView); var triggerPoint = textView.Caret.Position.BufferPosition; var project = IdeScope.GetProject(textBuffer); if (project == null || !project.GetProjectSettings().IsSpecFlowProject) { IdeScope.Actions.ShowProblem("Unable to find step definition usages: the project is not detected to be a SpecFlow project or it is not initialized yet."); return(true); } var specFlowTestProjects = IdeScope.GetProjectsWithFeatureFiles() .Where(p => p.GetProjectSettings().IsSpecFlowTestProject) .ToArray(); if (specFlowTestProjects.Length == 0) { IdeScope.Actions.ShowProblem("Unable to find step definition usages: could not find any SpecFlow project with feature files."); return(true); } var asyncContextMenu = IdeScope.Actions.ShowAsyncContextMenu(PopupHeader); Task.Run(() => FindUsagesInProjectsAsync(specFlowTestProjects, fileName, triggerPoint, asyncContextMenu, asyncContextMenu.CancellationToken), asyncContextMenu.CancellationToken); return(true); }
public override DeveroomEditorCommandStatus QueryStatus(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey) { var projectScope = IdeScope.GetProject(textView.TextBuffer); var projectSettings = projectScope?.GetProjectSettings(); if (projectScope == null || !projectSettings.IsSpecFlowProject) { return(DeveroomEditorCommandStatus.Disabled); } return(base.QueryStatus(textView, commandKey)); }
public override bool PreExec(IWpfTextView textView, DeveroomEditorCommandTargetKey commandKey, IntPtr inArgs = default(IntPtr)) { Logger.LogVerbose("Create Step Definitions"); var projectScope = IdeScope.GetProject(textView.TextBuffer); var projectSettings = projectScope?.GetProjectSettings(); if (projectScope == null || !projectSettings.IsSpecFlowProject) { IdeScope.Actions.ShowProblem("Define steps command can only be invoked for feature files in SpecFlow projects"); return(true); } var featureTag = GetDeveroomTagForCaret(textView, DeveroomTagTypes.FeatureBlock); if (featureTag == null) { Logger.LogWarning("Define steps command called for a file without feature block"); return(true); } var snippetService = projectScope.GetSnippetService(); if (snippetService == null) { return(true); } var undefinedStepTags = featureTag.GetDescendantsOfType(DeveroomTagTypes.UndefinedStep).ToArray(); if (undefinedStepTags.Length == 0) { IdeScope.Actions.ShowProblem("All steps have been defined in this file already."); return(true); } const string indent = " "; string newLine = Environment.NewLine; var feature = (Feature)featureTag.Data; var viewModel = new CreateStepDefinitionsDialogViewModel(); viewModel.ClassName = feature.Name.ToIdentifier() + "Steps"; foreach (var undefinedStepTag in undefinedStepTags) { var matchResult = (MatchResult)undefinedStepTag.Data; foreach (var match in matchResult.Items.Where(mi => mi.Type == MatchResultType.Undefined)) { var snippet = snippetService.GetStepDefinitionSkeletonSnippet(match.UndefinedStep, indent, newLine); if (viewModel.Items.Any(i => i.Snippet == snippet)) { continue; } viewModel.Items.Add(new StepDefinitionSnippetItemViewModel { Snippet = snippet }); } } IdeScope.WindowManager.ShowDialog(viewModel); if (viewModel.Result == CreateStepDefinitionsDialogResult.Cancel) { return(true); } if (viewModel.Items.Count(i => i.IsSelected) == 0) { IdeScope.Actions.ShowProblem("No snippet was selected"); return(true); } var combinedSnippet = string.Join(newLine, viewModel.Items.Where(i => i.IsSelected).Select(i => i.Snippet.Indent(indent + indent))); MonitoringService.MonitorCommandDefineSteps(viewModel.Result, viewModel.Items.Count(i => i.IsSelected)); switch (viewModel.Result) { case CreateStepDefinitionsDialogResult.Create: SaveAsStepDefinitionClass(projectScope, combinedSnippet, viewModel.ClassName, indent, newLine); break; case CreateStepDefinitionsDialogResult.CopyToClipboard: Logger.LogVerbose($"Copy to clipboard: {combinedSnippet}"); IdeScope.Actions.SetClipboardText(combinedSnippet); break; } return(true); }
private IProjectScope GetProjectScope(ITextBuffer textBuffer) { return(IdeScope.GetProject(textBuffer)); }