/// <summary> /// Return true and set reason to empty string if the given browser /// node can be edited. Otherwise, return false and set the error /// reason with the error description. Handles both folder and workspace renaming. /// </summary> private bool CanEditTreeNode(KwsBrowserNode node, ref String reason) { // Logic statements are separated for clarity's sake. if (StaleBrowser || node == null) { reason = "selected node is invalid"; return false; } // Folder nodes. if (node is KwsBrowserFolderNode && ((KwsBrowserFolderNode)node).PermanentFlag) { reason = "cannot rename the default folder"; return false; } // Kws nodes. if (node is KwsBrowserKwsNode) { KwsBrowserKwsNode kws = node as KwsBrowserKwsNode; if (!m_uiBroker.CanPerformKwsAction(KwsAction.Rename, kws.Kws, ref reason)) { Debug.Assert(reason != ""); return false; } } reason = ""; return true; }
/// <summary> /// Return a TreeNode matching the specified browser node. /// </summary> private TreeNode CreateTvWorkspacesTreeNode(KwsBrowserNode bNode) { TreeNode tNode = new TreeNode(); tNode.Name = bNode.ID; tNode.Tag = bNode.FullPath; UpdateTvWorkspacesTreeNode(tNode, bNode); return tNode; }
/// <summary> /// Return true if this node is a descendant of the node specified. /// </summary> public bool IsDescendantOf(KwsBrowserNode folder) { if (Parent == null) return false; if (Parent == folder) return true; return Parent.IsDescendantOf(folder); }
/// <summary> /// Update the tree node information with the browser node specified. /// </summary> private void UpdateTvWorkspacesTreeNode(TreeNode tNode, KwsBrowserNode bNode) { String text = ""; String imageKey = ""; tNode.NodeFont = new Font(tvWorkspaces.Font, bNode.NotifyFlag ? FontStyle.Bold : FontStyle.Regular); if (bNode is KwsBrowserFolderNode) { KwsBrowserFolderNode folderNode = bNode as KwsBrowserFolderNode; text = folderNode.FolderName; imageKey = folderNode.ExpandedFlag ? "FolderOpened" : "FolderClosed"; } else { KwsBrowserKwsNode kwsNode = bNode as KwsBrowserKwsNode; text = kwsNode.Kws.GetKwsName(); imageKey = kwsNode.GetKwsIconImageKey().Name; } // Not sure if this is really necessary for performance; not taking // chances. if (tNode.Text != text) tNode.Text = text; if (tNode.ImageKey != imageKey) tNode.ImageKey = tNode.SelectedImageKey = imageKey; }
/// <summary> /// Return true if the index specified is valid for an insert of the /// node specified. /// </summary> public bool IsIndexValidForInsert(KwsBrowserNode node, int index) { return (index >= 0 && index <= GetListForNode(node).Count); }
/// <summary> /// Remove the node specified. /// </summary> public void RemoveNode(KwsBrowserNode node) { Debug.Assert(GetContainedNodeIndex(node) != -1); GetListForNode(node).Remove(node); node.Parent = null; }
/// <summary> /// Return the index of the node specified, or -1 if the node /// isn't in the folder. /// </summary> public int GetContainedNodeIndex(KwsBrowserNode node) { ArrayList nodes = GetListForNode(node); for (int i = 0; i < nodes.Count; i++) if (nodes[i] == node) return i; return -1; }
/// <summary> /// Return the list that could store the node specified. /// </summary> public ArrayList GetListForNode(KwsBrowserNode node) { if (node is KwsBrowserFolderNode) return FolderNodes; return KwsNodes; }
/// <summary> /// Add the node specified at the position specified. /// </summary> public void AddNode(KwsBrowserNode node, int index) { Debug.Assert(GetContainedNodeIndex(node) == -1); Debug.Assert(IsIndexValidForInsert(node, index)); GetListForNode(node).Insert(index, node); node.Parent = this; }
/// <summary> /// Check if the specified move is valid. If the move is valid, a null /// string is returned, otherwise a string describing the problem is /// returned. /// </summary> public String MoveCheck(KwsBrowserNode srcNode, KwsBrowserFolderNode dstFolder, String dstName, int dstIndex) { String dstID = MakeIDForNodeName(srcNode, dstName); if ((srcNode is KwsBrowserFolderNode) && ((KwsBrowserFolderNode)srcNode).PermanentFlag) return "cannot move or rename this folder"; if (srcNode is KwsBrowserKwsNode && dstFolder.IsRoot()) return "workspaces must be in folders"; if (srcNode is KwsBrowserKwsNode && dstID != srcNode.ID) return "cannot change workspace ID"; if (srcNode is KwsBrowserFolderNode && !KwsBrowserFolderNode.IsValidFolderName(dstName)) return "invalid destination name"; if (srcNode == dstFolder || dstFolder.IsDescendantOf(srcNode)) return "invalid move"; bool reindexFlag = (dstFolder.GetNodeByID(dstID) == srcNode); if (!reindexFlag && dstFolder.GetNodeByID(dstID) != null) return "destination already exists"; if (!dstFolder.IsIndexValidForInsert(srcNode, dstIndex)) return "invalid destination index"; return null; }
/// <summary> /// Move the node at the source specified to the destination specified /// with the index specified. Throw an exception on error. /// </summary> public void Move(KwsBrowserNode srcNode, KwsBrowserFolderNode dstFolder, String dstName, int dstIndex) { String MoveCheckRes = MoveCheck(srcNode, dstFolder, dstName, dstIndex); if (MoveCheckRes != null) throw new Exception(MoveCheckRes); // Adjust the destination index if we're moving the source node // to the last index of a different folder than its parent. if (dstFolder.GetNodeByID(srcNode.ID) == null && dstIndex + 1 == dstFolder.KwsNodes.Count) { dstIndex++; } srcNode.Parent.RemoveNode(srcNode); if (srcNode is KwsBrowserFolderNode) ((KwsBrowserFolderNode)srcNode).FolderName = dstName; dstFolder.AddNode(srcNode, dstIndex); // The workspace list has changed. m_wm.OutlookBroker.OnKwsListChanged(); }
/// <summary> /// Return the ID the node specified would have if it had the name /// specified. /// </summary> public String MakeIDForNodeName(KwsBrowserNode node, String name) { if (node is KwsBrowserKwsNode) return name; return "f_" + name; }
/// <summary> /// Return true if the folder contains any node that has /// the NotifyFlag set to true. The method is not recursive. /// </summary> private bool ContainsNotifyFlagItems(KwsBrowserNode node) { if (node is KwsBrowserKwsNode) return false; KwsBrowserFolderNode fNode = node as KwsBrowserFolderNode; foreach (KwsBrowserNode n in fNode.GetNodes()) if (n.NotifyFlag) return true; return false; }