diff --git a/CHANGELOG.md b/CHANGELOG.md index c602b7c1a..1a4f6e1e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## 0.12.2 +As part of this release we had [3 issues](https://github.com/chocolatey/ChocolateyGUI/issues?milestone=8&state=closed) closed. + +__Improvements__ + +- [__#224__](https://github.com/chocolatey/ChocolateyGUI/issues/224) Show package name in details +- [__#223__](https://github.com/chocolatey/ChocolateyGUI/issues/223) Highlight packages where update is available +- [__#222__](https://github.com/chocolatey/ChocolateyGUI/issues/222) Update appveyor.yml configuration + ## 0.12.1 As part of this release we had [4 issues](https://github.com/chocolatey/ChocolateyGUI/issues?milestone=7&state=closed) closed. diff --git a/Source/ChocolateyGui/ViewModels/Controls/LocalSourceControlViewModel.cs b/Source/ChocolateyGui/ViewModels/Controls/LocalSourceControlViewModel.cs index dd99b25dd..58c2e1e67 100644 --- a/Source/ChocolateyGui/ViewModels/Controls/LocalSourceControlViewModel.cs +++ b/Source/ChocolateyGui/ViewModels/Controls/LocalSourceControlViewModel.cs @@ -1,143 +1,162 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace ChocolateyGui.ViewModels.Controls -{ - using System; - using System.Collections.Generic; - using System.Collections.ObjectModel; - using System.ComponentModel; - using System.Globalization; - using System.Linq; - using System.Reactive.Linq; - using System.Threading.Tasks; - using System.Windows; - using ChocolateyGui.Base; - using ChocolateyGui.Models; - using ChocolateyGui.Services; - using ChocolateyGui.Utilities; - using ChocolateyGui.ViewModels.Items; - - public class LocalSourceControlViewModel : ObservableBase, ILocalSourceControlViewModel, IWeakEventListener - { - private readonly IChocolateyService _chocolateyService; - private readonly ILogService _logService; - private readonly List _packages; - private readonly IProgressService _progressService; - private bool _hasLoaded; - - private bool _matchWord; - private ObservableCollection _packageViewModels; - - private string _searchQuery; - - private string _sortColumn; - - private bool _sortDescending; - - public LocalSourceControlViewModel(IChocolateyService chocolateyService, IProgressService progressService, Func logFactory) - { - if (logFactory == null) - { - throw new ArgumentNullException("logFactory"); - } - - this._chocolateyService = chocolateyService; - this._progressService = progressService; - this._logService = logFactory(typeof(LocalSourceControlViewModel)); - PackagesChangedEventManager.AddListener(this._chocolateyService, this); - - this.Packages = new ObservableCollection(); - this._packages = new List(); - } - - public bool MatchWord - { - get { return this._matchWord; } - set { this.SetPropertyValue(ref this._matchWord, value); } - } - - public ObservableCollection Packages - { - get { return this._packageViewModels; } - set { this.SetPropertyValue(ref this._packageViewModels, value); } - } - - public string SearchQuery - { - get { return this._searchQuery; } - set { this.SetPropertyValue(ref this._searchQuery, value); } - } - - public string SortColumn - { - get { return this._sortColumn; } - set { this.SetPropertyValue(ref this._sortColumn, value); } - } - - public bool SortDescending - { - get { return this._sortDescending; } - set { this.SetPropertyValue(ref this._sortDescending, value); } - } - - public bool CanUpdateAll() - { - return this.Packages.Any(p => p.CanUpdate); +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright 2014 - Present Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace ChocolateyGui.ViewModels.Controls +{ + using System; + using System.Collections.Generic; + using System.Collections.ObjectModel; + using System.ComponentModel; + using System.Globalization; + using System.Linq; + using System.Reactive.Linq; + using System.Threading.Tasks; + using System.Windows; + using ChocolateyGui.Base; + using ChocolateyGui.Models; + using ChocolateyGui.Services; + using ChocolateyGui.Utilities; + using ChocolateyGui.ViewModels.Items; + + public class LocalSourceControlViewModel : ObservableBase, ILocalSourceControlViewModel, IWeakEventListener + { + private readonly IChocolateyService _chocolateyService; + private readonly ILogService _logService; + private readonly List _packages; + private readonly IProgressService _progressService; + private bool _hasLoaded; + private bool _matchWord; + private bool _showOnlyPackagesWithUpdate; + private ObservableCollection _packageViewModels; + private string _searchQuery; + private string _sortColumn; + private bool _sortDescending; + + public LocalSourceControlViewModel(IChocolateyService chocolateyService, IProgressService progressService, Func logFactory) + { + if (logFactory == null) + { + throw new ArgumentNullException("logFactory"); + } + + this._chocolateyService = chocolateyService; + this._progressService = progressService; + this._logService = logFactory(typeof(LocalSourceControlViewModel)); + PackagesChangedEventManager.AddListener(this._chocolateyService, this); + + this.Packages = new ObservableCollection(); + this._packages = new List(); + } + + public bool MatchWord + { + get + { + return this._matchWord; + } + + set + { + this.SetPropertyValue(ref this._matchWord, value); + this.ShowOnlyPackagesWithUpdate = false; + } + } + + public bool ShowOnlyPackagesWithUpdate + { + get { return this._showOnlyPackagesWithUpdate; } + set { this.SetPropertyValue(ref this._showOnlyPackagesWithUpdate, value); } + } + + public ObservableCollection Packages + { + get { return this._packageViewModels; } + set { this.SetPropertyValue(ref this._packageViewModels, value); } + } + + public string SearchQuery + { + get + { + return this._searchQuery; + } + + set + { + this.SetPropertyValue(ref this._searchQuery, value); + this.ShowOnlyPackagesWithUpdate = false; + } + } + + public string SortColumn + { + get { return this._sortColumn; } + set { this.SetPropertyValue(ref this._sortColumn, value); } + } + + public bool SortDescending + { + get { return this._sortDescending; } + set { this.SetPropertyValue(ref this._sortDescending, value); } + } + + public bool CanUpdateAll() + { + return this.Packages.Any(p => p.CanUpdate); } public bool CanRefreshPackages() { return this._hasLoaded; } - - public async void Loaded(object sender, EventArgs e) - { - try - { - if (this._hasLoaded) - { - return; - } - - await this.LoadPackages(); - - Observable.FromEventPattern(this, "PropertyChanged") - .Where(eventPattern => eventPattern.EventArgs.PropertyName == "MatchWord" || eventPattern.EventArgs.PropertyName == "SearchQuery") - .ObserveOnDispatcher() - .Subscribe(eventPattern => this.FilterPackages()); - - this._hasLoaded = true; - - var chocoPackage = this._packages.FirstOrDefault(p => p.Id.ToLower() == "chocolatey"); - if (chocoPackage != null && chocoPackage.CanUpdate) - { - this._progressService.ShowMessageAsync("Chocolatey", "There's an update available for chocolatey.").ConfigureAwait(false); - } - } - catch (Exception ex) - { - this._logService.Fatal("Local source control view model failed to load.", ex); - throw; - } - } - - public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) - { - if (sender is IChocolateyService && e is PackagesChangedEventArgs) - { - this.LoadPackages().ConfigureAwait(false); - } - - return true; - } - - public async void UpdateAll() - { - try + + public async void Loaded(object sender, EventArgs e) + { + try + { + if (this._hasLoaded) + { + return; + } + + await this.LoadPackages(); + + Observable.FromEventPattern(this, "PropertyChanged") + .Where(eventPattern => eventPattern.EventArgs.PropertyName == "MatchWord" || eventPattern.EventArgs.PropertyName == "SearchQuery" || eventPattern.EventArgs.PropertyName == "ShowOnlyPackagesWithUpdate") + .ObserveOnDispatcher() + .Subscribe(eventPattern => this.FilterPackages()); + + this._hasLoaded = true; + + var chocoPackage = this._packages.FirstOrDefault(p => p.Id.ToLower() == "chocolatey"); + if (chocoPackage != null && chocoPackage.CanUpdate) + { + this._progressService.ShowMessageAsync("Chocolatey", "There's an update available for chocolatey.").ConfigureAwait(false); + } + } + catch (Exception ex) + { + this._logService.Fatal("Local source control view model failed to load.", ex); + throw; + } + } + + public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) + { + if (sender is IChocolateyService && e is PackagesChangedEventArgs) + { + this.LoadPackages().ConfigureAwait(false); + } + + return true; + } + + public async void UpdateAll() + { + try { await this._progressService.StartLoading("Packages", true); var token = this._progressService.GetCancellationToken(); @@ -154,14 +173,14 @@ public async void UpdateAll() this._progressService.Report(Math.Min((current++) / packages.Count, 100)); await package.Update(); } - - await this._progressService.StopLoading(); - } - catch (Exception ex) - { - this._logService.Fatal("Updated all has failed.", ex); - throw; - } + + await this._progressService.StopLoading(); + } + catch (Exception ex) + { + this._logService.Fatal("Updated all has failed.", ex); + throw; + } } public async void RefreshPackages() @@ -169,58 +188,63 @@ public async void RefreshPackages() this._chocolateyService.ClearPackageCache(); await this.LoadPackages(); } - - private void FilterPackages() - { - this.Packages.Clear(); - if (!string.IsNullOrWhiteSpace(this.SearchQuery)) - { - var query = this.MatchWord - ? this._packages.Where( - package => - string.Compare( - package.Title ?? package.Id, - this.SearchQuery, - StringComparison.OrdinalIgnoreCase) == 0) - : this._packages.Where( - package => - CultureInfo.CurrentCulture.CompareInfo.IndexOf( - package.Title ?? package.Id, - this.SearchQuery, - CompareOptions.OrdinalIgnoreCase) >= 0); - - query.ToList().ForEach(this.Packages.Add); - } - else - { - this.Packages = new ObservableCollection(this._packages); - } - } - - private async Task LoadPackages() - { - try - { - this._packages.Clear(); - this.Packages.Clear(); - - var packages = await this._chocolateyService.GetInstalledPackages(); - foreach (var packageViewModel in packages) - { - this._packages.Add(packageViewModel); - this.Packages.Add(packageViewModel); - - if (packageViewModel.LatestVersion == null) - { - packageViewModel.RetrieveLatestVersion().ConfigureAwait(false); - } - } - } - catch (Exception ex) - { - this._logService.Fatal("Packages failed to load", ex); - throw; - } - } - } -} + + private void FilterPackages() + { + this.Packages.Clear(); + if (!string.IsNullOrWhiteSpace(this.SearchQuery)) + { + var query = this.MatchWord + ? this._packages.Where( + package => + string.Compare( + package.Title ?? package.Id, + this.SearchQuery, + StringComparison.OrdinalIgnoreCase) == 0) + : this._packages.Where( + package => + CultureInfo.CurrentCulture.CompareInfo.IndexOf( + package.Title ?? package.Id, + this.SearchQuery, + CompareOptions.OrdinalIgnoreCase) >= 0); + + query.ToList().ForEach(this.Packages.Add); + } + else if (this.ShowOnlyPackagesWithUpdate) + { + var query = this._packages.Where(p => p.CanUpdate == true); + query.ToList().ForEach(this.Packages.Add); + } + else + { + this.Packages = new ObservableCollection(this._packages); + } + } + + private async Task LoadPackages() + { + try + { + this._packages.Clear(); + this.Packages.Clear(); + + var packages = await this._chocolateyService.GetInstalledPackages(); + foreach (var packageViewModel in packages) + { + this._packages.Add(packageViewModel); + this.Packages.Add(packageViewModel); + + if (packageViewModel.LatestVersion == null) + { + packageViewModel.RetrieveLatestVersion().ConfigureAwait(false); + } + } + } + catch (Exception ex) + { + this._logService.Fatal("Packages failed to load", ex); + throw; + } + } + } +} diff --git a/Source/ChocolateyGui/Views/Controls/LocalSourceControl.xaml b/Source/ChocolateyGui/Views/Controls/LocalSourceControl.xaml index 444fa1acc..89e126996 100644 --- a/Source/ChocolateyGui/Views/Controls/LocalSourceControl.xaml +++ b/Source/ChocolateyGui/Views/Controls/LocalSourceControl.xaml @@ -17,7 +17,9 @@ - + + + diff --git a/Source/ChocolateyGui/Views/Controls/PackageControl.xaml b/Source/ChocolateyGui/Views/Controls/PackageControl.xaml index 29231f4f2..2274740b5 100644 --- a/Source/ChocolateyGui/Views/Controls/PackageControl.xaml +++ b/Source/ChocolateyGui/Views/Controls/PackageControl.xaml @@ -84,6 +84,8 @@ + + @@ -91,23 +93,25 @@ - - - - + + + + + + - + - - +