Skip to content

Commit

Permalink
bak
Browse files Browse the repository at this point in the history
  • Loading branch information
TC999 committed Jan 10, 2025
1 parent 7e17ef9 commit 575c64d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
45 changes: 43 additions & 2 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::move_module; // 导入移动模块
use crate::open;
use crate::scanner;
use crate::utils;
use crate::yaml_loader;
use crate::yaml_loader::{FolderDescriptions, load_folder_descriptions};
use eframe::egui::{self, Grid, ScrollArea};
use std::collections::HashSet;
Expand All @@ -28,6 +29,8 @@ pub struct AppDataCleaner {
folder_descriptions: Option<FolderDescriptions>,
yaml_error_logged: bool, // 新增字段,用于标记是否已经记录过错误
status: Option<String>, // 添加 status 字段
editing_description: Option<String>,
editing_folder: Option<String>,
}

impl Default for AppDataCleaner {
Expand All @@ -50,6 +53,8 @@ impl Default for AppDataCleaner {
yaml_error_logged: false, // 初始时假定未记录过错误
//status: None, // 初始化为 None
status: Some("未扫描".to_string()), // 初始化为 "未扫描"
editing_description: None,
editing_folder: None,
}
}
}
Expand Down Expand Up @@ -177,10 +182,46 @@ impl eframe::App for AppDataCleaner {
let description = self.folder_descriptions.as_ref().and_then(|desc| {
desc.get_description(folder, &self.selected_appdata_folder)
});
// 显示描述和编辑按钮
if let Some(desc) = description {
ui.label(desc);
ui.horizontal(|ui| {
ui.label(desc);
if ui.button("编辑").on_hover_text("编辑描述").clicked() {
self.editing_folder = Some(folder.clone());
self.editing_description = Some(desc.clone());
}
});
} else {
ui.label("无描述");
ui.horizontal(|ui| {
ui.label("无描述");
if ui.button("编辑").on_hover_text("编辑描述").clicked() {
self.editing_folder = Some(folder.clone());
self.editing_description = Some(String::new());
}
});
}
if let Some(editing_folder) = &self.editing_folder {
if editing_folder == folder {
if let Some(editing_description) = &mut self.editing_description {
ui.horizontal(|ui| {
ui.text_edit_singleline(editing_description);
if ui.button("保存").clicked() {
if let Some(folder_descriptions) = &mut self.folder_descriptions {
folder_descriptions.set_description(folder, &self.selected_appdata_folder, editing_description.clone());
yaml_loader::save_folder_descriptions("folders_description.yaml", folder_descriptions)
.expect("保存描述失败");
}
self.editing_folder = None;
self.editing_description = None;
logger::log_info(&format!("文件夹 '{}' 的描述已更新", folder));
}
if ui.button("取消").clicked() {
self.editing_folder = None;
self.editing_description = None;
}
});
}
}
}

if !self.ignored_folders.contains(folder) {
Expand Down
14 changes: 14 additions & 0 deletions src/yaml_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ impl FolderDescriptions {
_ => None,
}
}

pub fn set_description(&mut self, folder_name: &str, folder_type: &str, description: String) {
match folder_type {
"Roaming" => self.Roaming.insert(folder_name.to_string(), description),
"Local" => self.Local.insert(folder_name.to_string(), description),
"LocalLow" => self.LocalLow.insert(folder_name.to_string(), description),
_ => None,
};
}
}

// 新增函数,用于加载文件夹描述
Expand All @@ -48,4 +57,9 @@ pub fn load_folder_descriptions(file_path: &str, yaml_error_logged: &mut bool) -
None
}
}
}

pub fn save_folder_descriptions(file_path: &str, descriptions: &FolderDescriptions) -> Result<(), String> {
let content = serde_yaml::to_string(descriptions).map_err(|e| format!("序列化 YAML 文件失败: {}", e))?;
fs::write(file_path, content).map_err(|e| format!("写入 YAML 文件失败: {}", e))
}

0 comments on commit 575c64d

Please sign in to comment.