コード例 #1
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);
                    }
                }
            }
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: tanmoydeb07/LiteDevelop
        private bool SaveUnsavedFiles(ISavableFile[] unsavedItems)
        {
            if (unsavedItems.Length > 0)
            {
                using (var dialog = new UnsavedFilesDialog(unsavedItems))
                {
                    switch (dialog.ShowDialog())
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        foreach (var item in dialog.GetItemsToSave())
                        {
                            item.Save(_extensionHost.CreateOrGetReporter("Build"));
                        }
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        break;

                    case System.Windows.Forms.DialogResult.Cancel:
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #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);
                    }
                }
            }
        }
コード例 #4
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 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);
                    }
                }
            }
        }
コード例 #5
0
ファイル: MainForm.cs プロジェクト: lanicon/LiteDevelop
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (var ofd = new OpenFileDialog())
            {
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if (Path.GetExtension(ofd.FileName) == ".sln")
                    {
                        if (_extensionHost.CurrentSolution != null)
                        {
                            CloseCurrentSolution();
                        }

                        var solution = Solution.OpenSolution(ofd.FileName);
                        solution.LoadComplete += new SolutionNodeLoadEventHandler(solution_LoadComplete);
                        solution.BeginLoad(_extensionHost.CreateOrGetReporter(string.Empty));
                    }
                    else
                    {
                        UserOpenWith(ofd.FileName);
                    }
                }
            }
        }
コード例 #6
0
        private void ViewContent_Closing(object sender, System.Windows.Forms.FormClosingEventArgs e)
        {
            var documentContent = DocumentContent;

            if (_extensionHost.ControlManager.NotifyUnsavedFilesWhenClosing && documentContent != null && documentContent.AssociatedFile != null)
            {
                if (documentContent.AssociatedFile.HasUnsavedData)
                {
                    var dialog = new UnsavedFilesDialog(new OpenedFile[1] {
                        documentContent.AssociatedFile
                    });
                    switch (dialog.ShowDialog())
                    {
                    case DialogResult.Yes:
                        dialog.GetItemsToSave()[0].Save(_extensionHost.CreateOrGetReporter("Build"));
                        break;

                    case DialogResult.Cancel:
                        e.Cancel = true;
                        break;
                    }
                }
            }
        }
コード例 #7
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)
                {
                    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));
                    }
                }
            }
        }