/// <summary> /// Return true if the selected Treeview node is a Permanent folder node, /// false otherwise. /// </summary> private bool IsNodePermFolder(KwsBrowserFolderNode bNode) { return (bNode != null && bNode.PermanentFlag); }
/// <summary> /// Create a new workspace object having the credentials specified and /// insert it in the workspace manager, with the current task Stop and /// under the folder specified. Set selectFlag to true if you want the /// workspace to be selected once created. /// </summary> public Workspace CreateWorkspaceObject(KwsCredentials creds, KwsBrowserFolderNode folder, bool firstFlag) { try { // Clear the public flag if we already have a public workspace. if (PublicKwsID != 0) creds.PublicFlag = false; // Get the KAS object. WmKas kas = GetOrCreateKas(creds.KasID); // Create the workspace object, if possible. Workspace kws = new Workspace(this, kas, NextKwsInternalId++, creds); // Register the workspace in the WM and the KAS. KwsTree[kws.InternalID] = kws; kas.KwsTree[kws.InternalID] = kws; AdjustPublicKwsID(); // Insert the workspace in the folder specified. UiBroker.Browser.AddKws(kws, folder, firstFlag); UiBroker.RequestBrowserUiUpdate(true); // Insert the workspace in the database. AddKwsToDb(kws); SetDirty(); return kws; } catch (Exception ex) { Base.HandleException(ex, true); return null; } }
/// <summary> /// Relink a workspace to the workspace manager after it has been /// deserialized. /// </summary> private void RelinkWorkspaceObject(Workspace kws, KwsBrowserFolderNode folder, bool notifyFlag, bool notInDbFlag) { Debug.Assert(kws != null); // Call Initialize() to restore the link to us. kws.Initialize(this); // Insert the workspace in the database. if (notInDbFlag) AddKwsToDb(kws); // Add the workspace to the workspace tree. KwsTree[kws.InternalID] = kws; // The workspace has a serialized KAS, but it is not the same // object as the one serialized in the WM. We need to correct // that situation. WmKas kas = GetOrCreateKas(kws.Kas.KasID); kws.Kas = kas; kas.KwsTree.Add(kws.InternalID, kws); // Make sure our workspace ID generator is in a sane state. NextKwsInternalId = Math.Max(NextKwsInternalId, kws.InternalID + 1); // Add the workspace to the browser. UiBroker.Browser.AddKws(kws, folder, false); // Set the node's Notify flag. Checking the return value is unnecessary. if (notifyFlag) UiBroker.MarkNodeNotifyFlag(kws); }
public KwmCreateKwsOp(WorkspaceManager wm, KwsBrowserFolderNode parentNode, String kwsName) : base(wm) { m_parentNode = parentNode; Creds.KwsName = kwsName; }
/// <summary> /// Helper to create the workspace object. /// </summary> public void CreateKwsObject(KwsBrowserFolderNode folder) { Logging.Log(1, "CreateKwsObject()"); Op.m_opStep = KwmCoreKwsOpStep.CreateKwsObject; Op.m_kws = Op.Wm.CreateWorkspaceObject(Creds, folder, FirstInBrowserFlag); Op.RegisterToKws(true); Op.m_kws.Sm.RequestTaskSwitch(KwsTask.Spawn); }
/// <summary> /// Request the deletion of the folder specified. /// </summary> public void RequestDeleteFolder(KwsBrowserFolderNode folder) { // Cache the path, the browser content may change during the // prompt. String path = folder.FullPath; String msg = "Are you sure you want to remove the folder " + folder.Name + " and all its " + Base.GetKwsString() + "?"; DialogResult res = Misc.KwmTellUser(msg, "Confirm Folder Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (res != DialogResult.Yes) return; // Update the folder node. folder = Browser.GetFolderNodeByPath(path); if (folder == null || folder.PermanentFlag) return; // We're changing the WM state. m_wm.SetDirty(); // Request an UI update. RequestBrowserUiUpdate(true); // Get the list of folders and workspaces, depth first. List<KwsBrowserFolderNode> folderList = new List<KwsBrowserFolderNode>(); List<KwsBrowserKwsNode> kwsList = new List<KwsBrowserKwsNode>(); Browser.RecursiveList(false, folder, folderList, kwsList); // Move the workspace to the primary folder and delete them. foreach (KwsBrowserKwsNode kwsNode in kwsList) { Browser.Move(kwsNode, Browser.PrimaryFolder, kwsNode.Name, Browser.PrimaryFolder.KwsNodes.Count); kwsNode.Kws.Sm.RequestTaskSwitch(KwsTask.Delete); } // Delete the folders, depth first. foreach (KwsBrowserFolderNode folderNode in folderList) { // If we are deleting the selected folder, select something clever. if (Browser.SelectedFolder == folderNode) { KwsBrowserFolderNode nextNodeToSelect = null; // Try the following folder. nextNodeToSelect = folderNode.Parent.GetFolderNodeByIndex(folderNode.Index + 1); if (nextNodeToSelect == null) { // No following folder, try the previous one. nextNodeToSelect = folderNode.Parent.GetFolderNodeByIndex(folderNode.Index - 1); } if (nextNodeToSelect != null) { // Select the folder found. Browser.SelectedFolder = nextNodeToSelect; } else { // No more folders in folderNode.Parent. Select Parent. Browser.SelectedFolder = folderNode.Parent; } } Browser.RemoveFolder(folderNode); } }
public SerializedKwsBrowserFolder(KwsBrowserFolderNode node) { Path = node.FullPath; ExpandedFlag = node.ExpandedFlag; }
/// <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> /// Fill folderList and kwsList with the folders and workspaces found /// under the folder specified. The folder itself is added to the /// folder list before or after the subfolders depending on the value /// of addBeforeFlag. /// </summary> public void RecursiveList(bool addBeforeFlag, KwsBrowserFolderNode folder, List<KwsBrowserFolderNode> folderList, List<KwsBrowserKwsNode> kwsList) { if (addBeforeFlag) folderList.Add(folder); foreach (KwsBrowserFolderNode node in folder.FolderNodes) RecursiveList(addBeforeFlag, node, folderList, kwsList); foreach (KwsBrowserKwsNode node in folder.KwsNodes) kwsList.Add(node); if (!addBeforeFlag) folderList.Add(folder); }
/// <summary> /// Add a workspace at the end of the folder specified. Throw an /// exception on error. /// </summary> public KwsBrowserKwsNode AddKws(Workspace kws, KwsBrowserFolderNode dstFolder, bool firstFlag) { if (m_kwsTree.ContainsKey(kws.InternalID)) throw new Exception(Base.GetKwsString() + "already exist"); if (dstFolder.IsRoot()) throw new Exception(Base.GetKwsString() + " must be in folders"); KwsBrowserKwsNode node = new KwsBrowserKwsNode(kws); dstFolder.AddNode(node, firstFlag ? 0 : dstFolder.KwsNodes.Count); m_kwsTree[kws.InternalID] = node; return node; }
/// <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> /// Add a folder with the name specified at the end of the folder /// specified. Throw an exception on error. /// </summary> public KwsBrowserFolderNode AddFolder(KwsBrowserFolderNode dstFolder, String name) { if (!KwsBrowserFolderNode.IsValidFolderName(name)) throw new Exception("invalid folder name"); KwsBrowserFolderNode node = new KwsBrowserFolderNode(name); if (dstFolder.GetNodeByID(node.ID) != null) throw new Exception("destination already exists"); dstFolder.AddNode(node, dstFolder.FolderNodes.Count); return node; }
public KwsBrowser(WorkspaceManager wm) { m_wm = wm; // Create the root folder and the primary folder. RootNode = new KwsBrowserFolderNode(""); RootNode.PermanentFlag = true; PrimaryFolder = AddFolder(RootNode, "My Teamboxes"); PrimaryFolder.PermanentFlag = true; }
/// <summary> /// Set the 'expanded' flag value of a folder. /// </summary> public void RequestSetFolderExpansion(KwsBrowserFolderNode folder, bool expandFlag) { // We're changing the WM state. if (folder.ExpandedFlag != expandFlag) { m_wm.SetDirty(); folder.ExpandedFlag = expandFlag; } }
/// <summary> /// Make the right menus visible when the selected node is a folder and /// set the Enabled property properly. /// </summary> private void UpdateFolderMenus(ToolStripItemCollection items, KwsBrowserFolderNode folderNode) { items["CmCollapse"].Visible = folderNode.ExpandedFlag; items["CmExpand"].Visible = !folderNode.ExpandedFlag; items["CmCollapse"].Enabled = folderNode.ExpandedFlag; items["CmExpand"].Enabled = (!folderNode.ExpandedFlag && folderNode.FolderNodes.Count > 0); items["separator1"].Visible = true; items["CmCreateNewFolder"].Visible = true; items["CmCreateNewFolder"].Enabled = true; items["separator2"].Visible = true; items["CmDeleteFolder"].Visible = true; items["CmDeleteFolder"].Enabled = !folderNode.PermanentFlag; items["CmRenameFolder"].Visible = true; items["CmRenameFolder"].Enabled = !folderNode.PermanentFlag; }
/// <summary> /// Remove the folder specified. Throw an exception on error. /// </summary> public void RemoveFolder(KwsBrowserFolderNode node) { Debug.Assert(SelectedFolder != node); if (node.PermanentFlag) throw new Exception("cannot remove permanent folder"); if (node.GetNodes().Count != 0) throw new Exception("folder isn't empty"); node.Parent.RemoveNode(node); }
/// <summary> /// Insert the children of the parent folder specified recursively. /// </summary> private void AddTvWorkspacesChildNodes(KwsBrowserFolderNode bParent, TreeNodeCollection tnc) { foreach (KwsBrowserNode bNode in bParent.GetNodes()) { KwsBrowserKwsNode bKwsNode = bNode as KwsBrowserKwsNode; KwsBrowserFolderNode bFolderNode = bNode as KwsBrowserFolderNode; if (bKwsNode != null && !bKwsNode.Kws.IsDisplayable()) continue; TreeNode tNode = CreateTvWorkspacesTreeNode(bNode); tnc.Add(tNode); if (bFolderNode != null) { AddTvWorkspacesChildNodes(bFolderNode, tNode.Nodes); if (bFolderNode.ExpandedFlag) tNode.Expand(); } } }
/// <summary> /// Request the creation of a folder. Return the node of the created folder. /// Warning: UpdateTvWorkspacesList() must be called after a call to this /// method. /// </summary> public KwsBrowserFolderNode RequestCreateFolder(KwsBrowserFolderNode parent) { // We're changing the WM state. m_wm.SetDirty(); // Generate a default folder name. String baseName = "New folder"; String name = baseName; int count = 0; while (parent.GetNodeByID("f_" + name) != null) name = baseName + " (" + ++count + ")"; // Insert the node in the browser. return Browser.AddFolder(parent, name); }