/*
* Copyright (C) 2006 Eskil Bylund
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using Gtk;
using Glade;
namespace DCSharp.GUI{
public class MessageDialog
{
private Glade.XML xml;
private Window parent;
[Widget]
private Dialog dialog;
[Widget]
private Image image;
[Widget]
private Label primaryLabel;
[Widget]
private Label secondaryLabel;
[Widget]
private Expander detailsExpander;
[Widget]
private TextView detailsTextView;
#region Constructors
public MessageDialog(string primaryText, string secondaryText,
string detailedText, MessageType messageType, Window parent) : base()
{
xml = new Glade.XML (null, "MessageDialog.glade", "dialog",
null);
xml.BindFields (this);
this.parent = parent;
PrimaryText = primaryText;
SecondaryText = secondaryText;
DetailedText = detailedText;
MessageType = messageType;
}
#endregion
#region Properties
private string primaryText;
public string PrimaryText
{
get
{
return primaryText;
}
set
{
primaryText = value;
primaryLabel.Markup = String.Format(
"<span size=\"large\" weight=\"bold\">{0}</span>",
primaryText);
primaryLabel.Visible = primaryText != null;
}
}
private string secondaryText;
public string SecondaryText
{
get
{
return secondaryText;
}
set
{
secondaryText = value;
secondaryLabel.Text = secondaryText;
secondaryLabel.Visible = secondaryText != null;
}
}
private string detailedText;
public string DetailedText
{
get
{
return detailedText;
}
set
{
detailedText = value;
detailsTextView.Buffer.Text = detailedText != null ? detailedText : String.Empty;
detailsExpander.Visible = detailedText != null;
dialog.Resizable = detailedText != null;
}
}
private MessageType messageType;
public MessageType MessageType
{
get
{
return messageType;
}
set
{
messageType = value;
image.Visible = true;
switch (messageType)
{
case MessageType.Error:
image.Stock = Stock.DialogError;
break;
case MessageType.Info:
image.Stock = Stock.DialogInfo;
break;
case MessageType.Question:
image.Stock = Stock.DialogQuestion;
break;
case MessageType.Warning:
image.Stock = Stock.DialogWarning;
break;
default:
image.Visible = false;
break;
}
}
}
public Dialog Dialog
{
get
{
return dialog;
}
}
#endregion
#region Methods
public int Run()
{
if (parent != null)
{
dialog.TransientFor = parent;
dialog.WindowPosition = WindowPosition.CenterOnParent;
}
return dialog.Run();
}
public void Hide()
{
dialog.Hide();
}
public void Destroy()
{
dialog.Destroy();
}
public Widget AddButton(string text, ResponseType response)
{
return dialog.AddButton(text, response);
}
#endregion
}
}
|