feat: add shortcut for simulator
This commit is contained in:
@ -7,6 +7,19 @@
|
||||
mc:Ignorable="d"
|
||||
x:Name="uiMainWindow"
|
||||
Title="课表模拟器" Height="500" Width="700" Closed="uiMainWindow_Closed" Loaded="uiMainWindow_Loaded">
|
||||
<Window.Resources>
|
||||
<RoutedUICommand x:Key="commandBtnPrevWeek"/>
|
||||
<RoutedUICommand x:Key="commandBtnNextWeek"/>
|
||||
</Window.Resources>
|
||||
<Window.InputBindings>
|
||||
<KeyBinding Gesture="Left" Command="{StaticResource commandBtnPrevWeek}"/>
|
||||
<KeyBinding Gesture="Right" Command="{StaticResource commandBtnNextWeek}"/>
|
||||
</Window.InputBindings>
|
||||
<Window.CommandBindings>
|
||||
<CommandBinding Command="{StaticResource commandBtnPrevWeek}" Executed="commandBtnPrevWeek_Execute" CanExecute="commandBtnPrevWeek_CanExecute"/>
|
||||
<CommandBinding Command="{StaticResource commandBtnNextWeek}" Executed="commandBtnNextWeek_Execute" CanExecute="commandBtnNextWeek_CanExecute"/>
|
||||
</Window.CommandBindings>
|
||||
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="auto"/>
|
||||
@ -19,8 +32,8 @@
|
||||
<TextBlock x:Name="uiWeek" Text="1"/>
|
||||
</StackPanel>
|
||||
|
||||
<Button x:Name="uiBtnPrev" HorizontalAlignment="Left" Content="上一周" Margin="5" Padding="5" Click="uiBtnPrev_Click"/>
|
||||
<Button x:Name="uiBtnNext" HorizontalAlignment="Right" Content="下一周" Margin="5" Padding="5" Click="uiBtnNext_Click"/>
|
||||
<Button x:Name="uiBtnPrevWeek" HorizontalAlignment="Left" Content="上一周" Margin="5" Padding="5" Click="uiBtnPrevWeek_Click"/>
|
||||
<Button x:Name="uiBtnNextWeek" HorizontalAlignment="Right" Content="下一周" Margin="5" Padding="5" Click="uiBtnNextWeek_Click"/>
|
||||
</Grid>
|
||||
|
||||
<Grid x:Name="uiCoreGrid" Grid.Row="1">
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.Remoting.Contexts;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@ -168,29 +169,49 @@ namespace HFUTCourseSimulation.Dialog {
|
||||
// 更新教学周序号
|
||||
uiWeek.Text = currentWeek.ToString();
|
||||
// 更新按钮启用情况
|
||||
uiBtnPrev.IsEnabled = currentWeek > 1;
|
||||
uiBtnNext.IsEnabled = currentWeek < CurrentSemester.weekCount;
|
||||
uiBtnPrevWeek.IsEnabled = currentWeek > 1;
|
||||
uiBtnNextWeek.IsEnabled = currentWeek < CurrentSemester.weekCount;
|
||||
}
|
||||
|
||||
private void uiBtnPrev_Click(object sender, RoutedEventArgs e) {
|
||||
if (currentWeek == 1) {
|
||||
Win32Dialog.Info("已经是第一周了", "错误");
|
||||
return;
|
||||
private bool HasPrevWeek() {
|
||||
return currentWeek > 1;
|
||||
}
|
||||
|
||||
private void PrevWeek() {
|
||||
if (HasPrevWeek()) {
|
||||
currentWeek--;
|
||||
RenderWeek();
|
||||
}
|
||||
|
||||
currentWeek--;
|
||||
RenderWeek();
|
||||
}
|
||||
|
||||
private void uiBtnNext_Click(object sender, RoutedEventArgs e) {
|
||||
if (currentWeek == CurrentSemester.weekCount) {
|
||||
Win32Dialog.Info("已经是最后一周了", "错误");
|
||||
return;
|
||||
private bool HasNextWeek() {
|
||||
return currentWeek < CurrentSemester.weekCount;
|
||||
}
|
||||
|
||||
private void NextWeek() {
|
||||
if (HasNextWeek()) {
|
||||
currentWeek++;
|
||||
RenderWeek();
|
||||
}
|
||||
|
||||
currentWeek++;
|
||||
RenderWeek();
|
||||
}
|
||||
|
||||
#region UI and Shotcuts
|
||||
|
||||
private void uiBtnPrevWeek_Click(object sender, RoutedEventArgs e) {
|
||||
PrevWeek();
|
||||
}
|
||||
|
||||
private void uiBtnNextWeek_Click(object sender, RoutedEventArgs e) {
|
||||
NextWeek();
|
||||
}
|
||||
|
||||
private void commandBtnPrevWeek_Execute(object sender, ExecutedRoutedEventArgs e) => uiBtnPrevWeek_Click(sender, e);
|
||||
private void commandBtnNextWeek_Execute(object sender, ExecutedRoutedEventArgs e) => uiBtnNextWeek_Click(sender, e);
|
||||
|
||||
private void commandBtnPrevWeek_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = HasPrevWeek();
|
||||
private void commandBtnNextWeek_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = HasNextWeek();
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -40,9 +40,9 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
|
||||
this.Schedule = new List<ScheduleItem>();
|
||||
}
|
||||
|
||||
[JsonProperty("Name", Required = Required.Always)]
|
||||
[JsonProperty("Name", Required = Required.AllowNull)]
|
||||
public string Name { get; set; }
|
||||
[JsonProperty("Description", Required = Required.Always)]
|
||||
[JsonProperty("Description", Required = Required.AllowNull)]
|
||||
public string Description { get; set; }
|
||||
[JsonProperty("BkColor", Required = Required.Always)]
|
||||
[JsonConverter(typeof(CustomColorConverter))]
|
||||
@ -52,8 +52,8 @@ namespace HFUTCourseSimulation.Kernel.Data.LegacyStorage.V1 {
|
||||
|
||||
public Storage.Course ToLatest() {
|
||||
return new Storage.Course() {
|
||||
Name = Name,
|
||||
Description = Description,
|
||||
Name = Name is null ? "" : Name,
|
||||
Description = Description is null ? "" : Description,
|
||||
Color = new Storage.ColorPair() {
|
||||
Foreground = Colors.Black,
|
||||
Background = BkColor
|
||||
|
@ -19,9 +19,9 @@
|
||||
<KeyBinding Gesture="Ctrl+S" Command="{StaticResource commandMenuSave}"/>
|
||||
</Window.InputBindings>
|
||||
<Window.CommandBindings>
|
||||
<CommandBinding Command="{StaticResource commandMenuNew}" Executed="commandMenuNew_Click" CanExecute="commandCanExec_NotLoaded"/>
|
||||
<CommandBinding Command="{StaticResource commandMenuOpen}" Executed="commandMenuOpen_Click" CanExecute="commandCanExec_NotLoaded"/>
|
||||
<CommandBinding Command="{StaticResource commandMenuSave}" Executed="commandMenuSave_Click" CanExecute="commandCanExec_Loaded"/>
|
||||
<CommandBinding Command="{StaticResource commandMenuNew}" Executed="commandMenuNew_Execute" CanExecute="commandMenuNew_CanExecute"/>
|
||||
<CommandBinding Command="{StaticResource commandMenuOpen}" Executed="commandMenuOpen_Execute" CanExecute="commandMenuNew_CanExecute"/>
|
||||
<CommandBinding Command="{StaticResource commandMenuSave}" Executed="commandMenuSave_Execute" CanExecute="commandMenuNew_CanExecute"/>
|
||||
</Window.CommandBindings>
|
||||
|
||||
<Grid>
|
||||
|
@ -140,7 +140,7 @@ namespace HFUTCourseSimulation {
|
||||
_context.FilePath = filepath;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
|
||||
Util.Win32Dialog.Error(ex.Message, "打开文件时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -164,7 +164,7 @@ namespace HFUTCourseSimulation {
|
||||
_context.FilePath = filepath;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Util.Win32Dialog.Error(ex.ToString(), "打开文件时出错");
|
||||
Util.Win32Dialog.Error(ex.Message, "打开文件时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -191,7 +191,7 @@ namespace HFUTCourseSimulation {
|
||||
fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
|
||||
Util.Win32Dialog.Error(ex.Message, "保存文件时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -213,7 +213,7 @@ namespace HFUTCourseSimulation {
|
||||
fs.Write(JsonConvert.SerializeObject(_context.Semester.ToStorage()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
Util.Win32Dialog.Error(ex.ToString(), "保存文件时出错");
|
||||
Util.Win32Dialog.Error(ex.Message, "保存文件时出错");
|
||||
return;
|
||||
}
|
||||
|
||||
@ -289,12 +289,13 @@ namespace HFUTCourseSimulation {
|
||||
|
||||
#region Shortcut Handlers
|
||||
|
||||
private void commandCanExec_Loaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnLoaded;
|
||||
private void commandCanExec_NotLoaded(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
|
||||
private void commandMenuNew_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuNew_Click(sender, e);
|
||||
private void commandMenuOpen_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuOpen_Click(sender, e);
|
||||
private void commandMenuSave_Execute(object sender, ExecutedRoutedEventArgs e) => uiMenuSave_Click(sender, e);
|
||||
|
||||
private void commandMenuNew_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuNew_Click(sender, e);
|
||||
private void commandMenuOpen_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuOpen_Click(sender, e);
|
||||
private void commandMenuSave_Click(object sender, ExecutedRoutedEventArgs e) => uiMenuSave_Click(sender, e);
|
||||
private void commandMenuNew_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
|
||||
private void commandMenuOpen_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnNotLoaded;
|
||||
private void commandMenuSave_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = _context.MenuOnLoaded;
|
||||
|
||||
#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user