Skip to content

Commit

Permalink
迁移了行为设置项
Browse files Browse the repository at this point in the history
  • Loading branch information
STBBRD committed Jul 9, 2024
1 parent 2e7fb6c commit e2ccb29
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 45 deletions.
6 changes: 0 additions & 6 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@
<ui:ScrollViewerEx PanningMode="VerticalOnly">
<ui:SimpleStackPanel Spacing="16">
<TextBlock FontSize="32" Text="初次使用,请查看以下常用设置项" Foreground="{DynamicResource ForegroundColor}"/>
<ui:ToggleSwitch Header="开机时运行" OnContent="" OffContent="" IsOn="{Binding IsOn, ElementName=ToggleSwitchRunAtStartup}"/>
<TextBox ui:ControlHelper.Header="天气城市" Text="{Binding Text, ElementName=TextBoxWeatherCity}"/>
</ui:SimpleStackPanel>
</ui:ScrollViewerEx>
Expand Down Expand Up @@ -298,11 +297,6 @@
<ui:SimpleStackPanel Spacing="16">
<GroupBox Header="行为" Foreground="{DynamicResource ForegroundColor}">
<ui:SimpleStackPanel Spacing="12">
<Button x:Name="btnRestart" Content="重新启动黑板贴" Width="240" Click="btnRestart_Click"
Foreground="{DynamicResource ForegroundColor}"/>
<Button Name="ButtonClose" Content="关闭黑板贴" Width="240" Click="ButtonClose_Click"
Foreground="{DynamicResource ForegroundColor}"/>
<ui:ToggleSwitch Name="ToggleSwitchRunAtStartup" Header="开机时运行" OnContent="启用" OffContent="禁用" Toggled="ToggleSwitchRunAtStartup_Toggled" Foreground="{DynamicResource ForegroundColor}"/>
<ui:ToggleSwitch Name="ToggleSwitchBottomMost" Header="将黑板贴置于底层" OnContent="启用" OffContent="禁用" Toggled="ToggleSwitchBottomMost_Toggled" Foreground="{DynamicResource ForegroundColor}"/>
</ui:SimpleStackPanel>
</GroupBox>
Expand Down
62 changes: 26 additions & 36 deletions ZongziTEK_Blackboard_Sticker/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ private void window_Closing(object sender, System.ComponentModel.CancelEventArgs
if (MessageBox.Show("是否取消关闭 ZongziTEK 黑板贴 ?", "ZongziTEK 黑板贴", MessageBoxButton.YesNo, MessageBoxImage.Error) != MessageBoxResult.Yes)
{
e.Cancel = false;
Application.Current.Shutdown();
}
}
}
Expand All @@ -174,7 +175,7 @@ protected override void OnDpiChanged(DpiScale oldDpi, DpiScale newDpi)
//处理 DPI 变化
if (MessageBox.Show("检测到系统 DPI 变化,为确保黑板贴显示正常,需要重启黑板贴。\r\n是否立即重启黑板贴?", "ZongziTEK 黑板贴", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
btnRestart_Click(null, null);
Restart();
}
}

Expand Down Expand Up @@ -1517,14 +1518,28 @@ private void LauncherEditor_Closed(object sender, EventArgs e)

#region Panel Show & Hide

private bool isSettingsWindowOpen = false;

private void iconShowSettingsPanel_MouseDown(object sender, MouseButtonEventArgs e)
{
if (borderSettingsPanel.Visibility == Visibility.Collapsed) borderSettingsPanel.Visibility = Visibility.Visible;
/*if (borderSettingsPanel.Visibility == Visibility.Collapsed) borderSettingsPanel.Visibility = Visibility.Visible;
else btnHideSettingsPanel_Click(null, null);
ButtonRefreshBNSStatus_Click(null, null);
ButtonRefreshBNSStatus_Click(null, null);*/
if (!isSettingsWindowOpen)
{
SettingsWindow settingsWindow = new();
settingsWindow.Closed += SettingsWindow_Closed;
settingsWindow.Show();
isSettingsWindowOpen = true;
}
}

private void SettingsWindow_Closed(object sender, EventArgs e)
{
isSettingsWindowOpen = false;
}

private void btnHideSettingsPanel_Click(object sender, RoutedEventArgs e)
{
borderSettingsPanel.Visibility = Visibility.Collapsed;
Expand All @@ -1537,33 +1552,6 @@ private void btnCloseFirstOpening_Click(object sender, RoutedEventArgs e)
#endregion

#region Settings Panel

private void btnRestart_Click(object sender, RoutedEventArgs e)
{
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");

CloseIsFromButton = true;
System.Windows.Application.Current.Shutdown();
}

private void ButtonClose_Click(object sender, RoutedEventArgs e)
{
Close();
}

private void ToggleSwitchRunAtStartup_Toggled(object sender, RoutedEventArgs e)
{
if (!isSettingsLoaded) return;
if (ToggleSwitchRunAtStartup.IsOn)
{
StartAutomaticallyCreate("ZongziTEK_Blackboard_Sticker");
}
else
{
StartAutomaticallyDel("ZongziTEK_Blackboard_Sticker");
}
}

private void ToggleSwitchBottomMost_Toggled(object sender, RoutedEventArgs e)
{
if (!isSettingsLoaded) return;
Expand All @@ -1575,7 +1563,7 @@ private void ToggleSwitchBottomMost_Toggled(object sender, RoutedEventArgs e)
{
if (MessageBox.Show("需要重新启动黑板贴来使此设置生效\n确定要重新启动黑板贴吗", "ZongziTEK 黑板贴", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
{
btnRestart_Click(null, null);
Restart();
}
else
{
Expand Down Expand Up @@ -1899,11 +1887,6 @@ private void LoadSettings()
borderFirstOpening.Visibility = Visibility.Visible;
}

if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\ZongziTEK_Blackboard_Sticker" + ".lnk"))
{
ToggleSwitchRunAtStartup.IsOn = true;
}

if (Settings.Storage.IsFilesSavingWithProgram)
{
ToggleSwitchDataLocation.IsOn = true;
Expand Down Expand Up @@ -2151,6 +2134,13 @@ private void LoadFrameInfoPagesList()
#endregion

#region Other Functions
public static void Restart()
{
Process.Start(System.Windows.Forms.Application.ExecutablePath, "-m");

CloseIsFromButton = true;
System.Windows.Application.Current.Shutdown();
}

public static string GetDataPath()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
<card:GenericSettingsCard Icon="{x:Static ui:FluentSystemIcons.ArrowExit_20_Regular}" Header="关闭或重新启动黑板贴">
<card:GenericSettingsCard.CardContent>
<ui:SimpleStackPanel Orientation="Horizontal" Spacing="4">
<Button>
<Button Click="ButtonClose_Click">
<ui:FontIcon Icon="{x:Static ui:FluentSystemIcons.ArrowExit_20_Regular}"/>
</Button>
<Button>
<Button Click="ButtonRestart_Click">
<ui:FontIcon Icon="{x:Static ui:FluentSystemIcons.ArrowClockwise_20_Regular}"/>
</Button>
</ui:SimpleStackPanel>
</card:GenericSettingsCard.CardContent>
</card:GenericSettingsCard>
<card:ToggleSwitchCard Icon="{x:Static ui:FluentSystemIcons.Rocket_20_Regular}" Header="开机时运行" OnContent="启用" OffContent="禁用"/>
<card:ToggleSwitchCard x:Name="ToggleSwitchRunOnStartup" Icon="{x:Static ui:FluentSystemIcons.Rocket_20_Regular}" Header="开机时运行" OnContent="启用" OffContent="禁用" Toggled="ToggleSwitchRunOnStartup_Toggled"/>
</ui:SimpleStackPanel>
</ui:ScrollViewerEx>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -23,6 +24,38 @@ public partial class BehaviorSettingsPage : Page
public BehaviorSettingsPage()
{
InitializeComponent();

LoadSettings();
}

private void ButtonClose_Click(object sender, RoutedEventArgs e)
{
Application.Current.MainWindow.Close();
}

private void ButtonRestart_Click(object sender, RoutedEventArgs e)
{
MainWindow.Restart();
}

private void ToggleSwitchRunOnStartup_Toggled(object sender, RoutedEventArgs e)
{
if (ToggleSwitchRunOnStartup.IsOn)
{
MainWindow.StartAutomaticallyCreate("ZongziTEK_Blackboard_Sticker");
}
else
{
MainWindow.StartAutomaticallyDel("ZongziTEK_Blackboard_Sticker");
}
}

private void LoadSettings()
{
if (File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Startup) + "\\ZongziTEK_Blackboard_Sticker" + ".lnk"))
{
ToggleSwitchRunOnStartup.IsOn = true;
}
}
}
}

0 comments on commit e2ccb29

Please sign in to comment.