Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix saving naming styles options page #34212

Merged
merged 3 commits into from
Mar 19, 2019
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
3 changes: 0 additions & 3 deletions src/Tools/ILAsm/IlAsmDeploy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
<TargetLatestRuntimePatch>false</TargetLatestRuntimePatch>
<SelfContained>true</SelfContained>

<!-- Do not build again when publishing -->
<NoBuild>true</NoBuild>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is unrelated to the fix, but allows for builds in VS to not fail. This same change is already in the master branch.


<PublishDir>$(ArtifactsDir)tools\ILAsm\$(Configuration)\</PublishDir>
</PropertyGroup>

Expand Down
39 changes: 32 additions & 7 deletions src/VisualStudio/Core/Impl/Options/AbstractOptionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ internal abstract class AbstractOptionPage : UIElementDialogPage
{
private static IOptionService s_optionService;
private static OptionStore s_optionStore;
private static bool s_needsLoadOnNextActivate = true;
private static bool s_needsToUpdateOptionStore = true;

private bool _needsLoadOnNextActivate = true;

protected abstract AbstractOptionPageControl CreateOptionPage(IServiceProvider serviceProvider, OptionStore optionStore);

Expand Down Expand Up @@ -50,16 +52,22 @@ protected override void OnActivate(System.ComponentModel.CancelEventArgs e)
{
EnsureOptionPageCreated();

if (s_needsLoadOnNextActivate)
if (s_needsToUpdateOptionStore)
{
// Reset the option store to the current state of the options.
s_optionStore.SetOptions(s_optionService.GetOptions());
s_optionStore.SetRegisteredOptions(s_optionService.GetRegisteredOptions());

s_needsLoadOnNextActivate = false;
s_needsToUpdateOptionStore = false;
}

pageControl.LoadSettings();
if (_needsLoadOnNextActivate)
{
// For pages that don't use option bindings we need to load setting changes.
pageControl.OnLoad();

_needsLoadOnNextActivate = false;
}
}

public override void LoadSettingsFromStorage()
Expand All @@ -81,19 +89,36 @@ public override void LoadSettingsFromStorage()
// they may have been changed programmatically. Therefore, we'll set a flag so we load
// next time

s_needsLoadOnNextActivate = pageControl != null;
// When pageControl is null we know that Activation has not happened for this page.
// We only need to update the OptionStore after a cancel or close click (2).
s_needsToUpdateOptionStore = pageControl != null;

// For pages that don't use option bindings we need to load settings when it is
// activated next.
_needsLoadOnNextActivate = true;
}

public override void SaveSettingsToStorage()
{
EnsureOptionPageCreated();

// Allow page controls to perist their settings to the option store before updating the
// option service.
pageControl.OnSave();

// Save the changes that were accumulated in the option store.
s_optionService.SetOptions(s_optionStore.GetOptions());
var oldOptions = s_optionService.GetOptions();
var newOptions = s_optionStore.GetOptions();
s_optionService.SetOptions(newOptions);
OptionLogger.Log(oldOptions, newOptions);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As pointed out by David offline, we had been logging option changes on SaveSettings before the earlier PR moved logging into the OptionStore. This reverts the behavior back.


// Make sure we load the next time a page is activated, in case that options changed
// programmatically between now and the next time the page is activated
s_needsLoadOnNextActivate = true;
s_needsToUpdateOptionStore = true;

// For pages that don't use option bindings we need to load settings when it is
// activated next.
_needsLoadOnNextActivate = true;
}

protected override void OnClosed(EventArgs e)
Expand Down
13 changes: 2 additions & 11 deletions src/VisualStudio/Core/Impl/Options/AbstractOptionPageControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,25 +148,16 @@ protected void BindToFullSolutionAnalysisOption(CheckBox checkbox, string langua
_bindingExpressions.Add(bindingExpression);
}

internal virtual void LoadSettings()
internal virtual void OnLoad()
{
foreach (var bindingExpression in _bindingExpressions)
{
bindingExpression.UpdateTarget();
}
}

internal virtual void SaveSettings()
internal virtual void OnSave()
{
foreach (var bindingExpression in _bindingExpressions)
{
if (!bindingExpression.IsDirty)
{
continue;
}

bindingExpression.UpdateSource();
}
}

internal virtual void Close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void Options_PreviewKeyDown(object sender, KeyEventArgs e)
}
}

internal override void LoadSettings()
internal override void OnLoad()
{
this.ViewModel = _createViewModel(OptionStore, _serviceProvider);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void Options_PreviewKeyDown(object sender, KeyEventArgs e)
}
}

internal override void LoadSettings()
internal override void OnLoad()
{
this.ViewModel = _createViewModel(this.OptionStore, _serviceProvider);

Expand Down
10 changes: 3 additions & 7 deletions src/VisualStudio/Core/Impl/Options/OptionStore.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis.Options;

Expand Down Expand Up @@ -28,27 +30,21 @@ public OptionStore(OptionSet optionSet, IEnumerable<IOption> registeredOptions)

public void SetOption(OptionKey optionKey, object value)
{
var oldOptions = _optionSet;
_optionSet = _optionSet.WithChangedOption(optionKey, value);
OptionLogger.Log(oldOptions, _optionSet);

OnOptionChanged(optionKey);
}

public void SetOption<T>(Option<T> option, T value)
{
var oldOptions = _optionSet;
_optionSet = _optionSet.WithChangedOption(option, value);
OptionLogger.Log(oldOptions, _optionSet);

OnOptionChanged(new OptionKey(option));
}

public void SetOption<T>(PerLanguageOption<T> option, string language, T value)
{
var oldOptionSet = _optionSet;
_optionSet = _optionSet.WithChangedOption(option, language, value);
OptionLogger.Log(oldOptionSet, _optionSet);

OnOptionChanged(new OptionKey(option, language));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal NamingStyleOptionPageControl(OptionStore optionStore, INotificationServ
_notificationService = notificationService;

InitializeComponent();
LoadSettings();
OnLoad();
}

private NamingStyleOptionPageViewModel.NamingRuleViewModel CreateItemWithNoSelections()
Expand Down Expand Up @@ -139,7 +139,7 @@ private void SetFocusToSelectedRow()
}
}

internal override void SaveSettings()
internal override void OnSave()
{
var symbolSpecifications = ArrayBuilder<SymbolSpecification>.GetInstance();
var namingRules = ArrayBuilder<SerializableNamingRule>.GetInstance();
Expand Down Expand Up @@ -177,15 +177,12 @@ internal override void SaveSettings()
namingStyles.ToImmutableAndFree(),
namingRules.ToImmutableAndFree());

var oldOptions = OptionStore.GetOptions();
var newOptions = oldOptions.WithChangedOption(SimplificationOptions.NamingPreferences, _languageName, info);
OptionStore.SetOptions(newOptions);
OptionLogger.Log(oldOptions, newOptions);
OptionStore.SetOption(SimplificationOptions.NamingPreferences, _languageName, info);
}

internal override void LoadSettings()
internal override void OnLoad()
{
base.LoadSettings();
base.OnLoad();

var preferences = OptionStore.GetOption(SimplificationOptions.NamingPreferences, _languageName);
if (preferences == null)
Expand Down