Beispiel #1
0
        public TextSelectionOverlay(TextEditingValue value                  = null,
                                    BuildContext context                    = null, Widget debugRequiredFor = null,
                                    LayerLink layerLink                     = null,
                                    RenderEditable renderObject             = null,
                                    TextSelectionControls selectionControls = null,
                                    TextSelectionDelegate selectionDelegate = null,
                                    DragStartBehavior dragStartBehavior     = DragStartBehavior.start)
        {
            D.assert(value != null);
            D.assert(context != null);
            this.context           = context;
            this.debugRequiredFor  = debugRequiredFor;
            this.layerLink         = layerLink;
            this.renderObject      = renderObject;
            this.selectionControls = selectionControls;
            this.selectionDelegate = selectionDelegate;
            this._value            = value;
            OverlayState overlay = Overlay.of(context);

            D.assert(overlay != null, () => $"No Overlay widget exists above {context}.\n" +
                     "Usually the Navigator created by WidgetsApp provides the overlay. Perhaps your " +
                     "app content was created above the Navigator with the WidgetsApp builder parameter.");
            this._toolbarController = new AnimationController(duration: fadeDuration, vsync: overlay);
            this.dragStartBehavior  = dragStartBehavior;
        }
Beispiel #2
0
        public ActionResult CreateNode([Bind] CreateNode Node, int InstanceID)
        {
            if (ModelState.IsValid)
            {
                //make sure the layer exists in this instance.
                var Layer = db.Layers.DefaultIfEmpty(null).FirstOrDefault(x => x.InstanceID == Node.InstanceID && x.LayerID == Node.LayerID);
                if (Layer == null)
                {
                    ModelState.AddModelError("Layer", "Unable to find Layer.");
                    return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
                }
                //

                Node node = new Node(Node);
                db.Nodes.Add(node);
                node.Links = new List <Link>();
                db.SaveChanges();
                Link Link = null;
                //create a link if needed.
                if (Node.ParentNodeID != null)
                {
                    CreateLink l = new CreateLink
                    {
                        OriginID = (int)Node.ParentNodeID,
                        TargetID = node.NodeID,
                        Type     = "Parent"
                    };
                    Link = new Link(l);
                    db.Links.Add(Link);
                    db.SaveChanges();
                }


                if (Node.SiblingNodeID != null)
                {
                    CreateLink l = new CreateLink
                    {
                        OriginID = (int)Node.ParentNodeID,
                        TargetID = node.NodeID,
                        Type     = "Sibling"
                    };
                    Link = new Link(l);
                    db.Links.Add(Link);
                    //node.Links.Add(l);
                    db.SaveChanges();
                }

                //link to the layer.
                var layerLink = new LayerLink(new CreateLayerLink {
                    NodeID = node.NodeID, LayerID = Node.LayerID
                });
                db.LayerLinks.Add(layerLink);
                db.SaveChanges();
                return(Json(new { node = node, layerlink = new JsonLayerLink(layerLink), link = Link }));
            }

            return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
        }
Beispiel #3
0
        public ActionResult AssignLayer(int[] NodeID, int LayerID, int InstanceID)
        {
            //first find the node and the layer in the same instance.
            if (NodeID.Length == 0)
            {
                return(Json(new { success = true }));
            }
            //now remove any that aren't in the appropriate instance.

            bool found = db.Layers.Any(x => x.LayerID == LayerID && x.InstanceID == InstanceID);

            if (!found)
            {
                ModelState.AddModelError("Layer", "Invalid Layer.");
            }

            List <int> Nodes = new List <int>();

            foreach (var x in NodeID)
            {
                var thisNode = db.Nodes.DefaultIfEmpty(null).FirstOrDefault(y => y.NodeID == x && y.InstanceID == InstanceID && y.Active);
                if (thisNode != null)
                {
                    Nodes.Add(x);
                }
            }

            if (Nodes.Count() == 0)
            {
                ModelState.AddModelError("Nodes", "No Nodes Found.");
            }

            if (!ModelState.IsValid)
            {
                return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
            }

            foreach (var i in Nodes)
            {
                var thisLink = new LayerLink(new CreateLayerLink {
                    LayerID = LayerID, NodeID = i
                });
                if (thisLink.LayerLinkID != 0)
                {
                    var link = db.LayerLinks.Find(thisLink.LayerLinkID);
                    link = thisLink;
                }
                else
                {
                    db.LayerLinks.Add(thisLink);
                }
            }
            db.SaveChanges();
            return(Json(new { success = true }));
        }
Beispiel #4
0
 internal _TextSelectionHandleOverlay(
     Key key = null,
     TextSelection selection = null,
     _TextSelectionHandlePosition position = _TextSelectionHandlePosition.start,
     LayerLink layerLink         = null,
     RenderEditable renderObject = null,
     ValueChanged <TextSelection> onSelectionHandleChanged = null,
     VoidCallback onSelectionHandleTapped    = null,
     TextSelectionControls selectionControls = null
     ) : base(key: key)
 {
     this.selection                = selection;
     this.position                 = position;
     this.layerLink                = layerLink;
     this.renderObject             = renderObject;
     this.onSelectionHandleChanged = onSelectionHandleChanged;
     this.onSelectionHandleTapped  = onSelectionHandleTapped;
     this.selectionControls        = selectionControls;
 }
Beispiel #5
0
        public ActionResult CreatePath([Bind] CreateLayer c, int InstanceID)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new { error = Generic.GetValidationErrors(ModelState) }));
            }
            var layer = new Layer(c);

            db.Layers.Add(layer);
            db.SaveChanges();
            //crate layer links, if appropriate.
            List <LayerLink> LayerLinks = new List <LayerLink>();

            if (c.Nodes != null)
            {
                foreach (var x in c.Nodes)
                {
                    var node = db.Nodes.DefaultIfEmpty(null).FirstOrDefault(y => y.NodeID == x && y.InstanceID == InstanceID);
                    if (node == null)
                    {
                        continue;
                    }
                    var thisLink = new LayerLink(new CreateLayerLink {
                        LayerID = layer.LayerID, NodeID = x
                    });
                    LayerLinks.Add(thisLink);
                }
                db.LayerLinks.AddRange(LayerLinks);
                db.SaveChanges();
            }

            var jsonLinks = new List <JsonLayerLink>();

            foreach (var l in LayerLinks)
            {
                jsonLinks.Add(new JsonLayerLink(l));
            }
            return(Json(new
            {
                layer = new JsonLayer(layer),
                layerLinks = jsonLinks
            }));
        }
Beispiel #6
0
        public TextSelectionOverlay(TextEditingValue value                  = null,
                                    BuildContext context                    = null, Widget debugRequiredFor = null,
                                    LayerLink layerLink                     = null,
                                    RenderEditable renderObject             = null,
                                    TextSelectionControls selectionControls = null,
                                    TextSelectionDelegate selectionDelegate = null)
        {
            D.assert(value != null);
            D.assert(context != null);
            this.context           = context;
            this.debugRequiredFor  = debugRequiredFor;
            this.layerLink         = layerLink;
            this.renderObject      = renderObject;
            this.selectionControls = selectionControls;
            this.selectionDelegate = selectionDelegate;
            this._value            = value;
            OverlayState overlay = Overlay.of(context);

            D.assert(overlay != null);
            this._handleController  = new AnimationController(duration: _fadeDuration, vsync: overlay);
            this._toolbarController = new AnimationController(duration: _fadeDuration, vsync: overlay);
        }
Beispiel #7
0
 internal _TextSelectionHandleOverlay(
     Key key = null,
     TextSelection selection = null,
     _TextSelectionHandlePosition position = _TextSelectionHandlePosition.start,
     LayerLink startHandleLayerLink        = null,
     LayerLink endHandleLayerLink          = null,
     RenderEditable renderObject           = null,
     ValueChanged <TextSelection> onSelectionHandleChanged = null,
     VoidCallback onSelectionHandleTapped    = null,
     TextSelectionControls selectionControls = null,
     DragStartBehavior dragStartBehavior     = DragStartBehavior.start
     ) : base(key: key)
 {
     this.selection                = selection;
     this.position                 = position;
     this.startHandleLayerLink     = startHandleLayerLink;
     this.endHandleLayerLink       = endHandleLayerLink;
     this.renderObject             = renderObject;
     this.onSelectionHandleChanged = onSelectionHandleChanged;
     this.onSelectionHandleTapped  = onSelectionHandleTapped;
     this.selectionControls        = selectionControls;
     this.dragStartBehavior        = dragStartBehavior;
 }
Beispiel #8
0
        public TextSelectionOverlay(
            TextEditingValue value                  = null,
            BuildContext context                    = null,
            Widget debugRequiredFor                 = null,
            LayerLink toolbarLayerLink              = null,
            LayerLink startHandleLayerLink          = null,
            LayerLink endHandleLayerLink            = null,
            RenderEditable renderObject             = null,
            TextSelectionControls selectionControls = null,
            bool?handlesVisible = false,
            TextSelectionDelegate selectionDelegate = null,
            DragStartBehavior dragStartBehavior     = DragStartBehavior.start,
            VoidCallback onSelectionHandleTapped    = null)
        {
            D.assert(value != null);
            D.assert(context != null);
            D.assert(handlesVisible != null);
            _handlesVisible              = handlesVisible.Value;
            this.context                 = context;
            this.debugRequiredFor        = debugRequiredFor;
            this.toolbarLayerLink        = toolbarLayerLink;
            this.startHandleLayerLink    = startHandleLayerLink;
            this.endHandleLayerLink      = endHandleLayerLink;
            this.renderObject            = renderObject;
            this.selectionControls       = selectionControls;
            this.selectionDelegate       = selectionDelegate;
            this.onSelectionHandleTapped = onSelectionHandleTapped;
            _value = value;
            OverlayState overlay = Overlay.of(context, rootOverlay: true);

            D.assert(overlay != null, () => $"No Overlay widget exists above {context}.\n" +
                     "Usually the Navigator created by WidgetsApp provides the overlay. Perhaps your " +
                     "app content was created above the Navigator with the WidgetsApp builder parameter.");
            _toolbarController     = new AnimationController(duration: fadeDuration, vsync: overlay);
            this.dragStartBehavior = dragStartBehavior;
        }
Beispiel #9
0
        public override Widget build(BuildContext context)
        {
            LayerLink layerLink          = null;
            TextSelectionHandleType type = TextSelectionHandleType.left;

            switch (widget.position)
            {
            case _TextSelectionHandlePosition.start:
                layerLink = widget.startHandleLayerLink;
                type      = _chooseType(
                    widget.renderObject.textDirection,
                    TextSelectionHandleType.left,
                    TextSelectionHandleType.right
                    );
                break;

            case _TextSelectionHandlePosition.end:
                D.assert(!widget.selection.isCollapsed);
                layerLink = widget.endHandleLayerLink;
                type      = _chooseType(
                    widget.renderObject.textDirection,
                    TextSelectionHandleType.right,
                    TextSelectionHandleType.left
                    );
                break;
            }

            Offset handleAnchor = widget.selectionControls.getHandleAnchor(
                type,
                widget.renderObject.preferredLineHeight
                );
            Size handleSize = widget.selectionControls.getHandleSize(
                widget.renderObject.preferredLineHeight
                );

            Rect handleRect = Rect.fromLTWH(
                -handleAnchor.dx,
                -handleAnchor.dy,
                handleSize.width,
                handleSize.height
                );

            Rect interactiveRect = handleRect.expandToInclude(
                Rect.fromCircle(center: handleRect.center, radius: kMinInteractiveDimension / 2)
                );
            RelativeRect padding = RelativeRect.fromLTRB(
                Mathf.Max((interactiveRect.width - handleRect.width) / 2, 0),
                Mathf.Max((interactiveRect.height - handleRect.height) / 2, 0),
                Mathf.Max((interactiveRect.width - handleRect.width) / 2, 0),
                Mathf.Max((interactiveRect.height - handleRect.height) / 2, 0)
                );

            return(new CompositedTransformFollower(
                       link: layerLink,
                       offset: interactiveRect.topLeft,
                       showWhenUnlinked: false,
                       child: new FadeTransition(
                           opacity: _opacity,
                           child: new Container(
                               alignment: Alignment.topLeft,
                               width: interactiveRect.width,
                               height: interactiveRect.height,
                               child: new GestureDetector(
                                   behavior: HitTestBehavior.translucent,
                                   dragStartBehavior: widget.dragStartBehavior,
                                   onPanStart: _handleDragStart,
                                   onPanUpdate: _handleDragUpdate,
                                   onTap: _handleTap,
                                   child: new Padding(
                                       padding: EdgeInsets.only(
                                           left: padding.left,
                                           top: padding.top,
                                           right: padding.right,
                                           bottom: padding.bottom
                                           ),
                                       child: widget.selectionControls.buildHandle(context, type,
                                                                                   widget.renderObject.preferredLineHeight)
                                       )
                                   )
                               )
                           )
                       ));
        }
Beispiel #10
0
 public AnchoredTag(Point point, LayerLink link, Tag tag) : base(point, link)
 {
     Tag = tag;
     Tag.AddLayer(link.Layer);
 }