2014-01-29 19:09:30 -08:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
using MatterHackers.Agg;
|
|
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Agg.Image;
|
|
|
|
|
|
using MatterHackers.Agg.Font;
|
2014-02-05 18:29:58 -08:00
|
|
|
|
using MatterHackers.Localizations;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl
|
|
|
|
|
|
{
|
|
|
|
|
|
public class StyledMessageBox : SystemWindow
|
|
|
|
|
|
{
|
|
|
|
|
|
public EventHandler ClickedOk;
|
|
|
|
|
|
TextImageButtonFactory textImageButtonFactory = new TextImageButtonFactory();
|
|
|
|
|
|
|
|
|
|
|
|
public enum MessageType { OK, YES_NO };
|
|
|
|
|
|
|
|
|
|
|
|
public static bool ShowMessageBox(String message, string caption, MessageType messageType = MessageType.OK)
|
|
|
|
|
|
{
|
|
|
|
|
|
string wrappedMessage = TypeFacePrinter.InsertCRs(message, 350, 12);
|
|
|
|
|
|
StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, null, 400, 300);
|
|
|
|
|
|
bool okClicked = false;
|
|
|
|
|
|
messageBox.ClickedOk += (sender, e) => { okClicked = true; };
|
|
|
|
|
|
messageBox.ShowAsSystemWindow();
|
|
|
|
|
|
return okClicked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool ShowMessageBox(string message, string caption, GuiWidget[] extraWidgetsToAdd, MessageType messageType)
|
|
|
|
|
|
{
|
|
|
|
|
|
string wrappedMessage = TypeFacePrinter.InsertCRs(message, 300, 12);
|
|
|
|
|
|
StyledMessageBox messageBox = new StyledMessageBox(wrappedMessage, caption, messageType, extraWidgetsToAdd, 400, 300);
|
|
|
|
|
|
bool okClicked = false;
|
|
|
|
|
|
messageBox.ClickedOk += (sender, e) => { okClicked = true; };
|
|
|
|
|
|
messageBox.ShowAsSystemWindow();
|
|
|
|
|
|
return okClicked;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public StyledMessageBox(String message, string windowTitle, MessageType messageType, GuiWidget[] extraWidgetsToAdd, double width, double height)
|
|
|
|
|
|
: base(width, height)
|
|
|
|
|
|
{
|
|
|
|
|
|
BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;
|
|
|
|
|
|
|
|
|
|
|
|
textImageButtonFactory.FixedWidth = 50;
|
|
|
|
|
|
|
|
|
|
|
|
FlowLayoutWidget topToBottomFlow = new FlowLayoutWidget(FlowDirection.TopToBottom);
|
|
|
|
|
|
//topToBottomFlow.DebugShowBounds = true;
|
|
|
|
|
|
TextWidget messageContainer = new TextWidget(message, textColor: ActiveTheme.Instance.PrimaryTextColor);
|
|
|
|
|
|
messageContainer.HAnchor = Agg.UI.HAnchor.ParentCenter;
|
|
|
|
|
|
topToBottomFlow.AddChild(messageContainer);
|
|
|
|
|
|
|
|
|
|
|
|
if (extraWidgetsToAdd != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (GuiWidget widget in extraWidgetsToAdd)
|
|
|
|
|
|
{
|
|
|
|
|
|
topToBottomFlow.AddChild(widget);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Title = windowTitle;
|
|
|
|
|
|
|
|
|
|
|
|
// add a spacer
|
|
|
|
|
|
GuiWidget spacer = new GuiWidget(10, 10);
|
|
|
|
|
|
spacer.HAnchor |= Agg.UI.HAnchor.ParentCenter;
|
|
|
|
|
|
//spacer.DebugShowBounds = true;
|
|
|
|
|
|
topToBottomFlow.AddChild(spacer);
|
|
|
|
|
|
topToBottomFlow.HAnchor = Agg.UI.HAnchor.ParentCenter | Agg.UI.HAnchor.FitToChildren;
|
|
|
|
|
|
topToBottomFlow.VAnchor = Agg.UI.VAnchor.ParentCenter | Agg.UI.VAnchor.FitToChildren;
|
|
|
|
|
|
|
|
|
|
|
|
switch (messageType)
|
|
|
|
|
|
{
|
|
|
|
|
|
case MessageType.YES_NO:
|
|
|
|
|
|
{
|
|
|
|
|
|
FlowLayoutWidget yesNoButtonsFlow = new FlowLayoutWidget();
|
|
|
|
|
|
yesNoButtonsFlow.HAnchor |= HAnchor.ParentCenter;
|
|
|
|
|
|
|
2014-02-05 18:29:58 -08:00
|
|
|
|
Button yesButton = textImageButtonFactory.Generate(new LocalizedString("Yes").Translated, centerText:true);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
yesButton.Click += new ButtonBase.ButtonEventHandler(okButton_Click);
|
|
|
|
|
|
yesNoButtonsFlow.AddChild(yesButton);
|
|
|
|
|
|
|
|
|
|
|
|
GuiWidget buttonSpacer = new GuiWidget(10, 10);
|
|
|
|
|
|
yesNoButtonsFlow.AddChild(buttonSpacer);
|
|
|
|
|
|
|
2014-02-05 18:29:58 -08:00
|
|
|
|
Button noButton = textImageButtonFactory.Generate(new LocalizedString("No").Translated, centerText: true);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
noButton.Click += new ButtonBase.ButtonEventHandler(noButton_Click);
|
|
|
|
|
|
yesNoButtonsFlow.AddChild(noButton);
|
|
|
|
|
|
|
|
|
|
|
|
topToBottomFlow.AddChild(yesNoButtonsFlow);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MessageType.OK:
|
|
|
|
|
|
{
|
2014-02-05 18:29:58 -08:00
|
|
|
|
Button okButton = textImageButtonFactory.Generate(new LocalizedString("Ok").Translated, centerText: true);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
//okButton.DebugShowBounds = true;
|
|
|
|
|
|
okButton.Click += new ButtonBase.ButtonEventHandler(okButton_Click);
|
|
|
|
|
|
okButton.HAnchor = HAnchor.ParentCenter;
|
|
|
|
|
|
topToBottomFlow.AddChild(okButton);
|
|
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AddChild(topToBottomFlow);
|
|
|
|
|
|
|
|
|
|
|
|
IsModal = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void noButton_Click(object sender, MouseEventArgs mouseEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
UiThread.RunOnIdle(CloseOnIdle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void okButton_Click(object sender, MouseEventArgs mouseEvent)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (ClickedOk != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ClickedOk(this, null);
|
|
|
|
|
|
}
|
|
|
|
|
|
UiThread.RunOnIdle(CloseOnIdle);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CloseOnIdle(object state)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|