/// <summary> /// Creates a widget that contains a label with an icon on its left. /// </summary> /// <param name="text">The label text</param> /// <param name="icon">Icon path/Stock name</param> /// <remarks> /// If 'icon' is not a valid path, it is treated like a stock name. /// Invalid stock names default to an invalid file icon. /// </remarks> public Widget LabelWithIcon(string text, string icon) { Gtk.Image image; if (String.IsNullOrEmpty(icon)) // If no icon name provided, try using the text. { string nameForImage = "ApsimNG.Resources.TreeViewImages." + text + ".png"; if (HasResource(nameForImage)) { icon = nameForImage; } else { icon = "ApsimNG.Resources.apsim logo32.png"; } } // Are we looking for a resource? if (HasResource(icon)) { image = new Gtk.Image(new Gdk.Pixbuf(null, icon, 12, 12)); } // Or maybe a file? else if (File.Exists(icon)) { image = new Gtk.Image(new Gdk.Pixbuf(icon, 12, 12)); } else // OK, let's try the stock icons { image = new Gtk.Image(); image.SetFromIconName(icon, IconSize.Menu); } image.Visible = true; // Make a label Label label = new Label(text); label.Visible = true; // Attach the label and icon together HBox box = new HBox(false, 4); box.PackStart(image, false, true, 0); box.PackStart(label, false, true, 0); box.Visible = true; return(box); }
public GtkAlertDialog(MessageDescription message) { Init(); this.buttons = message.Buttons.ToArray(); string primaryText; string secondaryText; if (string.IsNullOrEmpty(message.SecondaryText)) { secondaryText = message.Text; primaryText = null; } else { primaryText = message.Text; secondaryText = message.SecondaryText; } image.Stock = message.Icon; image.SetFromIconName(Util.ToGtkStock(message.Icon), Gtk.IconSize.Dialog); // image.Pixbuf = ImageService.GetPixbuf (message.Icon, IconSize.Dialog); StringBuilder markup = new StringBuilder(@"<span weight=""bold"" size=""larger"">"); markup.Append(GLib.Markup.EscapeText(primaryText)); markup.Append("</span>"); if (!String.IsNullOrEmpty(secondaryText)) { if (!String.IsNullOrEmpty(primaryText)) { markup.AppendLine(); markup.AppendLine(); } markup.Append(GLib.Markup.EscapeText(secondaryText)); } label.Markup = markup.ToString(); label.Selectable = true; label.CanFocus = false; foreach (Command button in message.Buttons) { Gtk.Button newButton = new Gtk.Button(); newButton.Label = button.Label; newButton.UseUnderline = true; newButton.UseStock = button.IsStockButton; if (!String.IsNullOrEmpty(button.Icon)) { newButton.Image = new Gtk.Image(Util.ToGtkStock(button.Icon), Gtk.IconSize.Button); } newButton.Clicked += ButtonClicked; ActionArea.Add(newButton); } foreach (var op in message.Options) { CheckButton check = new CheckButton(op.Text); check.Active = op.Value; labelsBox.PackStart(check, false, false, 0); check.Toggled += delegate { message.SetOptionValue(op.Id, check.Active); }; } if (message.AllowApplyToAll) { CheckButton check = new CheckButton("Apply to all"); labelsBox.PackStart(check, false, false, 0); check.Toggled += delegate { ApplyToAll = check.Active; }; } //don't show this yet, let the consumer decide when this.Child.ShowAll(); }