public void OpenProject(string fileName) { Project project = Storage.GetProject(fileName); if (project == null) { MessageBox.Show( "An error occured while opening project file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } else if (OpenProjects.ToList().Find(i => i.Id == project.Id) != null) { SelectedProject = OpenProjects.ToList().Find(i => i.Id == project.Id); } else { //if (dialog.FileName != project.Path) //{ project.Path = fileName; project.Code = Path.GetFileNameWithoutExtension(fileName); foreach (Unit unit in project.Units) { unit.Project.Path = fileName; unit.Project.Code = Path.GetFileNameWithoutExtension(fileName); } //} var projectViewModel = new ProjectViewModel(project); OpenProjects.Add(projectViewModel); SelectedProject = projectViewModel; } }
private void NewProject() { Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog(); dlg.FileName = "Urcie Project"; // Default file name dlg.DefaultExt = ".urc1"; // Default file extension dlg.Filter = "Urcie Project (.urc1)|*.urc1"; // Filter files by extension Nullable <bool> result = dlg.ShowDialog(); if (result == true) { ProjectViewModel viewModel = new ProjectViewModel(); viewModel.Code = dlg.FileName; try { viewModel.Code = Path.GetFileNameWithoutExtension(dlg.FileName); viewModel.Path = dlg.FileName; Storage.SaveProject(viewModel.ToModel()); OpenProjects.Add(viewModel); SelectedProject = viewModel; SelectedProject.Original = viewModel.ToModel(); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } } }
private void CreateNew() { var project = new Project(); project.RemovingRequested += RemovingRequestedHandler; OpenProjects.Add(project); SelectedProject = project; }
public void OpenProject(Stream stream, string fileName) { IProject project = new Project.Project(stream, fileName); CurrentProject = project; OpenProjects.Add(project); ProjectOpened(project, EventArgs.Empty); }
private void Open() { var ofd = new OpenFileDialog(); ofd.DefaultExt = ".mmproj"; ofd.Filter = "MagicMesh project files|*.mmproj|All files|*.*"; ofd.CheckFileExists = true; ofd.CheckPathExists = true; ofd.Multiselect = true; if (ofd.ShowDialog() == true) { Project project = null; foreach (string fileName in ofd.FileNames) { project = Project.Load(fileName); project.RemovingRequested += RemovingRequestedHandler; OpenProjects.Add(project); } SelectedProject = project; } }
public MainWindowViewModel() { _openProjects = new ObservableCollection <ProjectViewModel>(); SelectProjectCommand = new RelayCommand <ProjectViewModel>((project) => { SelectActiveProject(project); }); NewProjectCommand = new RelayCommand(() => { var proj = new ProjectViewModel(); proj.ProjectName = ProjectViewModel.UnNamedProjectName; // bug waiting to happen. names should be more unique because of how saving saving works at SelectActiveProject(proj); OpenProjects.Add(proj); }); CloseActiveProjectCommand = new RelayCommand(() => { if (ActiveProject != null) { // TODO: Ask if to save first ActiveProject.SaveState(); OpenProjects.Remove(ActiveProject); SelectActiveProject(OpenProjects.LastOrDefault()); } }); OpenProjectCommand = new RelayCommand(() => { OpenFileDialog openFileDialog = new OpenFileDialog(); if (openFileDialog.ShowDialog() == DialogResult.OK) { var proj = ProjectViewModel.FromFile(openFileDialog.FileName); if (proj != null) { SelectActiveProject(proj); OpenProjects.Add(proj); } } }); SaveProjectCommand = new RelayCommand(() => { if (ActiveProject.ProjectName == ProjectViewModel.UnNamedProjectName) { SaveAs(); } else { ActiveProject.SaveState(); } }); SaveAsProjectCommand = new RelayCommand(() => { SaveAs(); }); CloseAllCommand = new RelayCommand(() => { foreach (var item in OpenProjects) { item.SaveState(); } ActiveProject = null; OpenProjects.Clear(); }); }