Example #1
0
        /// <summary>
        /// 初始化 LeftMenu
        /// </summary>
        private void InitLeftMenu()
        {
            var allLeftMenus = _leftMenusManage.GetAll();

            _leftMenu = new LeftMenu(allLeftMenus);
            // 给每个组的根目录添加“根节点”选择
            _leftMenu.NavBarControlMain.Groups.ForEach(a =>
            {
                var leftMenusModel = new LeftMenus
                {
                    DisplayName   = Config.RootDisplayName,
                    NavBarGroupId = ((NavBarGroups)a.DataContext).Id
                };
                var treeViewItem = new TreeViewImgItem
                {
                    DataContext = leftMenusModel,
                    HeaderText  = leftMenusModel.DisplayName,
                };
                ((CTreeView)a.Items[0]).Items.Insert(0, treeViewItem);
                treeViewItem.Selected += LeftMenu_RootItemSelected;
            });

            _leftMenu.ParentItemSelected += LeftMenu_ParentItemSelected;
            _leftMenu.ChildItemSelected  += LeftMenu_ChildItemSelected;
            GridLeftMenu.Children.Add(_leftMenu);
        }
Example #2
0
        public void initProjectTree()
        {
            String projectPath = txbProjectPath.Text;

            if (projectPath == "")
            {
                return;
            }

            Hashtable nodesHash = new Hashtable();

            trvProject.Items.Clear();

            DirectoryInfo   di   = new DirectoryInfo(projectPath);
            TreeViewImgItem node = new TreeViewImgItem(NODE_PROJECT);

            node.Text          = di.Name;
            node.SelectedImage = _projectIcon;
            node.IsExpanded    = true;

            trvProject.Items.Add(node);
            nodesHash.Add("", node);

            scanProjectTree(node, di);
        }
Example #3
0
        public TreeViewImgItem GenerateTreeViewItem(LeftMenus leftMenusModel)
        {
            var treeViewItem = new TreeViewImgItem
            {
                HeaderText  = leftMenusModel.DisplayName,
                DataContext = leftMenusModel
            };

            InitSelectedAndIco(treeViewItem, 0);

            return(treeViewItem);
        }
Example #4
0
 /// <summary>
 /// 向节点添加图片
 /// </summary>
 /// <param name="fileType"></param>
 /// <param name="item"></param>
 private static void AddImage(FileTypeEnum fileType, TreeViewImgItem item)
 {
     if (fileType == FileTypeEnum.Directory)
     {
         item.DefaultImageSource  = new BitmapImage(new Uri("pack://application:,,,/Frame.SysWindows;component/Resources/Open_16x16.png"));
         item.ExpandedImageSource = new BitmapImage(new Uri("pack://application:,,,/Frame.SysWindows;component/Resources/Article_16x16.png"));
     }
     else
     {
         item.DefaultImageSource  = new BitmapImage(new Uri("pack://application:,,,/Frame.SysWindows;component/Resources/New_16x16.png"));
         item.ExpandedImageSource = item.DefaultImageSource;
     }
 }
Example #5
0
 public void InitSelectedAndIco(TreeViewImgItem item, int itemsCount)
 {
     if (itemsCount == 0)
     {
         SetChildItemIco(item);
         item.Selected += (sender, e) => ChildItemSelected?.Invoke((TreeViewItem)sender, e);
     }
     else
     {
         SetParentItemIco(item);
         item.Selected += (sender, e) => ParentItemSelected?.Invoke((TreeViewItem)sender, e);
     }
 }
Example #6
0
        public CTreeView(int navBarGroupId, List <LeftMenus> leftMenusList)
        {
            var leftMenuList = leftMenusList.Where(b => b.NavBarGroupId == navBarGroupId && b.ParentId == 0).OrderBy(a => a.Sort).ToList();

            leftMenuList.ForEach(b => {
                var item = new TreeViewImgItem {
                    HeaderText = b.DisplayName, DataContext = b
                };

                Items.Add(item);
                ForeachTreeViewItem(leftMenusList, item, b.Id);
            });
        }
Example #7
0
        /// <summary>
        /// 子节点递归显示
        /// </summary>
        /// <param name="menuList"></param>
        /// <param name="item"></param>
        /// <param name="parentId"></param>
        private void ForeachTreeViewItem(List <LeftMenus> menuList, TreeViewImgItem item, int parentId)
        {
            var list = menuList.Where(a => a.ParentId == parentId).OrderBy(a => a.Sort).ToList();

            InitSelectedAndIco(item, list.Count);

            list.ForEach(a => {
                var newItem = new TreeViewImgItem {
                    HeaderText = a.DisplayName, DataContext = a
                };
                item.Items.Add(newItem);
                ForeachTreeViewItem(menuList, newItem, a.Id);
            });
        }
Example #8
0
        /// <summary>
        /// 添加节点
        /// </summary>
        /// <param name="treeItem"></param>
        /// <param name="list"></param>
        /// <param name="parentId"></param>
        private static void TvAddItems(TreeViewImgItem treeItem, List <FilePathSelTreeView> list, Guid parentId)
        {
            var items = list.Where(a => a.ParentId == parentId).ToList();

            foreach (var myClass in items)
            {
                var item = new TreeViewImgItem
                {
                    HeaderText  = myClass.FileName,
                    DataContext = myClass
                };
                AddImage(myClass.FileType, item);
                treeItem.Items.Add(item);
                TvAddItems(item, list, myClass.Id);
            }
        }
Example #9
0
        private void _AddTrashBox(RssTargetInfo targetInfo)
        {
            TrashBox trashBox = targetInfo.TrashBox;

            _trashBoxes.Add(trashBox);

            TreeViewImgItem targetNode = new TreeViewImgItem(TRASH_NODE_TARGET);

            targetNode.Text          = targetInfo.Title;
            targetNode.SelectedImage = (targetInfo.IsZeptDist) ? _zeptairIcon : _feedIcon;
            targetNode.IsExpanded    = true;

            ArrayList channels = new ArrayList();

            foreach (InfoItem infoItem in trashBox.InfoItems)
            {
                if (!channels.Contains(infoItem.Channel))
                {
                    channels.Add(infoItem.Channel);
                }
            }

            Hashtable channelHash = new Hashtable();

            foreach (string channel in channels)
            {
                TreeViewImgItem channelNode = new TreeViewImgItem(TRASH_NODE_CHANNEL);
                channelNode.Text          = channel;
                channelNode.SelectedImage = _channelIcon;
                channelNode.IsExpanded    = false;

                channelHash[channel] = channelNode;
                targetNode.Items.Add(channelNode);
            }

            foreach (InfoItem infoItem in trashBox.InfoItems)
            {
                TreeViewImgItem itemNode = new TreeViewImgItem(TRASH_NODE_ITEM);
                itemNode.Text           = infoItem.Title;
                itemNode.SelectedImage  = _itemIcon;
                itemNode.AdditionalInfo = infoItem;

                ((TreeViewImgItem)channelHash[infoItem.Channel]).Items.Add(itemNode);
            }
            trvTrash.Items.Add(targetNode);
        }
Example #10
0
        private void AddTreeViewItem(CTreeView treeView, ItemCollection items, TreeViewImgItem selectedItem, LeftMenus leftMenus)
        {
            if (leftMenus.ParentId == 0)
            {
                treeView.Items.Add(GetSelectedTreeView().GenerateTreeViewItem(selectedItem));
                selectedItem.IsSelected = true;
                return;
            }

            foreach (var i in items)
            {
                var item = (TreeViewImgItem)i;
                if (((LeftMenus)item.DataContext).Id == leftMenus.ParentId)
                {
                    var treeViewMain = GetSelectedTreeView();
                    item.Items.Add(treeViewMain.GenerateTreeViewItem(selectedItem));
                    selectedItem.IsSelected = true;
                    item.IsExpanded         = true;

                    var requestModel = new LeftMenusUpdateSortRequestModel
                    {
                        DisplayName = leftMenus.DisplayName,
                        Sort        = int.MaxValue,
                        Timestamp   = _leftMenusManage.ServerTime.ToUnixTimestamp()
                    };
                    var result = _leftMenusManage.UpdateSort(leftMenus.Id, Timestamp, requestModel);
                    if (result.ResultStatus == ResultStatus.Success)
                    {
                        leftMenus.DisplayName = result.Data.DisplayName;
                        leftMenus.Sort        = result.Data.Sort;
                        leftMenus.Timestamp   = result.Data.Timestamp;
                    }
                    else
                    {
                        _metroWindow.ShowMessageAsync("更新节点排序失败", result.Message);
                    }
                    break;
                }

                if (item.HasItems)
                {
                    AddTreeViewItem(treeView, item.Items, selectedItem, leftMenus);
                }
            }
        }
Example #11
0
        public static void TreeViewAddItems(TreeView tv, string rootPath, params string[] filExtension)
        {
            var list = GetAllFiles(rootPath, filExtension, new Guid(), null);

            var rootes = list.Where(a => a.ParentId == new Guid()).ToList();

            rootes.ForEach(a =>
            {
                var root = new TreeViewImgItem
                {
                    HeaderText  = a.FileName,
                    DataContext = a
                };
                AddImage(a.FileType, root);
                tv.Items.Add(root);
                TvAddItems(root, list, a.Id);
            });
        }
Example #12
0
        /// <summary>
        /// 根据原有的 TreeViewItem 生成一个新的 TreeViewItem,其中也包括了事件
        /// </summary>
        /// <param name="oldItem"></param>
        /// <returns></returns>
        public TreeViewImgItem GenerateTreeViewItem(TreeViewImgItem oldItem)
        {
            var leftMenuModel = (LeftMenus)oldItem.DataContext;
            var item          = new TreeViewImgItem
            {
                HeaderText  = leftMenuModel.DisplayName,
                DataContext = leftMenuModel
            };

            for (var i = 0; i < oldItem.Items.Count; i++)
            {
                var old = oldItem.Items[i];
                oldItem.Items.Remove(old);
                item.Items.Add(old);

                --i;
            }
            item.IsExpanded = oldItem.IsExpanded;

            InitSelectedAndIco(item, item.Items.Count);

            return(item);
        }
Example #13
0
        /// <summary>Click event handler of the Trash Delete button.</summary>
        /// <param name="sender">Sender Object.</param>
        /// <param name="e">Event parameters.</param>
        private void btnTrashDelete_Click(object sender, RoutedEventArgs e)
        {
            TreeViewImgItem selItem = (TreeViewImgItem)trvTrash.SelectedItem;

            if (selItem == null)
            {
                return;
            }

            string selTitle = selItem.Text;

            if (selTitle.Length > 20)
            {
                selTitle = selTitle.Substring(0, 20) + " ...";
            }

            string msg = null;

            if (selItem.Type == TRASH_NODE_ITEM)
            {
                msg = "\"" + selTitle + "\"" + Properties.Resources.CONFIRM_COMPLETELY_DELETE;
            }
            else
            {
                msg = Properties.Resources.CONFIRM_COMPLETELY_ALL_DELETE_1 + "\"" + selTitle + "\"" + Properties.Resources.CONFIRM_COMPLETELY_ALL_DELETE_2;
            }

            System.Windows.Forms.DialogResult ret =
                System.Windows.Forms.MessageBox.Show(
                    msg,
                    this.Title,
                    System.Windows.Forms.MessageBoxButtons.OKCancel,
                    System.Windows.Forms.MessageBoxIcon.Question
                    );
            if (ret == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    ThetisCore.Lib.IIpcTaskService ipcTaskService = ThetisCore.Lib.IpcServiceAgent.GetTaskService();
                    if (ipcTaskService == null)
                    {
                        return;
                    }

                    if (selItem.Type == TRASH_NODE_ITEM)
                    {
                        InfoItem infoItem = (InfoItem)selItem.AdditionalInfo;
                        ipcTaskService.BurnUpTrash(infoItem.GeneratorId, new int[1] {
                            infoItem.Id
                        });

                        ((TreeViewImgItem)selItem.Parent).Items.Remove(selItem);
                    }
                    else if (selItem.Type == TRASH_NODE_CHANNEL)
                    {
                        if (selItem.Items.Count <= 0)
                        {
                            return;
                        }

                        string generatorId = null;
                        int[]  itemIds     = new int[selItem.Items.Count];

                        for (int i = 0; i < selItem.Items.Count; i++)
                        {
                            InfoItem infoItem = (InfoItem)((TreeViewImgItem)selItem.Items[i]).AdditionalInfo;
                            generatorId = infoItem.GeneratorId;
                            itemIds[i]  = infoItem.Id;
                        }
                        selItem.Items.Clear();

                        ipcTaskService.BurnUpTrash(generatorId, itemIds);
                    }
                    else if (selItem.Type == TRASH_NODE_TARGET)
                    {
                        foreach (TreeViewImgItem channel in selItem.Items)
                        {
                            if (channel.Items.Count <= 0)
                            {
                                continue;
                            }

                            string generatorId = null;
                            int[]  itemIds     = new int[channel.Items.Count];

                            for (int i = 0; i < channel.Items.Count; i++)
                            {
                                InfoItem infoItem = (InfoItem)((TreeViewImgItem)channel.Items[i]).AdditionalInfo;
                                generatorId = infoItem.GeneratorId;
                                itemIds[i]  = infoItem.Id;
                            }
                            channel.Items.Clear();

                            ipcTaskService.BurnUpTrash(generatorId, itemIds);
                        }
                    }
                }
                catch (System.Runtime.Remoting.RemotingException ex)
                {
                    Log.AddError(ex.Message + "\n" + ex.StackTrace);
                }
            }
        }
Example #14
0
        private void scanProjectTree(TreeViewImgItem parentNode, DirectoryInfo parentDi)
        {
            try
            {
                foreach (DirectoryInfo di in parentDi.GetDirectories())
                {
                    if (chkProjectDispAll.IsChecked != true)
                    {
                        if (di.Name.StartsWith(".") ||
                            di.Name.Equals("node_modules"))
                        {
                            continue;
                        }
                    }
                    TreeViewImgItem folderNode = new TreeViewImgItem(NODE_FOLDER);
                    folderNode.Text          = di.Name;
                    folderNode.SelectedImage = _folderIcon;

                    if (di.Name.Equals("src") || parentDi.Name.Equals("src"))
                    {
                        folderNode.IsExpanded = true;
                    }
                    else
                    {
                        folderNode.IsExpanded = false;
                    }

                    parentNode.Items.Add(folderNode);
                    scanProjectTree(folderNode, di);
                }

                foreach (FileInfo fi in parentDi.EnumerateFiles())
                {
                    if (chkProjectDispAll.IsChecked != true)
                    {
                        if (fi.Name.StartsWith(".") ||
                            fi.Name.Contains(".spec."))
                        {
                            continue;
                        }
                    }
                    TreeViewImgItem fileNode = new TreeViewImgItem(NODE_FILE);
                    fileNode.Text = fi.Name;
                    if (fi.Name.Contains(".module."))
                    {
                        fileNode.SelectedImage = _moduleIcon;
                    }
                    else if (fi.Name.EndsWith(".ts"))
                    {
                        fileNode.SelectedImage = _itemIcon;
                    }
                    else
                    {
                        fileNode.SelectedImage = _fileIcon;
                    }
                    parentNode.Items.Add(fileNode);
                }
            }
            catch (IOException ie)
            {
                // TODO
            }
        }
Example #15
0
 /// <summary>
 /// 设置不含有Items的Item的ICO
 /// </summary>
 /// <param name="item"></param>
 public static void SetChildItemIco(TreeViewImgItem item)
 {
     item.DefaultImageSource  = new BitmapImage(new Uri("pack://application:,,,/Frame.Proxy;component/Resources/TreeViewItem.gif"));
     item.ExpandedImageSource = item.DefaultImageSource;
 }
Example #16
0
 /// <summary>
 /// 设置含有Items的Item的ICO
 /// </summary>
 /// <param name="item"></param>
 public static void SetParentItemIco(TreeViewImgItem item)
 {
     item.DefaultImageSource  = new BitmapImage(new Uri("pack://application:,,,/Frame.SysWindows;component/Resources/Open_16x16.png"));
     item.ExpandedImageSource = new BitmapImage(new Uri("pack://application:,,,/Frame.SysWindows;component/Resources/Open2_16x16.png"));
 }