Esempio n. 1
0
        //******************************************************************
        /// <summary>
        /// Copies the selected features from the ListView to the clipboard.
        /// </summary>
        private void CopySelectedFeatures()
        {
            //**************************************************************
            // Create a SyntaxNode and set its features by copying the
            // selected feature names and values from the ListView.
            //
            // (Do not copy blank features, which can appear when the
            // show-all-favorites option is checked.)

            SyntaxNode oNode = new SyntaxNode();
            foreach (ListViewItem oItem in moListView.SelectedItems)
            {
                string sName = oItem.SubItems[moNameColumn.Index].Text;
                string sValue = oItem.SubItems[moValueColumn.Index].Text;
                if ((sName != "") && (sValue != ""))
                {
                    oNode.Features[sName] = sValue;
                }
            }

            //**************************************************************
            // Create a RuleWriter that writes to a string.

            StringBuilder oStringBuilder = new StringBuilder();
            TextWriter oTextWriter = new StringWriter(oStringBuilder);
            RuleWriter oRuleWriter = new RuleWriter(oTextWriter);

            //**************************************************************
            // Make a rule that uses the SyntaxNode with the selected
            // features as its find pattern (and has an empty replace
            // pattern).

            oRuleWriter.RuleName = "(tree fragment on clipboard)";
            oRuleWriter.FindPatternRoot = oNode;
            oRuleWriter.ReplacePatternRoot = null;

            //**************************************************************
            // Write the rule to the string.

            oRuleWriter.Write();

            //**************************************************************
            // Close the RuleWriter.

            oRuleWriter.Close();

            //**************************************************************
            // Copy the string to the clipboard.

            const bool bCopy = true;
            Clipboard.SetDataObject(oStringBuilder.ToString(),bCopy);
        }
Esempio n. 2
0
        //******************************************************************
        /// <summary>
        /// Copies the current selection to the clipboard.
        /// </summary>
        public void Copy()
        {
            //**************************************************************
            // Validate the current state.

            if (! CanCopy())
            {
                string sMessage = "Invalid state: "
                    + "A call to ParseListViewer.Copy() is not allowed "
                    + "if ParseListViewer.CanCopy() returns false.";
                throw new Exception(sMessage);
            }

            //**************************************************************
            // Create a RuleWriter that writes to a string.

            StringBuilder oStringBuilder = new StringBuilder();
            TextWriter oTextWriter = new StringWriter(oStringBuilder);
            RuleWriter oRuleWriter = new RuleWriter(oTextWriter);

            //**************************************************************
            // Write each selected parse to the string.

            foreach (ListViewItem oItem in moListView.Items)
            {
                //**********************************************************
                // Get the parse from the ListView item.

                Debug.Assert(oItem is ParseListViewerItem);

                ParseListViewerItem oParseItem
                    = (ParseListViewerItem) oItem;

                //**********************************************************
                // If the item is selected, write the parse to the string.

                if (oParseItem.Selected)
                {
                    //******************************************************
                    // Make sure the parse tree is not null.

                    SyntaxNode oParseTreeRoot = oParseItem.ParseTreeRoot;
                    if (oParseTreeRoot == null)
                    {
                        oParseTreeRoot = new SyntaxNode();
                    }

                    //******************************************************
                    // Write the parse tree to the string.
                    //
                    // The parse tree is written in the format of a transfer
                    // rule: the .RuleName is the item's displayed text, the
                    // .FindPatternRoot is the parse tree, and the
                    // .ReplacePatternRoot is null.

                    oRuleWriter.RuleName = oParseItem.Text;
                    oRuleWriter.FindPatternRoot = oParseTreeRoot;
                    oRuleWriter.ReplacePatternRoot = null;
                    oRuleWriter.Write();
                }
            }

            //**************************************************************
            // Close the RuleWriter.

            oRuleWriter.Close();

            //**************************************************************
            // Copy the string to the clipboard.

            const bool bCopy = true;
            Clipboard.SetDataObject(oStringBuilder.ToString(),bCopy);
        }
Esempio n. 3
0
        //******************************************************************
        /// <summary>
        /// Saves the displayed rules to the indicated rule file
        /// (sFileName). The Modified property is set to false after the
        /// file is saved.
        /// </summary>
        public void SaveRuleFile(string sFileName)
        {
            //**************************************************************
            // Validate the parameters.

            if ((sFileName == null) || (sFileName == ""))
            {
                string sMessage = "Invalid argument: "
                    + "RuleListViewer.SaveRuleFile() requires "
                    + "a file name that is not null or blank.";
                throw new Exception(sMessage);
            }

            //**************************************************************
            // Create a RuleWriter to write to the indicated rule file.

            StreamWriter oStreamWriter = new StreamWriter(sFileName);
            RuleWriter oRuleWriter = new RuleWriter(oStreamWriter);

            //**************************************************************
            // For each item in the ListView, write the rule to the file.

            foreach (ListViewItem oItem in moListView.Items)
            {
                //**********************************************************
                // Get the rule from the ListView item.

                Debug.Assert(oItem is RuleListViewerItem);

                RuleListViewerItem oRuleItem = (RuleListViewerItem) oItem;

                //**********************************************************
                // Make sure the find pattern is not null.

                SyntaxNode oFindPatternRoot
                    = oRuleItem.FindPatternRoot;
                if (oFindPatternRoot == null)
                {
                    oFindPatternRoot = new SyntaxNode();
                }

                //**********************************************************
                // Make sure the replace pattern is not null.

                SyntaxNode oReplacePatternRoot
                    = oRuleItem.ReplacePatternRoot;
                if (oReplacePatternRoot == null)
                {
                    oReplacePatternRoot = new SyntaxNode();
                }

                //**********************************************************
                // Write the rule to the file.

                oRuleWriter.RuleName = oRuleItem.Text;
                oRuleWriter.FindPatternRoot = oFindPatternRoot;
                oRuleWriter.ReplacePatternRoot = oReplacePatternRoot;
                oRuleWriter.Write();
            }

            //**************************************************************
            // Close the RuleWriter.

            oRuleWriter.Close();

            //**************************************************************
            // Set the Modified property to false.

            Modified = false;
        }
Esempio n. 4
0
        //******************************************************************
        /// <summary>
        /// Copies the current selection to the clipboard.
        /// </summary>
        public void Copy()
        {
            //**************************************************************
            // Validate the current state.

            if (! CanCopy())
            {
                string sMessage = "Invalid state: "
                    + "A call to RuleListViewer.Copy() is not allowed "
                    + "if RuleListViewer.CanCopy() returns false.";
                throw new Exception(sMessage);
            }

            //**************************************************************
            // Create a RuleWriter that writes to a string.

            StringBuilder oStringBuilder = new StringBuilder();
            TextWriter oTextWriter = new StringWriter(oStringBuilder);
            RuleWriter oRuleWriter = new RuleWriter(oTextWriter);

            //**************************************************************
            // Write each selected rule to the string.

            foreach (ListViewItem oItem in moListView.Items)
            {
                //**********************************************************
                // Get the rule from the ListView item.

                Debug.Assert(oItem is RuleListViewerItem);

                RuleListViewerItem oRuleItem = (RuleListViewerItem) oItem;

                //**********************************************************
                // If the item is selected, write the rule to the string.

                if (oRuleItem.Selected)
                {
                    //******************************************************
                    // Make sure the find pattern is not null.

                    SyntaxNode oFindPatternRoot
                        = oRuleItem.FindPatternRoot;
                    if (oFindPatternRoot == null)
                    {
                        oFindPatternRoot = new SyntaxNode();
                    }

                    //******************************************************
                    // Make sure the replace pattern is not null.

                    SyntaxNode oReplacePatternRoot
                        = oRuleItem.ReplacePatternRoot;
                    if (oReplacePatternRoot == null)
                    {
                        oReplacePatternRoot = new SyntaxNode();
                    }

                    //******************************************************
                    // Write the rule to the string.

                    oRuleWriter.RuleName = oRuleItem.Text;
                    oRuleWriter.FindPatternRoot = oFindPatternRoot;
                    oRuleWriter.ReplacePatternRoot = oReplacePatternRoot;
                    oRuleWriter.Write();
                }
            }

            //**************************************************************
            // Close the RuleWriter.

            oRuleWriter.Close();

            //**************************************************************
            // Copy the string to the clipboard.

            const bool bCopy = true;
            Clipboard.SetDataObject(oStringBuilder.ToString(),bCopy);
        }
Esempio n. 5
0
        //******************************************************************
        /// <summary>
        /// Copies the current selection to the clipboard.
        /// </summary>
        public void Copy()
        {
            //**************************************************************
            // Validate the current state.

            if (! CanCopy())
            {
                string sMessage = "Invalid state: "
                    + "A call to ParseTreeViewer.Copy() is not allowed "
                    + "if ParseTreeViewer.CanCopy() returns false.";
                throw new Exception(sMessage);
            }

            //**************************************************************
            // Clone the selected branch. If no branch is selected, clone
            // the whole tree. (As a last result, use an empty node.)

            SyntaxNode oSyntaxBranchToCopy = null;
            if (moTreeViewer.SelectedNode != null)
            {
                oSyntaxBranchToCopy
                    = CloneBranch(moTreeViewer.SelectedNode);
            }
            if (oSyntaxBranchToCopy == null)
            {
                oSyntaxBranchToCopy = CloneTree();
            }
            if (oSyntaxBranchToCopy == null)
            {
                oSyntaxBranchToCopy = new SyntaxNode();
            }

            //**************************************************************
            // If the CopyFavoritesOnly option is true and we are copying
            // from a parse tree (not a find pattern or replace pattern),
            // filter out any features that are not named in the
            // FavoriteListFeatures collection.

            if (FeaturesForm.CopyFavoritesOnly)
            {
                if ((! DisplayFindPattern) && (! DisplayReplacePattern))
                {
                    FilterFeatures(oSyntaxBranchToCopy,
                        FeaturesForm.FavoriteListFeatures);
                }
            }

            //**************************************************************
            // Create a RuleWriter that writes to a string.

            StringBuilder oStringBuilder = new StringBuilder();
            TextWriter oTextWriter = new StringWriter(oStringBuilder);
            RuleWriter oRuleWriter = new RuleWriter(oTextWriter);

            //**************************************************************
            // Make a rule that uses the indicated branch as its find
            // pattern (and has an empty replace pattern).

            oRuleWriter.RuleName = "(tree fragment on clipboard)";
            oRuleWriter.FindPatternRoot = oSyntaxBranchToCopy;
            oRuleWriter.ReplacePatternRoot = null;

            //**************************************************************
            // Write the rule to the string.

            oRuleWriter.Write();

            //**************************************************************
            // Close the RuleWriter.

            oRuleWriter.Close();

            //**************************************************************
            // Copy the string to the clipboard.

            const bool bCopy = true;
            Clipboard.SetDataObject(oStringBuilder.ToString(),bCopy);
        }