From 503e0fc62fa2f8e07d8245dce3907ca75086023a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 15 Mar 2026 02:11:38 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9A=A1=20Optimize=20UI=20updates=20by=20?= =?UTF-8?q?batching=20collection=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced the one-by-one addition of instructions to `_currentPlan` with a batch creation and assignment. This significantly reduces the number of `CollectionChanged` events and UI thread blocking when loading large analysis plans. Co-authored-by: gonzoga <6003443+gonzoga@users.noreply.github.com> --- FileOrganizer/MainWindow.xaml.cs | 328 +++++++++++++++---------------- 1 file changed, 163 insertions(+), 165 deletions(-) diff --git a/FileOrganizer/MainWindow.xaml.cs b/FileOrganizer/MainWindow.xaml.cs index 3279b93..2d1fc6e 100644 --- a/FileOrganizer/MainWindow.xaml.cs +++ b/FileOrganizer/MainWindow.xaml.cs @@ -1,166 +1,164 @@ -using System; -using System.Collections.Generic; -using System.Windows; -using Microsoft.Win32; -using FileOrganizer.Models; -using FileOrganizer.Engines; -using System.Collections.ObjectModel; -using System.Linq; -using System.Threading.Tasks; - -namespace FileOrganizer -{ - public partial class MainWindow : Window - { - private ObservableCollection _currentPlan = new ObservableCollection(); - private readonly AnalysisEngine _analysisEngine; - private readonly ExecutionEngine _executionEngine; - - public MainWindow() - { - InitializeComponent(); - _analysisEngine = new AnalysisEngine(new RoutingEngine(), new PdfHeuristic(), new MetadataEngine()); - _executionEngine = new ExecutionEngine(); - } - - private void SelectSourceButton_Click(object sender, RoutedEventArgs e) - { - var dialog = new OpenFolderDialog { Title = "Select Source Folder" }; - if (dialog.ShowDialog() == true) - { - SourceTextBox.Text = dialog.FolderName; - ClearPlan(); - } - } - - private void SelectDestButton_Click(object sender, RoutedEventArgs e) - { - var dialog = new OpenFolderDialog { Title = "Select Destination Folder" }; - if (dialog.ShowDialog() == true) - { - DestTextBox.Text = dialog.FolderName; - ClearPlan(); - } - } - - private async void AnalyzeButton_Click(object sender, RoutedEventArgs e) - { - if (string.IsNullOrWhiteSpace(SourceTextBox.Text) || string.IsNullOrWhiteSpace(DestTextBox.Text)) - { - MessageBox.Show("Please select both source and destination folders.", "Missing Paths", MessageBoxButton.OK, MessageBoxImage.Warning); - return; - } - - try - { - bool isCopyMode = CopyModeCheckBox.IsChecked == true; - string sourcePath = SourceTextBox.Text; - string destPath = DestTextBox.Text; - - AnalyzeButton.IsEnabled = false; - ExecuteButton.IsEnabled = false; - StatusTextBlock.Text = "Analysis Pending..."; - ActionProgressBar.Visibility = Visibility.Collapsed; - ProgressLabelText.Visibility = Visibility.Collapsed; - ProgressPercentText.Visibility = Visibility.Collapsed; - - LoadingOverlay.Visibility = Visibility.Visible; - InstructionsListView.IsEnabled = false; - - _currentPlan.Clear(); - InstructionsListView.ItemsSource = _currentPlan; - - var instructions = await Task.Run(() => _analysisEngine.Analyze(sourcePath, destPath, isCopyMode)); - - foreach(var instruction in instructions) - { - _currentPlan.Add(instruction); - } - - ExecuteButton.IsEnabled = _currentPlan.Any(); - - if (!_currentPlan.Any()) - { - StatusTextBlock.Text = "No Files Found"; - MessageBox.Show("No files found or no actions needed.", "Analysis Complete", MessageBoxButton.OK, MessageBoxImage.Information); - } - else - { - StatusTextBlock.Text = "Analysis Complete"; - } - } - catch (Exception ex) - { - MessageBox.Show($"Error during analysis: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - } - finally - { - LoadingOverlay.Visibility = Visibility.Collapsed; - InstructionsListView.IsEnabled = true; - AnalyzeButton.IsEnabled = true; - } - } - - private async void ExecuteButton_Click(object sender, RoutedEventArgs e) - { - if (!_currentPlan.Any()) return; - - try - { - bool isCopyMode = CopyModeCheckBox.IsChecked == true; - - ExecuteButton.IsEnabled = false; - AnalyzeButton.IsEnabled = false; - ActionProgressBar.Value = 0; - StatusTextBlock.Text = "Executing Plan..."; - ActionProgressBar.Visibility = Visibility.Visible; - ProgressLabelText.Visibility = Visibility.Visible; - ProgressPercentText.Visibility = Visibility.Visible; - ProgressPercentText.Text = "0%"; - - var progress = new Progress(percent => - { - ActionProgressBar.Value = percent; - ProgressPercentText.Text = $"{percent}%"; - }); - - await Task.Run(() => _executionEngine.Execute(_currentPlan.ToList(), isCopyMode, progress)); - - StatusTextBlock.Text = "Execution Complete"; - MessageBox.Show("Task Complete.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); - ClearPlan(); - } - catch (Exception ex) - { - MessageBox.Show($"Error during execution: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); - ExecuteButton.IsEnabled = true; - AnalyzeButton.IsEnabled = true; - } - finally - { - } - } - - private void ClearPlan() - { - _currentPlan.Clear(); - InstructionsListView.ItemsSource = null; - ExecuteButton.IsEnabled = false; - StatusTextBlock.Text = "Pending Analysis"; - ActionProgressBar.Visibility = Visibility.Collapsed; - ProgressLabelText.Visibility = Visibility.Collapsed; - ProgressPercentText.Visibility = Visibility.Collapsed; - } - - private void CloseButton_Click(object sender, RoutedEventArgs e) - { - this.Close(); - } - - private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) - { - if (e.ChangedButton == System.Windows.Input.MouseButton.Left) - this.DragMove(); - } - } +using System; +using System.Collections.Generic; +using System.Windows; +using Microsoft.Win32; +using FileOrganizer.Models; +using FileOrganizer.Engines; +using System.Collections.ObjectModel; +using System.Linq; +using System.Threading.Tasks; + +namespace FileOrganizer +{ + public partial class MainWindow : Window + { + private ObservableCollection _currentPlan = new ObservableCollection(); + private readonly AnalysisEngine _analysisEngine; + private readonly ExecutionEngine _executionEngine; + + public MainWindow() + { + InitializeComponent(); + _analysisEngine = new AnalysisEngine(new RoutingEngine(), new PdfHeuristic(), new MetadataEngine()); + _executionEngine = new ExecutionEngine(); + } + + private void SelectSourceButton_Click(object sender, RoutedEventArgs e) + { + var dialog = new OpenFolderDialog { Title = "Select Source Folder" }; + if (dialog.ShowDialog() == true) + { + SourceTextBox.Text = dialog.FolderName; + ClearPlan(); + } + } + + private void SelectDestButton_Click(object sender, RoutedEventArgs e) + { + var dialog = new OpenFolderDialog { Title = "Select Destination Folder" }; + if (dialog.ShowDialog() == true) + { + DestTextBox.Text = dialog.FolderName; + ClearPlan(); + } + } + + private async void AnalyzeButton_Click(object sender, RoutedEventArgs e) + { + if (string.IsNullOrWhiteSpace(SourceTextBox.Text) || string.IsNullOrWhiteSpace(DestTextBox.Text)) + { + MessageBox.Show("Please select both source and destination folders.", "Missing Paths", MessageBoxButton.OK, MessageBoxImage.Warning); + return; + } + + try + { + bool isCopyMode = CopyModeCheckBox.IsChecked == true; + string sourcePath = SourceTextBox.Text; + string destPath = DestTextBox.Text; + + AnalyzeButton.IsEnabled = false; + ExecuteButton.IsEnabled = false; + StatusTextBlock.Text = "Analysis Pending..."; + ActionProgressBar.Visibility = Visibility.Collapsed; + ProgressLabelText.Visibility = Visibility.Collapsed; + ProgressPercentText.Visibility = Visibility.Collapsed; + + LoadingOverlay.Visibility = Visibility.Visible; + InstructionsListView.IsEnabled = false; + + _currentPlan.Clear(); + InstructionsListView.ItemsSource = _currentPlan; + + var instructions = await Task.Run(() => _analysisEngine.Analyze(sourcePath, destPath, isCopyMode)); + + _currentPlan = new ObservableCollection(instructions); + InstructionsListView.ItemsSource = _currentPlan; + + ExecuteButton.IsEnabled = _currentPlan.Any(); + + if (!_currentPlan.Any()) + { + StatusTextBlock.Text = "No Files Found"; + MessageBox.Show("No files found or no actions needed.", "Analysis Complete", MessageBoxButton.OK, MessageBoxImage.Information); + } + else + { + StatusTextBlock.Text = "Analysis Complete"; + } + } + catch (Exception ex) + { + MessageBox.Show($"Error during analysis: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + } + finally + { + LoadingOverlay.Visibility = Visibility.Collapsed; + InstructionsListView.IsEnabled = true; + AnalyzeButton.IsEnabled = true; + } + } + + private async void ExecuteButton_Click(object sender, RoutedEventArgs e) + { + if (!_currentPlan.Any()) return; + + try + { + bool isCopyMode = CopyModeCheckBox.IsChecked == true; + + ExecuteButton.IsEnabled = false; + AnalyzeButton.IsEnabled = false; + ActionProgressBar.Value = 0; + StatusTextBlock.Text = "Executing Plan..."; + ActionProgressBar.Visibility = Visibility.Visible; + ProgressLabelText.Visibility = Visibility.Visible; + ProgressPercentText.Visibility = Visibility.Visible; + ProgressPercentText.Text = "0%"; + + var progress = new Progress(percent => + { + ActionProgressBar.Value = percent; + ProgressPercentText.Text = $"{percent}%"; + }); + + await Task.Run(() => _executionEngine.Execute(_currentPlan.ToList(), isCopyMode, progress)); + + StatusTextBlock.Text = "Execution Complete"; + MessageBox.Show("Task Complete.", "Success", MessageBoxButton.OK, MessageBoxImage.Information); + ClearPlan(); + } + catch (Exception ex) + { + MessageBox.Show($"Error during execution: {ex.Message}", "Error", MessageBoxButton.OK, MessageBoxImage.Error); + ExecuteButton.IsEnabled = true; + AnalyzeButton.IsEnabled = true; + } + finally + { + } + } + + private void ClearPlan() + { + _currentPlan.Clear(); + InstructionsListView.ItemsSource = null; + ExecuteButton.IsEnabled = false; + StatusTextBlock.Text = "Pending Analysis"; + ActionProgressBar.Visibility = Visibility.Collapsed; + ProgressLabelText.Visibility = Visibility.Collapsed; + ProgressPercentText.Visibility = Visibility.Collapsed; + } + + private void CloseButton_Click(object sender, RoutedEventArgs e) + { + this.Close(); + } + + private void Window_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e) + { + if (e.ChangedButton == System.Windows.Input.MouseButton.Left) + this.DragMove(); + } + } } \ No newline at end of file From e3a3a94cc31cd205435b2ddcba1cf2f4463e4d54 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 15 Mar 2026 04:25:35 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9A=A1=20Optimize=20UI=20updates=20by=20?= =?UTF-8?q?batching=20collection=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaced the one-by-one addition of instructions to `_currentPlan` with a batch creation and assignment. This significantly reduces the number of `CollectionChanged` events and UI thread blocking when loading large analysis plans. Co-authored-by: gonzoga <6003443+gonzoga@users.noreply.github.com>