Beispiel #1
0
        public void ImportProject()
        {
            // Make sure we give the user a chance to
            // save the project if they need too.
            if (!AskSaveProject())
            {
                return;
            }

            if (!View.AskImportProject(out string projectFilePath))
            {
                return;
            }

            CloseProject();

            OnProjectLoading?.Invoke();

#if SHIPPING
            try
#endif
            {
                _actionStack.Clear();
                _project = new PipelineProject();
                var parser = new PipelineProjectParser(this, _project);
                parser.ImportProject(projectFilePath);

                ResolveTypes();

                ProjectOpen  = true;
                ProjectDirty = true;
            }
#if SHIPPING
            catch (Exception e)
            {
                View.ShowError("Open Project", "Failed to open project!");
                return;
            }
#endif

            UpdateTree();
            View.UpdateTreeItem(_project);

            OnProjectLoaded?.Invoke();

            UpdateMenu();
        }
Beispiel #2
0
        public void OpenProject(string projectFilePath)
        {
            CloseProject();

            OnProjectLoading?.Invoke();

            var errortext = "Failed to open the project due to an unknown error.";

            try
            {
                _actionStack.Clear();
                _project = new PipelineProject();

                var parser        = new PipelineProjectParser(this, _project);
                var errorCallback = new MGBuildParser.ErrorCallback((msg, args) =>
                {
                    errortext = string.Format(msg, args);
                    throw new Exception();
                });
                parser.OpenProject(projectFilePath, errorCallback);

                ResolveTypes();

                ProjectOpen  = true;
                ProjectDirty = false;

                PipelineSettings.Default.AddProjectHistory(projectFilePath);
                PipelineSettings.Default.StartupProject = projectFilePath;
                PipelineSettings.Default.Save();
                View.UpdateRecentList(PipelineSettings.Default.ProjectHistory);
            }
            catch (Exception)
            {
                View.ShowError("Error Opening Project", Path.GetFileName(projectFilePath) + ": " + errortext);
                return;
            }

            UpdateTree();
            View.UpdateTreeItem(_project);

            OnProjectLoaded?.Invoke();

            UpdateMenu();
        }
Beispiel #3
0
        public void NewProject()
        {
            // Make sure we give the user a chance to
            // save the project if they need too.
            if (!AskSaveProject())
            {
                return;
            }

            // A project needs a root directory or it is impossible to resolve relative paths.
            // So we need the user to choose that location even though the project has not
            // yet actually been saved to disk.
            var projectFilePath = Environment.CurrentDirectory;

            if (!View.AskSaveName(ref projectFilePath, "New Project"))
            {
                return;
            }

            CloseProject();

            OnProjectLoading?.Invoke();

            // Clear existing project data, initialize to a new blank project.
            _actionStack.Clear();
            _project = new PipelineProject();
            PipelineTypes.Load(_project);

            // Save the new project.
            _project.OriginalPath = projectFilePath;
            ProjectOpen           = true;
            ProjectDirty          = true;

            UpdateTree();

            OnProjectLoaded?.Invoke();

            UpdateMenu();
        }