]> O.S.I.I.S - jp/crow.git/commitdiff
cut, copy, paste
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 31 Oct 2021 11:20:31 +0000 (12:20 +0100)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Sun, 31 Oct 2021 11:20:31 +0000 (12:20 +0100)
14 files changed:
Crow/Default.style
Crow/Templates/MenuButton.template
Crow/Templates/MenuItem.template
Crow/src/EventArgs/SelectionChangeEventArgs.cs
Crow/src/EventArgs/TextSelectionChangeEventArgs.cs [new file with mode: 0644]
Crow/src/Widgets/Button.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/MenuItem.cs
Crow/src/Widgets/TextBox.cs
Samples/ShowCase/ShowCase.cs
Samples/ShowCase/ui/showcase.crow
Samples/common/src/Editor.cs
Samples/common/src/SampleBaseForEditor.cs
Samples/common/ui/Interfaces/TemplatedGroup/menu3.crow

index 54c44b42ea4132f4565216003e9f05799794ede0..066eb21bac610cf1c78056b6abea2086a5a814e2 100644 (file)
@@ -81,6 +81,7 @@ Button {
        MinimumSize = "60,22";
        Height          = "Fit";
        Width           = "Fit";
+       BubbleEvents= "None";
 }
 ButtonBorder {
        BorderWidth="1";
index 8025954b3879b6480fd6bf051104951b18b24637..8bde1c593c4c5ddb703d02ad2b5420e226b7a649 100644 (file)
@@ -5,4 +5,4 @@
                                                MouseEnter="{Background=${ControlHighlight}}"
                                                MouseLeave="{Background=Transparent}"/>
        </Template>
-</Button>
+</Button>
\ No newline at end of file
index 4075be945b3caf9b08c9b00782aa5ba1483b6594..a86c3538d43ef7f1d04078c7afeb805f72915e2b 100644 (file)
@@ -4,17 +4,15 @@
                Foreground = "{./Foreground}" BubbleEvents="All"
                IsPopped="{²./IsOpened}" PopWidth="{./PopWidth}" PopHeight="{./PopHeight}">
                <Template>
-                       
-                                       <Border Name="border1"
-                                                       MinimumSize = "60,0"
-                                                       Foreground="Transparent"
-                                                       Background="{./Background}">
-                                                       <Label Text="{./Caption}"
-                                                               Foreground="{./Foreground}"
-                                                               Margin="2" HorizontalAlignment="Left"
-                                                               Font="{./Font}" />
-                                       </Border>
-                       
+                       <Border Name="border1"
+                                       MinimumSize = "60,0"
+                                       Foreground="Transparent"
+                                       Background="{./Background}">
+                                       <Label Text="{./Caption}"
+                                               Foreground="{./Foreground}"
+                                               Margin="2" HorizontalAlignment="Left"
+                                               Font="{./Font}" />
+                       </Border>
                </Template>
                <Border Foreground="DimGrey" Width="{../PopWidth}" Height="{../PopHeight}" Background="${MenuBackground}">
                        <VerticalStack Name="ItemsContainer" Width="Stretched" />
index c45c880a8a4ee43298f556a7c8e05fd2075727a3..186de3fa7d331eb5473888eeefddc8838a6dab7e 100644 (file)
@@ -6,8 +6,11 @@ using System;
 
 namespace Crow
 {
+       /// <summary>
+       /// Occurs when the selection has changed.
+       /// </summary>
        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 (file)
index 0000000..979c710
--- /dev/null
@@ -0,0 +1,26 @@
+// Copyright (c) 2013-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT)
+
+using Crow.Text;
+using System;
+
+namespace Crow
+{
+       /// <summary>
+       /// Occurs in the TextBox widget and Label when the current selected text has changed.
+       /// </summary>
+       public class TextSelectionChangeEventArgs: EventArgs
+       {
+               /// <summary>
+               /// The text span of the current selection.
+               /// </summary>
+               public TextSpan Selection;
+
+               public TextSelectionChangeEventArgs (TextSpan newSelection) : base()
+               {
+                       Selection = newSelection;
+               }
+       }
+}
+
index cdd9c5908e673ee37f07a0fba313f01e0787293c..607e0337a3d31e6faeedb299436390b37eaf4bac 100644 (file)
@@ -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);
                }
 
index 7bd16b92afe63958dffd903a8b65857f3221ec25..15a38357e266847b983551c6c50343bdb92b8330 100644 (file)
@@ -26,11 +26,19 @@ namespace Crow
                /// Occurs when Text has changed.
                /// </summary>
                public event EventHandler<TextChangeEventArgs> TextChanged;
+               /// <summary>
+               /// Occurs when the current selected text has changed
+               /// </summary>
+               public event EventHandler<TextSelectionChangeEventArgs> 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:
index 91c4677c4c0b5b9f342faff9dd68cbee3329a2a5..4fc6d86aa32fa2487c1269527584c5110e8daac3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (c) 2013-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2013-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // 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;
index 900075ff8ebbb9a6e6999e3ec211db3ccd206e72..e3fac1b406983301468a2a2aa8dd9c861b450e4b 100644 (file)
@@ -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;
index 06fca8371778077b6060061792f3e0dd53f13ef5..6774314af3881557e176e9104a171e15e1b388c3 100644 (file)
@@ -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 ();
index 19939654cf56d6a634208bbff99c6f742aa0cedd..692ce88e249ea21554894446a237546848453991 100644 (file)
@@ -83,9 +83,9 @@
                                <Button Style="IcoButton" Command="{CMDSaveAs}" />
                                <Button Style="IcoButton" Command="{CMDUndo}" />
                                <Button Style="IcoButton" Command="{CMDRedo}" />
-                               <!--<Button Style="IcoButton" Command="{CMDCut}" />
+                               <Button Style="IcoButton" Command="{CMDCut}" />
                                <Button Style="IcoButton" Command="{CMDCopy}" />
-                               <Button Style="IcoButton" Command="{CMDPaste}" />-->
+                               <Button Style="IcoButton" Command="{CMDPaste}" />
                                <Popper RootDataLevel="true" IsVisible="{DebugLoggingEnabled}" Fit="true">
                                        <Template>
                                                <CheckBox IsChecked="{²./IsPopped}">
                                                </Border>
                                        </Template>
                                        <VerticalStack Width="200" Height="200" Background="Jet" Margin="5">
-                                               <CheckBox Caption="Embed source in templated control" IsChecked="{²EncloseInTemplatedControl}"/>
+                                               <CheckBox Caption="Embed source in template" IsChecked="{²EncloseInTemplatedControl}"/>
                                                <TextBox BubbleEvents="None" Text="{²TemplateContainerSource}" Width="Stretched" Height="Stretched" Multiline="true"
                                                        Tooltip="Add '*source* where you want to load the source in the editor."/>
                                        </VerticalStack>
                        <HorizontalStack>
                                <Editor Name="tb" Text="{Source}" Multiline="true" Font="consolas, 12" Focusable="true" Height="Stretched" Width="Stretched"
                                                TextChanged="onTextChanged" KeyDown="textView_KeyDown" ContextCommands="{EditorCommands}"
+                                               SelectionChanged="onEditorSelectionChanged"
                                                Foreground="DarkGrey" Background="White" MouseWheelSpeed="20"/>
-                                               <!--SelectionChanged="onSelectedTextChanged"-->
                                <ScrollBar Value="{²../tb.ScrollY}"
                                                LargeIncrement="{../tb.PageHeight}" SmallIncrement="1"
                                                CursorRatio="{../tb.ChildHeightRatio}" Maximum="{../tb.MaxScrollY}" />
index 25a15c5ad24f546c4a9bfbdb6e76aa64bdbda595..90335d83e8224f6bdb4d78c4e9858fab4721f261 100644 (file)
@@ -210,7 +210,7 @@ namespace Crow
                                        if (attrib.ValueToken.HasValue) {
                                                TextChange tc = new TextChange (currentToken.Start, currentToken.Length, selectedSugg);
                                                update (tc);
-                                               selectionStart = lines.GetLocation (attrib.ValueToken.Value.Start + tc.CharDiff + 1);
+                                               SelectionStart = lines.GetLocation (attrib.ValueToken.Value.Start + tc.CharDiff + 1);
                                                CurrentLoc = lines.GetLocation (attrib.ValueToken.Value.End + tc.CharDiff - 1);
                                        } else {
                                                update (new TextChange (currentToken.Start, currentToken.Length, selectedSugg + "=\"\""));
@@ -224,7 +224,10 @@ namespace Crow
                        hideOverlay ();
                        base.onMouseDown (sender, e);
                }
-
+               public override void onMouseEnter(object sender, MouseMoveEventArgs e) {
+                       base.onMouseEnter (sender, e);
+                       HasFocus = true;
+               }
                public override void onKeyDown(object sender, KeyEventArgs e)
                {
                        TextSpan selection = Selection;
@@ -280,7 +283,7 @@ namespace Crow
                                                update (new TextChange (lines[l].Start, 0, "\t"));
                                }
 
-                               selectionStart = new CharLocation (lineStart, 0);
+                               SelectionStart = new CharLocation (lineStart, 0);
                                CurrentLoc = new CharLocation (lineEnd, lines[lineEnd].Length);
 
                                disableSuggestions = false;
@@ -305,7 +308,7 @@ namespace Crow
                                        CharLocation selStart = default, selEnd = default;
                                        bool selectionNotEmpty = false;
 
-                                       if (HasFocus) {
+                                       //if (HasFocus) {
                                                if (currentLoc?.Column < 0) {
                                                        updateLocation (gr, cb.Width, ref currentLoc);
                                                        NotifyValueChanged ("CurrentColumn", CurrentColumn);
@@ -322,28 +325,28 @@ namespace Crow
                                                                overlay.Top = p.Y;
                                                        }
                                                }
-                                               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
                                                        IFace.forceTextCursor = true;
-                                       }
+                                       //}
 
                                        double spacePixelWidth = gr.TextExtents (" ").XAdvance;
                                        int x = 0, y = 0;
@@ -429,7 +432,7 @@ namespace Crow
                                                        tok = source.Tokens[tokPtr];
                                                }
 
-                                               if (HasFocus && selectionNotEmpty) {
+                                               if (selectionNotEmpty) {
                                                        RectangleD lineRect = new RectangleD (cb.X,     lineHeight * y + cb.Top, pixX, lineHeight);
                                                        RectangleD selRect = lineRect;
 
index 92d0634c741a437cd410664cc975f42b63423163..b207eea365fea514f9384b0b059b609c9affff49 100644 (file)
@@ -27,12 +27,11 @@ namespace Samples
 
                        if (string.IsNullOrEmpty (CurrentDir))
                                CurrentDir = Path.Combine (Directory.GetCurrentDirectory (), "Interfaces");
-
                }
 
                protected const string _defaultFileName = "unnamed.txt";
                protected string source = "", origSource;
-               protected TextBox editor;
+               protected Editor editor;
                bool debugLogRecording;
 
 
@@ -148,7 +147,10 @@ namespace Samples
                protected TextSpan selection;
                protected string SelectedText =>
                                selection.IsEmpty ? "" : Source.AsSpan (selection.Start, selection.Length).ToString ();
-
+               public void onEditorSelectionChanged(Object sender, TextSelectionChangeEventArgs e) {
+                       selection = e.Selection;
+                       CMDCut.CanExecute = CMDCopy.CanExecute = !selection.IsEmpty;
+               }
                protected void undo () {
                        if (undoStack.TryPop (out TextChange tch)) {
                                redoStack.Push (tch.Inverse (source));
@@ -182,6 +184,7 @@ namespace Samples
                }
                protected void copy () {
                        Clipboard = SelectedText;
+                       CMDPaste.CanExecute = !string.IsNullOrEmpty (Clipboard);
                }
                protected void paste () {
                        applyChange (new TextChange (selection.Start, selection.Length, Clipboard));
@@ -276,6 +279,10 @@ namespace Samples
                        disableTextChangedEvent = true;
                        Source = tmp.ToString ();
                        disableTextChangedEvent = false;
+                       editor.SelectionStart = null;
+                       editor.SetCursorPosition (change.Start + change.ChangedText.Length);
+
+                       forceTextCursor = true;
                }
                protected void applyChange (TextChange change) {
                        undoStack.Push (change.Inverse (source));
@@ -316,12 +323,6 @@ namespace Samples
                                return;
                        applyChange (e.Change);
                }
-
-               protected void onSelectedTextChanged (object sender, EventArgs e) {
-                       selection = (sender as Label).Selection;
-                       Console.WriteLine($"selection:{selection.Start} length:{selection.Length}");
-                       CMDCut.CanExecute = CMDCopy.CanExecute = !selection.IsEmpty;
-               }
                protected void textView_KeyDown (object sender, Crow.KeyEventArgs e) {
                        if (Ctrl) {
                                if (e.Key == Glfw.Key.W) {
index d58c9653593e2a6394aeaf3a6970ce14ec6937f0..ba7a8e0cd1fe4738f5e31967378648012c9aa1db 100644 (file)
@@ -13,7 +13,7 @@
                                        </Template>
                                        <VerticalStack Margin="0" Name="ItemsContainer" Fit="true" Background="Jet"/>
                                </Popper>
-                       </Template>             
+                       </Template>
                        <ItemTemplate DataType="Crow.Command" Path="#Crow.MenuButton.template"/>
                        <ItemTemplate DataType="Crow.CommandGroup" Data="Commands">
                                <Popper PopDirection="Right" Caption="{Caption}" IsEnabled="{CanExecute}" Width="Stretched"
                                                        <Label Text="{./Caption}"   Width="Fit" Height="Stretched"/>
                                                        <Label Text="..."/>
                                                </HorizontalStack>
-                                       </Template>             
+                                       </Template>
                                        <VerticalStack Margin="0" Name="ItemsContainer" Width="{../PopWidth}" Height="{../PopHeight}" Background="${MenuBackground}"/>
                                </Popper>
-                       </ItemTemplate>                                         
+                       </ItemTemplate>
                </MenuItem>
        </ItemTemplate>
 </Menu>
\ No newline at end of file