Skip to content
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

Merged
merged 2 commits into from
Dec 3, 2024
Merged

忽略测试 #11

merged 2 commits into from
Dec 3, 2024

Conversation

TC999
Copy link
Owner

@TC999 TC999 commented Dec 3, 2024

当前可正常忽略,但是不区分在哪个文件夹下

Summary by CodeRabbit

  • New Features

    • Introduced functionality to manage ignored folders, allowing users to specify which folders should be ignored during operations.
    • Added a new button to ignore folders, updating the ignored list dynamically.
  • Bug Fixes

    • Updated logic to ensure ignored folders are displayed correctly and interactively disabled in the UI.
  • Documentation

    • Updated comments and descriptions related to the new ignored folders functionality.

Copy link

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes in this pull request introduce new functionality for managing ignored folders in the application. A new file, adcignore.txt, is added to the .gitignore list, and two public functions are introduced in src/ignore.rs for loading and saving ignored folders. Additionally, the AppDataCleaner struct in src/ui.rs is modified to include a field for these ignored folders, affecting the user interface by enabling or disabling actions based on folder status. A new module for ignore functionality is also added in src/main.rs.

Changes

File Change Summary
.gitignore Added entry adcignore.txt and updated -*.log to +*.log for ignored files.
src/ignore.rs Added functions: pub fn load_ignored_folders() -> HashSet<String> and pub fn save_ignored_folders(ignored: &HashSet<String>).
src/main.rs Added module mod ignore;.
src/ui.rs Modified AppDataCleaner struct to include ignored_folders: HashSet<String>. Updated default implementation and update method to handle ignored folders. Introduced a new button "忽略" (ignore).

Poem

In the burrow, changes bloom,
Ignored folders find their room.
With adcignore.txt in sight,
We tidy up, make things right.
Buttons gray, a gentle sway,
Hop and skip, let’s clear the way! 🐰✨


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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@TC999 TC999 merged commit 01d2552 into main Dec 3, 2024
5 checks passed
Copy link

@coderabbitai coderabbitai bot left a 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 API

Public 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 organization

The 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 folders

The 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

📥 Commits

Reviewing files that changed from the base of the PR and between 84039d3 and c93dea4.

📒 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.

Comment on lines +18 to +24
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();
}
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

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.

Suggested change
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(())
}

Comment on lines +8 to +16
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
}
Copy link

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.

Suggested change
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
}

Comment on lines +195 to +199
if ui.button("忽略").clicked() {
self.ignored_folders.insert(folder.clone());
ignore::save_ignored_folders(&self.ignored_folders);
println!("文件夹 '{}' 已被忽略", folder);
log::info!("文件夹 '{}' 已被忽略", folder);
Copy link

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.

Suggested change
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);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant