public SettingsLoadedEventArgs(ProjectSettings settings)
 {
     _settings = settings;
 }
예제 #2
0
        /// <summary>
        /// Handles the <see cref="DialogProject"/> form, checks all the directories and builds the <see cref="Project"/> object.
        /// </summary>
        public void NewProject()
        {
            using (var dialog = new DialogProject())
            {
                var result = dialog.ShowDialog();
                if (result != DialogResult.OK) return;

                if (Project != null)
                {
                    var dialogResult = MessageBox.Show(@"Creating a new project will close the current one. Continue?", @"New Project", MessageBoxButtons.YesNo);
                    if (dialogResult != DialogResult.Yes) return;
                    CloseProject();
                }

                var name = dialog.ProjectName;
                var author = dialog.Author;
                var description = dialog.Description;
                var path = dialog.FilePath;

                Project = new Project(name, author, description, path);

                if (ProjectLoaded != null)
                    ProjectLoaded.Invoke(this, new ProjectLoadedEventArgs(Project));

                Settings = new ProjectSettings();

                if (SettingsLoaded != null)
                    SettingsLoaded.Invoke(this, new SettingsLoadedEventArgs(Settings));

                SaveProject();

                Console.WriteLine(@"Project {0} created.", name);
            }
        }
예제 #3
0
        /// <summary>
        /// Destroys the <see cref="Project"/> object.
        /// </summary>
        public bool CloseProject()
        {
            if (Project != null)
            {
                List<string> files = new List<string>();
                foreach (var map in MapManager.Instance.Maps)
                {
                    if (map.UnsavedChanges)
                    {
                        files.Add(map.Name);
                    }
                }

                if (files.Count > 0)
                {
                    using (var closeDialog = new DialogClose(files))
                    {
                        var closeResult = closeDialog.ShowDialog();
                        if (closeResult == DialogResult.Cancel) return false;
                        if (closeResult == DialogResult.Yes)
                            MapManager.Instance.SaveMaps();
                        if (closeResult == DialogResult.No)
                        {
                            foreach (var map in MapManager.Instance.Maps)
                            {
                                map.UnsavedChanges = false;
                            }
                        }
                    }
                }

                Console.WriteLine(@"Project {0} closed.", Project.Name);
            }

            if (Settings != null)
                Settings.Ignore = true;

            if (Project != null)
                Project.Closing = true;

            if (ProjectClosed != null)
                ProjectClosed.Invoke(this, new ProjectClosedEventArgs(Project));

            if (Settings != null && Project != null)
                Settings.SaveToXml(Path.Combine(Project.SettingsPath, "settings.xml"));

            Project = null;
            Settings = null;

            return true;
        }
예제 #4
0
        /// <summary>
        /// Deserializes the <see cref="Project"/> object.
        /// </summary>
        public void LoadProject()
        {
            using (var folderDialog = new OpenFileDialog())
            {
                folderDialog.FileName = "Project.xml";
                folderDialog.DefaultExt = ".xml";

                var folderResult = folderDialog.ShowDialog();
                if (folderResult != DialogResult.OK) return;

                if (Project != null)
                {
                    var dialogResult = MessageBox.Show(@"Opening a project will close the current one. Continue?", @"Open Project", MessageBoxButtons.YesNo);
                    if (dialogResult != DialogResult.Yes) return;
                    if (!CloseProject()) return;
                }

                string path = folderDialog.FileName;

                if (!File.Exists(path))
                {
                    MessageBox.Show(@"This is not a valid Crystal Toolset Project.", @"Open Project");
                    return;
                }

                Project = Project.LoadFromXml(path);
                Project.FilePath = Path.GetDirectoryName(path);
                Project.CheckDirectories();

                Console.WriteLine(@"Project {0} loaded.", Project.Name);

                if (ProjectLoaded != null)
                    ProjectLoaded.Invoke(this, new ProjectLoadedEventArgs(Project));

                var settingsPath = Path.Combine(Project.SettingsPath, "settings.xml");

                Settings = File.Exists(settingsPath) ? ProjectSettings.LoadFromXml(settingsPath) : new ProjectSettings();

                Settings.Ignore = true;

                if (SettingsLoaded != null)
                    SettingsLoaded.Invoke(this, new SettingsLoadedEventArgs(Settings));

                Settings.Ignore = false;
            }
        }