public void RunStarted(object automationObject,
                           Dictionary <string, string> replacementsDictionary,
                           WizardRunKind runKind,
                           object[] customParams)
    {
        using var _ = LogUserAction(UserTask.CreateFromTemplate, new TemplateInfo(runKind, replacementsDictionary));
        Assert(automationObject is DTE2, "Automation Object is wrong kind");
        if (automationObject is DTE2 dte)
        {
            var replacementDictionaryLookup = replacementsDictionary.TryGetValue("$type$", out var result);
            Assert(replacementDictionaryLookup, "Invalid replacements dictionary in template file");
            if (!replacementDictionaryLookup)
            {
                return;
            }

            bool isDotnet = StringComparer.OrdinalIgnoreCase.Compare(result, "dotnet") == 0;
            (bool success, string fileName) = EditorConfigFileGenerator.TryAddFileToSolution(isDotnet);
            Assert(success, "Unable to add the editorconfig file to the solution");

            if (success)
            {
                VSHelpers.OpenFile(fileName);
            }
        }
    }
    protected override bool Execute(List <WorkspaceVisualNodeBase> selection)
    {
        Assert(selection.Count == 1, "Multiple items selected");
        if (selection.Count == 1 && selection[0] is IFolderNode folder)
        {
            using var _1 = LogUserAction(UserTask.CreateFromRightClickMenuAnyCode);
            _            = EditorConfigFileGenerator.TryAddFileToFolder(folder.FullPath);
            return(true);
        }

        return(false);
    }
Example #3
0
    protected override async Task ExecuteAsync(OleMenuCmdEventArgs e)
    {
        using var _ = LogUserAction(UserTask.CreateFromRightClickMenu);
        await Package.JoinableTaskFactory.SwitchToMainThreadAsync(Package.DisposalToken);

        var(success, fileName) = EditorConfigFileGenerator.TryAddFileToSolution();
        Assert(success, "Unable to add the editorconfig file to the solution");

        if (success)
        {
            VSHelpers.OpenFile(fileName);
        }
    }
    public void RunStarted(object automationObject,
                           Dictionary <string, string> replacementsDictionary,
                           WizardRunKind runKind,
                           object[] customParams)
    {
        if (automationObject is DTE2 dte)
        {
            if (!replacementsDictionary.TryGetValue("$type$", out var result))
            {
                return;
            }

            var generator = new EditorConfigFileGenerator(dte);

            bool isDotnet = StringComparer.OrdinalIgnoreCase.Compare(result, "dotnet") == 0;
            (bool success, string fileName) = generator.TryGenerateFile(isDotnet);
            if (success)
            {
                generator.OpenFile(fileName);
            }
        }
    }
        private static SourceText WithNamingStyles(SourceText sourceText, IEnumerable <NamingRule> rules, Language language)
        {
            if (rules.Any())
            {
                var parseResult           = NamingStylesParser.Parse(sourceText, null); // file path unnecessary here
                var newNamingStyleSection = new StringBuilder();
                if (parseResult.TryGetSectionForLanguage(language, out var existingSection))
                {
                    var span = new TextSpan(existingSection.Span.End, 0);
                    EditorConfigFileGenerator.AppendNamingStylePreferencesToEditorConfig(rules, newNamingStyleSection, GetLanguageString(language));
                    return(WithChanges(sourceText, span, newNamingStyleSection.ToString()));
                }
                else
                {
                    var span = new TextSpan(sourceText.Length, 0);
                    newNamingStyleSection.Append("\r\n");
                    newNamingStyleSection.Append(Section.GetHeaderTextForLanguage(language));
                    EditorConfigFileGenerator.AppendNamingStylePreferencesToEditorConfig(rules, newNamingStyleSection, GetLanguageString(language));
                    return(WithChanges(sourceText, span, newNamingStyleSection.ToString()));
                }
            }

            return(sourceText);