/// <summary> /// 资源树的右键事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnTreeListPopMenuShow(object sender, PopupMenuShowingEventArgs e) { TreeList tree = sender as TreeList; TreeListHitInfo treeListHitInfo = tree.CalcHitInfo(e.Point); if (treeListHitInfo.HitInfoType == HitInfoType.Cell) { tree.SetFocusedNode(treeListHitInfo.Node); } if (tree.FocusedNode != null) { var item = navigationTreeList.GetRow(tree.FocusedNode.Id); if (item is ResourceItem) { ResourceItem _item = item as ResourceItem; popupMenu1.ClearLinks(); IResource resource = _item.Resource; if (resource.ResourceMetaData != null && resource.ResourceMetaData.ContextActionTypes != null && resource.ResourceMetaData.ContextActionTypes.Count > 0) { foreach (Type itemActionType in resource.ResourceMetaData.ContextActionTypes) { IContextMenuItemAction contextMenuItemAction = IocManager.Instance.Resolve(itemActionType) as IContextMenuItemAction; if (contextMenuItemAction.IsSplitor) { var link = popupMenu1.AddItem(new BarLargeButtonItem()); link.BeginGroup = true; } else { contextMenuItemAction.Sender = resource; var buttonItem = new DevExpress.XtraBars.BarButtonItem(this.barManager1, contextMenuItemAction.Caption); buttonItem.ImageOptions.Image = contextMenuItemAction.ItemIcon; buttonItem.ItemClick += (itemSender, ee) => { contextMenuItemAction.Excute(); }; popupMenu1.AddItem( buttonItem ); } } Point p = new Point(Cursor.Position.X, Cursor.Position.Y); popupMenu1.ShowPopup(p); } } else if (item is DirectoryItem) { popupMenu1.ClearLinks(); var barbutton = new DevExpress.XtraBars.BarButtonItem(this.barManager1, "打开资源文件目录"); barbutton.ImageOptions.Image = AssemblyResource.GetResourceImage(Assembly.GetExecutingAssembly(), "ZtgeoGISDesktop.Icons.ResourceManager16.png"); barbutton.ItemClick += (itemSender, ee) => { System.Diagnostics.Process.Start("explorer.exe", ((DirectoryItem)item).FullName); }; var barbutton2 = new DevExpress.XtraBars.BarButtonItem(this.barManager1, "刷新"); barbutton2.ImageOptions.Image = AssemblyResource.GetResourceImage(Assembly.GetExecutingAssembly(), "ZtgeoGISDesktop.Icons.Refesh16.png"); barbutton2.ItemClick += (itemSender, ee) => { //tree.FocusedNode.Collapse(); //tree.FocusedNode.HasChildren = true; //tree.RefreshNode(tree.FocusedNode); tree.RefreshDataSource(); }; popupMenu1.AddItem(barbutton); popupMenu1.AddItem(barbutton2); Point p = new Point(Cursor.Position.X, Cursor.Position.Y); popupMenu1.ShowPopup(p); } else if (item is FileItem) { } } }