コード例 #1
0
        public static string GetDefaultNamespace(AIMS.Libraries.Scripting.ScriptControl.Project.IProject project, string fileName)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            if (fileName == null)
            {
                throw new ArgumentNullException("fileName");
            }

            string relPath = FileUtility.GetRelativePath(project.Directory, Path.GetDirectoryName(project.Directory + fileName));

            string[]      subdirs           = relPath.Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            StringBuilder standardNameSpace = new StringBuilder(project.RootNamespace);

            foreach (string subdir in subdirs)
            {
                if (subdir == "." || subdir == ".." || subdir.Length == 0)
                {
                    continue;
                }
                if (subdir.Equals("src", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                if (subdir.Equals("source", StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                standardNameSpace.Append('.');
                standardNameSpace.Append(NewFileDialog.GenerateValidClassOrNamespaceName(subdir, true));
            }
            return(standardNameSpace.ToString());
        }
コード例 #2
0
        private string GetInitialContents(NewFileDialog f, string fileName)
        {
            string defNameSpace = NewFileDialog.GetDefaultNamespace(m_AIMSProject, fileName);
            string defClassName = NewFileDialog.GenerateValidClassOrNamespaceName(Path.GetFileNameWithoutExtension(fileName), true);

            StringBuilder contents = new StringBuilder();

            if (_scriptLanguage == ScriptLanguage.CSharp)
            {
                contents.AppendLine("#region Usings ...");
                contents.AppendLine("using System;");
                contents.AppendLine("using System.Collections.Generic;");
                contents.AppendLine("using System.Text;");
                contents.AppendLine("#endregion");
                contents.AppendLine("");
                contents.AppendLine("namespace " + defNameSpace);
                contents.AppendLine("{");
                contents.AppendLine("    " + (f.SelectedItemType == SelectedItemType.Class ? "class " : "interface ") + defClassName);
                contents.AppendLine("    {");
                contents.AppendLine("");
                contents.AppendLine("    }");
                contents.AppendLine("}");
            }
            else
            {
                contents.AppendLine("#Region Usings ...");
                contents.AppendLine("Imports System");
                contents.AppendLine("Imports System.Collections.Generic");
                contents.AppendLine("Imports System.Text");
                contents.AppendLine("#End Region");
                contents.AppendLine("");
                contents.AppendLine("Namespace " + defNameSpace);
                contents.AppendLine("    " + (f.SelectedItemType == SelectedItemType.Class ? "Class " : "Interface ") + defClassName);
                contents.AppendLine("");
                contents.AppendLine("    End " + (f.SelectedItemType == SelectedItemType.Class ? "Class" : "Interface"));
                contents.AppendLine("End Namespace");
            }

            return(contents.ToString());
        }
コード例 #3
0
        private void AddNewItem()
        {
            dockContainer1.SuspendLayout();
            StringCollection files = new StringCollection();

            foreach (string Name in Parser.ProjectParser.ProjectFiles.Keys)
            {
                files.Add(Name);
            }
            NewFileDialog f = new NewFileDialog(_scriptLanguage, files);

            f.ShowDialog(dockContainer1);
            string fileName = f.FileName;

            if (fileName.Length > 0)
            {
                Document doc = AddDocument(fileName);
                doc.Editor.ActiveViewControl.Document.Text = GetInitialContents(f, fileName);
                doc.ParseContentsNow();
                doc.Editor.ActiveViewControl.Caret.Position = new TextPoint(0, 1);
            }

            dockContainer1.ResumeLayout();
        }