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);
        }
 public CreateStepDefinitionsDialog(CreateStepDefinitionsDialogViewModel viewModel, IVsUIShell vsUiShell = null) : base(vsUiShell)
 {
     ViewModel        = viewModel;
     viewModel.Result = CreateStepDefinitionsDialogResult.Cancel;
     InitializeComponent();
 }