Skip to content

Commit c49be4c

Browse files
authored
Merge pull request #2545 from comintern/next
Fixes #2180, #2266, initial implementation for #2286
2 parents ee65797 + 3b551b5 commit c49be4c

26 files changed

+1018
-134
lines changed

RetailCoder.VBE/Refactorings/EncapsulateField/EncapsulateFieldRefactoring.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ private string GetPropertyText()
231231
(_model.ImplementSetSetterType ? setterText : string.Empty)).TrimEnd() + Environment.NewLine;
232232

233233
var propertyTextLines = propertyText.Split(new[] {Environment.NewLine}, StringSplitOptions.None);
234-
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines, "test"));
234+
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines, true));
235235
}
236236
}
237237
}

RetailCoder.VBE/Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ private void AddInterface()
103103
{
104104
interfaceComponent.Name = _model.InterfaceName;
105105

106-
interfaceModule.InsertLines(1, Tokens.Option + ' ' + Tokens.Explicit + Environment.NewLine);
106+
var optionPresent = interfaceModule.CountOfLines > 1;
107+
if (!optionPresent)
108+
{
109+
interfaceModule.InsertLines(1, Tokens.Option + ' ' + Tokens.Explicit + Environment.NewLine);
110+
}
107111
interfaceModule.InsertLines(3, GetInterfaceModuleBody());
108112

109113
var module = _model.TargetDeclaration.QualifiedSelection.QualifiedName.Component.CodeModule;

RetailCoder.VBE/Refactorings/ExtractMethod/ExtractMethodPresenter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void GeneratePreview(IExtractMethodModel extractMethodModel,IExtractMeth
8585
*/
8686
var extractedMethod = extractMethodProc.createProc(extractMethodModel);
8787
var code = extractedMethod.Split(new[]{Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
88-
code = _indenter.Indent(code, "Preview").ToArray();
88+
code = _indenter.Indent(code).ToArray();
8989
_view.Preview = string.Join(Environment.NewLine, code);
9090
}
9191
}

RetailCoder.VBE/UI/Refactorings/EncapsulateFieldDialog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ private string GetPropertyText()
164164
(MustImplementSetSetterType ? setterText : string.Empty);
165165

166166
var propertyTextLines = propertyText.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
167-
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines, "test"));
167+
return string.Join(Environment.NewLine, _indenter.Indent(propertyTextLines));
168168
}
169169

170170
private void ValidatePropertyName()

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 19 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

RetailCoder.VBE/UI/RubberduckUI.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,4 +1902,10 @@ End Sub</value>
19021902
<value>Smart Indenter settings were found in your registry.
19031903
Would you like to import them to Rubberduck?</value>
19041904
</data>
1905+
<data name="IndenterSettings_VerticalSpacing" xml:space="preserve">
1906+
<value>Maintain vertical spacing</value>
1907+
</data>
1908+
<data name="IndenterSettings_VerticalSpacingLabel" xml:space="preserve">
1909+
<value>Vertical Spacing</value>
1910+
</data>
19051911
</root>

RetailCoder.VBE/UI/Settings/IndenterSettings.xaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,23 @@
194194
NumValue="{Binding IndentSpaces, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
195195
MinNumber="0"/>
196196
</StackPanel>
197+
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_VerticalSpacingLabel}"
198+
FontWeight="SemiBold" />
199+
<WrapPanel Orientation="Horizontal">
200+
<CheckBox Name="SpaceProcedures"
201+
IsChecked="{Binding VerticallySpaceProcedures, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
202+
Margin="5,0,0,5"
203+
HorizontalAlignment="Left">
204+
<AccessText Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_VerticalSpacing}"
205+
TextWrapping="WrapWithOverflow" />
206+
</CheckBox>
207+
<controls:NumberPicker Margin="0,-6,0,0"
208+
IsEnabled="{Binding ElementName=SpaceProcedures, Path=IsChecked}"
209+
NumValue="{Binding LinesBetweenProcedures, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
210+
HorizontalAlignment="Left"
211+
MinNumber="0"
212+
MaxNumber="2"/>
213+
</WrapPanel>
197214
</StackPanel>
198215
</Grid>
199216
</StackPanel>

RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public IndenterSettingsViewModel(Configuration config)
2828
_indentFirstCommentBlock = config.UserSettings.IndenterSettings.IndentFirstCommentBlock;
2929
_indentFirstDeclarationBlock = config.UserSettings.IndenterSettings.IndentFirstDeclarationBlock;
3030
_indentSpaces = config.UserSettings.IndenterSettings.IndentSpaces;
31+
_spaceProcedures = config.UserSettings.IndenterSettings.VerticallySpaceProcedures;
32+
_procedureSpacing = config.UserSettings.IndenterSettings.LinesBetweenProcedures;
3133

3234
PropertyChanged += IndenterSettingsViewModel_PropertyChanged;
3335
ExportButtonCommand = new DelegateCommand(LogManager.GetCurrentClassLogger(), _ => ExportSettings());
@@ -269,14 +271,42 @@ public int IndentSpaces
269271
}
270272
}
271273

274+
private bool _spaceProcedures;
275+
public bool VerticallySpaceProcedures
276+
{
277+
get { return _spaceProcedures; }
278+
set
279+
{
280+
if (_spaceProcedures != value)
281+
{
282+
_spaceProcedures = value;
283+
OnPropertyChanged();
284+
}
285+
}
286+
}
287+
288+
private int _procedureSpacing;
289+
public int LinesBetweenProcedures
290+
{
291+
get { return _procedureSpacing; }
292+
set
293+
{
294+
if (_procedureSpacing != value)
295+
{
296+
_procedureSpacing = value;
297+
OnPropertyChanged();
298+
}
299+
}
300+
}
301+
272302
public string PreviewSampleCode
273303
{
274304
get
275305
{
276306
var indenter = new Indenter(null, GetCurrentSettings);
277307

278308
var lines = RubberduckUI.IndenterSettings_PreviewCode.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
279-
lines = indenter.Indent(lines, "TestModule").ToArray();
309+
lines = indenter.Indent(lines).ToArray();
280310
return string.Join(Environment.NewLine, lines);
281311
}
282312
}
@@ -300,7 +330,9 @@ private IIndenterSettings GetCurrentSettings()
300330
IndentEntireProcedureBody = IndentEntireProcedureBody,
301331
IndentFirstCommentBlock = IndentFirstCommentBlock,
302332
IndentFirstDeclarationBlock = IndentFirstDeclarationBlock,
303-
IndentSpaces = IndentSpaces
333+
IndentSpaces = IndentSpaces,
334+
VerticallySpaceProcedures = VerticallySpaceProcedures,
335+
LinesBetweenProcedures = LinesBetweenProcedures
304336
};
305337
}
306338

@@ -324,6 +356,8 @@ public void UpdateConfig(Configuration config)
324356
config.UserSettings.IndenterSettings.IndentFirstCommentBlock = IndentFirstCommentBlock;
325357
config.UserSettings.IndenterSettings.IndentFirstDeclarationBlock = IndentFirstDeclarationBlock;
326358
config.UserSettings.IndenterSettings.IndentSpaces = IndentSpaces;
359+
config.UserSettings.IndenterSettings.VerticallySpaceProcedures = VerticallySpaceProcedures;
360+
config.UserSettings.IndenterSettings.LinesBetweenProcedures = LinesBetweenProcedures;
327361
}
328362

329363
public void SetToDefaults(Configuration config)
@@ -348,7 +382,9 @@ private void TransferSettingsToView(IIndenterSettings toLoad)
348382
IndentEntireProcedureBody = toLoad.IndentEntireProcedureBody;
349383
IndentFirstCommentBlock = toLoad.IndentFirstCommentBlock;
350384
IndentFirstDeclarationBlock = toLoad.IndentFirstDeclarationBlock;
351-
IndentSpaces = toLoad.IndentSpaces;
385+
IndentSpaces = toLoad.IndentSpaces;
386+
VerticallySpaceProcedures = toLoad.VerticallySpaceProcedures;
387+
LinesBetweenProcedures = toLoad.LinesBetweenProcedures;
352388
}
353389

354390
private void ImportSettings()
Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Antlr4.Runtime;
2+
using Rubberduck.Parsing.Grammar;
23
using Rubberduck.VBEditor;
34

45
namespace Rubberduck.Parsing
@@ -14,17 +15,26 @@ public static Selection GetSelection(this ParserRuleContext context)
1415
// 1 is the default value that will select all lines. Replace zeroes with ones.
1516
// See also: https://msdn.microsoft.com/en-us/library/aa443952(v=vs.60).aspx
1617

17-
var startLine = context.Start.Line == 0 ? 1 : context.Start.Line;
18-
var startCol = context.Start.Column + 1;
19-
var endLine = context.Stop.Line == 0 ? 1 : context.Stop.Line;
20-
var endCol = context.Stop.Column + context.Stop.Text.Length + 1;
18+
return new Selection(context.Start.Line == 0 ? 1 : context.Start.Line,
19+
context.Start.Column + 1,
20+
context.Stop.Line == 0 ? 1 : context.Stop.Line,
21+
context.Stop.Column + context.Stop.Text.Length + 1);
22+
}
23+
24+
//This set of overloads returns the selection for the entire procedure statement body, i.e. Public Function Foo(bar As String) As String
25+
public static Selection GetProcedureSelection(this VBAParser.FunctionStmtContext context) { return GetProcedureContextSelection(context); }
26+
public static Selection GetProcedureSelection(this VBAParser.SubStmtContext context) { return GetProcedureContextSelection(context); }
27+
public static Selection GetProcedureSelection(this VBAParser.PropertyGetStmtContext context) { return GetProcedureContextSelection(context); }
28+
public static Selection GetProcedureSelection(this VBAParser.PropertyLetStmtContext context) { return GetProcedureContextSelection(context); }
29+
public static Selection GetProcedureSelection(this VBAParser.PropertySetStmtContext context) { return GetProcedureContextSelection(context); }
2130

22-
return new Selection(
23-
startLine,
24-
startCol,
25-
endLine,
26-
endCol
27-
);
31+
private static Selection GetProcedureContextSelection(ParserRuleContext context)
32+
{
33+
var endContext = context.GetRuleContext<VBAParser.EndOfStatementContext>(0);
34+
return new Selection(context.Start.Line == 0 ? 1 : context.Start.Line,
35+
context.Start.Column + 1,
36+
endContext.Start.Line == 0 ? 1 : endContext.Start.Line,
37+
endContext.Start.Column + 1);
2838
}
2939
}
3040
}

Rubberduck.Parsing/Symbols/DeclarationSymbolsListener.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ public override void EnterFunctionStmt(VBAParser.FunctionStmtContext context)
470470
? Tokens.Variant
471471
: asTypeClause.type().GetText();
472472
var typeHint = Identifier.GetTypeHintValue(identifier);
473-
var isArray = asTypeClause != null && asTypeClause.type().LPAREN() != null;
473+
var isArray = asTypeName.EndsWith("()");
474474
var declaration = CreateDeclaration(
475475
name,
476476
asTypeName,

0 commit comments

Comments
 (0)