private void CloseDocument(Document document) { // Does the actual close of a document. Not necessarily used when application is shutting down // This does not check if this document is displayed; that is done by the above functions if (document == null) { return; } if (!document.IsPaletteWithin) // Don't want to dispose palettes just because we stop editing them! { // we need to check in case the document being closed contained any palettes which are open for editing, or displayed on-screen List <Datum> removedPalettes = new List <Datum>(); // List of all palette documents which are no longer valid; Will all be Document objects, type is just so that AddRange can be used... if (document.UserSettings != null) { removedPalettes.AddRange(document.UserSettings.CustomPalettes.Values); } if (document.BothSettings != null) { removedPalettes.AddRange(document.BothSettings.CustomPalettes.Values); } // Check if any are open for editing foreach (Document remove in removedPalettes) { int index = m_Documents.IndexOf(remove); if (index >= 0) { RemoveDocument(index); } } // And remove from the positioning system: foreach (Document remove in removedPalettes) { Palette.Deregister(remove.ID.ToString()); } // This must be after the palette test above (which clears the config properties) document.Dispose(); } else { // if it was from an activity, make sure it gets saved if (Config.ActivityConfigs.Contains(document.PaletteWithin.Document)) { SaveAllActivityConfigs(); } } }
public void btnPaletteDelete_Click(object sender, EventArgs e) { Document selected = m_DisplayedPalettes[lstPalettes.SelectedIndex]; if (Globals.Root.DocumentIsOpen(selected)) { MessageBox.Show(Strings.Item("Config_PalettesDeleteEditingDocument")); return; } if (MessageBox.Show(Strings.Item("Config_PalettesDeleteConfirm"), RootApplication.AppName, MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } // The user is warned that the palette won't be restored to the definition list m_Config.CustomPalettes.Remove(selected); m_Transaction.Delete(selected); WrittenToCurrent(); OnDisplay(); Palette.Deregister(selected.ID.ToString()); }