Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/next' into rkapka-master
Browse files Browse the repository at this point in the history
# Conflicts:
#	RetailCoder.VBE/Rubberduck.csproj
  • Loading branch information
rkapka committed Jan 12, 2018
2 parents 5eb456b + 4a6db52 commit e6eacab
Show file tree
Hide file tree
Showing 48 changed files with 384 additions and 215 deletions.
Expand Up @@ -558,7 +558,7 @@ private void ExecuteRemoveComand(object param)

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/Properties/Settings.settings
Expand Up @@ -49,7 +49,7 @@
<Setting Name="DefaultHotkey_CodeExplorerCommand" Type="Rubberduck.Settings.HotkeySetting" Scope="Application">
<Value Profile="(Default)">&lt;?xml version="1.0" encoding="utf-16"?&gt;
&lt;HotkeySetting xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
&lt;Key1&gt;C&lt;/Key1&gt;
&lt;Key1&gt;R&lt;/Key1&gt;
&lt;IsEnabled&gt;true&lt;/IsEnabled&gt;
&lt;HasShiftModifier&gt;false&lt;/HasShiftModifier&gt;
&lt;HasAltModifier&gt;false&lt;/HasAltModifier&gt;
Expand Down Expand Up @@ -158,4 +158,4 @@
&lt;ToDoMarker xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Text="BUG" /&gt;</Value>
</Setting>
</Settings>
</SettingsFile>
</SettingsFile>
59 changes: 43 additions & 16 deletions RetailCoder.VBE/Root/RubberduckIoCInstaller.cs
Expand Up @@ -45,7 +45,7 @@
using Rubberduck.VBEditor.SafeComWrappers.Office.Core.Abstract;
using Component = Castle.MicroKernel.Registration.Component;
using Rubberduck.UI.CodeMetrics;
using Rubberduck.Navigation.CodeMetrics;
using Rubberduck.Parsing.Common;

namespace Rubberduck.Root
{
Expand Down Expand Up @@ -158,7 +158,9 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Classes.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

container.Register(Classes.From(assemblyTypes)
.InSameNamespaceAs<Configuration>()
.WithService.AllInterfaces()
.LifestyleSingleton());
Expand All @@ -184,11 +186,15 @@ private void RegisterConfiguration(IWindsorContainer container, Assembly[] assem
.LifestyleTransient());
}

private static void ApplyDefaultInterfaceConvention(IWindsorContainer container, Assembly[] assembliesToRegister)
private void ApplyDefaultInterfaceConvention(IWindsorContainer container, Assembly[] assembliesToRegister)
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Classes.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

assemblyTypes.Any(t => t.Name == nameof(IMessageBox));

container.Register(Classes.From(assemblyTypes)
.Where(type => type.Namespace != null
&& !type.Namespace.StartsWith("Rubberduck.VBEditor.SafeComWrappers")
&& !type.Name.Equals("SelectionChangeService")
Expand All @@ -201,11 +207,13 @@ private static void ApplyDefaultInterfaceConvention(IWindsorContainer container,
}
}

private static void RegisterFactories(IWindsorContainer container, Assembly[] assembliesToRegister)
private void RegisterFactories(IWindsorContainer container, Assembly[] assembliesToRegister)
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Types.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

container.Register(Types.From(assemblyTypes)
.Where(type => type.IsInterface && type.Name.EndsWith("Factory"))
.Configure(c => c.AsFactory())
.LifestyleSingleton());
Expand All @@ -222,34 +230,40 @@ private static void RegisterSpecialFactories(IWindsorContainer container)
.LifestyleSingleton());
}

private static void RegisterQuickFixes(IWindsorContainer container, Assembly[] assembliesToRegister)
private void RegisterQuickFixes(IWindsorContainer container, Assembly[] assembliesToRegister)
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Classes.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

container.Register(Classes.From(assemblyTypes)
.BasedOn<IQuickFix>()
.WithService.Base()
.WithService.Self()
.LifestyleSingleton());
}
}

private static void RegisterInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
private void RegisterInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Classes.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

container.Register(Classes.From(assemblyTypes)
.BasedOn<IInspection>()
.WithService.Base()
.LifestyleTransient());
}
}

private static void RegisterParseTreeInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
private void RegisterParseTreeInspections(IWindsorContainer container, Assembly[] assembliesToRegister)
{
foreach (var assembly in assembliesToRegister)
{
container.Register(Classes.FromAssembly(assembly)
var assemblyTypes = GetIoCRegisteredTypes(assembly);

container.Register(Classes.From(assemblyTypes)
.BasedOn<IParseTreeInspection>()
.WithService.Base()
.WithService.Select(new[]{typeof(IInspection)})
Expand Down Expand Up @@ -497,7 +511,7 @@ private Type[] ToolsMenuItems()
typeof(ExportAllCommandMenuItem)
};

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

private void RegisterCommandsWithPresenters(IWindsorContainer container)
{
if (_initialSettings.IsSourceControlEnabled)
if (_initialSettings.EnableExperimentalFeatures.Any(a => a.Key == nameof(RubberduckUI.GeneralSettings_EnableSourceControl) && a.IsEnabled))
{
container.Register(Component.For<CommandBase>()
.ImplementedBy<SourceControlCommand>()
Expand Down Expand Up @@ -789,7 +803,7 @@ private void RegisterCustomDeclarationLoadersToParser(IWindsorContainer containe
.LifestyleSingleton());
}

private IEnumerable<Assembly> AssembliesToRegister()
public static IEnumerable<Assembly> AssembliesToRegister()
{
var assemblies = new[]
{
Expand All @@ -802,7 +816,7 @@ private IEnumerable<Assembly> AssembliesToRegister()
return assemblies;
}

private IEnumerable<Assembly> FindPlugins()
private static IEnumerable<Assembly> FindPlugins()
{
var assemblies = new List<Assembly>();
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
Expand Down Expand Up @@ -856,5 +870,18 @@ private static void RegisterHotkeyFactory(IWindsorContainer container)
{
container.Register(Component.For<HotkeyFactory>().LifestyleSingleton());
}

private IEnumerable<TypeInfo> GetIoCRegisteredTypes(Assembly assembly)
{
return assembly.DefinedTypes
.Where(w =>
{
var attribute = w.CustomAttributes.FirstOrDefault(f => f.AttributeType == typeof(ExperimentalAttribute));
var ctorArg = attribute?.ConstructorArguments.Any() == true ? (string)attribute.ConstructorArguments.First().Value : string.Empty;
return attribute == null ||
_initialSettings.EnableExperimentalFeatures.Any(a => a.Key == ctorArg && a.IsEnabled);
});
}
}
}
11 changes: 6 additions & 5 deletions RetailCoder.VBE/Rubberduck.csproj
Expand Up @@ -31,7 +31,7 @@
<NoWarn>1591</NoWarn>
<PlatformTarget>AnyCPU</PlatformTarget>
<UseVSHostingProcess>true</UseVSHostingProcess>
<LangVersion>7.1</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -44,7 +44,7 @@
<DocumentationFile>bin\Release\Rubberduck.XML</DocumentationFile>
<DebugSymbols>true</DebugSymbols>
<NoWarn>1591</NoWarn>
<LangVersion>7.1</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugAccess|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -58,7 +58,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
<LangVersion>7.1</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -156,7 +156,7 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<Optimize>false</Optimize>
<LangVersion>7.1</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug64|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -197,7 +197,7 @@
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<WarningLevel>4</WarningLevel>
<LangVersion>7.1</LangVersion>
<LangVersion>7.2</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release64|x64'">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -372,6 +372,7 @@
<Compile Include="RubberduckGuid.cs" />
<Compile Include="RubberduckProgId.cs" />
<Compile Include="Settings\CodeInspectionConfigProvider.cs" />
<Compile Include="Settings\ExperimentalFeatures.cs" />
<Compile Include="Settings\DefaultSettings.cs" />
<Compile Include="Settings\GeneralConfigProvider.cs" />
<Compile Include="Settings\HotkeySettings.cs" />
Expand Down
54 changes: 54 additions & 0 deletions RetailCoder.VBE/Settings/ExperimentalFeatures.cs
@@ -0,0 +1,54 @@
using System.Xml.Serialization;
using Rubberduck.UI;

namespace Rubberduck.Settings
{
public class ExperimentalFeatures : ViewModelBase
{
private bool _isEnabled;
public bool IsEnabled
{
get { return _isEnabled; }
set
{
_isEnabled = value;
OnPropertyChanged();
}
}

private string _key;
public string Key
{
get { return _key; }
set
{
_key = value;
OnPropertyChanged();
OnPropertyChanged(nameof(DisplayValue));
}
}

[XmlIgnore]
public string DisplayValue => Key == null ? string.Empty : RubberduckUI.ResourceManager.GetString(Key);

public override string ToString()
{
return Key;
}

public override bool Equals(object obj)
{
return obj is ExperimentalFeatures value &&
value.IsEnabled == IsEnabled &&
value.Key == Key;
}

public override int GetHashCode()
{
unchecked
{
return (IsEnabled.GetHashCode() * 397) ^ (Key != null ? Key.GetHashCode() : 0);
}
}
}
}
11 changes: 7 additions & 4 deletions RetailCoder.VBE/Settings/GeneralSettings.cs
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using System.Xml.Serialization;
using Rubberduck.Common;
Expand All @@ -14,7 +16,7 @@ public interface IGeneralSettings
bool IsAutoSaveEnabled { get; set; }
int AutoSavePeriod { get; set; }
int MinimumLogLevel { get; set; }
bool IsSourceControlEnabled { get; set; }
List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }
}

[XmlType(AnonymousType = true)]
Expand Down Expand Up @@ -48,7 +50,7 @@ public int MinimumLogLevel
}
}

public bool IsSourceControlEnabled { get; set; }
public List<ExperimentalFeatures> EnableExperimentalFeatures { get; set; }

public GeneralSettings()
{
Expand All @@ -59,7 +61,7 @@ public GeneralSettings()
IsAutoSaveEnabled = false;
AutoSavePeriod = 10;
MinimumLogLevel = LogLevel.Off.Ordinal;
IsSourceControlEnabled = false;
EnableExperimentalFeatures = new List<ExperimentalFeatures>();
}

public bool Equals(GeneralSettings other)
Expand All @@ -72,7 +74,8 @@ public bool Equals(GeneralSettings other)
IsAutoSaveEnabled == other.IsAutoSaveEnabled &&
AutoSavePeriod == other.AutoSavePeriod &&
MinimumLogLevel == other.MinimumLogLevel &&
IsSourceControlEnabled == other.IsSourceControlEnabled;
EnableExperimentalFeatures.All(a => other.EnableExperimentalFeatures.Contains(a)) &&
EnableExperimentalFeatures.Count == other.EnableExperimentalFeatures.Count;
}
}
}
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/CodeExplorer/CodeExplorerControl.xaml
Expand Up @@ -271,7 +271,7 @@
</Image>
</MenuItem.Icon>
</MenuItem>
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControlPanel_Caption}" Visibility="{Binding IsSourceControlEnabled, Converter={StaticResource BoolToVisibility}}" >
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=SourceControlPanel_Caption}" Visibility="{Binding EnableSourceControl, Converter={StaticResource BoolToVisibility}}" >
<MenuItem Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=CodeExplorer_Commit}"
Command="{Binding CommitCommand}"
CommandParameter="{Binding SelectedItem}" />
Expand Down
@@ -1,7 +1,9 @@
using Rubberduck.UI.Command.MenuItems.ParentMenus;
using Rubberduck.Parsing.Common;
using Rubberduck.UI.Command.MenuItems.ParentMenus;

namespace Rubberduck.UI.Command.MenuItems
{
[Experimental(nameof(RubberduckUI.GeneralSettings_EnableSourceControl))]
public class SourceControlCommandMenuItem : CommandMenuItemBase
{
public SourceControlCommandMenuItem(CommandBase command)
Expand Down
4 changes: 2 additions & 2 deletions RetailCoder.VBE/UI/RubberduckUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e6eacab

Please sign in to comment.