/// <summary> /// Insert a media link into the document /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void MediaLinkItem_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; ImageReference ir = cmsDropImage.Tag as ImageReference; if (ir != null) { if (sender == miMediaLink) { ContentEditorControl.InsertString(textArea, ir.ToMediaLink()); } else if (sender == miMediaLinkInline) { ContentEditorControl.InsertString(textArea, ir.ToMediaLinkInline()); } else { ContentEditorControl.InsertString(textArea, ir.ToExternalLink()); } } }
/// <summary> /// Insert a link to a site map table of contents entry (HTML only) /// </summary> /// <param name="extension">The extension of the file in which the /// link is being inserted.</param> /// <param name="tocEntry">The TOC entry for which to create a link</param> /// <remarks>If dropped inside some selected text, the link will /// wrap the selected text.</remarks> private void InsertTocLink(string extension, TocEntry tocEntry) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; } else { selectedText = String.Empty; } if (extension == ".htm" || extension == ".html") { ContentEditorControl.InsertString(textArea, tocEntry.ToAnchor(selectedText)); } else { ContentEditorControl.InsertString(textArea, tocEntry.Title); // Not supported in MAML topics } }
/// <summary> /// Insert a code element /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void miCode_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; ContentEditorControl.InsertString(textArea, "\r\n<code language=\"cs\">\r\n/// Code\r\n</code>\r\n"); editor.Focus(); this.TrackLastInsertedElement(sender as ToolStripMenuItem); }
/// <summary> /// Insert a section /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void miSection_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; ContentEditorControl.InsertString(textArea, "\r\n<section address=\"optionalAddress\">\r\n" + " <title>Title</title>\r\n <content>\r\n <para>Content goes here</para>\r\n" + " </content>\r\n</section>\r\n"); editor.Focus(); this.TrackLastInsertedElement(sender as ToolStripMenuItem); }
/// <summary> /// Insert a table element /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void tsbTable_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; ContentEditorControl.InsertString(textArea, "\r\n<table>\r\n <tableHeader>\r\n " + "<row>\r\n <entry>Header 1</entry>\r\n <entry>" + "Header 2</entry>\r\n </row>\r\n </tableHeader>\r\n " + "<row>\r\n <entry>Column 1</entry>\r\n <entry>" + "Column 2</entry>\r\n </row>\r\n</table>\r\n"); editor.Focus(); }
/// <summary> /// Insert a definition table /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void miDefinitionTable_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; ContentEditorControl.InsertString(textArea, "\r\n<definitionTable>\r\n" + " <definedTerm>Term 1</definedTerm>\r\n <definition>" + "<para>Definition 1</para></definition>\r\n <definedTerm>Term 2" + "</definedTerm>\r\n <definition><para>Definition 2</para></definition>" + "\r\n</definitionTable>"); editor.Focus(); this.TrackLastInsertedElement(sender as ToolStripMenuItem); }
/// <summary> /// Execute the HTML Encode action /// </summary> /// <param name="textArea">The text area in which to perform the /// action</param> public override void Execute(TextArea textArea) { int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; ContentEditorControl.InsertString(textArea, HttpUtility.HtmlEncode(selectedText)); } }
/// <summary> /// Execute the HTML Encode action /// </summary> /// <param name="textArea">The text area in which to perform the action</param> public override void Execute(TextArea textArea) { int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; // HTML encode everything but single and double quotes as they're fine as-is ContentEditorControl.InsertString(textArea, WebUtility.HtmlEncode(selectedText).Replace(""", "\"").Replace("'", "'")); } }
/// <summary> /// Insert a list element /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void insertList_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; string style; if (sender == tsbListBullet) { style = "bullet"; } else { style = "ordered"; } ContentEditorControl.InsertString(textArea, "\r\n<list class=\"" + style + "\">\r\n" + " <listItem><para>Item 1</para></listItem>\r\n <listItem><para>Item 2</para>" + "</listItem>\r\n</list>\r\n"); editor.Focus(); }
/// <summary> /// Insert an alert element /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void miAlert_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; } else { selectedText = "Alert text"; } ContentEditorControl.InsertString(textArea, "\r\n<alert class=\"note\">\r\n <para>" + selectedText + "</para>\r\n</alert>\r\n"); editor.Focus(); this.TrackLastInsertedElement(sender as ToolStripMenuItem); }
/// <summary> /// Execute the Insert Element action /// </summary> /// <param name="textArea">The text area in which to perform the /// action</param> public override void Execute(TextArea textArea) { int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; } else { selectedText = String.Empty; } ContentEditorControl.InsertString(textArea, String.Format( CultureInfo.CurrentCulture, "<{0}>{1}</{0}>", elementName, selectedText)); textArea.Caret.Column -= elementName.Length + 3; }
/// <summary> /// Insert a link to an in-page address attribute value /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void tsbLocalLink_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; } else { selectedText = "inner text"; } ContentEditorControl.InsertString(textArea, "<link xlink:href=\"#addr\">" + selectedText + "</link>"); textArea.Caret.Column -= 7; editor.Focus(); }
/// <summary> /// This handles the drop operation for the editor /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void editor_DragDrop(object sender, DragEventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; DataObject data = e.Data as DataObject; Topic topic; TocEntry tocEntry; string extension = Path.GetExtension(this.ToolTipText).ToLower(CultureInfo.InvariantCulture); if (data == null) { return; } if (data.GetDataPresent(typeof(Topic))) { topic = data.GetData(typeof(Topic)) as Topic; // Topic links can wrap selected text if (topic != null) { this.InsertTopicLink(extension, topic); } } else if (data.GetDataPresent(typeof(TocEntry))) { tocEntry = data.GetData(typeof(TocEntry)) as TocEntry; // Topic links can wrap selected text if (tocEntry != null) { this.InsertTocLink(extension, tocEntry); } } else if (data.GetDataPresent(DataFormats.Text)) { ContentEditorControl.InsertString(textArea, data.GetText()); } }
/// <summary> /// Insert an external link /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void tsbExternalLink_Click(object sender, EventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; int offset = textArea.Caret.Offset; string selectedText; if (textArea.SelectionManager.HasSomethingSelected && textArea.SelectionManager.SelectionCollection[0].ContainsOffset(offset)) { selectedText = textArea.SelectionManager.SelectionCollection[0].SelectedText; } else { selectedText = "link text"; } ContentEditorControl.InsertString(textArea, "<externalLink>\r\n<linkText>" + selectedText + "</linkText>\r\n<linkAlternateText>Optional alternate text</linkAlternateText>\r\n" + "<linkUri>http://www.url.com</linkUri>\r\n<linkTarget>_blank</linkTarget>\r\n" + "</externalLink>\r\n"); editor.Focus(); }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public FindText(ContentEditorControl parent) { editor = parent; }
/// <summary> /// This handles the drop operation for the editor /// </summary> /// <param name="sender">The sender of the event</param> /// <param name="e">The event arguments</param> private void editor_DragDrop(object sender, DragEventArgs e) { TextArea textArea = editor.ActiveTextAreaControl.TextArea; DataObject data = e.Data as DataObject; ImageReference ir; CodeReference cr; CodeEntityReference cer; Token token; Topic topic; TocEntry tocEntry; string extension = Path.GetExtension(this.ToolTipText).ToLower( CultureInfo.InvariantCulture); if (data == null) { return; } // Images have multiple link formats so a context menu is used // to let the user pick a format. if (data.GetDataPresent(typeof(ImageReference))) { if (extension == ".htm" || extension == ".html") { ir = data.GetData(typeof(ImageReference)) as ImageReference; if (ir != null) { ContentEditorControl.InsertString(textArea, ir.ToImageLink()); } } else { cmsDropImage.Tag = data.GetData(typeof(ImageReference)); cmsDropImage.Show(e.X, e.Y); } return; } // Everything else is fairly simple. Topic links will wrap the // selected text if dropped inside it. if (data.GetDataPresent(typeof(Token))) { token = data.GetData(typeof(Token)) as Token; if (token != null) { ContentEditorControl.InsertString(textArea, token.ToToken()); } } else if (data.GetDataPresent(typeof(CodeReference))) { cr = data.GetData(typeof(CodeReference)) as CodeReference; if (cr != null) { ContentEditorControl.InsertString(textArea, cr.ToCodeReference()); } } else if (data.GetDataPresent(typeof(CodeEntityReference))) { cer = data.GetData(typeof(CodeEntityReference)) as CodeEntityReference; if (cer != null) { if (extension == ".htm" || extension == ".html") { ContentEditorControl.InsertString(textArea, cer.ToSee()); } else { ContentEditorControl.InsertString(textArea, cer.ToCodeEntityReference()); } } } else if (data.GetDataPresent(typeof(Topic))) { topic = data.GetData(typeof(Topic)) as Topic; // Topic links can wrap selected text if (topic != null) { this.InsertTopicLink(extension, topic); } } else if (data.GetDataPresent(typeof(TocEntry))) { tocEntry = data.GetData(typeof(TocEntry)) as TocEntry; // Topic links can wrap selected text if (tocEntry != null) { this.InsertTocLink(extension, tocEntry); } } }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public ReplaceText(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public PasteSpecial(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public ReplaceText(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public SpellCheck(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public FindText(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public PasteSpecial(ContentEditorControl parent) { editor = parent; }
/// <summary> /// Constructor /// </summary> /// <param name="parent">The parent editor control</param> public SpellCheck(ContentEditorControl parent) { editor = parent; }