//****************************************************************** /// <summary> /// Displays the Features form so the user can view (but not edit) /// the features of the given SyntaxNode. The user can also modify /// the FavoriteListFeatures, FavoriteTreeFeatures and /// CopyFavoritesOnly settings. If the user clicks OK, changes are /// saved to the settings, and DialogResult.OK is returned. /// Otherwise, DialogResult.Cancel is returned and any changes are /// discarded. /// </summary> public static DialogResult OpenFeaturesReadOnly(SyntaxNode oNode) { //************************************************************** // Validate the parameters. if (oNode == null) { string sMessage = "Invalid argument: " + "FeaturesForm.OpenFeaturesReadOnly() requires " + "a SyntaxNode object that is not null."; throw new Exception(sMessage); } //************************************************************** // Create an instance of the FeaturesForm. FeaturesForm oForm = new FeaturesForm(); //************************************************************** // Set the form's ReadOnly property to true (the user is not // allowed to edit features). oForm.ReadOnly = true; //************************************************************** // Set the form's DisplayedNode property to a copy of the node // specified by the oNode parameter. oForm.DisplayedNode = oNode.CloneNode(); //************************************************************** // Show the form so the user can view (but not edit) the // features of the DisplayedNode. DialogResult iResult = oForm.ShowDialog(); //************************************************************** // Return the dialog result. return iResult; }
//****************************************************************** /// <summary> /// Associates the given oTreeNode with with the indicated /// oSyntaxNode (by setting oTreeNode.Tag to oSyntaxNode). The /// oSyntaxNode features are then used to determine the text that is /// displayed by the oTreeNode. (If this node is a leaf node and /// morphology nodes are not shown, the oSyntaxNode can have child /// nodes to represent morphology. Otherwise, the given oSyntaxNode /// cannot have child nodes.) /// </summary> private void PopulateNode(TreeViewerNode oTreeNode, SyntaxNode oSyntaxNode) { Debug.Assert(oTreeNode != null); Debug.Assert(oSyntaxNode != null); //************************************************************** // The oSyntaxNode can have child nodes (representing // morphology) only if this is a leaf node and morphology nodes // are not shown. if (! oSyntaxNode.IsSyntaxLeaf) { Debug.Assert(oSyntaxNode.ChildNodes.Count == 0); } if (ShowMorphology) { Debug.Assert(oSyntaxNode.ChildNodes.Count == 0); } //************************************************************** // Set the oTreeNode.Tag to associate the displayed node with // the indicated oSyntaxNode. oTreeNode.Tag = oSyntaxNode; //************************************************************** // If this is a leaf node, display the node's text in a bold // font style. Otherwise, use a regular font style. if (oSyntaxNode.IsSyntaxLeaf) { Font oFont = Font; if (oFont.FontFamily.IsStyleAvailable(FontStyle.Bold)) { oFont = new Font(oFont,FontStyle.Bold); } oTreeNode.Font = oFont; } else { Font oFont = Font; if (oFont.FontFamily.IsStyleAvailable(FontStyle.Regular)) { oFont = new Font(oFont,FontStyle.Regular); } oTreeNode.Font = oFont; } //************************************************************** // The displayed text always starts with the node's label. string sText = oSyntaxNode.Label; //************************************************************** // If the ShowFeatures property is true, add the name and value // text for each feature. if (ShowFeatures) { //********************************************************** // For find-pattern and replace-pattern nodes, show all // features. // // For parse-tree nodes, only show the features that are // named in the FavoriteTreeFeatures collection. SyntaxNode oFilteredSyntaxNode = oSyntaxNode.CloneNode(); if ((! DisplayFindPattern) && (! DisplayReplacePattern)) { FilterFeatures(oFilteredSyntaxNode, FavoriteTreeFeatures); } //********************************************************** // Append the name and value text for each feature (except // the node-label feature, since the text already starts // with the node's label). foreach (SyntaxFeature oFeature in oFilteredSyntaxNode.Features) { if (oFeature.Name != TreeTranEngineString.NodeLabel) { string sName = oFeature.Name; string sValue = oFeature.Value; sText = sText + Environment.NewLine + sName + "=" + sValue; } } } //************************************************************** // Set the text of the displayed node. oTreeNode.Text = sText; }
//****************************************************************** /// <summary> /// Displays the Features form so the user can view and edit the /// features of the given SyntaxNode. The user can also modify the /// FavoriteListFeatures, FavoriteTreeFeatures and CopyFavoritesOnly /// settings. If the user clicks OK, the edits are saved to the /// SyntaxNode features, changes are saved to the settings, and /// DialogResult.OK is returned. Otherwise, DialogResult.Cancel is /// returned and any changes are discarded. /// </summary> public static DialogResult OpenFeatures(SyntaxNode oNode) { //************************************************************** // Validate the parameters. if (oNode == null) { string sMessage = "Invalid argument: " + "FeaturesForm.OpenFeatures() requires " + "a SyntaxNode object that is not null."; throw new Exception(sMessage); } //************************************************************** // Create an instance of the FeaturesForm. FeaturesForm oForm = new FeaturesForm(); //************************************************************** // Set the form's ReadOnly property to false. oForm.ReadOnly = false; //************************************************************** // Set the form's DisplayedNode property to a copy of the node // specified by the oNode parameter. oForm.DisplayedNode = oNode.CloneNode(); //************************************************************** // Show the form so the user can view and edit the features of // the DisplayedNode. DialogResult iResult = oForm.ShowDialog(); //************************************************************** // If the user clicked OK, save the changes that the user made // to the features: // // Update the specified oNode by clearing its features and then // copying all the features from the form's DisplayedNode to the // oNode.Features collection. if (iResult == DialogResult.OK) { oNode.Features.Clear(); foreach (SyntaxFeature oFeature in oForm.DisplayedNode.Features) { oNode.Features[oFeature.Name] = oFeature.Value; } } //************************************************************** // Return the dialog result. return iResult; }
//****************************************************************** /// <summary> /// Uses the given oTreeNode to display features of the indicated /// oSyntaxNode. Children are then recursively added to oTreeNode to /// represent the children of oSyntaxNode (unless it is a leaf node /// and morphology nodes are hidden). If the optional oTreeTransfer /// argument is given, its CurrentParseTreeNode indicates the node /// to select, and items in its MatchingNodes and ReplacedNodes /// collections indicate nodes to highlight. /// </summary> private void PopulateBranch(TreeViewerNode oTreeNode, SyntaxNode oSyntaxNode,TreeTransfer oTreeTransfer) { Debug.Assert(oTreeNode != null); Debug.Assert(oSyntaxNode != null); Debug.Assert(oTreeTransfer != null); //************************************************************** // The given oTreeNode should not already have children. Debug.Assert(oTreeNode.ChildNodes.Count == 0); //************************************************************** // Set the node's context menu. oTreeNode.ContextMenu = moMenu; //************************************************************** // Use the oTreeTransfer.CurrentParseTreeNode property to // determine if the node is selected. if (oSyntaxNode == oTreeTransfer.CurrentParseTreeNode) { moTreeViewer.SelectedNode = oTreeNode; } //************************************************************** // Use the oTreeTransfer.MatchingNodes and .ReplacedNodes // collections to determine the node's background color. Color oForeColor = SystemColors.WindowText; Color oBackColor = SystemColors.Window; foreach (SyntaxNodePair oNodePair in oTreeTransfer.MatchingNodes) { if (oSyntaxNode == oNodePair.ParseTreeNode) { oBackColor = FindPatternColor; } } foreach (SyntaxNodeTriple oNodeTriple in oTreeTransfer.ReplacedNodes) { if (oSyntaxNode == oNodeTriple.ParseTreeNode) { oBackColor = ReplacePatternColor; } } if (DisplayFindPattern) { oBackColor = FindPatternColor; } if (DisplayReplacePattern) { oBackColor = ReplacePatternColor; } oTreeNode.ForeColor = oForeColor; oTreeNode.BackColor = oBackColor; //************************************************************** // Determine if the node's children should be shown. // // A node's children are usually shown, but if the node is a // leaf node and ShowMorphology is false, the leaf node's // children (representing morphology) are not shown (unless the // leaf node's children are selected or highlighted). bool bShowChildNodes = true; if (oSyntaxNode.IsSyntaxLeaf) { if (! ShowMorphology) { bShowChildNodes = false; //****************************************************** // Even if ShowMorphology is false, a leaf node's // children are shown if any of the child branches // contains a selected or highlighted node. foreach (SyntaxNode oSyntaxChild in oSyntaxNode.ChildNodes) { if (BranchContainsSelectionOrHighlight( oSyntaxChild,oTreeTransfer)) { bShowChildNodes = true; } } } } //************************************************************** // Display the node (showing or hiding its children). if (bShowChildNodes) { //********************************************************** // Display the node and its children. // // Clone the oSyntaxNode (without including child nodes) and // call PopulateNode(). PopulateNode(oTreeNode,oSyntaxNode.CloneNode()); //********************************************************** // For each child node, add a new TreeViewerNode to the tree // and make a recursive call to PopulateBranch(). foreach (SyntaxNode oSyntaxChild in oSyntaxNode.ChildNodes) { TreeViewerNode oTreeChild = new TreeViewerNode(); oTreeNode.ChildNodes.Add(oTreeChild); PopulateBranch(oTreeChild,oSyntaxChild,oTreeTransfer); } } else { //********************************************************** // Display the node, but hide its children. // // Clone the entire oSyntaxNode branch (so the cloned branch // includes child nodes that represent morphology) and call // PopulateNode(). PopulateNode(oTreeNode,oSyntaxNode.CloneBranch()); } }