public MainWindowViewmodel() { instantiateCommands(); _renamer = new FileRenamer(AppDomain.CurrentDomain.BaseDirectory /*TODO: add the last working dorectory to app.config*/); FileExtensionFilter.CollectionChanged += (s, e) => { _renamer.FileExtensionFilter = FileExtensionFilter.ToArray(); this.RaisePropertyChanged(nameof(FilesToActOn), nameof(ResultingFilenames)); }; }
private void EnumerateFiles() { var dp = (Path as DirectoryInfoEx); if (!_isEnumerationRequired) { return; } _isEnumerationRequired = false; Children.Clear(); if (dp == null) { return; } Children.AddRange(from fsi in dp.GetFileSystemInfos() where _filterAction == null || (!fsi.IsFolder && !(FileExtensionFilter.Contains(fsi.FullName.GetExt()) ^ (bool)_filterAction)) || fsi.IsFolder select new FileTreeViewModel(this, fsi) { _isChecked = _isChecked == true, FileExtensionFilter = FileExtensionFilter, _filterAction = _filterAction }); OnPropertyChanged("IsThreeState"); }
/// <summary> /// Applies the sepcified filter (<see cref="FileExtensionFilter"/>) to the Enumerable input /// </summary> /// <param name="input"></param> /// <returns></returns> public IEnumerable <string> GetTheFilteredFilesByFileType(IEnumerable <string> input) => returnEmptyArrayIfPassedArrayIsEmptyOrFilledWithDefaultValues( input.Where(f => FileExtensionFilter.Any(t => f.EndsWith(t, StringComparison.OrdinalIgnoreCase))).DefaultIfEmpty(string.Empty));
public void Refresh() { if (_isEnumerationRequired) { return; } var dp = (Path as DirectoryInfoEx); if (dp == null) { return; } Children = Children.Intersect(from fsi in dp.GetFileSystemInfos() where _filterAction == null || (!fsi.IsFolder && !(FileExtensionFilter.Contains(fsi.FullName.GetExt()) ^ (bool)_filterAction)) || fsi.IsFolder select new FileTreeViewModel(this, fsi) { _isChecked = _isChecked == true, FileExtensionFilter = FileExtensionFilter, _filterAction = _filterAction }).ToList(); Children.ForEach(m => m.Refresh()); if (IsChecked != null) { SetIsChecked(IsChecked, true, false, true); } else { VerifyCheckState(); } }