From: Jean-Philippe Bruyère Date: Sun, 31 Oct 2021 11:20:31 +0000 (+0100) Subject: cut, copy, paste X-Git-Tag: v0.9.8-beta~2 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6f2069f51fd45b0bd15a1e6531e8089af921c29c;p=jp%2Fcrow.git cut, copy, paste --- diff --git a/Crow/Default.style b/Crow/Default.style index 54c44b42..066eb21b 100644 --- a/Crow/Default.style +++ b/Crow/Default.style @@ -81,6 +81,7 @@ Button { MinimumSize = "60,22"; Height = "Fit"; Width = "Fit"; + BubbleEvents= "None"; } ButtonBorder { BorderWidth="1"; diff --git a/Crow/Templates/MenuButton.template b/Crow/Templates/MenuButton.template index 8025954b..8bde1c59 100644 --- a/Crow/Templates/MenuButton.template +++ b/Crow/Templates/MenuButton.template @@ -5,4 +5,4 @@ MouseEnter="{Background=${ControlHighlight}}" MouseLeave="{Background=Transparent}"/> - + \ No newline at end of file diff --git a/Crow/Templates/MenuItem.template b/Crow/Templates/MenuItem.template index 4075be94..a86c3538 100644 --- a/Crow/Templates/MenuItem.template +++ b/Crow/Templates/MenuItem.template @@ -4,17 +4,15 @@ Foreground = "{./Foreground}" BubbleEvents="All" IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}"> diff --git a/Crow/src/EventArgs/SelectionChangeEventArgs.cs b/Crow/src/EventArgs/SelectionChangeEventArgs.cs index c45c880a..186de3fa 100644 --- a/Crow/src/EventArgs/SelectionChangeEventArgs.cs +++ b/Crow/src/EventArgs/SelectionChangeEventArgs.cs @@ -6,8 +6,11 @@ using System; namespace Crow { + /// + /// Occurs when the selection has changed. + /// public class SelectionChangeEventArgs: EventArgs - { + { public object NewValue; public SelectionChangeEventArgs (object _newValue) : base() diff --git a/Crow/src/EventArgs/TextSelectionChangeEventArgs.cs b/Crow/src/EventArgs/TextSelectionChangeEventArgs.cs new file mode 100644 index 00000000..979c7109 --- /dev/null +++ b/Crow/src/EventArgs/TextSelectionChangeEventArgs.cs @@ -0,0 +1,26 @@ +// Copyright (c) 2013-2021 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using Crow.Text; +using System; + +namespace Crow +{ + /// + /// Occurs in the TextBox widget and Label when the current selected text has changed. + /// + public class TextSelectionChangeEventArgs: EventArgs + { + /// + /// The text span of the current selection. + /// + public TextSpan Selection; + + public TextSelectionChangeEventArgs (TextSpan newSelection) : base() + { + Selection = newSelection; + } + } +} + diff --git a/Crow/src/Widgets/Button.cs b/Crow/src/Widgets/Button.cs index cdd9c590..607e0337 100644 --- a/Crow/src/Widgets/Button.cs +++ b/Crow/src/Widgets/Button.cs @@ -106,7 +106,7 @@ namespace Crow public override void onMouseClick (object sender, MouseButtonEventArgs e) { command?.Execute (this); - e.Handled = true; + //e.Handled = true; base.onMouseClick (sender, e); } diff --git a/Crow/src/Widgets/Label.cs b/Crow/src/Widgets/Label.cs index 7bd16b92..15a38357 100644 --- a/Crow/src/Widgets/Label.cs +++ b/Crow/src/Widgets/Label.cs @@ -26,11 +26,19 @@ namespace Crow /// Occurs when Text has changed. /// public event EventHandler TextChanged; + /// + /// Occurs when the current selected text has changed + /// + public event EventHandler SelectionChanged; public virtual void OnTextChanged(Object sender, TextChangeEventArgs e) { TextChanged.Raise (this, e); } + public virtual void OnSelectionChanged(Object sender, TextSelectionChangeEventArgs e) + { + SelectionChanged.Raise (this, e); + } //TODO:change protected to private #region private and protected fields @@ -54,6 +62,8 @@ namespace Crow currentLoc = value; NotifyValueChanged ("CurrentLine", CurrentLine); NotifyValueChanged ("CurrentColumn", CurrentColumn); + if (SelectionChanged != null) + OnSelectionChanged (this, new TextSelectionChangeEventArgs (Selection)); } } public virtual int CurrentLine { @@ -137,7 +147,7 @@ namespace Crow _textAlignment = value; CurrentLoc?.ResetVisualX (); - selectionStart?.ResetVisualX (); + SelectionStart?.ResetVisualX (); RegisterForRedraw (); NotifyValueChangedAuto (_textAlignment); @@ -170,10 +180,10 @@ namespace Crow } void constraintsLocations () { - if (selectionStart.HasValue) { + if (SelectionStart.HasValue) { CharLocation loc = CurrentLoc.Value; int l = Math.Min (loc.Line, lines.Count - 1); - selectionStart = new CharLocation (l, Math.Min (loc.Column, lines[l].Length - 1)); + SelectionStart = new CharLocation (l, Math.Min (loc.Column, lines[l].Length - 1)); } if (CurrentLoc.HasValue) { CharLocation loc = CurrentLoc.Value; @@ -308,27 +318,27 @@ namespace Crow public TextSpan Selection { set { if (value.IsEmpty) - selectionStart = null; + SelectionStart = null; else - selectionStart = lines.GetLocation (value.Start); + SelectionStart = lines.GetLocation (value.Start); CurrentLoc = lines.GetLocation (value.End); } get { if (CurrentLoc == null) return default; CharLocation selStart = CurrentLoc.Value, selEnd = CurrentLoc.Value; - if (selectionStart.HasValue) { - if (CurrentLoc.Value.Line < selectionStart.Value.Line) { + if (SelectionStart.HasValue) { + if (CurrentLoc.Value.Line < SelectionStart.Value.Line) { selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; - } else if (CurrentLoc.Value.Line > selectionStart.Value.Line) { - selStart = selectionStart.Value; + selEnd = SelectionStart.Value; + } else if (CurrentLoc.Value.Line > SelectionStart.Value.Line) { + selStart = SelectionStart.Value; selEnd = CurrentLoc.Value; - } else if (CurrentLoc.Value.Column < selectionStart.Value.Column) { + } else if (CurrentLoc.Value.Column < SelectionStart.Value.Column) { selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; + selEnd = SelectionStart.Value; } else { - selStart = selectionStart.Value; + selStart = SelectionStart.Value; selEnd = CurrentLoc.Value; } } @@ -341,7 +351,17 @@ namespace Crow return selection.IsEmpty ? "" : Text.AsSpan (selection.Start, selection.Length).ToString (); } } - public bool SelectionIsEmpty => selectionStart.HasValue ? Selection.IsEmpty : true; + public bool SelectionIsEmpty => SelectionStart.HasValue ? Selection.IsEmpty : true; + public CharLocation? SelectionStart { + get => selectionStart; + set { + if (selectionStart == value) + return; + selectionStart = value; + if (SelectionChanged != null) + OnSelectionChanged (this, new TextSelectionChangeEventArgs (Selection)); + } + } protected virtual void measureTextBounds (Context gr) { fe = gr.FontExtents; @@ -380,23 +400,23 @@ namespace Crow NotifyValueChanged ("CurrentColumn", CurrentColumn); } else updateLocation (gr, cb.Width, ref currentLoc); - if (selectionStart.HasValue) { + if (SelectionStart.HasValue) { updateLocation (gr, cb.Width, ref selectionStart); - if (CurrentLoc.Value != selectionStart.Value) + if (CurrentLoc.Value != SelectionStart.Value) selectionNotEmpty = true; } if (selectionNotEmpty) { - if (CurrentLoc.Value.Line < selectionStart.Value.Line) { + if (CurrentLoc.Value.Line < SelectionStart.Value.Line) { selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; - } else if (CurrentLoc.Value.Line > selectionStart.Value.Line) { - selStart = selectionStart.Value; + selEnd = SelectionStart.Value; + } else if (CurrentLoc.Value.Line > SelectionStart.Value.Line) { + selStart = SelectionStart.Value; selEnd = CurrentLoc.Value; - } else if (CurrentLoc.Value.Column < selectionStart.Value.Column) { + } else if (CurrentLoc.Value.Column < SelectionStart.Value.Column) { selStart = CurrentLoc.Value; - selEnd = selectionStart.Value; + selEnd = SelectionStart.Value; } else { - selStart = selectionStart.Value; + selStart = SelectionStart.Value; selEnd = CurrentLoc.Value; } } else @@ -600,10 +620,10 @@ namespace Crow } protected void checkShift (Modifier modifier) { if (modifier.HasFlag (Modifier.Shift)) { - if (!selectionStart.HasValue) - selectionStart = CurrentLoc; + if (!SelectionStart.HasValue) + SelectionStart = CurrentLoc; } else - selectionStart = null; + SelectionStart = null; } #region Widget overrides @@ -670,7 +690,7 @@ namespace Crow { base.onFocused (sender, e); if (CurrentLoc == null) { - selectionStart = new CharLocation (0, 0); + SelectionStart = new CharLocation (0, 0); CurrentLoc = new CharLocation (lines.Count - 1, lines[lines.Count - 1].Length); } RegisterForRedraw (); @@ -702,9 +722,9 @@ namespace Crow targetColumn = -1; if (HasFocus) { if (!IFace.Shift) - selectionStart = hoverLoc; - else if (!selectionStart.HasValue) - selectionStart = CurrentLoc; + SelectionStart = hoverLoc; + else if (!SelectionStart.HasValue) + SelectionStart = CurrentLoc; CurrentLoc = hoverLoc; IFace.forceTextCursor = true; RegisterForRedraw (); @@ -718,10 +738,10 @@ namespace Crow public override void onMouseUp (object sender, MouseButtonEventArgs e) { base.onMouseUp (sender, e); - if (e.Button != MouseButton.Left || !HasFocus || !selectionStart.HasValue) + if (e.Button != MouseButton.Left || !HasFocus || !SelectionStart.HasValue) return; - if (selectionStart.Value == CurrentLoc.Value) - selectionStart = null; + if (SelectionStart.Value == CurrentLoc.Value) + SelectionStart = null; } public override void onMouseDoubleClick (object sender, MouseButtonEventArgs e) { @@ -730,7 +750,7 @@ namespace Crow return; GotoWordStart (); - selectionStart = CurrentLoc; + SelectionStart = CurrentLoc; GotoWordEnd (); RegisterForRedraw (); } @@ -741,7 +761,7 @@ namespace Crow switch (e.Key) { case Key.Escape: - selectionStart = null; + SelectionStart = null; RegisterForRedraw (); break; case Key.Home: diff --git a/Crow/src/Widgets/MenuItem.cs b/Crow/src/Widgets/MenuItem.cs index 91c4677c..4fc6d86a 100644 --- a/Crow/src/Widgets/MenuItem.cs +++ b/Crow/src/Widgets/MenuItem.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) @@ -25,7 +25,7 @@ namespace Crow #region Public properties [DefaultValue(false)] public bool IsOpened { - get { return isOpened; } + get => isOpened; set { if (isOpened == value) return; @@ -149,7 +149,7 @@ namespace Crow { if (command != null) { command.Execute (this); - closeMenu (); + CloseMenu (); } if (hasClick) base.onMouseClick (sender, e); @@ -159,8 +159,8 @@ namespace Crow m.AutomaticOpening = false; } - void closeMenu () { - MenuItem tmp = LogicalParent as MenuItem; + public void CloseMenu () { + MenuItem tmp = this; while (tmp != null) { tmp.IsOpened = false; tmp.Background = Colors.Transparent; diff --git a/Crow/src/Widgets/TextBox.cs b/Crow/src/Widgets/TextBox.cs index 900075ff..e3fac1b4 100644 --- a/Crow/src/Widgets/TextBox.cs +++ b/Crow/src/Widgets/TextBox.cs @@ -298,7 +298,7 @@ namespace Crow OnValidate (this, new ValidateEventArgs (_text)); break; case Key.Escape: - selectionStart = null; + SelectionStart = null; CurrentLoc = lines.GetLocation (selection.Start); RegisterForRedraw (); break; @@ -349,7 +349,7 @@ namespace Crow _text = tmp.ToString (); lines.Update (change); //lines.Update (_text); - selectionStart = null; + SelectionStart = null; CurrentLoc = lines.GetLocation (change.Start + change.ChangedText.Length); textMeasureIsUpToDate = false; diff --git a/Samples/ShowCase/ShowCase.cs b/Samples/ShowCase/ShowCase.cs index 06fca837..6774314a 100644 --- a/Samples/ShowCase/ShowCase.cs +++ b/Samples/ShowCase/ShowCase.cs @@ -111,7 +111,7 @@ namespace ShowCase } void showError (Exception ex) { - Console.WriteLine (ex); + Debug.WriteLine (ex); NotifyValueChanged ("ErrorMessage", ex); NotifyValueChanged ("ShowError", true); } @@ -127,7 +127,7 @@ namespace ShowCase Load ("#ShowCase.showcase.crow").DataSource = this; crowContainer = FindByName ("CrowContainer") as Container; - editor = FindByName ("tb") as TextBox; + editor = FindByName ("tb") as Editor; if (!File.Exists (CurrentFile)) newFile (); diff --git a/Samples/ShowCase/ui/showcase.crow b/Samples/ShowCase/ui/showcase.crow index 19939654..692ce88e 100644 --- a/Samples/ShowCase/ui/showcase.crow +++ b/Samples/ShowCase/ui/showcase.crow @@ -83,9 +83,9 @@