Пример #1
0
        private bool Save()
        {
            if (this.DocumentPath == null)
            {
                return(SaveAs());
            }
            else if (DocumentPath.ToLowerInvariant().EndsWith(".tex"))
            {
                var result = MessageBox.Show(
                    "This will transfer the Worksheet content to TeX-file '" + Path.GetFileName(this.DocumentPath) + "'." + Environment.NewLine
                    + "The content of the tex-file will be altered!" + Environment.NewLine
                    + "Ensure the file is saved in the TeX-Editor before clicking 'OK'!" + Environment.NewLine
                    + "Afterwards, reload the file.",
                    "Transfer from Worksheet to TeX-file...",
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Exclamation);

                if (result == DialogResult.OK)
                {
#if !DEBUG
                    try {
#endif
                    LatexIO.UpdateTexFile(this.DocumentPath, this.currentDocument);
#if !DEBUG
                }
                catch (Exception exc) {
                    MessageBox.Show(
                        exc.GetType().Name + ":" + Environment.NewLine + exc.Message,
                        "TeXlink Error.",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error);
                    return(false);
                }
#endif

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                try {
                    this.currentDocument.Serialize(this.DocumentPath);
                    this.Altered = false;
                } catch (Exception e) {
                    MessageBox.Show(this,
                                    e.GetType().Name + ":\n" + e.Message,
                                    "Error saving file",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    return(false);
                }
            }

            return(true);
        }