~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Dialogs/GtkErrorDialog.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2012-02-05 10:49:36 UTC
  • mto: (10.3.1)
  • mto: This revision was merged to the branch mainline in revision 25.
  • Revision ID: package-import@ubuntu.com-20120205104936-4ujoylapu24cquuo
Tags: upstream-2.8.6.3+dfsg
ImportĀ upstreamĀ versionĀ 2.8.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
{
33
33
        internal partial class GtkErrorDialog : Gtk.Dialog
34
34
        {
35
 
                TextTag tagNoWrap;
36
 
                TextTag tagWrap;
 
35
                TextTag tagWrap, tagNoWrap;
 
36
                TextView detailsTextView;
 
37
                Expander expander;
37
38
                
38
 
                public GtkErrorDialog (Window parent)
 
39
                public GtkErrorDialog (Window parent, string title, string message, AlertButton[] buttons)
39
40
                {
40
 
                        this.Build ();
41
 
                        this.Title = BrandingService.ApplicationName;
 
41
                        if (string.IsNullOrEmpty (title))
 
42
                                throw new ArgumentException ();
 
43
                        if (buttons == null)
 
44
                                throw new ArgumentException ();
 
45
                        
 
46
                        Title = BrandingService.ApplicationName;
42
47
                        TransientFor = parent;
43
 
                        descriptionLabel.ModifyBg (StateType.Normal, new Gdk.Color (255,0,0));
 
48
                        Modal = true;
 
49
                        WindowPosition = Gtk.WindowPosition.CenterOnParent;
 
50
                        DefaultWidth = 624;
 
51
                        DefaultHeight = 142;
 
52
                        
 
53
                        this.VBox.BorderWidth = 2;
 
54
                        
 
55
                        var hbox = new HBox () {
 
56
                                Spacing = 6,
 
57
                                BorderWidth = 12,
 
58
                        };
 
59
                        
 
60
                        var errorImage = new Image (Gtk.Stock.DialogError, IconSize.Dialog) {
 
61
                                Yalign = 0F,
 
62
                        };
 
63
                        hbox.PackStart (errorImage, false, false, 0);
 
64
                        this.VBox.Add (hbox);
 
65
                        
 
66
                        var vbox = new VBox () {
 
67
                                Spacing = 6,
 
68
                        };
 
69
                        hbox.PackEnd (vbox, true, true, 0);
 
70
                        
 
71
                        var titleLabel = new Label () {
 
72
                                Markup = "<b>" + GLib.Markup.EscapeText (title) + "</b>",
 
73
                                Xalign = 0F,
 
74
                        };
 
75
                        vbox.PackStart (titleLabel, false, false, 0);
 
76
                        
 
77
                        if (!string.IsNullOrWhiteSpace (message)) {
 
78
                                message = message.Trim ();
 
79
                                var descriptionLabel = new Label (message) {
 
80
                                        Xalign = 0F,
 
81
                                        Selectable = true,
 
82
                                };
 
83
                                descriptionLabel.LineWrap = true;
 
84
                                descriptionLabel.WidthRequest = 500;
 
85
                                descriptionLabel.ModifyBg (StateType.Normal, new Gdk.Color (255,0,0));
 
86
                                vbox.PackStart (descriptionLabel, false, false, 0);
 
87
                        }
 
88
                        
 
89
                        expander = new Expander (GettextCatalog.GetString ("Details")) {
 
90
                                CanFocus = true,
 
91
                                Visible = false,
 
92
                        };
 
93
                        vbox.PackEnd (expander, true, true, 0);
 
94
                        
 
95
                        var sw = new ScrolledWindow () {
 
96
                                HeightRequest = 180,
 
97
                                ShadowType = ShadowType.Out,
 
98
                        };
 
99
                        expander.Add (sw);
 
100
                        
 
101
                        detailsTextView = new TextView () {
 
102
                                CanFocus = true,
 
103
                        };
 
104
                        sw.Add (detailsTextView);
 
105
                        
 
106
                        var aa = this.ActionArea;
 
107
                        aa.Spacing = 10;
 
108
                        aa.LayoutStyle = ButtonBoxStyle.End;
 
109
                        aa.BorderWidth = 5;
 
110
                        aa.Homogeneous = true;
 
111
                        
 
112
                        expander.Activated += delegate {
 
113
                                this.AllowGrow = expander.Expanded;
 
114
                                GLib.Timeout.Add (100, delegate {
 
115
                                        Resize (DefaultWidth, 1);
 
116
                                        return false;
 
117
                                });
 
118
                        };
44
119
                        
45
120
                        tagNoWrap = new TextTag ("nowrap");
46
121
                        tagNoWrap.WrapMode = WrapMode.None;
50
125
                        tagWrap.WrapMode = WrapMode.Word;
51
126
                        detailsTextView.Buffer.TagTable.Add (tagWrap);
52
127
                        
53
 
                        expander.Visible = false;
54
 
                }
55
 
                
56
 
                public string Message {
57
 
                        get { return descriptionLabel.Text; }
58
 
                        set {
59
 
                                string message = value;
60
 
                                while (message.EndsWith ("\r") || message.EndsWith ("\n"))
61
 
                                        message = message.Substring (0, message.Length - 1);
62
 
                                if (!message.EndsWith (".")) message += ".";
63
 
                                descriptionLabel.Text = message;
 
128
                        this.Buttons = buttons;
 
129
                        for (int i = 0; i < Buttons.Length; i++) {
 
130
                                Gtk.Button button;
 
131
                                button = new Gtk.Button (Buttons[i].Label);
 
132
                                button.ShowAll ();
 
133
                                AddActionWidget (button, i);
64
134
                        }
 
135
                        
 
136
                        Child.ShowAll ();
 
137
                        Hide ();
65
138
                }
66
139
                
 
140
                public AlertButton[] Buttons {
 
141
                        get; private set;
 
142
                }
 
143
 
67
144
                public void AddDetails (string text, bool wrapped)
68
145
                {
69
146
                        TextIter it = detailsTextView.Buffer.EndIter;
73
150
                                detailsTextView.Buffer.InsertWithTags (ref it, text, tagNoWrap);
74
151
                        expander.Visible = true;
75
152
                }
76
 
                
77
 
                protected virtual void OnExpander1Activated (object sender, System.EventArgs e)
78
 
                {
79
 
                        GLib.Timeout.Add (100, new GLib.TimeoutHandler (UpdateSize));
80
 
                }
81
 
                
82
 
                bool UpdateSize ()
83
 
                {
84
 
                        int w, h;
85
 
                        GetSize (out w, out h);
86
 
                        Resize (w, 1);
87
 
                        return false;
88
 
                }
89
 
                
90
 
                protected virtual void OnOkButtonClicked (object sender, System.EventArgs e)
91
 
                {
92
 
                        Destroy ();
93
 
                }
94
153
        }
95
154
}
96
155