]> O.S.I.I.S - jp/crow.git/commitdiff
add error message in showcase
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 5 Nov 2017 22:01:15 +0000 (23:01 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 5 Nov 2017 22:01:15 +0000 (23:01 +0100)
1  2 
Tests/Showcase.cs
Tests/ui/showcase.crow

index 2639b0f70bce3716e7d419dd35c5cd7a7ae59275,0000000000000000000000000000000000000000..4880ede5b7f126c58619a2286320438122fe0fbd
mode 100644,000000..100644
--- /dev/null
@@@ -1,201 -1,0 +1,216 @@@
-                               GraphicObject g = this.CurrentInterface.Load (fi.FullName);
-                               crowContainer.SetChild (g);
-                               g.DataSource = this;
 +//
 +// UIEditor.cs
 +//
 +// Author:
 +//       Jean-Philippe Bruyère <jp.bruyere@hotmail.com>
 +//
 +// Copyright (c) 2013-2017 Jean-Philippe Bruyère
 +//
 +// Permission is hereby granted, free of charge, to any person obtaining a copy
 +// of this software and associated documentation files (the "Software"), to deal
 +// in the Software without restriction, including without limitation the rights
 +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 +// copies of the Software, and to permit persons to whom the Software is
 +// furnished to do so, subject to the following conditions:
 +//
 +// The above copyright notice and this permission notice shall be included in
 +// all copies or substantial portions of the Software.
 +//
 +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 +// THE SOFTWARE.
 +
 +using System;
 +using OpenTK;
 +using OpenTK.Graphics.OpenGL;
 +using Crow;
 +using System.IO;
 +using System.Collections.Generic;
 +using System.Reflection;
 +using System.Linq;
 +
 +namespace Tests
 +{
 +      class Showcase : CrowWindow
 +      {
 +              [STAThread]
 +              static void Main ()
 +              {
 +                      Showcase win = new Showcase ();
 +                      win.Run (30);
 +              }
 +
 +              public Showcase ()
 +                      : base(1024, 800,"Showcase")
 +              {
 +              }
 +
 +              Container crowContainer;
 +
 +              protected override void OnLoad (EventArgs e)
 +              {
 +                      base.OnLoad (e);
 +
 +                      GraphicObject g = Load ("#Tests.ui.showcase.crow");
 +                      g.DataSource = this;
 +                      crowContainer = g.FindByName ("CrowContainer") as Container;
 +                      //I set an empty object as datasource at this level to force update when new
 +                      //widgets are added to the interface
 +                      crowContainer.DataSource = new object ();
++                      hideError ();
 +              }
 +
 +              void Dv_SelectedItemChanged (object sender, SelectionChangeEventArgs e)
 +              {
 +                      FileSystemInfo fi = e.NewValue as FileSystemInfo;
 +                      if (fi == null)
 +                              return;
 +                      if (fi is DirectoryInfo)
 +                              return;
++                      hideError();
 +                      lock (this.CurrentInterface.UpdateMutex) {
-                               }                               
++                              try {
++                                      GraphicObject g = this.CurrentInterface.Load (fi.FullName);
++                                      crowContainer.SetChild (g);
++                                      g.DataSource = this;
++                              } catch (Exception ex) {
++                                      showError (ex);
++                              }
 +                      }
 +
 +                      string source = "";
 +                      using (Stream s = new FileStream (fi.FullName, FileMode.Open)) {
 +                              using (StreamReader sr = new StreamReader (s)) {
 +                                      source = sr.ReadToEnd ();
 +                              }
 +                      }
 +                      NotifyValueChanged ("source", source);
 +              }
 +
++              void showError(Exception ex) {
++                      NotifyValueChanged ("ErrorMessage", ex.Message + ex.InnerException);
++                      NotifyValueChanged ("ShowError", true);
++              }
++              void hideError () {
++                      NotifyValueChanged ("ShowError", false);
++              }
++
 +              void Tb_TextChanged (object sender, TextChangeEventArgs e)
 +              {
++                      hideError();
 +                      GraphicObject g = null;
 +                      try {
 +                              lock (this.ifaceControl [0].CrowInterface.UpdateMutex) {
 +                                      Instantiator inst = null;
 +                                      using (MemoryStream ms = new MemoryStream (System.Text.Encoding.Unicode.GetBytes (e.Text))){
 +                                              inst = new Instantiator (ms);
 +                                      }
 +                                      g = inst.CreateInstance (this.ifaceControl [0].CrowInterface);
 +                                      crowContainer.SetChild (g);
-                       g.DataSource = this;
++                                      g.DataSource = this;
++                              }
 +                      } catch (Exception ex) {
 +                              System.Diagnostics.Debug.WriteLine (ex.ToString ());
++                              showError (ex);
 +                      }
-               {                       
 +              }
 +              public override void OnRender (FrameEventArgs e)
++              {
 +                      base.OnRender (e);
 +              }
 +
 +              #region Test values for Binding
 +              public int intValue = 500;
 +              DirectoryInfo curDir = new DirectoryInfo (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
 +              //DirectoryInfo curDir = new DirectoryInfo (@"/mnt/data/Images");
 +              public FileSystemInfo[] CurDirectory {
 +                      get { return curDir.GetFileSystemInfos (); }
 +              }
 +              public int IntValue {
 +                      get {
 +                              return intValue;
 +                      }
 +                      set {
 +                              intValue = value;
 +                              NotifyValueChanged ("IntValue", intValue);
 +                      }
 +              }
 +              void onSpinnerValueChange(object sender, ValueChangeEventArgs e){
 +                      if (e.MemberName != "Value")
 +                              return;
 +                      intValue = Convert.ToInt32(e.NewValue);
 +              }
 +              void change_alignment(object sender, EventArgs e){
 +                      RadioButton rb = sender as RadioButton;
 +                      if (rb == null)
 +                              return;
 +                      NotifyValueChanged ("alignment", Enum.Parse(typeof(Alignment), rb.Caption));
 +              }
 +              public IList<String> List2 = new List<string>(new string[]
 +                      {
 +                              "string1",
 +                              "string2",
 +                              "string3",
 +                              //                              "string4",
 +                              //                              "string5",
 +                              //                              "string6",
 +                              //                              "string7",
 +                              //                              "string8",
 +                              //                              "string8",
 +                              //                              "string8",
 +                              //                              "string8",
 +                              //                              "string8",
 +                              //                              "string8",
 +                              //                              "string9"
 +                      }
 +              );
 +              public IList<String> TestList2 {
 +                      set{
 +                              List2 = value;
 +                              NotifyValueChanged ("TestList2", testList);
 +                      }
 +                      get { return List2; }
 +              }
 +              IList<Color> testList = Color.ColorDic.Values.ToList();
 +              public IList<Color> TestList {
 +                      set{
 +                              testList = value;
 +                              NotifyValueChanged ("TestList", testList);
 +                      }
 +                      get { return testList; }
 +              }
 +              string curSources = "";
 +              public string CurSources {
 +                      get { return curSources; }
 +                      set {
 +                              if (value == curSources)
 +                                      return;
 +                              curSources = value;
 +                              NotifyValueChanged ("CurSources", curSources);
 +                      }
 +              }
 +              bool boolVal = true;
 +              public bool BoolVal {
 +                      get { return boolVal; }
 +                      set {
 +                              if (boolVal == value)
 +                                      return;
 +                              boolVal = value;
 +                              NotifyValueChanged ("BoolVal", boolVal);
 +                      }
 +              }
 +
 +              #endregion
 +
 +              void OnClear (object sender, MouseButtonEventArgs e) => TestList = null;
 +
 +              void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = Color.ColorDic.Values.ToList();
 +
 +      }
 +
 +
 +}
index 4453e6aac60bfefe43fdb113a1df5e86303a7ac1,0000000000000000000000000000000000000000..a511a100ca8f4b03f9d2b9f905a17283dbb47029
mode 100755,000000..100755
--- /dev/null
@@@ -1,22 -1,0 +1,24 @@@
 +<?xml version="1.0"?>
 +<HorizontalStack Background="Onyx" Margin="5">
 +      <DirectoryView Name="dv" CurrentDirectory="Interfaces" Width="25%" SelectedItemChanged="Dv_SelectedItemChanged"
 +              />
 +      <Splitter Width="6"/>
 +      <VerticalStack>
 +              <Container Name="CrowContainer" Height="60%" Background="SmokyBlack"/>
 +              <Splitter/>
 +              <HorizontalStack>
 +                      <Scroller Name="scroller1" Background="White"
 +                                      Margin="2" VerticalScrolling="true" ScrollY="{../scrollbar1.Value}"
 +                                      ValueChanged="./_scroller_ValueChanged">
 +                              <TextBox VerticalAlignment="Top" TextChanged="Tb_TextChanged"
 +                                      Text="{source}" Multiline="true" TextAlignment="TopLeft"
 +                                      Font="Courriernew 10"/>
 +                      </Scroller>
 +                      <ScrollBar Name="scrollbar1" Value="{../scroller1.ScrollY}"
 +                              Maximum="{../scroller1.MaximumScroll}" Orientation="Vertical"
 +                              Width="14" />
 +              </HorizontalStack>
++              <Label Visible="{ShowError}" Text="{ErrorMessage}" Background="Red" Foreground="White" Width="Stretched" Margin="2"
++                      Multiline="true"/>
 +      </VerticalStack>
 +</HorizontalStack>