public CodeCellEditorView( CodeCellState codeCellState, CodeCell codeCell, HtmlElement element) { if (codeCellState == null) { throw new ArgumentNullException(nameof(codeCellState)); } if (codeCell == null) { throw new ArgumentNullException(nameof(codeCell)); } if (element == null) { throw new ArgumentNullException(nameof(element)); } this.state = codeCellState; this.jsContext = element.Context; Cell = codeCell; codeEditor = jsContext.GlobalObject.xiexports.monaco.WorkbookCodeEditor(jsContext.CreateObject(o => { o.placeElem = element; o.readOnly = false; o.fontSize = Prefs.UI.Font.GetSize(); o.showLineNumbers = Prefs.Editor.ShowLineNumbers.GetValue(); o.onFocus = (ScriptAction)HandleFocus; o.onChange = (ScriptAction)HandleChange; o.onCursorUpDown = (ScriptFunc)HandleCursorUpDown; o.onEnter = (ScriptFunc)HandleEnter; o.theme = GetThemeName(); o.wrapLongLines = Prefs.Submissions.WrapLongLinesInEditor.GetValue(); })); codeEditor.setText(codeCell.Buffer.Value); preferenceSubscription = PreferenceStore.Default.Subscribe(change => { if (change.Key == Prefs.UI.Font.Key) { // TODO: Figure out why this doesn't appear to update font size in completion window codeEditor.setFontSize(Prefs.UI.Font.GetSize()); } else if (change.Key == Prefs.Editor.ShowLineNumbers.Key) { codeEditor.setShowLineNumbers(Prefs.Editor.ShowLineNumbers.GetValue()); } else if (change.Key == Prefs.UI.Theme.UseHighContrast.Key || change.Key == Prefs.UI.Theme.ThemeName.Key) { codeEditor.setTheme(GetThemeName()); } else if (change.Key == Prefs.Submissions.WrapLongLinesInEditor.Key) { codeEditor.setWordWrap(Prefs.Submissions.WrapLongLinesInEditor.GetValue()); } }); }
public CodeCellView( Models.CodeCellState codeCellState, CodeCell codeCell, HtmlDocument document, RendererContext rendererContext) : base( document, "submission " + codeCell.LanguageName) { this.codeCell = codeCell ?? throw new ArgumentNullException(nameof(codeCell)); this.rendererContext = rendererContext ?? throw new ArgumentNullException(nameof(rendererContext)); ContentElement.AppendChild(editorElem = CreateContentContainer("editor")); editor = new CodeCellEditorView(codeCellState, codeCell, editorElem); PreferenceStore.Default.Subscribe(change => { if (change.Key == Prefs.Submissions.ShowExecutionTimings.Key) { UpdateEvaluationDurationHidden(); } }); }
protected override void BindCodeCellToView(CodeCell cell, CodeCellState codeCellState) { var view = new ConsoleCellView(cell, output); codeCellState.Editor = view.Editor; codeCellState.View = view; cell.View = view; }
public static string ToHtml(this BaseCell cell) { return(cell switch { CodeCell codeCell => convertCodeToHtml(codeCell), MarkdownCell mdCell => convertMarkdownToHtml(mdCell), RawCell rwCell => convertRawToHtml(rwCell), _ => throw new NotSupportedException(), });
public void SetCellExecutionStarted(CodeCell cell) { var cellVm = Cells.First(item => item.AttachedCell == cell); if (cellVm is InputCellVM inputCellVM) { inputCellVM.Status = CellEvaluationStatus.Running; inputCellVM.OnPropertyChanged(string.Empty); } }
public void SetCellExecutionCompleted(CodeCell cell, JupyterMessage.ExecuteReplyContent content) { var cellVm = Cells.First(item => item.AttachedCell == cell); if (cellVm is InputCellVM inputCellVM) { inputCellVM.Status = content.status == "ok" ? CellEvaluationStatus.Completed : CellEvaluationStatus.Error; inputCellVM.OnPropertyChanged(string.Empty); } }
public void Execute(CodeCell cell) => SendShell( JupyterMessage.Header.MsgType.execute_request, new JupyterMessage.ExecuteRequestContent { code = cell.source, silent = false, store_history = true, user_expressions = null, allow_stdin = true, stop_on_error = false }, cell);
protected override void BindCodeCellToView(CodeCell cell, Models.CodeCellState codeCellState) { var codeCellView = new CodeCellView( codeCellState, cell, webView.Document, rendererContext); cell.View = codeCellView; codeCellState.Editor = codeCellView.Editor; codeCellState.View = codeCellView; codeCellView.Events.Subscribe(new Observer <IEvent> (HandleCodeCellViewEvent)); }
IEnumerable <FilePath> Visit(CodeCell codeCell) => CSharpSyntaxTree .ParseText( codeCell.Buffer.Value, CSharpParseOptions.Default .WithKind(SourceCodeKind.Script) .WithLanguageVersion(LanguageVersion.CSharp7_1)) .GetRoot() .DescendantTrivia() .Where(trivia => trivia.HasStructure && ( trivia.IsKind(SyntaxKind.LoadDirectiveTrivia) || trivia.IsKind(SyntaxKind.ReferenceDirectiveTrivia))) .Select(trivia => trivia.GetStructure()) .SelectMany(node => node.ChildTokens()) .Where(token => token.IsKind(SyntaxKind.StringLiteralToken)) .Select(token => GetRelativePath(token.ValueText)) .Where(path => !path.IsNull);
private static string GetCellsContent(List <BaseCell> cells) { string content = ""; foreach (BaseCell cell in cells) { CodeCell codeCell = cell as CodeCell; string counter = codeCell != null ? "<p>[" + codeCell.ExecutionCount.ToString() + "]</p>" : ""; content += $"<tr><td>{counter}</td><td>{new HtmlString(cell.ToHtml())}</td></tr>"; if (codeCell != null) { foreach (var outputCell in codeCell.Outputs) { content += $"<tr><td/><td>{new HtmlString(outputCell.ToHtml())}</td></tr>"; } } } return(content); }