/// ------------------------------------------------------------------------------------
        /// <summary>
        /// Save the new find phone category name.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnAfterLabelEdit(NodeLabelEditEventArgs e)
        {
            // There's nothing to do if the node's text didn't change.
            if (e.Label != null && e.Node.Text != e.Label)
            {
                e.CancelEdit = !(e.Node.Level == 0 ?
                                 VerifyCategoryRename(e.Node, e.Label) : VerifyQueryRename(e.Node, e.Label));

                if (!e.CancelEdit)
                {
                    if (e.Node.Tag is SearchQueryGroup)
                    {
                        AfterCategoryEdited(e.Node, e.Label);
                    }
                    else if (e.Node.Tag is SearchQuery)
                    {
                        AfterQueryNameEdited(e.Node.Tag as SearchQuery, e.Label);
                    }
                }
            }

            if (m_slidingPanel != null)
            {
                m_slidingPanel.Freeze = false;
                m_slidingPanel        = null;
            }

            base.OnAfterLabelEdit(e);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a new category to the database and the tree. If the sliding panel is not
        /// null then it must be frozen until editing the category name is finished.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void AddCategory(SlidingPanel slidingPanel, bool beginEditAfterAdding)
        {
            var msg = LocalizationManager.GetString(
                "Views.Search.SavedSearchPatterns.NewSavedPatternCategoryName",
                "New Category",
                "This is the default name given to new categories in the saved search pattern tree in search view.");

            AddCategory(msg, slidingPanel, beginEditAfterAdding);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Adds a new category to the database and the tree. If the sliding panel is not
        /// null then it must be frozen until editing the category name is finished.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void AddCategory(string newCategoryName, SlidingPanel slidingPanel,
                                bool beginEditAfterAdding)
        {
            // Make sure the category name is unique.
            int i       = 0;
            var newName = newCategoryName;

            while (CategoryExists(newName))
            {
                newName = string.Format("{0} ({1})", newCategoryName, ++i);
            }

            newCategoryName = newName;

            var group = new SearchQueryGroup();

            group.Name = newCategoryName;
            App.Project.SearchQueryGroups.Add(group);
            App.Project.SearchQueryGroups.Save();

            // Hide the label that tells the user there are no saved patterns
            // because we know there is at least one category now.
            m_lblNoPatternsMsg.Visible = false;

            // Now add the category to the tree, select it and put user in edit mode.
            var node = Nodes.Add(newCategoryName);

            node.Tag     = group;
            SelectedNode = node;

            if (!beginEditAfterAdding)
            {
                return;
            }

            node.BeginEdit();
            if (slidingPanel != null)
            {
                m_slidingPanel      = slidingPanel;
                slidingPanel.Freeze = true;
            }
        }