Esempio n. 1
0
        private void SaveDocument(DocumentWindow window)
        {
            NAntDocument document = _documents[window];

            if (document.FileType == FileType.New)
            {
                SaveDocumentAs(window);
            }
            else if (IsDirty(window))
            {
                try
                {
                    document.Save(window.Contents, true);

                    if (window == ActiveWindow)
                    {
                        List <IBuildTarget> targets = _mainForm.SelectedTargets;
                        UpdateTitle();
                        UpdateDisplay();
                        _mainForm.SelectedTargets = targets;
                    }
                }
                catch (Exception ex)
                {
                    Errors.CouldNotSave(document.Name, ex.Message);
                }
            }
        }
Esempio n. 2
0
        private void CloseDocument(object sender, FormClosingEventArgs e)
        {
            DocumentWindow window;

            if (sender is DocumentWindow)
            {
                window = sender as DocumentWindow;
            }
            else
            {
                window = ActiveWindow;
            }

            NAntDocument document = _documents[window];

            if (document.FileType == FileType.New)
            {
                DialogResult result = Errors.DocumentNotSaved(document.Name);

                if (result == DialogResult.Yes)
                {
                    SaveDocumentAs(window);
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }
            else if (IsDirty(window))
            {
                DialogResult result = Errors.DocumentNotSaved(document.Name);

                if (result == DialogResult.Yes)
                {
                    try
                    {
                        document.Save(window.Contents, false);
                    }
                    catch (Exception ex)
                    {
                        Errors.CouldNotSave(document.Name, ex.Message);
                    }
                }
                else if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                }
            }

            if (!e.Cancel)
            {
                _mainForm.RemoveDocumentMenuItem(document);
            }
        }