public void SetCustomAttributes(HtmlReportUtils.CustomAttributes customAttributes) { foreach (var attrib in customAttributes) { var menuItem = new ToolStripMenuItem(); menuItem.Text = String.Format(m_Trans.Translate("{0} (Custom)"), attrib.Value); menuItem.Name = attrib.Key.ToLower(); menuItem.Click += new System.EventHandler(base.OnAttributeMenuClick); ToolStripAttributeMenu.DropDownItems.Add(menuItem); } }
// -------------------------------------------------------------- public HtmlReportTemplateForm(String typeId, Translator trans, TaskList tasks, bool printing, Preferences prefs, String key) { m_TypeId = typeId; m_Trans = trans; m_Tasklist = tasks; m_Prefs = prefs; m_PrefsKey = key; m_Printing = printing; m_Template = new HtmlReportTemplate(); m_PrevTemplate = new HtmlReportTemplate(); m_CustomAttributes = new HtmlReportUtils.CustomAttributes(); m_EditedSinceLastSave = false; m_ChangeTimer = new Timer(); m_ChangeTimer.Tick += new EventHandler(OnChangeTimer); m_ChangeTimer.Interval = 500; InitializeComponent(); InitialiseFontAndColors(); DoHighDPIFixups(); // Build list custom attribute IDs for later use if (tasks.HasCustomAttributes()) { var numAttrib = tasks.GetCustomAttributeCount(); var custAttribs = new HtmlReportUtils.CustomAttributes(); for (var attrib = 0; attrib < numAttrib; attrib++) { m_CustomAttributes.Add(tasks.GetCustomAttributeID(attrib).ToLower(), tasks.GetCustomAttributeLabel(attrib)); } } this.htmlReportTasksControl.SetCustomAttributes(m_CustomAttributes); var prevSize = LoadPreferences(); if ((prevSize.Width > 0) && (prevSize.Height > 0)) { this.Size = prevSize; } }
private void Initialise(string text, TableHeaderRowType tableHeaderType, HtmlReportUtils.CustomAttributes customAttributes) { Clear(); if (String.IsNullOrWhiteSpace(text)) { return; } try { // Defaults this.TaskHtml = text; this.TableHeaderRow = TableHeaderRowType.NotRequired; this.CustomAttributes = customAttributes; var doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(text); // Remove everything before the first bit of text // or the first major structural element var elm = doc.DocumentNode.FirstChild; while (elm != null) { // get next sibling in case we need to delete this node var nextElm = elm.NextSibling; if (AgilityUtils.ElementHasContent(elm)) { break; } elm.Remove(); elm = nextElm; } if (elm != null) { switch (elm.Name.ToUpper()) { case "TABLE": CleanTableCellContents(elm); this.Style = StyleType.Table; this.TableHeaderRow = tableHeaderType; break; case "UL": this.Style = StyleType.UnorderedList; break; case "OL": this.Style = StyleType.OrderedList; break; } if (this.Style != StyleType.None) { String taskHtml = GetTaskHtml(elm); int taskStart = elm.OuterHtml.IndexOf(taskHtml); this.StartHtml = elm.OuterHtml.Substring(0, taskStart); this.EndHtml = elm.OuterHtml.Substring(taskStart + taskHtml.Length); // Handle table header row if (this.Style == StyleType.Table) { if (tableHeaderType != TableHeaderRowType.NotRequired) { // Prefix 'Table:Tbody' with header row int tbodyStart = this.StartHtml.ToUpper().IndexOf("<TBODY>"); if (tbodyStart != -1) { if (tableHeaderType == TableHeaderRowType.AutoGenerate) { var theadStyle = "style=font-weight:bold;font-size:1.5em;display:table-header-group;"; var header = FormatHeader(taskHtml); var theadHtml = String.Format("\n<thead {0}>{1}</thead>", theadStyle, header); this.StartHtml = this.StartHtml.Insert(tbodyStart, theadHtml); } else if (tableHeaderType == TableHeaderRowType.FirstRow) { // Move the first row from 'TaskHtml' to 'StartHtml' and // change its type to 'thead' var tableBody = AgilityUtils.FindElement(elm, "TBODY"); var firstRow = AgilityUtils.FindElement(tableBody, "TR"); if (firstRow != null) { var theadHtml = String.Format("\n<thead>{0}</thead>", firstRow.OuterHtml); this.StartHtml = this.StartHtml.Insert(tbodyStart, theadHtml); tableBody.ChildNodes.Remove(firstRow); } } } this.TableHeaderRow = tableHeaderType; } } } else { elm = doc.DocumentNode; } this.TaskHtml = InjectTextColourPlaceholder(elm).Trim(); } } catch { this.Clear(); } }
public Layout GetLayout(HtmlReportUtils.CustomAttributes custAttribs) { return(new Layout(Text, TableHeaderRow, custAttribs)); }
// ------------------------------------------------------ public Layout(String text, TableHeaderRowType type, HtmlReportUtils.CustomAttributes customAttributes) { Initialise(text, type, customAttributes); }