-
Notifications
You must be signed in to change notification settings - Fork 0
/
TTP.cs
338 lines (273 loc) · 11.9 KB
/
TTP.cs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
using System.Windows.Forms;
using System.IO;
using TaskTrackerPro3000.Scripts;
using System.Net.Http.Headers;
using System.Collections;
using System.Text;
using Newtonsoft.Json;
using System.Data;
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
namespace TaskTrackerPro3000
{
public partial class TTP : Form
{
private bool LoadSessionFile = false;
private bool SaveSessionFile = false;
string pathsession = Path.Combine(Directory.GetCurrentDirectory(), "storage.json");
public static string GTMS_CreateGroup_Name = "Create Group";
public static string GTMS_DeleteGroup_Name = "Delete Group";
public static string WS_CreatorForm_Text = "WorkSpace Creator";
public static string WS_CreatorForm_Prompt = "WorkSpace Title:";
public static string GT_CreatorForm_Text = "Group Creator";
public static string GT_CreatorForm_Prompt = "Group Title:";
public static string GT_DeleteForm_Text = "Group Terminator";
public static string GT_DeleteFrom_Prompt = "Select Groups to delete";
public static string WS_DeleteForm_Text = "Workspace Terminator";
public static string WS_DeleteFrom_Prompt = "Select Workspace to delete";
public TTP()
{
InitializeComponent();
}
private void TTP_Load(object sender, EventArgs e)
{
#if DEBUG
if (LoadSessionFile)
loadSession();
#else
loadSession();
#endif
}
private void loadSession()
{
if (File.Exists(pathsession))
{
string sessionFile = File.ReadAllText(pathsession);
var deserializedData = JsonConvert.DeserializeObject<Dictionary<string, Dictionary<bool, Dictionary<string, Dictionary<string, bool>>>>>(sessionFile);
TabPage lastSelectedTab = new TabPage();
// Access the deserialized data
foreach (var workspaceData in deserializedData)
{
Workspace newWorkspacePage = new Workspace(workspaceData.Key.Trim());
newWorkspacePage._MS_workspace.ItemClicked += MS_workspace_ItemClicked;
WorkSpaceHandler.TabPages.Add(newWorkspacePage);
foreach (var selectedTab in workspaceData.Value)
{
if (selectedTab.Key == true)
{
lastSelectedTab = newWorkspacePage;
}
foreach (var groupData in selectedTab.Value)
{
GroupItem newGroup = newWorkspacePage.groupPanel.CreateNewGroup(groupData.Key.Trim());
foreach (var taskData in groupData.Value)
{
Dictionary<string, bool> taskslist = new Dictionary<string, bool>
{
{ taskData.Key, taskData.Value }
};
newGroup.TaskPanelHolder.taskListBox.AddTasks(taskslist);
}
}
}
}
WorkSpaceHandler.SelectTab(lastSelectedTab);
}
}
private void AboutMenuItem_Click(object sender, EventArgs e)
{
string aboutMenuText = "TaskTrackerPro3000 is an open-source extensive task tracker app\n" +
"https://github.com/recore67/TaskTrackerPro3000";
MessageBox.Show(aboutMenuText);
}
private void createNewToolStripMenuItem_Click(object sender, EventArgs e)
{
CreateNewTab(DialogPrompts.CreateDialog(WS_CreatorForm_Text, WS_CreatorForm_Prompt));
}
private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
{
List<Workspace> WSItems = WorkSpaceHandler.TabPages.Cast<Workspace>().ToList<Workspace>();
DeleteWorkspaceByList(DialogPrompts.DeleteWSDialogByList(WS_DeleteForm_Text, WS_DeleteFrom_Prompt, WSItems), WSItems);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
Application.Exit();
}
public void CreateNewTab(string Title)
{
if (!string.IsNullOrEmpty(Title))
{
string TitleFormated = Title.Trim();
for (int i = 0; i < WorkSpaceHandler.TabCount; i++)
{
if (WorkSpaceHandler.TabPages[i].Text == TitleFormated)
{
MessageBox.Show("sorry bub, another Workspace is using that Title");
return;
}
}
Workspace newWorkspacePage = new Workspace(TitleFormated);
newWorkspacePage._MS_workspace.ItemClicked += MS_workspace_ItemClicked;
//finally add new workspace to tabcontrol
WorkSpaceHandler.TabPages.Add(newWorkspacePage);
//SelectWorkSpaceByTitle(TitleFormated);
WorkSpaceHandler.SelectTab(newWorkspacePage);
}
}
public void CreateRecursiveNewWorkspace(string Title, string groupTitle, Dictionary<string, bool> tasks)
{
if (!string.IsNullOrEmpty(Title))
{
string TitleFormated = Title.Trim();
Workspace newWorkspacePage = new Workspace(TitleFormated);
newWorkspacePage._MS_workspace.ItemClicked += MS_workspace_ItemClicked;
GroupItem groupItem = newWorkspacePage.groupPanel.CreateNewGroup(groupTitle);
groupItem.TaskPanelHolder.taskListBox.AddTasks(tasks);
WorkSpaceHandler.TabPages.Add(newWorkspacePage);
WorkSpaceHandler.SelectTab(newWorkspacePage);
}
}
private void MS_workspace_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
if (e.ClickedItem.Text == GTMS_CreateGroup_Name)
{
CreateNewGroup(DialogPrompts.CreateDialog(GT_CreatorForm_Text, GT_CreatorForm_Prompt), (GrpPanel)GetNextControl(e.ClickedItem.GetCurrentParent().Parent, true));
}
if (e.ClickedItem.Text == GTMS_DeleteGroup_Name)
{
GrpPanel grpPanel = (GrpPanel)GetNextControl(e.ClickedItem.GetCurrentParent().Parent, true);
List<GroupItem> groupItems = grpPanel.groupItems;
DeleteGroupByList(DialogPrompts.DeleteGroupDialogByList(GT_DeleteForm_Text, GT_DeleteFrom_Prompt, groupItems), groupItems);
}
}
public void CreateNewGroup(string title, GrpPanel grpPanel)
{
if (!string.IsNullOrEmpty(title))
{
string TitleFormatted = title.Trim();
foreach (GroupItem item in grpPanel.groupItems)
{
if (item.GroupTitle == TitleFormatted)
return;
}
SplitContainer MainsplitContainer = (SplitContainer)grpPanel.Parent.Parent;
GroupItem groupItem = new GroupItem(TitleFormatted);
groupItem.TaskPanelHolder = new TaskPanel(groupItem.GroupTitle, MainsplitContainer);
grpPanel.AddNewGroupItem(groupItem);
}
}
public void DeleteGroupByList(List<string> selectedGroupsNames, List<GroupItem> GroupList)
{
if (selectedGroupsNames == null) return;
if (selectedGroupsNames.Count < 1) return;
//string tempS = "";
//foreach (string selectedName in selectedGroupsNames)
//{
// tempS += selectedName;
//}
//MessageBox.Show(tempS);
//for (int i = 0; i < GroupList.Count; i++)
//{
// if (GroupList[i].GroupTitle == selectedGroupsNames[i])
// {
// GroupItem grpItem = GroupList[i];
// grpItem.Dispose();
// grpItem.TaskPanelHolder.Dispose();
// GroupList.Remove(grpItem);
// }
//}
List<GroupItem> grpItemsRemove = new List<GroupItem>();
foreach (GroupItem grpitem in GroupList)
{
foreach (string selectedName in selectedGroupsNames)
{
if (selectedName == grpitem.GroupTitle)
{
grpItemsRemove.Add(grpitem);
grpitem.Dispose();
grpitem.TaskPanelHolder.Dispose();
}
}
}
foreach (GroupItem item in grpItemsRemove)
{
GroupList.Remove(item);
}
//GC.WaitForPendingFinalizers();
//GC.Collect();
}
public void DeleteWorkspaceByList(List<string> selectedWSNames, List<Workspace> WSList)
{
if (selectedWSNames == null) return;
if (selectedWSNames.Count < 1) return;
//string tempS = "";
//foreach (string selectedName in selectedGroupsNames)
//{
// tempS += selectedName;
//}
//MessageBox.Show(tempS);
foreach (Workspace wsitem in WSList)
{
foreach (string selectedName in selectedWSNames)
{
if (selectedName == wsitem.WSTitle)
{
wsitem.Dispose();
}
}
}
//GC.WaitForPendingFinalizers();
//GC.Collect();
}
public void DeleteWorkSpaceByTitle(string workSpaceTitle)
{
//if (workSpaceTitle != "Dashboard")
for (int i = 0; i < WorkSpaceHandler.TabCount; i++)
{
if (WorkSpaceHandler.TabPages[i].Text == workSpaceTitle)
{
//WorkSpaceHandler.TabPages.Remove(WorkSpaceHandler.TabPages[i]);
WorkSpaceHandler.TabPages[i].Dispose();
}
}
}
//disaster
private void TTP_FormClosed(object sender, FormClosedEventArgs e)
{
#if DEBUG
if (SaveSessionFile)
SaveSession();
#else
SaveSession();
#endif
}
private void SaveSession()
{
if (WorkSpaceHandler.TabCount != 0)
{
List<Workspace> WSItems = WorkSpaceHandler.TabPages.Cast<Workspace>().ToList<Workspace>();
Workspace selectedWS = (Workspace)WorkSpaceHandler.SelectedTab;
var data = new Dictionary<string, Dictionary<bool, Dictionary<string, Dictionary<string, bool>>>>();
foreach (Workspace ws in WSItems)
{
Dictionary<string, Dictionary<string, bool>> groupNameWithTasks = new Dictionary<string, Dictionary<string, bool>>();
foreach (GroupItem grp in ws.groupPanel.groupItems)
{
groupNameWithTasks.Add(grp.GroupTitle, grp.TaskPanelHolder.taskListBox.getCorrectTasks());
}
Dictionary<bool, Dictionary<string, Dictionary<string, bool>>> lastSelectedandgroupNameWithTasks = new Dictionary<bool, Dictionary<string, Dictionary<string, bool>>>();
lastSelectedandgroupNameWithTasks.Add(selectedWS == ws ? true : false, groupNameWithTasks);
data.Add(ws.WSTitle, lastSelectedandgroupNameWithTasks);
if (WorkSpaceHandler.SelectedTab == ws)
{
selectedWS = ws;
}
}
File.WriteAllText(pathsession, JsonConvert.SerializeObject(data, Formatting.Indented));
}
}
}
}