Ejemplo n.º 1
0
        /// <summary>
        /// 获取指定名称的上下文菜单
        /// </summary>
        /// <param name="name">上下文菜单名称</param>
        /// <returns>返回正确的上下文菜单,如果不存在指定名称的上下文菜单则返回空的<see cref="PopupMenu"/>对象</returns>
        public object GetContentMenu(string name)
        {
            PopupMenu content = new PopupMenu();

            content.Manager = barManager;
            if (contents.ContainsKey(name))
            {
                AddInTree addInTree = workItem.Services.Get <AddInTree>();
                if (addInTree != null)
                {
                    try
                    {
                        AddInNode addInNode = addInTree.GetChild(name);
                        if (addInNode != null)
                        {
                            addInNode.BuildChildItems(this);
                        }
                    }
                    catch (Exception ex) {
                        throw new UniframeworkException(String.Format("无法创建指定路径 \"{0} \" 的插件单元,{1}", name, ex.Message));
                    }
                }
            }

            if (contents.ContainsKey(name))
            {
                foreach (BarItemLink link in contents[name].ItemLinks)
                {
                    BarItemLink barlink = content.AddItem(link.Item);
                    barlink.BeginGroup = link.BeginGroup;
                }
            }

            return(content);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 查找指定路径的插件节点
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="throwOnNotFound">未找到是否触发异常</param>
        /// <returns>返回找到的插件节点</returns>
        public AddInNode GetChild(string path, bool throwOnNotFound)
        {
            if (path == null || path.Length == 0)
            {
                return(rootNode);
            }
            string[]  splittedPath = path.Split('/');
            AddInNode curPath      = rootNode;
            int       i            = 0;

            while (i < splittedPath.Length)
            {
                if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath))
                {
                    if (throwOnNotFound)
                    {
                        throw new AddInException(String.Format("不存在路径为 \"{0}\" 的插件节点。", path));
                    }
                    else
                    {
                        return(null);
                    }
                }
                ++i;
            }
            return(curPath);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建指定路径下的插件节点
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="caller">调用者</param>
        /// <returns>返回创建的插件节点</returns>
        public object BuildItem(object caller, string path)
        {
            int       pos    = path.LastIndexOf('/');
            string    parent = path.Substring(0, pos);
            string    child  = path.Substring(pos + 1);
            AddInNode node   = GetChild(parent);

            return(node.BuildChildItem(child, caller, BuildItems(caller, path, false)));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 向插件树中加入扩展路径对象
        /// </summary>
        /// <param name="path">扩展路径</param>
        private void AddExtensionPath(ExtensionPath path)
        {
            AddInNode treePath = CreatePath(rootNode, path.Name);

            treePath.Path  = path.Name;
            treePath.Label = path.Label;
            foreach (AddInElement element in path.AddInElements)
            {
                treePath.AddInElements.Add(element);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 创建指定路径下的插件节点
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="caller">调用者</param>
        /// <param name="throwOnNotFound">如果为true,当未找到指定路径的节点时将抛出异常</param>
        public List <T> BuildItems <T>(object caller, string path, bool throwOnNotFound)
        {
            AddInNode node = GetChild(path, throwOnNotFound);

            if (node == null)
            {
                return(new List <T>());
            }
            else
            {
                return(node.BuildChildItems <T>(caller));
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 创建指定路径下的插件节点列表
        /// </summary>
        /// <param name="path">路径</param>
        /// <param name="caller">调用者</param>
        /// <param name="throwOnNotFound">未找到是否触发异常</param>
        /// <returns>返回创建的插件节点列表</returns>
        public ArrayList BuildItems(object caller, string path, bool throwOnNotFound)
        {
            AddInNode node = GetChild(path, throwOnNotFound);

            if (node == null)
            {
                return(new ArrayList());
            }
            else
            {
                return(node.BuildChildItems(caller));
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 检查是否存在指定路径的插件节点
        /// </summary>
        /// <param name="path">路径</param>
        /// <returns>如果存在返回true,否则返回false</returns>
        public bool Exists(string path)
        {
            if (path == null || path.Length == 0)
            {
                return(true);
            }

            string[]  splittedPath = path.Split('/');
            AddInNode curPath      = rootNode;
            int       i            = 0;

            while (i < splittedPath.Length)
            {
                // curPath = curPath.ChildNodes[splittedPath[i]] - check if child path exists
                if (!curPath.ChildNodes.TryGetValue(splittedPath[i], out curPath))
                {
                    return(false);
                }
                ++i;
            }
            return(true);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 以指定节点为根路径创建插件节点
        /// </summary>
        /// <param name="localRoot">根节点</param>
        /// <param name="path">路径</param>
        /// <returns>创建好的插件节点</returns>
        private AddInNode CreatePath(AddInNode localRoot, string path)
        {
            if (path == null || path.Length == 0)
            {
                return(localRoot);
            }

            string[]  splittedPath = path.Split('/');
            AddInNode curPath      = localRoot;
            int       i            = 0;

            while (i < splittedPath.Length)
            {
                if (!curPath.ChildNodes.ContainsKey(splittedPath[i]))
                {
                    curPath.ChildNodes[splittedPath[i]] = new AddInNode();
                }
                curPath = curPath.ChildNodes[splittedPath[i]];
                ++i;
            }

            return(curPath);
        }