Skip to content

Commit

Permalink
优化课程表编辑器的性能与使用体验,优化启动台编辑器的外观
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Apr 21, 2024
1 parent 37393d8 commit 5a31ef2
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
<Grid Grid.Column="0" Margin="8,6">
<TextBlock x:Name="TextBlockHintSubject" Text="在此输入课程名称" Foreground="#CC000000" FontSize="14"
TextAlignment="Center" VerticalAlignment="Center"/>
<TextBox x:Name="TextBoxSubject" BorderThickness="0"
<TextBox x:Name="TextBoxSubject" BorderThickness="0"
Text="{Binding Subject, RelativeSource={RelativeSource AncestorType=UserControl}}"
TextAlignment="Center" VerticalContentAlignment="Center" Background="{x:Null}"
GotFocus="TextBoxSubject_GotFocus" LostFocus="TextBoxSubject_LostFocus" TextChanged="TextBoxSubject_TextChanged"/>
TextChanged="TextBoxSubject_TextChanged" GotFocus="TextBoxSubject_GotFocus" LostFocus="TextBoxSubject_LostFocus"/>
</Grid>
<local:TimeTextBox x:Name="StartTimeTextBox" BorderThickness="0" Grid.Column="1" Margin="8,6"
Text="{Binding StartTime, RelativeSource={RelativeSource AncestorType=UserControl}}"
Expand All @@ -42,7 +42,7 @@
<ui:FontIcon Glyph="{x:Static ui:SegoeIcons.More}" FontFamily="{StaticResource SegoeFluentIcons}"/>
<ui:FlyoutService.Flyout>
<ui:MenuFlyout>
<MenuItem Name="MenuItemSplit" Header="在这节课后添加空隙" IsCheckable="True" Click="MenuItemSplit_Click"/>
<MenuItem Name="MenuItemSplit" Header="在这节课下方添加空隙" IsCheckable="True" Click="MenuItemSplit_Click"/>
<Separator/>
<MenuItem Header="删除" Click="MenuItemDelete_Click">
<MenuItem.Icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public TimetableEditorItem()

public event EventHandler LessonInfoChanged;
public event EventHandler LessonDeleting;
private bool isLoaded = false;

#region Properties
public static readonly DependencyProperty SubjectProperty =
Expand Down Expand Up @@ -116,18 +117,25 @@ private void TextBoxSubject_TextChanged(object sender, TextChangedEventArgs e)
{
TextBlockHintSubject.Visibility = Visibility.Hidden;
}

if (!isLoaded) return;

Subject = TextBoxSubject.Text;
OnLessonInfoChanged();
}

private void StartTimeTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!isLoaded) return;

StartTime = StartTimeTextBox.Text;
OnLessonInfoChanged();
}

private void EndTimeTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
if (!isLoaded) return;

EndTime = EndTimeTextBox.Text;
OnLessonInfoChanged();
}
Expand All @@ -146,6 +154,7 @@ private void MenuItemSplit_Click(object sender, RoutedEventArgs e)
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
MenuItemSplit.IsChecked = IsSplitBelow;
isLoaded = true;
}
#endregion
}
Expand Down
31 changes: 21 additions & 10 deletions ZongziTEK_Blackboard_Sticker/LauncherEditor.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using iNKORE.UI.WPF.Modern;
using iNKORE.UI.WPF.Modern.Controls;
using IWshRuntimeLibrary;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -37,6 +38,7 @@ public LauncherEditor()
LoadList();
});
});
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
}

private async void LoadList()
Expand Down Expand Up @@ -80,26 +82,29 @@ private async void LoadList()
foreach (KeyValuePair<string, Drawing.Bitmap> file in fileInfo)
{
//列表项
Button LinkButton = new()
Border BorderItem = new()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
Height = 48,
//Background = new SolidColorBrush(Color.FromArgb(255, 251, 251, 251))
Background = (Brush)FindResource(ThemeKeys.CardBackgroundFillColorDefaultBrushKey),
CornerRadius = new CornerRadius(2),
BorderBrush = (Brush)FindResource("BorderBrush"),
BorderThickness = new Thickness(1)
};

//按钮里面的布局
SimpleStackPanel ContentStackPanel = new()
{
Spacing = 8,
Margin = new(8, 8, 8, 8),
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Left
HorizontalAlignment = HorizontalAlignment.Left,
VerticalAlignment = VerticalAlignment.Center
};

Grid ContentGrid = new()
{
HorizontalAlignment = HorizontalAlignment.Stretch
HorizontalAlignment = HorizontalAlignment.Stretch,
Margin = new(16, 8, 16, 8)
};

//图标
Expand Down Expand Up @@ -127,11 +132,12 @@ private async void LoadList()
Button DeleteButton = new()
{
HorizontalAlignment = HorizontalAlignment.Right,
Width = 36,
Height = 36,
Width = 28,
Height = 28,
Background = Brushes.Transparent,
Padding = new Thickness(0),
BorderThickness = new Thickness(0),
Margin = new(0, 0, -6, 0)
};

FontIcon DeleteIcon = new()
Expand All @@ -147,7 +153,7 @@ private async void LoadList()
ContentStackPanel.Children.Add(image);
ContentStackPanel.Children.Add(textBlockFileName);
ContentStackPanel.Children.Add(textBlockLinkName);
LinkButton.Content = ContentGrid;
BorderItem.Child = ContentGrid;
ContentGrid.Children.Add(ContentStackPanel);
ContentGrid.Children.Add(DeleteButton);
DeleteButton.Click += DeleteButton_Click;
Expand All @@ -157,7 +163,7 @@ await Task.Run(() =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
ListStackPanel.Children.Add(LinkButton);
ListStackPanel.Children.Add(BorderItem);
}));
});
}
Expand Down Expand Up @@ -254,5 +260,10 @@ private void TextBoxFilePath_TextChanged(object sender, TextChangedEventArgs e)
}
catch (Exception) { }
}

private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e)
{
ButtonRefresh_Click(null, null);
}
}
}
2 changes: 1 addition & 1 deletion ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public MainWindow()
TimetableEditor.EditorButtonUseCurriculum_Click += EditorButtonSettingUseCurriculum;

// 颜色主题
Microsoft.Win32.SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged;
SystemEvents_UserPreferenceChanged(null, null);

// 小黑板 2
Expand Down
22 changes: 19 additions & 3 deletions ZongziTEK_Blackboard_Sticker/TimetableEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs
if (!isCloseWithoutWarning)
{
e.Cancel = true;
if (MessageBox.Show("确定要直接关闭课程表编辑器吗\n这将丢失未保存的课程", "ZongziTEK 黑板贴", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
if (!isEdited || MessageBox.Show("确定要直接关闭课程表编辑器吗\n这将丢失未保存的课程", "ZongziTEK 黑板贴", MessageBoxButton.OKCancel, MessageBoxImage.Warning) == MessageBoxResult.OK)
{
e.Cancel = false;
}
Expand All @@ -68,7 +68,7 @@ private void ButtonClose_Click(object sender, RoutedEventArgs e)

private void ButtonUseCurriculum_Click(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("是否保存当前含时间信息的课程表内容", "ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.OK)
if (isEdited || MessageBox.Show("是否保存当前含时间信息的课程表内容", "ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.OK)
{
ButtonSave_Click(null, null);
}
Expand Down Expand Up @@ -113,6 +113,8 @@ private void Item_LessonInfoChanged(object sender, EventArgs e)
}
catch { }
}

isEdited = true;
}

private void Item_LessonDeleting(object sender, EventArgs e)
Expand All @@ -125,6 +127,8 @@ private void Item_LessonDeleting(object sender, EventArgs e)
ListStackPanel.Children.RemoveAt(index);
GetSelectedDay().RemoveAt(index);
}

isEdited = true;
}

private void ButtonInsertLesson_Click(object sender, RoutedEventArgs e)
Expand All @@ -134,6 +138,8 @@ private void ButtonInsertLesson_Click(object sender, RoutedEventArgs e)
item.LessonDeleting += Item_LessonDeleting;
GetSelectedDay().Add(new Lesson("", new TimeSpan(0, 0, 0), new TimeSpan(0, 0, 0), false));
ListStackPanel.Children.Add(item);

isEdited = true;
}

private void ScrollViewerTimetable_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
Expand All @@ -144,7 +150,8 @@ private void ScrollViewerTimetable_PreviewMouseWheel(object sender, MouseWheelEv
#endregion

#region Load & Save
Timetable Timetable = MainWindow.Timetable;
private Timetable Timetable = MainWindow.Timetable;
private bool isEdited = false;

private void LoadTimetable()
{
Expand All @@ -166,6 +173,15 @@ private void LoadTimetable()
item.LessonDeleting += Item_LessonDeleting;
ListStackPanel.Children.Add(item);
}

if (GetSelectedDay().Count == 0)
{
ButtonCopy.IsEnabled = false;
}
else
{
ButtonCopy.IsEnabled = true;
}
}
#endregion

Expand Down

0 comments on commit 5a31ef2

Please sign in to comment.