Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit f71f6c6

Browse files
committed
Merged work on #304 and #306: GUI for C# formatting options.
Conflicts: src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj
2 parents f9ae991 + 2cf319c commit f71f6c6

23 files changed

Lines changed: 1874 additions & 187 deletions

src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
label = "${res:Dialog.ProjectOptions.Publish}"
120120
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.Publish"/>-->
121121
<Include id = "AllManaged" path="/SharpDevelop/BackendBindings/ProjectOptions/AllManaged"/>
122+
<!-- TODO Localize label! -->
123+
<OptionPanel id = "CSharpProjectFormattingOptions"
124+
label = "Code Formatting"
125+
class = "CSharpBinding.OptionPanels.CSharpProjectFormattingOptionPanel"/>
122126
</Path>
123127

124128
<Path name = "/Workspace/Icons">
@@ -148,9 +152,18 @@
148152
label="Code inspection"
149153
class="CSharpBinding.Refactoring.IssueOptions"/>
150154
<ContextActionOptionPanel id="ContextActions" path="/SharpDevelop/ViewContent/TextEditor/C#/ContextActions"/>
155+
<OptionPanel id="Formatting"
156+
label="Formatting"
157+
class="CSharpBinding.OptionPanels.CSharpGlobalFormattingOptionPanel"/>
151158
</OptionPanel>
152159
</Path>
153160

161+
<Path path = "/SharpDevelop/Dialogs/SolutionFormattingOptionsDialog">
162+
<OptionPanel id="C#Formatting"
163+
label="C#"
164+
class="CSharpBinding.OptionPanels.CSharpSolutionFormattingOptionPanel"/>
165+
</Path>
166+
154167
<Path path = "/SharpDevelop/Workbench/MainMenu/Search">
155168
<MenuItem id = "SearchForIssues"
156169
label="Search For Issues..."
@@ -495,4 +508,10 @@
495508
class = "CSharpBinding.FormsDesigner.FormsDesignerSecondaryDisplayBinding"
496509
fileNamePattern = "\.cs$"/>
497510
</Path>
511+
512+
<!-- Autostart command for initialization -->
513+
<Path name = "/SharpDevelop/Autostart">
514+
<Class id = "CSharpFormattingOptionsPersistenceInitCommand"
515+
class = "CSharpBinding.FormattingStrategy.CSharpFormattingOptionsPersistenceInitCommand"/>
516+
</Path>
498517
</AddIn>

src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.csproj

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@
6262
</Reference>
6363
<Reference Include="System.Xml" />
6464
<Reference Include="Microsoft.Build.Engine" />
65+
<Reference Include="System.Xml.Linq">
66+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
67+
</Reference>
6568
<Reference Include="WindowsBase">
6669
<RequiredTargetFramework>3.0</RequiredTargetFramework>
6770
</Reference>
@@ -86,14 +89,29 @@
8689
<Compile Include="Src\CSharpSemanticHighlighterVisitor.cs">
8790
<DependentUpon>CSharpSemanticHighlighter.cs</DependentUpon>
8891
</Compile>
92+
<Compile Include="Src\FormattingStrategy\CSharpFormattingOptionsContainer.cs" />
8993
<Compile Include="Src\FormattingStrategy\CSharpFormatter.cs" />
94+
<Compile Include="Src\FormattingStrategy\CSharpFormattingOptionsPersistence.cs" />
95+
<Compile Include="Src\FormattingStrategy\FormattingOptionBinding.cs" />
9096
<Compile Include="Src\FormsDesigner\CSharpDesignerGenerator.cs" />
9197
<Compile Include="Src\FormsDesigner\CSharpDesignerLoader.cs" />
9298
<Compile Include="Src\FormsDesigner\CSharpDesignerLoaderProvider.cs" />
9399
<Compile Include="Src\FormsDesigner\CSharpEventBindingService.cs" />
94100
<Compile Include="Src\FormsDesigner\CSharpFormsDesignerLoaderContext.cs" />
95101
<Compile Include="Src\FormsDesigner\ICSharpDesignerLoaderContext.cs" />
96102
<Compile Include="Src\FormsDesigner\SecondaryDisplayBinding.cs" />
103+
<Compile Include="Src\OptionPanels\CSharpFormattingEditor.xaml.cs">
104+
<DependentUpon>CSharpFormattingEditor.xaml</DependentUpon>
105+
<SubType>Code</SubType>
106+
</Compile>
107+
<Compile Include="Src\OptionPanels\CSharpFormattingOptionPanel.xaml.cs">
108+
<DependentUpon>CSharpFormattingOptionPanel.xaml</DependentUpon>
109+
<SubType>Code</SubType>
110+
</Compile>
111+
<Compile Include="Src\OptionPanels\CSharpProjectFormattingOptions.xaml.cs">
112+
<DependentUpon>CSharpProjectFormattingOptions.xaml</DependentUpon>
113+
<SubType>Code</SubType>
114+
</Compile>
97115
<Compile Include="Src\Parser\FoldingVisitor.cs" />
98116
<Compile Include="Src\Refactoring\AbstractInlineRefactorDialog.cs" />
99117
<Compile Include="Src\Refactoring\ConvertInterfaceToAbstractClassContextAction.cs" />
@@ -240,6 +258,9 @@
240258
</ProjectReference>
241259
</ItemGroup>
242260
<ItemGroup>
261+
<Page Include="Src\OptionPanels\CSharpFormattingEditor.xaml" />
262+
<Page Include="Src\OptionPanels\CSharpFormattingOptionPanel.xaml" />
263+
<Page Include="Src\OptionPanels\CSharpProjectFormattingOptions.xaml" />
243264
<Page Include="Src\Refactoring\CreatePropertiesDialog.xaml" />
244265
<Page Include="Src\Refactoring\InsertCtorDialog.xaml" />
245266
<Page Include="Src\Refactoring\IssueOptions.xaml" />

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/OverrideCompletionData.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ public override void Complete(CompletionContext context)
9898

9999
var document = context.Editor.Document;
100100
StringWriter w = new StringWriter();
101-
var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
102-
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
101+
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(contextAtCaret.Compilation.GetProject());
102+
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(
103+
w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options);
103104

104105
using (document.OpenUndoGroup()) {
105106
string newText = w.ToString().TrimEnd();
@@ -109,7 +110,7 @@ public override void Complete(CompletionContext context)
109110
var segment = segmentDict[throwStatement];
110111
context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
111112
}
112-
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
113+
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer);
113114
}
114115
}
115116

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/OverrideEqualsGetHashCodeCompletionData.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,9 @@ public override void Complete(CompletionContext context)
8484

8585
var document = context.Editor.Document;
8686
StringWriter w = new StringWriter();
87-
var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
88-
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
87+
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(contextAtCaret.Compilation.GetProject());
88+
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(
89+
w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options);
8990

9091
using (document.OpenUndoGroup()) {
9192
InsertionContext insertionContext = new InsertionContext(context.Editor.GetService(typeof(TextArea)) as TextArea, declarationBegin);
@@ -98,7 +99,7 @@ public override void Complete(CompletionContext context)
9899
var segment = segmentDict[throwStatement];
99100
context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
100101
}
101-
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
102+
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer);
102103

103104
var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
104105
var typeResolveContext = refactoringContext.GetTypeResolveContext();

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/OverrideToStringCompletionData.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
using ICSharpCode.AvalonEdit.Editing;
2525
using ICSharpCode.AvalonEdit.Snippets;
2626
using ICSharpCode.NRefactory.Editor;
27+
using ICSharpCode.SharpDevelop;
2728
using CSharpBinding.FormattingStrategy;
2829
using ICSharpCode.NRefactory.CSharp;
2930
using ICSharpCode.NRefactory.CSharp.Refactoring;
@@ -80,8 +81,9 @@ public override void Complete(CompletionContext context)
8081

8182
var document = context.Editor.Document;
8283
StringWriter w = new StringWriter();
83-
var formattingOptions = FormattingOptionsFactory.CreateSharpDevelop();
84-
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(w, entityDeclaration, formattingOptions, context.Editor.Options);
84+
var formattingOptions = CSharpFormattingOptionsPersistence.GetProjectOptions(contextAtCaret.Compilation.GetProject());
85+
var segmentDict = SegmentTrackingOutputFormatter.WriteNode(
86+
w, entityDeclaration, formattingOptions.OptionsContainer.GetEffectiveOptions(), context.Editor.Options);
8587

8688
using (document.OpenUndoGroup()) {
8789
InsertionContext insertionContext = new InsertionContext(context.Editor.GetService(typeof(TextArea)) as TextArea, declarationBegin);
@@ -94,7 +96,7 @@ public override void Complete(CompletionContext context)
9496
var segment = segmentDict[throwStatement];
9597
context.Editor.Select(declarationBegin + segment.Offset, segment.Length);
9698
}
97-
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions);
99+
CSharpFormatterHelper.Format(context.Editor, declarationBegin, newText.Length, formattingOptions.OptionsContainer);
98100

99101
var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
100102
var typeResolveContext = refactoringContext.GetTypeResolveContext();

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormatter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
namespace CSharpBinding.FormattingStrategy
2626
{
27-
public class CSharpFormatterHelper
27+
internal class CSharpFormatterHelper
2828
{
2929
/// <summary>
3030
/// Formats the specified part of the document.
3131
/// </summary>
32-
public static void Format(ITextEditor editor, int offset, int length, CSharpFormattingOptions options)
32+
public static void Format(ITextEditor editor, int offset, int length, CSharpFormattingOptionsContainer optionsContainer)
3333
{
34-
var formatter = new CSharpFormatter(options, editor.ToEditorOptions());
34+
var formatter = new CSharpFormatter(optionsContainer.GetEffectiveOptions(), editor.ToEditorOptions());
3535
formatter.AddFormattingRegion(new DomRegion(editor.Document.GetLocation(offset), editor.Document.GetLocation(offset + length)));
3636
var changes = formatter.AnalyzeFormatting(editor.Document, SyntaxTree.Parse(editor.Document));
3737
changes.ApplyChanges(offset, length);

0 commit comments

Comments
 (0)