private void CutOrDelete(IDataObject dataObject, out bool isDeleted)
        {
            isDeleted = false;

            string Content = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);

            Debug.Assert(Content != null);
            Debug.Assert(Start <= End);
            Debug.Assert(End <= Content.Length);

            if (Start < End)
            {
                if (dataObject != null)
                {
                    dataObject.SetData(typeof(string), Content.Substring(Start, End - Start));
                }

                Content = Content.Substring(0, Start) + Content.Substring(End);

                FocusController Controller       = StateView.ControllerView.Controller;
                int             OldCaretPosition = StateView.ControllerView.CaretPosition;
                int             NewCaretPosition = Start;
                Controller.ChangeTextAndCaretPosition(StateView.State.ParentIndex, PropertyName, Content, OldCaretPosition, NewCaretPosition, true);

                StateView.ControllerView.ClearSelection();
                isDeleted = true;
            }
        }
        /// <summary>
        /// Gets the value corresponding to a value property.
        /// The value type can be obtained from <see cref="ValuePropertyTypeTable"/>.
        /// </summary>
        /// <param name="propertyName">Property name.</param>
        /// <param name="value">Value of the property upon return.</param>
        /// <param name="minValue">Min value of the property upon return. Only applies to enum and booleans.</param>
        /// <param name="maxValue">Max value of the property upon return. Only applies to enum and booleans.</param>
        public virtual void PropertyToValue(string propertyName, out object value, out int minValue, out int maxValue)
        {
            Debug.Assert(!string.IsNullOrEmpty(propertyName));
            Debug.Assert(ValuePropertyTypeTable.ContainsKey(propertyName));

            value    = null;
            minValue = -1;
            maxValue = -1;
            bool IsHandled = false;

            switch (ValuePropertyTypeTable[propertyName])
            {
            case ValuePropertyType.Boolean:
            case ValuePropertyType.Enum:
                value = NodeTreeHelper.GetEnumValue(Node, propertyName);
                NodeTreeHelper.GetEnumRange(Node.GetType(), propertyName, out minValue, out maxValue);
                IsHandled = true;
                break;

            case ValuePropertyType.String:
                value     = NodeTreeHelper.GetString(Node, propertyName);
                IsHandled = true;
                break;

            case ValuePropertyType.Guid:
                value     = NodeTreeHelper.GetGuid(Node, propertyName);
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
        }
        private protected virtual string GetFocusedStringContent(IFocusStringContentFocus textCellFocus)
        {
            IFocusStringContentFocusableCellView CellView = textCellFocus.CellView;
            Node   Node         = CellView.StateView.State.Node;
            string PropertyName = CellView.PropertyName;

            return(NodeTreeHelper.GetString(Node, PropertyName));
        }
        /// <summary>
        /// Copy the selection in the clipboard.
        /// </summary>
        /// <param name="dataObject">The clipboard data object that can already contain other custom formats.</param>
        public override void Copy(IDataObject dataObject)
        {
            string Content = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);

            Debug.Assert(Content != null);
            Debug.Assert(Start <= End);
            Debug.Assert(End <= Content.Length);

            dataObject.SetData(typeof(string), Content.Substring(Start, End - Start));
        }
        /// <summary>
        /// Returns the value of a string.
        /// </summary>
        /// <param name="index">Index of the node.</param>
        /// <param name="propertyName">Name of the property to read.</param>
        public virtual string GetStringValue(IReadOnlyIndex index, string propertyName)
        {
            Debug.Assert(Contains(index));

            IReadOnlyNodeState State = StateTable[index];

            Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(propertyName));
            Debug.Assert(State.ValuePropertyTypeTable[propertyName] == Constants.ValuePropertyType.String);

            string Value = NodeTreeHelper.GetString(State.Node, propertyName);

            return(Value);
        }
Example #6
0
        private protected void DrawTextCaret(ILayoutStringContentFocus textCellFocus)
        {
            ILayoutStringContentFocusableCellView CellView = textCellFocus.CellView;

            Node   Node         = CellView.StateView.State.Node;
            string PropertyName = CellView.PropertyName;
            string Text         = NodeTreeHelper.GetString(Node, PropertyName);

            Point   CellOrigin  = CellView.CellOrigin;
            Padding CellPadding = CellView.CellPadding;

            Point OriginWithPadding = CellOrigin.Moved(CellPadding.Left, CellPadding.Top);

            DrawContext.ShowCaret(OriginWithPadding, Text, FocusedTextStyle, ActualCaretMode, CaretPosition);
        }
        /// <summary>
        /// Replaces the selection with the content of the clipboard.
        /// </summary>
        public override void Paste(out bool isChanged)
        {
            isChanged = false;

            if (ClipboardHelper.TryReadText(out string Text) && Text.Length > 0)
            {
                string Content = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);
                Debug.Assert(Content != null);
                Debug.Assert(Start <= End);
                Debug.Assert(End <= Content.Length);

                Content = Content.Substring(0, Start) + Text + Content.Substring(End);

                FocusController Controller       = StateView.ControllerView.Controller;
                int             OldCaretPosition = StateView.ControllerView.CaretPosition;
                int             NewCaretPosition = Start + Text.Length;
                Controller.ChangeTextAndCaretPosition(StateView.State.ParentIndex, PropertyName, Content, OldCaretPosition, NewCaretPosition, false);

                StateView.ControllerView.ClearSelection();
                isChanged = true;
            }
        }
Example #8
0
        private protected virtual void ExecuteChangeText(WriteableChangeTextOperation operation)
        {
            Node   ParentNode   = operation.ParentNode;
            string PropertyName = operation.PropertyName;
            string NewText      = operation.NewText;

            IWriteableNodeState State = (IWriteableNodeState)GetState(ParentNode);

            Debug.Assert(State != null);
            Debug.Assert(State.ValuePropertyTypeTable.ContainsKey(PropertyName));
            Debug.Assert(State.ValuePropertyTypeTable[PropertyName] == Constants.ValuePropertyType.String);

            string OldText = NodeTreeHelper.GetString(State.Node, PropertyName);

            Debug.Assert(OldText != null);

            NodeTreeHelper.SetString(State.Node, PropertyName, NewText);

            operation.Update(State, OldText);

            NotifyTextChanged(operation);
        }
Example #9
0
        /// <summary>
        /// Checks if the string associated to the <paramref name="propertyName"/> property of the <paramref name="stateView"/> state matches the pattern in <paramref name="textPattern"/>.
        /// </summary>
        /// <param name="stateView">The state view for the node with property <paramref name="propertyName"/>.</param>
        /// <param name="propertyName">Name of the property pointing to the template to check.</param>
        /// <param name="textPattern">Expected text.</param>
        public virtual bool StringMatchTextPattern(IFocusNodeStateView stateView, string propertyName, string textPattern)
        {
            IFocusNodeState State = stateView.State;

            Debug.Assert(State.InnerTable.ContainsKey(propertyName));

            bool IsHandled = false;
            bool Result    = false;

            switch (State.InnerTable[propertyName])
            {
            case IFocusPlaceholderInner AsPlaceholderInner:
                Debug.Assert(AsPlaceholderInner.InterfaceType.IsTypeof <Identifier>());
                IFocusPlaceholderNodeState ChildState = AsPlaceholderInner.ChildState as IFocusPlaceholderNodeState;
                Debug.Assert(ChildState != null);
                Result    = NodeTreeHelper.GetString(ChildState.Node, nameof(Identifier.Text)) == textPattern;
                IsHandled = true;
                break;
            }

            Debug.Assert(IsHandled);
            return(Result);
        }
        /// <summary>
        /// Prints the selection.
        /// </summary>
        public virtual void Print()
        {
            LayoutControllerView ControllerView = StateView.ControllerView;

            Debug.Assert(ControllerView.PrintContext != null);
            ControllerView.UpdateLayout();

            Debug.Assert(RegionHelper.IsValid(StateView.ActualCellSize));

            ILayoutTemplateSet             TemplateSet   = ControllerView.TemplateSet;
            IList <FocusFrameSelectorList> SelectorStack = StateView.GetSelectorStack();
            ILayoutTextValueFrame          Frame         = (ILayoutTextValueFrame)TemplateSet.PropertyToFrame(StateView.State, PropertyName, SelectorStack);

            Debug.Assert(Frame != null);

            string Text = NodeTreeHelper.GetString(StateView.State.Node, PropertyName);

            Debug.Assert(Text != null);

            Debug.Assert(Start <= End);
            Debug.Assert(End <= Text.Length);

            Frame.Print(ControllerView.PrintContext, Text.Substring(Start, End - Start), Point.Origin);
        }