public void FormatSample() { if (textStylePolicy != null) { texteditor.Options.IndentationSize = textStylePolicy.IndentWidth; texteditor.Options.TabSize = textStylePolicy.TabWidth; texteditor.Options.TabsToSpaces = textStylePolicy.TabsToSpaces; } texteditor.Document.Text = CSharpFormatter.FormatText(policy, textStylePolicy, CSharpFormatter.MimeType, example, 0, example.Length); }
public override void PostFomatPastedText(int insertionOffset, int insertedChars) { if (indent.Editor.Options.IndentStyle == IndentStyle.None || indent.Editor.Options.IndentStyle == IndentStyle.Auto) { return; } if (DefaultSourceEditorOptions.Instance.OnTheFlyFormatting) { int lineStartOffset = indent.Editor.GetLineByOffset(insertionOffset).Offset; int formatCharsCount = insertedChars + (lineStartOffset - insertionOffset); var newText = CSharpFormatter.FormatText( indent.DocumentContext.GetFormattingPolicy(), indent.DocumentContext.Project.Policies.Get <Ide.Gui.Content.TextStylePolicy> (), indent.Editor.GetTextBetween(lineStartOffset, insertionOffset + insertedChars), 0, formatCharsCount ); indent.Editor.ReplaceText(lineStartOffset, formatCharsCount, newText); return; } // Just correct the start line of the paste operation - the text is already indented. var curLine = indent.Editor.GetLineByOffset(insertionOffset); var curLineOffset = curLine.Offset; indent.SafeUpdateIndentEngine(curLineOffset); if (!indent.stateTracker.IsInsideOrdinaryCommentOrString) { int pos = curLineOffset; string curIndent = curLine.GetIndentation(indent.Editor); int nlwsp = curIndent.Length; if (!indent.stateTracker.LineBeganInsideMultiLineComment || (nlwsp < curLine.LengthIncludingDelimiter && indent.Editor.GetCharAt(curLineOffset + nlwsp) == '*')) { // Possibly replace the indent indent.SafeUpdateIndentEngine(curLineOffset + curLine.Length); string newIndent = indent.stateTracker.ThisLineIndent; if (newIndent != curIndent) { if (CompletionWindowManager.IsVisible) { if (pos < CompletionWindowManager.CodeCompletionContext.TriggerOffset) { CompletionWindowManager.CodeCompletionContext.TriggerOffset -= nlwsp; } } indent.Editor.ReplaceText(pos, nlwsp, newIndent); // textEditorData.Document.CommitLineUpdate (textEditorData.CaretLine); } } } indent.Editor.FixVirtualIndentation(); }
void UpdateExample(string example) { string text; if (!string.IsNullOrEmpty(example)) { text = Environment.NewLine != "\n" ? example.Replace("\n", Environment.NewLine) : example; } else { text = ""; } var types = DesktopService.GetMimeTypeInheritanceChain(MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType); var textPolicy = MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> (types); texteditor.Text = CSharpFormatter.FormatText(profile, textPolicy, text, 0, text.Length); }
public override void CreateNewType(AstNode newType, NewTypeContext ntctx) { if (newType == null) { throw new System.ArgumentNullException("newType"); } var correctFileName = MoveTypeToFile.GetCorrectFileName(context, (EntityDeclaration)newType); var content = context.TextEditor.Text; var types = new List <EntityDeclaration> (context.Unit.GetTypes()); types.Sort((x, y) => y.StartLocation.CompareTo(x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset(removeType.StartLocation); var end = context.GetOffset(removeType.EndLocation); content = content.Remove(start, end - start); } var insertLocation = types.Count > 0 ? context.GetOffset(types.Last().StartLocation) : -1; if (insertLocation < 0 || insertLocation > content.Length) { insertLocation = content.Length; } content = content.Substring(0, insertLocation) + newType.ToString(FormattingOptions) + content.Substring(insertLocation); var formatter = new MonoDevelop.CSharp.Formatting.CSharpFormatter(); var policy = context.Project.Policies.Get <CSharpFormattingPolicy> (); var textPolicy = context.Project.Policies.Get <TextStylePolicy> (); content = formatter.FormatText(policy, textPolicy, MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType, content, 0, content.Length); File.WriteAllText(correctFileName, content); context.Project.AddFile(correctFileName); IdeApp.ProjectOperations.Save(context.Project); IdeApp.Workbench.OpenDocument(correctFileName); }
void UpdateExample (string example) { var formatter = new CSharpFormatter (); string text; if (!string.IsNullOrEmpty (example)) { text = Environment.NewLine != "\n" ? example.Replace ("\n", Environment.NewLine) : example; } else { text = ""; } texteditor.Document.Text = formatter.FormatText (profile, null, CSharpFormatter.MimeType, text, 0, text.Length); }
public override void CreateNewType (AstNode newType, NewTypeContext ntctx) { if (newType == null) throw new System.ArgumentNullException ("newType"); var correctFileName = MoveTypeToFile.GetCorrectFileName (context, (EntityDeclaration)newType); var content = context.TextEditor.Text; var types = new List<EntityDeclaration> (context.Unit.GetTypes ()); types.Sort ((x, y) => y.StartLocation.CompareTo (x.StartLocation)); foreach (var removeType in types) { var start = context.GetOffset (removeType.StartLocation); var end = context.GetOffset (removeType.EndLocation); content = content.Remove (start, end - start); } var insertLocation = types.Count > 0 ? context.GetOffset (types.Last ().StartLocation) : -1; if (insertLocation < 0 || insertLocation > content.Length) insertLocation = content.Length; content = content.Substring (0, insertLocation) + newType.ToString (FormattingOptions) + content.Substring (insertLocation); var formatter = new MonoDevelop.CSharp.Formatting.CSharpFormatter (); var policy = context.Project.Policies.Get<CSharpFormattingPolicy> (); var textPolicy = context.Project.Policies.Get<TextStylePolicy> (); content = formatter.FormatText (policy, textPolicy, MonoDevelop.CSharp.Formatting.CSharpFormatter.MimeType, content, 0, content.Length); File.WriteAllText (correctFileName, content); context.Project.AddFile (correctFileName); IdeApp.ProjectOperations.Save (context.Project); IdeApp.Workbench.OpenDocument (correctFileName); }
public void FormatSample() { texteditor.Options = DefaultSourceEditorOptions.Instance.WithTextStyle(textStylePolicy); texteditor.Text = CSharpFormatter.FormatText(policy, textStylePolicy, example, 0, example.Length); }
public void FormatSample() { var formatter = new CSharpFormatter(); texteditor.Document.Text = formatter.FormatText(policy, null, CSharpFormatter.MimeType, example, 0, example.Length); }
void UpdateExample (string example) { CSharpFormatter formatter = new CSharpFormatter (); var parent = new MonoDevelop.Projects.DotNetAssemblyProject (); parent.Policies.Set<CSharpFormattingPolicy> (profile, CSharpFormatter.MimeType); texteditor.Document.Text = formatter.FormatText (parent.Policies, CSharpFormatter.MimeType, example); }
public CSharpFormattingPolicyPanelWidget () { this.Build (); buttonNew.Clicked += HandleButtonNewClicked; buttonImport.Clicked += HandleButtonImportClicked; buttonExport.Clicked += HandleButtonExportClicked; buttonEdit.Clicked += HandleButtonEditClicked; buttonRemove.Clicked += HandleButtonRemoveClicked; var options = MonoDevelop.SourceEditor.DefaultSourceEditorOptions.Instance; texteditor.Options.FontName = options.FontName; texteditor.Options.ColorScheme = options.ColorScheme; texteditor.Options.ShowFoldMargin = false; texteditor.Options.ShowIconMargin = false; texteditor.Options.ShowLineNumberMargin = false; texteditor.Options.ShowInvalidLines = false; texteditor.Document.ReadOnly = true; texteditor.Document.MimeType = CSharpFormatter.MimeType; scrolledwindow1.Child = texteditor; policies.AddRange (FormattingProfileService.Profiles); comboboxProfiles.Model = model; comboboxProfiles.Changed += delegate { if (comboboxProfiles.Active < 0) return; var profile = policies[comboboxProfiles.Active]; CSharpFormatter formatter = new CSharpFormatter (); var parent = new MonoDevelop.Projects.DotNetAssemblyProject (); parent.Policies.Set<CSharpFormattingPolicy> (profile, CSharpFormatter.MimeType); texteditor.Document.Text = formatter.FormatText (parent.Policies, CSharpFormatter.MimeType, example); }; ShowAll (); InitComboBox (); }
public void FormatSample () { var formatter = new CSharpFormatter (); texteditor.Document.Text = formatter.FormatText (policy, null, CSharpFormatter.MimeType, example, 0, example.Length); }
public void FormatSample () { var formatter = new CSharpFormatter (); if (textStylePolicy != null) { texteditor.Options.IndentationSize = textStylePolicy.IndentWidth; texteditor.Options.TabSize = textStylePolicy.TabWidth; texteditor.Options.TabsToSpaces = textStylePolicy.TabsToSpaces; } texteditor.Document.Text = formatter.FormatText (policy, textStylePolicy, CSharpFormatter.MimeType, example, 0, example.Length); }