/// <summary> /// Determine if the button should be enabled. /// </summary> protected override bool _shouldBeEnabled() { CadKit.Interfaces.IDocument idoc = CadKit.Documents.Manager.Instance.ActiveDocument; CadKit.Documents.Document doc = idoc as CadKit.Documents.Document; CadKit.Interfaces.ICommandHistory commands = (null == doc) ? null : doc.CommandHistory; return((null == commands) ? false : commands.CanRedo); }
/// <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> /// Execute the command. /// </summary> public override void execute() { CadKit.Interfaces.IDocument idoc = CadKit.Documents.Manager.Instance.ActiveDocument; CadKit.Documents.Document doc = idoc as CadKit.Documents.Document; CadKit.Interfaces.ICommandHistory commands = (null == doc) ? null : doc.CommandHistory; if (null != commands && true == commands.CanRedo) { commands.redo(); } }
/// <summary> /// Called when the parent is shown. /// </summary> void _parentShown(object sender, System.EventArgs e) { try { _documentNew = CadKit.Plugins.Manager.Instance.getAll <CadKit.Interfaces.IDocumentNew>(); for (uint i = 0; i < _documentNew.Length; ++i) { CadKit.Documents.Document doc = this._createDocument(i); CadKit.Interfaces.IDocument iDoc = doc as CadKit.Interfaces.IDocument; if (null != doc && null != iDoc) { System.Windows.Forms.LinkLabel label = new System.Windows.Forms.LinkLabel(); label.Name = iDoc.TypeName; label.Text = iDoc.TypeName; label.Click += new System.EventHandler(_labelClick); CadKit.Interfaces.IDocumentIcon docIcon = iDoc as CadKit.Interfaces.IDocumentIcon; if (docIcon == null || docIcon.Icon == null) { label.Image = CadKit.Images.Image.load(CadKit.Helios.Application.Instance.IconDir + "/new_document.png"); } else { label.Image = docIcon.Icon as System.Drawing.Image; } label.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; label.TextAlign = System.Drawing.ContentAlignment.MiddleRight; _flowLayoutPanel.Controls.Add(label); } doc = null; } System.Windows.Forms.Form parent = sender as System.Windows.Forms.Form; CadKit.Tools.ToolWindow.configure(this, parent, "New Document", false); _configureDockWindow(sender, this); CadKit.Interfaces.IWindowMenu windowMenu = sender as CadKit.Interfaces.IWindowMenu; if (null != windowMenu) { windowMenu.addFormWindowMenu(this.Text, this); } parent.Activate(); } catch (System.Exception ex) { System.Console.WriteLine("Error 3980677532: building new document form: {0}", ex.Message); } }
/// <summary> /// Create a document. /// </summary> private CadKit.Documents.Document _createDocument(uint i) { try { CadKit.Documents.Document doc = _documentNew[i].create(_caller) as CadKit.Documents.Document; return(doc); } catch (System.Exception e) { System.Console.WriteLine("Error 3381080104: {0}", e.Message); return(null); } }
/// <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); } }