SaveFile() public method

public SaveFile ( MonoDevelop.Projects.SolutionFolderItem policyParent, Project project, string language, string baseDirectory, string entryName ) : string
policyParent MonoDevelop.Projects.SolutionFolderItem
project MonoDevelop.Projects.Project
language string
baseDirectory string
entryName string
return string
Ejemplo n.º 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);
        }
Ejemplo n.º 2
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);
        }