/// <summary> /// Updates the SelectedItems collection based on the content of /// the SelectedValue property. /// </summary> private void UpdateFromSelectedValue() { _ignoreSelectedItemsCollectionChanged++; // Just update the SelectedItems collection content // and let the synchronization be made from UpdateFromSelectedItems(); SelectedItems.Clear(); if (!String.IsNullOrEmpty(SelectedValue)) { List <string> selectedValues = SelectedValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).ToList(); ValueEqualityComparer comparer = new ValueEqualityComparer(); foreach (object item in ItemsCollection) { object itemValue = this.GetItemValue(item); bool isSelected = (itemValue != null) && selectedValues.Contains(itemValue.ToString(), comparer); if (isSelected) { SelectedItems.Add(item); } } } _ignoreSelectedItemsCollectionChanged--; this.UpdateFromSelectedItems(); }
public void ClearMatches() { Items.Clear(); SelectedItems.Clear(); m_TaskMatchesHaveIcons = false; }
/// <summary> /// 行尾列按钮点击回调此方法 /// </summary> /// <param name="item"></param> protected Func <Task <bool> > ClickBeforeDelete(TItem item) => () => { SelectedItems.Clear(); SelectedItems.Add(item); return(Task.FromResult(true)); };
private void RefreshSelectedItems() { DoActionWhenSelecting(() => { //ItemsSource重新绑定时,设置SelectedItems var newCustomSelectedItems = SelectedCoursewares; if (SelectionMode == SelectionMode.Multiple) { SelectedItems.Clear(); foreach (var newSelectedItem in newCustomSelectedItems) { SelectedItems.Add(newSelectedItem); } } else { if (newCustomSelectedItems.Count == 0) { SelectedItem = null; } else { SelectedItem = newCustomSelectedItems[0]; } } }); }
/// <summary> /// 删除数据方法 /// </summary> protected Func <Task> DeleteAsync() => async() => { var ret = false; if (OnDeleteAsync != null) { ret = await OnDeleteAsync(SelectedItems); } else if (UseInjectDataService && DataService != null) { ret = await DataService.DeleteAsync(SelectedItems); } var option = new ToastOption() { Title = DeleteButtonToastTitle }; option.Category = ret ? ToastCategory.Success : ToastCategory.Error; option.Content = string.Format(DeleteButtonToastResultContent, ret ? SuccessText : FailText, Math.Ceiling(option.Delay / 1000.0)); if (ret) { // 删除成功 重新查询 // 由于数据删除导致页码会改变,尤其是最后一页 // 重新计算页码 // https://gitee.com/LongbowEnterprise/BootstrapBlazor/issues/I1UJSL PageIndex = Math.Max(1, Math.Min(PageIndex, int.Parse(Math.Ceiling((TotalCount - SelectedItems.Count) * 1d / PageItems).ToString()))); var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedItems.Count)); PageItems = Math.Min(PageItems, items.Any() ? items.Min() : PageItems); SelectedItems.Clear(); await QueryAsync(); } Toast.Show(option); };
public void SetState(State state) { if (state == null) { SelectedItems.Clear(); } else { if (state.UnstagedSeleted && _unstagedItem != null) { _unstagedItem.IsSelected = true; } if (state.StagedSelected && _stagedItem != null) { _stagedItem.IsSelected = true; } if (state.SelectedRevisions != null) { foreach (var item in state.SelectedRevisions) { RevisionListItem revItem; if (_itemLookupTable.TryGetValue(item, out revItem)) { revItem.IsSelected = true; } } } var scrollPos = state.VScrollPos; if (scrollPos > MaxVScrollPos) { scrollPos = MaxVScrollPos; } VScrollBar.Value = scrollPos; } }
/// <summary> /// Notifies that the collection of selected items has changed in the control. Updates the collection of selected items in the view model. /// This method must be invoked by the implementations of the <see cref="BindableSelectedItemsBehavior{T}"/>. /// </summary> /// <param name="addedItems">The list of items that have been added to the selection.</param> /// <param name="removedItems">The list of items that have been removed from the selection.</param> protected void ControlSelectionChanged(IEnumerable addedItems, IList removedItems) { if (BindableSelectedItemsControl.DisableBindings) { return; } if (SelectedItems != null) { updatingCollection = true; if (removedItems != null) { // Optimize removal if most of the selected items are removed if (removedItems.Count > SelectedItems.Count / 2) { var remainingItems = SelectedItems.Where(x => !removedItems.Contains(x)).ToList(); SelectedItems.Clear(); SelectedItems.AddRange(remainingItems); } else { foreach (var removedItem in removedItems.Cast <object>()) { SelectedItems.Remove(removedItem); } } } if (addedItems != null) { SelectedItems.AddRange(addedItems.Cast <object>().Where(x => !SelectedItems.Contains(x))); } updatingCollection = false; } }
private void HandleSelectionEvent(EventArgs eventArgs) { var selectionChanged = (SelectionChangedEventArgs)eventArgs; selectionChanged.Handled = true; if (_itemsReloaded) { SelectedItems.Clear(); _itemsReloaded = false; } var addedItems = selectionChanged.AddedItems.Cast <IFileSystemItem>(); var removedItems = selectionChanged.RemovedItems.Cast <IFileSystemItem>(); foreach (var addedItem in addedItems) { SelectedItems.Add(addedItem); } foreach (var removedItem in removedItems) { SelectedItems.RemoveAll(element => element.Path == removedItem.Path); } }
/// <summary> /// Get items in frame and select them. /// </summary> private void _SelectInFrame() { Debug.Assert(SelectedItems != null); Debug.Assert(_selectionFrame != null); Debug.Assert(_clustering != null); ESRI.ArcGIS.Client.Geometry.Envelope frame = _selectionFrame.Geometry.Extent; if (Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control) { SelectedItems.Clear(); } for (int index = _objectLayers.Count - 1; index >= 0; index--) { ObjectLayer objectLayer = _objectLayers[index]; if (objectLayer == _clustering.ClusteringLayer) { continue; } if (objectLayer.Selectable && !objectLayer.SingleSelection) { //Get elements in selection frame List <object> elementsInFrame = _GetElementsInSelectionFrame(objectLayer, frame); _ProcessSelectionChanges(elementsInFrame, objectLayer); } } }
public async Task SetSelectedItem(Item item) { if (SelectedItems == null) { SelectedItems = new List <Item>(); } if (IsSelected(item)) { SelectedItems.Remove(item); SelectedItem = default; } else { if (!MultiSelect) { SelectedItems.Clear(); } SelectedItems.Add(item); } SelectedItem = item; await UpdateSelected(); }
public void UnselectAll() { if (MultiSelect) { SelectedItems.Clear(); } }
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e) { base.OnMouseLeftButtonUp(e); if (iDelayClickAction) { var listViewItem = (e.OriginalSource as DependencyObject).FindVisualAncestor <ListViewItem>(); var clickedItem = listViewItem == null ? null : ItemContainerGenerator.ItemFromContainer(listViewItem); if (clickedItem != null) { if (Keyboard.Modifiers == ModifierKeys.None) { SelectedItems.Clear(); SelectedItem = clickedItem; } else if (Keyboard.Modifiers == ModifierKeys.Control) { SelectedItems.Remove(clickedItem); } } } iDelayClickAction = false; }
private void TokenizingTextBoxItem_Click(object sender, RoutedEventArgs e) { if (sender is TokenizingTextBoxItem item) { bool isControlDown = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); if (!item.IsSelected && !isControlDown) { foreach (var child in _wrapPanel.Children) { if (child is TokenizingTextBoxItem childItem) { childItem.IsSelected = false; } } SelectedItems.Clear(); } item.IsSelected = !item.IsSelected; var clickedItem = item.Content; if (item.IsSelected) { SelectedItems.Add(clickedItem); } else { SelectedItems.Remove(clickedItem); } TokenItemClicked?.Invoke(this, item); // TODO: Do we want to use EventArgs here to have the OriginalSource like ItemClickEventArgs? } }
public void Receive(object message) { var columns = (List <string>)message; UnselectedItems = new ObservableCollection <string>(columns); SelectedItems.Clear(); }
/// <summary> /// 删除数据方法 /// </summary> protected async Task DeleteAsync() { var ret = false; if (OnDeleteAsync != null) { ret = await OnDeleteAsync(SelectedItems); } var option = new ToastOption() { Title = "删除数据" }; option.Category = ret ? ToastCategory.Success : ToastCategory.Error; option.Content = $"删除数据{(ret ? "成功" : "失败")}, {Math.Ceiling(option.Delay / 1000.0)} 秒后自动关闭"; if (ret) { SelectedItems.Clear(); // 删除成功 重新查询 // 由于数据删除导致页码会改变,尤其是最后一页 // 重新计算页码 PageIndex = Math.Max(1, Math.Min(PageIndex, (TotalCount - SelectedItems.Count) / PageItems)); var items = PageItemsSource.Where(item => item >= (TotalCount - SelectedItems.Count)); PageItems = Math.Min(PageItems, items.Any() ? items.Min() : PageItems); await QueryAsync(); } Toast?.Show(option); }
/// <summary> /// Process data graphic mouse events. /// </summary> /// <param name="dataGraphic">Data graphic.</param> /// <param name="clickedGraphic">Last clicked item.</param> private void _ProcessDataGraphicMouseEvents(DataGraphicObject dataGraphic, Graphic clickedGraphic) { Debug.Assert(dataGraphic != null); Debug.Assert(_mapControl != null); ObjectLayer layer = _FindObjectLayer(dataGraphic); // Candidates selects not in common map selected items, but diretly in object layer. if (dataGraphic is CandidateGraphicObject) { _AddToSelection(dataGraphic.Data); } else if (layer != null && layer.Selectable && !_mapControl.IsInEditedMode) { // Check down and up points equals. if (clickedGraphic == dataGraphic && layer.Selectable) { // Do not need to clear selection and return the same element. if (!(SelectedItems.Count == 1 && SelectedItems[0] == dataGraphic.Data)) { if (Keyboard.Modifiers != ModifierKeys.Shift && Keyboard.Modifiers != ModifierKeys.Control && SelectedItems.Count > 0) { SelectedItems.Clear(); } SelectionWasMade = true; List <object> elementList = new List <object>(); elementList.Add(dataGraphic.Data); _ProcessSelectionChanges(elementList, layer); } } } }
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Remove: case NotifyCollectionChangedAction.Replace: if (e.OldItems != null) { foreach (var item in e.OldItems) { SelectedItems.Remove(item); // Don't preview and ask, it is already gone so it must be removed from // the SelectedItems list } } break; case NotifyCollectionChangedAction.Reset: // If the items list has considerably changed, the selection is probably // useless anyway, clear it entirely. SelectedItems.Clear(); break; } base.OnItemsChanged(e); }
private void ChatsMarkExecute() { var chats = SelectedItems.ToList(); var unread = chats.Any(x => x.IsUnread()); foreach (var chat in chats) { if (unread) { if (chat.UnreadCount > 0) { ProtoService.Send(new ViewMessages(chat.Id, 0, new[] { chat.LastMessage.Id }, true)); } else if (chat.IsMarkedAsUnread) { ProtoService.Send(new ToggleChatIsMarkedAsUnread(chat.Id, false)); } if (chat.UnreadMentionCount > 0) { ProtoService.Send(new ReadAllChatMentions(chat.Id)); } } else if (chat.UnreadCount == 0 && !chat.IsMarkedAsUnread) { ProtoService.Send(new ToggleChatIsMarkedAsUnread(chat.Id, true)); } } Delegate?.SetSelectionMode(false); SelectedItems.Clear(); }
private void OnKeyDown(object sender, KeyEventArgs e) { if (!IsDropDownOpen) { if (KeyboardUtilities.IsKeyModifyingPopupState(e)) { IsDropDownOpen = true; // Popup_Opened() will Focus on ComboBoxItem. e.Handled = true; } } else { if (KeyboardUtilities.IsKeyModifyingPopupState(e)) { CloseDropDown(true); e.Handled = true; } else if (e.Key == Key.Enter) { CloseDropDown(true); e.Handled = true; } else if (e.Key == Key.Escape) { SelectedItems.Clear(); foreach (object o in _initialValue) { SelectedItems.Add(o); } CloseDropDown(true); e.Handled = true; } } }
private async void ChatsClearExecute() { var chats = SelectedItems.ToList(); var confirm = await MessagePopup.ShowAsync(Strings.Resources.AreYouSureClearHistoryFewChats, Locale.Declension("ChatsSelected", chats.Count), Strings.Resources.ClearHistory, Strings.Resources.Cancel); if (confirm == ContentDialogResult.Primary) { Delegate?.ShowChatsUndo(chats, UndoType.Clear, items => { foreach (var undo in items) { _deletedChats.Remove(undo.Id); Items.Handle(undo.Id, undo.Positions); } }, items => { var clear = items.FirstOrDefault(); if (clear == null) { return; } ProtoService.Send(new DeleteChatHistory(clear.Id, false, false)); }); } Delegate?.SetSelectionMode(false); SelectedItems.Clear(); }
public override void RowSelected(UITableView tableView, NSIndexPath indexPath) { NSIndexPath [] indexPathsToReload = null; if (AllowsMultipleSelection) { var item = AllItems [indexPath.Row]; // Togle selection if (!SelectedItems.Remove(item)) { SelectedItems.Add(item); } indexPathsToReload = new NSIndexPath [] { indexPath }; } else { indexPathsToReload = (SelectedItems.Count == 0) ? new NSIndexPath [] { indexPath } : SelectedItems.Select(f => Array.IndexOf(AllItems, f)) .Select(i => NSIndexPath.FromRowSection(i, 0)) .Concat(indexPath) .ToArray(); SelectedItems.Clear(); SelectedItems.Add(AllItems [indexPath.Row]); } // Deselect the selected row & reload the table view cells for the old and new items to swap checkmarks. tableView.DeselectRow(indexPath, true); tableView.ReloadRows(indexPathsToReload, UITableViewRowAnimation.Automatic); }
/// <summary> /// Select item beneath the mouse, if any /// </summary> /// <param name="x">Mouse X position</param> /// <param name="y">Mouse Y position</param> protected override void OnMouseMoved(float x, float y) { _mouseY = y; if (ListRowLocator != null) { try { int row = ListRowLocator.GetRow(GetAbsoluteBounds(), 0, Items.Count, _mouseY); if (row >= 0 && row < Items.Count) { SelectedItems.Clear(); SelectedItems.Add(row); } else { SelectedItems.Clear(); } } catch (InvalidOperationException e) { } } }
/// <summary> /// Handles the onclick action for table rows. /// This allows the RowClickAction to be optional. /// </summary> private void OnRowClickHandler(TableItem tableItem) { try { RowClickAction?.Invoke(tableItem); } catch (Exception ex) { Logger.LogError(ex, "RowClickAction threw an exception: {0}", ex); } switch (SelectionType) { case SelectionType.None: return; case SelectionType.Single: SelectedItems.Clear(); SelectedItems.Add(tableItem); break; case SelectionType.Multiple: if (SelectedItems.Contains(tableItem)) { SelectedItems.Remove(tableItem); } else { SelectedItems.Add(tableItem); } break; } }
/// <summary> /// Sets the specified model to be the only selected <see cref="BaseModel"/>. /// </summary> /// <param name="model">The model.</param> public bool SetSelection(BaseModel model) { if (FocusedItem != model) { FocusedItem = model; } if (SelectedItems.Count > 1) { SelectedItems.Clear(); SelectedItems.Add(model); return(true); } else if (SelectedItems.Count == 1) { if (SelectedItems[0] != model) { SelectedItems.Clear(); SelectedItems.Add(model); return(true); } return(false); } else { SelectedItems.Add(model); return(true); } }
/// <summary> /// 行尾列按钮点击回调此方法 /// </summary> /// <param name="item"></param> protected bool ClickDeleteButton(TItem item) { SelectedItems.Clear(); SelectedItems.Add(item); StateHasChanged(); return(true); }
public async Task PlayAll() { await AddToPlaylist(SelectedSubsonicItems.ToList(), true); SelectedItems.Clear(); NavigateOnPlay(); }
/// <summary> /// 单选模式下选择行时调用此方法 /// </summary> /// <param name="val"></param> protected Func <Task> ClickRow(TItem val) => async() => { if (ClickToSelect) { // 多选模式清空 if (!IsMultipleSelect) { SelectedItems.Clear(); } if (SelectedItems.Contains(val)) { SelectedItems.Remove(val); } else { SelectedItems.Add(val); } await OnSelectedRowsChanged(); } if (OnClickRowCallback != null) { await OnClickRowCallback(val); } };
internal void UpdateFromList(List <string> selectedValues, Func <object, object> GetItemfunction) { _ignoreSelectedItemsCollectionChanged++; // Just update the SelectedItems collection content // and let the synchronization be made from UpdateFromSelectedItems(); SelectedItems.Clear(); if ((selectedValues != null) && (selectedValues.Count > 0)) { ValueEqualityComparer comparer = new ValueEqualityComparer(); foreach (object item in ItemsCollection) { object itemValue = GetItemfunction(item); bool isSelected = (itemValue != null) && selectedValues.Contains(itemValue.ToString(), comparer); if (isSelected) { SelectedItems.Add(item); } } } _ignoreSelectedItemsCollectionChanged--; this.UpdateFromSelectedItems(); }
internal void SelectSingleItemCore(object item) { if (SelectedItem != item) { PseudoClasses.Remove(":normal"); PseudoClasses.Add(":normal"); } if (SelectedItem is not null) { (SelectedItem as ISelectable).IsSelected = false; } (item as ISelectable).IsSelected = true; SelectedItems.Clear(); SelectedItems.Add(item); var item_parents = (item as ILogical).GetLogicalAncestors().OfType <NavigationViewItem>(); if (this.IsOpen) { foreach (NavigationViewItem n in item_parents) { n.IsExpanded = true; } } // Debug.WriteLine($"{item_parents.Count()}"); SelectedItem = item; }
public void OnSelectedItemsChanged(IEnumerable <PlaylistItem> selection) { SelectedItems.Clear(); int localSongs = 0; int spotifySongs = 0; int streams = 0; foreach (PlaylistItem item in selection) { SelectedItems.Add(item); if (item.Content is SongMetadata) { SongMetadata song = item.Content as SongMetadata; if (song.IsLocal) { localSongs += 1; } else if (song.IsSpotify) { spotifySongs += 1; } } else if (item.Content is StreamMetadata) { streams += 1; } } NumberOfSelectedLocalSongs = localSongs; NumberOfSelectedSpotifySongs = spotifySongs; NumberOfSelectedStreams = streams; }