Пример #1
0
        /// <summary>
        /// Occurs when a drag-and-drop operation is completed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragDropHandler(object sender, DragEventArgs e)
        {
            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
                lastDragDropTarget           = null;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (sourceNode == null)
            {
                MessageBox.Show(this, @"Drag & Drop Canceled: Unknown Source");

                return;
            }

            var targetNode = GetDragDropTargetNode(e);

            switch (e.Effect)
            {
            case DragDropEffects.Copy:
                DoDragDropCopy((dynamic)sourceNode, (dynamic)targetNode);
                break;

            case DragDropEffects.Move:
                DoDragDropMove((dynamic)sourceNode, (dynamic)targetNode);
                break;
            }
        }
Пример #2
0
        private void AddWizardItem_Click(Object sender, EventArgs e)
        {
            var newItem = new ItemDefinition();

            newItem.ShowDialog(this);
            var itemType = newItem.Type;

            if (string.IsNullOrEmpty(itemType))
            {
                return;
            }

            var itemDescription = newItem.Description;

            JTokenNode = (JTokenTreeNode)InsertJToken(JObject.Parse("{}"), true);

            var subitems = InsertProperty("subitems", new JArray());

            if (!string.IsNullOrEmpty(itemDescription))
            {
                InsertProperty("desc", itemDescription);
            }
            InsertProperty("type", itemType);

            subitems.Expand();
            JTokenNode.TreeView.SelectedNode = subitems.FirstNode;
            JTokenNode          = (JTokenTreeNode)subitems.FirstNode;
            JTokenNode.NodeFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
        }
Пример #3
0
        private bool IsDragDropValid(JTokenTreeNode sourceNode, JTokenTreeNode targetNode, DragDropEffects effect)
        {
            if (sourceNode == null || targetNode == null)
            {
                return(false);
            }

            if (sourceNode.JTokenTag is JProperty)
            {
                return(targetNode.JTokenTag is JObject);
            }

            if (sourceNode.JTokenTag is JObject)
            {
                switch (effect)
                {
                case DragDropEffects.Copy:
                    return(targetNode.JTokenTag is JArray);

                case DragDropEffects.Move:
                    return(!(targetNode.JTokenTag.Parent is JProperty) &&
                           targetNode.JTokenTag is JArray);
                }
            }

            if (sourceNode.JTokenTag is JArray)
            {
                switch (effect)
                {
                case DragDropEffects.Copy:
                    return(targetNode.JTokenTag is JArray);

                case DragDropEffects.Move:
                    return(!(targetNode.JTokenTag.Parent is JProperty) &&
                           targetNode.JTokenTag is JArray);
                }
            }

            if (sourceNode.JTokenTag is JValue)
            {
                switch (effect)
                {
                case DragDropEffects.Copy:
                    return(targetNode.JTokenTag is JArray);

                case DragDropEffects.Move:
                    return(!(targetNode.JTokenTag.Parent is JProperty) &&
                           targetNode.JTokenTag is JArray);
                }
            }

            return(false);
        }
Пример #4
0
        // ReSharper disable once UnusedParameter.Local
        private void JsonTreeView_AfterSelectImplementation(JTokenTreeNode node, TreeViewEventArgs e)
        {
            newtonsoftJsonTypeTextBox.Text = node.Tag.GetType().Name;

            jsonTypeComboBox.Text = node.JTokenTag.Type.ToString();

            // If jsonValueTextBox is focused then it triggers this event in the update process, so don't update it again ! (risk: infinite loop between events).
            if (!jsonValueTextBox.Focused)
            {
                jsonValueTextBox.Text = node.JTokenTag.ToString();
            }
        }
Пример #5
0
        private bool IsDragDropValid(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
        {
            if (sourceNode == null || targetNode == null)
            {
                return(false);
            }

            if (sourceNode.JTokenTag is JProperty)
            {
                return(targetNode.JTokenTag is JObject);
            }
            if (sourceNode.JTokenTag is JObject)
            {
                return(targetNode.JTokenTag is JProperty || targetNode.JTokenTag is JArray);
            }
            if (sourceNode.JTokenTag is JArray)
            {
                return(targetNode.JTokenTag is JArray);
            }

            return(false);
        }
        /// <inheritdoc />
        protected override void OnVisibleChanged(EventArgs e)
        {
            if (Visible)
            {
                JTokenNode = FindSourceTreeNode <JTokenTreeNode>();

                // Collapse item shown if node is expanded and has children
                CollapseAllToolStripItem.Visible = JTokenNode.IsExpanded &&
                                                   JTokenNode.Nodes.Cast <TreeNode>().Any();

                // Expand item shown if node if not expanded or has a children not expanded
                ExpandAllToolStripItem.Visible = !JTokenNode.IsExpanded ||
                                                 JTokenNode.Nodes.Cast <TreeNode>().Any(t => !t.IsExpanded);

                // Remove item enabled if it is not the root or the value of a property
                DeleteNodeToolStripItem.Enabled = (JTokenNode.Parent != null) &&
                                                  !(JTokenNode.Parent is JPropertyTreeNode);

                // Cut item enabled if delete is
                CutNodeToolStripItem.Enabled = DeleteNodeToolStripItem.Enabled;

                // Paste items enabled only when a copy or cut operation is pending
                PasteNodeAfterToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                      (JTokenNode.Parent != null) &&
                                                      !(JTokenNode.Parent is JPropertyTreeNode);

                PasteNodeBeforeToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                       (JTokenNode.Parent != null) &&
                                                       !(JTokenNode.Parent is JPropertyTreeNode);

                PasteNodeReplaceToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                        (JTokenNode.Parent != null);
            }

            base.OnVisibleChanged(e);
        }
Пример #7
0
        private void AddWizardStep_Click(Object sender, EventArgs e)
        {
            var newStep = new StepDefinition();

            newStep.ShowDialog(this);
            var stepName = newStep.Title;

            if (string.IsNullOrEmpty(stepName))
            {
                return;
            }

            var stepValidation   = newStep.Validation;
            var stepActivation   = newStep.Activation;
            var stepDeactivation = newStep.Deactivation;

            JTokenNode = (JTokenTreeNode)InsertJToken(JObject.Parse("{}"), true);

            var items = InsertProperty("items", new JArray());

            if (!string.IsNullOrEmpty(stepActivation))
            {
                InsertProperty("activate", stepActivation); ////Should I do the same Typo 'activeate' as in official Synology documentation??
            }
            if (!string.IsNullOrEmpty(stepDeactivation))
            {
                InsertProperty("deactivate", stepDeactivation); //"{console.log('deactivate', arguments);}"
            }
            InsertProperty("invalid_next_disabled", stepValidation.ToString());
            InsertProperty("step_title", stepName);

            items.Expand();
            JTokenNode.TreeView.SelectedNode = items.FirstNode;
            JTokenNode          = (JTokenTreeNode)items.FirstNode;
            JTokenNode.NodeFont = new Font(SystemFonts.DefaultFont, FontStyle.Bold | FontStyle.Underline);
        }
Пример #8
0
        /// <summary>
        /// Occurs when an object is dragged over the control's bounds.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragOverHandler(object sender, DragEventArgs e)
        {
            var targetNode = GetDragDropTargetNode(e);

            var keyState = (KeyStates)e.KeyState;

            if ((keyState & KeyStates.Control) == KeyStates.Control)
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if ((keyState & KeyStates.Shift) == KeyStates.Shift)
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.Copy;
            }

            if (targetNode == null)
            {
                if (e.Effect != DragDropEffects.None)
                {
                    lastValidDragDropEffect = e.Effect;
                    e.Effect = DragDropEffects.None;
                }

                if (lastDragDropTarget != null)
                {
                    lastDragDropTarget.BackColor = lastDragDropBackColor;
                }

                lastDragDropTarget = null;

                return;
            }

            if (targetNode == lastDragDropTarget)
            {
                if (DateTime.Now - lastDragDropDateTime >= new TimeSpan(5000000))
                {
                    targetNode.Expand();
                }

                return;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (IsDragDropValid(sourceNode, targetNode))
            {
                if (e.Effect == DragDropEffects.None)
                {
                    e.Effect = lastValidDragDropEffect;
                }

                lastDragDropBackColor = targetNode.BackColor;
                targetNode.BackColor  = Color.BlueViolet;
            }
            else
            {
                if (e.Effect != DragDropEffects.None)
                {
                    lastValidDragDropEffect = e.Effect;
                    e.Effect = DragDropEffects.None;
                }
            }

            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropBackColor;
            }

            lastDragDropTarget   = targetNode;
            lastDragDropDateTime = DateTime.Now;
        }
Пример #9
0
 /// <summary>
 /// Catches all unmanaged copies.
 /// </summary>
 /// <param name="sourceNode"></param>
 /// <param name="targetNode"></param>
 private void DoDragDropCopy(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
 {
     MessageBox.Show(@"Drag & Drop: Unmanaged Copy");
 }
Пример #10
0
        private bool IsDragDropValid(JTokenTreeNode sourceNode, JTokenTreeNode targetNode, DragDropEffects effect)
        {
            if (sourceNode == null || targetNode == null)
            {
                return false;
            }

            if (sourceNode.JTokenTag is JProperty)
            {
                return targetNode.JTokenTag is JObject;
            }

            if (sourceNode.JTokenTag is JObject)
            {
                switch (effect)
                {
                    case DragDropEffects.Copy:
                        return targetNode.JTokenTag is JArray;
                    case DragDropEffects.Move:
                        return !(targetNode.JTokenTag.Parent is JProperty)
                               && targetNode.JTokenTag is JArray;
                }
            }

            if (sourceNode.JTokenTag is JArray)
            {
                switch (effect)
                {
                    case DragDropEffects.Copy:
                        return targetNode.JTokenTag is JArray;
                    case DragDropEffects.Move:
                        return !(targetNode.JTokenTag.Parent is JProperty)
                               && targetNode.JTokenTag is JArray;
                }
            }

            if (sourceNode.JTokenTag is JValue)
            {
                switch (effect)
                {
                    case DragDropEffects.Copy:
                        return targetNode.JTokenTag is JArray;
                    case DragDropEffects.Move:
                        return !(targetNode.JTokenTag.Parent is JProperty)
                               && targetNode.JTokenTag is JArray;
                }
            }

            return false;
        }
Пример #11
0
        /// <summary>
        /// Occurs when an object is dragged over the control's bounds. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragOverHandler(object sender, DragEventArgs e)
        {
            var targetNode = GetDragDropTargetNode(e);

            if (targetNode == null)
            {
                e.Effect = DragDropEffects.None;

                if (lastDragDropTarget != null)
                {
                    lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
                }

                lastDragDropTarget = null;

                return;
            }

            var keyState = (KeyStates)e.KeyState;
            if (keyState.HasFlag(KeyStates.Control | KeyStates.Shift))
            {
                e.Effect = DragDropEffects.None;
            }
            else if (keyState.HasFlag(KeyStates.Control))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if (keyState.HasFlag(KeyStates.Shift))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.Move;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (targetNode == lastDragDropTarget)
            {
                if (!targetNode.IsExpanded && DateTime.Now - lastDragOverDateTime >= dragDropExpandDelay)
                {
                    targetNode.Expand();
                }

                if (IsDragDropValid(sourceNode, targetNode, e.Effect))
                {
                    lastDragDropTargetBackColor = targetNode.BackColor;
                    targetNode.BackColor = Color.BlueViolet;
                }
                else
                {
                    targetNode.BackColor = lastDragDropTargetBackColor;
                    e.Effect = DragDropEffects.None;
                }
            }
            else
            {
                lastDragDropTarget = targetNode;
                lastDragOverDateTime = DateTime.Now;

                if (IsDragDropValid(sourceNode, targetNode, e.Effect))
                {
                    lastDragDropTargetBackColor = targetNode.BackColor;
                    targetNode.BackColor = Color.BlueViolet;
                }
                else
                {
                    targetNode.BackColor = lastDragDropTargetBackColor;
                    e.Effect = DragDropEffects.None;
                }
            }

            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
            }
        }
Пример #12
0
        /// <summary>
        /// Occurs when a drag-and-drop operation is completed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragDropHandler(object sender, DragEventArgs e)
        {
            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
                lastDragDropTarget = null;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (sourceNode == null)
            {
                MessageBox.Show(@"Drag & Drop Canceled: Unknown Source");

                return;
            }

            var targetNode = GetDragDropTargetNode(e);

            switch (e.Effect)
            {
                case DragDropEffects.Copy:
                    DoDragDropCopy((dynamic)sourceNode, (dynamic)targetNode);
                    break;
                case DragDropEffects.Move:
                    DoDragDropMove((dynamic)sourceNode, (dynamic)targetNode);
                    break;
            }
        }
Пример #13
0
 private void DoDragDropMove(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
 {
     // TODO: Move sourceNode to target
     MessageBox.Show(@"Drag & Drop: Unmanaged Move");
 }
Пример #14
0
        /// <inheritdoc />
        protected override void OnVisibleChanged(EventArgs e)
        {
            var type = "";

            if (Visible)
            {
                JTokenNode = FindSourceTreeNode <JTokenTreeNode>();

                // Collapse item shown if node is expanded and has children
                CollapseAllToolStripItem.Visible = JTokenNode.IsExpanded &&
                                                   JTokenNode.Nodes.Cast <TreeNode>().Any();

                // Expand item shown if node if not expanded or has a children not expanded
                ExpandAllToolStripItem.Visible = !JTokenNode.IsExpanded ||
                                                 JTokenNode.Nodes.Cast <TreeNode>().Any(t => !t.IsExpanded);

                // Remove item enabled if it is not the root or the value of a property
                DeleteNodeToolStripItem.Enabled = (JTokenNode.Parent != null) &&
                                                  !(JTokenNode.Parent is JPropertyTreeNode);

                // Cut item enabled if delete is
                CutNodeToolStripItem.Enabled = DeleteNodeToolStripItem.Enabled;

                // Paste items enabled only when a copy or cut operation is pending
                PasteNodeAfterToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                      (JTokenNode.Parent != null) &&
                                                      !(JTokenNode.Parent is JPropertyTreeNode);

                PasteNodeBeforeToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                       (JTokenNode.Parent != null) &&
                                                       !(JTokenNode.Parent is JPropertyTreeNode);

                PasteNodeReplaceToolStripItem.Enabled = !EditorClipboard <JTokenTreeNode> .IsEmpty() &&
                                                        (JTokenNode.Parent != null);

                AddWizardStepToolStripItem.Visible    = (JTokenNode.Level == 0 && JTokenNode.Text.StartsWith("[Array]"));
                AddWizardItemToolStripItem.Visible    = (JTokenNode.Level == 3 && JTokenNode.Text.StartsWith("[Array]"));
                AddWizardSubitemToolStripItem.Visible = (JTokenNode.Level == 6 && JTokenNode.Text.StartsWith("[Array]"));
                if (AddWizardSubitemToolStripItem.Visible)
                {
                    try
                    {
                        type = JTokenNode.Parent.Parent.FirstNode.FirstNode.Text;
                    }
                    catch
                    {
                        MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    type = Helper.GetSubItemType(type);
                    if (type != "")
                    {
                        AddWizardSubitemToolStripItem.Text = "Add a " + type;
                    }
                }
                RemoveWizardStepToolStripItem.Visible = (JTokenNode.Level == 1 && JTokenNode.Text.StartsWith("{Object}"));
                if (RemoveWizardStepToolStripItem.Visible)
                {
                    try
                    {
                        RemoveWizardStepToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.FirstNode.FirstNode.Text);
                    }
                    catch
                    {
                        MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                RemoveWizardItemToolStripItem.Visible = (JTokenNode.Level == 4 && JTokenNode.Text.StartsWith("{Object}"));
                if (RemoveWizardItemToolStripItem.Visible)
                {
                    try
                    {
                        RemoveWizardItemToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.Nodes[1].FirstNode.Text);
                    }
                    catch
                    {
                        MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                RemoveWizardSubitemToolStripItem.Visible = (JTokenNode.Level == 7 && JTokenNode.Text.StartsWith("{Object}"));
                if (RemoveWizardSubitemToolStripItem.Visible)
                {
                    try
                    {
                        RemoveWizardSubitemToolStripItem.Text = string.Format("Remove '{0}'", JTokenNode.Nodes[1].FirstNode.Text);
                    }
                    catch
                    {
                        MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }

            base.OnVisibleChanged(e);
        }
Пример #15
0
        private void AddWizardSubitem_Click(Object sender, EventArgs e)
        {
            var node = JTokenNode;
            var type = "";

            try
            {
                type = node.Parent.Parent.FirstNode.FirstNode.Text;
            }
            catch
            {
                MessageBox.Show(this, "Type of Item cannot be found. Did you modify the json? Possibly recreate this item!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            if (!string.IsNullOrEmpty(type))
            {
                var newSubitem = new SubitemDefinition(type);
                newSubitem.ShowDialog(this);
                var subitemKey = newSubitem.Key;

                if (string.IsNullOrEmpty(subitemKey))
                {
                    return;
                }

                var subitemDescription        = newSubitem.Description;
                var subitemDefaultValue       = newSubitem.DefaultValue;
                var subitemEmptyValue         = newSubitem.EmptyValue;
                var subitemInvalidValue       = newSubitem.InvalidValue;
                var subitemWidth              = newSubitem.Width;
                var subitemHeight             = newSubitem.Height;
                var subitemDisabled           = newSubitem.Disable;
                var subitemHidden             = newSubitem.Hidden;
                var subitemPreventMark        = newSubitem.PreventMark;
                var subitemBaseParams         = newSubitem.BaseParams;
                var subitemRoot               = newSubitem.Root;
                var subitemApi                = newSubitem.Api;
                var subitemValueField         = newSubitem.ValueField;
                var subitemDisplayField       = newSubitem.DisplayField;
                var subitemStaticCombo        = newSubitem.StaticCombo;
                var subitemValueFieldUnique   = newSubitem.ValueFieldIsUnique;
                var subitemDisplayFieldUnique = newSubitem.DisplayFieldIsUnique;


                JTokenNode = (JTokenTreeNode)InsertJToken(JObject.Parse("{}"), true);

                if (subitemBaseParams.Count > 0)
                {
                    if (subitemStaticCombo)
                    {
                        // Static Combo is filled
                        var comboNode = JTokenNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("store", new JObject()).FirstNode;
                        InsertProperty("xtype", "arraystore");
                        var storeNode = JTokenNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("fields", new JArray()).FirstNode;
                        if (!string.IsNullOrEmpty(subitemValueField))
                        {
                            InsertJToken(new JValue(subitemValueField));
                        }
                        if (!string.IsNullOrEmpty(subitemDisplayField))
                        {
                            InsertJToken(new JValue(subitemDisplayField));
                        }
                        JTokenNode = storeNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("data", new JArray()).FirstNode;
                        foreach (var item in subitemBaseParams)
                        {
                            InsertJToken(new JArray(new JValue(item.value), new JValue(item.name)));
                        }

                        JTokenNode = comboNode;
                        InsertProperty("mode", "local");
                        if (string.IsNullOrEmpty(subitemDefaultValue))
                        {
                            subitemDefaultValue = "false";
                        }
                        InsertProperty("editable", Convert.ToBoolean(subitemDefaultValue)); //TODO: fix this. Should use "Editable"
                        if (!string.IsNullOrEmpty(subitemValueField))
                        {
                            InsertProperty("valuefield", subitemValueField);
                        }
                        if (!string.IsNullOrEmpty(subitemDisplayField))
                        {
                            InsertProperty("displayfield", subitemDisplayField);
                        }
                    }
                    else
                    {
                        // Dynamic Combo is filled
                        var comboNode = JTokenNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("api_store", new JObject()).FirstNode;
                        InsertProperty("api", subitemApi);
                        InsertProperty("method", "list");
                        InsertProperty("version", 1);
                        InsertProperty("root", subitemRoot);
                        if (subitemValueFieldUnique)
                        {
                            InsertProperty("idProperty", subitemValueField);
                        }
                        else if (subitemDisplayFieldUnique)
                        {
                            InsertProperty("idProperty", subitemDisplayField);
                        }
                        var storeNode = JTokenNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("fields", new JArray()).FirstNode;
                        if (!string.IsNullOrEmpty(subitemValueField))
                        {
                            InsertJToken(new JValue(subitemValueField));
                        }
                        if (!string.IsNullOrEmpty(subitemDisplayField))
                        {
                            InsertJToken(new JValue(subitemDisplayField));
                        }
                        JTokenNode = storeNode;
                        JTokenNode = (JTokenTreeNode)InsertProperty("baseParams", new JObject()).FirstNode;
                        foreach (var item in subitemBaseParams)
                        {
                            InsertProperty(item.name, item.value);
                        }

                        JTokenNode = comboNode;
                        InsertProperty("mode", "remote");
                        if (string.IsNullOrEmpty(subitemDefaultValue))
                        {
                            subitemDefaultValue = "false";
                        }
                        InsertProperty("editable", Convert.ToBoolean(subitemDefaultValue)); //TODO: fix this. Should use "Editable"
                        if (!string.IsNullOrEmpty(subitemValueField))
                        {
                            InsertProperty("valuefield", subitemValueField);
                        }
                        if (!string.IsNullOrEmpty(subitemDisplayField))
                        {
                            InsertProperty("displayfield", subitemDisplayField);
                        }
                    }
                }

                if (subitemDisabled)
                {
                    InsertProperty("disabled", subitemDisabled);
                }
                if (subitemHidden)
                {
                    InsertProperty("hidden", subitemHidden);
                }
                if (subitemPreventMark)
                {
                    InsertProperty("preventMark", subitemPreventMark);
                }
                if (!string.IsNullOrEmpty(subitemWidth))
                {
                    InsertProperty("width", subitemWidth);
                }
                if (!string.IsNullOrEmpty(subitemHeight))
                {
                    InsertProperty("height", subitemHeight);
                }
                if (!string.IsNullOrEmpty(subitemDescription))
                {
                    InsertProperty("desc", subitemDescription);
                }
                if (!string.IsNullOrEmpty(subitemDefaultValue))
                {
                    InsertProperty("defaultValue", subitemDefaultValue);
                }
                InsertProperty("key", subitemKey);

                JTokenNode.TreeView.SelectedNode = node;
                JTokenNode = node;
            }
        }
Пример #16
0
        /// <summary>
        /// Occurs when an object is dragged over the control's bounds. 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragOverHandler(object sender, DragEventArgs e)
        {
            var targetNode = GetDragDropTargetNode(e);

            var keyState = (KeyStates)e.KeyState;
            if ((keyState & KeyStates.Control) == KeyStates.Control)
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if ((keyState & KeyStates.Shift) == KeyStates.Shift)
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.Copy;
            }

            if (targetNode == null)
            {
                if (e.Effect != DragDropEffects.None)
                {
                    lastValidDragDropEffect = e.Effect;
                    e.Effect = DragDropEffects.None;
                }

                if (lastDragDropTarget != null)
                {
                    lastDragDropTarget.BackColor = lastDragDropBackColor;
                }

                lastDragDropTarget = null;

                return;
            }

            if (targetNode == lastDragDropTarget)
            {
                if (DateTime.Now - lastDragDropDateTime >= new TimeSpan(5000000))
                {
                    targetNode.Expand();
                }

                return;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (IsDragDropValid(sourceNode, targetNode))
            {
                if (e.Effect == DragDropEffects.None)
                {
                    e.Effect = lastValidDragDropEffect;
                }

                lastDragDropBackColor = targetNode.BackColor;
                targetNode.BackColor = Color.BlueViolet;
            }
            else
            {
                if (e.Effect != DragDropEffects.None)
                {
                    lastValidDragDropEffect = e.Effect;
                    e.Effect = DragDropEffects.None;
                }
            }

            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropBackColor;
            }

            lastDragDropTarget = targetNode;
            lastDragDropDateTime = DateTime.Now;
        }
Пример #17
0
        private bool IsDragDropValid(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
        {
            if (sourceNode == null || targetNode == null)
            {
                return false;
            }

            if (sourceNode.JTokenTag is JProperty)
            {
                return targetNode.JTokenTag is JObject;
            }
            if (sourceNode.JTokenTag is JObject)
            {
                return targetNode.JTokenTag is JProperty || targetNode.JTokenTag is JArray;
            }
            if (sourceNode.JTokenTag is JArray)
            {
                return targetNode.JTokenTag is JArray;
            }

            return false;
        }
        // ReSharper disable once UnusedParameter.Local
        private void JsonTreeView_AfterSelectImplementation(JTokenTreeNode node, TreeViewEventArgs e)
        {
            newtonsoftJsonTypeTextBox.Text = node.Tag.GetType().Name;

            jsonTypeComboBox.Text = node.JTokenTag.Type.ToString();

            // If jsonValueTextBox is focused then it triggers this event in the update process, so don't update it again ! (risk: infinite loop between events).
            if (!jsonValueTextBox.Focused)
            {
                jsonValueTextBox.Text = node.JTokenTag.ToString();
            }
        }
Пример #19
0
 /// <summary>
 /// Catches all unmanaged copies.
 /// </summary>
 /// <param name="sourceNode"></param>
 /// <param name="targetNode"></param>
 private void DoDragDropCopy(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
 {
     MessageBox.Show(this, @"Drag & Drop: Unmanaged Copy");
 }
Пример #20
0
 private void DoDragDropMove(JTokenTreeNode sourceNode, JTokenTreeNode targetNode)
 {
     // TODO: Move sourceNode to target
     MessageBox.Show(this, @"Drag & Drop: Unmanaged Move");
 }
Пример #21
0
        /// <summary>
        /// Occurs when an object is dragged over the control's bounds.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragOverHandler(object sender, DragEventArgs e)
        {
            var targetNode = GetDragDropTargetNode(e);

            if (targetNode == null)
            {
                e.Effect = DragDropEffects.None;

                if (lastDragDropTarget != null)
                {
                    lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
                }

                lastDragDropTarget = null;

                return;
            }

            var keyState = (KeyStates)e.KeyState;

            if (keyState.HasFlag(KeyStates.Control | KeyStates.Shift))
            {
                e.Effect = DragDropEffects.None;
            }
            else if (keyState.HasFlag(KeyStates.Control))
            {
                e.Effect = DragDropEffects.Copy;
            }
            else if (keyState.HasFlag(KeyStates.Shift))
            {
                e.Effect = DragDropEffects.Move;
            }
            else
            {
                e.Effect = DragDropEffects.Move;
            }

            var sourceNode = GetDragDropSourceNode(e);

            if (targetNode == lastDragDropTarget)
            {
                if (!targetNode.IsExpanded && DateTime.Now - lastDragOverDateTime >= dragDropExpandDelay)
                {
                    targetNode.Expand();
                }

                if (IsDragDropValid(sourceNode, targetNode, e.Effect))
                {
                    lastDragDropTargetBackColor = targetNode.BackColor;
                    targetNode.BackColor        = Color.BlueViolet;
                }
                else
                {
                    targetNode.BackColor = lastDragDropTargetBackColor;
                    e.Effect             = DragDropEffects.None;
                }
            }
            else
            {
                lastDragDropTarget   = targetNode;
                lastDragOverDateTime = DateTime.Now;

                if (IsDragDropValid(sourceNode, targetNode, e.Effect))
                {
                    lastDragDropTargetBackColor = targetNode.BackColor;
                    targetNode.BackColor        = Color.BlueViolet;
                }
                else
                {
                    targetNode.BackColor = lastDragDropTargetBackColor;
                    e.Effect             = DragDropEffects.None;
                }
            }

            if (lastDragDropTarget != null)
            {
                lastDragDropTarget.BackColor = lastDragDropTargetBackColor;
            }
        }