Skip to content

Commit 84503b7

Browse files
committed
Address PR comments
Revert changes to RegistryAccess and IndenterSettings -- registry work requires more thought than simply wrapping a new using block.
1 parent 9bfbca0 commit 84503b7

File tree

12 files changed

+250
-175
lines changed

12 files changed

+250
-175
lines changed

Rubberduck.Core/Common/WinAPI/RegistryAccess.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ internal static RegistryKey GetDeviceKey(string device)
1818

1919
internal static string GetClassType(string classGuid)
2020
{
21-
using (var classGuidKey =
22-
Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + classGuid))
23-
{
24-
return classGuidKey != null ? (string) classGuidKey.GetValue("Class") : string.Empty;
25-
}
21+
var classGuidKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Control\Class\" + classGuid);
22+
23+
return classGuidKey != null ? (string)classGuidKey.GetValue("Class") : string.Empty;
2624
}
2725
}
2826
}

Rubberduck.Core/UI/Command/ExportAllCommand.cs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -61,32 +61,44 @@ private bool Evaluate(IVBProject project)
6161

6262
protected override void OnExecute(object parameter)
6363
{
64-
var projectNode = parameter as CodeExplorerProjectViewModel;
64+
switch (parameter)
65+
{
66+
case CodeExplorerProjectViewModel projectNode when projectNode.Declaration.Project != null:
67+
Export(projectNode.Declaration.Project);
68+
break;
69+
case IVBProject vbproject:
70+
Export(vbproject);
71+
break;
72+
default:
73+
{
74+
using (var project = _vbe.ActiveVBProject)
75+
{
76+
Export(project);
77+
}
78+
break;
79+
}
80+
}
81+
}
6582

66-
var vbproject = parameter as IVBProject;
83+
private void Export(IVBProject project)
84+
{
85+
var desc = string.Format(RubberduckUI.ExportAllCommand_SaveAsDialog_Title, project.Name);
6786

68-
using (var activeProject = _vbe.ActiveVBProject)
87+
// If .GetDirectoryName is passed an empty string for a RootFolder,
88+
// it defaults to the Documents library (Win 7+) or equivalent.
89+
var path = string.Empty;
90+
if (!string.IsNullOrWhiteSpace(project.FileName))
6991
{
70-
var project = projectNode?.Declaration.Project ?? vbproject ?? activeProject;
71-
72-
var desc = string.Format(RubberduckUI.ExportAllCommand_SaveAsDialog_Title, project.Name);
92+
path = Path.GetDirectoryName(project.FileName);
93+
}
7394

74-
// If .GetDirectoryName is passed an empty string for a RootFolder,
75-
// it defaults to the Documents library (Win 7+) or equivalent.
76-
var path = string.Empty;
77-
if (!string.IsNullOrWhiteSpace(project.FileName))
78-
{
79-
path = Path.GetDirectoryName(project.FileName);
80-
}
95+
using (var _folderBrowser = _factory.CreateFolderBrowser(desc, true, path))
96+
{
97+
var result = _folderBrowser.ShowDialog();
8198

82-
using (var _folderBrowser = _factory.CreateFolderBrowser(desc, true, path))
99+
if (result == DialogResult.OK)
83100
{
84-
var result = _folderBrowser.ShowDialog();
85-
86-
if (result == DialogResult.OK)
87-
{
88-
project.ExportSourceFiles(_folderBrowser.SelectedPath);
89-
}
101+
project.ExportSourceFiles(_folderBrowser.SelectedPath);
90102
}
91103
}
92104
}

Rubberduck.Core/UI/Command/FindAllReferencesCommand.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,7 @@ private Declaration FindFormDesignerTarget(QualifiedModuleName? qualifiedModuleN
239239
return null;
240240
}
241241

242-
// Cannot use DeclarationType.UserForm, parser only assigns UserForms the ClassModule flag
243-
(selectedType, selectedName) = selectedCount == 0
244-
? (DeclarationType.ClassModule, component.Name)
245-
: (DeclarationType.Control, selectedControls[0].Name);
242+
(selectedType, selectedName) = GetSelectedName(component, selectedControls, selectedCount);
246243
}
247244

248245
return _state.DeclarationFinder
@@ -256,6 +253,20 @@ private Declaration FindFormDesignerTarget(QualifiedModuleName? qualifiedModuleN
256253
}
257254
}
258255

256+
private static (DeclarationType, string Name) GetSelectedName(IVBComponent component, IControls selectedControls, int selectedCount)
257+
{
258+
// Cannot use DeclarationType.UserForm, parser only assigns UserForms the ClassModule flag
259+
if (selectedCount == 0)
260+
{
261+
return (DeclarationType.ClassModule, component.Name);
262+
}
263+
264+
using (var firstSelectedControl = selectedControls[0])
265+
{
266+
return (DeclarationType.Control, firstSelectedControl.Name);
267+
}
268+
}
269+
259270
private Declaration FindFormDesignerTarget(QualifiedModuleName qualifiedModuleName)
260271
{
261272
var projectId = qualifiedModuleName.ProjectId;

Rubberduck.Core/UI/Command/MenuItems/CommandBars/AppCommandBarBase.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public virtual void Initialize()
8787

8888
try
8989
{
90-
Item?.Dispose();
9190
Item = Parent.Add(_name, _position);
9291
Item.IsVisible = true;
9392
}
@@ -170,8 +169,27 @@ public void EvaluateCanExecute(RubberduckParserState state)
170169
}
171170
}
172171

173-
public ICommandBars Parent { get; set; }
174-
public ICommandBar Item { get; private set; }
172+
private ICommandBars _parent;
173+
public ICommandBars Parent
174+
{
175+
get => _parent;
176+
set
177+
{
178+
_parent?.Dispose();
179+
_parent = value;
180+
}
181+
}
182+
183+
private ICommandBar _item;
184+
public ICommandBar Item
185+
{
186+
get => _item;
187+
private set
188+
{
189+
_item?.Dispose();
190+
_item = value;
191+
}
192+
}
175193

176194
public void RemoveCommandBar()
177195
{
@@ -184,7 +202,6 @@ public void RemoveCommandBar()
184202
Item.Delete();
185203
Item.Dispose();
186204
Item = null;
187-
Parent?.Dispose();
188205
Parent = null;
189206
}
190207
}

Rubberduck.Core/UI/Command/MenuItems/ParentMenus/ParentMenuItemBase.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,27 @@ protected ParentMenuItemBase(string key, IEnumerable<IMenuItem> items, int? befo
2424
_items = items.ToDictionary(item => item, item => null as ICommandBarControl);
2525
}
2626

27-
public ICommandBarControls Parent { get; set; }
28-
public ICommandBarPopup Item { get; private set; }
27+
private ICommandBarControls _parent;
28+
public ICommandBarControls Parent
29+
{
30+
get => _parent;
31+
set
32+
{
33+
_parent?.Dispose();
34+
_parent = value;
35+
}
36+
}
37+
38+
private ICommandBarPopup _item;
39+
public ICommandBarPopup Item
40+
{
41+
get => _item;
42+
private set
43+
{
44+
_item?.Dispose();
45+
_item = value;
46+
}
47+
}
2948

3049
public string Key => Item?.Tag;
3150

@@ -73,7 +92,6 @@ public void Initialize()
7392
return;
7493
}
7594

76-
Item?.Dispose();
7795
Item = Parent.AddPopup(_beforeIndex);
7896

7997
Item.Tag = _key;
@@ -92,7 +110,6 @@ public void RemoveMenu()
92110
Logger.Debug($"Removing menu {_key}.");
93111
RemoveChildren();
94112
Item?.Delete();
95-
Item?.Dispose();
96113
Item = null;
97114
}
98115

0 commit comments

Comments
 (0)