예제 #1
0
        private void SetupFileTemplates()
        {
            var formDesignerClassTemplate = new NetAstFileTemplate(
                "%file%.Designer",
                "%file%",
                null,
                this,
                CodeDomUnitFactory.CreateFormDesignerClass("%folder%", "%file%"));

            var formClassTemplate = new NetAstFileTemplate(
                "%file%",
                null,
                null,
                CodeEditorExtension.Instance,
                CodeDomUnitFactory.CreateFormClass("%folder%", "%file%"));

            var formTemplate = new NetFormTemplate(
                "Form",
                Properties.Resources.window_new,
                this,
                formDesignerClassTemplate, formClassTemplate);

            LanguageDescriptor.GetLanguage <CSharpLanguage>().Templates.Add(formTemplate);
            LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Templates.Add(formTemplate);
        }
예제 #2
0
        private void SetupProjectTemplates()
        {
            var programTemplate = new NetAstFileTemplate("Program", "Program", null, this, CodeDomUnitFactory.CreateEntryPointModuleUnit("%folder%", "Program"));

            LanguageDescriptor.GetLanguage <CSharpLanguage>().Templates.Add(new NetProjectTemplate(
                                                                                "Console Application",
                                                                                Properties.Resources.console,
                                                                                LanguageDescriptor.GetLanguage <CSharpLanguage>(),
                                                                                SubSystem.Console, programTemplate));

            LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Templates.Add(new NetProjectTemplate(
                                                                                     "Console Application",
                                                                                     Properties.Resources.console,
                                                                                     LanguageDescriptor.GetLanguage <VisualBasicLanguage>(),
                                                                                     SubSystem.Console,
                                                                                     programTemplate));

            programTemplate = new NetAstFileTemplate("Class1", "Class1", null, this, CodeDomUnitFactory.CreateClassUnit("%folder%", "Class1"));

            LanguageDescriptor.GetLanguage <CSharpLanguage>().Templates.Add(new NetProjectTemplate(
                                                                                "Class Library",
                                                                                Properties.Resources.dll,
                                                                                LanguageDescriptor.GetLanguage <CSharpLanguage>(),
                                                                                SubSystem.Library, programTemplate));

            LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Templates.Add(new NetProjectTemplate(
                                                                                     "Class Library",
                                                                                     Properties.Resources.dll,
                                                                                     LanguageDescriptor.GetLanguage <VisualBasicLanguage>(),
                                                                                     SubSystem.Library,
                                                                                     programTemplate));
        }
예제 #3
0
        private void SetupFileTemplates()
        {
            var icon = Properties.Resources.file;

            foreach (var descriptor in LanguageDescriptor.RegisteredLanguages)
            {
                descriptor.Templates.Add(new SourceFileTemplate("Empty File", icon, this, string.Empty));
            }

            LanguageDescriptor.GetLanguage <CSharpLanguage>().Templates.Add(
                new NetAstFileTemplate(
                    "Class File",
                    null,
                    Properties.Resources.csharp_file_icon.ToBitmap(),
                    this,
                    CodeDomUnitFactory.CreateClassUnit("%folder%", "%file%")));

            LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Templates.Add(
                new NetAstFileTemplate(
                    "Class File",
                    null,
                    Properties.Resources.vb_file_icon.ToBitmap(),
                    this,
                    CodeDomUnitFactory.CreateClassUnit("%folder%", "%file%")));

            LanguageDescriptor.GetLanguage <HtmlLanguage>().Templates.Add(
                new SourceFileTemplate(
                    "Web page",
                    Properties.Resources.html_file_icon,
                    this,
                    Properties.Resources.HtmlPageFile,
                    (f) => { f.SetContents(f.GetContentsAsString().Replace("%file%", f.FilePath.FileName)); }));
        }
예제 #4
0
        /// <inheritdoc />
        protected override TemplateResult CreateFileCore(IFileService fileService, Project parentProject, FilePath filePath)
        {
            string @namespace = "MyNamespace";

            if (parentProject != null && parentProject is NetProject)
            {
                @namespace = (parentProject as NetProject).RootNamespace;
                var relativePath = filePath.ParentDirectory.GetRelativePath(parentProject);
                if (!string.IsNullOrEmpty(relativePath))
                {
                    @namespace += "." + relativePath.Replace(Path.DirectorySeparatorChar, '.');
                }
            }

            var language     = (LanguageDescriptor.GetLanguageByPath(filePath) as NetLanguageDescriptor);
            var codeProvider = language.CodeProvider;
            var fileName     = filePath.FileName;

            using (var stringWriter = new StringWriter())
            {
                // generate source
                using (var writer = new IndentedTextWriter(stringWriter))
                {
                    codeProvider.GenerateCodeFromCompileUnit(CompileUnit, writer, new CodeGeneratorOptions()
                    {
                        BlankLinesBetweenMembers = true,
                        BracingStyle             = "C",
                    });
                }

                string source = stringWriter.ToString();

                // replace auto generated message.
                var match = Regex.Match(source, string.Format("{0}[^\r\n]+\r\n[^{0}]", language.CommentPrefix));
                if (match.Success)
                {
                    source = source.Remove(0, match.Index + match.Length);
                }

                // VbCodeProvider adds two option statements which should be removed as well because they are specified by default in the project settings.
                if (language.Name == LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Name)
                {
                    match = Regex.Match(source, @"Option\s+\w+\s+\w+\s+Option\s+\w+\s+\w+");
                    if (match.Success)
                    {
                        source = source.Remove(0, match.Index + match.Length);
                    }
                }

                // create file instance.
                source = source.Replace("%folder%", @namespace)
                         .Replace("%file%", (string.IsNullOrEmpty(ObjectName) ? fileName : ObjectName));

                var file = fileService.CreateFile(filePath, Encoding.UTF8.GetBytes(source));
                return(new TemplateResult(new CreatedFile(file, ExtensionToUse)));
            }
        }
        private string[] GetModifiers(string input)
        {
            MatchCollection matches = Regex.Matches(input, BuildRegexAlternativeRange(LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Modifiers));

            string[] output = new string[matches.Count];

            for (int i = 0; i < matches.Count; i++)
            {
                output[i] = matches[i].Value;
            }

            return(output);
        }
예제 #6
0
        private void SetupProjectTemplates()
        {
            var programClassTemplate = new NetAstFileTemplate("Program", "Program", null, CodeEditorExtension.Instance, CodeDomUnitFactory.CreateEntryPointModuleUnit("%folder%", "Program"));

            var method = programClassTemplate.CompileUnit.Namespaces[1].Types[0].Members[0] as CodeMemberMethod;

            method.CustomAttributes.Add(new CodeAttributeDeclaration(new CodeTypeReference(typeof(STAThreadAttribute))));
            method.Statements.AddRange(new CodeStatement[]
            {
                new CodeExpressionStatement(
                    new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            new CodeTypeReferenceExpression(typeof(Application)),
                            "EnableVisualStyles"))),
                new CodeExpressionStatement(
                    new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            new CodeTypeReferenceExpression(typeof(Application)),
                            "SetCompatibleTextRenderingDefault"),
                        new CodePrimitiveExpression(false))),
                new CodeExpressionStatement(
                    new CodeMethodInvokeExpression(
                        new CodeMethodReferenceExpression(
                            new CodeTypeReferenceExpression(typeof(Application)),
                            "Run"),
                        new CodeObjectCreateExpression("Form1"))),
            });

            var formClassTemplate = new NetAstFileTemplate(
                "Form1",
                "Form1",
                null,
                CodeEditorExtension.Instance,
                CodeDomUnitFactory.CreateFormClass("%folder%", "Form1"));
            var formDesignerClassTemplate = new NetAstFileTemplate(
                "Form1.Designer",
                "Form1",
                null,
                this,
                CodeDomUnitFactory.CreateFormDesignerClass("%folder%", "Form1"));

            var formTemplate = new NetFormTemplate(
                "Form1",
                Properties.Resources.window_new,
                this,
                formDesignerClassTemplate, formClassTemplate);

            var csProject = new NetProjectTemplate(
                "Windows Forms Application",
                Properties.Resources.window_list,
                LanguageDescriptor.GetLanguage <CSharpLanguage>(),
                SubSystem.Windows,
                programClassTemplate,
                formTemplate);

            csProject.References.AddRange(new string[] { "System.Drawing.dll", "System.Windows.Forms.dll" });

            LanguageDescriptor.GetLanguage <CSharpLanguage>().Templates.Add(csProject);

            var vbProject = new NetProjectTemplate(
                "Windows Forms Application",
                Properties.Resources.window_list,
                LanguageDescriptor.GetLanguage <VisualBasicLanguage>(),
                SubSystem.Windows,
                programClassTemplate,
                formTemplate);

            vbProject.References.AddRange(new string[] { "System.Drawing.dll", "System.Windows.Forms.dll" });

            LanguageDescriptor.GetLanguage <VisualBasicLanguage>().Templates.Add(vbProject);
        }