/// <summary> /// A new GraphView will have a GraphDoc as its document. /// </summary> /// <returns>A <see cref="GraphDoc"/></returns> public override GoDocument CreateDocument() { GoDocument doc = new GraphDoc(); doc.UndoManager = new GoUndoManager(); return(doc); }
public static List <GraphViewWindow> OpenAll() { List <GraphViewWindow> windows = new List <GraphViewWindow>(); if (!System.IO.Directory.Exists(@".\Config\FlowChart\")) { System.IO.Directory.CreateDirectory(@".\Config\FlowChart\"); } var filePaths = Directory.GetFiles(@".\Config\FlowChart\"); foreach (var item in filePaths) { OpenFileDialog dlg = new OpenFileDialog(); dlg.FileName = item; String loc = item; GraphDoc olddoc = GraphDoc.FindDocument(loc); if (olddoc != null) { //IList windows = GraphViewWindow.FindWindows(mdiparent, olddoc); //if (windows.Count > 0) //{ // GraphViewWindow w = windows[0] as GraphViewWindow; // if (w.Reload()) // { // w.Show(); // w.Activate(); // } // return w; //} } else { Stream file = dlg.OpenFile(); if (file != null) { GraphDoc doc = null; try { doc = GraphDoc.Load(file, loc); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error reading graph from a file"); } finally { file.Close(); } if (doc != null) { GraphViewWindow w = new GraphViewWindow(); w.View.Document = doc; w.Activate(); windows.Add(w); } } } } return(windows); }
protected override void OnClosed(EventArgs evt) { base.OnClosed(evt); IList windows = FindWindows(this.MdiParent, this.Doc); if (windows.Count <= 1) { GraphDoc.RemoveDocument(this.Doc.Location); } }
public static GraphViewWindow Open(DockPanel dockPanel1) { OpenFileDialog dlg = new OpenFileDialog(); if (dlg.ShowDialog() == DialogResult.OK) { String loc = dlg.FileName; GraphDoc olddoc = GraphDoc.FindDocument(loc); if (olddoc != null) { return(null); //IList windows = GraphViewWindow.FindWindows(mdiparent, olddoc); //if (windows.Count > 0) //{ // GraphViewWindow w = windows[0] as GraphViewWindow; // if (w.Reload()) // { // w.Show(); // w.Activate(); // } // return w; //} } else { Stream file = dlg.OpenFile(); if (file != null) { GraphDoc doc = null; try { doc = GraphDoc.Load(file, loc); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error reading graph from a file"); } finally { file.Close(); } if (doc != null) { GraphViewWindow w = new GraphViewWindow(); w.View.Document = doc; w.Show(dockPanel1, DockState.Document); w.Activate(); return(w); } } return(null); } } return(null); }
// ICustomTypeDescriptor /// <summary> /// When the document is read-only, this implementation of GetAttributes /// dynamically adds a ReadOnlyAttribute to the collection of attributes for /// this class, to disable the PropertyGrid in which this object is being /// displayed. /// </summary> /// <returns></returns> public AttributeCollection GetAttributes() { AttributeCollection coll = TypeDescriptor.GetAttributes(this, true); GraphDoc doc = this.GraphNode.Document as GraphDoc; if (doc != null && doc.IsReadOnly) { ReadOnlyAttribute ro = new ReadOnlyAttribute(true); Attribute[] atts = new Attribute[coll.Count + 1]; coll.CopyTo(atts, 0); atts[coll.Count] = ro; return(new AttributeCollection(atts)); } return(coll); }
public static IList FindWindows(Form mdiparent, GraphDoc doc) { ArrayList windows = new ArrayList(); Form[] children = mdiparent.MdiChildren; foreach (Form f in children) { GraphViewWindow w = f as GraphViewWindow; if (w != null && w.Doc == doc) { windows.Add(w); } } return(windows); }
public static GraphDoc Load(Stream file, String loc) { GoXmlReader xr = new GoXmlReader(); InitReaderWriter(xr); GraphDoc doc = xr.Consume(file) as GraphDoc; if (doc == null) { return(null); } doc.EnsureUniquePartID(); // update the file location doc.Location = loc; // undo managers are not serialized doc.UndoManager = new GoUndoManager(); doc.IsModified = false; AddDocument(loc, doc); return(doc); }
public virtual bool Reload() { String loc = this.Doc.Location; if (loc != "") { FileStream file = File.Open(loc, FileMode.Open); GraphDoc olddoc = this.View.Doc; GraphDoc newdoc = null; try { newdoc = GraphDoc.Load(file, loc); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "Error reading graph from a file"); return(false); } finally { file.Close(); } if (newdoc != null) { IList windows = GraphViewWindow.FindWindows(this.MdiParent, olddoc); foreach (Object obj in windows) { GraphViewWindow w = obj as GraphViewWindow; if (w != null) { w.View.Document = newdoc; } } } } return(true); }
internal static void AddDocument(String location, GraphDoc doc) { myDocuments[location] = doc; }