Example #1
0
 private void CloseProject()
 {
     foreach (UnitViewModel uvm in SelectedProject.Units)
     {
         uvm.CloseCommand.Execute(null);
     }
     OpenProjects.Remove(SelectedProject);
     SelectedProject = null;
 }
Example #2
0
        private void RemovingRequestedHandler(object sender, EventArgs e)
        {
            Project project = (Project)sender;

            if (!project.IsSaved)
            {
                new ConfirmDialog().ShowDialog();

                //MessageBoxResult result =
                //    MessageBox.Show(
                //        "There are stil some unsaved changes in this project. Do you want to close it anyways?",
                //        "Close without saving?",
                //        MessageBoxButton.YesNo);

                //switch (result)
                //{
                //    case MessageBoxResult.Yes:
                //        break;
                //    default:
                //        return;
                //}
            }

            if (project == SelectedProject)
            {
                if (OpenProjects.Count == 1)
                {
                    SelectedProject = null;
                }
                else
                {
                    int newIndex = OpenProjects.IndexOf(project) - 1;
                    if (newIndex < 0)
                    {
                        newIndex       += 2;
                        SelectedProject = newIndex < OpenProjects.Count ? OpenProjects[newIndex] : null;
                    }
                    SelectedProject = OpenProjects[newIndex];
                }
            }
            OpenProjects.Remove(project);
        }
Example #3
0
        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();
            });
        }