The table editor supports all kind of table manipulation. Once activated, the user can move cell borders with the mouse and invoke commands to split or merge cells, add or remove columns and rows. The table editor can mark several cells and invoke a command to any of them.
To insert a table a dialog is appropriate. You can also create a default grid and let the user modify it later.
private InsertTable tableDialog; void _buttonInsertTable_ExecuteEvent(object sender, ExecuteEventArgs e) { // CALL Insert Dialog if (tableDialog == null) { tableDialog = new InsertTable(); } if (tableDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { // insert IElement newTable = EditorDocument.HtmlEditor.Document.InsertTable(tableDialog.Rows, tableDialog.Columns, "", (int)tableDialog.BorderWidth.Value); // and set more properties if (newTable != null && newTable is TableElement) { ((TableElement)newTable).cellPadding = tableDialog.CellPadding; ((TableElement)newTable).cellSpacing = tableDialog.CellSpacing; } } }
Here the InsertTable method is used, which supports some predefined attributes. Evereything else can be set by using the freshly created object (newTable).
Several properties apply in design mode only. They do not persist in the document. This is just to support a sophisticated design time experience. In code, this looks like this:
EditorDocument.TableDesigner.GetTableDesigner(EditorDocument.HtmlEditor).CellSelectionColor = _colorpickerTableCellColor.Color;
The GetTableDesigner calls pulls the right property bag from the plug-in. All plug-ins are implemented as extender providers and hence the caller must take care to reference the current editor control.
Commands are method calls exposed by a plug-in. For example, merge a cell to the one at thr right requires this call:
EditorDocument.HtmlEditor.InvokeCommand(EditorDocument.TableDesigner.Commands.MergeRight);
Note that the call goes to the editor, but the command is read from the plug-in. The editor routes it to the right destination for invocation.