Ejemplo n.º 1
0
 private void Save()
 {
     if (fileChanged)
     {
         pf.WriteProject();
         SystemSounds.Beep.Play();
         fileChanged = false;
     }
 }
Ejemplo n.º 2
0
        private void Save()
        {
            var newpf = new ProjectFile
            {
                project = new ProjectFile.Project()
                {
                    name      = projNameBox.Text,
                    type      = projTypeBox.SelectedItem.ToString(),
                    orig_path = origFilesBox.Text,
                    tran_path = tranFilesBox.Text
                }
            };

            if (projectFilesList == null)
            {
                newpf.project.file_list = MakeFileList(firstFileBox.Text, lastFileBox.Text);
            }
            else
            {
                newpf.project.file_list = projectFilesList.ToArray();
            }

            if (newProj)
            {
                newpf.project.files = new SortedDictionary <string, ProjectFile.RevisedFile>();

                SaveFileDialog sfd = new SaveFileDialog()
                {
                    Title    = "Save Project",
                    Filter   = "DragonPunk Reviser Project (*.drpj)|*.drpj",
                    FileName = newpf.project.name
                };

                if (sfd.ShowDialog() == DialogResult.OK)
                {
                    newpf.path = sfd.FileName;
                    newpf.WriteProject();

                    mf.Open(sfd.FileName);

                    Close();
                }
            }
            else
            {
                var diff = pf.project.file_list.Except(newpf.project.file_list);

                if (diff.Count() > 0)
                {
                    bool lines = false;

                    foreach (string file in diff)
                    {
                        if (pf.project.files.ContainsKey(file) && pf.project.files[file].content.Count > 0)
                        {
                            lines = true;
                            break;
                        }
                    }

                    if (lines)
                    {
                        if (MessageBox.Show("Looks like the file list has changed." +
                                            "\nBy saving the project right now, you will lose the comments related to the files which are not in the file list anymore." +
                                            "\nAre you sure you want to continue?" +
                                            "\n\n(clicking \"No\" will ignore the new file list and the new file paths.)", "Warning", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            foreach (string file in diff)
                            {
                                if (pf.project.files.ContainsKey(file))
                                {
                                    pf.project.files.Remove(file);
                                }
                            }
                        }
                        else
                        {
                            newpf.project.orig_path = pf.project.orig_path;
                            newpf.project.tran_path = pf.project.tran_path;
                            newpf.project.file_list = pf.project.file_list;
                        }
                    }
                }

                newpf.project.files = pf.project.files;

                newpf.path = pf.path;
                newpf.WriteProject();

                mf.Open(pf.path);

                DialogResult = DialogResult.OK;

                Close();
            }
        }