public async void DeleteBooks() { var selectedBooks = SelectedBooks?.Cast <Book>(); if (selectedBooks?.Count() > 1) { await _bookManager.DeleteBooks(selectedBooks); _allBooks.RemoveRange(selectedBooks); _recentBooks.RemoveRange(selectedBooks); } else { await _bookManager.DeleteBook(SelectedBook); _allBooks.Remove(SelectedBook); _recentBooks.Remove(SelectedBook); } BooksSelectionMode = ListViewSelectionMode.None; BooksClickEnabled = true; NotifyOfPropertyChange(nameof(RecentBooks)); NotifyOfPropertyChange(nameof(AllBooks)); }
public void when_RemoveRange_is_called_and_IsNotifying_is_false_then_Reset_event_fired() { var testSchedulerProvider = new TestDispatcherSchedulerProvider(); var result = false; var bindableCollection = new BindableCollection <int>(testSchedulerProvider); var items = Enumerable.Range(0, 1).ToList(); bindableCollection.AddRange(items); bindableCollection.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Reset) { result = true; } }; bindableCollection.IsNotifying = false; bindableCollection.RemoveRange(items); Assert.That(result, Is.False); }
public override void CanClose(Action <bool> callback) { CloseStrategy.Execute(items, (canClose, closable) => { if (!canClose && closable.Any()) { if (closable.Contains(ActiveItem)) { var list = items.ToList(); var next = ActiveItem; do { var previous = next; next = DetermineNextItemToActivate(list, list.IndexOf(previous)); list.Remove(previous); } while (closable.Contains(next)); var previousActive = ActiveItem; ChangeActiveItem(next, true); items.Remove(previousActive); var stillToClose = closable.ToList(); stillToClose.Remove(previousActive); closable = stillToClose; } closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } callback(canClose); }); }
public void ClearCompleted() { var result = nativeDialogService.ShowMessageBox(this, "Are you sure?", "Clear Completed", MessageBoxButton.YesNo, MessageBoxImage.Warning); if (result == MessageBoxResult.Yes) { Todos.RemoveRange(Todos.Where(todo => todo.IsCompleted).ToArray()); } }
public void RemoveSubCategories(IList list) { var itemsToDelete = new List <Item>(); var subCategoriesToDelete = list.Cast <SubCategory>().ToList(); foreach (var subCategory in subCategoriesToDelete) { itemsToDelete.AddRange( _shop.Items.Where( x => x.CategoryId == SelectedCategoryIndex && x.SubCategoryId == SubCategories.IndexOf(subCategory) ) ); } _shop.Items.RemoveRange(itemsToDelete); #region MoveItems var index = -1; for (int i = 0; i < _shop.Items.Count; i++) { if (_shop.Items[i].CategoryId == SelectedCategoryIndex) { index++; int subCat = _shop.Items[i].SubCategoryId; int j = i; for (; j < _shop.Items.Count; j++) { if (subCat == _shop.Items[j].SubCategoryId) { while (_shop.Items[j].SubCategoryId > index) { _shop.Items[j].SubCategoryId--; } } else { break; } } i = j - 1; } } #endregion _subCategories.RemoveRange(subCategoriesToDelete); NotifyOfPropertyChange(nameof(SubCategories)); NotifyOfPropertyChange(nameof(Items)); }
private void BuildTrackerConnectionProgressChanged(object sender, BuildTrackerConnectionProgressEventArgs e) { if (ShouldExitHandler(e)) { return; } foreach (var project in e.Projects) { var projectToUpdate = _projects.SingleOrDefault(p => p.Id == project.Id); if (projectToUpdate != null) { projectToUpdate.TryUpdate(project.Name); } else { _application.Dispatcher.Invoke(() => { var projectToAdd = _projectFactory.Create(SettingsId, project.Id, project.Name); var names = _projects.Select(p => p.Name).Concat(new[] { projectToAdd.Name }).OrderBy(name => name).ToArray(); var index = Array.IndexOf(names, projectToAdd.Name); _projects.Insert(index, projectToAdd); }); } } var projectsToKeep = e.Projects.Select(project => project.Id).ToArray(); var projectsToRemove = _projects.Where(project => !projectsToKeep.Contains(project.Id)).ToArray(); if (_projects.Any()) { _application.Dispatcher.Invoke(() => { _projects.RemoveRange(projectsToRemove); }); } _trie = new SuffixTrie <IProjectViewModel>(3); foreach (var project in _projects) { _trie.Add(project.Name.ToLowerInvariant(), project); } IsErrored = false; IsBusy = false; NotifyOfPropertyChange(() => HasProjects); NotifyOfPropertyChange(() => HasNoProjects); NotifyOfPropertyChange(() => IsViewable); }
private void BuildTrackerProjectProgressChanged(object sender, BuildTrackerProjectProgressEventArgs e) { if (ShouldExitHandler(e)) { return; } foreach (var build in e.Builds) { var buildToUpdate = _builds.SingleOrDefault(b => b.Id == build.Id); if (buildToUpdate != null) { buildToUpdate.TryUpdate(e.Project.Name, build.Status, build.StartTime, build.EndTime, build.RunTime()); } else { _application.Dispatcher.Invoke(() => { var buildToAdd = _buildFactory.Create(e.Project.Name, build.Id, build.Branch, build.VersionNumber(), build.RequestedBy, build.Changes, build.Status, build.StartTime, build.EndTime, build.RunTime(), build.WebUrl); var time = new Tuple <DateTime, DateTime>(buildToAdd.EndTime ?? DateTime.MaxValue, buildToAdd.StartTime ?? DateTime.MaxValue); var times = _builds.Select(b => new Tuple <DateTime, DateTime>(b.EndTime ?? DateTime.MaxValue, b.StartTime ?? DateTime.MaxValue)).Concat(new[] { time }).OrderByDescending(t => t.Item1).ThenByDescending(t => t.Item2).ToArray(); var index = Array.IndexOf(times, time); _builds.Insert(index, buildToAdd); }); } } var buildsToKeep = e.Builds.Select(build => build.Id).ToArray(); var buildsToRemove = _builds.Where(build => !buildsToKeep.Contains(build.Id)).ToArray(); if (buildsToRemove.Any()) { _application.Dispatcher.Invoke(() => { _builds.RemoveRange(buildsToRemove); }); } IsErrored = false; IsBusy = false; NotifyOfPropertyChange(() => HasBuilds); NotifyOfPropertyChange(() => HasNoBuilds); NotifyOfPropertyChange(() => LatestBuild); NotifyOfPropertyChange(() => HasLatestBuild); NotifyOfPropertyChange(() => QueuedBuilds); NotifyOfPropertyChange(() => HasQueuedBuilds); NotifyOfPropertyChange(() => IsViewable); }
/// <summary> /// Called to check whether or not this instance can close. /// </summary> /// <param name="callback">The implementor calls this action with the result of the close check.</param> public override void CanClose(Action <bool> callback) { CloseStrategy.Execute(items, (canClose, closable) => { if (!canClose && closable.Any()) { closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } callback(canClose); }); }
public AddSpecializationViewModel(SpecializationDTO specialization) { AvailableEquipment = new BindableCollection <EquipmentDTO>(EquipmentService.GetAll().ToList()); BindableCollection <EquipmentDTO> abc = new BindableCollection <EquipmentDTO>(); foreach (var a in AvailableEquipment) { bool toDelete = false; foreach (var b in a.Specialization) { if (b.Id == specialization.Id) { toDelete = true; } } if (toDelete) { abc.Add(a); } } AvailableEquipment.RemoveRange(abc); ActualEquipment = new BindableCollection <EquipmentDTO>(EquipmentService.GetAll().Where(x => x.Specialization.Where(y => y.Id == specialization.Id).Any()).ToList()); AvailablePermissions = new BindableCollection <PermissionDTO>(PermissionService.GetAll().ToList()); BindableCollection <PermissionDTO> abc1 = new BindableCollection <PermissionDTO>(); foreach (var a in AvailablePermissions) { bool toDelete = false; foreach (var b in a.Specialization) { if (b.Id == specialization.Id) { toDelete = true; } } if (toDelete) { abc1.Add(a); } } AvailablePermissions.RemoveRange(abc1); ActualPermissions = new BindableCollection <PermissionDTO>(PermissionService.GetAll().Where(x => x.Specialization.Where(y => y.Id == specialization.Id).Any()).ToList()); IsEdit = true; ButtonLabel = "Edit"; this.toEdit = specialization; Name = toEdit.Name; Description = toEdit.Description; NotifyOfPropertyChange(() => Name); NotifyOfPropertyChange(() => Description); }
/// <summary> /// Called to check whether or not this instance can close. /// </summary> /// <param name="cancellationToken">The cancellation token to cancel operation.</param> /// <returns>A task that represents the asynchronous operation.</returns> public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken) { var closeResult = await CloseStrategy.ExecuteAsync(_items.ToArray(), cancellationToken); if (!closeResult.CloseCanOccur && closeResult.Children.Any()) { foreach (var deactivate in closeResult.Children.OfType <IActivate>()) { await deactivate.DeactivateAsync(true, cancellationToken); } _items.RemoveRange(closeResult.Children); } return(closeResult.CloseCanOccur); }
public void RemoveRangeFiresPropertyChangedAfterRemovingItems() { var itemsToRemove = new[] { new Element(), new Element() }; var collection = new BindableCollection <Element>(new[] { new Element() }.Concat(itemsToRemove)); var changedProperties = new List <string>(); ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => { Assert.AreEqual(1, collection.Count); changedProperties.Add(e.PropertyName); }; collection.RemoveRange(itemsToRemove); Assert.That(changedProperties, Is.EquivalentTo(new[] { "Count", "Item[]" })); }
public void RemoveRangeUsesDispatcherToRemoveElements() { var itemsToRemove = new[] { new Element(), new Element() }; var existingItems = new[] { new Element() }; var collection = new BindableCollection<Element>(itemsToRemove.Concat(existingItems)); var dispatcher = new TestDispatcher(); Execute.Dispatcher = dispatcher; collection.RemoveRange(itemsToRemove); Assert.That(collection, Is.EquivalentTo(itemsToRemove.Concat(existingItems))); Assert.NotNull(dispatcher.SendAction); dispatcher.SendAction(); Assert.AreEqual(existingItems, collection); }
public void RemoveRangeUsesDispatcherToRemoveElements() { var itemsToRemove = new[] { new Element(), new Element() }; var existingItems = new[] { new Element() }; var collection = new BindableCollection <Element>(itemsToRemove.Concat(existingItems)); var dispatcher = new TestDispatcher(); Execute.Dispatcher = dispatcher; collection.RemoveRange(itemsToRemove); Assert.That(collection, Is.EquivalentTo(itemsToRemove.Concat(existingItems))); Assert.NotNull(dispatcher.SendAction); dispatcher.SendAction(); Assert.AreEqual(existingItems, collection); }
public void RemoveRangeFiresCollectionChangedAfterRemovingItems() { var itemsToRemove = new[] { new Element(), new Element() }; var collection = new BindableCollection <Element>(new[] { new Element() }.Concat(itemsToRemove)); var changedEvents = new List <NotifyCollectionChangedEventArgs>(); collection.CollectionChanged += (o, e) => { Assert.AreEqual(1, collection.Count); changedEvents.Add(e); }; collection.RemoveRange(itemsToRemove); Assert.AreEqual(1, changedEvents.Count); var changedEvent = changedEvents[0]; Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action); }
/// <summary> /// Initializes a new instance of the <see cref="Conductor<T>.Collection.AllActive"/> class. /// </summary> public AllActive() { items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: items.OfType <IChild>().Apply(x => x.Parent = this); break; } }; CloseGuard = () => { var tcs = new TaskCompletionSource <bool>(); CloseStrategy.Execute(items.ToList(), (canClose, closable) => { if (!canClose && closable.Any()) { closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } tcs.SetResult(canClose); }); return(tcs.Task); }; }
public void RemoveRangeFiresCollectionChangingBeforeRemovingItems() { var collection = new BindableCollection <Element>() { new Element() }; var changedEvents = new List <NotifyCollectionChangedEventArgs>(); collection.CollectionChanging += (o, e) => { changedEvents.Add(e); Assert.AreEqual(1, collection.Count); }; collection.RemoveRange(new[] { new Element() }); Assert.AreEqual(1, changedEvents.Count); var changedEvent = changedEvents[0]; Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action); }
/// <summary> /// Called to check whether or not this instance can close. /// </summary> /// <param name="cancellationToken">The cancellation token to cancel operation.</param> /// <returns>A task that represents the asynchronous operation.</returns> public override async Task <bool> CanCloseAsync(CancellationToken cancellationToken) { var closeResult = await CloseStrategy.ExecuteAsync(_items.ToArray(), cancellationToken); if (!closeResult.CloseCanOccur && closeResult.Children.Any()) { var closable = closeResult.Children; if (closable.Contains(ActiveItem)) { var list = _items.ToList(); var next = ActiveItem; do { var previous = next; next = DetermineNextItemToActivate(list, list.IndexOf(previous)); list.Remove(previous); } while (closable.Contains(next)); var previousActive = ActiveItem; await ChangeActiveItemAsync(next, true, cancellationToken); _items.Remove(previousActive); var stillToClose = closable.ToList(); stillToClose.Remove(previousActive); closable = stillToClose; } foreach (var deactivate in closable.OfType <IActivate>()) { await deactivate.DeactivateAsync(true, cancellationToken); } _items.RemoveRange(closable); } return(closeResult.CloseCanOccur); }
public MainViewModel(IWindowManager windowManager, ProfileService profileService, CompilerService compilerService) : this() { _windowManager = windowManager; _profileService = profileService; _compilerService = compilerService; _ctsTools = new CancellationTokenSource(); Summary = new BindableCollection <KeyValuePair <string, string> >(); Profiles = new BindableCollection <Profile>(_profileService.Profiles); ((INotifyCollectionChanged)_profileService.Profiles).CollectionChanged += (sender, args) => { switch (args.Action) { case NotifyCollectionChangedAction.Add: Profiles.AddRange(args.NewItems.Cast <Profile>()); break; case NotifyCollectionChangedAction.Remove: Profiles.RemoveRange(args.OldItems.Cast <Profile>()); break; } }; // if (!ToolsExistValidation.CheckToolsExistence(ToolsFolderPath)) { FindToolsAsync(); } // Validate(); }
/// <summary> /// Initializes a new instance of the <see cref="Conductor<T>.Collection.OneActive"/> class. /// </summary> public OneActive() { items.CollectionChanged += (s, e) => { switch (e.Action) { case NotifyCollectionChangedAction.Add: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); break; case NotifyCollectionChangedAction.Remove: e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Replace: e.NewItems.OfType <IChild>().Apply(x => x.Parent = this); e.OldItems.OfType <IChild>().Apply(x => x.Parent = null); break; case NotifyCollectionChangedAction.Reset: items.OfType <IChild>().Apply(x => x.Parent = this); break; } }; CloseGuard = () => { var tcs = new TaskCompletionSource <bool>(); CloseStrategy.Execute(items.ToList(), (canClose, closable) => { if (!canClose && closable.Any()) { if (closable.Contains(ActiveItem)) { var list = items.ToList(); var next = ActiveItem; do { var previous = next; next = DetermineNextItemToActivate(list, list.IndexOf(previous)); list.Remove(previous); } while (closable.Contains(next)); var previousActive = ActiveItem; ChangeActiveItem(next, true); items.Remove(previousActive); var stillToClose = closable.ToList(); stillToClose.Remove(previousActive); closable = stillToClose; } closable.OfType <IDeactivate>().Apply(x => x.Deactivate(true)); items.RemoveRange(closable); } tcs.SetResult(canClose); }); return(tcs.Task); }; }
public void RemoveRangeFiresPropertyChangedAfterRemovingItems() { var itemsToRemove = new[] { new Element(), new Element() }; var collection = new BindableCollection<Element>(new[] { new Element() }.Concat(itemsToRemove)); var changedProperties = new List<string>(); ((INotifyPropertyChanged)collection).PropertyChanged += (o, e) => { Assert.AreEqual(1, collection.Count); changedProperties.Add(e.PropertyName); }; collection.RemoveRange(itemsToRemove); Assert.That(changedProperties, Is.EquivalentTo(new[] { "Count", "Item[]" })); }
public void when_RemoveRange_is_called_then_Reset_event_fired() { var testSchedulerProvider = new TestDispatcherSchedulerProvider(); var result = false; var bindableCollection = new BindableCollection<int>(testSchedulerProvider); var items = Enumerable.Range(0, 1).ToList(); bindableCollection.AddRange(items); bindableCollection.CollectionChanged += (sender, args) => { if (args.Action == NotifyCollectionChangedAction.Reset) { result = true; } }; bindableCollection.RemoveRange(items); Assert.That(result, Is.True); }
public void RemoveRangeFiresCollectionChangingBeforeRemovingItems() { var collection = new BindableCollection<Element>() { new Element() }; var changedEvents = new List<NotifyCollectionChangedEventArgs>(); collection.CollectionChanging += (o, e) => { changedEvents.Add(e); Assert.AreEqual(1, collection.Count); }; collection.RemoveRange(new[] { new Element() }); Assert.AreEqual(1, changedEvents.Count); var changedEvent = changedEvents[0]; Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action); }
public void RemoveRangeFiresCollectionChangedAfterRemovingItems() { var itemsToRemove = new[] { new Element(), new Element() }; var collection = new BindableCollection<Element>(new[] { new Element() }.Concat(itemsToRemove)); var changedEvents = new List<NotifyCollectionChangedEventArgs>(); collection.CollectionChanged += (o, e) => { Assert.AreEqual(1, collection.Count); changedEvents.Add(e); }; collection.RemoveRange(itemsToRemove); Assert.AreEqual(1, changedEvents.Count); var changedEvent = changedEvents[0]; Assert.AreEqual(NotifyCollectionChangedAction.Reset, changedEvent.Action); }