Example #1
0
        private bool SaveOrSaveAs(bool saveAs = false)
        {
            SaveOpenItems();

            if (_isNew || saveAs)
            {
                var f = new SaveFileDialog {
                    AddExtension                 = true,
                    AutoUpgradeEnabled           = true,
                    CheckPathExists              = true,
                    DefaultExt                   = ".sqlnb",
                    Filter                       = "SQL Notebook files|*.sqlnb",
                    OverwritePrompt              = true,
                    SupportMultiDottedExtensions = true,
                    Title         = "Save Notebook As",
                    ValidateNames = true
                };
                using (f) {
                    if (f.ShowDialog(this) == DialogResult.OK)
                    {
                        new WaitForm("Save", "Saving your notebook...", () => {
                            _manager.SaveAs(f.FileName);
                        }).ShowDialogAndDispose(this);
                        _isNew = false;
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            else
            {
                new WaitForm("Save", "Saving your notebook...", () => {
                    _manager.Save();
                }).ShowDialogAndDispose(this);
            }

            // set this after doing the isNew stuff above so that if you click Save and then cancel the Save As dialog,
            // the file remains dirty. since untitled files are in stored in temporary files it doesn't matter that we
            // saved to it despite the cancelation.
            _isDirty.Value = false;

            _manager.Rescan();
            SetTitle();
            return(true);
        }