Exemple #1
0
        private void OpenFromDialog()
        {
            if (IDEWindow.Instance.ViewModel.CurrentProject is null)
            {
                string path = this.CommonFileDialog();
                if (path is null)
                {
                    return;
                }
                ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json");
                IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel();
                App.Metadata.RecentlyOpenedProjects.Add(new RecentItem {
                    Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath
                });
                IDEWindow.Instance.ViewModel.CurrentProject.LoadMods();
                App.Metadata.Save();
            }
            else
            {
                MessageBoxResult result = Xceed.Wpf.Toolkit.MessageBox.Show($"Changes have been made to {IDEWindow.Instance.ViewModel.CurrentProject.Name}. Would you like to save these changes before closing the project?", "Save Changes?", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning);
                if (result == MessageBoxResult.Yes)
                {
                    string path = this.CommonFileDialog();
                    if (path is null)
                    {
                        return;
                    }

                    IDEWindow.Instance.ViewModel.CurrentProject.Close(true);
                    ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json");
                    IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel();
                    App.Metadata.RecentlyOpenedProjects.Add(new RecentItem {
                        Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath
                    });
                    IDEWindow.Instance.ViewModel.CurrentProject.LoadMods();
                    App.Metadata.Save();
                }
                else if (result == MessageBoxResult.No)
                {
                    string path = this.CommonFileDialog();
                    if (path is null)
                    {
                        return;
                    }

                    IDEWindow.Instance.ViewModel.CurrentProject.Close(false);
                    ProjectFile file = JFile.Load <ProjectFile>(Path.GetDirectoryName(path), "project.json");
                    IDEWindow.Instance.ViewModel.CurrentProject = file.CreateModel();
                    App.Metadata.RecentlyOpenedProjects.Add(new RecentItem {
                        Name = IDEWindow.Instance.ViewModel.CurrentProject.Name, Path = IDEWindow.Instance.ViewModel.CurrentProject.FilePath
                    });
                    IDEWindow.Instance.ViewModel.CurrentProject.LoadMods();
                    App.Metadata.Save();
                }
                else
                {
                    return;
                }
            }
        }