public void CloseDocument(Document document)
{
int index = OpenDocuments.IndexOf (document);
OpenDocuments.Remove (document);
if (index == active_document_index) {
// If there's other documents open, switch to one of them
if (HasOpenDocuments) {
if (index > 0)
SetActiveDocument (index - 1);
else
SetActiveDocument (index);
} else {
active_document_index = -1;
OnActiveDocumentChanged (EventArgs.Empty);
}
}
document.Close ();
OnDocumentClosed (new DocumentEventArgs (document));
}