void UpdateSelection() { var rowsToSelect = new HashSet <nuint>(); void DiscoverSelected(ITreeNode node) // todo: remove linear traversal { if (node.IsSelected) { var rowToSelect = treeView.RowForItem(ToObject(nodeToItem[node])); Debug.Assert(rowToSelect >= 0); rowsToSelect.Add((nuint)rowToSelect); } if (node.IsExpanded) { foreach (var n in node.Children) { DiscoverSelected(n); } } } DiscoverSelected(rootItem.Node); treeView.SelectRows(NSIndexSet.FromArray(rowsToSelect.ToArray()), byExtendingSelection: false); }
void IView.EndUpdateStateHistoryList(int[] newSelectedIndexes, bool fullUpdate, bool redrawFocusedMessageMark) { EnsureLoaded(); if (!updatingStateHistory) { throw new InvalidOperationException(); } if (fullUpdate) { stateHistoryView.ReloadData(); } if (newSelectedIndexes != null) { stateHistoryView.SelectRows( NSIndexSet.FromArray(newSelectedIndexes), byExtendingSelection: false ); } if (redrawFocusedMessageMark) { InvalidateStateHistoryTableView(); } if (fullUpdate) { UpdateStateHistoryTimeColumn(); } updatingStateHistory = false; }
public static void SelectAndScrollInView <Item>(NSOutlineView treeView, Item[] items, Func <Item, Item> parentGetter) where Item : NSObject { var rows = new List <uint> (); foreach (var item in items) { var rowIdx = treeView.RowForItem(item); if (rowIdx < 0) { var stack = new Stack <Item>(); for (var i = parentGetter(item); i != null; i = parentGetter(i)) { stack.Push(i); } while (stack.Count > 0) { treeView.ExpandItem(stack.Pop()); } rowIdx = treeView.RowForItem(item); } if (rowIdx >= 0) { rows.Add((uint)rowIdx); } } treeView.SelectRows( NSIndexSet.FromArray(rows.ToArray()), byExtendingSelection: false ); if (rows.Count > 0) { treeView.ScrollRowToVisible((nint)rows[0]); } }
public void ReloadData(IEnumerable <int> rows) { Control.ReloadData(NSIndexSet.FromArray(rows.Select(r => (nuint)r).ToArray()), NSIndexSet.FromNSRange(new NSRange(0, Control.TableColumns().Length))); if (Widget.Columns.Any(r => r.AutoSize)) { AutoSizeColumns(true); } }
void DoFullUpdate() { outlineView.ReloadData(); outlineView.SelectRows(NSIndexSet.FromArray( GetItems() .ZipWithIndex() .Where(x => x.Value.isSelected) .Select(x => x.Key) .ToArray() ), byExtendingSelection: false); }
void DoFullUpdate() { listView.ReloadData(); listView.SelectRows(NSIndexSet.FromArray( dataSource.Items .ZipWithIndex() .Where(x => x.Value.isSelected) .Select(x => x.Key) .ToArray() ), byExtendingSelection: false); }
public void SetListSelectedItem(int index) { list.SelectRows( NSIndexSet.FromArray(index >= 0 ? new [] { index } : new int[0]), byExtendingSelection: false ); if (index >= 0) { list.ScrollRowToVisible(index); } }
public void ToggleSelected() { var updated = new List<nuint>(); for (int i = 0; i < dataSource.Items.Count; ++i) { if (tableView.IsRowSelected(i)) { updated.Add((nuint)i); dataSource.Items[i].IsSelected = !dataSource.Items[i].IsSelected; } }; tableView.ReloadData(NSIndexSet.FromArray(updated.ToArray()), NSIndexSet.FromIndex(0)); }
void UpdateStructure(IReadOnlyList <Item> newList) { var edits = ListEdit.GetListEdits(items, newList); items = newList; var columns = tableView.TableColumns(); NSIndexSet allColumnsSet = null; foreach (var e in edits) { switch (e.Type) { case ListEdit.EditType.Insert: using (var set = new NSIndexSet(e.Index)) tableView.InsertRows(set, NSTableViewAnimation.None); break; case ListEdit.EditType.Delete: using (var set = new NSIndexSet(e.Index)) tableView.RemoveRows(set, NSTableViewAnimation.None); break; case ListEdit.EditType.Reuse: if (owner.OnUpdateView != null && owner.OnCreateView != null) { for (int col = 0; col < columns.Length; ++col) { var existingView = tableView.GetView(col, e.Index, makeIfNecessary: false); if (existingView != null) { owner.OnUpdateView((Item)e.Item, columns[col], existingView, (Item)e.OldItem); } } } else { if (allColumnsSet == null) { allColumnsSet = NSIndexSet.FromArray(Enumerable.Range(0, columns.Length).ToArray()); } using (var set = new NSIndexSet(e.Index)) tableView.ReloadData(set, allColumnsSet); } break; } } allColumnsSet?.Dispose(); }
void IView.UpdateItems(IEnumerable <ViewItem> viewItems, ViewUpdateFlags flags) { isUpdating = true; var items = dataSource.items; items.Clear(); items.AddRange(viewItems.Select((d, i) => new Item(this, d, i))); tableView.ReloadData(); tableView.SelectRows( NSIndexSet.FromArray(items.Where(i => i.Data.IsSelected).Select(i => i.Index).ToArray()), byExtendingSelection: false ); UpdateTimeDeltasColumn(); isUpdating = false; }
void IView.SetViewModel(IViewModel viewModel) { this.viewModel = viewModel; selectedBkColor = Selectors.Create( () => viewModel.Theme, theme => theme == Presenters.ColorThemeMode.Light ? NSColor.FromDeviceRgba(.77f, .80f, .90f, 1f) : NSColor.FromDeviceRgba(.37f, .40f, .60f, 1f) ); var updateItems = Updaters.Create( () => viewModel.Items, viewItems => { isUpdating = true; var items = dataSource.items; items.Clear(); items.AddRange(viewItems.Select((d, i) => new Item(this, d, i))); tableView.ReloadData(); tableView.SelectRows( NSIndexSet.FromArray(items.Where(i => i.Data.IsSelected).Select(i => i.Index).ToArray()), byExtendingSelection: false ); UpdateTimeDeltasColumn(); isUpdating = false; } ); var updateFocusedMessageMark = Updaters.Create( () => viewModel.FocusedMessagePosition, (_) => { InvalidateTable(); } ); viewModel.ChangeNotification.CreateSubscription(() => { updateItems(); updateFocusedMessageMark(); }); }
void UpdateSelection() { var rowsToSelect = new HashSet <nuint>(); nuint idx = 0; foreach (var i in items) { if (i.IsSelected) { rowsToSelect.Add(idx); } ++idx; } if (rowsToSelect.SetEquals(tableView.SelectedRows)) { return; } tableView.SelectRows(NSIndexSet.FromArray(rowsToSelect.ToArray()), byExtendingSelection: false); }
void UpdateItems(NotifyCollectionChangedEventArgs e, int section, bool resetWhenGrouped) { var exArgs = e as NotifyCollectionChangedEventArgsEx; if (exArgs != null) { _dataSource.Counts[section] = exArgs.Count; } var groupReset = resetWhenGrouped && Element.IsGroupingEnabled; switch (e.Action) { case NotifyCollectionChangedAction.Add: if (e.NewStartingIndex == -1 || groupReset) { goto case NotifyCollectionChangedAction.Reset; } _table.BeginUpdates(); _table.InsertRows(NSIndexSet.FromArray(Enumerable.Range(e.NewStartingIndex, e.NewItems.Count).ToArray()), NSTableViewAnimation.SlideUp); _table.EndUpdates(); break; case NotifyCollectionChangedAction.Remove: if (e.OldStartingIndex == -1 || groupReset) { goto case NotifyCollectionChangedAction.Reset; } _table.BeginUpdates(); _table.RemoveRows(NSIndexSet.FromArray(Enumerable.Range(e.OldStartingIndex, e.OldItems.Count).ToArray()), NSTableViewAnimation.SlideDown); _table.EndUpdates(); break; case NotifyCollectionChangedAction.Move: if (e.OldStartingIndex == -1 || e.NewStartingIndex == -1 || groupReset) { goto case NotifyCollectionChangedAction.Reset; } _table.BeginUpdates(); for (var i = 0; i < e.OldItems.Count; i++) { var oldi = e.OldStartingIndex; var newi = e.NewStartingIndex; if (e.NewStartingIndex < e.OldStartingIndex) { oldi += i; newi += i; } _table.MoveRow(oldi, newi); } _table.EndUpdates(); break; case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Reset: _table.ReloadData(); return; } }
public void ReloadData(IEnumerable <int> rows) { Control.ReloadData(NSIndexSet.FromArray(rows.Select(r => (nuint)r).ToArray()), NSIndexSet.FromNSRange(new NSRange(0, Control.TableColumns().Length))); }
protected static NSIndexSet CreateNSIndexSet(int startingPosition, int count) { return(NSIndexSet.FromArray(Enumerable.Range(startingPosition, count).ToArray())); }