private static GroupBase GetParentGroupForServerAdd(TreeNode node) { GroupBase groupBase = null; if (node != null) { groupBase = ((node as GroupBase) ?? (node.Parent as GroupBase)); while (groupBase != null && !groupBase.CanAddServers()) { groupBase = (groupBase.Parent as GroupBase); } } return(groupBase); }
private void PopulateNodeContextMenu(ContextMenuStrip menu, RdcTreeNode node) { menu.Items.Clear(); if (node == null) { if (AnyOpenedEditableFiles()) { menu.Items.Add(new DelegateMenuItem("添加服务器", MenuNames.EditAddServer, AddNodeDialogHelper.AddServersDialog)); menu.Items.Add(new DelegateMenuItem("导入服务器配置", MenuNames.EditImportServers, AddNodeDialogHelper.ImportServersDialog)); menu.Items.Add("-"); menu.Items.Add(new DelegateMenuItem("添加群组", MenuNames.EditAddGroup, AddNodeDialogHelper.AddGroupDialog)); } else { ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem("Please open or create a file"); toolStripMenuItem.Enabled = false; menu.Items.Add(toolStripMenuItem); } return; } GroupBase groupBase = node as GroupBase; if (groupBase != null) { groupBase.AnyOrAllConnected(out bool anyConnected, out bool allConnected); ToolStripMenuItem toolStripMenuItem = new DelegateMenuItem("整组连接", MenuNames.SessionConnect, groupBase.Connect); toolStripMenuItem.Enabled = !allConnected; menu.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("连接组为...", MenuNames.SessionConnectAs, groupBase.DoConnectAs); toolStripMenuItem.Enabled = !allConnected; menu.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("重连整组", MenuNames.SessionReconnect, groupBase.Reconnect); toolStripMenuItem.Enabled = anyConnected; menu.Items.Add(toolStripMenuItem); menu.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("断开整组", MenuNames.SessionDisconnect, groupBase.Disconnect); toolStripMenuItem.Enabled = anyConnected; menu.Items.Add(toolStripMenuItem); menu.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("登出整组", MenuNames.SessionLogOff, groupBase.LogOff); toolStripMenuItem.Enabled = (!Policies.DisableLogOff && anyConnected); menu.Items.Add(toolStripMenuItem); menu.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("添加服务器", MenuNames.EditAddServer, delegate { AddNodeDialogHelper.AddServersDialog(node); }); toolStripMenuItem.Enabled = groupBase.CanAddServers(); menu.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("添加群组", MenuNames.EditAddGroup, delegate { AddNodeDialogHelper.AddGroupDialog(node); }); toolStripMenuItem.Enabled = groupBase.CanAddGroups(); menu.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("添加智能群组", MenuNames.EditAddSmartGroup, delegate { AddNodeDialogHelper.AddSmartGroupDialog(node); }); toolStripMenuItem.Enabled = groupBase.CanAddGroups(); menu.Items.Add(toolStripMenuItem); menu.Items.Add("-"); FileGroup file = node as FileGroup; if (file != null) { toolStripMenuItem = new DelegateMenuItem("保存 " + file.GetFilename(), MenuNames.FileSave, delegate { Program.TheForm.DoFileSave(file); }); toolStripMenuItem.Enabled = file.AllowEdit(popUI: false); menu.Items.Add(toolStripMenuItem); menu.Items.Add(new DelegateMenuItem("关闭 " + file.GetFilename(), MenuNames.FileClose, delegate { Program.TheForm.DoFileClose(file); })); } else { toolStripMenuItem = new DelegateMenuItem("删除服务器", MenuNames.EditRemoveServers, delegate { DoRemoveChildren(node); }); toolStripMenuItem.Enabled = groupBase.CanRemoveChildren(); menu.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("删除群组", MenuNames.EditRemove, delegate { ConfirmRemove(node, askUser: true); }); toolStripMenuItem.Enabled = node.CanRemove(popUI: false); menu.Items.Add(toolStripMenuItem); } menu.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("属性", MenuNames.EditProperties, node.DoPropertiesDialog); toolStripMenuItem.Enabled = node.HasProperties; menu.Items.Add(toolStripMenuItem); } else { ServerBase server = node as ServerBase; MenuHelper.AddSessionMenuItems(menu, server); menu.Items.Add("-"); MenuHelper.AddDockingMenuItems(menu, server); menu.Items.Add("-"); MenuHelper.AddMaintenanceMenuItems(menu, server); } }
protected override bool CanBeParent(GroupBase group) { return(group.CanAddServers()); }