/// <summary> /// Saves the specified filename. /// </summary> /// <param name = "filename">The filename.</param> /// <param name = "o">The o.</param> /// <param name = "SuppressWarnings">if set to <c>true</c> [suppress warnings].</param> public override void Save(string filename, object o, Boolean suppressWarnings = false) { this.suppressWarnings = suppressWarnings; if (o is ruleWindow || o is grammarRule || (o is object[] && ((object[])o)[0] is grammarRule)) { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { FilerProgressWindow.SaveRule(filename, false, this, o); } else if (o is object[]) { SaveRule(filename, (object[])o); } else { SaveRule(filename, new[] { o }); } } else if (o is graphWindow || o is designGraph || (o is object[] && ((object[])o)[0] is designGraph)) { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { FilerProgressWindow.SaveGraph(filename, false, this, o); } else if (o is object[]) { SaveGraph(filename, (object[])o); } else { SaveGraph(filename, new[] { o }); } } else { base.Save(filename, o); } }
public override object[] Open(string filename, Boolean suppressWarnings = false) { this.suppressWarnings = suppressWarnings; XmlReader xR; try { xR = XmlReader.Create(filename); /* Load the file. */ var doc = new XmlDocument(); doc.Load(xR); xR.Close(); /* create prefix<->namespace mappings (if any) */ var nsMgr = new XmlNamespaceManager(doc.NameTable); /* Query the document */ if (main.windowsMgr.FindAndFocusFileInCollection(doc, nsMgr, filename)) { if (!suppressWarnings && (progWindow != null)) { progWindow.QueryUser("That file is already open, or there is another file open with the" + " same name. If this is another file, please rename one of the names.", 5000, "OK", "", false); } if (main.windowsMgr.activeWindow is graphWindow) { var gWin = (graphWindow)main.windowsMgr.activeWindow; return(new object[] { gWin.graph, gWin.canvasProps, gWin.filename }); } else if (main.windowsMgr.activeWindow is ruleWindow) { var rWin = (ruleWindow)main.windowsMgr.activeWindow; return(new object[] { rWin.rule, rWin.canvasProps, rWin.filename }); } else if (main.windowsMgr.activeWindow is ruleSetWindow) { var rsWin = (ruleSetWindow)main.windowsMgr.activeWindow; return(new object[] { rsWin.Ruleset }); } } else if (doc.SelectNodes("/designGraph", nsMgr).Count > 0) { return new object[] { OpenGraph(filename) } } ; else if (doc.SelectNodes("/grammarRule", nsMgr).Count > 0) { return new object[] { OpenRule(filename) } } ; else if (doc.SelectNodes("/candidate", nsMgr).Count > 0) { return new object[] { OpenCandidate(filename) } } ; else if (doc.SelectNodes("/ruleSet", nsMgr).Count > 0) { return(FilerProgressWindow.OpenRuleSet(filename, suppressWarnings, this)); } else if (doc.DocumentElement.Attributes["Tag"].Value == "Graph") { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { return(FilerProgressWindow.OpenGraph(filename, suppressWarnings, this)); } else { return(OpenGraphAndCanvas(filename)); } } else if (doc.DocumentElement.Attributes["Tag"].Value == "Rule") { if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA) { return(FilerProgressWindow.OpenRule(filename, suppressWarnings, this)); } else { return(OpenRuleAndCanvas(filename)); } } else { throw new Exception(); } } catch (Exception e) { if (!suppressWarnings && (progWindow != null)) { progWindow.QueryUser("The XML files that you have attempted to open contains an unknown " + "type (not designGraph, grammarRule, ruleSet, or candidate).", 10000, "", "Cancel", false); } SearchIO.output(e.ToString()); } return(null); }