/// <summary> /// Called when the label is clicked. /// </summary> void _labelClick(object sender, System.EventArgs args) { try { int index = _flowLayoutPanel.Controls.IndexOf(sender as System.Windows.Forms.Control); if (index >= 0 && index < _documentNew.Length) { // Create the document. CadKit.Documents.Document doc = _documentNew[index].create(_caller) as CadKit.Documents.Document; CadKit.Interfaces.IDocument idoc = doc as CadKit.Interfaces.IDocument; CadKit.Documents.Manager.Instance.addDocument(idoc); // Give the document a command history. Assigning this avoids a dependency. if (null != doc) { doc.CommandHistory = new CadKit.Commands.History(); } // Set the delegate. CadKit.Documents.Manager.Instance.setGuiDelegate(idoc, this.Caller); // Create the default user-interface. if (false == this._createDefaultGui(idoc)) { idoc.close(); CadKit.Documents.Manager.Instance.remove(idoc); } } } catch (System.Exception e) { System.Console.WriteLine("Error 96335236: trying to create new document: {0}", e.Message); } }
/// <summary> /// Remove the document. /// </summary> public void remove(CadKit.Interfaces.IDocument document) { if (null != document) { if (document == this.ActiveDocument) { // This also sets active document to null. this.ActiveView = null; } using (this.Lock.write()) { while (true == _documents.Remove(document)) { } // Clear the GUI delegate. //document.GuiDelegate.Document = null; //document.GuiDelegate = null; document.close(); // Wait for cleanup. System.GC.Collect(); System.GC.WaitForPendingFinalizers(); } } }
/// <summary> /// Called when the thread starts. /// </summary> protected override void _startJob(CadKit.Threads.Jobs.Job job) { // Should be true. System.Diagnostics.Debug.Assert(false == CadKit.Threads.Tools.MainThread.Instance.IsMainThread); // If it exists then bring it forward. CadKit.Interfaces.IDocument idoc = CadKit.Documents.Manager.Instance.findDocument(this.File); if (null != idoc) { CadKit.Documents.Manager.Instance.windowsForward(idoc, this.Caller); return; } // Feedback. System.Console.WriteLine(System.String.Format("Opening file: {0}", this.File)); // Open the document. idoc = CadKit.Documents.Manager.Instance.open(this.File, null, this); // Give the document a command history. Assigning this avoids a dependency. CadKit.Documents.Document doc = idoc as CadKit.Documents.Document; if (null != doc) { doc.CommandHistory = new CadKit.Commands.History(); doc.CommandHistory.add(this.Command); } // Set the delegate. CadKit.Documents.Manager.Instance.setGuiDelegate(idoc, this.Caller); // Create the default user-interface. if (false == this._createDefaultGui(idoc)) { idoc.close(); CadKit.Documents.Manager.Instance.remove(idoc); } }