Skip to content

Commit c380cd6

Browse files
authored
Merge pull request #3621 from Hosch250/FixResx
"Experimental Features" settings enhancements.
2 parents a54e4c7 + c643afd commit c380cd6

File tree

45 files changed

+371
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+371
-205
lines changed

RetailCoder.VBE/Navigation/CodeExplorer/CodeExplorerViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ private void ExecuteRemoveComand(object param)
558558

559559
public Visibility ExportAllVisibility => CanExecuteExportAllCommand ? Visibility.Visible : Visibility.Collapsed;
560560

561-
public bool IsSourceControlEnabled => _generalSettings.IsSourceControlEnabled;
561+
public bool EnableSourceControl => _generalSettings.EnableExperimentalFeatures.Any(a => a.Key == RubberduckUI.GeneralSettings_EnableSourceControl);
562562

563563
public Visibility TreeViewVisibility => Projects == null || Projects.Count == 0 ? Visibility.Collapsed : Visibility.Visible;
564564

RetailCoder.VBE/Root/RubberduckIoCInstaller.cs

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
4646
using Component = Castle.MicroKernel.Registration.Component;
4747
using Rubberduck.UI.CodeMetrics;
48-
using Rubberduck.Navigation.CodeMetrics;
48+
using Rubberduck.Parsing.Common;
4949

5050
namespace Rubberduck.Root
5151
{
@@ -158,7 +158,9 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
158158
{
159159
foreach (var assembly in assembliesToRegister)
160160
{
161-
container.Register(Classes.FromAssembly(assembly)
161+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
162+
163+
container.Register(Classes.From(assemblyTypes)
162164
.InSameNamespaceAs<Configuration>()
163165
.WithService.AllInterfaces()
164166
.LifestyleSingleton());
@@ -184,11 +186,15 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
184186
.LifestyleTransient());
185187
}
186188

187-
private static void ApplyDefaultInterfaceConvention(IWindsorContainer container, Assembly[] assembliesToRegister)
189+
private void ApplyDefaultInterfaceConvention(IWindsorContainer container, Assembly[] assembliesToRegister)
188190
{
189191
foreach (var assembly in assembliesToRegister)
190192
{
191-
container.Register(Classes.FromAssembly(assembly)
193+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
194+
195+
assemblyTypes.Any(t => t.Name == nameof(IMessageBox));
196+
197+
container.Register(Classes.From(assemblyTypes)
192198
.Where(type => type.Namespace != null
193199
&& !type.Namespace.StartsWith("Rubberduck.VBEditor.SafeComWrappers")
194200
&& !type.Name.Equals("SelectionChangeService")
@@ -201,11 +207,13 @@ private static void ApplyDefaultInterfaceConvention(IWindsorContainer container,
201207
}
202208
}
203209

204-
private static void RegisterFactories(IWindsorContainer container, Assembly[] assembliesToRegister)
210+
private void RegisterFactories(IWindsorContainer container, Assembly[] assembliesToRegister)
205211
{
206212
foreach (var assembly in assembliesToRegister)
207213
{
208-
container.Register(Types.FromAssembly(assembly)
214+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
215+
216+
container.Register(Types.From(assemblyTypes)
209217
.Where(type => type.IsInterface && type.Name.EndsWith("Factory"))
210218
.Configure(c => c.AsFactory())
211219
.LifestyleSingleton());
@@ -222,34 +230,40 @@ private static void RegisterSpecialFactories(IWindsorContainer container)
222230
.LifestyleSingleton());
223231
}
224232

225-
private static void RegisterQuickFixes(IWindsorContainer container, Assembly[] assembliesToRegister)
233+
private void RegisterQuickFixes(IWindsorContainer container, Assembly[] assembliesToRegister)
226234
{
227235
foreach (var assembly in assembliesToRegister)
228236
{
229-
container.Register(Classes.FromAssembly(assembly)
237+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
238+
239+
container.Register(Classes.From(assemblyTypes)
230240
.BasedOn<IQuickFix>()
231241
.WithService.Base()
232242
.WithService.Self()
233243
.LifestyleSingleton());
234244
}
235245
}
236246

237-
private static void RegisterInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
247+
private void RegisterInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
238248
{
239249
foreach (var assembly in assembliesToRegister)
240250
{
241-
container.Register(Classes.FromAssembly(assembly)
251+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
252+
253+
container.Register(Classes.From(assemblyTypes)
242254
.BasedOn<IInspection>()
243255
.WithService.Base()
244256
.LifestyleTransient());
245257
}
246258
}
247259

248-
private static void RegisterParseTreeInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
260+
private void RegisterParseTreeInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
249261
{
250262
foreach (var assembly in assembliesToRegister)
251263
{
252-
container.Register(Classes.FromAssembly(assembly)
264+
var assemblyTypes = GetIoCRegisteredTypes(assembly);
265+
266+
container.Register(Classes.From(assemblyTypes)
253267
.BasedOn<IParseTreeInspection>()
254268
.WithService.Base()
255269
.WithService.Select(new[]{typeof(IInspection)})
@@ -497,7 +511,7 @@ private Type[] ToolsMenuItems()
497511
typeof(ExportAllCommandMenuItem)
498512
};
499513

500-
if (_initialSettings.IsSourceControlEnabled)
514+
if (_initialSettings.EnableExperimentalFeatures.Any(a => a.Key == nameof(RubberduckUI.GeneralSettings_EnableSourceControl) && a.IsEnabled))
501515
{
502516
items.Add(typeof(SourceControlCommandMenuItem));
503517
}
@@ -564,7 +578,7 @@ private void RegisterCommands(IWindsorContainer container)
564578

565579
private void RegisterCommandsWithPresenters(IWindsorContainer container)
566580
{
567-
if (_initialSettings.IsSourceControlEnabled)
581+
if (_initialSettings.EnableExperimentalFeatures.Any(a => a.Key == nameof(RubberduckUI.GeneralSettings_EnableSourceControl) && a.IsEnabled))
568582
{
569583
container.Register(Component.For<CommandBase>()
570584
.ImplementedBy<SourceControlCommand>()
@@ -789,7 +803,7 @@ private void RegisterCustomDeclarationLoadersToParser(IWindsorContainer containe
789803
.LifestyleSingleton());
790804
}
791805

792-
private IEnumerable<Assembly> AssembliesToRegister()
806+
public static IEnumerable<Assembly> AssembliesToRegister()
793807
{
794808
var assemblies = new[]
795809
{
@@ -802,7 +816,7 @@ private IEnumerable<Assembly> AssembliesToRegister()
802816
return assemblies;
803817
}
804818

805-
private IEnumerable<Assembly> FindPlugins()
819+
private static IEnumerable<Assembly> FindPlugins()
806820
{
807821
var assemblies = new List<Assembly>();
808822
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
@@ -856,5 +870,18 @@ private static void RegisterHotkeyFactory(IWindsorContainer container)
856870
{
857871
container.Register(Component.For<HotkeyFactory>().LifestyleSingleton());
858872
}
873+
874+
private IEnumerable<TypeInfo> GetIoCRegisteredTypes(Assembly assembly)
875+
{
876+
return assembly.DefinedTypes
877+
.Where(w =>
878+
{
879+
var attribute = w.CustomAttributes.FirstOrDefault(f => f.AttributeType == typeof(ExperimentalAttribute));
880+
var ctorArg = attribute?.ConstructorArguments.Any() == true ? (string)attribute.ConstructorArguments.First().Value : string.Empty;
881+
882+
return attribute == null ||
883+
_initialSettings.EnableExperimentalFeatures.Any(a => a.Key == ctorArg && a.IsEnabled);
884+
});
885+
}
859886
}
860887
}

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<NoWarn>1591</NoWarn>
3232
<PlatformTarget>AnyCPU</PlatformTarget>
3333
<UseVSHostingProcess>true</UseVSHostingProcess>
34-
<LangVersion>7.1</LangVersion>
34+
<LangVersion>7.2</LangVersion>
3535
</PropertyGroup>
3636
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
3737
<DebugType>full</DebugType>
@@ -44,7 +44,7 @@
4444
<DocumentationFile>bin\Release\Rubberduck.XML</DocumentationFile>
4545
<DebugSymbols>true</DebugSymbols>
4646
<NoWarn>1591</NoWarn>
47-
<LangVersion>7.1</LangVersion>
47+
<LangVersion>7.2</LangVersion>
4848
</PropertyGroup>
4949
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugAccess|AnyCPU'">
5050
<DebugSymbols>true</DebugSymbols>
@@ -58,7 +58,7 @@
5858
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
5959
<WarningLevel>4</WarningLevel>
6060
<Optimize>false</Optimize>
61-
<LangVersion>7.1</LangVersion>
61+
<LangVersion>7.2</LangVersion>
6262
</PropertyGroup>
6363
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
6464
<DebugSymbols>true</DebugSymbols>
@@ -156,7 +156,7 @@
156156
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
157157
<WarningLevel>4</WarningLevel>
158158
<Optimize>false</Optimize>
159-
<LangVersion>7.1</LangVersion>
159+
<LangVersion>7.2</LangVersion>
160160
</PropertyGroup>
161161
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|x64'">
162162
<DebugSymbols>true</DebugSymbols>
@@ -197,7 +197,7 @@
197197
<ErrorReport>prompt</ErrorReport>
198198
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
199199
<WarningLevel>4</WarningLevel>
200-
<LangVersion>7.1</LangVersion>
200+
<LangVersion>7.2</LangVersion>
201201
</PropertyGroup>
202202
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release64|x64'">
203203
<DebugSymbols>true</DebugSymbols>
@@ -372,6 +372,7 @@
372372
<Compile Include="RubberduckGuid.cs" />
373373
<Compile Include="RubberduckProgId.cs" />
374374
<Compile Include="Settings\CodeInspectionConfigProvider.cs" />
375+
<Compile Include="Settings\ExperimentalFeatures.cs" />
375376
<Compile Include="Settings\DefaultHotkeySettings.cs" />
376377
<Compile Include="Settings\GeneralConfigProvider.cs" />
377378
<Compile Include="Settings\HotkeySettings.cs" />
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Xml.Serialization;
2+
using Rubberduck.UI;
3+
4+
namespace Rubberduck.Settings
5+
{
6+
public class ExperimentalFeatures : ViewModelBase
7+
{
8+
private bool _isEnabled;
9+
public bool IsEnabled
10+
{
11+
get { return _isEnabled; }
12+
set
13+
{
14+
_isEnabled = value;
15+
OnPropertyChanged();
16+
}
17+
}
18+
19+
private string _key;
20+
public string Key
21+
{
22+
get { return _key; }
23+
set
24+
{
25+
_key = value;
26+
OnPropertyChanged();
27+
OnPropertyChanged(nameof(DisplayValue));
28+
}
29+
}
30+
31+
[XmlIgnore]
32+
public string DisplayValue => Key == null ? string.Empty : RubberduckUI.ResourceManager.GetString(Key);
33+
34+
public override string ToString()
35+
{
36+
return Key;
37+
}
38+
39+
public override bool Equals(object obj)
40+
{
41+
return obj is ExperimentalFeatures value &&
42+
value.IsEnabled == IsEnabled &&
43+
value.Key == Key;
44+
}
45+
46+
public override int GetHashCode()
47+
{
48+
unchecked
49+
{
50+
return (IsEnabled.GetHashCode() * 397) ^ (Key != null ? Key.GetHashCode() : 0);
51+
}
52+
}
53+
}
54+
}

RetailCoder.VBE/Settings/GeneralSettings.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
24
using NLog;
35
using System.Xml.Serialization;
46
using Rubberduck.Common;
@@ -14,7 +16,7 @@ public interface IGeneralSettings
1416
bool IsAutoSaveEnabled { get; set; }
1517
int AutoSavePeriod { get; set; }
1618
int MinimumLogLevel { get; set; }
17-
bool IsSourceControlEnabled { get; set; }
19+
List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
1820
}
1921

2022
[XmlType(AnonymousType = true)]
@@ -48,7 +50,7 @@ public int MinimumLogLevel
4850
}
4951
}
5052

51-
public bool IsSourceControlEnabled { get; set; }
53+
public List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
5254

5355
public GeneralSettings()
5456
{
@@ -59,7 +61,7 @@ public GeneralSettings()
5961
IsAutoSaveEnabled = false;
6062
AutoSavePeriod = 10;
6163
MinimumLogLevel = LogLevel.Off.Ordinal;
62-
IsSourceControlEnabled = false;
64+
EnableExperimentalFeatures = new List<ExperimentalFeatures>();
6365
}
6466

6567
public bool Equals(GeneralSettings other)
@@ -72,7 +74,8 @@ public bool Equals(GeneralSettings other)
7274
IsAutoSaveEnabled == other.IsAutoSaveEnabled &&
7375
AutoSavePeriod == other.AutoSavePeriod &&
7476
MinimumLogLevel == other.MinimumLogLevel &&
75-
IsSourceControlEnabled == other.IsSourceControlEnabled;
77+
EnableExperimentalFeatures.All(a => other.EnableExperimentalFeatures.Contains(a)) &&
78+
EnableExperimentalFeatures.Count == other.EnableExperimentalFeatures.Count;
7679
}
7780
}
7881
}

RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@
271271
</Image>
272272
</MenuItem.Icon>
273273
</MenuItem>
274-
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControlPanel_Caption}" Visibility="{Binding IsSourceControlEnabled, Converter={StaticResource BoolToVisibility}}" >
274+
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControlPanel_Caption}" Visibility="{Binding EnableSourceControl, Converter={StaticResource BoolToVisibility}}" >
275275
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_Commit}"
276276
Command="{Binding CommitCommand}"
277277
CommandParameter="{Binding SelectedItem}" />

RetailCoder.VBE/UI/Command/MenuItems/SourceControlCommandMenuItem.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using Rubberduck.UI.Command.MenuItems.ParentMenus;
1+
using Rubberduck.Parsing.Common;
2+
using Rubberduck.UI.Command.MenuItems.ParentMenus;
23

34
namespace Rubberduck.UI.Command.MenuItems
45
{
6+
[Experimental(nameof(RubberduckUI.GeneralSettings_EnableSourceControl))]
57
public class SourceControlCommandMenuItem : CommandMenuItemBase
68
{
79
public SourceControlCommandMenuItem(CommandBase command)

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

0 commit comments

Comments
 (0)