-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
忽略测试 #11
Conversation
WalkthroughThe changes in this pull request introduce new functionality for managing ignored folders in the application. A new file, Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 3
🧹 Outside diff range and nitpick comments (3)
src/ignore.rs (1)
1-24
: Add documentation for public APIPublic functions should be documented with rustdoc comments explaining their purpose, parameters, and return values.
Add the following documentation:
/// Loads the list of ignored folders from the ignore file. /// /// Returns a HashSet containing the folder names that should be ignored. /// If the ignore file doesn't exist, returns an empty set. pub fn load_ignored_folders() -> HashSet<String> /// Saves the given set of ignored folders to the ignore file. /// /// # Arguments /// /// * `ignored` - A reference to a HashSet containing the folder names to ignore /// /// # Returns /// /// Returns Ok(()) if the save was successful, or an IO error if it failed. pub fn save_ignored_folders(ignored: &HashSet<String>) -> io::Result<()>src/ui.rs (2)
170-192
: Simplify UI logic and improve code organizationThe code has redundant checks and nested conditions that make it harder to read.
- let is_ignored = self.ignored_folders.contains(folder); - if is_ignored { - ui.add_enabled(false, egui::Label::new(egui::RichText::new(folder).color(egui::Color32::GRAY))); - } else { - ui.label(folder); - } + let is_ignored = self.ignored_folders.contains(folder); + let folder_label = if is_ignored { + egui::RichText::new(folder).color(egui::Color32::GRAY) + } else { + egui::RichText::new(folder) + }; + ui.label(folder_label); ui.label(utils::format_size(*size)); ui.label("敬请期待"); ui.label("敬请期待"); - if !self.ignored_folders.contains(folder) { - if ui.button("彻底删除").clicked() { - self.confirm_delete = Some((folder.clone(), false)); - } - if ui.button("移动").clicked() { - // 移动逻辑 - } - } else { - ui.add_enabled(false, |ui: &mut egui::Ui| { - let response1 = ui.button("彻底删除"); - let response2 = ui.button("移动"); - response1 | response2 // 返回合并的 Response - }); + ui.add_enabled(!is_ignored, |ui: &mut egui::Ui| { + let mut clicked = false; + if ui.button("彻底删除").clicked() { + self.confirm_delete = Some((folder.clone(), false)); + clicked = true; + } + if ui.button("移动").clicked() { + // 移动逻辑 + clicked = true; + } + clicked + });
41-41
: Consider adding persistence for ignored foldersThe ignored folders are loaded on startup but there's no mechanism to persist changes across sessions.
Consider implementing a save-on-change mechanism or periodic auto-save to ensure ignored folders persist across application restarts.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
.gitignore
(1 hunks)src/ignore.rs
(1 hunks)src/main.rs
(1 hunks)src/ui.rs
(4 hunks)
✅ Files skipped from review due to trivial changes (1)
- .gitignore
🔇 Additional comments (2)
src/main.rs (1)
8-8
: LGTM: Module declaration is correctly integrated
The new ignore module is properly declared alongside other modules.
src/ignore.rs (1)
6-6
: 🛠️ Refactor suggestion
Use platform-independent path handling
The hardcoded path separator in the constant might cause issues on different platforms.
-const IGNORE_FILE: &str = "adcignore.txt";
+const IGNORE_FILE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/adcignore.txt");
Likely invalid or redundant comment.
pub fn save_ignored_folders(ignored: &HashSet<String>) { | ||
if let Ok(mut file) = OpenOptions::new().write(true).create(true).truncate(true).open(IGNORE_FILE) { | ||
for folder in ignored { | ||
writeln!(file, "{}", folder).unwrap(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle errors properly in save_ignored_folders
The function uses unwrap() which could panic and silently ignores file operation errors.
-pub fn save_ignored_folders(ignored: &HashSet<String>) {
+pub fn save_ignored_folders(ignored: &HashSet<String>) -> io::Result<()> {
- if let Ok(mut file) = OpenOptions::new().write(true).create(true).truncate(true).open(IGNORE_FILE) {
- for folder in ignored {
- writeln!(file, "{}", folder).unwrap();
- }
- }
+ let mut file = OpenOptions::new()
+ .write(true)
+ .create(true)
+ .truncate(true)
+ .open(IGNORE_FILE)?;
+
+ for folder in ignored {
+ writeln!(file, "{}", folder)?;
+ }
+ Ok(())
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pub fn save_ignored_folders(ignored: &HashSet<String>) { | |
if let Ok(mut file) = OpenOptions::new().write(true).create(true).truncate(true).open(IGNORE_FILE) { | |
for folder in ignored { | |
writeln!(file, "{}", folder).unwrap(); | |
} | |
} | |
} | |
pub fn save_ignored_folders(ignored: &HashSet<String>) -> io::Result<()> { | |
let mut file = OpenOptions::new() | |
.write(true) | |
.create(true) | |
.truncate(true) | |
.open(IGNORE_FILE)?; | |
for folder in ignored { | |
writeln!(file, "{}", folder)?; | |
} | |
Ok(()) | |
} |
pub fn load_ignored_folders() -> HashSet<String> { | ||
let mut ignored = HashSet::new(); | ||
if let Ok(file) = fs::File::open(IGNORE_FILE) { | ||
for line in io::BufReader::new(file).lines().flatten() { | ||
ignored.insert(line); | ||
} | ||
} | ||
ignored | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Improve error handling and add logging for load_ignored_folders
The function silently ignores file operation errors without logging them.
pub fn load_ignored_folders() -> HashSet<String> {
let mut ignored = HashSet::new();
- if let Ok(file) = fs::File::open(IGNORE_FILE) {
- for line in io::BufReader::new(file).lines().flatten() {
- ignored.insert(line);
- }
+ match fs::File::open(IGNORE_FILE) {
+ Ok(file) => {
+ for line in io::BufReader::new(file).lines() {
+ match line {
+ Ok(line) => ignored.insert(line),
+ Err(e) => {
+ log::error!("Error reading line from {}: {}", IGNORE_FILE, e);
+ false
+ }
+ };
+ }
+ }
+ Err(e) => {
+ log::info!("No ignore file found at {}: {}", IGNORE_FILE, e);
+ }
}
ignored
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
pub fn load_ignored_folders() -> HashSet<String> { | |
let mut ignored = HashSet::new(); | |
if let Ok(file) = fs::File::open(IGNORE_FILE) { | |
for line in io::BufReader::new(file).lines().flatten() { | |
ignored.insert(line); | |
} | |
} | |
ignored | |
} | |
pub fn load_ignored_folders() -> HashSet<String> { | |
let mut ignored = HashSet::new(); | |
match fs::File::open(IGNORE_FILE) { | |
Ok(file) => { | |
for line in io::BufReader::new(file).lines() { | |
match line { | |
Ok(line) => ignored.insert(line), | |
Err(e) => { | |
log::error!("Error reading line from {}: {}", IGNORE_FILE, e); | |
false | |
} | |
}; | |
} | |
} | |
Err(e) => { | |
log::info!("No ignore file found at {}: {}", IGNORE_FILE, e); | |
} | |
} | |
ignored | |
} |
if ui.button("忽略").clicked() { | ||
self.ignored_folders.insert(folder.clone()); | ||
ignore::save_ignored_folders(&self.ignored_folders); | ||
println!("文件夹 '{}' 已被忽略", folder); | ||
log::info!("文件夹 '{}' 已被忽略", folder); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix inconsistent logging and error handling
The code uses both println! and log::info! for logging, and doesn't handle potential errors from save_ignored_folders.
if ui.button("忽略").clicked() {
self.ignored_folders.insert(folder.clone());
- ignore::save_ignored_folders(&self.ignored_folders);
- println!("文件夹 '{}' 已被忽略", folder);
- log::info!("文件夹 '{}' 已被忽略", folder);
+ if let Err(e) = ignore::save_ignored_folders(&self.ignored_folders) {
+ log::error!("无法保存忽略的文件夹: {}", e);
+ } else {
+ log::info!("文件夹 '{}' 已被忽略", folder);
+ }
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
if ui.button("忽略").clicked() { | |
self.ignored_folders.insert(folder.clone()); | |
ignore::save_ignored_folders(&self.ignored_folders); | |
println!("文件夹 '{}' 已被忽略", folder); | |
log::info!("文件夹 '{}' 已被忽略", folder); | |
if ui.button("忽略").clicked() { | |
self.ignored_folders.insert(folder.clone()); | |
if let Err(e) = ignore::save_ignored_folders(&self.ignored_folders) { | |
log::error!("无法保存忽略的文件夹: {}", e); | |
} else { | |
log::info!("文件夹 '{}' 已被忽略", folder); | |
} | |
} |
当前可正常忽略,但是不区分在哪个文件夹下
Summary by CodeRabbit
New Features
Bug Fixes
Documentation