Exemplo n.º 1
0
        protected void CheckForLimitation(TreeNode node, ref string strXPath, XPathNavigator navigator,
                                          XmlNamespaceManager manager)
        {
            // make sure it has something in common with the path we're going to work on (otherwise
            //  such a filter makes no sense)
            string strLimitXPath     = GetXPath(node);
            int    nIndexOfLastSlash = IndexOfFirstDifference(strXPath, strLimitXPath);

            // under certain conditions, we want to skip to the last element:
            //  1) if the given strXPath contains a constraint already (we want that included; not consider a diff
            //  2) if the two XPath expressions are identical (in which case, the user is filtering on the item they
            //      want...)
            if ((strXPath.Length > nIndexOfLastSlash) && (strXPath[nIndexOfLastSlash] != '[') ||
                (strXPath == strLimitXPath))
            {
                nIndexOfLastSlash = strLimitXPath.LastIndexOf('/', nIndexOfLastSlash - 1);
            }
            if (nIndexOfLastSlash > 0)
            {
                XPathNodeIterator xpIterator = null;
                if (manager != null)
                {
                    xpIterator = navigator.Select(strLimitXPath, manager);
                }
                else
                {
                    xpIterator = navigator.Select(strLimitXPath);
                }

                // ask the user what they want to do
                string strXPathRoot = strLimitXPath.Substring(0, nIndexOfLastSlash);
                string strName      = (strLimitXPath.Length > nIndexOfLastSlash) ? strLimitXPath.Substring(nIndexOfLastSlash + 1)
                    : null;
                CreateLimitationForm dlg = new CreateLimitationForm(strXPathRoot, strName, xpIterator,
                                                                    IsAttribute(node), Properties.Settings.Default.RecentFilters);
                DialogResult res = dlg.ShowDialog();
                if (res == DialogResult.OK)
                {
                    string strFilter         = dlg.FilterXPath;
                    string strLastConstraint = strFilter + strXPath.Substring(nIndexOfLastSlash);
                    Program.AddRecentXPathExpression(strLastConstraint);
                    strXPath = strLastConstraint;
                }
                else if (res == DialogResult.Cancel)
                {
                    throw new ApplicationException(cstrCaption);
                }
            }
        }
Exemplo n.º 2
0
		protected void CheckForLimitation(TreeNode node, ref string strXPath, XPathNavigator navigator,
			XmlNamespaceManager manager)
		{
			// make sure it has something in common with the path we're going to work on (otherwise
			//  such a filter makes no sense)
			string strLimitXPath = GetXPath(node);
			int nIndexOfLastSlash = IndexOfFirstDifference(strXPath, strLimitXPath);

			// under certain conditions, we want to skip to the last element:
			//  1) if the given strXPath contains a constraint already (we want that included; not consider a diff
			//  2) if the two XPath expressions are identical (in which case, the user is filtering on the item they
			//      want...)
			if ((strXPath.Length > nIndexOfLastSlash) && (strXPath[nIndexOfLastSlash] != '[')
				|| (strXPath == strLimitXPath))
				nIndexOfLastSlash = strLimitXPath.LastIndexOf('/', nIndexOfLastSlash - 1);
			if (nIndexOfLastSlash > 0)
			{
				XPathNodeIterator xpIterator = null;
				if (manager != null)
					xpIterator = navigator.Select(strLimitXPath, manager);
				else
					xpIterator = navigator.Select(strLimitXPath);

				// ask the user what they want to do
				string strXPathRoot = strLimitXPath.Substring(0, nIndexOfLastSlash);
				string strName = (strLimitXPath.Length > nIndexOfLastSlash) ? strLimitXPath.Substring(nIndexOfLastSlash + 1)
					: null;
				CreateLimitationForm dlg = new CreateLimitationForm(strXPathRoot, strName, xpIterator,
					IsAttribute(node), Properties.Settings.Default.RecentFilters);
				DialogResult res = dlg.ShowDialog();
				if (res == DialogResult.OK)
				{
					string strFilter = dlg.FilterXPath;
					string strLastConstraint = strFilter + strXPath.Substring(nIndexOfLastSlash);
					Program.AddRecentXPathExpression(strLastConstraint);
					strXPath = strLastConstraint;
				}
				else if (res == DialogResult.Cancel)
					throw new ApplicationException(cstrCaption);
			}
		}