Skip to content

Commit

Permalink
迁移存储设置项
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Jul 14, 2024
1 parent d96183c commit 92fd4ed
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 75 deletions.
14 changes: 0 additions & 14 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -295,20 +295,6 @@
<TextBlock Text="设置" Foreground="{DynamicResource ForegroundColor}" FontSize="32"/>
<ui:ScrollViewerEx PanningMode="VerticalOnly" Margin="12,64,12,64">
<ikw:SimpleStackPanel Spacing="16">
<GroupBox Header="存储" Foreground="{DynamicResource ForegroundColor}">
<ikw:SimpleStackPanel Spacing="12">
<ui:ToggleSwitch Name="ToggleSwitchDataLocation" Header="将数据与本程序保存在同一位置" OnContent="" OffContent="" IsOn="True" Toggled="ToggleSwitchDataLocation_Toggled" Foreground="{DynamicResource ForegroundColor}"/>
<TextBlock Text="将数据保存在何处" FontSize="14" Visibility="{Binding Visibility, ElementName=GridDataLocation}" Foreground="{DynamicResource ForegroundColor}"/>
<Grid Name="GridDataLocation" Visibility="Collapsed">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="64"/>
</Grid.ColumnDefinitions>
<TextBox Name="TextBoxDataLocation" TextChanged="TextBoxDataLocation_TextChanged" Margin="0,0,16,0" Foreground="{DynamicResource ForegroundColor}"/>
<Button Name="ButtonDataLocation" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="1" Content="浏览" Click="ButtonDataLocation_Click" Foreground="{DynamicResource ForegroundColor}"/>
</Grid>
</ikw:SimpleStackPanel>
</GroupBox>
<GroupBox Header="课程表" Foreground="{DynamicResource ForegroundColor}">
<ikw:SimpleStackPanel Spacing="12">
<ui:ToggleSwitch Name="ToggleSwitchUseTimetable" Header="使用带时间信息的课程表" OnContent="" OffContent="" IsOn="True" Toggled="ToggleSwitchUseTimetable_Toggled" Foreground="{DynamicResource ForegroundColor}"/>
Expand Down
43 changes: 1 addition & 42 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1574,34 +1574,6 @@ private void ToggleSwitchLiteModeWithInfoBoard_Toggled(object sender, RoutedEven
SwitchLookMode();
}*/

private void ToggleSwitchDataLocation_Toggled(object sender, RoutedEventArgs e)
{
if (!isSettingsLoaded) return;
if (ToggleSwitchDataLocation.IsOn)
{
Settings.Storage.IsFilesSavingWithProgram = true;
GridDataLocation.Visibility = Visibility.Collapsed;
SaveSettings();
}
else
{
Settings.Storage.IsFilesSavingWithProgram = false;
GridDataLocation.Visibility = Visibility.Visible;
SaveSettings();
}
}
private void TextBoxDataLocation_TextChanged(object sender, TextChangedEventArgs e)
{
if (!isSettingsLoaded) return;
Settings.Storage.DataPath = TextBoxDataLocation.Text;
SaveSettings();
}
private void ButtonDataLocation_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
folderBrowser.ShowDialog();
TextBoxDataLocation.Text = folderBrowser.SelectedPath;
}
private void ToggleSwitchUseTimetable_Toggled(object sender, RoutedEventArgs e)
{
if (!isSettingsLoaded) return;
Expand Down Expand Up @@ -1817,20 +1789,7 @@ private void LoadSettings()
else
{
borderFirstOpening.Visibility = Visibility.Visible;
}

if (Settings.Storage.IsFilesSavingWithProgram)
{
ToggleSwitchDataLocation.IsOn = true;
GridDataLocation.Visibility = Visibility.Collapsed;
}
else
{
ToggleSwitchDataLocation.IsOn = false;
GridDataLocation.Visibility = Visibility.Visible;
}

TextBoxDataLocation.Text = Settings.Storage.DataPath;
}

ToggleSwitchUseTimetable.IsOn = Settings.TimetableSettings.IsTimetableEnabled;
ToggleSwitchTimetableNotification.IsOn = Settings.TimetableSettings.IsTimetableNotificationEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,31 @@
<ui:ScrollViewerEx>
<ikw:SimpleStackPanel Spacing="8" Margin="24">
<Label FontSize="24" Content="存储" Margin="12,8" FontWeight="Bold"/>
<card:ToggleSwitchCard x:Name="ToggleSwitchIsFilesSavingWithProgram" Icon="{x:Static ui:FluentSystemIcons.Attach_20_Regular}" Header="将数据与本程序保存在同一位置" OnContent="启用" OffContent="禁用"/>
<card:GenericSettingsCard Icon="{x:Static ui:FluentSystemIcons.Storage_20_Regular}" Header="数据保存位置" Visibility="{Binding ElementName=ToggleSwitchIsFilesSavingWithProgram, Path=IsOn, Converter={StaticResource InverseBoolToVisibilityConverter}}">
<card:GenericSettingsCard.CardContent>
<Button Grid.Column="2" Height="32" Content="调整该项设置" Background="Transparent" Foreground="{DynamicResource {x:Static ui:ThemeKeys.AccentButtonBackgroundKey}}" BorderThickness="0">
<ui:FlyoutService.Flyout>
<ui:Flyout>
<Grid Width="420">
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Margin="0,0,8,0"/>
<Button Grid.Column="1" Content="浏览"/>
</Grid>
</ui:Flyout>
</ui:FlyoutService.Flyout>
</Button>
</card:GenericSettingsCard.CardContent>
</card:GenericSettingsCard>
<card:ToggleSwitchCard x:Name="ToggleSwitchIsFilesSavingWithProgram" Icon="{x:Static ui:FluentSystemIcons.Attach_20_Regular}" Header="将数据与本程序保存在同一位置"
OnContent="" OffContent="" IsOn="{Binding IsFilesSavingWithProgram, Mode=TwoWay}"
Toggled="ToggleSwitchIsFilesSavingWithProgram_Toggled"/>
<Border HorizontalAlignment="Stretch" Background="{DynamicResource {x:Static ui:ThemeKeys.CardBackgroundFillColorDefaultBrushKey}}"
CornerRadius="4" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="0">
<Expander x:Name="CodeExpander" Grid.Row="1" HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" ui:ControlHelper.CornerRadius="4"
Background="{DynamicResource CardBackgroundFillColorSecondaryBrush}" Style="{DynamicResource {x:Static ui:ThemeKeys.ExpanderCardStyleKey}}" IsExpanded="True"
Visibility="{Binding ElementName=ToggleSwitchIsFilesSavingWithProgram, Path=IsOn, Converter={StaticResource InverseBoolToVisibilityConverter}}" MinHeight="68">
<Expander.Header>
<ikw:SimpleStackPanel Orientation="Horizontal" Spacing="14">
<ui:FontIcon Icon="{x:Static ui:FluentSystemIcons.Storage_20_Regular}" FontSize="20" Margin="-2,0,0,0"/>
<Label Content="数据保存位置" VerticalContentAlignment="Center"/>
</ikw:SimpleStackPanel>
</Expander.Header>

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="auto"/>
</Grid.ColumnDefinitions>
<TextBox x:Name="TextBoxDataPath" Grid.Column="0" Margin="0,0,8,0" Text="{Binding DataPath, Mode=TwoWay}" TextChanged="TextBoxDataPath_TextChanged"/>
<Button Grid.Column="1" Content="浏览" Click="ButtonBrowse_Click"/>
</Grid>
</Expander>
</Border>
</ikw:SimpleStackPanel>
</ui:ScrollViewerEx>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,26 @@ public partial class StorageSettingsPage : Page
public StorageSettingsPage()
{
InitializeComponent();

DataContext = MainWindow.Settings.Storage;
}

private void ToggleSwitchIsFilesSavingWithProgram_Toggled(object sender, RoutedEventArgs e)
{
MainWindow.SaveSettings();
}

private void TextBoxDataPath_TextChanged(object sender, TextChangedEventArgs e)
{
MainWindow.Settings.Storage.DataPath = TextBoxDataPath.Text;
MainWindow.SaveSettings();
}

private void ButtonBrowse_Click(object sender, RoutedEventArgs e)
{
System.Windows.Forms.FolderBrowserDialog folderBrowser = new System.Windows.Forms.FolderBrowserDialog();
folderBrowser.ShowDialog();
TextBoxDataPath.Text = folderBrowser.SelectedPath;
}
}
}

0 comments on commit 92fd4ed

Please sign in to comment.