protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // get the table and its cells IHTMLTable sourceTable = GetSourceTable(DataMeister); IHTMLElementCollection cells = (sourceTable as IHTMLElement2).getElementsByTagName("td"); // single-cell tables just get the innerHTML of the cell pasted at the selection if (cells.length == 1) { IHTMLElement cell = cells.item(0, 0) as IHTMLElement; EditorContext.InsertHtml(begin, end, cell.innerHTML, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } else { // if we are inside a table TableSelection tableSelection = new TableSelection(EditorContext.MarkupServices.CreateMarkupRange(begin, end)); if (tableSelection.Table != null) { // paste the source cells into the table PasteCellsIntoTable(sourceTable, tableSelection); } else { // get table html (make sure width matches # of rows selected) TableHelper.SynchronizeTableWidthForEditing(sourceTable); string html = (sourceTable as IHTMLElement).outerHTML; // insert the html (nests within an undo unit) EditorContext.InsertHtml(begin, end, html, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } } return(true); }
protected override bool DoInsertData(DataAction action, MarkupPointer begin, MarkupPointer end) { // get the table and its cells IHTMLTable sourceTable = GetSourceTable(DataMeister); IHTMLElementCollection cells = (sourceTable as IHTMLElement2).getElementsByTagName("td"); // single-cell tables just get the innerHTML of the cell pasted at the selection if (cells.length == 1) { IHTMLElement cell = cells.item(0, 0) as IHTMLElement; EditorContext.InsertHtml(begin, end, cell.innerHTML, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } else { // if we are inside a table TableSelection tableSelection = new TableSelection(EditorContext.MarkupServices.CreateMarkupRange(begin, end)); if (tableSelection.Table != null) { // paste the source cells into the table PasteCellsIntoTable(sourceTable, tableSelection); } else { // get table html (make sure width matches # of rows selected) TableHelper.SynchronizeTableWidthForEditing(sourceTable); string html = (sourceTable as IHTMLElement).outerHTML; // insert the html (nests within an undo unit) EditorContext.InsertHtml(begin, end, html, UrlHelper.GetBaseUrl(DataMeister.HTMLData.SourceURL)); } } return true; }
private void commandClearCell_Execute(object sender, EventArgs e) { TableSelection tableSelection = new TableSelection(_editorContext.Selection.SelectedMarkupRange); if (tableSelection.Table != null) { MarkupRange tableMarkupRange = _editorContext.MarkupServices.CreateMarkupRange(tableSelection.Table as IHTMLElement); using (_editorContext.DamageServices.CreateDamageTracker(tableMarkupRange, false)) TableEditor.ClearCells(_editorContext); } }
public void EditorSelectionChanged(TableSelection tableSelection) { // list of currently selected cells (default to none) ArrayList selectedCells = new ArrayList(); if (tableSelection != null && tableSelection.HasContiguousSelection) { selectedCells = tableSelection.SelectedCells; } // build hashtables of element behaviors for our selected and unselected cells Hashtable selectedCellBehaviors = new Hashtable(); foreach (IHTMLElement cellElement in selectedCells) { TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(cellElement); if (cellBehavior != null) { selectedCellBehaviors[cellElement.sourceIndex] = cellBehavior; } } Hashtable lastSelectedCellBehaviors = new Hashtable(); foreach (IHTMLElement cellElement in _lastSelectedCells) { TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(cellElement); if (cellBehavior != null) { lastSelectedCellBehaviors[cellElement.sourceIndex] = cellBehavior; } } // unselect cells that should no longer be selected foreach (DictionaryEntry entry in lastSelectedCellBehaviors) { if (!selectedCellBehaviors.ContainsKey(entry.Key)) { (entry.Value as TableCellEditingElementBehavior).DrawSelectionBorder = false; } } // select cells that are joining the selection foreach (DictionaryEntry entry in selectedCellBehaviors) { if (!lastSelectedCellBehaviors.ContainsKey(entry.Key)) { (entry.Value as TableCellEditingElementBehavior).DrawSelectionBorder = true; } } // update the last selected cells _lastSelectedCells = selectedCells; }
internal void ManageCommands() { // state variables bool editableTableSelected, multipleRowsSelected, multipleColumnsSelected, multipleCellsSelected; if (_editorContext.EditMode) { // analyze selection TableSelection tableSelection = new TableSelection(_editorContext.Selection.SelectedMarkupRange); editableTableSelected = (tableSelection.Table != null) && (tableSelection.Table as IHTMLElement3).isContentEditable; multipleRowsSelected = editableTableSelected && !tableSelection.SingleRowSelected; multipleColumnsSelected = editableTableSelected && !tableSelection.SingleColumnSelected; multipleCellsSelected = editableTableSelected && tableSelection.HasContiguousSelection; } else { editableTableSelected = multipleRowsSelected = multipleColumnsSelected = multipleCellsSelected = false; } commandTableProperties.Enabled = editableTableSelected; commandDeleteTable.Enabled = editableTableSelected; commandRowProperties.Enabled = editableTableSelected && !multipleRowsSelected; commandInsertRowAbove.Enabled = editableTableSelected; commandInsertRowBelow.Enabled = editableTableSelected; commandMoveRowUp.Enabled = editableTableSelected && !multipleRowsSelected; commandMoveRowDown.Enabled = editableTableSelected && !multipleRowsSelected; commandDeleteRow.Enabled = editableTableSelected; // commandDeleteRow.MenuFormatArgs = new object[] { multipleRowsSelected ? "s" : String.Empty }; commandColumnProperties.Enabled = editableTableSelected && !multipleColumnsSelected; commandInsertColumnLeft.Enabled = editableTableSelected; commandInsertColumnRight.Enabled = editableTableSelected; commandMoveColumnLeft.Enabled = editableTableSelected && !multipleColumnsSelected; commandMoveColumnRight.Enabled = editableTableSelected && !multipleColumnsSelected; commandDeleteColumn.Enabled = editableTableSelected; // commandDeleteColumn.MenuFormatArgs = new object[] { multipleColumnsSelected ? "s" : String.Empty }; commandCellProperties.Enabled = editableTableSelected && !multipleCellsSelected; commandClearCell.Enabled = editableTableSelected; // commandClearCell.MenuFormatArgs = new object[] { multipleCellsSelected ? "s" : String.Empty } ; }
protected override bool QueryElementSelected() { if (_tableIsEditable) { TableSelection tableSelection = new TableSelection(EditorContext.Selection.SelectedMarkupRange); if ((tableSelection.Table != null) && HTMLElementHelper.ElementsAreEqual(HTMLElement, tableSelection.Table as IHTMLElement)) { _currentTableSelection = tableSelection; return(true); } else { _currentTableSelection = null; return(false); } } else { return(false); } }
protected override bool QueryElementSelected() { if (_tableIsEditable) { TableSelection tableSelection = new TableSelection(EditorContext.Selection.SelectedMarkupRange); if ((tableSelection.Table != null) && HTMLElementHelper.ElementsAreEqual(HTMLElement, tableSelection.Table as IHTMLElement)) { _currentTableSelection = tableSelection; return true; } else { _currentTableSelection = null; return false; } } else { return false; } }
public void EditorSelectionChanged(TableSelection tableSelection) { // list of currently selected cells (default to none) ArrayList selectedCells = new ArrayList(); if (tableSelection != null && tableSelection.HasContiguousSelection) selectedCells = tableSelection.SelectedCells; // build hashtables of element behaviors for our selected and unselected cells Hashtable selectedCellBehaviors = new Hashtable(); foreach (IHTMLElement cellElement in selectedCells) { TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(cellElement); if (cellBehavior != null) selectedCellBehaviors[cellElement.sourceIndex] = cellBehavior; } Hashtable lastSelectedCellBehaviors = new Hashtable(); foreach (IHTMLElement cellElement in _lastSelectedCells) { TableCellEditingElementBehavior cellBehavior = _tableEditingContext.GetCellBehavior(cellElement); if (cellBehavior != null) lastSelectedCellBehaviors[cellElement.sourceIndex] = cellBehavior; } // unselect cells that should no longer be selected foreach (DictionaryEntry entry in lastSelectedCellBehaviors) { if (!selectedCellBehaviors.ContainsKey(entry.Key)) (entry.Value as TableCellEditingElementBehavior).DrawSelectionBorder = false; } // select cells that are joining the selection foreach (DictionaryEntry entry in selectedCellBehaviors) { if (!lastSelectedCellBehaviors.ContainsKey(entry.Key)) (entry.Value as TableCellEditingElementBehavior).DrawSelectionBorder = true; } // update the last selected cells _lastSelectedCells = selectedCells; }
private void PasteCellsIntoTable(IHTMLTable sourceTable, TableSelection tableSelection) { // collect up the top level cells we are pasting ArrayList cellsToPaste = new ArrayList(); foreach (IHTMLTableRow row in sourceTable.rows) { foreach (IHTMLElement cell in row.cells) { cellsToPaste.Add(cell); } } // get the list of cells we are pasting into int appendRows = 0; int cellsPerRow = 0; ArrayList targetCells; if (tableSelection.SelectedCells.Count > 1) { targetCells = tableSelection.SelectedCells; } else { targetCells = new ArrayList(); bool accumulatingCells = false; foreach (IHTMLTableRow row in tableSelection.Table.rows) { cellsPerRow = row.cells.length; foreach (IHTMLElement cell in row.cells) { if (!accumulatingCells && HTMLElementHelper.ElementsAreEqual(cell, tableSelection.BeginCell as IHTMLElement)) { accumulatingCells = true; } if (accumulatingCells) { targetCells.Add(cell); } } } // if the target cells aren't enough to paste all of the cells, then // calculate the number of rows we need to append to fit all of the // cells being pasted int cellGap = cellsToPaste.Count - targetCells.Count; if (cellGap > 0 && cellsPerRow > 0) { appendRows = cellGap / cellsPerRow + (cellGap % cellsPerRow == 0 ? 0 : 1); } } // perform the paste using (IUndoUnit undoUnit = EditorContext.CreateUndoUnit()) { // append rows if needed if (appendRows > 0) { // see if we can cast our editor context to the one required // by the table editor IHtmlEditorComponentContext editorContext = EditorContext as IHtmlEditorComponentContext; if (editorContext != null) { // markup range based on last target cell IHTMLElement lastCell = targetCells[targetCells.Count - 1] as IHTMLElement; MarkupRange lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(lastCell); for (int i = 0; i < appendRows; i++) { IHTMLTableRow row = TableEditor.InsertRowBelow(editorContext, lastCellRange); foreach (IHTMLElement cell in row.cells) { targetCells.Add(cell); } lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(row as IHTMLElement); } } else { Debug.Fail("Couldn't cast EditorContext!"); } } // do the paste for (int i = 0; i < cellsToPaste.Count && i < targetCells.Count; i++) { (targetCells[i] as IHTMLElement).innerHTML = (cellsToPaste[i] as IHTMLElement).innerHTML; } undoUnit.Commit(); } }
private void PasteCellsIntoTable(IHTMLTable sourceTable, TableSelection tableSelection) { // collect up the top level cells we are pasting ArrayList cellsToPaste = new ArrayList(); foreach (IHTMLTableRow row in sourceTable.rows) foreach (IHTMLElement cell in row.cells) cellsToPaste.Add(cell); // get the list of cells we are pasting into int appendRows = 0; int cellsPerRow = 0; ArrayList targetCells; if (tableSelection.SelectedCells.Count > 1) { targetCells = tableSelection.SelectedCells; } else { targetCells = new ArrayList(); bool accumulatingCells = false; foreach (IHTMLTableRow row in tableSelection.Table.rows) { cellsPerRow = row.cells.length; foreach (IHTMLElement cell in row.cells) { if (!accumulatingCells && HTMLElementHelper.ElementsAreEqual(cell, tableSelection.BeginCell as IHTMLElement)) accumulatingCells = true; if (accumulatingCells) targetCells.Add(cell); } } // if the target cells aren't enough to paste all of the cells, then // calculate the number of rows we need to append to fit all of the // cells being pasted int cellGap = cellsToPaste.Count - targetCells.Count; if (cellGap > 0 && cellsPerRow > 0) { appendRows = cellGap / cellsPerRow + (cellGap % cellsPerRow == 0 ? 0 : 1); } } // perform the paste using (IUndoUnit undoUnit = EditorContext.CreateUndoUnit()) { // append rows if needed if (appendRows > 0) { // see if we can cast our editor context to the one required // by the table editor IHtmlEditorComponentContext editorContext = EditorContext as IHtmlEditorComponentContext; if (editorContext != null) { // markup range based on last target cell IHTMLElement lastCell = targetCells[targetCells.Count - 1] as IHTMLElement; MarkupRange lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(lastCell); for (int i = 0; i < appendRows; i++) { IHTMLTableRow row = TableEditor.InsertRowBelow(editorContext, lastCellRange); foreach (IHTMLElement cell in row.cells) targetCells.Add(cell); lastCellRange = EditorContext.MarkupServices.CreateMarkupRange(row as IHTMLElement); } } else { Debug.Fail("Couldn't cast EditorContext!"); } } // do the paste for (int i = 0; i < cellsToPaste.Count && i < targetCells.Count; i++) { (targetCells[i] as IHTMLElement).innerHTML = (cellsToPaste[i] as IHTMLElement).innerHTML; } undoUnit.Commit(); } }
protected override bool ContentIsDeletableForInsert(MarkupPointer start, MarkupPointer end) { // if a table element is contained within the selection then it is not deleteable for insert TableSelection tableSelection = new TableSelection(MarkupServices.CreateMarkupRange(start, end)); bool contentIsDeletableForInsert = !tableSelection.HasContiguousSelection; // allow either our logic or the base class to veto deletion return contentIsDeletableForInsert && base.ContentIsDeletableForInsert(start, end); }
public virtual void UpdateContextAvailability() { commandImageContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; commandFormatImageTab.ContextAvailability = ContextAvailability.NotAvailable; commandMapContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; commandFormatMapTab.ContextAvailability = ContextAvailability.NotAvailable; commandTagContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; commandFormatTagTab.ContextAvailability = ContextAvailability.NotAvailable; commandVideoContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; commandFormatVideoTab.ContextAvailability = ContextAvailability.NotAvailable; // No contextual tabs in plain text or preview mode if (CurrentEditingMode == EditingMode.PlainText || CurrentEditingMode == EditingMode.Preview) return; bool initialInsertion = _makingInitialInsertion > 0; // We want this to get the source ids for any "containing" smart content. IHtmlEditorComponentContext componentContext = _currentEditor as IHtmlEditorComponentContext; MarkupRange selection = componentContext.Selection.SelectedMarkupRange; IHTMLElement smartContentElement = ContentSourceManager.GetContainingSmartContentElement(selection); string contentSourceId = smartContentElement != null ? smartContentElement.id : null; if (contentSourceId != null) { string sourceId; string contentBlockId; ContentSourceManager.ParseContainingElementId(contentSourceId, out sourceId, out contentBlockId); if (sourceId == MapContentSource.ID) { if (ApplicationDiagnostics.TestMode) { commandMapContextTabGroup.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; commandFormatMapTab.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; } } else if (sourceId == TagContentSource.ID) { if (ApplicationDiagnostics.TestMode) { commandTagContextTabGroup.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; commandFormatTagTab.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; } } else if (sourceId == VideoContentSource.ID) { commandVideoContextTabGroup.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; commandFormatVideoTab.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; } } bool imageSelected = componentContext.Selection.SelectedImage != null && EmoticonsManager.GetEmoticon(componentContext.Selection.SelectedControl) == null; if (imageSelected) commandImageContextTabGroup.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; else { commandImageContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; } commandFormatImageTab.ContextAvailability = commandImageContextTabGroup.ContextAvailability; TableSelection tableSelection = new TableSelection(selection); bool tableSelected = ((tableSelection.Table != null) && (tableSelection.Table as IHTMLElement3).isContentEditable); if (tableSelected) commandTableContextTabGroup.ContextAvailability = initialInsertion ? ContextAvailability.Active : ContextAvailability.Available; else commandTableContextTabGroup.ContextAvailability = ContextAvailability.NotAvailable; commandFormatTableTab.ContextAvailability = commandTableContextTabGroup.ContextAvailability; }
private void commandInsertTable_Execute(object sender, EventArgs e) { //Insert gestures are only supported in the body, so force focus to the body FocusBody(); using (TablePropertiesForm tableForm = new TablePropertiesForm()) { // show the dialog TableCreationParameters tableCreationParameters = tableForm.CreateTable(_mainFrameWindow); // insert if (tableCreationParameters != null) { using (new WaitCursor()) { // fixup bizzaro table selections IHtmlEditorComponentContext editorContext = _currentEditor as IHtmlEditorComponentContext; if (editorContext != null) { // check for a discontigous selection of cells within an existing table and // "fix" the selection accordingly so the editor doesn't barf on it TableSelection tableSelection = new TableSelection(editorContext.Selection.SelectedMarkupRange); if (tableSelection.HasContiguousSelection && !tableSelection.EntireTableSelected) { TableEditor.SelectCell(editorContext, tableSelection.BeginCell); } } // insert the table TableEditor.InsertTable(_currentEditor, editorContext, tableCreationParameters); } } // focus the editor so we see the cursor in the first cell _currentEditor.Focus(); } }