Fixed #374055:Only the first "tag" is detected in digikam.
[beagle.git] / Util / HigMessageDialog.cs
blob3b22aec4ce60c361e989417a77c80e2f7601a546
1 using System;
2 // created on 24/01/2005 at 20:14
3 // Taken pretty much wholesale from Tomboy
5 namespace Beagle.Util
7 public class HigMessageDialog : Gtk.Dialog
9 Gtk.AccelGroup accel_group;
11 public HigMessageDialog (Gtk.Window parent,
12 Gtk.DialogFlags flags,
13 Gtk.MessageType type,
14 Gtk.ButtonsType buttons,
15 string header,
16 string msg) : base ()
18 HasSeparator = false;
19 BorderWidth = 5;
20 Resizable = false;
21 Title = "";
23 VBox.Spacing = 12;
24 ActionArea.Layout = Gtk.ButtonBoxStyle.End;
26 accel_group = new Gtk.AccelGroup ();
27 AddAccelGroup (accel_group);
29 Gtk.HBox hbox = new Gtk.HBox (false, 12);
30 hbox.BorderWidth = 5;
31 hbox.Show ();
32 VBox.PackStart (hbox, false, false, 0);
34 Gtk.Image image = null;
36 switch (type) {
37 case Gtk.MessageType.Error:
38 image = new Gtk.Image (Gtk.Stock.DialogError, Gtk.IconSize.Dialog);
39 break;
40 case Gtk.MessageType.Question:
41 image = new Gtk.Image (Gtk.Stock.DialogQuestion, Gtk.IconSize.Dialog);
42 break;
43 case Gtk.MessageType.Info:
44 image = new Gtk.Image (Gtk.Stock.DialogInfo, Gtk.IconSize.Dialog);
45 break;
46 case Gtk.MessageType.Warning:
47 image = new Gtk.Image (Gtk.Stock.DialogWarning, Gtk.IconSize.Dialog);
48 break;
51 image.Show ();
52 hbox.PackStart (image, false, false, 0);
54 Gtk.VBox label_vbox = new Gtk.VBox (false, 0);
55 label_vbox.Show ();
56 hbox.PackStart (label_vbox, true, true, 0);
58 string title = String.Format ("<span weight='bold' size='larger'>{0}" +
59 "</span>\n",
60 header);
62 Gtk.Label label;
64 label = new Gtk.Label (title);
65 label.UseMarkup = true;
66 label.Justify = Gtk.Justification.Left;
67 label.LineWrap = true;
68 label.SetAlignment (0.0f, 0.5f);
69 label.Show ();
70 label_vbox.PackStart (label, false, false, 0);
72 label = new Gtk.Label (msg);
73 label.UseMarkup = true;
74 label.Justify = Gtk.Justification.Left;
75 label.LineWrap = true;
76 label.SetAlignment (0.0f, 0.5f);
77 label.Show ();
78 label_vbox.PackStart (label, false, false, 0);
80 switch (buttons) {
81 case Gtk.ButtonsType.None:
82 break;
83 case Gtk.ButtonsType.Ok:
84 AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok, true);
85 break;
86 case Gtk.ButtonsType.Close:
87 AddButton (Gtk.Stock.Close, Gtk.ResponseType.Close, true);
88 break;
89 case Gtk.ButtonsType.Cancel:
90 AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, true);
91 break;
92 case Gtk.ButtonsType.YesNo:
93 AddButton (Gtk.Stock.No, Gtk.ResponseType.No, false);
94 AddButton (Gtk.Stock.Yes, Gtk.ResponseType.Yes, true);
95 break;
96 case Gtk.ButtonsType.OkCancel:
97 AddButton (Gtk.Stock.Cancel, Gtk.ResponseType.Cancel, false);
98 AddButton (Gtk.Stock.Ok, Gtk.ResponseType.Ok, true);
99 break;
102 if (parent != null)
103 TransientFor = parent;
105 if ((int) (flags & Gtk.DialogFlags.Modal) != 0)
106 Modal = true;
108 if ((int) (flags & Gtk.DialogFlags.DestroyWithParent) != 0)
109 DestroyWithParent = true;
112 // constructor for a HIG confirmation alert with two buttons
113 public HigMessageDialog (Gtk.Window parent,
114 Gtk.DialogFlags flags,
115 Gtk.MessageType type,
116 string header,
117 string msg,
118 string ok_caption)
119 : this (parent, flags, type, Gtk.ButtonsType.Cancel, header, msg)
121 AddButton (ok_caption, Gtk.ResponseType.Ok, false);
124 void AddButton (string stock_id, Gtk.ResponseType response, bool is_default)
126 Gtk.Button button = new Gtk.Button (stock_id);
127 button.CanDefault = true;
128 button.Show ();
130 AddActionWidget (button, response);
132 if (is_default) {
133 DefaultResponse = response;
134 button.AddAccelerator ("activate",
135 accel_group,
136 (uint) Gdk.Key.Escape,
138 Gtk.AccelFlags.Visible);
142 //run and destroy a standard dialog
143 public static Gtk.ResponseType RunHigMessageDialog(Gtk.Window parent,
144 Gtk.DialogFlags flags,
145 Gtk.MessageType type,
146 Gtk.ButtonsType buttons,
147 string header,
148 string msg)
150 HigMessageDialog hmd = new HigMessageDialog(parent, flags, type, buttons, header, msg);
151 try {
152 return (Gtk.ResponseType)hmd.Run();
153 } finally {
154 hmd.Destroy();
158 //Run and destroy a standard confirmation dialog
159 public static Gtk.ResponseType RunHigConfirmation(Gtk.Window parent,
160 Gtk.DialogFlags flags,
161 Gtk.MessageType type,
162 string header,
163 string msg,
164 string ok_caption)
166 HigMessageDialog hmd = new HigMessageDialog(parent, flags, type, header, msg, ok_caption);
167 try {
168 return (Gtk.ResponseType)hmd.Run();
169 } finally {
170 hmd.Destroy();