public void SetItemEnabledState( ToolStripMenuItem contentsCutQuery, ToolStripMenuItem contentsCopyQuery, ToolStripMenuItem contentsDeleteQuery, ToolStripMenuItem contentsRenameQuery) { foreach (TreeListNode node in ContentsTreeCtl.TreeList.Selection) { // if any node in the selection turns the menu to false, it stays false MetaTreeNode mtn = ContentsTreeCtl.GetMetaTreeNode(node); bool hasWriteAccess = Permissions.UserHasWriteAccess(SS.I.UserName, mtn.Target); if (contentsCutQuery.Enabled) { contentsCutQuery.Enabled = hasWriteAccess; } if (contentsDeleteQuery.Enabled) { contentsDeleteQuery.Enabled = hasWriteAccess; } if (contentsRenameQuery.Enabled) { contentsRenameQuery.Enabled = hasWriteAccess; } if (contentsCopyQuery.Enabled) { contentsCopyQuery.Enabled = (hasWriteAccess || (MetaTreeNode.IsUserObjectNodeType(mtn.Type) && !MetaTreeNode.IsLeafNodeType(mtn.Type))); } } }
public void SetItemEnabledState( ToolStripMenuItem contentsCutQuery, ToolStripMenuItem contentsCopyQuery, ToolStripMenuItem contentsDeleteQuery, ToolStripMenuItem contentsRenameQuery, ToolStripMenuItem contentsAddQuery) { // set all to true or they will never be tested below contentsCutQuery.Enabled = contentsDeleteQuery.Enabled = contentsDeleteQuery.Enabled = contentsRenameQuery.Enabled = contentsCopyQuery.Enabled = contentsAddQuery.Enabled = true; foreach (TreeListNode node in QbContentsTreeCtl.TreeList.Selection) { // if any node in the selection turns the menu to false, it stays false MetaTreeNode mtn = QbContentsTreeCtl.GetMetaTreeNode(node); bool hasWriteAccess = Permissions.UserHasWriteAccess(SS.I.UserName, mtn.Target); if (contentsCutQuery.Enabled) { contentsCutQuery.Enabled = hasWriteAccess; } if (contentsDeleteQuery.Enabled) { contentsDeleteQuery.Enabled = hasWriteAccess; } if (contentsRenameQuery.Enabled) { contentsRenameQuery.Enabled = hasWriteAccess; } if (contentsCopyQuery.Enabled) { contentsCopyQuery.Enabled = hasWriteAccess || (MetaTreeNode.IsUserObjectNodeType(mtn.Type) && !MetaTreeNode.IsLeafNodeType(mtn.Type)); } if (contentsAddQuery.Enabled) { contentsAddQuery.Enabled = mtn.Type == MetaTreeNodeType.MetaTable || mtn.Type == MetaTreeNodeType.Annotation || mtn.Type == MetaTreeNodeType.CalcField; } } }
private void ContentsTree_Click(object sender, EventArgs e) { MouseEventArgs me = e as MouseEventArgs; if (me == null) { return; } TreeListHitInfo hi = QbContentsTreeCtl.TreeList.CalcHitInfo(me.Location); if (hi == null || hi.Node == null) { QbContentsTreeCtl.TreeList.OptionsSelection.MultiSelect = false; return; } MetaTreeNode currentNode = QbContentsTreeCtl.GetMetaTreeNode(hi.Node); if (currentNode == null) { return; } if (string.IsNullOrEmpty(currentNode.Target)) { DisableMultiselect(hi.Node); return; } // support multiple selections until we find otherwise QbContentsTreeCtl.TreeList.OptionsSelection.MultiSelect = true; CurrentContentsMetaTreeNodes = QbContentsTreeCtl.GetCurrentSelectedNodes(); if (CurrentContentsMetaTreeNodes.Count() > 1) { // process multiple nodes bool enabled = false; // If the user selected all Data Objects than we will allow muliselect if (MetaTreeNode.IsDataTableNodeType(currentNode.Type)) { foreach (MetaTreeNode node in CurrentContentsMetaTreeNodes) { if (node == currentNode) { break; } enabled = MetaTreeNode.IsDataTableNodeType(node.Type); if (!enabled) { break; } } } // If the Data Object check above failed, enable multiselect if we have all User Objects that are leafe nodes (no folders). if (!enabled && MetaTreeNode.IsUserObjectNodeType(currentNode.Type) && MetaTreeNode.IsLeafNodeType(currentNode.Type)) { foreach (MetaTreeNode node in CurrentContentsMetaTreeNodes) { if (node == currentNode) { break; } enabled = MetaTreeNode.IsUserObjectNodeType(node.Type) && MetaTreeNode.IsLeafNodeType(node.Type); if (!enabled) { break; } } } // Invalid combination of nodes, disable multiselect. if (!enabled) { DisableMultiselect(hi.Node); //MessageBox.Show("Multiselection is supported only for the following combinations\r\n\u2022 Lists, Queries, Annotation Tables, Calc Fields (Cut, Copy, Paste, Delete)\r\n\u2022 Data Tables, Anotation Tables, Calc Fields (Add to a Query)"); } } else { //process single node if ((currentNode.Type == MetaTreeNodeType.Url || currentNode.Type == MetaTreeNodeType.Action) && CurrentContentsTreeMouseDownEvent.Button != MouseButtons.Right) { ExecuteNodeAction(currentNode); // if url send command on 1st click } } }