Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions RetailCoder.VBE/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
using Rubberduck.Common;
using Rubberduck.Common.Dispatch;
using Rubberduck.Parsing;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.Settings;
using Rubberduck.SmartIndenter;
using Rubberduck.UI;
using Rubberduck.UI.Command.MenuItems;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using System.Windows.Forms;
using Rubberduck.Parsing.Symbols;

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

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

private void UpdateLoggingLevel()
{
var fileRule = LogManager.Configuration.LoggingRules.Where(rule => rule.Targets.Any(t => t.Name == FILE_TARGET_NAME)).FirstOrDefault();
if (fileRule == null)
{
return;
}
LogLevelHelper.SetMinimumLogLevel(fileRule, LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
LogLevelHelper.SetMinimumLogLevel(LogLevel.FromOrdinal(_config.UserSettings.GeneralSettings.MinimumLogLevel));
}

public void Startup()
Expand Down
10 changes: 10 additions & 0 deletions RetailCoder.VBE/Common/ApplicationConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
using System.IO;

namespace Rubberduck.Common
{
public static class ApplicationConstants
{
public static readonly string LOG_FOLDER_PATH = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Rubberduck", "Logs");
}
}
7 changes: 7 additions & 0 deletions RetailCoder.VBE/Common/IOperatingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Rubberduck.Common
{
public interface IOperatingSystem
{
void ShowFolder(string folderPath);
}
}
21 changes: 12 additions & 9 deletions RetailCoder.VBE/Common/LogLevelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
using NLog.Config;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Rubberduck.Common
{
Expand All @@ -32,21 +28,28 @@ private static IEnumerable<LogLevel> GetLogLevels()
return logLevels;
}

public static void SetMinimumLogLevel(LoggingRule loggingRule, LogLevel minimumLogLevel)
public static void SetMinimumLogLevel(LogLevel minimumLogLevel)
{
ClearLogLevels(loggingRule);
var loggingRules = LogManager.Configuration.LoggingRules;
foreach (var loggingRule in loggingRules)
{
ClearLogLevels(loggingRule);
}
if (minimumLogLevel == LogLevel.Off)
{
LogManager.DisableLogging();
LogManager.ReconfigExistingLoggers();
return;
}
LogManager.EnableLogging();
foreach (var logLevel in LogLevels)
foreach (var loggingRule in loggingRules)
{
if (logLevel != LogLevel.Off && logLevel >= minimumLogLevel)
foreach (var logLevel in LogLevels)
{
loggingRule.EnableLoggingForLevel(logLevel);
if (logLevel != LogLevel.Off && logLevel >= minimumLogLevel)
{
loggingRule.EnableLoggingForLevel(logLevel);
}
}
}
LogManager.ReconfigExistingLoggers();
Expand Down
13 changes: 13 additions & 0 deletions RetailCoder.VBE/Common/WindowsOperatingSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;
using System.Diagnostics;

namespace Rubberduck.Common
{
public sealed class WindowsOperatingSystem : IOperatingSystem
{
public void ShowFolder(string folderPath)
{
Process.Start(folderPath);
}
}
}
1 change: 1 addition & 0 deletions RetailCoder.VBE/Root/RubberduckModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public override void Load()
_kernel.Bind<NewTestMethodCommand>().ToSelf().InSingletonScope();
_kernel.Bind<RubberduckCommandBar>().ToSelf().InSingletonScope();
_kernel.Bind<TestExplorerModel>().ToSelf().InSingletonScope();
_kernel.Bind<IOperatingSystem>().To<WindowsOperatingSystem>().InSingletonScope();

BindCodeInspectionTypes();

Expand Down
3 changes: 3 additions & 0 deletions RetailCoder.VBE/Rubberduck.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@
<Compile Include="API\ParserState.cs" />
<Compile Include="AppMenu.cs" />
<Compile Include="AutoSave\AutoSave.cs" />
<Compile Include="Common\ApplicationConstants.cs" />
<Compile Include="Common\ExportFormatter.cs" />
<Compile Include="Common\ClipboardWriter.cs" />
<Compile Include="Common\DeclarationExtensions.cs" />
Expand All @@ -302,6 +303,7 @@
<Compile Include="Common\Hotkeys\Hotkey.cs" />
<Compile Include="Common\IAttachable.cs" />
<Compile Include="Common\Hotkeys\IHotkey.cs" />
<Compile Include="Common\IOperatingSystem.cs" />
<Compile Include="Common\IRubberduckHooks.cs" />
<Compile Include="Common\LogLevelHelper.cs" />
<Compile Include="Common\ModuleExporter.cs" />
Expand Down Expand Up @@ -346,6 +348,7 @@
<Compile Include="Common\WinAPI\User32.cs" />
<Compile Include="Common\WinAPI\WindowLongFlags.cs" />
<Compile Include="Common\WinAPI\WM.cs" />
<Compile Include="Common\WindowsOperatingSystem.cs" />
<Compile Include="Inspections\InspectionsUI.de.Designer.cs">
<DependentUpon>InspectionsUI.de.resx</DependentUpon>
<AutoGen>True</AutoGen>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,19 @@ public sealed class InspectionResultsViewModel : ViewModelBase, INavigateSelecti
private readonly VBE _vbe;
private readonly IClipboardWriter _clipboard;
private readonly IGeneralConfigService _configService;
private readonly IOperatingSystem _operatingSystem;
private static readonly Logger _logger = LogManager.GetCurrentClassLogger();

public InspectionResultsViewModel(RubberduckParserState state, IInspector inspector, VBE vbe, INavigateCommand navigateCommand, IClipboardWriter clipboard,
IGeneralConfigService configService)
IGeneralConfigService configService, IOperatingSystem operatingSystem)
{
_state = state;
_inspector = inspector;
_vbe = vbe;
_navigateCommand = navigateCommand;
_clipboard = clipboard;
_configService = configService;
_operatingSystem = operatingSystem;
_refreshCommand = new DelegateCommand(async param => await Task.Run(() => ExecuteRefreshCommandAsync(param)), CanExecuteRefreshCommand);
_disableInspectionCommand = new DelegateCommand(ExecuteDisableInspectionCommand);
_quickFixCommand = new DelegateCommand(ExecuteQuickFixCommand, CanExecuteQuickFixCommand);
Expand Down Expand Up @@ -174,7 +176,7 @@ public bool GroupByLocation

private void OpenSettings(object param)
{
using (var window = new SettingsForm(_configService, SettingsViews.InspectionSettings))
using (var window = new SettingsForm(_configService, _operatingSystem, SettingsViews.InspectionSettings))
{
window.ShowDialog();
}
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/Command/MenuItems/UiDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class UiDispatcher
// thanks to Pellared on http://stackoverflow.com/a/12909070/1188513

private static SynchronizationContext UiContext { get; set; }

public static void Initialize()
{
if (UiContext == null)
Expand Down
7 changes: 5 additions & 2 deletions RetailCoder.VBE/UI/Command/SettingsCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Runtime.InteropServices;
using Rubberduck.Settings;
using Rubberduck.UI.Settings;
using Rubberduck.Common;

namespace Rubberduck.UI.Command
{
Expand All @@ -11,14 +12,16 @@ namespace Rubberduck.UI.Command
public class SettingsCommand : CommandBase
{
private readonly IGeneralConfigService _service;
public SettingsCommand(IGeneralConfigService service)
private readonly IOperatingSystem _operatingSystem;
public SettingsCommand(IGeneralConfigService service, IOperatingSystem operatingSystem)
{
_service = service;
_operatingSystem = operatingSystem;
}

public override void Execute(object parameter)
{
using (var window = new SettingsForm(_service))
using (var window = new SettingsForm(_service, _operatingSystem))
{
window.ShowDialog();
}
Expand Down
9 changes: 9 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.Designer.cs

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

3 changes: 3 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.de.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1591,4 +1591,7 @@ Allen Sternguckern, Likern &amp; Followern, für das warme Kribbeln
<data name="GeneralSettings_WarnLogLevel" xml:space="preserve">
<value>Warnung</value>
</data>
<data name="GeneralSettings_ShowLogFolder" xml:space="preserve">
<value>Logging-Ordner anzeigen</value>
</data>
</root>
3 changes: 3 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.ja.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1508,4 +1508,7 @@
<data name="GeneralSettings_SlashDelimiter" xml:space="preserve">
<value>スラッシュ「 / 」</value>
</data>
<data name="GeneralSettings_ShowLogFolder" xml:space="preserve">
<value>ロギングフォルダを開く</value>
</data>
</root>
3 changes: 3 additions & 0 deletions RetailCoder.VBE/UI/RubberduckUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1617,4 +1617,7 @@ All our stargazers, likers &amp; followers, for the warm fuzzies
<data name="GeneralSettings_WarnLogLevel" xml:space="preserve">
<value>Warn</value>
</data>
<data name="GeneralSettings_ShowLogFolder" xml:space="preserve">
<value>Show Log Folder</value>
</data>
</root>
10 changes: 8 additions & 2 deletions RetailCoder.VBE/UI/Settings/GeneralSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,20 @@

<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_MinimumLogLevelLabel}"
FontWeight="SemiBold" />
<ComboBox Width="210"
<StackPanel Orientation="Horizontal">
<ComboBox Width="210"
HorizontalAlignment="Left"
Margin="5"
SelectedItem="{Binding SelectedLogLevel, Mode=TwoWay}"
ItemsSource="{Binding LogLevels, UpdateSourceTrigger=PropertyChanged}"
DisplayMemberPath="Name"/>
<Button
Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_ShowLogFolder}"
Padding="5"
Command="{Binding ShowLogFolderCommand}"/>
</StackPanel>

<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_HotkeysLabel}" FontWeight="SemiBold" />
<Label Content="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=GeneralSettings_HotkeysLabel}" FontWeight="SemiBold" />

<DataGrid ItemsSource="{Binding Hotkeys}"
HorizontalAlignment="Stretch"
Expand Down
20 changes: 19 additions & 1 deletion RetailCoder.VBE/UI/Settings/GeneralSettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Rubberduck.Settings;
using NLog;
using Rubberduck.Common;
using System.Windows.Input;
using Rubberduck.UI.Command;

namespace Rubberduck.UI.Settings
{
Expand All @@ -14,8 +16,11 @@ public enum DelimiterOptions

public class GeneralSettingsViewModel : ViewModelBase, ISettingsViewModel
{
public GeneralSettingsViewModel(Configuration config)
private readonly IOperatingSystem _operatingSystem;

public GeneralSettingsViewModel(Configuration config, IOperatingSystem operatingSystem)
{
_operatingSystem = operatingSystem;
Languages = new ObservableCollection<DisplayLanguageSetting>(
new[]
{
Expand All @@ -33,6 +38,8 @@ public GeneralSettingsViewModel(Configuration config)
Delimiter = (DelimiterOptions)config.UserSettings.GeneralSettings.Delimiter;
LogLevels = new ObservableCollection<MinimumLogLevel>(LogLevelHelper.LogLevels.Select(l => new MinimumLogLevel(l.Ordinal, l.Name)));
SelectedLogLevel = LogLevels.First(l => l.Ordinal == config.UserSettings.GeneralSettings.MinimumLogLevel);

_showLogFolderCommand = new DelegateCommand(_ => ShowLogFolder());
}

public ObservableCollection<DisplayLanguageSetting> Languages { get; set; }
Expand Down Expand Up @@ -122,6 +129,17 @@ public MinimumLogLevel SelectedLogLevel
}
}

private readonly ICommand _showLogFolderCommand;
public ICommand ShowLogFolderCommand
{
get { return _showLogFolderCommand; }
}

private void ShowLogFolder()
{
_operatingSystem.ShowFolder(ApplicationConstants.LOG_FOLDER_PATH);
}

public void UpdateConfig(Configuration config)
{
config.UserSettings.GeneralSettings.Language = SelectedLanguage;
Expand Down
3 changes: 2 additions & 1 deletion RetailCoder.VBE/UI/Settings/InspectionSettings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
HeadersVisibility="None"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ColumnHeaderHeight="22"
BorderThickness="0">
BorderThickness="0"
CellEditEnding="GroupingGrid_CellEditEnding">
<controls:GroupingGrid.Columns>
<DataGridTemplateColumn Header="{Resx ResxName=Rubberduck.UI.RubberduckUI, Key=NameLabelText}"
Width="2.75*"
Expand Down
11 changes: 10 additions & 1 deletion RetailCoder.VBE/UI/Settings/InspectionSettings.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace Rubberduck.UI.Settings
using System.Windows.Controls;

namespace Rubberduck.UI.Settings
{
/// <summary>
/// Interaction logic for InspectionSettings.xaml
Expand All @@ -16,5 +18,12 @@ public InspectionSettings(ISettingsViewModel vm) : this()
}

public ISettingsViewModel ViewModel { get { return DataContext as ISettingsViewModel; } }

private void GroupingGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
{
if (e.Cancel || e.EditAction == DataGridEditAction.Cancel) { return; }

((InspectionSettingsViewModel) ViewModel).UpdateCollection();
}
}
}
6 changes: 5 additions & 1 deletion RetailCoder.VBE/UI/Settings/InspectionSettingsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Data;
using Rubberduck.Inspections;
using Rubberduck.Settings;

namespace Rubberduck.UI.Settings
Expand All @@ -19,6 +18,11 @@ public InspectionSettingsViewModel(Configuration config)
}
}

public void UpdateCollection()
{
InspectionSettings.CommitEdit();
}

private ListCollectionView _inspectionSettings;
public ListCollectionView InspectionSettings
{
Expand Down
2 changes: 1 addition & 1 deletion RetailCoder.VBE/UI/Settings/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
d:DesignHeight="300" d:DesignWidth="600"
d:DataContext="{d:DesignInstance {x:Type settings:SettingsControlViewModel}, IsDesignTimeCreatable=False}">
<UserControl.InputBindings>
<KeyBinding Key="Esc"
<KeyBinding Key="Escape"
Command="{Binding CancelButtonCommand}" />
</UserControl.InputBindings>
<UserControl.Resources>
Expand Down
Loading