代码清理

This commit is contained in:
PrefacedCorg
2025-08-03 16:46:33 +08:00
parent 745b798d89
commit 11a5a7fdbe
73 changed files with 5733 additions and 3857 deletions
+16 -16
View File
@@ -1,8 +1,8 @@
using Microsoft.Win32;
using System;
using System.IO;
using System.Windows;
using System.Windows.Media.Imaging;
using Microsoft.Win32;
namespace Ink_Canvas
{
@@ -20,7 +20,7 @@ namespace Ink_Canvas
InitializeComponent();
mainWindow = owner;
IsSuccess = false;
// 添加TextBox内容变化事件以检查是否可以保存
IconNameTextBox.TextChanged += (s, e) => ValidateSaveButton();
}
@@ -37,7 +37,7 @@ namespace Ink_Canvas
{
selectedFilePath = openFileDialog.FileName;
IconPathTextBox.Text = selectedFilePath;
// 显示预览
try
{
@@ -51,15 +51,15 @@ namespace Ink_Canvas
{
MessageBox.Show($"无法加载图像: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
// 自动填充名称建议(文件名,不包括扩展名)
string suggestedName = Path.GetFileNameWithoutExtension(selectedFilePath);
IconNameTextBox.Text = suggestedName;
ValidateSaveButton();
}
}
private void ValidateSaveButton()
{
SaveButton.IsEnabled = !string.IsNullOrWhiteSpace(IconNameTextBox.Text) && !string.IsNullOrEmpty(selectedFilePath);
@@ -77,37 +77,37 @@ namespace Ink_Canvas
// 创建pictures/icons文件夹结构(如果不存在)
string picturesFolder = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "pictures");
string iconsFolder = Path.Combine(picturesFolder, "icons");
if (!Directory.Exists(picturesFolder))
{
Directory.CreateDirectory(picturesFolder);
}
if (!Directory.Exists(iconsFolder))
{
Directory.CreateDirectory(iconsFolder);
}
// 生成一个唯一的文件名(使用GUID)
string extension = Path.GetExtension(selectedFilePath);
string newFileName = $"{Guid.NewGuid()}{extension}";
string destPath = Path.Combine(iconsFolder, newFileName);
// 复制文件到pictures/icons文件夹
File.Copy(selectedFilePath, destPath);
// 创建新的自定义图标对象
var customIcon = new CustomFloatingBarIcon(IconNameTextBox.Text, destPath);
// 添加到主窗口的设置中
MainWindow.Settings.Appearance.CustomFloatingBarImgs.Add(customIcon);
// 更新ComboBox
mainWindow.UpdateCustomIconsInComboBox();
// 保存设置
MainWindow.SaveSettingsToFile();
IsSuccess = true;
Close();
}
@@ -117,4 +117,4 @@ namespace Ink_Canvas
}
}
}
}
}