Browse Source

Now creating solution-wide formatting options container correctly. Added "Code Formatting" option tab to project properties view.

pull/403/head
Andreas Weizel 12 years ago
parent
commit
144fde6b36
  1. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  2. 15
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/FormattingStrategy/CSharpFormattingOptionsPersistence.cs
  3. 10
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/OptionPanels/CSharpProjectFormattingOptions.xaml.cs
  4. 25
      src/Main/Base/Project/Src/Project/AbstractProject.cs

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

@ -119,6 +119,10 @@ @@ -119,6 +119,10 @@
label = "${res:Dialog.ProjectOptions.Publish}"
class = "ICSharpCode.SharpDevelop.Gui.OptionPanels.Publish"/>-->
<Include id = "AllManaged" path="/SharpDevelop/BackendBindings/ProjectOptions/AllManaged"/>
<!-- TODO Localize label! -->
<OptionPanel id = "CSharpProjectFormattingOptions"
label = "Code Formatting"
class = "CSharpBinding.OptionPanels.CSharpProjectFormattingOptionPanel"/>
</Path>
<Path name = "/Workspace/Icons">
@ -497,4 +501,10 @@ @@ -497,4 +501,10 @@
class = "CSharpBinding.FormsDesigner.FormsDesignerSecondaryDisplayBinding"
fileNamePattern = "\.cs$"/>
</Path>
<!-- Autostart command for initialization -->
<Path name = "/SharpDevelop/Autostart">
<Class id = "CSharpFormattingOptionsPersistenceInitCommand"
class = "CSharpBinding.FormattingStrategy.CSharpFormattingOptionsPersistenceInitCommand"/>
</Path>
</AddIn>

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

@ -25,6 +25,15 @@ using ICSharpCode.SharpDevelop.Project; @@ -25,6 +25,15 @@ using ICSharpCode.SharpDevelop.Project;
namespace CSharpBinding.FormattingStrategy
{
public class CSharpFormattingOptionsPersistenceInitCommand : SimpleCommand
{
public override void Execute(object parameter)
{
// Initialize CSharpFormattingOptionsPersistence as early as possible (before solution is opened)
CSharpFormattingOptionsPersistence.Initialize();
}
}
/// <summary>
/// Persistence helper for C# formatting options.
/// </summary>
@ -32,7 +41,7 @@ namespace CSharpBinding.FormattingStrategy @@ -32,7 +41,7 @@ namespace CSharpBinding.FormattingStrategy
{
static Dictionary<string, CSharpFormattingOptionsPersistence> projectOptions;
static CSharpFormattingOptionsPersistence()
public static void Initialize()
{
projectOptions = new Dictionary<string, CSharpFormattingOptionsPersistence>();
@ -64,10 +73,10 @@ namespace CSharpBinding.FormattingStrategy @@ -64,10 +73,10 @@ namespace CSharpBinding.FormattingStrategy
if (csproject != null) {
string key = project.FileName;
if (!projectOptions.ContainsKey(key)) {
// Lazily create options container
// Lazily create options container for project
projectOptions[key] = new CSharpFormattingOptionsPersistence(
csproject.ExtensionProperties,
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer)); // HACK!
new CSharpFormattingOptionsContainer((SolutionOptions ?? GlobalOptions).OptionsContainer));
}
return projectOptions[key];

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

@ -45,10 +45,14 @@ namespace CSharpBinding.OptionPanels @@ -45,10 +45,14 @@ namespace CSharpBinding.OptionPanels
protected override void Load(ICSharpCode.SharpDevelop.Project.MSBuildBasedProject project, string configuration, string platform)
{
base.Load(project, configuration, platform);
if (persistenceHelper != null) {
persistenceHelper.OptionsContainer.PropertyChanged -= ContainerPropertyChanged;
}
persistenceHelper = CSharpFormattingOptionsPersistence.GetProjectOptions(project);
formattingEditor.OptionsContainer = persistenceHelper.OptionsContainer;
formattingEditor.AllowPresets = true;
persistenceHelper.Load();
persistenceHelper.OptionsContainer.PropertyChanged += ContainerPropertyChanged;
}
protected override bool Save(ICSharpCode.SharpDevelop.Project.MSBuildBasedProject project, string configuration, string platform)
@ -56,5 +60,11 @@ namespace CSharpBinding.OptionPanels @@ -56,5 +60,11 @@ namespace CSharpBinding.OptionPanels
bool success = (persistenceHelper != null) && persistenceHelper.Save();
return base.Save(project, configuration, platform) && success;
}
void ContainerPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
// A formatting option has been changed, mark project settings as dirty
this.IsDirty = true;
}
}
}

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

@ -59,7 +59,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -59,7 +59,6 @@ namespace ICSharpCode.SharpDevelop.Project
this.configurationMapping = information.ConfigurationMapping ?? new ConfigurationMapping();
this.Name = information.ProjectName;
this.FileName = information.FileName;
this.globalPreferencesFileName = new FileName(fileName + ".sdsettings");
this.idGuid = (information.IdGuid != Guid.Empty ? information.IdGuid : Guid.NewGuid());
this.TypeGuid = information.TypeGuid;
if (information.ProjectSections != null)
@ -115,28 +114,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -115,28 +114,6 @@ namespace ICSharpCode.SharpDevelop.Project
}
}
Properties globalPreferences = new Properties();
public Properties GlobalPreferences {
get {
lock (syncRoot) {
if (globalPreferences == null) {
globalPreferences = new Properties(); // in case of errors, use empty properties container
if (FileUtility.IsValidPath(globalPreferencesFileName) && File.Exists(globalPreferencesFileName)) {
try {
globalPreferences = Properties.Load(globalPreferencesFileName);
} catch (IOException) {
} catch (UnauthorizedAccessException) {
} catch (XmlException) {
// ignore errors about inaccessible or malformed files
}
}
}
return globalPreferences;
}
}
}
static FileName GetPreferenceFileName(string projectFileName)
{
string directory = Path.Combine(PropertyService.ConfigDirectory, "preferences");
@ -154,7 +131,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -154,7 +131,6 @@ namespace ICSharpCode.SharpDevelop.Project
FileName preferencesFile = GetPreferenceFileName(fileName);
System.IO.Directory.CreateDirectory(preferencesFile.GetParentDirectory());
p.Save(preferencesFile);
this.GlobalPreferences.Save(globalPreferencesFileName);
} catch (IOException) {
} catch (UnauthorizedAccessException) {
}
@ -163,7 +139,6 @@ namespace ICSharpCode.SharpDevelop.Project @@ -163,7 +139,6 @@ namespace ICSharpCode.SharpDevelop.Project
#region Filename / Directory
volatile FileName fileName;
volatile FileName globalPreferencesFileName;
volatile DirectoryName directoryName;
protected IProjectChangeWatcher watcher;

Loading…
Cancel
Save