Ejemplo n.º 1
0
        private IEnumerable<DataNode> FindNode(DataNode node)
        {
            lock (_lock) {
                if (_cancel)
                    yield break;
            }

            if (node == null)
                yield break;

            bool searchExpanded = false;
            if (!node.IsExpanded) {
                node.Expand();
                searchExpanded = true;
            }

            TagDataNode tagNode = node as TagDataNode;
            if (tagNode != null) {
                bool mName = _state.SearchName == null;
                bool mValue = _state.SearchValue == null;

                if (_state.SearchName != null) {
                    string tagName = node.NodeName;
                    if (tagName != null)
                        mName = tagName.Contains(_state.SearchName);
                }
                if (_state.SearchValue != null) {
                    string tagValue = node.NodeDisplay;
                    if (tagValue != null)
                        mValue = tagValue.Contains(_state.SearchValue);
                }

                if (mName && mValue) {
                    InvokeDiscoverCallback(node);
                    yield return node;
                }
            }

            foreach (DataNode sub in node.Nodes) {
                foreach (DataNode s in FindNode(sub))
                    yield return s;
            }

            if (searchExpanded) {
                if (!node.IsModified) {
                    node.Collapse();
                    InvokeCollapseCallback(node);
                }
            }
        }
Ejemplo n.º 2
0
 private void InvokeDiscoverCallback(DataNode node)
 {
     _state.InvokeDiscoverCallback(node);
 }
Ejemplo n.º 3
0
 public void InvokeEndCallback(DataNode node)
 {
     if (_sender != null && EndCallback != null)
         _sender.BeginInvoke(EndCallback, new object[] { node });
 }
Ejemplo n.º 4
0
 public void InvokeCollapseCallback(DataNode node)
 {
     if (_sender != null && CollapseCallback != null)
         _sender.BeginInvoke(CollapseCallback, new object[] { node });
 }
Ejemplo n.º 5
0
        protected Dictionary<string, object> BuildExpandSet(DataNode node)
        {
            if (node == null || !node.IsExpanded)
                return null;

            Dictionary<string, object> dict = new Dictionary<string, object>();
            foreach (DataNode child in node.Nodes) {
                Dictionary<string, object> childDict = BuildExpandSet(child);
                if (childDict != null)
                    dict[child.NodeDisplay] = childDict;
            }

            return dict;
        }
Ejemplo n.º 6
0
        private void SearchDiscoveryCallback(DataNode node)
        {
            _nodeTree.SelectedNode = FindFrontNode(node);

            if(_searchForm != null) {
                _searchForm.DialogResult = DialogResult.OK;
                _searchForm = null;
            }
        }
Ejemplo n.º 7
0
 private bool ReorderNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.ReorderNodeCapabilities;
     return (dataNode != null) && dataNode.CanReoderNode;
 }
Ejemplo n.º 8
0
 private bool PasteIntoNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.PasteIntoNodeCapabilities;
     return (dataNode != null) && dataNode.CanPasteIntoNode;
 }
Ejemplo n.º 9
0
 private bool CreateCompoundNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_COMPOUND);
 }
Ejemplo n.º 10
0
        private void CollapseBelow(DataNode node)
        {
            Stack<DataNode> hierarchy;
            TreeNode frontNode = GetRootFromDataNodePath(node, out hierarchy);

            if(frontNode == null)
                return;

            while(hierarchy.Count > 0) {
                if(!frontNode.IsExpanded)
                    return;

                DataNode childData = hierarchy.Pop();
                foreach(TreeNode childFront in frontNode.Nodes) {
                    if(childFront.Tag == childData) {
                        frontNode = childFront;
                        break;
                    }
                }
            }

            if(frontNode.IsExpanded)
                frontNode.Collapse();
        }
Ejemplo n.º 11
0
        private ContextMenuStrip BuildNodeContextMenu(DataNode node)
        {
            if(node == null)
                return null;

            ContextMenuStrip menu = new ContextMenuStrip();

            if(node.CanReoderNode) {
                ToolStripMenuItem itemUp = new ToolStripMenuItem("向上移動 (&U)", Properties.Resources.ArrowUp, _contextMoveUp_Click);
                ToolStripMenuItem itemDn = new ToolStripMenuItem("向下移動 (&D)", Properties.Resources.ArrowDown, _contextMoveDown_Click);

                itemUp.Enabled = node.CanMoveNodeUp;
                itemDn.Enabled = node.CanMoveNodeDown;

                menu.Items.Add(itemUp);
                menu.Items.Add(itemDn);
            }

            return (menu.Items.Count > 0) ? menu : null;
        }
Ejemplo n.º 12
0
        private void UpdateUI(DataNode node)
        {
            if(node == null)
                return;

            _buttonAddTagByte.Enabled = node.CanCreateTag(TagType.TAG_BYTE);
            _buttonAddTagByteArray.Enabled = node.CanCreateTag(TagType.TAG_BYTE_ARRAY);
            _buttonAddTagCompound.Enabled = node.CanCreateTag(TagType.TAG_COMPOUND);
            _buttonAddTagDouble.Enabled = node.CanCreateTag(TagType.TAG_DOUBLE);
            _buttonAddTagFloat.Enabled = node.CanCreateTag(TagType.TAG_FLOAT);
            _buttonAddTagInt.Enabled = node.CanCreateTag(TagType.TAG_INT);
            _buttonAddTagIntArray.Enabled = node.CanCreateTag(TagType.TAG_INT_ARRAY);
            _buttonAddTagList.Enabled = node.CanCreateTag(TagType.TAG_LIST);
            _buttonAddTagLong.Enabled = node.CanCreateTag(TagType.TAG_LONG);
            _buttonAddTagShort.Enabled = node.CanCreateTag(TagType.TAG_SHORT);
            _buttonAddTagString.Enabled = node.CanCreateTag(TagType.TAG_STRING);

            _buttonSave.Enabled = CheckModifications();
            _buttonCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized;
            _buttonCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized;
            _buttonDelete.Enabled = node.CanDeleteNode;
            _buttonEdit.Enabled = node.CanEditNode;
            _buttonFindNext.Enabled = node.CanSearchNode || _searchState != null;
            _buttonPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized;
            _buttonRename.Enabled = node.CanRenameNode;
            _buttonRefresh.Enabled = node.CanRefreshNode;

            _menuItemSave.Enabled = _buttonSave.Enabled;
            _menuItemCopy.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized;
            _menuItemCopyJSON.Enabled = true;
            _menuItemCut.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized;
            _menuItemDelete.Enabled = node.CanDeleteNode;
            _menuItemEditValue.Enabled = node.CanEditNode;
            _menuItemCopy2.Enabled = node.CanCopyNode && NbtClipboardController.IsInitialized;
            _menuItemCopyJSON2.Enabled = true;
            _menuItemCut2.Enabled = node.CanCutNode && NbtClipboardController.IsInitialized;
            _menuItemDelete2.Enabled = node.CanDeleteNode;
            _menuItemEditValue2.Enabled = node.CanEditNode;
            _menuItemFind.Enabled = node.CanSearchNode;
            _menuItemPaste.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized;
            _menuItemRename.Enabled = node.CanRenameNode;
            _menuItemPaste2.Enabled = node.CanPasteIntoNode && NbtClipboardController.IsInitialized;
            _menuItemRename2.Enabled = node.CanRenameNode;
            _menuItemRefresh.Enabled = node.CanRefreshNode;
            _menuItemFind.Enabled = node.CanSearchNode;
            _menuItemFindNext.Enabled = _searchState != null;

            UpdateUI(_nodeTree.SelectedNodes);
        }
Ejemplo n.º 13
0
 private bool SearchNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.SearchNodeCapabilites;
     return (dataNode != null) && dataNode.CanSearchNode;
 }
Ejemplo n.º 14
0
        private TreeNode FindFrontNode(DataNode node)
        {
            Stack<DataNode> hierarchy;
            TreeNode frontNode = GetRootFromDataNodePath(node, out hierarchy);

            if(frontNode == null)
                return null;

            while(hierarchy.Count > 0) {
                if(!frontNode.IsExpanded) {
                    frontNode.Nodes.Add(new TreeNode());
                    frontNode.Expand();
                }

                DataNode childData = hierarchy.Pop();
                foreach(TreeNode childFront in frontNode.Nodes) {
                    if(childFront.Tag == childData) {
                        frontNode = childFront;
                        break;
                    }
                }
            }

            return frontNode;
        }
Ejemplo n.º 15
0
 private bool CreateDoubleNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_DOUBLE);
 }
Ejemplo n.º 16
0
        private TreeNode GetRootFromDataNodePath(DataNode node, out Stack<DataNode> hierarchy)
        {
            hierarchy = new Stack<DataNode>();
            while(node != null) {
                hierarchy.Push(node);
                node = node.Parent;
            }

            DataNode rootDataNode = hierarchy.Pop();
            TreeNode frontNode = null;
            foreach(TreeNode child in _nodeTree.Nodes) {
                if(child.Tag == rootDataNode)
                    frontNode = child;
            }

            return frontNode;
        }
Ejemplo n.º 17
0
 private bool CreateFloatNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_FLOAT);
 }
Ejemplo n.º 18
0
        private void RefreshChildNodes(TreeNode node, DataNode dataNode)
        {
            Dictionary<DataNode, TreeNode> currentNodes = new Dictionary<DataNode, TreeNode>();
            foreach(TreeNode child in node.Nodes) {
                if(child.Tag is DataNode)
                    currentNodes.Add(child.Tag as DataNode, child);
            }

            node.Nodes.Clear();
            foreach(DataNode child in dataNode.Nodes) {
                if(!currentNodes.ContainsKey(child))
                    node.Nodes.Add(CreateUnexpandedNode(child));
                else
                    node.Nodes.Add(currentNodes[child]);
            }

            foreach(TreeNode child in node.Nodes)
                child.ContextMenuStrip = BuildNodeContextMenu(child.Tag as DataNode);

            if(node.Nodes.Count == 0 && dataNode.HasUnexpandedChildren) {
                ExpandNode(node);
                node.Expand();
            }
        }
Ejemplo n.º 19
0
 private bool CreateIntArrayNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_INT_ARRAY);
 }
Ejemplo n.º 20
0
 private void SearchCollapseCallback(DataNode node)
 {
     CollapseBelow(node);
 }
Ejemplo n.º 21
0
 private bool CreateStringNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = GroupCapabilities.Single;
     return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_STRING);
 }
Ejemplo n.º 22
0
        private void SearchEndCallback(DataNode node)
        {
            _searchForm.DialogResult = DialogResult.OK;
            _searchForm = null;

            MessageBox.Show("沒有更多的結果了。");
        }
Ejemplo n.º 23
0
        private TreeNode CreateUnexpandedNode(DataNode node)
        {
            TreeNode frontNode = new TreeNode(node.NodeDisplay);
            frontNode.ImageIndex = _iconRegistry.Lookup(node.GetType());
            frontNode.SelectedImageIndex = frontNode.ImageIndex;
            frontNode.Tag = node;
            frontNode.ContextMenuStrip = BuildNodeContextMenu(node);

            if(node.HasUnexpandedChildren || node.Nodes.Count > 0)
                frontNode.Nodes.Add(new TreeNode());

            return frontNode;
        }
Ejemplo n.º 24
0
        protected void RestoreExpandSet(DataNode node, Dictionary<string, object> expandSet)
        {
            node.Expand();

            foreach (DataNode child in node.Nodes) {
                if (expandSet.ContainsKey(child.NodeDisplay)) {
                    Dictionary<string, object> childDict = (Dictionary<string, object>)expandSet[child.NodeDisplay];
                    if (childDict != null)
                        RestoreExpandSet(child, childDict);
                }
            }
        }
Ejemplo n.º 25
0
 private bool DeleteNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.DeleteNodeCapabilities;
     return (dataNode != null) && dataNode.CanDeleteNode;
 }
Ejemplo n.º 26
0
 public void InvokeDiscoverCallback(DataNode node)
 {
     if (_sender != null && DiscoverCallback != null)
         _sender.BeginInvoke(DiscoverCallback, new object[] { node });
 }
Ejemplo n.º 27
0
 private bool EditNodePred(DataNode dataNode, out GroupCapabilities caps)
 {
     caps = dataNode.EditNodeCapabilities;
     return (dataNode != null) && dataNode.CanEditNode;
 }
Ejemplo n.º 28
0
 public void InvokeProgressCallback(DataNode node)
 {
     if (_sender != null && ProgressCallback != null)
         _sender.BeginInvoke(ProgressCallback, new object[] { node });
 }
Ejemplo n.º 29
0
 private void InvokeCollapseCallback(DataNode node)
 {
     _state.InvokeCollapseCallback(node);
 }