public static void UserCreateFile(LiteExtensionHost extensionHost, Project currentProject, string directory)
        {
            using (var dlg = new CreateFileDialog(currentProject))
            {
                if (!string.IsNullOrEmpty(directory))
                {
                    dlg.Directory = directory;
                }

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var filePath = new FilePath(dlg.FileName);
                    var files = dlg.Template.Create(new FileCreationContext()
                        {
                            CurrentProject = currentProject,
                            CurrentSolution = extensionHost.CurrentSolution,
                            FilePath = filePath,
                            FileService = extensionHost.FileService,
                            ProgressReporter = extensionHost.CreateOrGetReporter("Build"),
                        });

                    foreach (var createdFile in files)
                    {
                        extensionHost.FileService.SelectFileHandler(
                            extensionHost.ExtensionManager.GetFileHandlers(createdFile.FilePath),
                            createdFile.FilePath).OpenFile((OpenedFile)createdFile);
                    }
                }
            }
        }
        public static void UserCreateProject(LiteExtensionHost extensionHost)
        {
            var solution = extensionHost.CurrentSolution;

               using (var dlg = new CreateProjectDialog(solution))
               {
               if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
               {
                   var projectDirectory = new FilePath(dlg.Directory, dlg.FileName);

                   if (dlg.CreateSolutionDirectory)
                       projectDirectory = projectDirectory.Combine(projectDirectory.FileName);

                   if (System.IO.Directory.Exists(projectDirectory.FullPath))
                   {
                       if (MessageBox.Show(LiteDevelopApplication.Current.MuiProcessor.GetString("CreateProjectDialog.FolderAlreadyExists", "folder=" + projectDirectory), "LiteDevelop", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                           return;
                   }
                   else
                   {
                       System.IO.Directory.CreateDirectory(projectDirectory.FullPath);
                   }

                   bool newSolution = solution == null;
                   if (newSolution)
                   {
                       var solutionDirectory = dlg.CreateSolutionDirectory ? projectDirectory.ParentDirectory : projectDirectory;

                       solution = Solution.CreateSolution(projectDirectory.FileName);
                       solution.FilePath = solutionDirectory.Combine(projectDirectory.FileName + ".sln");
                   }

                   var projects = dlg.Template.Create(new FileCreationContext()
                       {
                           CurrentProject = null,
                           CurrentSolution = solution,
                           FilePath = projectDirectory,
                           FileService = extensionHost.FileService,
                           ProgressReporter = extensionHost.CreateOrGetReporter("Build"),
                       }).Cast<Project>();

                   if (newSolution)
                       extensionHost.DispatchSolutionCreated(new SolutionEventArgs(solution));

                   foreach (var project in projects)
                       solution.Nodes.Add(new ProjectEntry(project));

                   if (newSolution)
                       extensionHost.DispatchSolutionLoad(new SolutionEventArgs(solution));
               }
               }
        }
Esempio n. 3
0
        public static void UserCreateFile(LiteExtensionHost extensionHost, Project currentProject, string directory)
        {
            using (var dlg = new CreateFileDialog(currentProject))
            {
                if (!string.IsNullOrEmpty(directory))
                {
                    dlg.Directory = directory;
                }

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var result = (dlg.Template as FileTemplate).CreateFile(extensionHost.FileService, currentProject, new FilePath(dlg.FileName));

                    foreach (var createdFile in result.CreatedFiles)
                    {
                        var openedFile = createdFile.File as OpenedFile;
                        openedFile.Save(extensionHost.CreateOrGetReporter("Build"));

                        if (currentProject != null)
                        {
                            currentProject.ProjectFiles.Add(new ProjectFileEntry(openedFile));
                        }

                        createdFile.ExtensionToUse.OpenFile(openedFile);
                    }
                }
            }
        }
Esempio n. 4
0
        public static void UserCreateProject(LiteExtensionHost extensionHost)
        {
            var solution = extensionHost.CurrentSolution;

            using (var dlg = new CreateProjectDialog(solution))
            {
                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    string projectDirectory = Path.Combine(dlg.Directory, Path.GetFileNameWithoutExtension(dlg.FileName));

                    if (dlg.CreateSolutionDirectory)
                        projectDirectory = Path.Combine(projectDirectory, Path.GetFileNameWithoutExtension(dlg.FileName));

                    if (System.IO.Directory.Exists(projectDirectory))
                    {
                        if (MessageBox.Show(LiteDevelopApplication.Current.MuiProcessor.GetString("CreateProjectDialog.FolderAlreadyExists", "folder=" + projectDirectory), "LiteDevelop", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != DialogResult.Yes)
                            return;
                    }
                    else
                    {
                        System.IO.Directory.CreateDirectory(projectDirectory);
                    }

                    var projectTemplate = dlg.Template as ProjectTemplate;
                    var result = projectTemplate.CreateProject(extensionHost.FileService, new FilePath(projectDirectory, Path.GetFileName(dlg.FileName)));

                    result.Project.Save(extensionHost.CreateOrGetReporter("Build"));

                    if (solution == null)
                    {
                        string solutionDirectory = dlg.CreateSolutionDirectory ? Path.GetDirectoryName(projectDirectory) : projectDirectory;

                        solution = Solution.CreateSolution(result.Project.Name);
                        solution.FilePath = new FilePath(solutionDirectory, Path.GetFileNameWithoutExtension(dlg.FileName) + ".sln");
                        solution.Settings.StartupProjects.Add(result.Project.ProjectGuid);
                        solution.Save(extensionHost.CreateOrGetReporter("Build"));
                        extensionHost.DispatchSolutionCreated(new SolutionEventArgs(solution));
                        solution.Nodes.Add(new ProjectEntry(result.Project));
                        extensionHost.DispatchSolutionLoad(new SolutionEventArgs(solution));
                    }
                    else
                        solution.Nodes.Add(new ProjectEntry(result.Project));

                    for (int i = 0; i < result.CreatedFiles.Count; i++)
                    {
                        result.CreatedFiles[i].ExtensionToUse.OpenFile(result.CreatedFiles[i].File as OpenedFile);
                    }
                }
            }
        }