void selectItems(MediaSelectionPayload selection) { ICollection <MediaItem> selectedItems = MediaStateCollectionView.getSelectedItems(); if (Enumerable.SequenceEqual(selection.Items, selectedItems)) { return; } if (selection.Items.Count() == 0) { MediaStateCollectionView.deselectAll(); } else { MediaStateCollectionView.selectExclusive(selection.Items.ElementAt(0)); } }
public ImageSearchViewModel() { NrColumns = 4; SearchCommand = new AsyncCommand <int>(async(imageOffset) => { try { if (imageOffset == 0) { CurrentQuery = new ImageSearchQuery(this); } SearchCommand.IsExecutable = false; await doSearch(CurrentQuery, imageOffset); } catch (Exception e) { MessageBox.Show("Image search error\n\n" + e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { SearchCommand.IsExecutable = true; } }); ViewCommand = new Command <SelectableMediaItem>((selectableItem) => { ImageResultItem item = (ImageResultItem)selectableItem.Item; if (item.ImageInfo.ContentType.Equals("image/animatedgif")) { Shell.ShellViewModel.navigateToVideoView(item); } else { Shell.ShellViewModel.navigateToImageView(item); } }); ViewSourceCommand = new Command <SelectableMediaItem>((selectableItem) => { ImageResultItem item = (ImageResultItem)selectableItem.Item; Process.Start(item.ImageInfo.SourceUrl); }); SelectAllCommand = new Command(() => { MediaStateCollectionView.selectAll(); }, false); DeselectAllCommand = new Command(() => { MediaStateCollectionView.deselectAll(); }); CloseCommand = new Command(() => { OnClosingRequest(); }); DownloadCommand = new AsyncCommand <SelectableMediaItem>(async(selectableItem) => { List <MediaItem> items = MediaStateCollectionView.getSelectedItems(); if (items.Count == 0) { items.Add(selectableItem.Item); } String outputPath = null; switch (ImageSearchPlugin.Properties.Settings.Default.ImageSaveMode) { case MediaViewer.Infrastructure.Constants.SaveLocation.Current: { outputPath = MediaFileWatcher.Instance.Path; break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Ask: { DirectoryPickerView directoryPicker = new DirectoryPickerView(); directoryPicker.DirectoryPickerViewModel.InfoString = "Select Output Directory"; directoryPicker.DirectoryPickerViewModel.SelectedPath = MediaFileWatcher.Instance.Path; if (directoryPicker.ShowDialog() == false) { return; } outputPath = directoryPicker.DirectoryPickerViewModel.SelectedPath; break; } case MediaViewer.Infrastructure.Constants.SaveLocation.Fixed: { outputPath = ImageSearchPlugin.Properties.Settings.Default.FixedDownloadPath; break; } default: break; } CancellableOperationProgressView progressView = new CancellableOperationProgressView(); DownloadProgressViewModel vm = new DownloadProgressViewModel(); progressView.DataContext = vm; progressView.Show(); vm.OkCommand.IsExecutable = false; vm.CancelCommand.IsExecutable = true; try { await Task.Factory.StartNew(() => { vm.startDownload(outputPath, items); }, vm.CancellationToken); } catch (Exception) { } vm.OkCommand.IsExecutable = true; vm.CancelCommand.IsExecutable = false; }); SettingsViewModel = (ImageSearchSettingsViewModel)ServiceLocator.Current.GetInstance(typeof(ImageSearchSettingsViewModel)); Size = new ListCollectionView(size); Size.MoveCurrentTo(Settings.Default.Size); SafeSearch = new ListCollectionView(safeSearch); SafeSearch.MoveCurrentTo(Settings.Default.SafeSearch); Layout = new ListCollectionView(layout); Layout.MoveCurrentTo(Settings.Default.Layout); Type = new ListCollectionView(type); Type.MoveCurrentTo(Settings.Default.Type); People = new ListCollectionView(people); People.MoveCurrentTo(Settings.Default.People); Color = new ListCollectionView(color); Color.MoveCurrentTo(Settings.Default.Color); GeoTag = new GeoTagCoordinatePair(); MediaState = new MediaState(); MediaStateCollectionView = new ImageResultCollectionView(MediaState); MediaStateCollectionView.MediaState.MediaStateType = MediaStateType.SearchResult; WeakEventManager <MediaLockedCollection, EventArgs> .AddHandler(MediaStateCollectionView.MediaState.UIMediaCollection, "IsLoadingChanged", mediaCollection_IsLoadingChanged); }