public HtmlToolMediaHelper(HtmlEditingTool htmlEditingTool) { HtmlEditingTool = htmlEditingTool; HtmlEditingTool.MouseUp += VisualHtmlEditor_MouseUp; HtmlEditingTool.MouseDoubleClick += VisualHtmlEditor_MouseDoubleClick; }
public static void SwitchToHtmlEditingTool(HtmlEditingTool htmlEditingTool) { if (htmlEditingTool.IsNull()) { throw new ArgumentNullException(); } htmlEditingTool.BringToFront(); }
public HtmlToolContextMenuHelper(HtmlEditingTool htmlEditingTool) { HtmlEditingTool = htmlEditingTool; HtmlEditingTool.KeyDown += VisualHtmlEditor_KeyDown; HtmlEditingTool.KeyUp += VisualHtmlEditor_KeyUp; HtmlEditingTool.MouseDown += VisualHtmlEditor_MouseDown; HtmlEditingTool.MouseUp += VisualHtmlEditor_MouseUp; }
public static void EmbedHtmlEditingTool(HtmlEditingTool htmlEditingTool, Control parent) { if (htmlEditingTool.IsNull() || parent.IsNull()) { throw new ArgumentNullException(); } htmlEditingTool.Dock = DockStyle.Fill; parent.Controls.Add(htmlEditingTool); }
public static void SetDefaultDocumentHtml(HtmlEditingTool htmlEditingTool, bool outer = false) { SetDefaultStyle(htmlEditingTool, outer); List<HtmlElement> ms = htmlEditingTool.GetElementsByTagName("meta"); foreach (HtmlElement m in ms) { m.OuterHtml = string.Empty; } htmlEditingTool.BodyInnerHtml = "<p></p>"; }
public static void SetDefaultStyle(HtmlEditingTool htmlEditingTool, bool outer = false) { Dictionary<string, string> d = new Dictionary<string, string> { {"href", string.Concat((outer) ? Warehouse.Warehouse.OuterProjectEditorLocation : Warehouse.Warehouse.ProjectEditorLocation, "\\")} }; htmlEditingTool.SetBaseTag(d); d = new Dictionary<string, string> { {"href", string.Concat(Application.StartupPath, "\\css\\system.css")}, {"rel", "stylesheet"}, {"type", "text/css"} }; htmlEditingTool.SetLinkTag(d); }
private void InitializeDialog() { var oct = new OuterCourseTree { Dock = DockStyle.Fill, BorderStyle = BorderStyle.None }; splitContainer.Panel1.Controls.Add(oct); OuterCourseTree = oct; oct.AfterSelect += CourseTree_AfterSelect; oct.MouseDown += CourseTree_MouseDown; htmlEditingTool = new HtmlEditingTool { Dock = DockStyle.Fill }; splitContainer.Panel2.Controls.Add(htmlEditingTool); }
public static void Convert(HtmlEditingTool htmlEditingTool) { DocumentBase document = HtmlEditing.HtmlEditingToolHelper.GetParentDocument(EditorObserver.ActiveEditor); string s = EditorObserver.ActiveEditor.BodyInnerHtml ?? string.Empty; if (document is TrainingModuleDocument) { var tm = ((TrainingModuleDocument)document).TrainingModule; tm.DocumentHtml = s; HtmlEditing.HtmlEditingToolHelper.SetDefaultStyle(htmlEditingTool); ConvertBookmarks(htmlEditingTool); ConvertImages(htmlEditingTool); ConvertFlashes(htmlEditingTool); ConvertAudios(htmlEditingTool); ConvertVideos(htmlEditingTool); tm.PreviewHtml = s; } if (document is QuestionDocument) { var q = ((QuestionDocument)document).Question; q.DocumentHtml = s; HtmlEditing.HtmlEditingToolHelper.SetDefaultStyle(htmlEditingTool); ConvertQuestionDocument(htmlEditingTool, q); ConvertImages(htmlEditingTool); ConvertFlashes(htmlEditingTool); ConvertAudios(htmlEditingTool); ConvertVideos(htmlEditingTool); q.PreviewHtml = s; } if (document is ResponseDocument) { var r = ((ResponseDocument)document).Response; r.DocumentHtml = s; HtmlEditing.HtmlEditingToolHelper.SetDefaultStyle(htmlEditingTool); ConvertImages(htmlEditingTool); ConvertFlashes(htmlEditingTool); ConvertAudios(htmlEditingTool); ConvertVideos(htmlEditingTool); r.PreviewHtml = s; } }
private static void ConvertBookmarks(HtmlEditingTool htmlEditingTool) { var bs = Warehouse.Warehouse.Instance.Bookmarks; var ans = htmlEditingTool.Links; foreach (HtmlElement he in ans) { if (he.Id != null) { foreach (var b in bs) { if (he.Id.Equals(b.Id.ToString())) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); ahe.InnerHtml = he.InnerHtml; ahe.Id = he.Id; he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); he.OuterHtml = string.Empty; break; } } } } }
public static void WaitForValidBody(HtmlEditingTool htmlEditingTool) { if (htmlEditingTool.IsNull() || htmlEditingTool.Document.IsNull()) { throw new ArgumentNullException(); } while (htmlEditingTool.Document.Body.IsNull()) { Application.DoEvents(); } }
public static void WaitForIdleness(HtmlEditingTool htmlEditingTool) { if (htmlEditingTool.IsNull()) { throw new ArgumentNullException(); } while (htmlEditingTool.IsBusy) { Application.DoEvents(); } }
//моя функция для стилей public static void SurroundWithStyleHtml(HtmlEditingTool htmlEditingTool, string tagName, Dictionary<string, string> attributes) { if (htmlEditingTool.IsNull() || tagName.IsNull() || attributes.IsNull()) { throw new ArgumentNullException(); } if (htmlEditingTool.Mode == Enums.HtmlEditingToolMode.Preview) { throw new InvalidOperationException(); } // Обрамление html кода разрешено только при наличии выделения. if (!htmlEditingTool.IsSelection) { return; } var htmlDocument = htmlEditingTool.GetNativeHtmlDocument(); IHTMLTxtRange textRange; try { textRange = htmlDocument.selection.createRange() as IHTMLTxtRange; } catch { throw new InvalidOperationException(); } if (textRange.IsNull()) { throw new NullReferenceException(); } var selection = textRange.htmlText; // var htmlText = textRange.htmlText; selection = string.Copy(selection); // var htmlPaste = htmlText; // var selection = htmlEditingTool.GetSelection(); // selection = string.Copy(selection); if (selection.IsNull()) { throw new NullReferenceException(); } if (selection.StartsWith(" ")) { selection = selection.Remove(0, 1); selection = string.Concat(" ", selection); } var attrs = ConcatAttributes(attributes); selection = string.Concat("<", tagName, " ", attrs, ">", selection, "</", tagName, ">"); try { textRange.pasteHTML(selection); textRange.collapse(false); textRange.select(); } catch { throw new InvalidOperationException(); } }
public static void ConvertQuestionDocument(HtmlEditingTool htmlEditingTool, Question q) { var testModuleText = string.Empty; if (q.Parent is TestModule) { testModuleText = q.Parent.Text; } else { testModuleText = q.Parent.Parent.Text; } var questionHtml = q.DocumentHtml; if (q.QuestionDocument != null) { questionHtml = q.QuestionDocument.HtmlEditingTool.BodyInnerHtml; } var html = string.Empty; html = "<table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n" + "<tr>\n" + "<td>" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" + "<tr align=\"center\" bgcolor=\"#CCCCFF\">\n" + // имя и время теста "<td bgcolor=\"#eeeeee\" width=\"70%\" align=\"center\">" + "<b>" + testModuleText + "</b>" + "</td>\n" + "<td bgcolor=\"#ffeeee\"></td>\n" + "</tr>\n" + "<tr>\n" + // имя и время вопроса "<td bgcolor=\"#f5f5f5\" width=\"70%\" align=\"center\">" + "<i>" + q.Text + "</i> " + "</td>\n" + "<td bgcolor=\"#ffeeee\"></td>\n" + "</tr>\n" + "</table>\n" + "</td>\n" + "</tr>\n" + "<tr>\n" + "<td>\n" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" + "<tr bgcolor=\"#eeeeff\">\n" + // вопрос "<td colspan=\"3\">\n" + questionHtml + "</td>\n" + "</tr>\n" + "</table>\n" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n"; if (q is OpenQuestion) { html += "<tr bgcolor=\"#f5f5f5\">\n" + "<td width=\"100%\" align=\"left\">\n" + "<input type=\"text\"/>\n" + "</td>\n" + "</tr>\n"; } else { char letter = 'a'; foreach (var response in q.Responses) { html += "<tr bgcolor=\"#f5f5f5\">\n" + "<td width=\"5%\" align=\"center\">\n" + letter + "</td>\n" + "<td width=\"5%\" align=\"center\">\n"; if (q is ChoiceQuestion) { html += "<input type=\"radio\" />\n"; } else if (q is MultichoiceQuestion) { html += "<input type=\"checkbox\" />\n"; } else if (q is OrderingQuestion) { html += "<input type=\"hidden\" value=\"c\" />\n"; html += "<select name=\"c\">\n"; html += "<option></option>\n"; for (int i = 1; i <= q.Responses.Count; i++) { html += "<option value=\"" + i + "\">" + i + "</option>\n"; } html += "</select>\n"; } var responseHtml = response.DocumentHtml; if (response.ResponseDocument != null) { responseHtml = response.ResponseDocument.HtmlEditingTool.BodyInnerHtml; } html += "</td>\n" + "<td>\n" + responseHtml + "</td>\n" + "</tr>\n"; letter++; } } html += "</table>"; htmlEditingTool.BodyInnerHtml = html; }
private void viewNextQuestionButton_Click(object sender, EventArgs e) { var q = GetNextQuestion(); if (q != null) { questionPreviewDialog = new Form { StartPosition = FormStartPosition.CenterParent, Width = 600, Height = 500, KeyPreview = true, MaximizeBox = false, MinimizeBox = false, ShowIcon = false, ShowInTaskbar = false, Text = "Предварительный просмотр вопроса" }; var htmlEditingTool = new HtmlEditingTool { Dock = DockStyle.Fill, Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Preview }; Logic.Controls.HtmlEditing.HtmlEditingToolHelper.SetDefaultDocumentHtml(htmlEditingTool); htmlEditingTool.KeyDown += vhe_KeyDown1; questionPreviewDialog.Controls.Add(htmlEditingTool); PreviewConverter.ConvertQuestionDocument(htmlEditingTool, q); questionPreviewDialog.ShowDialog(this); } }
private void viewVariantButton_Click(object sender, EventArgs e) { ((ResponseVariant)question.ResponseVariants[selectedTabIndex]).Responses = new ArrayList(0); if (((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Count == 0) { if (question is ChoiceQuestion) { foreach (RadioButton rb in variantsTabControl.SelectedTab.Controls) { if (rb.Checked) { foreach (Response r in question.Responses) { if (r.Text == rb.Text && !question.ResponseVariants.Contains(r)) { ((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Add(r); } } } } } else if (question is MultichoiceQuestion) { foreach (CheckBox ch in variantsTabControl.SelectedTab.Controls) { if (ch.Checked) { foreach (Response r in question.Responses) { if (r.Text == ch.Text && !question.ResponseVariants.Contains(r)) { ((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Add(r); } } } } } else if (question is OrderingQuestion) { int i = 0; foreach (Control cb in variantsTabControl.SelectedTab.Controls) { if (cb is ComboBox) { int j = 0; int.TryParse(cb.Text, out j); ((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Add(j); i++; } } } else if (question is OpenQuestion) { foreach (Control cb in variantsTabControl.SelectedTab.Controls) { if (cb is RichTextBox) { ((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Add(cb.Text); } else if (cb is NumericUpDown) { ((ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]).Responses.Add(((NumericUpDown)cb).Value); } } } } #region Диалог предварительного просмотра responseVariantsPreviewDialog = new Form { StartPosition = FormStartPosition.CenterParent, Width = 600, Height = 500, KeyPreview = true, MaximizeBox = false, MinimizeBox = false, ShowIcon = false, ShowInTaskbar = false, Text = "Предварительный просмотр варианта ответа" }; var htmlEditingTool = new HtmlEditingTool { Dock = DockStyle.Fill, Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Preview }; Logic.Controls.HtmlEditing.HtmlEditingToolHelper.SetDefaultDocumentHtml(htmlEditingTool); htmlEditingTool.KeyDown += vhe_KeyDown; responseVariantsPreviewDialog.Controls.Add(htmlEditingTool); PreviewConverter.ConvertResponseVariantDocument(htmlEditingTool, question, (ResponseVariant)question.ResponseVariants[variantsTabControl.SelectedIndex]); responseVariantsPreviewDialog.ShowDialog(this); #endregion }
private void InitializeEditor() { htmlEditingTool = new HtmlEditingTool { Dock = DockStyle.Fill, Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design }; Logic.Controls.HtmlEditing.HtmlEditingToolHelper.SetDefaultDocumentHtml(htmlEditingTool); splitContainer.Panel2.Controls.Clear(); splitContainer.Panel2.Controls.Add(htmlEditingTool); if (Owner is QuestionDialog || Owner is QuestionInGroupDialog || Owner is NetQuestionDialog) { var q = Warehouse.Warehouse.Instance.CourseTree.CurrentNode as Question; htmlEditingTool.BodyInnerHtml = q.Hint; } else if (Owner is ResponseVariantDialog || Owner is NetResponseVariantDialog) { htmlEditingTool.BodyInnerHtml = hint; } htmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Preview; htmlEditingTool.Mode = Utils.Controls.HtmlEditing.Enums.HtmlEditingToolMode.Design; }
private static void ConvertFlashes(HtmlEditingTool htmlEditingTool) { var ims = htmlEditingTool.Images; var sd = string.Empty; var t = string.Empty; foreach (HtmlElement he in ims) { sd = he.GetAttribute("sdocument"); if (sd.Equals("1")) { t = he.GetAttribute("src"); if (t.Contains("Anim.png")) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); ahe.InnerHtml = he.GetAttribute("alt"); ahe.SetAttribute("src_", he.GetAttribute("src_")); ahe.SetAttribute("href", "anim"); he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); he.OuterHtml = string.Empty; } } else if (sd.Equals("0")) { t = he.GetAttribute("src"); if (t.Contains("Anim.png")) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); var html = "<OBJECT width=\"800\" height=\"500\" " + "classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" " + "codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\">" + "<PARAM name=movie value=\"" + he.GetAttribute("src_").Replace("\\", "/") + "\"></OBJECT>"; ahe.InnerHtml = html; try { he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); } catch (Exception exception) { ExceptionManager.Instance.LogException(exception); return; } he.OuterHtml = string.Empty; } } } }
public static DocumentBase GetParentDocument(HtmlEditingTool htmlEditingTool) { return htmlEditingTool.Parent as DocumentBase; }
private static void ConvertVideos(HtmlEditingTool htmlEditingTool) { var ims = htmlEditingTool.Images; var sd = string.Empty; var t = string.Empty; foreach (HtmlElement he in ims) { sd = he.GetAttribute("sdocument"); if (sd.Equals("1")) { t = he.GetAttribute("src"); if (t.Contains("Vid.png")) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); ahe.InnerHtml = he.GetAttribute("alt"); ahe.SetAttribute("src_", he.GetAttribute("src_")); ahe.SetAttribute("href", "vid"); he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); he.OuterHtml = string.Empty; } } else if (sd.Equals("0")) { t = he.GetAttribute("src"); if (t.Contains("Vid.png")) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); var flashPlayerAbsolutePath = Path.Combine(Application.StartupPath, Warehouse.Warehouse.FlashPlayerRelativePath); var absoluteVideoSettingsPath = Path.Combine(Application.StartupPath, Warehouse.Warehouse.FlashPlayerRelativeVideoSettingsPath); var absoluteVideoPath = Path.Combine(Warehouse.Warehouse.ProjectEditorLocation, he.GetAttribute("src_")); var html = "<P><OBJECT type=\"application/x-shockwave-flash\" width=\"500\" height=\"400\" " + "data=\"" + flashPlayerAbsolutePath + "\">" + "<PARAM name=\"bgcolor\" value=\"#ffffff\" />" + "<PARAM name=\"allowFullScreen\" value=\"true\" />" + "<PARAM name=\"allowScriptAccess\" value=\"always\" />" + "<PARAM name=\"wmode\" value=\"transparent\" />" + "<PARAM name=\"movie\" value=\"" + flashPlayerAbsolutePath + "\"/>" + "<PARAM name=\"flashvars\" value=\"st=" + absoluteVideoSettingsPath + "&file=" + absoluteVideoPath + "\"/>" + "</OBJECT></P>"; ahe.InnerHtml = html; try { he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); } catch (Exception exception) { ExceptionManager.Instance.LogException(exception); return; } he.OuterHtml = string.Empty; } } } }
public static void InsertHtml(HtmlEditingTool htmlEditingTool, string tagName, Dictionary<string, string> attributes) { if (htmlEditingTool.IsNull() || tagName.IsNull() || attributes.IsNull()) { throw new ArgumentNullException(); } if (htmlEditingTool.Mode == Enums.HtmlEditingToolMode.Preview) { throw new InvalidOperationException(); } // Вставка html кода разрешена только при снятом выделении. if (htmlEditingTool.IsSelection) { return; } var htmlDocument = htmlEditingTool.GetNativeHtmlDocument(); IHTMLTxtRange textRange; try { textRange = htmlDocument.selection.createRange() as IHTMLTxtRange; } catch { throw new InvalidOperationException(); } if (textRange.IsNull()) { throw new NullReferenceException(); } var attrs = ConcatAttributes(attributes); var html = string.Concat("<", tagName, " ", attrs, ">"); try { textRange.pasteHTML(html); textRange.collapse(false); textRange.select(); } catch { throw new InvalidOperationException(); } }
public static void ConvertResponseVariantDocument(HtmlEditingTool htmlEditingTool, Question question, ResponseVariant rv) { string html = string.Empty; var testModuleText = string.Empty; if (question.Parent is TestModule) { testModuleText = question.Parent.Text; } else { testModuleText = question.Parent.Parent.Text; } var questionHtml = question.DocumentHtml; if (question.QuestionDocument != null) { questionHtml = question.QuestionDocument.HtmlEditingTool.BodyInnerHtml; } html += "<table width=\"90%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n" + "<tr>\n" + "<td>" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" + "<tr align=\"center\" bgcolor=\"#CCCCFF\">\n" + // имя и время теста "<td bgcolor=\"#eeeeee\" width=\"70%\" align=\"center\">" + "<b>" + testModuleText + "</b>" + "</td>\n" + "<td bgcolor=\"#ffeeee\"></td>\n" + "</tr>\n" + "<tr>\n" + // имя и время вопроса "<td bgcolor=\"#f5f5f5\" width=\"70%\" align=\"center\">" + "<i>" + question.Text + "</i> " + "</td>\n" + "<td bgcolor=\"#ffeeee\"></td>\n" + "</tr>\n" + "</table>\n" + "</td>\n" + "</tr>\n" + "<tr>\n" + "<td>\n" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n" + "<tr bgcolor=\"#eeeeff\">\n" + // сам вопрос "<td colspan=\"3\">\n" + questionHtml + "</td>\n" + "</tr>\n" + "</table>\n" + "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\" width=\"100%\">\n"; if (question is OpenQuestion) { html += "<tr bgcolor=\"#f5f5f5\">\n" + "<td width=\"100%\" align=\"left\">\n" + "<input type=\"text\" value=\"" + rv.Responses[0].ToString() + "\"/>\n" + "</td>\n" + "</tr>\n"; } else { char letter = 'a'; foreach (Response response in question.Responses) { html += "<tr bgcolor=\"#f5f5f5\">\n" + "<td width=\"5%\" align=\"center\">\n" + letter + "</td>\n" + "<td width=\"5%\" align=\"center\">\n"; if (question is ChoiceQuestion) { if (rv.Responses.Contains(response)) { html += "<input type=\"radio\" checked/>\n"; } else { html += "<input type=\"radio\" />\n"; } } else if (question is MultichoiceQuestion) { if (rv.Responses.Contains(response)) { html += "<input type=\"checkbox\" checked/>\n"; } else { html += "<input type=\"checkbox\" />\n"; } } else if (question is OrderingQuestion) { html += "<input type=\"hidden\" value=\"c\" />\n"; html += "<select name=\"c\">\n"; html += "<option>" + (int)rv.Responses[question.Responses.IndexOf(response)] + "</option>\n"; for (int i = 1; i <= question.Responses.Count; i++) { html += "<option value=\"" + i + "\">" + i + "</option>\n"; } html += "</select>\n"; } var responseHtml = response.DocumentHtml; if (response.ResponseDocument != null) { responseHtml = response.ResponseDocument.HtmlEditingTool.BodyInnerHtml; } html += "</td>\n" + "<td>\n" + responseHtml + "</td>\n" + "</tr>\n"; letter++; } } html += "</table>\n" + "</BODY>\n" + "</HTML>"; htmlEditingTool.BodyInnerHtml = html; ConvertImages(htmlEditingTool); ConvertFlashes(htmlEditingTool); }
public static void InsertHtml(HtmlEditingTool htmlEditingTool, string html) { if (htmlEditingTool.IsNull() || html.IsNull()) { throw new ArgumentNullException(); } //if (htmlEditingTool.Mode == Enums.HtmlEditingToolMode.Preview) //{ // throw new InvalidOperationException(); //} // Вставка html кода разрешена только при снятом выделении. if (htmlEditingTool.IsSelection) { return; } var htmlDocument = htmlEditingTool.GetNativeHtmlDocument(); IHTMLTxtRange textRange; try { textRange = htmlDocument.selection.createRange() as IHTMLTxtRange; } catch { throw new InvalidOperationException(); } if (textRange.IsNull()) { throw new NullReferenceException(); } try { textRange.pasteHTML(html); textRange.collapse(false); textRange.select(); } catch { throw new InvalidOperationException(); } }
private static void ConvertImages(HtmlEditingTool htmlEditingTool) { var ims = htmlEditingTool.Images; var sd = string.Empty; var t = string.Empty; foreach (HtmlElement he in ims) { sd = he.GetAttribute("sdocument"); if (sd.Equals("1")) { t = he.GetAttribute("src"); if (t.Contains("Pic.png")) { var ahe = EditorObserver.ActiveEditor.Document.CreateElement(TagNames.AnchorTagName); ahe.InnerHtml = he.GetAttribute("alt"); ahe.SetAttribute("src_", he.GetAttribute("src_")); ahe.SetAttribute("href", "pic"); he.InsertAdjacentElement(HtmlElementInsertionOrientation.AfterEnd, ahe); he.OuterHtml = string.Empty; } } } }
public static void DeleteSurroundWithHtml(HtmlEditingTool htmlEditingTool, string tagName, Dictionary<string, string> attributes) { if (htmlEditingTool.IsNull() || tagName.IsNull() || attributes.IsNull()) { throw new ArgumentNullException(); } if (htmlEditingTool.Mode == Enums.HtmlEditingToolMode.Preview) { throw new InvalidOperationException(); } // Обрамление html кода разрешено только при наличии выделения. if (!htmlEditingTool.IsSelection) { return; } var htmlDocument = htmlEditingTool.GetNativeHtmlDocument(); IHTMLTxtRange textRange; try { textRange = htmlDocument.selection.createRange() as IHTMLTxtRange; } catch { throw new InvalidOperationException(); } if (textRange.IsNull()) { throw new NullReferenceException(); } var current = textRange.htmlText; var htmlText = textRange.htmlText; htmlText = string.Copy(htmlText); var htmlPaste = htmlText; string searchString1 = "<DIV"; string searchString2 = "</DIV"; while (htmlText.Contains(searchString1) && htmlText.Contains(searchString2)) { int first = htmlText.IndexOf(searchString1); int second = htmlText.IndexOf(searchString2); if (first < second) { int i = htmlPaste.IndexOf(searchString1); string temp=""; string temp2 = ""; while(htmlPaste[i]!='>') { for(int j=0; j<htmlPaste.Length; j++) if (j != i) { temp = string.Concat(temp, htmlPaste[j].ToString()); temp2 = string.Concat(temp2, htmlPaste[j].ToString()); } else { temp2 = string.Concat(temp2, " "); } htmlPaste = temp; htmlText = temp2; temp = ""; temp2 = ""; } for (int j = 0; j < htmlPaste.Length; j++) if (j != i) { temp = string.Concat(temp, htmlPaste[j].ToString()); } htmlPaste = temp; i = htmlPaste.IndexOf(searchString2); temp = ""; for (int j = 0; j < htmlPaste.Length; j++) if (j < i || j>(i+5)) { temp = string.Concat(temp, htmlPaste[j].ToString()); } htmlPaste = temp; i = htmlText.IndexOf(searchString2); temp2 = ""; for (int j = 0; j < htmlText.Length; j++) if (j < i || j > (i + 5)) { temp2 = string.Concat(temp2, htmlText[j].ToString()); } htmlText = temp2; } else { string temp2 = ""; for (int j = 0; j < htmlText.Length; j++) if (j < second || j > (second + 5)) { temp2 = string.Concat(temp2, htmlText[j].ToString()); } htmlText = temp2; } } try { textRange.pasteHTML(htmlPaste); textRange.collapse(false); textRange.select(); } catch { throw new InvalidOperationException(); } }