/// <summary> /// Updates the list of tasks /// </summary> private void UpdateTaskList() { this.taskContainerPanel.Controls.Clear(); for (int i = 0; i < Application.Options.Tasks.Count; i++) { int localIndex = i; // we need this so we don't access a changed `i` inside onEdit, onDelete closures this.taskContainerPanel.Controls.Add(new TaskEditControl(Application.Options.Tasks[i], () => { var dialog = new TaskPropertiesDialog(Application.Options.Tasks[localIndex]); if (dialog.ShowDialog(this) == DialogResult.OK) { Application.Options.Tasks[localIndex] = dialog.Task; ((TaskEditControl)this.taskContainerPanel.Controls[localIndex]).Task = dialog.Task; } }, () => { this.taskContainerPanel.Controls.RemoveAt(localIndex); Application.Options.Tasks.RemoveAt(localIndex); this.emptyTaskListLabel.Visible = this.taskContainerPanel.Controls.Count == 0; }) { Dock = DockStyle.Top }); } this.emptyTaskListLabel.Visible = this.taskContainerPanel.Controls.Count == 0; }
/// <summary> /// Triggered when the "Create task" button is clicked /// </summary> /// <param name="sender">Sender object</param> /// <param name="eventArgs">Event arguments</param> private void OnCreateTaskButtonClicked(object sender, EventArgs eventArgs) { var dialog = new TaskPropertiesDialog(); if (dialog.ShowDialog(this) == DialogResult.OK) { Application.Options.Tasks.Add(dialog.Task); UpdateTaskList(); } }