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