-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDecompositionResultWindow.xaml.cs
More file actions
131 lines (111 loc) · 5 KB
/
DecompositionResultWindow.xaml.cs
File metadata and controls
131 lines (111 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.ComponentModel; // Required for INotifyPropertyChanged
namespace TimeTask
{
public class SelectableSubTask : INotifyPropertyChanged
{
private string _description;
public string Description
{
get => _description;
set
{
if (_description != value)
{
_description = value;
OnPropertyChanged(nameof(Description));
}
}
}
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set
{
if (_isSelected != value)
{
_isSelected = value;
OnPropertyChanged(nameof(IsSelected));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
public partial class DecompositionResultWindow : Window
{
public List<string> SelectedSubTasks { get; private set; }
public int ParentQuadrantIndex { get; private set; } // 0-3 for task1-task4 respectively
public string ParentImportance { get; private set; }
public string ParentUrgency { get; private set; }
// Constructor accepting quadrant index
public DecompositionResultWindow(List<string> subTaskDescriptions, int parentQuadrantIndex)
{
InitializeComponent();
Owner = Application.Current.MainWindow; // Set owner for proper dialog behavior
this.ParentQuadrantIndex = parentQuadrantIndex;
// Map index to Importance/Urgency - mirrors logic that will be needed in MainWindow
(this.ParentImportance, this.ParentUrgency) = GetPriorityFromIndex(parentQuadrantIndex);
var selectableTasks = subTaskDescriptions.Select(desc => new SelectableSubTask { Description = desc, IsSelected = true }).ToList(); // Default to selected
SubTasksListBox.ItemsSource = selectableTasks;
SelectedSubTasks = new List<string>();
}
// Overloaded constructor accepting importance/urgency strings
public DecompositionResultWindow(List<string> subTaskDescriptions, string importance, string urgency)
{
InitializeComponent();
Owner = Application.Current.MainWindow;
this.ParentImportance = importance;
this.ParentUrgency = urgency;
// Attempt to derive ParentQuadrantIndex if needed, or acknowledge it might be -1 (if direct mapping is complex here)
this.ParentQuadrantIndex = GetIndexFromPriority(importance, urgency);
var selectableTasks = subTaskDescriptions.Select(desc => new SelectableSubTask { Description = desc, IsSelected = true }).ToList();
SubTasksListBox.ItemsSource = selectableTasks;
SelectedSubTasks = new List<string>();
}
private void AddSelectedButton_Click(object sender, RoutedEventArgs e)
{
if (SubTasksListBox.ItemsSource is List<SelectableSubTask> items)
{
SelectedSubTasks = items.Where(task => task.IsSelected).Select(task => task.Description).ToList();
}
this.DialogResult = true;
this.Close();
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
// Helper to map quadrant index to Importance/Urgency strings (consistent with MainWindow)
internal static (string Importance, string Urgency) GetPriorityFromIndex(int index)
{
switch (index)
{
case 0: return ("High", "High"); // task1: Important & Urgent
case 1: return ("High", "Low"); // task2: Important & Not Urgent
case 2: return ("Low", "High"); // task3: Not Important & Urgent
case 3: return ("Low", "Low"); // task4: Not Important & Not Urgent
default: return ("High", "High"); // Default to High/High
}
}
// Helper to map Importance/Urgency strings to quadrant index (consistent with AddTaskWindow)
internal static int GetIndexFromPriority(string importance, string urgency)
{
importance = importance?.ToLowerInvariant() ?? "unknown";
urgency = urgency?.ToLowerInvariant() ?? "unknown";
if (importance == "high" && urgency == "high") return 0;
if (importance == "high" && urgency == "low") return 1;
if (importance == "low" && urgency == "high") return 2;
if (importance == "low" && urgency == "low") return 3;
return 0; // Default to quadrant 0 if unknown
}
}
}