// bool AllowReload (IEnumerable projects) // { // IEnumerable<string> closedDocs; // return AllowReload (projects, out closedDocs); // } bool AllowReload (IEnumerable projects, out IEnumerable<string> closedDocs) { closedDocs = null; if (projects == null) return true; List<Document> docs = new List<Document> (); foreach (Project p in projects) { docs.AddRange (GetOpenDocuments (p, false)); } if (docs.Count == 0) return true; // Find a common project reload capability bool hasUnsaved = false; bool hasNoFiles = false; ProjectReloadCapability prc = ProjectReloadCapability.Full; foreach (Document doc in docs) { if (doc.IsDirty) hasUnsaved = true; if (!doc.IsFile) hasNoFiles = true; var c = doc.ProjectReloadCapability; if ((int) c < (int) prc) prc = c; } string msg = null; switch (prc) { case ProjectReloadCapability.None: if (hasNoFiles && hasUnsaved) msg = GettextCatalog.GetString ("WARNING: Some documents may need to be closed, and unsaved data will be lost. You will be asked to save the unsaved documents."); else if (hasNoFiles) msg = GettextCatalog.GetString ("WARNING: Some documents may need to be reloaded or closed, and unsaved data will be lost. You will be asked to save the unsaved documents."); else if (hasUnsaved) msg = GettextCatalog.GetString ("WARNING: Some files may need to be reloaded, and unsaved data will be lost. You will be asked to save the unsaved files."); else goto case ProjectReloadCapability.UnsavedData; break; case ProjectReloadCapability.UnsavedData: msg = GettextCatalog.GetString ("Some files may need to be reloaded, and editing status for those files (such as the undo queue) will be lost."); break; } if (msg != null) { if (!MessageService.Confirm (GettextCatalog.GetString ("The project '{0}' has been modified by an external application. Do you want to reload it?", docs[0].Project.Name), msg, AlertButton.Reload)) return false; } List<string> closed = new List<string> (); foreach (Document doc in docs) { if (doc.IsDirty) hasUnsaved = true; if (doc.ProjectReloadCapability != ProjectReloadCapability.None) doc.SetProject (null); else { FilePath file = doc.IsFile ? doc.FileName : FilePath.Null; EventHandler saved = delegate { if (doc.IsFile) file = doc.FileName; }; doc.Saved += saved; try { if (!doc.Close ()) return false; else if (!file.IsNullOrEmpty && File.Exists (file)) closed.Add (file); } finally { doc.Saved -= saved; } } } closedDocs = closed; return true; }
public void SetReloadCapability(ProjectReloadCapability cap) { capability = cap; }