Ejemplo n.º 1
0
        public void Apply(CanvasDocument document)
        {
            // Screen addition
            if (ParentControlPath == ControlPath.Empty)
            {
                if (!IsControlTreeCollisionFree(this.Control, document._editorStateStore))
                {
                    return;
                }

                AddControlStates(this.Control, document._editorStateStore);

                document._screens.Add(this.Control.Name.Identifier, this.Control);
                return;
            }

            // screen was removed?
            if (!document._screens.TryGetValue(ParentControlPath.Current, out var control))
            {
                return;
            }

            var path = ParentControlPath.Next();

            while (path.Current != null)
            {
                var found = false;
                foreach (var child in control.Children)
                {
                    if (child.Name.Identifier == path.Current)
                    {
                        control = child;
                        path    = path.Next();
                        found   = true;
                        break;
                    }
                }
                // tree was deleted
                if (!found)
                {
                    return;
                }
            }

            if (!IsControlTreeCollisionFree(this.Control, document._editorStateStore))
            {
                return;
            }

            AddControlStates(this.Control, document._editorStateStore);

            control.Children.Add(this.Control);
        }
        public void Apply(CanvasDocument document)
        {
            var controlSet = _isInComponent ? document._components : document._screens;

            // Screen removal
            if (_parentControlPath == ControlPath.Empty)
            {
                controlSet.Remove(_controlName);
                return;
            }

            // error case?
            if (!controlSet.TryGetValue(_parentControlPath.Current, out var control))
            {
                return;
            }

            var path = _parentControlPath.Next();

            while (path.Current != null)
            {
                var found = false;
                foreach (var child in control.Children)
                {
                    if (child.Name.Identifier == path.Current)
                    {
                        control = child;
                        path    = path.Next();
                        found   = true;
                        break;
                    }
                }
                // Already removed
                if (!found)
                {
                    return;
                }
            }

            // Remove the control
            // maybe add error checks here too?
            control.Children = control.Children.Where(child => child.Name.Identifier != _controlName).ToList();
            document._editorStateStore.Remove(_controlName);
        }
        public void Apply(CanvasDocument document)
        {
            var controlSet = _isInComponent ? document._components : document._screens;

            // Top level addition
            if (_parentControlPath == ControlPath.Empty)
            {
                var repairedTopParent = MakeControlTreeCollisionFree(_control, _controlStates, document._editorStateStore);
                if (repairedTopParent == null)
                {
                    return;
                }

                AddControlStates(repairedTopParent, document._editorStateStore);

                controlSet.Add(_control.Name.Identifier, repairedTopParent);

                // Add screen to order set to avoid confusing diffs
                if (!_isInComponent && !document._screenOrder.Contains(ControlName))
                {
                    document._screenOrder.Add(ControlName);
                }

                return;
            }

            // Top Parent was removed
            if (!controlSet.TryGetValue(_parentControlPath.Current, out var control))
            {
                return;
            }

            var path = _parentControlPath.Next();

            while (path.Current != null)
            {
                var found = false;
                foreach (var child in control.Children)
                {
                    if (child.Name.Identifier == path.Current)
                    {
                        control = child;
                        path    = path.Next();
                        found   = true;
                        break;
                    }
                }
                // tree was deleted
                if (!found)
                {
                    return;
                }
            }

            var repairedControl = MakeControlTreeCollisionFree(_control, _controlStates, document._editorStateStore);

            if (repairedControl == null)
            {
                return;
            }
            AddControlStates(repairedControl, document._editorStateStore);

            control.Children.Add(repairedControl);
        }