diff options
| author | jpbruyere <jp.bruyere@hotmail.com> | 2017-02-28 14:26:21 +0100 |
|---|---|---|
| committer | jpbruyere <jp.bruyere@hotmail.com> | 2017-02-28 14:26:21 +0100 |
| commit | 81f601a58343fb673a580df7583cbbadcd6b1e1b (patch) | |
| tree | 1b56482d70226cb39ac51ac4bbe1b9402171caa6 | |
| parent | fcd9ef9adfbd93b508201dea4074566c04618326 (diff) | |
messageBox improvements
| -rw-r--r-- | Crow.csproj | 4 | ||||
| -rw-r--r-- | Default.style | 6 | ||||
| -rw-r--r-- | Templates/MessageBox.template | 12 | ||||
| -rw-r--r-- | src/GraphicObjects/MessageBox.cs | 91 |
4 files changed, 100 insertions, 13 deletions
diff --git a/Crow.csproj b/Crow.csproj index cd8a07b4..20b38cf8 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -204,7 +204,9 @@ <EmbeddedResource Include="Images\Icons\member.svg" /> <EmbeddedResource Include="Images\Icons\exit2.svg" /> <EmbeddedResource Include="Images\button.svg" /> - <EmbeddedResource Include="Images\Icons\iconInfo.svg" /> + <EmbeddedResource Include="Images\Icons\iconInfo.svg"> + <LogicalName>Crow.Images.Icons.Informations.svg</LogicalName> + </EmbeddedResource> <EmbeddedResource Include="Templates\tmpDirItem.goml" /> <EmbeddedResource Include="Templates\ScrollingListBox.goml" /> <EmbeddedResource Include="Templates\imgItemTemplate.goml" /> diff --git a/Default.style b/Default.style index a09c363d..0db6a08a 100644 --- a/Default.style +++ b/Default.style @@ -40,9 +40,11 @@ MenuItem { MouseLeave = {Foreground=LightGray;Background=Transparent;} } MessageBox { - Width=200; + Background = 0.3,0.3,0.3,0.3; + Width = Fit; Title=MessageBox; - MinimumSize=150,80; + Font = serif, 12; + MinimumSize = 200,120; } Slider { Background = vgradient|0:Black|0.1:Gray|0.9:Gray|1:LightGray; diff --git a/Templates/MessageBox.template b/Templates/MessageBox.template index 8c58d61d..c33eb869 100644 --- a/Templates/MessageBox.template +++ b/Templates/MessageBox.template @@ -3,13 +3,13 @@ MouseEnter="./onBorderMouseEnter" MouseLeave="./onBorderMouseLeave"> <VerticalStack Background="{./Background}"> - <Border BorderWidth="0" Foreground="White" Height="Fit" + <Border BorderWidth="0" Foreground="White" Height="Fit" Width="Stretched" MinimumSize="200,0" Background="vgradient|0:0.4,0.6,0.0,0.5|1:0.0,0.8,0.8,0.9"> <HorizontalStack Name="hs" Margin="2" Spacing="1" Height="Fit" > <GraphicObject Width="5" Height="5"/> <Image Margin="1" Width="12" Height="12" Path="{./Icon}"/> <Label Width="Stretched" Foreground="White" Margin="1" TextAlignment="Center" Text="{./Caption}" /> - <Border CornerRadius="6" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" + <Border CornerRadius="3" BorderWidth="1" Foreground="Transparent" Height="12" Width="12" MouseEnter="{Foreground=White}" MouseLeave="{Foreground=Transparent}"> <Image Focusable="true" Name="Image" Path="#Crow.Images.Icons.exit2.svg" MouseClick="./butQuitPress"/> @@ -18,14 +18,14 @@ </HorizontalStack> </Border> <HorizontalStack Margin="5"> - <Image Name="Image" Width="20%" Height="20" Path="#Crow.Images.Icons.iconInfo.svg" /> - <Label Margin="5" Font="serif, 10" Width="80%" Text="{./Message}" + <Image Name="Image" Width="20%" Height="30" Path="{./MsgIcon}" /> + <Label Margin="5" Font="{./Font}" Width="Fit" Text="{./Message}" TextAlignment="Left" Multiline="true" /> </HorizontalStack> <HorizontalStack Margin="1" Spacing="0" Height="Fit" Width="60%" HorizontalAlignment="Right"> - <Button Width="50%" Caption="Ok" MouseClick="./onOkButtonClick" /> - <Button Width="50%" Caption="Cancel" MouseClick="./onCancelButtonClick" /> + <Button Width="50%" Caption="{./OkMessage}" MouseClick="./onOkButtonClick" /> + <Button Width="50%" Caption="{./CancelMessage}" MouseClick="./onCancelButtonClick" /> </HorizontalStack> </VerticalStack> </Border> diff --git a/src/GraphicObjects/MessageBox.cs b/src/GraphicObjects/MessageBox.cs index dbca769d..65bb66c3 100644 --- a/src/GraphicObjects/MessageBox.cs +++ b/src/GraphicObjects/MessageBox.cs @@ -25,9 +25,21 @@ namespace Crow { public class MessageBox : Window { - public MessageBox ():base(){} + public enum Type { + Information, + YesNo, + Alert, + Error + } + public MessageBox (): base(){} - string message; + protected override void loadTemplate (GraphicObject template) + { + base.loadTemplate (template); + NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg"); + } + string message, okMessage, cancelMessage; + Type msgType = Type.Information; public event EventHandler Ok; public event EventHandler Cancel; @@ -43,7 +55,65 @@ namespace Crow NotifyValueChanged ("Message", message); } } - + [XmlAttributeAttribute][DefaultValue("Ok")] + public virtual string OkMessage + { + get { return okMessage; } + set { + if (okMessage == value) + return; + okMessage = value; + NotifyValueChanged ("OkMessage", okMessage); + } + } + [XmlAttributeAttribute][DefaultValue("Cancel")] + public virtual string CancelMessage + { + get { return cancelMessage; } + set { + if (cancelMessage == value) + return; + cancelMessage = value; + NotifyValueChanged ("CancelMessage", cancelMessage); + } + } + [XmlAttributeAttribute][DefaultValue("Information")] + public virtual Type MsgType + { + get { return msgType; } + set { + if (msgType == value) + return; + msgType = value; + NotifyValueChanged ("MsgType", msgType); + switch (msgType) { + case Type.Information: + NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.Informations.svg"); + Caption = "Informations"; + OkMessage = "Ok"; + CancelMessage = "Cancel"; + break; + case Type.YesNo: + NotifyValueChanged ("MsgIcon", "#Crow.Icons.question.svg"); + Caption = "Choice"; + OkMessage = "Yes"; + CancelMessage = "No"; + break; + case Type.Alert: + NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.IconAlerte.svg"); + Caption = "Alert"; + OkMessage = "Ok"; + CancelMessage = "Cancel"; + break; + case Type.Error: + NotifyValueChanged ("MsgIcon", "#Crow.Images.Icons.exit.svg"); + Caption = "Error"; + OkMessage = "Ok"; + CancelMessage = "Cancel"; + break; + } + } + } void onOkButtonClick (object sender, EventArgs e) { Ok.Raise (this, null); @@ -52,7 +122,20 @@ namespace Crow { Cancel.Raise (this, null); } - + public static MessageBox Show (Type msgBoxType, string message, string okMsg = "", string cancelMsg = ""){ + lock (Interface.CurrentInterface.UpdateMutex) { + MessageBox mb = new MessageBox (); + mb.Initialize (); + mb.CurrentInterface.AddWidget (mb); + mb.MsgType = msgBoxType; + mb.Message = message; + if (!string.IsNullOrEmpty(okMsg)) + mb.OkMessage = okMsg; + if (!string.IsNullOrEmpty(cancelMsg)) + mb.CancelMessage = cancelMsg; + return mb; + } + } } } |