|
|
@ -18,6 +18,7 @@ |
|
|
|
|
|
|
|
|
|
|
|
using System; |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Generic; |
|
|
|
|
|
|
|
using System.ComponentModel; |
|
|
|
using ICSharpCode.Core; |
|
|
|
using ICSharpCode.Core; |
|
|
|
using ICSharpCode.NRefactory.CSharp; |
|
|
|
using ICSharpCode.NRefactory.CSharp; |
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
|
using ICSharpCode.SharpDevelop; |
|
|
@ -25,42 +26,41 @@ using ICSharpCode.SharpDevelop.Project; |
|
|
|
|
|
|
|
|
|
|
|
namespace CSharpBinding.FormattingStrategy |
|
|
|
namespace CSharpBinding.FormattingStrategy |
|
|
|
{ |
|
|
|
{ |
|
|
|
public class CSharpFormattingOptionsPersistenceInitCommand : SimpleCommand |
|
|
|
public class CSharpFormattingOptionsPoliciesInitCommand : SimpleCommand |
|
|
|
{ |
|
|
|
{ |
|
|
|
public override void Execute(object parameter) |
|
|
|
public override void Execute(object parameter) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Initialize CSharpFormattingOptionsPersistence as early as possible (before solution is opened)
|
|
|
|
// Initialize CSharpFormattingOptionsPersistence as early as possible (before solution is opened)
|
|
|
|
CSharpFormattingOptionsPersistence.Initialize(); |
|
|
|
CSharpFormattingPolicies.Instance.Initialize(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Persistence helper for C# formatting options.
|
|
|
|
/// Management class for formatting policies.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
internal class CSharpFormattingOptionsPersistence |
|
|
|
internal class CSharpFormattingPolicies |
|
|
|
{ |
|
|
|
{ |
|
|
|
static bool initialized; |
|
|
|
public static readonly CSharpFormattingPolicies Instance = new CSharpFormattingPolicies(); |
|
|
|
static Dictionary<string, CSharpFormattingOptionsPersistence> projectOptions; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static CSharpFormattingOptionsPersistence() |
|
|
|
public event EventHandler<CSharpFormattingPolicyUpdateEventArgs> FormattingPolicyUpdated; |
|
|
|
{ |
|
|
|
|
|
|
|
Initialize(); |
|
|
|
static bool initialized; |
|
|
|
} |
|
|
|
static Dictionary<string, CSharpFormattingPolicy> projectOptions; |
|
|
|
|
|
|
|
|
|
|
|
public static void Initialize() |
|
|
|
public void Initialize() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (initialized) |
|
|
|
if (initialized) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
initialized = true; |
|
|
|
initialized = true; |
|
|
|
projectOptions = new Dictionary<string, CSharpFormattingOptionsPersistence>(); |
|
|
|
projectOptions = new Dictionary<string, CSharpFormattingPolicy>(); |
|
|
|
|
|
|
|
|
|
|
|
// Load global settings
|
|
|
|
// Load global settings
|
|
|
|
GlobalOptions = new CSharpFormattingOptionsPersistence( |
|
|
|
GlobalOptions = new CSharpFormattingPolicy( |
|
|
|
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer() |
|
|
|
SD.PropertyService.MainPropertiesContainer, new CSharpFormattingOptionsContainer() { |
|
|
|
{ |
|
|
|
|
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.GlobalOptionReference}") |
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.GlobalOptionReference}") |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
GlobalOptions.FormattingPolicyUpdated += OnFormattingPolicyUpdated; |
|
|
|
GlobalOptions.Load(); |
|
|
|
GlobalOptions.Load(); |
|
|
|
|
|
|
|
|
|
|
|
// Handlers for solution loading/unloading
|
|
|
|
// Handlers for solution loading/unloading
|
|
|
@ -71,8 +71,7 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool AutoFormatting |
|
|
|
public static bool AutoFormatting { |
|
|
|
{ |
|
|
|
|
|
|
|
get { |
|
|
|
get { |
|
|
|
return SD.PropertyService.Get("CSharpBinding.Formatting.AutoFormatting", false); |
|
|
|
return SD.PropertyService.Get("CSharpBinding.Formatting.AutoFormatting", false); |
|
|
|
} |
|
|
|
} |
|
|
@ -81,31 +80,32 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static CSharpFormattingOptionsPersistence GlobalOptions |
|
|
|
public CSharpFormattingPolicy GlobalOptions { |
|
|
|
{ |
|
|
|
|
|
|
|
get; |
|
|
|
get; |
|
|
|
private set; |
|
|
|
private set; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static CSharpFormattingOptionsPersistence SolutionOptions |
|
|
|
public CSharpFormattingPolicy SolutionOptions { |
|
|
|
{ |
|
|
|
|
|
|
|
get; |
|
|
|
get; |
|
|
|
private set; |
|
|
|
private set; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static CSharpFormattingOptionsPersistence GetProjectOptions(IProject project) |
|
|
|
public CSharpFormattingPolicy GetProjectOptions(IProject project) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
if (projectOptions == null) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
|
|
var csproject = project as CSharpProject; |
|
|
|
var csproject = project as CSharpProject; |
|
|
|
if (csproject != null) { |
|
|
|
if (csproject != null) { |
|
|
|
string key = project.FileName; |
|
|
|
string key = project.FileName; |
|
|
|
if (!projectOptions.ContainsKey(key)) { |
|
|
|
if (!projectOptions.ContainsKey(key)) { |
|
|
|
// Lazily create options container for project
|
|
|
|
// Lazily create options container for project
|
|
|
|
var projectFormattingPersistence = new CSharpFormattingOptionsPersistence( |
|
|
|
var projectFormattingPersistence = new CSharpFormattingPolicy( |
|
|
|
csproject.GlobalPreferences, |
|
|
|
csproject.GlobalPreferences, |
|
|
|
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer) |
|
|
|
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer) { |
|
|
|
{ |
|
|
|
|
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.ProjectOptionReference}") |
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.ProjectOptionReference}") |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
projectFormattingPersistence.FormattingPolicyUpdated += OnFormattingPolicyUpdated; |
|
|
|
projectFormattingPersistence.Load(); |
|
|
|
projectFormattingPersistence.Load(); |
|
|
|
projectOptions[key] = projectFormattingPersistence; |
|
|
|
projectOptions[key] = projectFormattingPersistence; |
|
|
|
} |
|
|
|
} |
|
|
@ -116,34 +116,70 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
return SolutionOptions ?? GlobalOptions; |
|
|
|
return SolutionOptions ?? GlobalOptions; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void SolutionOpened(object sender, SolutionEventArgs e) |
|
|
|
void SolutionOpened(object sender, SolutionEventArgs e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// Load solution settings
|
|
|
|
// Load solution settings
|
|
|
|
SolutionOptions = new CSharpFormattingOptionsPersistence( |
|
|
|
SolutionOptions = new CSharpFormattingPolicy( |
|
|
|
e.Solution.SDSettings, |
|
|
|
e.Solution.SDSettings, |
|
|
|
new CSharpFormattingOptionsContainer(GlobalOptions.OptionsContainer) |
|
|
|
new CSharpFormattingOptionsContainer(GlobalOptions.OptionsContainer) { |
|
|
|
{ |
|
|
|
|
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.SolutionOptionReference}") |
|
|
|
DefaultText = StringParser.Parse("${res:CSharpBinding.Formatting.SolutionOptionReference}") |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
SolutionOptions.FormattingPolicyUpdated += OnFormattingPolicyUpdated; |
|
|
|
SolutionOptions.Load(); |
|
|
|
SolutionOptions.Load(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void SolutionClosed(object sender, SolutionEventArgs e) |
|
|
|
void SolutionClosed(object sender, SolutionEventArgs e) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
SolutionOptions.FormattingPolicyUpdated -= OnFormattingPolicyUpdated; |
|
|
|
SolutionOptions = null; |
|
|
|
SolutionOptions = null; |
|
|
|
projectOptions.Clear(); |
|
|
|
projectOptions.Clear(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnFormattingPolicyUpdated(object sender, CSharpFormattingPolicyUpdateEventArgs e) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (FormattingPolicyUpdated != null) { |
|
|
|
|
|
|
|
FormattingPolicyUpdated(sender, e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Contains event data for formatting policy update events.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
internal class CSharpFormattingPolicyUpdateEventArgs : EventArgs |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public CSharpFormattingPolicyUpdateEventArgs(CSharpFormattingOptionsContainer container) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
OptionsContainer = container; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Returns updated options container.
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public CSharpFormattingOptionsContainer OptionsContainer |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
get; |
|
|
|
|
|
|
|
private set; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// Persistence helper for C# formatting options of a certain policy (e.g. global, solution, project).
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
internal class CSharpFormattingPolicy |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
public event EventHandler<CSharpFormattingPolicyUpdateEventArgs> FormattingPolicyUpdated; |
|
|
|
|
|
|
|
|
|
|
|
readonly Properties propertiesContainer; |
|
|
|
readonly Properties propertiesContainer; |
|
|
|
CSharpFormattingOptionsContainer optionsContainer; |
|
|
|
readonly CSharpFormattingOptionsContainer optionsContainer; |
|
|
|
CSharpFormattingOptionsContainer optionsContainerWorkingCopy; |
|
|
|
CSharpFormattingOptionsContainer optionsContainerWorkingCopy; |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Creates a new instance of formatting options persistence helper, using given options to predefine the options container.
|
|
|
|
/// Creates a new instance of formatting options policy, using given options to predefine the options container.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="propertiesContainer">Properties container to load from and save to.</param>
|
|
|
|
/// <param name="propertiesContainer">Properties container to load from and save to.</param>
|
|
|
|
/// <param name="initialContainer">Initial (empty) instance of formatting options container.</param>
|
|
|
|
/// <param name="initialContainer">Initial (empty) instance of formatting options container.</param>
|
|
|
|
public CSharpFormattingOptionsPersistence(Properties propertiesContainer, CSharpFormattingOptionsContainer initialContainer) |
|
|
|
public CSharpFormattingPolicy(Properties propertiesContainer, CSharpFormattingOptionsContainer initialContainer) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (initialContainer == null) |
|
|
|
if (initialContainer == null) |
|
|
|
throw new ArgumentNullException("initialContainer"); |
|
|
|
throw new ArgumentNullException("initialContainer"); |
|
|
@ -153,7 +189,7 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// Returns the option container managed by this helper.
|
|
|
|
/// Returns the option container for this policy.
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public CSharpFormattingOptionsContainer OptionsContainer |
|
|
|
public CSharpFormattingOptionsContainer OptionsContainer |
|
|
|
{ |
|
|
|
{ |
|
|
@ -196,7 +232,15 @@ namespace CSharpBinding.FormattingStrategy |
|
|
|
|
|
|
|
|
|
|
|
// Convert to SD properties
|
|
|
|
// Convert to SD properties
|
|
|
|
optionsContainer.Save(propertiesContainer); |
|
|
|
optionsContainer.Save(propertiesContainer); |
|
|
|
|
|
|
|
OnFormattingPolicyUpdated(this, optionsContainer); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void OnFormattingPolicyUpdated(object sender, CSharpFormattingOptionsContainer container) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (FormattingPolicyUpdated != null) { |
|
|
|
|
|
|
|
FormattingPolicyUpdated(sender, new CSharpFormattingPolicyUpdateEventArgs(container)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|