/// <summary> /// Removes the given node from the nodemap. /// </summary> /// <param name="node">Node to be removed.</param> public void removeNodeFromMap(goog.ui.tree.BaseNode node) { var labelText = node.getText(); if (labelText != null && !String.IsNullOrWhiteSpace(/*goog.string.makeSafe*/ (labelText))) { labelText = labelText.ToLowerCase(); if (this.nodeMap_.TryGetValue(labelText, out var nodeList)) { // Remove the node's descendants from the nodemap. var count = node.getChildCount(); for (var i = 0; i < count; i++) { this.removeNodeFromMap((BaseNode)node.getChildAt(i)); } // Remove the node from the array. nodeList.Remove(node); if (nodeList.Length == 0) { this.nodeMap_.Remove(labelText); } } } }
/// <summary> /// Adds or updates the given node in the nodemap. The label text is used as a /// key and the node id is used as a value. In the case that the key already /// exists, such as when more than one node exists with the same label, then this /// function creates an array to hold the multiple nodes. /// </summary> /// <param name="node">Node to be added or updated.</param> public void setNodeInMap(goog.ui.tree.BaseNode node) { var labelText = node.getText(); if (labelText != null && !String.IsNullOrWhiteSpace(/*goog.string.makeSafe*/ (labelText))) { // Typeahead is case insensitive, convert to lowercase. labelText = labelText.ToLowerCase(); if (this.nodeMap_.TryGetValue(labelText, out var previousValue)) { // Found a previously created array, add the given node. previousValue.Push(node); } else { // Create a new array and set the array as value. var nodeList = new JsArray <BaseNode> { node }; this.nodeMap_[labelText] = nodeList; } } }