Пример #1
0
        void m_genDataViewer_SetMenu(object sender, RefreshMenuEventArgs e)
        {
            if (e.Actions == null || this.m_detailHostObj == null)
            {
                return;
            }

            Type classType = m_detailHostObj.GetType();

            foreach (ScriptAction action in e.Actions)
            {
                string strFuncName = action.ScriptEntry + "_setMenu";
                if (string.IsNullOrEmpty(strFuncName) == true)
                {
                    continue;
                }

                DigitalPlatform.Script.SetMenuEventArgs e1 = new DigitalPlatform.Script.SetMenuEventArgs();
                e1.Action = action;
                e1.sender = e.sender;
                e1.e      = e.e;

                ScriptUtil.InvokeMember(classType,
                                        strFuncName,
                                        this.m_detailHostObj,
                                        new object[] { sender, e1 });
#if NO
                classType = m_detailHostObj.GetType();
                while (classType != null)
                {
                    try
                    {
                        // 有两个参数的成员函数
                        // 用 GetMember 先探索看看函数是否存在
                        MemberInfo [] infos = classType.GetMember(strFuncName,
                                                                  BindingFlags.DeclaredOnly |
                                                                  BindingFlags.Public | BindingFlags.NonPublic |
                                                                  BindingFlags.Instance | BindingFlags.InvokeMethod);
                        if (infos == null || infos.Length == 0)
                        {
                            classType = classType.BaseType;
                            if (classType == null)
                            {
                                break;
                            }
                            continue;
                        }

                        classType.InvokeMember(strFuncName,
                                               BindingFlags.DeclaredOnly |
                                               BindingFlags.Public | BindingFlags.NonPublic |
                                               BindingFlags.Instance | BindingFlags.InvokeMethod
                                               ,
                                               null,
                                               this.m_detailHostObj,
                                               new object[] { sender, e1 });
                        break;
                    }
                    catch (System.MissingMethodException /*ex*/)
                    {
                        classType = classType.BaseType;
                        if (classType == null)
                        {
                            break;
                        }
                    }
                }
#endif
            }
        }
Пример #2
0
        public void RefreshState()
        {
            if (this.SetMenu == null)
            {
                return;
            }

            RefreshMenuEventArgs e = new RefreshMenuEventArgs();

            e.Actions = this.Actions;
            e.sender  = this.sender;
            e.e       = this.e;

            this.SetMenu(this, e);

            DpRow first_selected_row = null;
            DpRow last_selected_row  = null;

            for (int i = 0; i < this.ActionTable.Rows.Count; i++)
            {
                DpRow row = this.ActionTable.Rows[i];

                if (row.Style == DpRowStyle.Seperator)
                {
                    continue;
                }

                ScriptAction action = (ScriptAction)row.Tag;
                if (action == null)
                {
                    Debug.Assert(false, "");
                    continue;
                }

                if (this.Actions.IndexOf(action) == -1)
                {
                    row.Selected = false;
                    continue;
                }

                if (row.Count == 0)
                {
                    continue;
                }

                Debug.Assert(row.Count >= 4, "");

                // 刷新一行
                row[0].Text = action.Name;
                string strText = "";
                if (action.ShortcutKey != (char)0)
                {
                    strText = new string(action.ShortcutKey, 1);
                    strText = strText.ToUpper();
                }
                row[1].Text = strText;
                row[2].Text = action.Comment;
                row[3].Text = action.ScriptEntry;

                row.Selected = action.Active;

                if (first_selected_row == null &&
                    row.Selected == true)
                {
                    first_selected_row = row;
                }
                if (row.Selected == true)
                {
                    last_selected_row = row;
                }
            }

            if (first_selected_row != null)
            {
                first_selected_row.EnsureVisible();
            }
            if (last_selected_row != null &&
                last_selected_row != first_selected_row)
            {
                last_selected_row.EnsureVisible();
            }
        }