Skip to content

Commit

Permalink
优化课程表编辑器保存操作
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Sep 21, 2024
1 parent 62d964a commit 674e492
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public MainWindow()
// 加载文件
LoadSettings();
LoadStrokes();
LoadTimetableOrCurriculum();
Task.Run(() =>
{
Dispatcher.BeginInvoke(() =>
Expand All @@ -93,10 +92,11 @@ public MainWindow()
frameInfoNavigationTimer.Interval = TimeSpan.FromSeconds(4);
frameInfoNavigationTimer.Start();

// 课程表
timetableTimer = new DispatcherTimer();
timetableTimer.Tick += CheckTimetable;
timetableTimer.Interval = new TimeSpan(0, 0, 1);
timetableTimer.Start();
LoadTimetableOrCurriculum();

// 颜色主题
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
Expand Down
2 changes: 1 addition & 1 deletion ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
<Button Style="{StaticResource AccentButtonStyle}" Height="32" HorizontalAlignment="Right" Click="ButtonSave_Click">
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="8">
<ui:FontIcon Icon="{x:Static ui:FluentSystemIcons.Save_20_Regular}"/>
<TextBlock Text="保存并关闭"/>
<TextBlock Text="保存"/>
</ikw:SimpleStackPanel>
</Button>
</Grid>
Expand Down
21 changes: 15 additions & 6 deletions ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public partial class TimetableEditor : Window
{
public TimetableEditor()
{
InitializeComponent();
InitializeComponent();

if (File.Exists(MainWindow.GetDataPath() + MainWindow.timetableFileName))
{
try
Expand All @@ -47,13 +47,21 @@ public TimetableEditor()

private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (!isCloseWithoutWarning)
if (!isCloseWithoutWarning && isEdited)
{
e.Cancel = true;
if (!isEdited || MessageBox.Show("确定要直接关闭课程表编辑器吗\n这将丢失未保存的课程", "关闭而不保存", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
if (MessageBox.Show("部分修改仍未保存,是否保存这些更改?", "是否保存更改", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
ButtonSave_Click(null, null);
e.Cancel = false;
}
else
{
if (MessageBox.Show("此操作将导致刚才的更改丢失,确定不要保存课表吗?", "关闭而不保存", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
e.Cancel = false;
}
}
}
}

Expand All @@ -65,9 +73,10 @@ private void ButtonSave_Click(object sender, RoutedEventArgs e)
File.WriteAllText(MainWindow.GetDataPath() + MainWindow.timetableFileName, text);
}
catch { }
isEdited = false;

isCloseWithoutWarning = true;
Close();
//isCloseWithoutWarning = true;
//Close();
}

private void ButtonClose_Click(object sender, RoutedEventArgs e)
Expand Down

0 comments on commit 674e492

Please sign in to comment.