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); } } }
private void InvokeDiscoverCallback(DataNode node) { _state.InvokeDiscoverCallback(node); }
public void InvokeEndCallback(DataNode node) { if (_sender != null && EndCallback != null) _sender.BeginInvoke(EndCallback, new object[] { node }); }
public void InvokeCollapseCallback(DataNode node) { if (_sender != null && CollapseCallback != null) _sender.BeginInvoke(CollapseCallback, new object[] { node }); }
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; }
private void SearchDiscoveryCallback(DataNode node) { _nodeTree.SelectedNode = FindFrontNode(node); if(_searchForm != null) { _searchForm.DialogResult = DialogResult.OK; _searchForm = null; } }
private bool ReorderNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = dataNode.ReorderNodeCapabilities; return (dataNode != null) && dataNode.CanReoderNode; }
private bool PasteIntoNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = dataNode.PasteIntoNodeCapabilities; return (dataNode != null) && dataNode.CanPasteIntoNode; }
private bool CreateCompoundNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = GroupCapabilities.Single; return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_COMPOUND); }
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(); }
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; }
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); }
private bool SearchNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = dataNode.SearchNodeCapabilites; return (dataNode != null) && dataNode.CanSearchNode; }
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; }
private bool CreateDoubleNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = GroupCapabilities.Single; return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_DOUBLE); }
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; }
private bool CreateFloatNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = GroupCapabilities.Single; return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_FLOAT); }
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(); } }
private bool CreateIntArrayNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = GroupCapabilities.Single; return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_INT_ARRAY); }
private void SearchCollapseCallback(DataNode node) { CollapseBelow(node); }
private bool CreateStringNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = GroupCapabilities.Single; return (dataNode != null) && dataNode.CanCreateTag(TagType.TAG_STRING); }
private void SearchEndCallback(DataNode node) { _searchForm.DialogResult = DialogResult.OK; _searchForm = null; MessageBox.Show("沒有更多的結果了。"); }
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; }
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); } } }
private bool DeleteNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = dataNode.DeleteNodeCapabilities; return (dataNode != null) && dataNode.CanDeleteNode; }
public void InvokeDiscoverCallback(DataNode node) { if (_sender != null && DiscoverCallback != null) _sender.BeginInvoke(DiscoverCallback, new object[] { node }); }
private bool EditNodePred(DataNode dataNode, out GroupCapabilities caps) { caps = dataNode.EditNodeCapabilities; return (dataNode != null) && dataNode.CanEditNode; }
public void InvokeProgressCallback(DataNode node) { if (_sender != null && ProgressCallback != null) _sender.BeginInvoke(ProgressCallback, new object[] { node }); }
private void InvokeCollapseCallback(DataNode node) { _state.InvokeCollapseCallback(node); }