CodeCellState InsertCodeCell(CodeCell newCell, Cell previousCell) { if (newCell == null) { throw new ArgumentNullException(nameof(newCell)); } InsertCellInDocumentModel(newCell, previousCell); var previousCodeCell = newCell.GetPreviousCell <CodeCell> (); var nextCodeCell = newCell.GetNextCell <CodeCell> (); var codeCellState = new CodeCellState(newCell); BindCodeCellToView(newCell, codeCellState); if (ClientSession.CompilationWorkspace != null) { codeCellState.CompilationWorkspace = ClientSession.CompilationWorkspace; codeCellState.DocumentId = ClientSession.CompilationWorkspace.AddSubmission( newCell.CodeAnalysisBuffer.CurrentText, GetDocumentId(previousCodeCell), GetDocumentId(nextCodeCell)); } InsertCellInViewModel(newCell, previousCell); OutdateAllCodeCells(newCell); AppendCodeCell(codeCellState.Editor, codeCellState); return(codeCellState); }
CodeCellId GetCodeCellId(CodeCell codeCell) { if (codeCell?.View?.Editor != null && CodeCells.TryGetValue(codeCell.View.Editor, out CodeCellState codeCellState)) { return(codeCellState.CodeCellId); } return(null); }
void OutdateAllCodeCells(CodeCell codeCell) { while (codeCell != null) { var view = (ICodeCellView)codeCell.View; if (view != null) { view.IsOutdated = true; } codeCell = codeCell.GetNextCell <CodeCell> (); } }
CodeCellState InsertCodeCell(CodeCell newCell, Cell previousCell, bool isHidden = false) { if (newCell == null) { throw new ArgumentNullException(nameof(newCell)); } InsertCellInDocumentModel(newCell, previousCell); var previousCodeCell = newCell.GetPreviousCell <CodeCell> (); var nextCodeCell = newCell.GetNextCell <CodeCell> (); var codeCellState = new CodeCellState(newCell); if (isHidden) { // Set up editor, required as dictionary key codeCellState.Editor = new HiddenCodeCellEditor(); codeCellState.View = new HiddenCodeCellView { Editor = codeCellState.Editor }; newCell.View = codeCellState.View; } else { BindCodeCellToView(newCell, codeCellState); } if (ClientSession.CompilationWorkspace != null) { codeCellState.BindToWorkspace( ClientSession.CompilationWorkspace, ClientSession.CompilationWorkspace.InsertCell( newCell.Buffer.Value, GetCodeCellId(previousCodeCell), GetCodeCellId(nextCodeCell))); } if (!isHidden) { InsertCellInViewModel(newCell, previousCell); } OutdateAllCodeCells(newCell); AppendCodeCell(codeCellState.Editor, codeCellState); return(codeCellState); }
public CodeCellState(CodeCell cell) => Cell = cell ?? throw new ArgumentNullException(nameof(cell));
protected abstract void BindCodeCellToView(CodeCell cell, CodeCellState codeCellState);