void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { if (TreeIter.Zero.Equals(iter)) { return; } var textRenderer = (CellRendererText)cell; var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn); if (searchResult == null || searchResult.Offset < 0) { textRenderer.Markup = "Invalid search result"; return; } string textMarkup = markupCache.FirstOrDefault(t => t.Item1 == searchResult)?.Item2; bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter); if (isSelected) { textMarkup = null; } if (textMarkup == null) { var doc = GetDocument(searchResult); if (doc == null) { textMarkup = "Can't create document for:" + searchResult.FileName; goto end; } int lineNumber, startIndex = 0, endIndex = 0; try { lineNumber = doc.OffsetToLineNumber(searchResult.Offset); } catch (ArgumentOutOfRangeException) { lineNumber = -1; textMarkup = "Invalid search result offset"; goto end; } var line = doc.GetLine(lineNumber); if (line == null) { textMarkup = "Invalid line number " + lineNumber + " from offset: " + searchResult.Offset; goto end; } int indent = line.GetIndentation(doc).Length; var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent); int col = searchResult.Offset - line.Offset - indent; // search result contained part of the indent. if (col + searchResult.Length < lineText.Length) { lineText = doc.GetTextAt(line.Offset, line.Length); } string markup; if (isSelected) { markup = Ambience.EscapeText(doc.GetTextAt(line.Offset + indent, line.Length - indent)); } else { markup = doc.GetMarkup(line.Offset + indent, line.Length - indent, new MarkupOptions(MarkupFormat.Pango)); markup = AdjustColors(markup); } if (col >= 0) { uint start; uint end; try { start = (uint)TranslateIndexToUTF8(lineText, col); end = (uint)TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col + searchResult.Length)); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e); return; } startIndex = (int)start; endIndex = (int)end; } try { textMarkup = markup; if (!isSelected) { var searchColor = searchResult.GetBackgroundMarkerColor(highlightStyle); double b1 = HslColor.Brightness(searchColor); double b2 = HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), SyntaxHighlightingService.GetColor(highlightStyle, EditorThemeColors.Foreground))); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { var color1 = SyntaxHighlightingService.GetColor(highlightStyle, EditorThemeColors.FindHighlight); if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } if (startIndex != endIndex) { textMarkup = PangoHelper.ColorMarkupBackground(textMarkup, (int)startIndex, (int)endIndex, searchColor); } } else { var searchColor = this.treeviewSearchResults.Style.Base(StateType.Selected); searchColor = searchColor.AddLight(-0.2); textMarkup = PangoHelper.ColorMarkupBackground(textMarkup, (int)startIndex, (int)endIndex, searchColor); } } catch (Exception e) { LoggingService.LogError("Error whil setting the text renderer markup to: " + markup, e); } end: textMarkup = textMarkup.Replace("\t", new string (' ', doc.Options.TabSize)); if (!isSelected) { markupCache.Add(Tuple.Create(searchResult, textMarkup)); if (markupCache.Count > 100) { markupCache.RemoveAt(0); } } } textRenderer.Markup = textMarkup; }
void ResultTextDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { if (TreeIter.Zero.Equals(iter)) { return; } var textRenderer = (CellRendererText)cell; var searchResult = (SearchResult)store.GetValue(iter, SearchResultColumn); if (searchResult == null || searchResult.Offset < 0) { textRenderer.Markup = "Invalid search result"; return; } var doc = GetDocument(searchResult); if (doc == null) { textRenderer.Markup = "Can't create document for:" + searchResult.FileName; return; } bool isSelected = treeviewSearchResults.Selection.IterIsSelected(iter); if (searchResult.Markup == null) { if (searchResult.LineNumber <= 0) { searchResult.LineNumber = doc.OffsetToLineNumber(searchResult.Offset); } DocumentLine line = doc.GetLine(searchResult.LineNumber); if (line == null) { textRenderer.Markup = "Invalid line number " + searchResult.LineNumber + " from offset: " + searchResult.Offset; return; } int indent = line.GetIndentation(doc).Length; var data = new Mono.TextEditor.TextEditorData(doc); data.ColorStyle = highlightStyle; var lineText = doc.GetTextAt(line.Offset + indent, line.Length - indent); int col = searchResult.Offset - line.Offset - indent; // search result contained part of the indent. if (col + searchResult.Length < lineText.Length) { lineText = doc.GetTextAt(line.Offset, line.Length); } var markup = doc.SyntaxMode != null? data.GetMarkup(line.Offset + indent, line.Length - indent, true, !isSelected, false) : GLib.Markup.EscapeText(lineText); searchResult.Markup = AdjustColors(markup.Replace("\t", new string (' ', TextEditorOptions.DefaultOptions.TabSize))); if (col >= 0) { uint start; uint end; try { start = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, col); end = (uint)TextViewMargin.TranslateIndexToUTF8(lineText, Math.Min(lineText.Length, col + searchResult.Length)); } catch (Exception e) { LoggingService.LogError("Exception while translating index to utf8 (column was:" + col + " search result length:" + searchResult.Length + " line text:" + lineText + ")", e); return; } searchResult.StartIndex = start; searchResult.EndIndex = end; } } try { textRenderer.Markup = searchResult.Markup; if (!isSelected) { var searchColor = searchResult.GetBackgroundMarkerColor(highlightStyle).Color; double b1 = Mono.TextEditor.HslColor.Brightness(searchColor); double b2 = Mono.TextEditor.HslColor.Brightness(AdjustColor(Style.Base(StateType.Normal), (Mono.TextEditor.HslColor)highlightStyle.PlainText.Foreground)); double delta = Math.Abs(b1 - b2); if (delta < 0.1) { Mono.TextEditor.HslColor color1 = highlightStyle.SearchResult.Color; if (color1.L + 0.5 > 1.0) { color1.L -= 0.5; } else { color1.L += 0.5; } searchColor = color1; } if (searchResult.StartIndex != searchResult.EndIndex) { var attr = new Pango.AttrBackground((ushort)(searchColor.R * ushort.MaxValue), (ushort)(searchColor.G * ushort.MaxValue), (ushort)(searchColor.B * ushort.MaxValue)); attr.StartIndex = searchResult.StartIndex; attr.EndIndex = searchResult.EndIndex; using (var list = textRenderer.Attributes.Copy()) { list.Insert(attr); textRenderer.Attributes = list; } } } } catch (Exception e) { LoggingService.LogError("Error whil setting the text renderer markup to: " + searchResult.Markup, e); } }
protected override bool OnExposeEvent(Gdk.EventExpose e) { Cairo.Context cr = Gdk.CairoHelper.Create(e.Window); Gdk.Rectangle area = e.Area; if (this.categories.Count == 0 || !string.IsNullOrEmpty(CustomMessage)) { Pango.Layout messageLayout = new Pango.Layout(this.PangoContext); messageLayout.Alignment = Pango.Alignment.Center; messageLayout.Width = (int)(Allocation.Width * 2 / 3 * Pango.Scale.PangoScale); if (!string.IsNullOrEmpty(CustomMessage)) { messageLayout.SetText(CustomMessage); } else { messageLayout.SetText(MonoDevelop.Core.GettextCatalog.GetString("There are no tools available for the current document.")); } cr.MoveTo(Allocation.Width * 1 / 6, 12); cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); Pango.CairoHelper.ShowLayout(cr, messageLayout); messageLayout.Dispose(); ((IDisposable)cr).Dispose(); return(true); } var backColor = Style.Base(StateType.Normal).ToCairoColor(); cr.SetSourceColor(backColor); cr.Rectangle(area.X, area.Y, area.Width, area.Height); cr.Fill(); int xpos = (this.hAdjustement != null ? (int)this.hAdjustement.Value : 0); int vadjustment = (this.vAdjustement != null ? (int)this.vAdjustement.Value : 0); int ypos = -vadjustment; Category lastCategory = null; int lastCategoryYpos = 0; Iterate(ref xpos, ref ypos, delegate(Category category, Gdk.Size itemDimension) { const int foldSegmentHeight = 8; ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); using (var pat = new Cairo.LinearGradient(xpos, ypos, xpos, ypos + itemDimension.Height)) { pat.AddColorStop(0, CategoryBackgroundGradientStartColor); pat.AddColorStop(1, CategoryBackgroundGradientEndColor); cr.SetSource(pat); cr.Fill(); } if (lastCategory == null || lastCategory.IsExpanded || lastCategory.AnimatingExpand) { cr.MoveTo(xpos, ypos + 0.5); cr.LineTo(itemDimension.Width, ypos + 0.5); } cr.MoveTo(0, ypos + itemDimension.Height - 0.5); cr.LineTo(xpos + Allocation.Width, ypos + itemDimension.Height - 0.5); cr.SetSourceColor(CategoryBorderColor); cr.LineWidth = 1; cr.Stroke(); headerLayout.SetText(category.Text); int width, height; cr.SetSourceColor(CategoryLabelColor); layout.GetPixelSize(out width, out height); cr.MoveTo(xpos + CategoryLeftPadding, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2))); Pango.CairoHelper.ShowLayout(cr, headerLayout); var img = category.IsExpanded ? discloseUp : discloseDown; cr.DrawImage(this, img, Allocation.Width - img.Width - CategoryRightPadding, ypos + Math.Round((itemDimension.Height - img.Height) / 2)); lastCategory = category; lastCategoryYpos = ypos + itemDimension.Height; }, delegate(Category curCategory, Item item, Gdk.Size itemDimension) { if (item == SelectedItem) { cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Rectangle(xpos, ypos, itemDimension.Width, itemDimension.Height); cr.Fill(); } if (listMode || !curCategory.CanIconizeItems) { cr.DrawImage(this, item.Icon, xpos + ItemLeftPadding, ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2)); layout.SetText(item.Text); int width, height; layout.GetPixelSize(out width, out height); cr.SetSourceColor(Style.Text(item != this.SelectedItem ? StateType.Normal : StateType.Selected).ToCairoColor()); cr.MoveTo(xpos + ItemLeftPadding + IconSize.Width + ItemIconTextItemSpacing, ypos + (double)(Math.Round((double)(itemDimension.Height - height) / 2))); Pango.CairoHelper.ShowLayout(cr, layout); } else { cr.DrawImage(this, item.Icon, xpos + Math.Round((itemDimension.Width - item.Icon.Width) / 2), ypos + Math.Round((itemDimension.Height - item.Icon.Height) / 2)); } if (item == mouseOverItem) { cr.SetSourceColor(Style.Dark(StateType.Prelight).ToCairoColor()); cr.Rectangle(xpos + 0.5, ypos + 0.5, itemDimension.Width - 1, itemDimension.Height - 1); cr.Stroke(); } }); ProcessExpandAnimation(cr, lastCategory, lastCategoryYpos, backColor, area, ref ypos); if (lastCategory != null && lastCategory.AnimatingExpand) { // Closing line when animating the last group of the toolbox cr.MoveTo(area.X, ypos + 0.5); cr.RelLineTo(area.Width, 0); cr.SetSourceColor(CategoryBorderColor); cr.Stroke(); } ((IDisposable)cr).Dispose(); return(true); }
protected override bool OnExposeEvent(Gdk.EventExpose e) { using (Cairo.Context cr = Gdk.CairoHelper.Create(e.Window)) { double xPos = padding, yPos = padding; var layout = PangoUtil.CreateLayout(this); int w, h; layout.SetText(new string ('X', maxLength)); layout.GetPixelSize(out w, out h); foreach (Category cat in categories) { yPos = padding; cr.MoveTo(xPos, yPos); layout.SetMarkup("<b>" + cat.Title + "</b>"); cr.SetSourceColor(Style.Text(StateType.Normal).ToCairoColor()); cr.ShowLayout(layout); if (cat.Items.Count == 0) { continue; } layout.SetMarkup(""); int w2, h2; layout.GetPixelSize(out w2, out h2); yPos += h2; yPos += headerDistance; var startY = yPos; int curItem = 0; int row = 0; var iconHeight = Math.Max(h, cat.Items [0].Icon.Height + 2) + itemPadding * 2; if (cat.FirstVisibleItem > 0) { Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None, new Rectangle((int)xPos, (int)yPos, w, h), this, "", ArrowType.Up, true, (int)xPos, (int)yPos, w, h); yPos += iconHeight; curItem++; } for (int i = cat.FirstVisibleItem; i < cat.Items.Count; i++) { var item = cat.Items [i]; if (curItem + 1 >= maxItems && row + 1 >= maxRows && i + 1 < cat.Items.Count) { Gtk.Style.PaintArrow(Style, e.Window, State, ShadowType.None, new Rectangle((int)xPos, (int)yPos, w, h), this, "", ArrowType.Down, true, (int)xPos, (int)yPos, w, h); break; } if (item == ActiveItem) { int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2; cr.Rectangle(xPos, yPos, itemWidth, iconHeight); cr.LineWidth = 1; cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Fill(); } else if (item == hoverItem) { int itemWidth = w + (int)item.Icon.Width + 2 + itemPadding * 2; cr.Rectangle(xPos + 0.5, yPos + 0.5, itemWidth - 1, iconHeight); cr.LineWidth = 1; cr.SetSourceColor(Style.Base(StateType.Selected).ToCairoColor()); cr.Stroke(); } cr.SetSourceColor(Style.Text(item == ActiveItem? StateType.Selected : StateType.Normal).ToCairoColor()); cr.MoveTo(xPos + item.Icon.Width + 2 + itemPadding, yPos + (iconHeight - h) / 2); layout.SetText(Ellipsize(item.ListTitle ?? item.Title, maxLength)); cr.ShowLayout(layout); cr.DrawImage(this, item == ActiveItem ? item.Icon.WithStyles("sel") : item.Icon, (int)xPos + itemPadding, (int)(yPos + (iconHeight - item.Icon.Height) / 2)); yPos += iconHeight; if (++curItem >= maxItems) { curItem = 0; yPos = startY; xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2; row++; } } xPos += w + cat.Items [0].Icon.Width + 2 + padding + itemPadding * 2; } layout.Dispose(); } return(true); }
private void BuildInfoBox() { var frame = new Hyena.Widgets.RoundedFrame(); var vbox = new VBox(); vbox.Spacing = 6; vbox.BorderWidth = 2; // Description var desc = new Hyena.Widgets.WrapLabel() { Markup = String.Format("{0}", GLib.Markup.EscapeText(Hyena.StringUtil.RemoveHtml(details.Description))) }; var desc_expander = CreateSection(Catalog.GetString("Description"), desc); // Details var table = new Banshee.Gui.TrackEditor.StatisticsPage() { ShadowType = ShadowType.None, BorderWidth = 0 }; table.NameRenderer.Scale = Pango.Scale.Medium; table.ValueRenderer.Scale = Pango.Scale.Medium; // Keep the table from needing to vertically scroll table.Child.SizeRequested += (o, a) => { table.SetSizeRequest(a.Requisition.Width, a.Requisition.Height); }; AddToTable(table, Catalog.GetString("Creator:"), details.Creator); AddToTable(table, Catalog.GetString("Venue:"), details.Venue); AddToTable(table, Catalog.GetString("Location:"), details.Coverage); if (details.DateCreated != DateTime.MinValue) { AddToTable(table, Catalog.GetString("Date:"), details.DateCreated); } else { AddToTable(table, Catalog.GetString("Year:"), details.Year); } AddToTable(table, Catalog.GetString("Publisher:"), details.Publisher); AddToTable(table, Catalog.GetString("Keywords:"), details.Subject); AddToTable(table, Catalog.GetString("License URL:"), details.LicenseUrl); AddToTable(table, Catalog.GetString("Language:"), details.Language); table.AddSeparator(); AddToTable(table, Catalog.GetString("Downloads, overall:"), details.DownloadsAllTime); AddToTable(table, Catalog.GetString("Downloads, past month:"), details.DownloadsLastMonth); AddToTable(table, Catalog.GetString("Downloads, past week:"), details.DownloadsLastWeek); table.AddSeparator(); AddToTable(table, Catalog.GetString("Added:"), details.DateAdded); AddToTable(table, Catalog.GetString("Added by:"), details.AddedBy); AddToTable(table, Catalog.GetString("Collections:"), details.Collections); AddToTable(table, Catalog.GetString("Source:"), details.Source); AddToTable(table, Catalog.GetString("Contributor:"), details.Contributor); AddToTable(table, Catalog.GetString("Recorded by:"), details.Taper); AddToTable(table, Catalog.GetString("Lineage:"), details.Lineage); AddToTable(table, Catalog.GetString("Transferred by:"), details.Transferer); var details_expander = CreateSection(Catalog.GetString("Details"), table); // Reviews Section reviews = null; if (details.NumReviews > 0) { string [] stars = { "\u2606\u2606\u2606\u2606\u2606", "\u2605\u2606\u2606\u2606\u2606", "\u2605\u2605\u2606\u2606\u2606", "\u2605\u2605\u2605\u2606\u2606", "\u2605\u2605\u2605\u2605\u2606", "\u2605\u2605\u2605\u2605\u2605" }; var reviews_box = new VBox() { Spacing = 12, BorderWidth = 0 }; reviews = CreateSection(Catalog.GetString("Reviews"), reviews_box); var avg_label = new Label(String.Format(Catalog.GetPluralString( // Translators: {0} is the number of reviewers, {1} is the average rating (not really relevant if there's only 1) "{0} reviewer", "{0} reviewers, avg {1}", details.NumReviews), details.NumReviews, stars[Math.Max(0, Math.Min(5, (int)Math.Round(details.AvgRating)))] )); avg_label.TooltipText = String.Format("{0:N2}", details.AvgRating); avg_label.Xalign = 1.0f; reviews.Header.Box.PackEnd(avg_label, false, false, 0); var sb = new System.Text.StringBuilder(); foreach (var review in details.Reviews) { //sb.Append ("<small>"); var review_txt = new Hyena.Widgets.WrapLabel(); var title = review.Title; if (title != null) { sb.AppendFormat("<b>{0}</b>\n", GLib.Markup.EscapeText(title)); } // Translators: {0} is the unicode-stars-rating, {1} is the name of a person who reviewed this item, and {1} is a date/time string sb.AppendFormat(Catalog.GetString("{0} by {1} on {2}"), stars[Math.Max(0, Math.Min(5, review.Stars))], GLib.Markup.EscapeText(review.Reviewer), GLib.Markup.EscapeText(review.DateReviewed.ToLocalTime().ToShortDateString()) ); var body = review.Body; if (body != null) { body = body.Replace("\r\n", "\n"); body = body.Replace("\n\n", "\n"); sb.Append("\n"); sb.Append(GLib.Markup.EscapeText(body)); } //sb.Append ("</small>"); review_txt.Markup = sb.ToString(); sb.Length = 0; reviews_box.PackStart(review_txt, false, false, 0); } } // Packing vbox.PackStart(desc_expander, true, true, 0); vbox.PackStart(details_expander, true, true, 0); if (reviews != null) { vbox.PackStart(reviews, true, true, 0); } string write_review_url = String.Format("http://www.archive.org/write-review.php?identifier={0}", item.Id); var write_review_button = new LinkButton(write_review_url, Catalog.GetString("Write your own review")); write_review_button.Clicked += (o, a) => Banshee.Web.Browser.Open(write_review_url); write_review_button.Xalign = 0f; vbox.PackStart(write_review_button, false, false, 0); var vbox2 = new VBox(); vbox2.PackStart(vbox, false, false, 0); var sw = new Gtk.ScrolledWindow() { ShadowType = ShadowType.None }; sw.AddWithViewport(vbox2); (sw.Child as Viewport).ShadowType = ShadowType.None; frame.Child = sw; frame.ShowAll(); sw.Child.ModifyBg(StateType.Normal, Style.Base(StateType.Normal)); sw.Child.ModifyFg(StateType.Normal, Style.Text(StateType.Normal)); sw.Child.ModifyText(StateType.Normal, Style.Text(StateType.Normal)); StyleSet += delegate { sw.Child.ModifyBg(StateType.Normal, Style.Base(StateType.Normal)); sw.Child.ModifyFg(StateType.Normal, Style.Text(StateType.Normal)); sw.Child.ModifyText(StateType.Normal, Style.Text(StateType.Normal)); }; PackStart(frame, true, true, 0); }
protected override void OnStyleSet(Style previous_style) { base.OnStyleSet(previous_style); results_tv.ModifyBg(StateType.Normal, Style.Base(StateType.Normal)); }
void SyntaxCellRenderer(Gtk.CellLayout cell_layout, Gtk.CellRenderer cell, Gtk.TreeModel tree_model, Gtk.TreeIter iter) { var renderer = (Gtk.CellRendererText)cell; var data = (ColorMetaData)colorStore.GetValue(iter, 2); var style = (ChunkStyle)colorStore.GetValue(iter, 1); string markup = GLib.Markup.EscapeText(data.Description); if (style.Bold) { markup = "<b>" + markup + "</b>"; } if (style.Italic) { markup = "<i>" + markup + "</i>"; } renderer.Markup = markup; if (data.ColorsAvailable == ColorsAvailable.Text || data.ColorsAvailable == ColorsAvailable.FgBg) { renderer.ForegroundGdk = style.Color; renderer.BackgroundGdk = style.GotBackgroundColorAssigned ? style.BackgroundColor : Style.Base(StateType.Normal); } else { var b = Math.Abs(HslColor.Brightness(style.Color) - HslColor.Brightness(Style.Text(StateType.Normal))); renderer.ForegroundGdk = b < 0.4 ? Style.Background(StateType.Normal) : Style.Text(StateType.Normal); renderer.BackgroundGdk = style.Color; } }