private void UpdateGameField(GameField gameField, bool isCreateNew) { _selectionController.Clear(); for (var i = 0; i < Dimension; i++) { for (var j = 0; j < Dimension; j++) { var cellIdx = i * Dimension + j; var isCellActive = (i + j) % 2 != 0; if (isCreateNew) { _cellHandlers.Add(new CellHandler( cellIdx: cellIdx, cellType: isCellActive ? CellColor.Black : CellColor.White, cellState: gameField[cellIdx], selectionController: _selectionController)); } else { _cellHandlers[cellIdx].CellState = gameField[cellIdx]; } } } }
/// <summary> /// Выбор фигур для последующего создания /// </summary> private void btnCreateFigure_Click(object sender, EventArgs e) { _selectionController.Clear(); Func <Figure> figureCreator = null; Cursor figureCreatorCursor = CursorFactory.GetCursor(UserCursor.SelectByRibbonRect); if (sender == tsbPointer) { figureCreatorCursor = Cursors.Default; Cursor = Cursors.Default; tsbPointer.Enabled = false; _selectionController.CreateFigureCursor = figureCreatorCursor; _selectionController.CreateFigureRequest = figureCreator; return; } tsbPointer.Enabled = true; // if (sender == btnRectangle || sender == tsbRect) { figureCreatorCursor = Cursor = CursorFactory.GetCursor(UserCursor.CreateRect); figureCreator = () => { var fig = new Figure(); FigureBuilder.BuildRectangleGeometry(fig); return(fig); }; } else if (sender == btnRoundedRectangle) { figureCreatorCursor = Cursor = CursorFactory.GetCursor(UserCursor.CreateRect); figureCreator = () => { var fig = new Figure(); FigureBuilder.BuildRoundedRectangleGeometry(fig, 0.25f); return(fig); }; } // _selectionController.CreateFigureCursor = figureCreatorCursor; _selectionController.CreateFigureRequest = figureCreator; }
public LogEntryViewer(ILogEntryService logEntryService) { //build an observable filter var filter = this.WhenAnyValue(x => x.SearchText) .Throttle(TimeSpan.FromMilliseconds(250)) .Select(BuildFilter); //filter, sort and populate reactive list. var shared = logEntryService.Items.Connect() .Transform(le => new LogEntryProxy(le)) .DelayRemove(TimeSpan.FromSeconds(0.75), proxy => proxy.FlagForRemove()) .Publish(); var loader = shared.Filter(filter) .Sort(SortExpressionComparer <LogEntryProxy> .Descending(le => le.TimeStamp).ThenByDescending(l => l.Key), SortOptions.UseBinarySearch) .ObserveOn(RxApp.MainThreadScheduler) .Bind(out var data) .DisposeMany() .Subscribe(); Data = data; //aggregate total items var summariser = shared.QueryWhenChanged(items => { var debug = items.Count(le => le.Level == LogLevel.Debug); var info = items.Count(le => le.Level == LogLevel.Info); var warn = items.Count(le => le.Level == LogLevel.Warning); var error = items.Count(le => le.Level == LogLevel.Error); return(new LogEntrySummary(debug, info, warn, error)); }) .Subscribe(s => Summary = s); //manage user selection, delete items command var selectedItems = _selectionController.SelectedItems.Connect().Publish(); //Build a message from selected items _deleteItemsText = selectedItems.QueryWhenChanged(query => { if (query.Count == 0) { return("Select log entries to delete"); } if (query.Count == 1) { return("Delete selected log entry?"); } return($"Delete {query.Count} log entries?"); }) .ToProperty(this, viewmodel => viewmodel.DeleteItemsText, "Select log entries to delete"); //make a command out of selected items - enabling the command when there is a selection DeleteCommand = ReactiveCommand.Create(() => { var toRemove = _selectionController.SelectedItems.Items.Select(proxy => proxy.Original).ToArray(); _selectionController.Clear(); logEntryService.Remove(toRemove); }, selectedItems.QueryWhenChanged(query => query.Count > 0)); var connected = selectedItems.Connect(); var connectedItems = shared.Connect(); _cleanUp = Disposable.Create(() => { loader.Dispose(); connected.Dispose(); _deleteItemsText.Dispose(); DeleteCommand.Dispose(); _selectionController.Dispose(); summariser.Dispose(); connectedItems.Dispose(); }); }