/// <summary> /// Retrieve the ISearchResult which will be played when the "play" toolbar button or context menu entry /// is clicked. /// Usually this is the first selected entry in the list. /// </summary> /// <returns></returns> public ISearchResult GetSelectedPlaybackCandidate() { SearchResultListItem item = GetSelectedItems().FirstOrDefault(); if (item != null) { return(item.SearchResult); } else { return(null); } }
/// <summary> /// Update the information panel (below the results list) based on the currently selected entries /// </summary> public void UpdateInformationPanel() { Action action = new Action(() => { IEnumerable <SearchResultListItem> selectedItems = GetSelectedItems(); int count = resultsListView.SelectedIndices.Count; if (count > 1) { // multiple elements selected // show either an appropriate message ("Multiple entries selected") or common info in the info box informationBox.Text = StringResources.PleaseSelectASingleItemToSeeMoreInfo; } else if (count == 1 && selectedItems.First().SearchResult != null) { // Just a single element has been selected string msg = ""; SearchResultListItem item = selectedItems.First(); msg += String.Format(StringResources.Length, (DateTime.Today + item.SearchResult.Duration).ToString("HH::mm::ss.fff")); if (item.SearchResult.ResultType == AudioSearchResultType.MusicFile) { if (item.SearchResult.Tags != null && item.SearchResult.Tags.Count > 0) { msg += Environment.NewLine + StringResources.Tags + item.SearchResult.Tags.Aggregate((s1, s2) => { return(s1 + ";" + s2); }); } else { msg += Environment.NewLine + StringResources.NoTags; } } informationBox.Text = msg; } else if (count < 1) { // no elements selected informationBox.Text = ""; } }); if (InvokeRequired) { Invoke(action); } else { action.Invoke(); } }
/// <summary> /// Determine the AudioSearchResultType of the given selected items. /// The first item's AudioSearchResultType is assumed to apply to all items, but /// this is verified and an InvalidOperationException is thrown if any item in the /// list has a different AudioSearchResultType than the first one. /// </summary> /// <param name="selectedItems"></param> /// <returns></returns> private static AudioSearchResultType FindAndVerifySelectedAudioType(IEnumerable <SearchResultListItem> selectedItems) { // Determine the overall AudioType from the first selected item SearchResultListItem firstItem = selectedItems.First(); AudioSearchResultType overallItemAudioType = firstItem.ItemAudioType; // Make sure all other items' AudioTypes are compatible (the same) foreach (SearchResultListItem item in selectedItems) { if (item.ItemAudioType != overallItemAudioType) { // Show a message to the user that he should only select items of the same type? throw new InvalidOperationException(StringResources.PleaseSelectOnlyEntriesOfTheSameType); } } return(overallItemAudioType); }