Skip to content

Commit dede9b2

Browse files
Andrin Meierretailcoder
authored andcommitted
fix #1648 (#1657)
1 parent 88ac6c9 commit dede9b2

21 files changed

+144
-49
lines changed

RetailCoder.VBE/App.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,19 @@
44
using Rubberduck.Common;
55
using Rubberduck.Common.Dispatch;
66
using Rubberduck.Parsing;
7+
using Rubberduck.Parsing.Symbols;
78
using Rubberduck.Parsing.VBA;
89
using Rubberduck.Settings;
910
using Rubberduck.SmartIndenter;
1011
using Rubberduck.UI;
1112
using Rubberduck.UI.Command.MenuItems;
1213
using System;
1314
using System.Collections.Generic;
14-
using System.Diagnostics;
1515
using System.Globalization;
1616
using System.Linq;
1717
using System.Runtime.InteropServices.ComTypes;
1818
using System.Threading.Tasks;
1919
using System.Windows.Forms;
20-
using Rubberduck.Parsing.Symbols;
2120

2221
namespace Rubberduck
2322
{
@@ -65,9 +64,6 @@ public App(VBE vbe, IMessageBox messageBox,
6564
_indenter = indenter;
6665
_hooks = hooks;
6766
_logger = LogManager.GetCurrentClassLogger();
68-
// Anyone else could be starting a parse task before we get to disable logging (if the user has configured it so)
69-
// that is why we are conservative and disable logging by default.
70-
LogManager.DisableLogging();
7167

7268
_hooks.MessageReceived += _hooks_MessageReceived;
7369
_configService.SettingsChanged += _configService_SettingsChanged;
@@ -143,12 +139,7 @@ private void _configService_SettingsChanged(object sender, EventArgs e)
143139

144140
private void UpdateLoggingLevel()
145141
{
146-
var fileRule = LogManager.Configuration.LoggingRules.Where(rule => rule.Targets.Any(t => t.Name == FILE_TARGET_NAME)).FirstOrDefault();
147-
if (fileRule == null)
148-
{
149-
return;
150-
}
151-
LogLevelHelper.SetMinimumLogLevel(fileRule, LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
142+
LogLevelHelper.SetMinimumLogLevel(LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
152143
}
153144

154145
public void Startup()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using System.IO;
3+
4+
namespace Rubberduck.Common
5+
{
6+
public static class ApplicationConstants
7+
{
8+
public static readonly string LOG_FOLDER_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "Logs");
9+
}
10+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Rubberduck.Common
2+
{
3+
public interface IOperatingSystem
4+
{
5+
void ShowFolder(string folderPath);
6+
}
7+
}

RetailCoder.VBE/Common/LogLevelHelper.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
using NLog.Config;
33
using System;
44
using System.Collections.Generic;
5-
using System.Collections.ObjectModel;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
95

106
namespace Rubberduck.Common
117
{
@@ -32,21 +28,28 @@ private static IEnumerable<LogLevel> GetLogLevels()
3228
return logLevels;
3329
}
3430

35-
public static void SetMinimumLogLevel(LoggingRule loggingRule, LogLevel minimumLogLevel)
31+
public static void SetMinimumLogLevel(LogLevel minimumLogLevel)
3632
{
37-
ClearLogLevels(loggingRule);
33+
var loggingRules = LogManager.Configuration.LoggingRules;
34+
foreach (var loggingRule in loggingRules)
35+
{
36+
ClearLogLevels(loggingRule);
37+
}
3838
if (minimumLogLevel == LogLevel.Off)
3939
{
4040
LogManager.DisableLogging();
4141
LogManager.ReconfigExistingLoggers();
4242
return;
4343
}
4444
LogManager.EnableLogging();
45-
foreach (var logLevel in LogLevels)
45+
foreach (var loggingRule in loggingRules)
4646
{
47-
if (logLevel != LogLevel.Off && logLevel >= minimumLogLevel)
47+
foreach (var logLevel in LogLevels)
4848
{
49-
loggingRule.EnableLoggingForLevel(logLevel);
49+
if (logLevel != LogLevel.Off && logLevel >= minimumLogLevel)
50+
{
51+
loggingRule.EnableLoggingForLevel(logLevel);
52+
}
5053
}
5154
}
5255
LogManager.ReconfigExistingLoggers();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Diagnostics;
3+
4+
namespace Rubberduck.Common
5+
{
6+
public sealed class WindowsOperatingSystem : IOperatingSystem
7+
{
8+
public void ShowFolder(string folderPath)
9+
{
10+
Process.Start(folderPath);
11+
}
12+
}
13+
}

RetailCoder.VBE/Root/RubberduckModule.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public override void Load()
7373
_kernel.Bind<NewTestMethodCommand>().ToSelf().InSingletonScope();
7474
_kernel.Bind<RubberduckCommandBar>().ToSelf().InSingletonScope();
7575
_kernel.Bind<TestExplorerModel>().ToSelf().InSingletonScope();
76+
_kernel.Bind<IOperatingSystem>().To<WindowsOperatingSystem>().InSingletonScope();
7677

7778
BindCodeInspectionTypes();
7879

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
<Compile Include="API\ParserState.cs" />
289289
<Compile Include="AppMenu.cs" />
290290
<Compile Include="AutoSave\AutoSave.cs" />
291+
<Compile Include="Common\ApplicationConstants.cs" />
291292
<Compile Include="Common\ExportFormatter.cs" />
292293
<Compile Include="Common\ClipboardWriter.cs" />
293294
<Compile Include="Common\DeclarationExtensions.cs" />
@@ -302,6 +303,7 @@
302303
<Compile Include="Common\Hotkeys\Hotkey.cs" />
303304
<Compile Include="Common\IAttachable.cs" />
304305
<Compile Include="Common\Hotkeys\IHotkey.cs" />
306+
<Compile Include="Common\IOperatingSystem.cs" />
305307
<Compile Include="Common\IRubberduckHooks.cs" />
306308
<Compile Include="Common\LogLevelHelper.cs" />
307309
<Compile Include="Common\ModuleExporter.cs" />
@@ -346,6 +348,7 @@
346348
<Compile Include="Common\WinAPI\User32.cs" />
347349
<Compile Include="Common\WinAPI\WindowLongFlags.cs" />
348350
<Compile Include="Common\WinAPI\WM.cs" />
351+
<Compile Include="Common\WindowsOperatingSystem.cs" />
349352
<Compile Include="Inspections\InspectionsUI.de.Designer.cs">
350353
<DependentUpon>InspectionsUI.de.resx</DependentUpon>
351354
<AutoGen>True</AutoGen>

RetailCoder.VBE/UI/CodeInspections/InspectionResultsViewModel.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,19 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
3030
private readonly VBE _vbe;
3131
private readonly IClipboardWriter _clipboard;
3232
private readonly IGeneralConfigService _configService;
33+
private readonly IOperatingSystem _operatingSystem;
3334
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();
3435

3536
public InspectionResultsViewModel(RubberduckParserState state, IInspector inspector, VBE vbe, INavigateCommand navigateCommand, IClipboardWriter clipboard,
36-
IGeneralConfigService configService)
37+
IGeneralConfigService configService, IOperatingSystem operatingSystem)
3738
{
3839
_state = state;
3940
_inspector = inspector;
4041
_vbe = vbe;
4142
_navigateCommand = navigateCommand;
4243
_clipboard = clipboard;
4344
_configService = configService;
45+
_operatingSystem = operatingSystem;
4446
_refreshCommand = new DelegateCommand(async param => await Task.Run(() => ExecuteRefreshCommandAsync(param)), CanExecuteRefreshCommand);
4547
_disableInspectionCommand = new DelegateCommand(ExecuteDisableInspectionCommand);
4648
_quickFixCommand = new DelegateCommand(ExecuteQuickFixCommand, CanExecuteQuickFixCommand);
@@ -174,7 +176,7 @@ public bool GroupByLocation
174176

175177
private void OpenSettings(object param)
176178
{
177-
using (var window = new SettingsForm(_configService, SettingsViews.InspectionSettings))
179+
using (var window = new SettingsForm(_configService, _operatingSystem, SettingsViews.InspectionSettings))
178180
{
179181
window.ShowDialog();
180182
}

RetailCoder.VBE/UI/Command/SettingsCommand.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Runtime.InteropServices;
22
using Rubberduck.Settings;
33
using Rubberduck.UI.Settings;
4+
using Rubberduck.Common;
45

56
namespace Rubberduck.UI.Command
67
{
@@ -11,14 +12,16 @@ namespace Rubberduck.UI.Command
1112
public class SettingsCommand : CommandBase
1213
{
1314
private readonly IGeneralConfigService _service;
14-
public SettingsCommand(IGeneralConfigService service)
15+
private readonly IOperatingSystem _operatingSystem;
16+
public SettingsCommand(IGeneralConfigService service, IOperatingSystem operatingSystem)
1517
{
1618
_service = service;
19+
_operatingSystem = operatingSystem;
1720
}
1821

1922
public override void Execute(object parameter)
2023
{
21-
using (var window = new SettingsForm(_service))
24+
using (var window = new SettingsForm(_service, _operatingSystem))
2225
{
2326
window.ShowDialog();
2427
}

RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

0 commit comments

Comments
 (0)