示例#1
0
        private void _cxtmTMTreeView_Opening(object sender, CancelEventArgs e)
        {
            TreeNode selectNode = this._treeViewFileSystem.SelectedNode;

            if (selectNode == _treeViewFileSystem.Nodes[0])
            {
                _cxtmTMTreeView.Items.Clear();
                ToolStripMenuItem menu = new ToolStripMenuItem(Global.Languages["Project/FileSystem/CM"]["Add Special Folder"]);

                foreach (LURootFolderType specFolder in Enum.GetValues(typeof(LURootFolderType)))
                {
                    TMSpecFolderMenuItem menuItem = new TMSpecFolderMenuItem(specFolder, TMContextMenuAction.AddSpecFolder, new EventHandler(tvCMMenuItem_Click));
                    menu.DropDownItems.Add(menuItem);
                    foreach (TreeNode node in this._treeViewFileSystem.Nodes[0].Nodes)
                    {
                        TMRootFolderNode rnode = node as TMRootFolderNode;
                        if ((rnode.Folder as TMRootFolder).RootFolderType == specFolder)
                        {
                            menuItem.Enabled = false;
                            break;
                        }
                    }
                }
                _cxtmTMTreeView.Items.Add(menu);
            }
            else if (selectNode is TMFolderNode)
            {
                _cxtmTMTreeView.Items.Clear();

                ToolStripMenuItem menuAdd = new ToolStripMenuItem(Global.Languages["Project/FileSystem/CM"]["Add"]);
                menuAdd.DropDownItems.AddRange(new ToolStripItem[] {
                    new TMContextMenuItem(TMContextMenuAction.AddFolder, new EventHandler(this.tvCMMenuItem_Click)),
                    new TMContextMenuItem(TMContextMenuAction.AddFile, new EventHandler(this.tvCMMenuItem_Click))
                });

                ToolStripMenuItem menuRename = new TMContextMenuItem(TMContextMenuAction.Rename, new EventHandler(this.tvCMMenuItem_Click));

                menuRename.Enabled = !(this._treeViewFileSystem.SelectedNode is TMRootFolderNode);

                _cxtmTMTreeView.Items.AddRange(new ToolStripItem[] {
                    menuAdd,
                    //menuRename,
                    new TMContextMenuItem(TMContextMenuAction.Delete, new EventHandler(this.tvCMMenuItem_Click))
                });
            }
            else
            {
                e.Cancel = true;
            }
        }
示例#2
0
        private void tvCMMenuItem_Click(object sender, EventArgs e)
        {
            if (sender is TMSpecFolderMenuItem)
            {
                TMSpecFolderMenuItem menuItem   = sender as TMSpecFolderMenuItem;
                TMRootFolder         rootFolder = new TMRootFolder(menuItem.SpecialFolder);

                _project.FileSystem.Add(rootFolder);
                _treeViewFileSystem.Nodes[0].Nodes.Add(new TMRootFolderNode(rootFolder));
                this.OnDataChanged();
            }
            else if (sender is TMContextMenuItem)
            {
                TMContextMenuItem menuItem   = sender as TMContextMenuItem;
                TMFolderNode      folderNode = this._treeViewFileSystem.SelectedNode as TMFolderNode;
                if (folderNode == null || menuItem == null)
                {
                    return;
                }

                switch (menuItem.Action)
                {
                case TMContextMenuAction.Delete:
                    this.DeleteFolder(folderNode);
                    break;

                case TMContextMenuAction.AddFile:
                    this.AddFile(folderNode.Folder);
                    break;

                case TMContextMenuAction.AddFolder:
                    this.AddFolder(folderNode);
                    break;
                }
            }
        }