private async Task LoadChatProfiles() { cbxChatProfiles.Items.Clear(); (await DataProviders.GetChatProfiles()).ForEach(item => cbxChatProfiles.Items.Add(item)); var activeProfile = await DataProviders.GetActiveProfile(); if (!cbxChatProfiles.Items.Contains(activeProfile)) { activeProfile = cbxChatProfiles.Items.Count > 0 ? cbxChatProfiles.Items[0].ToString() : null; } cbxChatProfiles.SelectedItem = activeProfile; }
private async void actionMenu_Clicked(object sender, ToolStripItemClickedEventArgs e) { var clicked = e.ClickedItem.AccessibilityObject.Name; { if (neuralTree.SelectedNode != null) { switch (clicked) { case MenuActionNew: { var newNode = await DbLinkCollection.InsertChildById(neuralTree.SelectedNode.Name, new NeuralLinkModel { Name = "New node" }); var newTreeNode = neuralTree.SelectedNode.Nodes.Add(newNode._id, newNode.Name); newTreeNode.Tag = newNode; neuralTree.SelectedNode = newTreeNode; ReloadTree(); } break; case MenuActionDelete: { if (DataProviders.ConfirmDialog($"Do you want to permanently delete node '{neuralTree.SelectedNode.Text}'?\n\n" + $"Warning: This will also deletes from all the references to this node in other parent nodes of this.\n\n" + $"Note: Refresh tree to view the updated changes.", "MenuActionDelete confirmation", MessageBoxIcon.Warning)) { var node = (NeuralLinkModel)neuralTree.SelectedNode.Tag; await DbLinkCollection.RemoveAndUnlinkFromParents(node); await DbTrainDataCollection.RemoveOneById(node._id); neuralTree.SelectedNode.Remove(); ReloadTree(); } } break; case MenuActionMapChild: { var selectedNode = (NeuralLinkModel)neuralTree.SelectedNode.Tag; var picker = new NodePicker(LinkType.NeuralLink, selectedNode._id, $"Map child to : {selectedNode.Name}"); var res = picker.ShowDialog(); if (res == DialogResult.OK && picker.NodeId != selectedNode._id) { var node = await DbLinkCollection.FindOneById(picker.NodeId); if (node != null) { await DbLinkCollection.LinkParentChild(selectedNode._id, picker.NodeId); var newTreeNode = neuralTree.SelectedNode.Nodes.Add(node._id, node.Name); newTreeNode.Tag = node; ReloadTree(); } } } break; case MenuActionUnmapChild: { if (neuralTree.SelectedNode.Parent == null) { await DbBotCollection.SetRootNodeById(BotAlphaName, null, cbxChatProfiles.Text); } else { await DbLinkCollection.UnLinkParentChild(neuralTree.SelectedNode.Parent.Name, neuralTree.SelectedNode.Name); neuralTree.SelectedNode.Remove(); } ReloadTree(); } break; default: break; } } switch (clicked) { case MenuActionRenameProfile: await RenameChatProfile(); break; case MenuActionDeleteProfile: await DeleteCurrentChatProfile(); break; case MenuActionNewProfile: await CreateNewChatProfile(); break; case MenuActionNew: { if (neuralTree.Nodes.Count == 0) { var rootNode = await DbLinkCollection.InsertNew(new NeuralLinkModel { Name = "RootNode" }); await DbBotCollection.SetRootNodeById(BotAlphaName, rootNode._id, await DataProviders.GetActiveProfile()); neuralTree.ImageList = DataProviders.LoadNeuralLinkValidationImageList(); var treeNode = neuralTree.Nodes.Add(rootNode._id, rootNode.Name); treeNode.Tag = rootNode; treeNode.ImageKey = rootNode.GetNodeImage(); neuralTree.SelectedNode = treeNode; ReloadTree(); } } break; default: break; } neuralTree.ExpandAll(); } }