Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 144fde6

Browse files
committed
Now creating solution-wide formatting options container correctly. Added "Code Formatting" option tab to project properties view.
1 parent 931dea8 commit 144fde6

4 files changed

Lines changed: 32 additions & 28 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
label = "${res:Dialog.ProjectOptions.Publish}"
120120
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.Publish"/>-->
121121
<Include id = "AllManaged" path="/SharpDevelop/BackendBindings/ProjectOptions/AllManaged"/>
122+
<!-- TODO Localize label! -->
123+
<OptionPanel id = "CSharpProjectFormattingOptions"
124+
label = "Code Formatting"
125+
class = "CSharpBinding.OptionPanels.CSharpProjectFormattingOptionPanel"/>
122126
</Path>
123127

124128
<Path name = "/Workspace/Icons">
@@ -497,4 +501,10 @@
497501
class = "CSharpBinding.FormsDesigner.FormsDesignerSecondaryDisplayBinding"
498502
fileNamePattern = "\.cs$"/>
499503
</Path>
504+
505+
<!-- Autostart command for initialization -->
506+
<Path name = "/SharpDevelop/Autostart">
507+
<Class id = "CSharpFormattingOptionsPersistenceInitCommand"
508+
class = "CSharpBinding.FormattingStrategy.CSharpFormattingOptionsPersistenceInitCommand"/>
509+
</Path>
500510
</AddIn>

src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,23 @@
2525

2626
namespace CSharpBinding.FormattingStrategy
2727
{
28+
public class CSharpFormattingOptionsPersistenceInitCommand : SimpleCommand
29+
{
30+
public override void Execute(object parameter)
31+
{
32+
// Initialize CSharpFormattingOptionsPersistence as early as possible (before solution is opened)
33+
CSharpFormattingOptionsPersistence.Initialize();
34+
}
35+
}
36+
2837
/// <summary>
2938
/// Persistence helper for C# formatting options.
3039
/// </summary>
3140
internal class CSharpFormattingOptionsPersistence
3241
{
3342
static Dictionary<string, CSharpFormattingOptionsPersistence> projectOptions;
3443

35-
static CSharpFormattingOptionsPersistence()
44+
public static void Initialize()
3645
{
3746
projectOptions = new Dictionary<string, CSharpFormattingOptionsPersistence>();
3847

@@ -64,10 +73,10 @@ public static CSharpFormattingOptionsPersistence GetProjectOptions(IProject proj
6473
if (csproject != null) {
6574
string key = project.FileName;
6675
if (!projectOptions.ContainsKey(key)) {
67-
// Lazily create options container
76+
// Lazily create options container for project
6877
projectOptions[key] = new CSharpFormattingOptionsPersistence(
6978
csproject.ExtensionProperties,
70-
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)); // HACK!
79+
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer));
7180
}
7281

7382
return projectOptions[key];

src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpProjectFormattingOptions.xaml.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,26 @@ public CSharpProjectFormattingOptionPanel()
4545
protected override void Load(ICSharpCode.SharpDevelop.Project.MSBuildBasedProject project, string configuration, string platform)
4646
{
4747
base.Load(project, configuration, platform);
48+
if (persistenceHelper != null) {
49+
persistenceHelper.OptionsContainer.PropertyChanged -= ContainerPropertyChanged;
50+
}
4851
persistenceHelper = CSharpFormattingOptionsPersistence.GetProjectOptions(project);
4952
formattingEditor.OptionsContainer = persistenceHelper.OptionsContainer;
5053
formattingEditor.AllowPresets = true;
5154
persistenceHelper.Load();
55+
persistenceHelper.OptionsContainer.PropertyChanged += ContainerPropertyChanged;
5256
}
5357

5458
protected override bool Save(ICSharpCode.SharpDevelop.Project.MSBuildBasedProject project, string configuration, string platform)
5559
{
5660
bool success = (persistenceHelper != null) && persistenceHelper.Save();
5761
return base.Save(project, configuration, platform) && success;
5862
}
63+
64+
void ContainerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
65+
{
66+
// A formatting option has been changed, mark project settings as dirty
67+
this.IsDirty = true;
68+
}
5969
}
6070
}

src/Main/Base/Project/Src/Project/AbstractProject.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ protected AbstractProject(ProjectInformation information)
5959
this.configurationMapping = information.ConfigurationMapping ?? new ConfigurationMapping();
6060
this.Name = information.ProjectName;
6161
this.FileName = information.FileName;
62-
this.globalPreferencesFileName = new FileName(fileName + ".sdsettings");
6362
this.idGuid = (information.IdGuid != Guid.Empty ? information.IdGuid : Guid.NewGuid());
6463
this.TypeGuid = information.TypeGuid;
6564
if (information.ProjectSections != null)
@@ -115,28 +114,6 @@ public Properties Preferences {
115114
}
116115
}
117116

118-
Properties globalPreferences = new Properties();
119-
120-
public Properties GlobalPreferences {
121-
get {
122-
lock (syncRoot) {
123-
if (globalPreferences == null) {
124-
globalPreferences = new Properties(); // in case of errors, use empty properties container
125-
if (FileUtility.IsValidPath(globalPreferencesFileName) && File.Exists(globalPreferencesFileName)) {
126-
try {
127-
globalPreferences = Properties.Load(globalPreferencesFileName);
128-
} catch (IOException) {
129-
} catch (UnauthorizedAccessException) {
130-
} catch (XmlException) {
131-
// ignore errors about inaccessible or malformed files
132-
}
133-
}
134-
}
135-
return globalPreferences;
136-
}
137-
}
138-
}
139-
140117
static FileName GetPreferenceFileName(string projectFileName)
141118
{
142119
string directory = Path.Combine(PropertyService.ConfigDirectory, "preferences");
@@ -154,7 +131,6 @@ public void SavePreferences()
154131
FileName preferencesFile = GetPreferenceFileName(fileName);
155132
System.IO.Directory.CreateDirectory(preferencesFile.GetParentDirectory());
156133
p.Save(preferencesFile);
157-
this.GlobalPreferences.Save(globalPreferencesFileName);
158134
} catch (IOException) {
159135
} catch (UnauthorizedAccessException) {
160136
}
@@ -163,7 +139,6 @@ public void SavePreferences()
163139

164140
#region Filename / Directory
165141
volatile FileName fileName;
166-
volatile FileName globalPreferencesFileName;
167142
volatile DirectoryName directoryName;
168143
protected IProjectChangeWatcher watcher;
169144

0 commit comments

Comments
 (0)