Refactored input component to handle checkbox optionally

closes #15
This commit is contained in:
tsommer committed 2022-07-09 15:29:22 +02:00
1 parent 91fabb658d
commit 97b7f823c8
3 files changed
+48 -23

No files matched your search

@@ -110,15 +110,24 @@ public partial class SectionTree : UserControl
private async void buttonAdd_Click(object sender, EventArgs e)
{
var result = InputDialog.Show("Please type the desired section name.", "Add a section", "My next section");
var result = InputDialog.Show(new InputDialog.Options(
Message: "Please type the desired section name.",
Title: "Add a section",
Placeholder: "My next section",
ShowQuestionCheckbox: true,
QuestionCheckboxText: "Add a root node (i.e. ignoring the selected node)"
));
if(result.DialogResult == DialogResult.Cancel)
return;
var addRootNode = result.AnswerToQuestion;
// Get the currently selected section as parent:
var selectedNode = this.treeView.SelectedNode;
// Add the new section to the database:
var addedSection = await SectionProcessor.AddSection(this.db, result.Text, result.IsRoot ? null : selectedNode?.Name);
var addedSection = await SectionProcessor.AddSection(this.db, result.Text, addRootNode ? null : selectedNode?.Name);
// Add the new section to the tree control:
var node = new TreeNode
@@ -128,7 +137,7 @@ public partial class SectionTree : UserControl
StateImageIndex = 1,
};
if(!result.IsRoot && selectedNode is not null)
if(!addRootNode && selectedNode is not null)
selectedNode.Nodes.Add(node);
else
this.treeView.Nodes.Add(node);