Наследование: MonoDevelop.Ide.Templates.FileDescriptionTemplate
Пример #1
0
        public void InitializeTest(string extension)
        {
            var xmlDocument = new XmlDocument();

            switch (extension)
            {
            case ".resx":
                xmlDocument.LoadXml(ResourcesFileXml);
                break;

            case ".tt":
                xmlDocument.LoadXml(T4FileXml);
                break;

            case ".cshtml":
                xmlDocument.LoadXml(RazorFileXml);
                break;

            default:
                xmlDocument.LoadXml(FileXml);
                break;
            }

            fileDescriptionTemplate = new SingleFileDescriptionTemplate();
            fileDescriptionTemplate.Load(xmlDocument.DocumentElement, null);
        }
Пример #2
0
        public virtual bool CanCreateUnsavedFiles(FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                return(true);
            }
            else
            {
                SingleFileDescriptionTemplate singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    return(false);
                }

                if (directory != null)
                {
                    return(true);
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    string mimeType = GuessMimeType(fileName);
                    return(DisplayBindingService.GetDefaultViewBinding(null, mimeType, null) != null);
                }
            }
        }
Пример #3
0
        protected virtual bool CreateFile(FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                if (newfile.AddToProject(policyParent, project, language, directory, name))
                {
                    newfile.Show();
                    return(true);
                }
            }
            else
            {
                SingleFileDescriptionTemplate singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    throw new InvalidOperationException("Single file template expected");
                }

                if (directory != null)
                {
                    string fileName = singleFile.SaveFile(policyParent, project, language, directory, name);
                    if (fileName != null)
                    {
                        IdeApp.Workbench.OpenDocument(fileName);
                        return(true);
                    }
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    Stream stream   = singleFile.CreateFileContent(policyParent, project, language, fileName, name);

                    // Guess the mime type of the new file
                    string fn  = Path.GetTempFileName();
                    string ext = Path.GetExtension(fileName);
                    int    n   = 0;
                    while (File.Exists(fn + n + ext))
                    {
                        n++;
                    }
                    FileService.MoveFile(fn, fn + n + ext);
                    string mimeType = DesktopService.GetMimeTypeForUri(fn + n + ext);
                    FileService.DeleteFile(fn + n + ext);
                    if (mimeType == null || mimeType == "")
                    {
                        mimeType = "text";
                    }

                    IdeApp.Workbench.NewDocument(fileName, mimeType, stream);
                    return(true);
                }
            }
            return(false);
        }
		public override void Load (XmlElement filenode)
		{
			foreach (XmlNode node in filenode.ChildNodes) {
				if (node is XmlElement) {
					template = CreateTemplate ((XmlElement) node) as SingleFileDescriptionTemplate;
					if (template == null)
						throw new InvalidOperationException ("Resource templates must contain single-file templates.");
					return;
				}
			}
		}
 public override void Load(XmlElement filenode, FilePath baseDirectory)
 {
     foreach (XmlNode node in filenode.ChildNodes)
     {
         if (node is XmlElement)
         {
             template = CreateTemplate((XmlElement)node, baseDirectory) as SingleFileDescriptionTemplate;
             if (template == null)
             {
                 throw new InvalidOperationException("Resource templates must contain single-file templates.");
             }
             return;
         }
     }
 }
Пример #6
0
		public override void Load (XmlElement filenode, FilePath baseDirectory)
		{
			foreach (XmlNode node in filenode.ChildNodes) {
				if (node is XmlElement) {
					template = CreateTemplate ((XmlElement) node, baseDirectory) as SingleFileDescriptionTemplate;
					if (template == null)
						throw new InvalidOperationException ("Resource templates must contain single-file templates.");
					var attr = node.Attributes ["CopyToOutputDirectory"];
					if (attr != null) {
						Enum.TryParse<FileCopyMode> ( attr.Value, out mode);
					}
					return;
				}
			}
		}
Пример #7
0
        protected virtual bool CreateFile(FileDescriptionTemplate newfile, SolutionItem policyParent, Project project, string directory, string language, string name)
        {
            if (project != null)
            {
                var model = project.GetStringTagModel(new DefaultConfigurationSelector());
                newfile.SetProjectTagModel(model);
                try {
                    if (newfile.AddToProject(policyParent, project, language, directory, name))
                    {
                        newfile.Show();
                        return(true);
                    }
                } finally {
                    newfile.SetProjectTagModel(null);
                }
            }
            else
            {
                SingleFileDescriptionTemplate singleFile = newfile as SingleFileDescriptionTemplate;
                if (singleFile == null)
                {
                    throw new InvalidOperationException("Single file template expected");
                }

                if (directory != null)
                {
                    string fileName = singleFile.SaveFile(policyParent, project, language, directory, name);
                    if (fileName != null)
                    {
                        IdeApp.Workbench.OpenDocument(fileName, project);
                        return(true);
                    }
                }
                else
                {
                    string fileName = singleFile.GetFileName(policyParent, project, language, directory, name);
                    Stream stream   = singleFile.CreateFileContent(policyParent, project, language, fileName, name);

                    string mimeType = GuessMimeType(fileName);
                    IdeApp.Workbench.NewDocument(fileName, mimeType, stream);
                    return(true);
                }
            }
            return(false);
        }
		public override void Load (XmlElement filenode)
		{
			foreach (XmlNode node in filenode.ChildNodes) {
				XmlElement elem = node as XmlElement;
				if (elem == null) continue;
				
				if (elem.Name == "SteticTemplate") {
					if (steticTemplate != null)
						throw new InvalidOperationException ("Widget templates can't contain more than one SteticTemplate element");
					steticTemplate = elem;
				} else if (fileTemplate == null) {
					fileTemplate = FileDescriptionTemplate.CreateTemplate (elem) as SingleFileDescriptionTemplate;
					if (fileTemplate == null)
						throw new InvalidOperationException ("Widget templates can only contain single-file and stetic templates.");
				}
			}
			if (fileTemplate == null)
				throw new InvalidOperationException ("File template not found in widget template.");
			if (steticTemplate == null)
				throw new InvalidOperationException ("Stetic template not found in widget template.");
		}
        public override void Load(XmlElement formNode)
        {
            m_UiNode = formNode.SelectSingleNode("ui");
            if (m_UiNode == null)
                throw new Exception("<ui> missing in template");

            XmlNode fileNode = formNode.SelectSingleNode("File");
            if (fileNode == null)
                throw new Exception("<File> missing in template");

            m_FileTemplate = (SingleFileDescriptionTemplate)FileDescriptionTemplate.CreateTemplate((XmlElement)fileNode);
        }
        internal static void ModifyTags(SolutionFolderItem policyParent, Project project, string language, string identifier, string fileName, ref Dictionary <string, string> tags)
        {
            //DotNetProject netProject = project as DotNetProject;
            string          languageExtension = "";
            LanguageBinding binding           = null;

            if (!string.IsNullOrEmpty(language))
            {
                binding = SingleFileDescriptionTemplate.GetLanguageBinding(language);
                if (binding != null)
                {
                    languageExtension = Path.GetExtension(binding.GetFileName("Default")).Remove(0, 1);
                }
            }

            //need a default namespace or if there is no project, substitutions can get very messed up
            string ns                  = "Application";
            string rootNamespace       = ns;
            var    dotNetFileContainer = project as IDotNetFileContainer;

            if (dotNetFileContainer != null)
            {
                ns            = dotNetFileContainer.GetDefaultNamespace(fileName);
                rootNamespace = dotNetFileContainer.GetDefaultNamespace(null);
            }

            //need an 'identifier' for tag substitution, e.g. class name or page name
            //if not given an identifier, use fileName
            if ((identifier == null) && (fileName != null))
            {
                identifier = Path.GetFileName(fileName);
            }

            if (identifier != null)
            {
                //remove all extensions
                while (Path.GetExtension(identifier).Length > 0)
                {
                    identifier = Path.GetFileNameWithoutExtension(identifier);
                }
                identifier        = CreateIdentifierName(identifier);
                tags ["Name"]     = identifier;
                tags ["FullName"] = ns.Length > 0 ? ns + "." + identifier : identifier;

                //some .NET languages may be able to use keywords as identifiers if they're escaped
                if (binding != null)
                {
                    System.CodeDom.Compiler.CodeDomProvider provider = binding.GetCodeDomProvider();
                    if (provider != null)
                    {
                        tags ["EscapedIdentifier"] = provider.CreateEscapedIdentifier(identifier);
                    }
                }
            }

            tags ["Namespace"]     = ns;
            tags ["RootNamespace"] = rootNamespace;
            if (policyParent != null)
            {
                tags ["SolutionName"] = policyParent.Name;
            }
            if (project != null)
            {
                tags ["ProjectName"]     = project.Name;
                tags ["SafeProjectName"] = CreateIdentifierName(project.Name);
                var info = project.AuthorInformation ?? AuthorInformation.Default;
                tags ["AuthorCopyright"] = info.Copyright;
                tags ["AuthorCompany"]   = info.Company;
                tags ["AuthorTrademark"] = info.Trademark;
                tags ["AuthorEmail"]     = info.Email;
                tags ["AuthorName"]      = info.Name;
            }
            if ((language != null) && (language.Length > 0))
            {
                tags ["Language"] = language;
            }
            if (languageExtension.Length > 0)
            {
                tags ["LanguageExtension"] = languageExtension;
            }

            if (fileName != FilePath.Null)
            {
                FilePath fileDirectory = Path.GetDirectoryName(fileName);
                if (project != null && project.BaseDirectory != FilePath.Null && fileDirectory.IsChildPathOf(project.BaseDirectory))
                {
                    tags ["ProjectRelativeDirectory"] = fileDirectory.ToRelative(project.BaseDirectory);
                }
                else
                {
                    tags ["ProjectRelativeDirectory"] = fileDirectory;
                }

                tags ["FileNameWithoutExtension"] = Path.GetFileNameWithoutExtension(fileName);
                tags ["Directory"] = fileDirectory;
                tags ["FileName"]  = fileName;
            }
        }