Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions RetailCoder.VBE/UI/Settings/IndenterSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@
NumValue="{Binding IndentSpaces, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
MinNumber="0"/>
</StackPanel>
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_EnableOptionsLabel}"
FontWeight="SemiBold" />
<CheckBox IsChecked="{Binding EnableUndo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Margin="5,0,0,5"
HorizontalAlignment="Left">
<AccessText Text="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=IndenterSettings_EnableUndo}"
TextWrapping="WrapWithOverflow" />
</CheckBox>
</StackPanel>
</Grid>
</StackPanel>
Expand Down
18 changes: 0 additions & 18 deletions RetailCoder.VBE/UI/Settings/IndenterSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public IndenterSettingsViewModel(Configuration config)
_alignContinuations = config.UserSettings.IndenterSettings.AlignContinuations;
_alignDimColumn = config.UserSettings.IndenterSettings.AlignDimColumn;
_alignDims = config.UserSettings.IndenterSettings.AlignDims;
_enableUndo = config.UserSettings.IndenterSettings.EnableUndo;
_endOfLineCommentColumnSpaceAlignment = config.UserSettings.IndenterSettings.EndOfLineCommentColumnSpaceAlignment;
_endOfLineCommentStyle = config.UserSettings.IndenterSettings.EndOfLineCommentStyle;
_forceCompilerDirectivesInColumn1 = config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1;
Expand Down Expand Up @@ -112,20 +111,6 @@ public bool AlignDims
}
}

private bool _enableUndo;
public bool EnableUndo
{
get { return _enableUndo; }
set
{
if (_enableUndo != value)
{
_enableUndo = value;
OnPropertyChanged();
}
}
}

private int _endOfLineCommentColumnSpaceAlignment;
public int EndOfLineCommentColumnSpaceAlignment
{
Expand Down Expand Up @@ -299,7 +284,6 @@ private IIndenterSettings GetCurrentSettings()
AlignContinuations = AlignContinuations,
AlignDimColumn = AlignDimColumn,
AlignDims = AlignDims,
EnableUndo = EnableUndo,
EndOfLineCommentColumnSpaceAlignment = EndOfLineCommentColumnSpaceAlignment,
EndOfLineCommentStyle = EndOfLineCommentStyle,
ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1,
Expand All @@ -323,7 +307,6 @@ public void UpdateConfig(Configuration config)
config.UserSettings.IndenterSettings.AlignContinuations = AlignContinuations;
config.UserSettings.IndenterSettings.AlignDimColumn = AlignDimColumn;
config.UserSettings.IndenterSettings.AlignDims = AlignDims;
config.UserSettings.IndenterSettings.EnableUndo = EnableUndo;
config.UserSettings.IndenterSettings.EndOfLineCommentColumnSpaceAlignment = EndOfLineCommentColumnSpaceAlignment;
config.UserSettings.IndenterSettings.EndOfLineCommentStyle = EndOfLineCommentStyle;
config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1 = ForceCompilerDirectivesInColumn1;
Expand All @@ -344,7 +327,6 @@ public void SetToDefaults(Configuration config)
AlignContinuations = config.UserSettings.IndenterSettings.AlignContinuations;
AlignDimColumn = config.UserSettings.IndenterSettings.AlignDimColumn;
AlignDims = config.UserSettings.IndenterSettings.AlignDims;
EnableUndo = config.UserSettings.IndenterSettings.EnableUndo;
EndOfLineCommentColumnSpaceAlignment = config.UserSettings.IndenterSettings.EndOfLineCommentColumnSpaceAlignment;
EndOfLineCommentStyle = config.UserSettings.IndenterSettings.EndOfLineCommentStyle;
ForceCompilerDirectivesInColumn1 = config.UserSettings.IndenterSettings.ForceCompilerDirectivesInColumn1;
Expand Down
13 changes: 9 additions & 4 deletions Rubberduck.SmartIndenter/AbsoluteCodeLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ internal class AbsoluteCodeLine
private const char BracketPlaceholder = '\x2';
private static readonly Regex StringReplaceRegex = new Regex(StringPlaceholder.ToString(CultureInfo.InvariantCulture));
private static readonly Regex BracketReplaceRegex = new Regex(BracketPlaceholder.ToString(CultureInfo.InvariantCulture));
private static readonly Regex LineNumberRegex = new Regex(@"^(?<number>\d+)\s+(?<code>.*)", RegexOptions.ExplicitCapture);
private static readonly Regex LineNumberRegex = new Regex(@"^(?<number>(-?\d+)|(&H[0-9A-F]{1,8}))\s+(?<code>.*)", RegexOptions.ExplicitCapture);
private static readonly Regex EndOfLineCommentRegex = new Regex(@"^(?!(Rem\s)|('))(?<code>[^']*)(\s(?<comment>'.*))$", RegexOptions.ExplicitCapture);
private static readonly Regex ProcedureStartRegex = new Regex(@"^(Public\s|Private\s|Friend\s)?(Static\s)?(Sub|Function|Property\s(Let|Get|Set))\s");
private static readonly Regex ProcedureStartIgnoreRegex = new Regex(@"^[LR]?Set\s|^Let\s|^(Public|Private)\sDeclare\s(Function|Sub)");
Expand All @@ -29,7 +29,7 @@ internal class AbsoluteCodeLine
private static readonly Regex SingleLineElseIfRegex = new Regex(@"^ElseIf\s.*\sThen\s.*");

private readonly IIndenterSettings _settings;
private uint _lineNumber;
private int _lineNumber;
private bool _numbered;
private string _code;
private readonly bool _stupidLineEnding;
Expand Down Expand Up @@ -129,9 +129,14 @@ private void ExtractLineNumber()
var match = LineNumberRegex.Match(_code);
if (match.Success)
{
_numbered = true;
_lineNumber = Convert.ToUInt32(match.Groups["number"].Value);
_code = match.Groups["code"].Value;
_numbered = true;
var number = match.Groups["number"].Value;
if (!int.TryParse(number, out _lineNumber))
{
int.TryParse(number.Replace("&H", string.Empty), NumberStyles.HexNumber,
CultureInfo.InvariantCulture, out _lineNumber);
}
}
}
_code = _code.Trim();
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.SmartIndenter/IIndenterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ public interface IIndenterSettings
bool IndentCompilerDirectives { get; set; }
bool AlignDims { get; set; }
int AlignDimColumn { get; set; }
bool EnableUndo { get; set; }
EndOfLineCommentStyle EndOfLineCommentStyle { get; set; }
int EndOfLineCommentColumnSpaceAlignment { get; set; }
int IndentSpaces { get; set; }
Expand Down
19 changes: 5 additions & 14 deletions Rubberduck.SmartIndenter/Indenter.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Configuration;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using Rubberduck.VBEditor.SafeComWrappers.VBA;
Expand Down Expand Up @@ -71,13 +72,8 @@ public void Indent(IVBComponent component)
var codeLines = module.GetLines(1, lineCount).Replace("\r", string.Empty).Split('\n');
var indented = Indent(codeLines, component.Name).ToArray();

for (var i = 0; i < lineCount; i++)
{
if (module.GetLines(i + 1, 1) != indented[i])
{
component.CodeModule.ReplaceLine(i + 1, indented[i]);
}
}
module.DeleteLines(1, lineCount);
module.InsertLines(1, string.Join("\r\n", indented));
}

public void Indent(IVBComponent component, string procedureName, Selection selection)
Expand All @@ -93,13 +89,8 @@ public void Indent(IVBComponent component, string procedureName, Selection selec

var indented = Indent(codeLines, procedureName).ToArray();

for (var i = 0; i < selection.EndLine - selection.StartLine; i++)
{
if (module.GetLines(selection.StartLine + i, 1) != indented[i])
{
component.CodeModule.ReplaceLine(selection.StartLine + i, indented[i]);
}
}
module.DeleteLines(selection.StartLine, selection.LineCount);
module.InsertLines(selection.StartLine, string.Join("\r\n", indented));
}

private IEnumerable<LogicalCodeLine> BuildLogicalCodeLines(IEnumerable<string> lines)
Expand Down
2 changes: 0 additions & 2 deletions Rubberduck.SmartIndenter/IndenterSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class IndenterSettings : IIndenterSettings
public virtual bool IndentCompilerDirectives { get; set; }
public virtual bool AlignDims { get; set; }
public virtual int AlignDimColumn { get; set; }
public virtual bool EnableUndo { get; set; }
public virtual EndOfLineCommentStyle EndOfLineCommentStyle { get; set; }
public virtual int EndOfLineCommentColumnSpaceAlignment { get; set; }
public virtual int IndentSpaces { get; set; }
Expand Down Expand Up @@ -48,7 +47,6 @@ public IndenterSettings()
IndentCompilerDirectives = true;
AlignDims = false;
AlignDimColumn = 15;
EnableUndo = true;
EndOfLineCommentStyle = EndOfLineCommentStyle.AlignInColumn;
EndOfLineCommentColumnSpaceAlignment = 50;
IndentSpaces = tabWidth;
Expand Down
80 changes: 48 additions & 32 deletions RubberduckTests/CodeExplorer/CodeExplorerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object,() => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -605,7 +605,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -650,7 +650,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -705,7 +705,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -743,7 +743,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -793,7 +793,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -853,7 +853,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -892,7 +892,7 @@ Dim d As Boolean
var state = new RubberduckParserState(new Mock<ISinks>().Object);
var commands = new List<CommandBase>
{
new IndentCommand(state, new Indenter(vbe.Object, GetDefaultIndenterSettings), null)
new IndentCommand(state, new Indenter(vbe.Object, () => Settings.IndenterSettingsTests.GetMockIndenterSettings()), null)
};

var vm = new CodeExplorerViewModel(new FolderHelper(state, GetDelimiterConfigLoader()), state, commands);
Expand Down Expand Up @@ -1476,30 +1476,46 @@ private Configuration GetDelimiterConfig()
return new Configuration(userSettings);
}

private IIndenterSettings GetDefaultIndenterSettings()
{
var indenterSettings = new IndenterSettings
{
IndentEntireProcedureBody = true,
IndentFirstCommentBlock = true,
IndentFirstDeclarationBlock = true,
AlignCommentsWithCode = true,
AlignContinuations = true,
IgnoreOperatorsInContinuations = true,
IndentCase = false,
ForceDebugStatementsInColumn1 = false,
ForceCompilerDirectivesInColumn1 = false,
IndentCompilerDirectives = true,
AlignDims = false,
AlignDimColumn = 15,
EnableUndo = true,
EndOfLineCommentStyle = EndOfLineCommentStyle.AlignInColumn,
EndOfLineCommentColumnSpaceAlignment = 50,
IndentSpaces = 4
};

return indenterSettings;
}
//private IIndenterSettings Settings.IndenterSettingsTests.GetMockIndenterSettings()()
//{
// var indenterSettings = new IndenterSettings
// {
// IndentEntireProcedureBody = true,
// IndentFirstCommentBlock = true,
// IndentFirstDeclarationBlock = true,
// AlignCommentsWithCode = true,
// AlignContinuations = true,
// IgnoreOperatorsInContinuations = true,
// IndentCase = false,
// ForceDebugStatementsInColumn1 = false,
// ForceCompilerDirectivesInColumn1 = false,
// IndentCompilerDirectives = true,
// AlignDims = false,
// AlignDimColumn = 15,
// EndOfLineCommentStyle = EndOfLineCommentStyle.AlignInColumn,
// EndOfLineCommentColumnSpaceAlignment = 50,
// IndentSpaces = 4
// };

// var settings = new Mock<IndenterSettings>();
// settings.Setup(s => s.IndentEntireProcedureBody).Returns(true);
// settings.Setup(s => s.IndentFirstCommentBlock).Returns(true);
// settings.Setup(s => s.IndentFirstDeclarationBlock).Returns(true);
// settings.Setup(s => s.AlignCommentsWithCode).Returns(true);
// settings.Setup(s => s.AlignContinuations).Returns(true);
// settings.Setup(s => s.IgnoreOperatorsInContinuations).Returns(true);
// settings.Setup(s => s.IndentCase).Returns(false);
// settings.Setup(s => s.ForceDebugStatementsInColumn1).Returns(false);
// settings.Setup(s => s.ForceCompilerDirectivesInColumn1).Returns(false);
// settings.Setup(s => s.IndentCompilerDirectives).Returns(true);
// settings.Setup(s => s.AlignDims).Returns(false);
// settings.Setup(s => s.AlignDimColumn).Returns(15);
// settings.Setup(s => s.EndOfLineCommentStyle).Returns(EndOfLineCommentStyle.AlignInColumn);
// settings.Setup(s => s.EndOfLineCommentColumnSpaceAlignment).Returns(50);
// settings.Setup(s => s.IndentSpaces).Returns(4);

// return indenterSettings;
//}

private ConfigurationLoader GetDelimiterConfigLoader()
{
Expand Down
37 changes: 18 additions & 19 deletions RubberduckTests/Commands/IndentCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,25 +224,24 @@ public void IndentModule_CanExecute()

private static IIndenter CreateIndenter(IVBE vbe)
{
var settings = new Mock<IndenterSettings>();
settings.Setup(s => s.IndentEntireProcedureBody).Returns(true);
settings.Setup(s => s.IndentFirstCommentBlock).Returns(true);
settings.Setup(s => s.IndentFirstDeclarationBlock).Returns(true);
settings.Setup(s => s.AlignCommentsWithCode).Returns(true);
settings.Setup(s => s.AlignContinuations).Returns(true);
settings.Setup(s => s.IgnoreOperatorsInContinuations).Returns(true);
settings.Setup(s => s.IndentCase).Returns(false);
settings.Setup(s => s.ForceDebugStatementsInColumn1).Returns(false);
settings.Setup(s => s.ForceCompilerDirectivesInColumn1).Returns(false);
settings.Setup(s => s.IndentCompilerDirectives).Returns(true);
settings.Setup(s => s.AlignDims).Returns(false);
settings.Setup(s => s.AlignDimColumn).Returns(15);
settings.Setup(s => s.EnableUndo).Returns(true);
settings.Setup(s => s.EndOfLineCommentStyle).Returns(EndOfLineCommentStyle.AlignInColumn);
settings.Setup(s => s.EndOfLineCommentColumnSpaceAlignment).Returns(50);
settings.Setup(s => s.IndentSpaces).Returns(4);

return new Indenter(vbe, () => new IndenterSettings());
//var settings = new Mock<IndenterSettings>();
//settings.Setup(s => s.IndentEntireProcedureBody).Returns(true);
//settings.Setup(s => s.IndentFirstCommentBlock).Returns(true);
//settings.Setup(s => s.IndentFirstDeclarationBlock).Returns(true);
//settings.Setup(s => s.AlignCommentsWithCode).Returns(true);
//settings.Setup(s => s.AlignContinuations).Returns(true);
//settings.Setup(s => s.IgnoreOperatorsInContinuations).Returns(true);
//settings.Setup(s => s.IndentCase).Returns(false);
//settings.Setup(s => s.ForceDebugStatementsInColumn1).Returns(false);
//settings.Setup(s => s.ForceCompilerDirectivesInColumn1).Returns(false);
//settings.Setup(s => s.IndentCompilerDirectives).Returns(true);
//settings.Setup(s => s.AlignDims).Returns(false);
//settings.Setup(s => s.AlignDimColumn).Returns(15);
//settings.Setup(s => s.EndOfLineCommentStyle).Returns(EndOfLineCommentStyle.AlignInColumn);
//settings.Setup(s => s.EndOfLineCommentColumnSpaceAlignment).Returns(50);
//settings.Setup(s => s.IndentSpaces).Returns(4);

return new Indenter(vbe, () => Settings.IndenterSettingsTests.GetMockIndenterSettings());
}
}
}
Loading