add:配置切换
This commit is contained in:
@@ -4289,6 +4289,115 @@ namespace Ink_Canvas
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshConfigProfileList()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ComboBoxConfigProfile == null) return;
|
||||
var names = ConfigProfileManager.ListProfileNames();
|
||||
var selected = ComboBoxConfigProfile.SelectedItem as string;
|
||||
ComboBoxConfigProfile.ItemsSource = names;
|
||||
if (selected != null && names.Contains(selected))
|
||||
ComboBoxConfigProfile.SelectedItem = selected;
|
||||
else if (names.Count > 0 && ComboBoxConfigProfile.SelectedIndex < 0)
|
||||
ComboBoxConfigProfile.SelectedIndex = 0;
|
||||
if (BtnDeleteConfigProfile != null)
|
||||
BtnDeleteConfigProfile.IsEnabled = ComboBoxConfigProfile.SelectedItem != null;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"刷新配置文件列表失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void ComboBoxConfigProfile_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (BtnDeleteConfigProfile != null)
|
||||
BtnDeleteConfigProfile.IsEnabled = ComboBoxConfigProfile?.SelectedItem != null;
|
||||
}
|
||||
|
||||
private void BtnSaveAsConfigProfile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
var name = TextBoxNewProfileName?.Text?.Trim();
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
MessageBox.Show("请输入配置文件名称后再保存。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(Settings, Formatting.Indented);
|
||||
if (ConfigProfileManager.SaveAsProfile(name, json))
|
||||
{
|
||||
RefreshConfigProfileList();
|
||||
if (TextBoxNewProfileName != null) TextBoxNewProfileName.Clear();
|
||||
ShowNotification($"已另存为配置文件:{name}");
|
||||
}
|
||||
else
|
||||
MessageBox.Show("保存配置文件失败,请查看日志。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"另存为配置文件失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"保存配置文件失败: {ex.Message}", "配置文件", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnApplyConfigProfile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
var name = ComboBoxConfigProfile?.SelectedItem as string;
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
MessageBox.Show("请先选择要应用的配置文件。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (ConfigProfileManager.ApplyProfile(name))
|
||||
{
|
||||
ReloadSettingsFromFile();
|
||||
ShowNotification($"已应用配置文件「{name}」并热重载");
|
||||
}
|
||||
else
|
||||
MessageBox.Show("应用配置文件失败,请查看日志。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"应用配置文件失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"应用配置文件失败: {ex.Message}", "配置文件", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private void BtnDeleteConfigProfile_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (!isLoaded) return;
|
||||
var name = ComboBoxConfigProfile?.SelectedItem as string;
|
||||
if (string.IsNullOrEmpty(name))
|
||||
{
|
||||
MessageBox.Show("请先选择要删除的配置文件。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Information);
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (MessageBox.Show($"确定要删除配置文件「{name}」吗?", "确认删除", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
|
||||
return;
|
||||
if (ConfigProfileManager.DeleteProfile(name))
|
||||
{
|
||||
RefreshConfigProfileList();
|
||||
ShowNotification($"已删除配置文件:{name}");
|
||||
}
|
||||
else
|
||||
MessageBox.Show("删除配置文件失败,请查看日志。", "配置文件", MessageBoxButton.OK, MessageBoxImage.Warning);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.WriteLogToFile($"删除配置文件失败: {ex.Message}", LogHelper.LogType.Error);
|
||||
MessageBox.Show($"删除配置文件失败: {ex.Message}", "配置文件", MessageBoxButton.OK, MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region RandSettings
|
||||
|
||||
@@ -25,6 +25,15 @@ namespace Ink_Canvas
|
||||
/// 从配置文件加载用户设置并将其应用到主窗口和相关控件的状态(包括启动、外观、画布、手势、PPT、自动化等各项配置)。
|
||||
/// </summary>
|
||||
/// <param name="isStartup">指示当前为应用启动阶段;为 true 时按启动流程应用启动相关设置(例如触发启动专用动作和启动时的行为)。</param>
|
||||
/// <summary>
|
||||
/// 从当前配置文件重新加载设置并应用到界面(热重载),不触发启动逻辑与自动更新检查。
|
||||
/// 用于配置文件切换后立即生效。
|
||||
/// </summary>
|
||||
public void ReloadSettingsFromFile()
|
||||
{
|
||||
LoadSettings(false, skipAutoUpdateCheck: true);
|
||||
}
|
||||
|
||||
/// <param name="skipAutoUpdateCheck">指示是否跳过自动更新检查;为 true 时不会在加载设置后执行自动更新检测。</param>
|
||||
private void LoadSettings(bool isStartup = false, bool skipAutoUpdateCheck = false)
|
||||
{
|
||||
@@ -1250,6 +1259,9 @@ namespace Ink_Canvas
|
||||
|
||||
// 加载画笔自动恢复设置
|
||||
LoadBrushAutoRestoreSettings();
|
||||
|
||||
// 刷新配置文件列表
|
||||
try { RefreshConfigProfileList(); } catch (Exception ex) { LogHelper.WriteLogToFile($"刷新配置文件列表失败: {ex.Message}", LogHelper.LogType.Warning); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user