protected override void Run() { var active = IdeApp.Workbench.ActiveDocument; if (active == null) { return; } var activeNotebook = ((SdiWorkspaceWindow)active.Window).TabControl; var except = GetDocumentException(); var docs = new List <Document> (); var dirtyDialogShown = false; var startRemoving = except == null || !StartAfterException; foreach (var doc in IdeApp.Workbench.Documents) { if (((SdiWorkspaceWindow)doc.Window).TabControl == activeNotebook) { if (except != null && doc == except) { startRemoving = true; continue; } if (startRemoving) { docs.Add(doc); dirtyDialogShown |= doc.IsDirty; } } } if (dirtyDialogShown) { using (var dlg = new DirtyFilesDialog(docs, closeWorkspace: false, groupByProject: false)) { dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg) != (int)Gtk.ResponseType.Ok) { return; } } } foreach (Document doc in docs) { if (dirtyDialogShown) { doc.Close(true).Ignore(); } else { doc.Close().Ignore(); } } }
internal async Task <bool> Close() { if (!IdeApp.OnExit()) { return(false); } IdeApp.Workspace.SavePreferences(); bool showDirtyDialog = false; foreach (var doc in Documents) { if (doc.IsDirty) { showDirtyDialog = true; break; } } if (showDirtyDialog) { using (var dlg = new DirtyFilesDialog()) { dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg, workbench) != (int)Gtk.ResponseType.Ok) { return(false); } } } if (!await IdeApp.Workspace.Close(false, false)) { return(false); } var tasks = new List <Task> (); foreach (var doc in Documents.ToList()) { tasks.Add(doc.Close(true)); } await Task.WhenAll(tasks); workbench.Close(); IdeApp.Workspace.SavePreferences(); IdeApp.OnExited(); IdeApp.CommandService.Dispose(); return(true); }
protected override bool OnDeleteEvent(Event evnt) { var documents = IdeApp.Workbench.Documents.Where(IsChildOfMe).ToList(); int howManyDirtyFiles = documents.Count(doc => doc.IsDirty); if (howManyDirtyFiles > 1) { using (var dlg = new DirtyFilesDialog(documents, closeWorkspace: false, groupByProject: false)) { dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg) != (int)Gtk.ResponseType.Ok) { return(true); } } } else if (howManyDirtyFiles == 1) { // Ensure dirty file is closed first. This prevents saved files being closed // if the save is cancelled. documents.Sort(DirtyFilesFirst); } foreach (var d in documents) { if (howManyDirtyFiles > 1) { d.Window.CloseWindow(true); } else { // d.Close() could leave the UI synchronization context, letting the Gtk signal handler pass // and Gtk would destroy the window immediately. Since we need to preserve the window // state until the async document.Close () has finished, we interrupt the signal (return true) // and destoy the window in a continuation task after the document has been closed. d.Close().ContinueWith((arg) => { if (arg.Result) { Destroy(); } }, Core.Runtime.MainTaskScheduler); return(true); } } return(base.OnDeleteEvent(evnt)); }
protected override void Run() { if (IdeApp.Workbench.Documents.Any(doc => doc.IsDirty)) { DirtyFilesDialog dlg = new DirtyFilesDialog(); dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg, IdeApp.Workbench.RootWindow) != (int)Gtk.ResponseType.Ok) { return; } } foreach (Document doc in IdeApp.Workbench.Documents) { doc.IsDirty = false; } IdeApp.Workbench.CloseAllDocuments(false); }
protected override void Run() { var active = IdeApp.Workbench.ActiveDocument; if (active == null) { return; } var activeNotebook = ((SdiWorkspaceWindow)active.Window).TabControl; var except = GetDocumentException(); var docs = IdeApp.Workbench.Documents .Where(doc => ((SdiWorkspaceWindow)doc.Window).TabControl == activeNotebook && (except == null || doc.Window.ViewContent != except)) .ToArray(); var dirtyDialogShown = docs.Count(doc => doc.IsDirty) > 1; if (dirtyDialogShown) { using (var dlg = new DirtyFilesDialog(docs, closeWorkspace: false, groupByProject: false)) { dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg) != (int)Gtk.ResponseType.Ok) { return; } } } foreach (Document doc in docs) { if (dirtyDialogShown) { doc.Window.CloseWindow(true); } else { doc.Close(); } } }
protected override bool OnDeleteEvent(Event evnt) { var documents = IdeApp.Workbench.Documents.Where(IsChildOfMe).ToList(); int howManyDirtyFiles = documents.Count(doc => doc.IsDirty); if (howManyDirtyFiles > 1) { using (var dlg = new DirtyFilesDialog(documents, closeWorkspace: false, groupByProject: false)) { dlg.Modal = true; if (MessageService.ShowCustomDialog(dlg) != (int)Gtk.ResponseType.Ok) { return(true); } } } else if (howManyDirtyFiles == 1) { // Ensure dirty file is closed first. This prevents saved files being closed // if the save is cancelled. documents.Sort(DirtyFilesFirst); } foreach (var d in documents) { if (howManyDirtyFiles > 1) { d.Window.CloseWindow(true); } else if (!d.Close()) { return(true); } } return(base.OnDeleteEvent(evnt)); }