From: Jean-Philippe Bruyère Date: Mon, 29 Mar 2021 10:18:38 +0000 (+0200) Subject: enumSelector for bitfields, CommandBase abstract class, numericControl onUp/down... X-Git-Tag: v0.9.5-beta~38 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=e5df4ae295d164042a91fb7f75cec4323d88833f;p=jp%2Fcrow.git enumSelector for bitfields, CommandBase abstract class, numericControl onUp/down handler, dock window reload bug --- diff --git a/Crow/Default.style b/Crow/Default.style index 0e442eb6..9833be47 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -1,11 +1,12 @@ ControlBackground = "Transparent"; +ControlForeground = "Grey"; +ControlHighlight = "RoyalBlue"; ControlBorderColor = "DimGrey"; ControlBorderWidth = "1"; -ControlCaptionColor = "LightGrey"; ControlCaptionHoverColor = "White"; ControlCornerRadius = "0"; ControlInsideMargin = "1"; -ControlHighlight = "RoyalBlue"; + IconSize = "11"; IconMargin = "1"; ToggleIconSize = "16"; @@ -47,12 +48,12 @@ ControlBorder { Margin = "${ControlInsideMargin}"; } ControlCaption { - Foreground = "${ControlCaptionColor}"; + Foreground = "${ControlForeground}"; MouseEnter = "{Foreground=${ControlCaptionHoverColor}}"; - MouseLeave = "{Foreground=${ControlCaptionColor}}"; + MouseLeave = "{Foreground=${ControlForeground}}"; } ControlEditableText { - Foreground = "${ControlCaptionColor}"; + Foreground = "${ControlForeground}"; Background = "Transparent"; MinimumSize = "40,10"; Margin = "1"; @@ -104,7 +105,7 @@ MenuItem { Width = "Stretched"; Height = "Fit"; Background = "${MenuBackground}"; - Foreground = "${ControlCaptionColor}"; + Foreground = "${ControlForeground}"; MouseEnter = "{Background=${ControlHighlight}}"; MouseLeave = "{Background=${MenuBackground}}"; //SelectionBackground = "${ControlHighlight}"; @@ -238,16 +239,12 @@ CheckBoxAlt { } ArrowBut { - MouseRepeat="true"; - //Focusable="true"; + MouseRepeat="true"; Foreground="Grey"; Background="Transparent"; - - //MouseUp="{Background=Transparent}"; - //MouseDown="{Background=Grey}"; - - MouseEnter="{Foreground=CornflowerBlue}"; + + MouseEnter="{Foreground=${ControlHighlight}}"; MouseLeave="{Foreground=Grey}"; Margin="2"; diff --git a/Crow/Templates/NumericControl.template b/Crow/Templates/NumericControl.template new file mode 100644 index 00000000..b3d87f88 --- /dev/null +++ b/Crow/Templates/NumericControl.template @@ -0,0 +1,11 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Crow/Templates/TabView.template b/Crow/Templates/TabView.template index af4eae07..cfe1a701 100644 --- a/Crow/Templates/TabView.template +++ b/Crow/Templates/TabView.template @@ -1,6 +1,6 @@  - + @@ -12,6 +12,6 @@ - + diff --git a/Crow/src/Command.cs b/Crow/src/Command.cs index 6c225030..34d48c4f 100644 --- a/Crow/src/Command.cs +++ b/Crow/src/Command.cs @@ -1,23 +1,40 @@ -// Copyright (c) 2013-2020 Jean-Philippe Bruyère +using System.Runtime.InteropServices.ComTypes; +// Copyright (c) 2013-2020 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; using System.ComponentModel; using System.Threading.Tasks; +using System.Collections; namespace Crow { - public class CommandGroup : ObservableList, IValueChange - { - string caption; - string icon; + public abstract class CommandBase : IValueChange { + #region IValueChange implementation + public event EventHandler ValueChanged; + public virtual void NotifyValueChanged(string MemberName, object _value) + { + ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); + } + #endregion + + #region CTOR + protected CommandBase() {} + protected CommandBase (string _caption, string _icon) + { + caption = _caption; + icon = _icon; + } + #endregion + + string caption, icon; /// /// label to display in the bound control /// - [DefaultValue ("Unamed Command Group")] + [DefaultValue("Unamed Command")] public virtual string Caption { - get { return caption; } + get => caption; set { if (caption == value) return; @@ -30,7 +47,7 @@ namespace Crow { /// Icon to display in the bound control /// public string Icon { - get { return icon; } + get => icon; set { if (icon == value) return; @@ -38,26 +55,33 @@ namespace Crow { NotifyValueChanged ("Icon", icon); } } + internal virtual void raiseAllValuesChanged() { + NotifyValueChanged ("Icon", icon); + NotifyValueChanged ("Caption", caption); + } + } + public class CommandGroup : CommandBase, IEnumerable + { + public ObservableList Commands = new ObservableList(); public CommandGroup () { } - public CommandGroup (params Command[] commands) { - AddRange (commands); + public CommandGroup (string caption, string icon, params CommandBase[] commands) : + base (caption, icon) { + Commands.AddRange (commands); } + public CommandGroup (params CommandBase[] commands) { + Commands.AddRange (commands); + } + + public IEnumerator GetEnumerator() => Commands.GetEnumerator (); } /// /// helper class to bind in one step icon, caption, action, and validity tests to a controls /// - public class Command : IValueChange + public class Command : CommandBase { - #region IValueChange implementation - public event EventHandler ValueChanged; - public virtual void NotifyValueChanged(string MemberName, object _value) - { - ValueChanged.Raise(this, new ValueChangeEventArgs(MemberName, _value)); - } - #endregion #region CTOR public Command () {} @@ -69,15 +93,18 @@ namespace Crow { { execute = _executeAction; } + public Command (string caption, Action executeAction, string icon = null, bool _canExecute = true) + :base (caption, icon) + { + execute = executeAction; + canExecute = _canExecute; + } + #endregion - Action execute; - - string caption; - string icon; + Action execute; bool canExecute = true; - - #region Public properties + /// /// if true, action defined in this command may be executed, /// @@ -90,50 +117,21 @@ namespace Crow { canExecute = value; NotifyValueChanged ("CanExecute", canExecute); } - } - - /// - /// label to display in the bound control - /// - [DefaultValue("Unamed Command")] - public virtual string Caption { - get { return caption; } - set { - if (caption == value) - return; - caption = value; - NotifyValueChanged ("Caption", caption); - - } - } - /// - /// Icon to display in the bound control - /// - public string Icon { - get { return icon; } - set { - if (icon == value) - return; - icon = value; - NotifyValueChanged ("Icon", icon); - } - } - #endregion + } /// /// trigger the execution of the command /// - public void Execute(){ + public virtual void Execute(){ if (execute != null && CanExecute){ Task task = new Task(execute); task.Start(); } } - internal void raiseAllValuesChanged(){ + internal override void raiseAllValuesChanged() + { + base.raiseAllValuesChanged(); NotifyValueChanged ("CanExecute", CanExecute); - NotifyValueChanged ("Icon", icon); - NotifyValueChanged ("Caption", caption); } - } } diff --git a/Crow/src/Widgets/Button.cs b/Crow/src/Widgets/Button.cs index b7b9326b..35dcee00 100644 --- a/Crow/src/Widgets/Button.cs +++ b/Crow/src/Widgets/Button.cs @@ -41,7 +41,7 @@ namespace Crow [DefaultValue (null)] public virtual Command Command { - get { return command; } + get => command; set { if (command == value) return; @@ -64,7 +64,7 @@ namespace Crow [DefaultValue ("#Crow.Icons.crow.svg")] public string Icon { - get { return Command == null ? icon : Command.Icon; ; } + get => Command == null ? icon : Command.Icon; set { if (icon == value) return; @@ -74,19 +74,19 @@ namespace Crow } } public override bool IsEnabled { - get { return Command == null ? base.IsEnabled : Command.CanExecute; } - set { base.IsEnabled = value; } + get => Command == null ? base.IsEnabled : Command.CanExecute; + set => base.IsEnabled = value; } public override string Caption { - get { return Command == null ? base.Caption : Command.Caption; } - set { base.Caption = value; } + get => Command == null ? base.Caption : Command.Caption; + set => base.Caption = value; } [DefaultValue (false)] public bool IsPressed { - get { return isPressed; } + get => isPressed; set { if (isPressed == value) diff --git a/Crow/src/Widgets/CheckBox.cs b/Crow/src/Widgets/CheckBox.cs index cd0297f7..ccd1ee75 100644 --- a/Crow/src/Widgets/CheckBox.cs +++ b/Crow/src/Widgets/CheckBox.cs @@ -26,7 +26,7 @@ namespace Crow [DefaultValue(false)] public bool IsChecked { - get { return isChecked; } + get => isChecked; set { if (isChecked == value) diff --git a/Crow/src/Widgets/DockStack.cs b/Crow/src/Widgets/DockStack.cs index 5645e374..b5c05ece 100644 --- a/Crow/src/Widgets/DockStack.cs +++ b/Crow/src/Widgets/DockStack.cs @@ -397,6 +397,7 @@ namespace Crow dw.DockingPosition = FastEnum.Parse (getConfAttrib (conf, ref i)); dw.savedSlot = Rectangle.Parse (getConfAttrib (conf, ref i)); dw.wasResizable = Boolean.Parse (getConfAttrib (conf, ref i)); + dw.Resizable = false; dw.IsDocked = true; dw.DataSource = dataSource; diff --git a/Crow/src/Widgets/DockWindow.cs b/Crow/src/Widgets/DockWindow.cs index 72a22a75..200f2f12 100644 --- a/Crow/src/Widgets/DockWindow.cs +++ b/Crow/src/Widgets/DockWindow.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2013-2020 Jean-Philippe Bruyère +// Copyright (c) 2013-2021 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) diff --git a/Crow/src/Widgets/EnumSelector.cs b/Crow/src/Widgets/EnumSelector.cs index 7e0fd476..c30c79a4 100644 --- a/Crow/src/Widgets/EnumSelector.cs +++ b/Crow/src/Widgets/EnumSelector.cs @@ -1,4 +1,6 @@ -// Copyright (c) 2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com +using System.Linq; +using System.Xml.Linq; +// Copyright (c) 2019 Bruyère Jean-Philippe jp_bruyere@hotmail.com // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) @@ -36,8 +38,8 @@ namespace Crow #region private fields Enum enumValue; Type enumType; - string rbStyle, iconsPrefix, iconsExtension; - IML.Instantiator radioButtonITor; + bool enumTypeIsBitsfield; + string rbStyle, iconsPrefix, iconsExtension; #endregion #region public properties @@ -73,8 +75,7 @@ namespace Crow set { if (rbStyle == value) return; - rbStyle = value; - radioButtonITor = null; + rbStyle = value; forceRefresh (); NotifyValueChangedAuto (rbStyle); } @@ -84,36 +85,91 @@ namespace Crow /// [DefaultValue(null)] public virtual Enum EnumValue { - get { return enumValue; } + get => enumValue; set { if (enumValue == value) return; - enumValue = value; - if (radioButtonITor == null) - radioButtonITor = IFace.CreateITorFromIMLFragment ($""); + enumValue = value; if (enumValue != null) { + if (enumType != enumValue.GetType ()) { enumValueContainer.ClearChildren (); - enumType = enumValue.GetType (); - foreach (string en in enumType.GetEnumNames ()) { - - RadioButton rb = radioButtonITor.CreateInstance (); - rb.Caption = en; - rb.LogicalParent = this; - rb.Tag = $"{iconsPrefix}{en}{IconsExtension}"; - if (enumValue.ToString () == en) - rb.IsChecked = true; - rb.Checked += (sender, e) => (((RadioButton)sender).LogicalParent as EnumSelector).EnumValue = (Enum)Enum.Parse (enumType, (sender as RadioButton).Caption); - enumValueContainer.AddChild (rb); + enumType = enumValue.GetType (); + + enumTypeIsBitsfield = enumType.CustomAttributes.Any (ca => ca.AttributeType == typeof(FlagsAttribute)); + + if (enumTypeIsBitsfield) { + IML.Instantiator iTor = IFace.CreateITorFromIMLFragment ($""); + UInt32 currentValue = Convert.ToUInt32 (EnumValue); + + foreach (Enum en in enumType.GetEnumValues()) { + CheckBox rb = iTor.CreateInstance (); + rb.Caption = en.ToString(); + rb.LogicalParent = this; + rb.Tag = $"{iconsPrefix}{en}{IconsExtension}"; + + UInt32 eni = Convert.ToUInt32 (en); + rb.Tooltip = $"0x{eni:x8}"; + if (eni == 0) { + rb.IsChecked = currentValue == 0; + rb.Checked += (sender, e) => EnumValue = (Enum)Enum.ToObject(enumType, 0); + } else { + rb.IsChecked = currentValue == 0 ? false : EnumValue.HasFlag (en); + rb.Checked += onChecked; + rb.Unchecked += onUnchecked; + } + /*rb.Checked += (sender, e) => (((CheckBox)sender).LogicalParent as EnumSelector).EnumValue = (Enum)(object) + (Convert.ToUInt32 ((((CheckBox)sender).LogicalParent as EnumSelector).EnumValue) | Convert.ToUInt32 (en)); + rb.Unchecked += (sender, e) => (((CheckBox)sender).LogicalParent as EnumSelector).EnumValue = (Enum)(object) + (Convert.ToUInt32 ((((CheckBox)sender).LogicalParent as EnumSelector).EnumValue) & ~Convert.ToUInt32 (en)); */ + + enumValueContainer.AddChild (rb); + } + + } else { + IML.Instantiator iTor = IFace.CreateITorFromIMLFragment ($""); + foreach (var en in enumType.GetEnumValues ()) { + RadioButton rb = iTor.CreateInstance (); + rb.Caption = en.ToString(); + rb.LogicalParent = this; + rb.Tag = $"{iconsPrefix}{en}{IconsExtension}"; + if (enumValue == en) + rb.IsChecked = true; + rb.Checked += (sender, e) => (((RadioButton)sender).LogicalParent as EnumSelector).EnumValue = (Enum)en; + enumValueContainer.AddChild (rb); + } } + + + } else if (enumTypeIsBitsfield) { + UInt32 currentValue = Convert.ToUInt32 (EnumValue); + if (currentValue == 0) { + foreach (CheckBox rb in enumValueContainer.Children) { + Enum en = (Enum)Enum.Parse(enumType, rb.Caption); + UInt32 eni = Convert.ToUInt32 (en); + if (eni == 0) + rb.IsChecked = true; + else + rb.IsChecked = false; + } + } else { + foreach (CheckBox rb in enumValueContainer.Children) { + Enum en = (Enum)Enum.Parse(enumType, rb.Caption); + UInt32 eni = Convert.ToUInt32 (en); + if (eni == 0) + rb.IsChecked = false; + else + rb.IsChecked = EnumValue.HasFlag (en); + } + } } else { foreach (RadioButton rb in enumValueContainer.Children) { if (rb.Caption == enumValue.ToString ()) rb.IsChecked = true; - else if (rb.IsChecked) + else rb.IsChecked = false; } } @@ -126,6 +182,19 @@ namespace Crow } #endregion + void onChecked (object sender, EventArgs e) { + Enum en =(Enum)Enum.Parse (enumType, (sender as CheckBox).Caption); + UInt32 newVal = Convert.ToUInt32 (en); + if (newVal == 0) + EnumValue = (Enum)Enum.ToObject(enumType, 0); + else + EnumValue = (Enum)Enum.ToObject(enumType, newVal | Convert.ToUInt32 (EnumValue)); + } + void onUnchecked (object sender, EventArgs e) { + Enum en =(Enum)Enum.Parse (enumType, (sender as CheckBox).Caption); + EnumValue = (Enum)Enum.ToObject(enumType, Convert.ToUInt32 (EnumValue) & ~Convert.ToUInt32 (en)); + } + //force refresh to use new template if values are already displayed void forceRefresh () { diff --git a/Crow/src/Widgets/Expandable.cs b/Crow/src/Widgets/Expandable.cs index 4cb0a2b4..e656d771 100644 --- a/Crow/src/Widgets/Expandable.cs +++ b/Crow/src/Widgets/Expandable.cs @@ -93,14 +93,14 @@ namespace Crow public virtual void onExpand(object sender, EventArgs e) { if (_contentContainer != null) - _contentContainer.Visible = true; + _contentContainer.IsVisible = true; Expand.Raise (this, e); } public virtual void onCollapse(object sender, EventArgs e) { if (_contentContainer != null) - _contentContainer.Visible = false; + _contentContainer.IsVisible = false; Collapse.Raise (this, e); } diff --git a/Crow/src/Widgets/GenericStack.cs b/Crow/src/Widgets/GenericStack.cs index 44b87133..b2fbe650 100644 --- a/Crow/src/Widgets/GenericStack.cs +++ b/Crow/src/Widgets/GenericStack.cs @@ -56,7 +56,7 @@ namespace Crow { layoutType &= (~LayoutingType.Y); } public override int measureRawSize (LayoutingType lt) { - int totSpace = Math.Max (0, Spacing * (Children.Count (c => c.Visible) - 1)); + int totSpace = Math.Max (0, Spacing * (Children.Count (c => c.IsVisible) - 1)); if (lt == LayoutingType.Width) { if (Orientation == Orientation.Horizontal) return contentSize.Width + totSpace + 2 * Margin; @@ -69,14 +69,14 @@ namespace Crow { int d = 0; if (Orientation == Orientation.Horizontal) { foreach (Widget c in Children) { - if (!c.Visible) + if (!c.IsVisible) continue; c.Slot.X = d; d += c.Slot.Width + Spacing; } } else { foreach (Widget c in Children) { - if (!c.Visible) + if (!c.IsVisible) continue; c.Slot.Y = d; d += c.Slot.Height + Spacing; diff --git a/Crow/src/Widgets/MenuItem.cs b/Crow/src/Widgets/MenuItem.cs index 62a00cb6..b9b9d1f3 100644 --- a/Crow/src/Widgets/MenuItem.cs +++ b/Crow/src/Widgets/MenuItem.cs @@ -64,17 +64,17 @@ namespace Crow } public override bool IsEnabled { - get { return Command == null ? base.IsEnabled : Command.CanExecute; } - set { base.IsEnabled = value; } + get => Command == null ? base.IsEnabled : Command.CanExecute; + set => base.IsEnabled = value; } public override string Caption { - get { return Command == null ? base.Caption : Command.Caption; } - set { base.Caption = value; } + get => Command == null ? base.Caption : Command.Caption; + set => base.Caption = value; } public string Icon { - get { return Command == null ? icon : Command.Icon;; } + get => Command == null ? icon : Command.Icon; set { if (icon == value) return; @@ -85,7 +85,7 @@ namespace Crow } [DefaultValue("Fit")] public virtual Measure PopWidth { - get { return popWidth; } + get => popWidth; set { if (popWidth == value) return; @@ -95,7 +95,7 @@ namespace Crow } [DefaultValue("Fit")] public virtual Measure PopHeight { - get { return popHeight; } + get => popHeight; set { if (popHeight == value) return; @@ -121,8 +121,7 @@ namespace Crow protected virtual void onOpen (object sender, EventArgs e){ Open.Raise (this, null); } - protected virtual void onClose (object sender, EventArgs e){ - System.Diagnostics.Debug.WriteLine ("close: " + this.ToString()); + protected virtual void onClose (object sender, EventArgs e){ Close.Raise (this, null); } public override bool MouseIsIn (Point m) diff --git a/Crow/src/Widgets/NumericControl.cs b/Crow/src/Widgets/NumericControl.cs index 80c68587..df8fa17d 100644 --- a/Crow/src/Widgets/NumericControl.cs +++ b/Crow/src/Widgets/NumericControl.cs @@ -23,7 +23,7 @@ namespace Crow { [DefaultValue(2)] public int Decimals { - get { return decimals; } + get => decimals; set { if (value == decimals) @@ -35,7 +35,7 @@ namespace Crow { } [DefaultValue(0.0)] public virtual double Minimum { - get { return minValue; } + get => minValue; set { if (minValue == value) return; @@ -48,7 +48,7 @@ namespace Crow { [DefaultValue(100.0)] public virtual double Maximum { - get { return maxValue; } + get => maxValue; set { if (maxValue == value) return; @@ -61,7 +61,7 @@ namespace Crow { [DefaultValue(1.0)] public virtual double SmallIncrement { - get { return smallStep; } + get => smallStep; set { if (smallStep == value) return; @@ -74,7 +74,7 @@ namespace Crow { [DefaultValue(5.0)] public virtual double LargeIncrement { - get { return bigStep; } + get => bigStep; set { if (bigStep == value) return; @@ -87,7 +87,7 @@ namespace Crow { [DefaultValue(0.0)] public virtual double Value { - get { return actualValue; } + get => actualValue; set { if (value == actualValue) @@ -110,6 +110,21 @@ namespace Crow { protected virtual void registerUpdate () => RegisterForRedraw (); + + protected virtual void onUp (object sender, MouseButtonEventArgs e) + { + if (IFace.Ctrl) + Value += SmallIncrement; + else + Value += LargeIncrement; + } + protected virtual void onDown (object sender, MouseButtonEventArgs e) + { + if (IFace.Ctrl) + Value -= SmallIncrement; + else + Value -= LargeIncrement; + } } } diff --git a/Crow/src/Widgets/Slider.cs b/Crow/src/Widgets/Slider.cs index 0d825526..b99fadfd 100644 --- a/Crow/src/Widgets/Slider.cs +++ b/Crow/src/Widgets/Slider.cs @@ -31,7 +31,7 @@ namespace Crow } protected virtual void HandleCursorContainerLayoutChanged (object sender, LayoutingEventArgs e) - { + { computeCursorPosition (); } #endregion @@ -119,13 +119,13 @@ namespace Crow } void computeCursorPosition () { - if (cursor == null) + if (cursor?.Parent == null) return; if (Maximum <= Minimum) { - cursor.Visible = false; + cursor.IsVisible = false; return; } - cursor.Visible = true; + cursor.IsVisible = true; Rectangle r = cursor.Parent.ClientRectangle; if (_orientation == Orientation.Horizontal) { unity = (r.Width - cursorSize) / (Maximum - Minimum); diff --git a/Crow/src/Widgets/Spinner.cs b/Crow/src/Widgets/Spinner.cs index 8126f8d5..fdff9ac8 100644 --- a/Crow/src/Widgets/Spinner.cs +++ b/Crow/src/Widgets/Spinner.cs @@ -14,27 +14,6 @@ namespace Crow protected Spinner() {} public Spinner (Interface iface, string style = null) : base (iface, style) { } #endregion - - public override void onMouseClick (object sender, MouseButtonEventArgs e) - { - e.Handled = true; - base.onMouseClick (sender, e); - } - void onUp (object sender, MouseButtonEventArgs e) - { - if (IFace.Ctrl) - Value += SmallIncrement; - else - Value += LargeIncrement; - } - void onDown (object sender, MouseButtonEventArgs e) - { - if (IFace.Ctrl) - Value -= SmallIncrement; - else - Value -= LargeIncrement; - } - } } diff --git a/Crow/src/Widgets/TemplatedGroup.cs b/Crow/src/Widgets/TemplatedGroup.cs index cfa6cd1c..37d560f3 100644 --- a/Crow/src/Widgets/TemplatedGroup.cs +++ b/Crow/src/Widgets/TemplatedGroup.cs @@ -483,6 +483,8 @@ namespace Crow { //void expandable_expandevent (object sender, EventHandler ) void Li_Selected (object sender, EventArgs e) { + if (sender == selectedItemContainer) + return; if (selectedItemContainer is ISelectable li) li.IsSelected = false; selectedItemContainer = sender as Widget; diff --git a/Samples/BasicTests/BasicTests.cs b/Samples/BasicTests/BasicTests.cs index dcf38db4..656c05a3 100644 --- a/Samples/BasicTests/BasicTests.cs +++ b/Samples/BasicTests/BasicTests.cs @@ -19,10 +19,10 @@ namespace tests protected override void OnInitialized () { Commands = new List (new Crow.Command [] { - new Crow.Command(new Action(() => command1())) { Caption = "command1"}, - new Crow.Command(new Action(() => command2())) { Caption = "command2"}, - new Crow.Command(new Action(() => command3())) { Caption = "command3"}, - new Crow.Command(new Action(() => command4())) { Caption = "command4"}, + new Crow.Command("command1", new Action(() => Console.WriteLine ("command1 triggered"))), + new Crow.Command("command2", new Action(() => Console.WriteLine ("command2 triggered"))), + new Crow.Command("command3", new Action(() => Console.WriteLine ("command3 triggered"))), + new Crow.Command("command4", new Action(() => Console.WriteLine ("command4 triggered"))), }); // += KeyboardKeyDown1; @@ -103,21 +103,5 @@ namespace tests void OnLoadList (object sender, MouseButtonEventArgs e) => TestList = null; //Color.ColorDic.Values.OrderBy (c => c.Hue).ToList (); - void command1 () - { - Console.WriteLine ("command1 triggered"); - } - void command2 () - { - Console.WriteLine ("command2 triggered"); - } - void command3 () - { - Console.WriteLine ("command3 triggered"); - } - void command4 () - { - Console.WriteLine ("command4 triggered"); - } } } diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs index 0628695f..699e84ff 100644 --- a/Samples/ShowCase/ShowCase.cs +++ b/Samples/ShowCase/ShowCase.cs @@ -20,8 +20,9 @@ namespace ShowCase { static void Main () { - DbgLogger.IncludeEvents = DbgEvtType.Widget; - DbgLogger.DiscardEvents = DbgEvtType.Focus | DbgEvtType.IFace; + DbgLogger.IncludeEvents = DbgEvtType.None; + DbgLogger.DiscardEvents = DbgEvtType.Focus | DbgEvtType.IFace; + DbgLogger.ConsoleOutput = false; Environment.SetEnvironmentVariable ("FONTCONFIG_PATH", @"C:\Users\Jean-Philippe\source\vcpkg\installed\x64-windows\tools\fontconfig\fonts"); @@ -31,6 +32,7 @@ namespace ShowCase } } + public Container crowContainer; public string CurrentDir { @@ -127,15 +129,15 @@ namespace ShowCase void initCommands () { - CMDNew = new Command (new Action (onNewFile)) { Caption = "New", Icon = "#Icons.blank-file.svg", CanExecute = true }; - CMDSave = new Command (new Action (onSave)) { Caption = "Save", Icon = "#Icons.save.svg", CanExecute = false }; - CMDSaveAs = new Command (new Action (onSaveAs)) { Caption = "Save As...", Icon = "#Icons.save.svg", CanExecute = true }; - CMDQuit = new Command (new Action (() => base.Quit ())) { Caption = "Quit", Icon = "#Icons.exit.svg", CanExecute = true }; - CMDUndo = new Command (new Action (undo)) { Caption = "Undo", Icon = "#Icons.undo.svg", CanExecute = false }; - CMDRedo = new Command (new Action (redo)) { Caption = "Redo", Icon = "#Icons.redo.svg", CanExecute = false }; - CMDCut = new Command (new Action (() => cut ())) { Caption = "Cut", Icon = "#Icons.scissors.svg", CanExecute = false }; - CMDCopy = new Command (new Action (() => copy ())) { Caption = "Copy", Icon = "#Icons.copy-file.svg", CanExecute = false }; - CMDPaste = new Command (new Action (() => paste ())) { Caption = "Paste", Icon = "#Icons.paste-on-document.svg", CanExecute = false }; + CMDNew = new Command ("New", new Action (onNewFile), "#Icons.blank-file.svg"); + CMDSave = new Command ("Save", new Action (onSave), "#Icons.save.svg", false); + CMDSaveAs = new Command ("Save As...", new Action (onSaveAs), "#Icons.save.svg"); + CMDQuit = new Command ("Quit", new Action (() => base.Quit ()), "#Icons.exit.svg"); + CMDUndo = new Command ("Undo", new Action (undo),"#Icons.undo.svg", false); + CMDRedo = new Command ("Redo", new Action (redo),"#Icons.redo.svg", false); + CMDCut = new Command ("Cut", new Action (() => cut ()), "#Icons.scissors.svg", false); + CMDCopy = new Command ("Copy", new Action (() => copy ()), "#Icons.copy-file.svg", false); + CMDPaste= new Command ("Paste", new Action (() => paste ()), "#Icons.paste-on-document.svg", false); } void onNewFile () { @@ -345,5 +347,48 @@ namespace ShowCase reloadChrono.Reset (); } + DbgEvtType recordedEvents, discardedEvents; + public DbgEvtType RecordedEvents { + get => recordedEvents; + set { + if (recordedEvents == value) + return; + recordedEvents = value; + NotifyValueChanged(recordedEvents); + } + } + public DbgEvtType DiscardedEvents { + get => discardedEvents; + set { + if (discardedEvents == value) + return; + discardedEvents = value; + NotifyValueChanged(discardedEvents); + } + } + + public override bool OnKeyDown (Key key) { + + switch (key) { + case Key.F5: + Load ("#ShowCase.DebugLog.crow").DataSource = this; + return true; + case Key.F6: + if (DbgLogger.IncludeEvents == recordedEvents) { + DbgLogger.IncludeEvents = DbgEvtType.None; + DbgLogger.DiscardEvents = DbgEvtType.All; + } else { + DbgLogger.IncludeEvents = recordedEvents; + DbgLogger.DiscardEvents = discardedEvents; + } + return true; + case Key.F2: + if (IsKeyDown (Key.LeftShift)) + DbgLogger.Reset (); + DbgLogger.Save (this); + return true; + } + return base.OnKeyDown (key); + } } } \ No newline at end of file diff --git a/Samples/ShowCase/ui/DebugLog.crow b/Samples/ShowCase/ui/DebugLog.crow new file mode 100644 index 00000000..db9528b1 --- /dev/null +++ b/Samples/ShowCase/ui/DebugLog.crow @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/Samples/ShowCase/ui/ShowCase.style b/Samples/ShowCase/ui/ShowCase.style index 0d688507..ce7572ab 100644 --- a/Samples/ShowCase/ui/ShowCase.style +++ b/Samples/ShowCase/ui/ShowCase.style @@ -1,4 +1,7 @@ IcoButton { Template = "#ShowCase.Button.template"; Background = "Onyx"; +} +CheckBox2 { + Width = "200"; } \ No newline at end of file diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 3d589b3d..c1ecbaac 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -17,11 +17,22 @@