コード例 #1
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);
        }
コード例 #2
0
        protected virtual bool CreateFile(FileDescriptionTemplate newfile, SolutionFolderItem 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
            {
                var 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);
        }
コード例 #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);

                    string mimeType = GuessMimeType(fileName);
                    IdeApp.Workbench.NewDocument(fileName, mimeType, stream);
                    return(true);
                }
            }
            return(false);
        }
コード例 #4
0
ファイル: FileTemplate.cs プロジェクト: riverans/monodevelop
		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;
        }
コード例 #5
0
ファイル: FileTemplate.cs プロジェクト: natosha/monodevelop
		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;
        }