Skip to content

Commit 1c2ca37

Browse files
committed
添加编辑目标功能
整理优化代码
1 parent 470e469 commit 1c2ca37

File tree

5 files changed

+129
-91
lines changed

5 files changed

+129
-91
lines changed

TimeControl/Tools/SystemControl.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Diagnostics;
1+
using System;
2+
using System.Diagnostics;
23

34
namespace TimeControl.Tools
45
{
@@ -15,5 +16,10 @@ public static void Shutdown()
1516
Process process = Process.Start(processStartInfo);
1617
process.StandardInput.WriteLine("shutdown -s -f -t 0");
1718
}
19+
public static void ProgramRestart()
20+
{
21+
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "TimeControl.exe");
22+
Environment.Exit(0);
23+
}
1824
}
1925
}

TimeControl/Tools/TCFile.cs

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,35 @@ public static class TCFile
3535

3636
//Title management
3737
public static readonly string TitleFile = BaseLocation + "Title.txt";
38-
//自动关机
38+
//Auto shutdown
3939
public static readonly string ShutdownSpan = BaseLocation + "\\Shutdown.txt";
4040

41-
//数据显示
41+
//TimeData dir
4242
public static readonly string SavedData = BaseLocation + "\\SavedData.xml";
4343

4444
public static readonly string SavedDataDir = BaseLocation + "\\SavedData";
45-
46-
public static string[] SavedDataFiles
45+
//Title management
46+
public static void SaveTitle(ListBox titleListBox)
4747
{
48-
get
48+
List<string> titleList = new();
49+
foreach (string s in titleListBox.Items)
4950
{
50-
return Directory.GetFiles(SavedDataDir);
51+
titleList.Add(s);
5152
}
53+
File.WriteAllLines(TCFile.TitleFile, titleList);
5254
}
55+
public static void ReadTitle(ListBox titleListBox)
56+
{
57+
if (File.Exists(TitleFile))
58+
{
59+
string[] strings = File.ReadAllLines(TitleFile);
60+
foreach (string s in strings)
61+
{
62+
titleListBox.Items.Add(s);
63+
}
64+
}
65+
}
66+
//Apps
5367

5468
public static void SaveApps(List<App> apps)
5569
{
@@ -122,6 +136,15 @@ public static FileInfo GetLatestAppsFile()
122136
return latestFile;
123137
}
124138

139+
//TimeData and Goals
140+
141+
public static string[] SavedDataFiles
142+
{
143+
get
144+
{
145+
return Directory.GetFiles(SavedDataDir);
146+
}
147+
}
125148
public static void SaveTimeData(TimeData time)
126149
{
127150
using (StreamWriter sw = new(SavedData))

TimeControl/Windows/ControlPanel.cs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -229,23 +229,11 @@ private void RemoveTitleButton_Click(object sender, EventArgs e)
229229
}
230230
private void SaveTitles()
231231
{
232-
List<string> titleList = new();
233-
foreach (string s in titleListBox.Items)
234-
{
235-
titleList.Add(s);
236-
}
237-
File.WriteAllLines(TCFile.TitleFile, titleList);
232+
TCFile.SaveTitle(titleListBox);
238233
}
239234
private void InitTitles()
240235
{
241-
if (File.Exists(TCFile.TitleFile))
242-
{
243-
string[] strings = File.ReadAllLines(TCFile.TitleFile);
244-
foreach (string s in strings)
245-
{
246-
titleListBox.Items.Add(s);
247-
}
248-
}
236+
TCFile.ReadTitle(titleListBox);
249237
}
250238
#endregion
251239

@@ -319,6 +307,7 @@ private void ProcessMonitorTimer_Tick(object sender, EventArgs e)
319307
Process.Start(process);
320308
}
321309
Process[] processes=Process.GetProcesses();
310+
//Title Management
322311
foreach (Process process in processes)
323312
{
324313
if(!string.IsNullOrWhiteSpace(process.MainWindowTitle))

TimeControl/Windows/GoalChangeWindow.Designer.cs

Lines changed: 81 additions & 68 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TimeControl/Windows/GoalChangeWindow.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ private void RefreshForm()
2828

2929
private void GoalChangeWindow_FormClosed(object sender, FormClosedEventArgs e)
3030
{
31-
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "TimeControl.exe");
32-
Environment.Exit(0);
31+
SystemControl.ProgramRestart();
3332
}
3433

3534
private void GoalChangeWindow_FormClosing(object sender, FormClosingEventArgs e)
@@ -88,5 +87,13 @@ private void deleteButton_Click(object sender, EventArgs e)
8887
RefreshForm();
8988
}
9089
}
90+
91+
private void EditButton_Click(object sender, EventArgs e)
92+
{
93+
TimeData timeData = TCFile.ReadTimeData();
94+
timeData.GoalName = goalTextBox.Text;
95+
TCFile.SaveTimeData(timeData);
96+
RefreshForm();
97+
}
9198
}
9299
}

0 commit comments

Comments
 (0)