Skip to content

Commit 176efbe

Browse files
committed
Merge branch 'comintern-next' into next
2 parents ea9af0a + 257c30d commit 176efbe

File tree

10 files changed

+163
-10
lines changed

10 files changed

+163
-10
lines changed

RetailCoder.VBE/App.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ public void Startup()
146146
{
147147
EnsureLogFolderPathExists();
148148
LoadConfig();
149+
CheckForLegacyIndenterSettings();
149150
_appMenus.Initialize();
150151
_stateBar.Initialize();
151152
_hooks.HookHotkeys(); // need to hook hotkeys before we localize menus, to correctly display ShortcutTexts
@@ -196,6 +197,32 @@ private void LoadConfig()
196197
}
197198
}
198199

200+
private void CheckForLegacyIndenterSettings()
201+
{
202+
try
203+
{
204+
Logger.Trace("Checking for legacy Smart Indenter settings.");
205+
if (_config.UserSettings.GeneralSettings.SmartIndenterPrompted ||
206+
!_config.UserSettings.IndenterSettings.LegacySettingsExist())
207+
{
208+
return;
209+
}
210+
var response =
211+
_messageBox.Show(RubberduckUI.SmartIndenter_LegacySettingPrompt, "Rubberduck", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
212+
if (response == DialogResult.Yes)
213+
{
214+
Logger.Trace("Attempting to load legacy Smart Indenter settings.");
215+
_config.UserSettings.IndenterSettings.LoadLegacyFromRegistry();
216+
}
217+
_config.UserSettings.GeneralSettings.SmartIndenterPrompted = true;
218+
_configService.SaveConfiguration(_config);
219+
}
220+
catch
221+
{
222+
//Meh.
223+
}
224+
}
225+
199226
private bool _disposed;
200227
public void Dispose()
201228
{

RetailCoder.VBE/Settings/GeneralSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface IGeneralSettings
77
{
88
DisplayLanguageSetting Language { get; set; }
99
bool ShowSplash { get; set; }
10+
bool SmartIndenterPrompted { get; set; }
1011
bool AutoSaveEnabled { get; set; }
1112
int AutoSavePeriod { get; set; }
1213
char Delimiter { get; set; }
@@ -18,6 +19,7 @@ public class GeneralSettings : IGeneralSettings
1819
{
1920
public DisplayLanguageSetting Language { get; set; }
2021
public bool ShowSplash { get; set; }
22+
public bool SmartIndenterPrompted { get; set; }
2123
public bool AutoSaveEnabled { get; set; }
2224
public int AutoSavePeriod { get; set; }
2325
public char Delimiter { get; set; }
@@ -27,6 +29,7 @@ public GeneralSettings()
2729
{
2830
Language = new DisplayLanguageSetting("en-US");
2931
ShowSplash = true;
32+
SmartIndenterPrompted = false;
3033
AutoSaveEnabled = false;
3134
AutoSavePeriod = 10;
3235
Delimiter = '.';

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Lines changed: 10 additions & 0 deletions
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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,4 +1883,8 @@ End Sub</value>
18831883
<value>references</value>
18841884
<comment>Used to display number of references in commandbar's context selection</comment>
18851885
</data>
1886+
<data name="SmartIndenter_LegacySettingPrompt" xml:space="preserve">
1887+
<value>Smart Indenter settings were found in your registry.
1888+
Would you like to import them to Rubberduck?</value>
1889+
</data>
18861890
</root>

RetailCoder.VBE/UI/Settings/GeneralSettingsViewModel.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public enum DelimiterOptions
1717
public class GeneralSettingsViewModel : SettingsViewModelBase, ISettingsViewModel
1818
{
1919
private readonly IOperatingSystem _operatingSystem;
20+
private bool _indenterPrompted;
2021

2122
public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem)
2223
{
@@ -166,6 +167,7 @@ private Rubberduck.Settings.GeneralSettings GetCurrentGeneralSettings()
166167
{
167168
Language = SelectedLanguage,
168169
ShowSplash = ShowSplashAtStartup,
170+
SmartIndenterPrompted = _indenterPrompted,
169171
AutoSaveEnabled = AutoSaveEnabled,
170172
AutoSavePeriod = AutoSavePeriod,
171173
Delimiter = (char)Delimiter,
@@ -178,6 +180,7 @@ private void TransferSettingsToView(IGeneralSettings general, IHotkeySettings ho
178180
SelectedLanguage = Languages.First(l => l.Code == general.Language.Code);
179181
Hotkeys = new ObservableCollection<HotkeySetting>(hottkey.Settings);
180182
ShowSplashAtStartup = general.ShowSplash;
183+
_indenterPrompted = general.SmartIndenterPrompted;
181184
AutoSaveEnabled = general.AutoSaveEnabled;
182185
AutoSavePeriod = general.AutoSavePeriod;
183186
Delimiter = (DelimiterOptions)general.Delimiter;
@@ -198,6 +201,8 @@ private void ImportSettings()
198201
var general = service.Load(new Rubberduck.Settings.GeneralSettings());
199202
var hkService = new XmlPersistanceService<HotkeySettings> { FilePath = dialog.FileName };
200203
var hotkey = hkService.Load(new HotkeySettings());
204+
//Always assume Smart Indenter registry import has been prompted if importing.
205+
general.SmartIndenterPrompted = true;
201206
TransferSettingsToView(general, hotkey);
202207
}
203208
}

Rubberduck.Parsing/Symbols/AliasDeclarations.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class AliasDeclarations : ICustomDeclarationLoader
1414
private Declaration _fileSystemModule;
1515
private Declaration _interactionModule;
1616
private Declaration _stringsModule;
17-
17+
private Declaration _dateTimeModule;
1818

1919
public AliasDeclarations(RubberduckParserState state)
2020
{
@@ -79,6 +79,9 @@ private void UpdateAliasFunctionModulesFromReferencedProjects(RubberduckParserSt
7979

8080
_stringsModule = state.AllDeclarations.SingleOrDefault(
8181
item => item.IdentifierName == "Strings" && item.Scope == "VBE7.DLL;VBA.Strings");
82+
83+
_dateTimeModule = state.AllDeclarations.SingleOrDefault(
84+
item => item.IdentifierName == "DateTime" && item.Scope == "VBE7.DLL;VBA.DateTime");
8285
}
8386

8487

Rubberduck.Parsing/Symbols/SerializableDeclaration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class SerializableDeclarationTree
1414
public readonly SerializableDeclaration Node;
1515

1616
[DataMember(IsRequired = true)]
17-
public readonly IEnumerable<SerializableDeclarationTree> Children;
17+
public IEnumerable<SerializableDeclarationTree> Children;
1818

1919
public SerializableDeclarationTree(Declaration declaration)
2020
: this(new SerializableDeclaration(declaration)) { }

Rubberduck.Parsing/VBA/RubberduckParser.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,17 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects)
432432
{
433433
try
434434
{
435-
LoadSerializedBuiltInReferences(State);
436-
//var comReflector = new ReferencedDeclarationsCollector(State);
437-
//SerializableDeclarationTree tree;
435+
var comReflector = new ReferencedDeclarationsCollector(State);
436+
437+
var items = comReflector.GetDeclarationsForReference(localReference);
438+
var root = items.SingleOrDefault(x => x.DeclarationType == DeclarationType.Project);
439+
var serialize = new List<Declaration>(items);
440+
var tree = GetSerializableTreeForDeclaration(root, serialize);
441+
442+
if (tree != null)
443+
{
444+
State.BuiltInDeclarationTrees.Add(tree);
445+
}
438446

439447
//var items = comReflector.GetDeclarationsForReference(localReference, out tree);
440448
//if (tree != null)
@@ -446,7 +454,7 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects)
446454
//{
447455
// State.AddDeclaration(declaration);
448456
//}
449-
}
457+
}
450458
catch (Exception exception)
451459
{
452460
unmapped.Add(reference);
@@ -488,6 +496,21 @@ private void SyncComReferences(IReadOnlyList<IVBProject> projects)
488496
}
489497
}
490498

499+
private SerializableDeclarationTree GetSerializableTreeForDeclaration(Declaration declaration, List<Declaration> declarations)
500+
{
501+
var output = new SerializableDeclarationTree(declaration);
502+
var children = new List<SerializableDeclarationTree>();
503+
var nodes = declarations.Where(x => x.ParentDeclaration.Equals(declaration)).ToList();
504+
declarations.RemoveAll(nodes.Contains);
505+
foreach (var item in nodes)
506+
{
507+
children.Add(GetSerializableTreeForDeclaration(item, declarations));
508+
}
509+
510+
output.Children = children;
511+
return output;
512+
}
513+
491514
private void LoadSerializedBuiltInReferences(RubberduckParserState state)
492515
{
493516
var basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "Declarations");

Rubberduck.SmartIndenter/IIndenterSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public interface IIndenterSettings
1818
EndOfLineCommentStyle EndOfLineCommentStyle { get; set; }
1919
int EndOfLineCommentColumnSpaceAlignment { get; set; }
2020
int IndentSpaces { get; set; }
21+
22+
bool LegacySettingsExist();
23+
void LoadLegacyFromRegistry();
2124
}
2225

2326
public enum EndOfLineCommentStyle

Rubberduck.SmartIndenter/IndenterSettings.cs

Lines changed: 79 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,20 @@ public class IndenterSettings : IIndenterSettings
2727
public IndenterSettings()
2828
{
2929
var tabWidth = 4;
30-
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\6.0\Common", false) ??
31-
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\7.0\Common", false);
32-
if (reg != null)
30+
try
3331
{
34-
tabWidth = Convert.ToInt32(reg.GetValue("TabWidth") ?? tabWidth);
32+
var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\6.0\Common", false) ??
33+
Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\VBA\7.0\Common", false);
34+
if (reg != null)
35+
{
36+
tabWidth = Convert.ToInt32(reg.GetValue("TabWidth") ?? tabWidth);
37+
}
3538
}
39+
// ReSharper disable once EmptyGeneralCatchClause
40+
catch { }
3641

42+
// Mocking requires these to be virtual.
43+
// ReSharper disable DoNotCallOverridableMethodsInConstructor
3744
IndentEntireProcedureBody = true;
3845
IndentFirstCommentBlock = true;
3946
IndentEnumTypeAsProcedure = false;
@@ -50,6 +57,74 @@ public IndenterSettings()
5057
EndOfLineCommentStyle = EndOfLineCommentStyle.AlignInColumn;
5158
EndOfLineCommentColumnSpaceAlignment = 50;
5259
IndentSpaces = tabWidth;
60+
// ReSharper restore DoNotCallOverridableMethodsInConstructor
61+
}
62+
63+
private const string LegacySettingsSubKey = @"Software\VB and VBA Program Settings\Office Automation Ltd.\Smart Indenter";
64+
public bool LegacySettingsExist()
65+
{
66+
try
67+
{
68+
return (Registry.CurrentUser.OpenSubKey(LegacySettingsSubKey, false) != null);
69+
}
70+
catch
71+
{
72+
return false;
73+
}
74+
75+
}
76+
77+
public void LoadLegacyFromRegistry()
78+
{
79+
try
80+
{
81+
var reg = Registry.CurrentUser.OpenSubKey(LegacySettingsSubKey, false);
82+
if (reg == null) return;
83+
IndentEntireProcedureBody = GetSmartIndenterBoolean(reg, "IndentProc", IndentEntireProcedureBody);
84+
IndentFirstCommentBlock = GetSmartIndenterBoolean(reg, "IndentFirst", IndentFirstCommentBlock);
85+
IndentFirstDeclarationBlock = GetSmartIndenterBoolean(reg, "IndentDim", IndentFirstDeclarationBlock);
86+
AlignCommentsWithCode = GetSmartIndenterBoolean(reg, "IndentCmt", AlignCommentsWithCode);
87+
AlignContinuations = GetSmartIndenterBoolean(reg, "AlignContinued", AlignContinuations);
88+
IgnoreOperatorsInContinuations = GetSmartIndenterBoolean(reg, "AlignIgnoreOps",
89+
IgnoreOperatorsInContinuations);
90+
IndentCase = GetSmartIndenterBoolean(reg, "IndentCase", IndentCase);
91+
ForceDebugStatementsInColumn1 = GetSmartIndenterBoolean(reg, "DebugCol1", ForceDebugStatementsInColumn1);
92+
ForceCompilerDirectivesInColumn1 = GetSmartIndenterBoolean(reg, "CompilerCol1",
93+
ForceCompilerDirectivesInColumn1);
94+
IndentCompilerDirectives = GetSmartIndenterBoolean(reg, "IndentCompiler", IndentCompilerDirectives);
95+
AlignDims = GetSmartIndenterBoolean(reg, "AlignDim", AlignDims);
96+
AlignDimColumn = Convert.ToInt32(reg.GetValue("AlignDimCol") ?? AlignDimColumn);
97+
98+
var eolSytle = reg.GetValue("EOLComments") as string;
99+
if (!string.IsNullOrEmpty(eolSytle))
100+
{
101+
switch (eolSytle)
102+
{
103+
case "Absolute":
104+
EndOfLineCommentStyle = EndOfLineCommentStyle.Absolute;
105+
break;
106+
case "SameGap":
107+
EndOfLineCommentStyle = EndOfLineCommentStyle.SameGap;
108+
break;
109+
case "StandardGap":
110+
EndOfLineCommentStyle = EndOfLineCommentStyle.StandardGap;
111+
break;
112+
case "AlignInCol":
113+
EndOfLineCommentStyle = EndOfLineCommentStyle.AlignInColumn;
114+
break;
115+
}
116+
}
117+
EndOfLineCommentColumnSpaceAlignment =
118+
Convert.ToInt32(reg.GetValue("EOLAlignCol") ?? EndOfLineCommentColumnSpaceAlignment);
119+
}
120+
// ReSharper disable once EmptyGeneralCatchClause
121+
catch { }
122+
}
123+
124+
private static bool GetSmartIndenterBoolean(RegistryKey key, string name, bool current)
125+
{
126+
var value = key.GetValue(name) as string;
127+
return string.IsNullOrEmpty(value) ? current : value.Trim().Equals("Y");
53128
}
54129
}
55130
}

0 commit comments

Comments
 (0)