Esempio n. 1
0
		// 显示值列表
		public void ShowValueList(
            int nCaretPosition,
            int nLineChars,
            string strCurLine)
		{
			this.Update();

			if (this.nCurLine == -1)
				return;

            if (this.m_nInShowValueList > 0)
            {
                // TODO: 是否Post一个消息出去,稍后再作?
                return;
            }


            this.m_nInShowValueList++;
            try
            {
                string strError = "";

                TemplateLine line = (TemplateLine)this.templateRoot.Lines[this.nCurLine];
                if (line == null)
                {
                    strError = "未找到序号为'" + Convert.ToString(this.nCurLine) + "'行";
                    return;
                }

                int nValueChars = 0;    // 值的字符数

                if (line.ValueListNodes == null
                    || line.ValueListNodes.Count == 0)
                {
                    this.listView_values.Items.Clear();
                    return;
                }

                Cursor oldCursor = this.Cursor;
                this.Cursor = Cursors.WaitCursor;

                if (this.CurValueListNodes != null
                    && this.CurValueListNodes == line.ValueListNodes)
                {
                    if (this.listView_values.Items.Count > 0)
                    {
                        nValueChars = this.listView_values.Items[0].Text.Length;
                        goto SELECT; // 优化
                    }
                }

                this.listView_values.Items.Clear();

                // 解决ref
                while (true)
                {
                    bool bFoundNew = false;
                    for (int i = 0; i < line.ValueListNodes.Count; i++)
                    {
                        XmlNode valuelist_node = line.ValueListNodes[i];
                        string strRef = DomUtil.GetAttr(valuelist_node, "ref");
                        if (string.IsNullOrEmpty(strRef) == true)
                            continue;

                        {
                            if (this.GetConfigDom == null)
                                return;

                            GetConfigDomEventArgs ar = new GetConfigDomEventArgs();
                            ar.Path = strRef;
                            ar.XmlDocument = null;
                            this.GetConfigDom(this, ar);
                            if (string.IsNullOrEmpty(ar.ErrorInfo) == false)
                            {
                                strError = "获取 '" + line.m_strName + "' 对应的ValueList出错,原因:" + ar.ErrorInfo;
                                goto END1;
                            }
                            if (ar.XmlDocument == null)
                                return; // ??

                            string strSource = "";
                            string strValueListName = "";
                            int nIndex = strRef.IndexOf('#');
                            if (nIndex != -1)
                            {
                                strSource = strRef.Substring(0, nIndex);
                                strValueListName = strRef.Substring(nIndex + 1);
                            }
                            else
                            {
                                strValueListName = strRef;
                            }
                            XmlNode valueListNode = ar.XmlDocument.SelectSingleNode("//ValueList[@name='" + strValueListName + "']");
                            if (valueListNode == null)
                            {
                                strError = "未找到路径为'" + strRef + "'的节点。";
                                goto END1;
                            }

                            // 替换
                            line.ValueListNodes[i] = valueListNode;
                            bFoundNew = true;
                        }
                    }

                    if (bFoundNew == false)
                        break;
                }

                this.listView_values.Items.Clear(); // 2006/5/30 add

                foreach (XmlNode valuelist_node in line.ValueListNodes)
                {
                    XmlNodeList itemList = valuelist_node.SelectNodes("Item");
                    foreach (XmlNode itemNode in itemList)
                    {
                        string strItemLable = "";

                        // 从一个元素的下级的多个<strElementName>元素中, 提取语言符合的XmlNode的InnerText
                        // parameters:
                        //      bReturnFirstNode    如果找不到相关语言的,是否返回第一个<strElementName>
                        strItemLable = DomUtil.GetXmlLangedNodeText(
                    this.Lang,
                    itemNode,
                    "Label",
                    true);
                        if (string.IsNullOrEmpty(strItemLable) == true)
                            strItemLable = "<尚未定义>";
                        else
                            strItemLable = StringUtil.Trim(strItemLable);

#if NO
                        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());
                        nsmgr.AddNamespace("xml", Ns.xml);
                        XmlNode itemLabelNode = itemNode.SelectSingleNode("Label[@xml:lang='" + this.Lang + "']", nsmgr);
                        if (itemLabelNode == null
                            || string.IsNullOrEmpty(itemLabelNode.InnerText.Trim()) == true)
                        {
                            // 如果找不到,则找到第一个有值的
                            XmlNodeList nodes = itemNode.SelectNodes("Label", nsmgr);
                            foreach (XmlNode temp_node in nodes)
                            {
                                if (string.IsNullOrEmpty(temp_node.InnerText.Trim()) == false)
                                {
                                    itemLabelNode = temp_node;
                                    break;
                                }
                            }
                        }

                        if (itemLabelNode == null)
                            strItemLable = "<尚未定义>";
                        else
                            strItemLable = StringUtil.Trim(itemLabelNode.InnerText);
#endif


                        XmlNode itemValueNode = itemNode.SelectSingleNode("Value");
                        string strItemValue = StringUtil.Trim(itemValueNode.InnerText);

                        if (String.IsNullOrEmpty(strItemValue) == false)
                        {
                            nValueChars = strItemValue.Length;
                        }

                        // 加入listview
                        ListViewItem item = new ListViewItem(strItemValue);
                        item.SubItems.Add(strItemLable);
                        this.listView_values.Items.Add(item);
                    }
                }

                this.CurValueListNodes = line.ValueListNodes;

            SELECT:

                // 加亮当前事项
                if (nValueChars != 0)
                {
                    // 算出当前插入符在第几个单元的值上
                    int nIndex = nCaretPosition / nValueChars;
                    if ((nIndex * nValueChars) + nValueChars <= strCurLine.Length)
                    {

                        string strCurUnit = strCurLine.Substring(nIndex * nValueChars, nValueChars);

                        // 在listview中找到这个值, 并选择它。
                        for (int i = 0; i < this.listView_values.Items.Count; i++)
                        {
                            if (this.listView_values.Items[i].Text.Replace("_", " ") == strCurUnit)
                            {
                                this.CurActiveValueUnit = strCurUnit;

                                this.listView_values.Items[i].Selected = true;
                                // 滚入视线内
                                this.listView_values.EnsureVisible(i);
                            }
                            else
                            {
                                if (this.listView_values.Items[i].Selected != false)
                                    this.listView_values.Items[i].Selected = false;
                            }
                        }
                    }

                }

            END1:
                /////////////////////////////////////
                // 触发EndGetValueList事件
                ///////////////////////////////////////
                EndGetValueListEventArgs argsEnd = new EndGetValueListEventArgs();
                if (strError != "")
                    argsEnd.Ref = strError;
                else
                    argsEnd.Ref = "";
                this.fireEndGetValueList(this, argsEnd);
                this.Cursor = oldCursor;
            }
            finally
            {
                this.m_nInShowValueList--;
            }
		}
Esempio n. 2
0
		public void fireEndGetValueList(object sender,
			EndGetValueListEventArgs args)
		{
			if (EndGetValueList != null)
			{
				this.EndGetValueList(sender,args);
			}
		}