async void HandleTextOptionsChanged(object sender, EventArgs e) { //var options = Editor.CreateNRefactoryTextEditorOptions (); var optionTask = DocumentContext?.AnalysisDocument?.GetOptionsAsync(); if (optionTask == null) { return; } optionSet = await optionTask; if (optionSet == null) { return; } //options.IndentBlankLines = true; ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine(optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols(DocumentContext.Project)) { csharpIndentEngine.DefineSymbol(symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine(); } await Runtime.RunInMainThread(delegate { stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine(indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { Editor.IndentationTracker = null; } else { Editor.IndentationTracker = new IndentVirtualSpaceManager(Editor, stateTracker); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { Editor.SetTextPasteHandler(null); } else { Editor.SetTextPasteHandler(new CSharpTextPasteHandler(this, stateTracker, optionSet)); } }); }
async void HandleTextOptionsChanged(object sender, EventArgs e) { optionSet = await DocumentContext.GetOptionsAsync(); IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine(optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols(DocumentContext.Project)) { csharpIndentEngine.DefineSymbol(symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine(); } await Runtime.RunInMainThread(delegate { try { var editor = Editor; if (editor == null) // disposed { return; } stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine(indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { editor.IndentationTracker = null; } else { editor.IndentationTracker = new CSharpIndentationTracker(editor, DocumentContext); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { editor.SetTextPasteHandler(null); } else { editor.SetTextPasteHandler(new CSharpTextPasteHandler(this, optionSet)); } } catch (Exception ex) { LoggingService.LogError("Error while handling text option change.", ex); } }); }
void HandleTextOptionsChanged (object sender, EventArgs e) { //var options = Editor.CreateNRefactoryTextEditorOptions (); optionSet = Policy.CreateOptions (Editor.Options); //options.IndentBlankLines = true; ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine indentEngine; try { var csharpIndentEngine = new ICSharpCode.NRefactory6.CSharp.CSharpIndentEngine (optionSet); //csharpIndentEngine.EnableCustomIndentLevels = true; foreach (var symbol in GetDefinedSymbols (DocumentContext.Project)) { csharpIndentEngine.DefineSymbol (symbol); } indentEngine = csharpIndentEngine; } catch (Exception ex) { LoggingService.LogError ("Error while creating the c# indentation engine", ex); indentEngine = new ICSharpCode.NRefactory6.CSharp.NullIStateMachineIndentEngine (); } stateTracker = new ICSharpCode.NRefactory6.CSharp.CacheIndentEngine (indentEngine); if (DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto) { Editor.SetIndentationTracker (null); } else { Editor.SetIndentationTracker (new IndentVirtualSpaceManager (Editor, stateTracker)); } indentationDisabled = DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.Auto || DefaultSourceEditorOptions.Instance.IndentStyle == IndentStyle.None; if (indentationDisabled) { Editor.SetTextPasteHandler (null); } else { Editor.SetTextPasteHandler (new CSharpTextPasteHandler (this, stateTracker, optionSet)); } }