Skip to content

Commit

Permalink
Simplified presets.
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgeAlexandria committed Oct 25, 2018
1 parent 2e37af5 commit b451911
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 66 deletions.
39 changes: 11 additions & 28 deletions src/vs14/CoCo_vs14/Services/PresetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace CoCo.Services
{
public static class PresetService
{
private static Dictionary<string, List<PresetSettings>> _defaultPresets;
private static Dictionary<string, IReadOnlyDictionary<string, PresetSettings>> _defaultPresets;

/// <summary>
/// Returns the default CoCo settings that are grouped by languages
/// </summary>
public static IReadOnlyDictionary<string, List<PresetSettings>> GetDefaultPresets()
public static IReadOnlyDictionary<string, IReadOnlyDictionary<string, PresetSettings>> GetDefaultPresets()
{
if (!(_defaultPresets is null)) return _defaultPresets;

_defaultPresets = new Dictionary<string, List<PresetSettings>>();
_defaultPresets = new Dictionary<string, IReadOnlyDictionary<string, PresetSettings>>();

var defaulltIdentifierFormatting = FormattingService.GetDefaultIdentifierFormatting();

Expand All @@ -35,32 +35,28 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
return classification;
}

var presets = new List<PresetSettings>
var presets = new Dictionary<string, PresetSettings>
{
new PresetSettings
["CoCo light|blue theme"] = new PresetSettings
{
Name = "CoCo light|blue theme",
Classifications = new List<ClassificationSettings>
{
CreateClassification(CSharpNames.AliasNamespaceName, 220, 220, 220),
CreateClassification(CSharpNames.ConstantFieldName, 255, 157, 255),
CreateClassification(CSharpNames.ConstructorName, 220, 220, 220),
CreateClassification(CSharpNames.DestructorName, 220, 220, 220),
CreateClassification(CSharpNames.EnumFieldName, 0, 193, 193),
CreateClassification(CSharpNames.EventName, 220, 220, 220),
CreateClassification(CSharpNames.ExtensionMethodName, 233, 122, 0),
CreateClassification(CSharpNames.FieldName, 255, 157, 255),
CreateClassification(CSharpNames.LabelName, 120, 20, 0),
CreateClassification(CSharpNames.LocalVariableName, 128, 128, 0),
CreateClassification(CSharpNames.MethodName, 187, 54, 4),
CreateClassification(CSharpNames.NamespaceName, 220, 220, 220),
CreateClassification(CSharpNames.ParameterName, 128, 128, 128),
CreateClassification(CSharpNames.PropertyName, 255, 0, 255),
CreateClassification(CSharpNames.RangeVariableName, 128, 128, 0),
CreateClassification(CSharpNames.StaticMethodName, 154, 82, 0)
}
},
new PresetSettings

["CoCo dark theme"] = new PresetSettings
{
Name = "CoCo dark theme",
Classifications = new List<ClassificationSettings>
Expand All @@ -86,23 +82,20 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
};
_defaultPresets[Languages.CSharp] = presets;

presets = new List<PresetSettings>
presets = new Dictionary<string, PresetSettings>
{
new PresetSettings
["CoCo light|blue theme"] = new PresetSettings
{
Name = "CoCo light|blue theme",
Classifications = new List<ClassificationSettings>
{
CreateClassification(VisualBasicNames.AliasNamespaceName, 220, 220, 220),
CreateClassification(VisualBasicNames.ConstantFieldName, 255, 157, 255),
CreateClassification(VisualBasicNames.EnumFieldName, 0, 193, 193),
CreateClassification(VisualBasicNames.EventName, 220, 220, 220),
CreateClassification(VisualBasicNames.ExtensionMethodName, 233, 122, 0),
CreateClassification(VisualBasicNames.FieldName, 255, 157, 255),
CreateClassification(VisualBasicNames.FunctionName, 187, 54, 4),
CreateClassification(VisualBasicNames.FunctionVariableName, 128, 64, 0),
CreateClassification(VisualBasicNames.LocalVariableName, 128, 128, 0),
CreateClassification(VisualBasicNames.NamespaceName, 220, 220, 220),
CreateClassification(VisualBasicNames.ParameterName, 128, 128, 128),
CreateClassification(VisualBasicNames.PropertyName, 255, 0, 255),
CreateClassification(VisualBasicNames.RangeVariableName, 128, 128, 0),
Expand All @@ -112,7 +105,8 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
CreateClassification(VisualBasicNames.WithEventsPropertyName, 255, 0, 128)
}
},
new PresetSettings

["CoCo dark theme"] = new PresetSettings
{
Name = "CoCo dark theme",
Classifications = new List<ClassificationSettings>
Expand Down Expand Up @@ -141,16 +135,5 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)

return _defaultPresets;
}

public static IReadOnlyDictionary<string, ISet<string>> GetDefaultPresetsNames()
{
var presets = new HashSet<string> { "CoCo light|blue theme", "CoCo dark theme" };

return new Dictionary<string, ISet<string>>
{
[Languages.CSharp] = presets,
[Languages.VisualBasic] = presets,
};
}
}
}
17 changes: 7 additions & 10 deletions src/vs15/CoCo/Services/OptionService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using CoCo.Analyser;
using CoCo.Settings;
Expand Down Expand Up @@ -32,15 +31,15 @@ List<ClassificationSettings> ToSettings(ICollection<Classification> classificati
{
var classificationsSettings = ToSettings(language.Classifications);

if (!PresetService.GetDefaultPresetsNames().TryGetValue(language.Name, out var defaultPresets))
if (!PresetService.GetDefaultPresets().TryGetValue(language.Name, out var defaultPresets))
{
defaultPresets = new HashSet<string>();
defaultPresets = null;
}

var presetsSettings = new List<PresetSettings>(language.Presets.Count);
foreach (var preset in language.Presets)
{
if (defaultPresets.Contains(preset.Name)) continue;
if (!(defaultPresets is null) && defaultPresets.ContainsKey(preset.Name)) continue;

presetsSettings.Add(new PresetSettings
{
Expand All @@ -64,11 +63,10 @@ List<ClassificationSettings> ToSettings(ICollection<Classification> classificati
/// </summary>
public static Option ToOption(Settings.Settings settings)
{
var classificationTypes = ClassificationManager.GetClassifications();
var defaultPresets = PresetService.GetDefaultPresets();

var option = new Option();
foreach (var (languageName, classifications) in classificationTypes)
foreach (var (languageName, classifications) in ClassificationManager.GetClassifications())
{
var language = new Language(languageName);
var languageClassifications = new List<(string, string)>(17);
Expand All @@ -79,9 +77,8 @@ public static Option ToOption(Settings.Settings settings)

if (!defaultPresets.TryGetValue(language.Name, out var defaultLanguagePresets))
{
defaultLanguagePresets = new List<PresetSettings>();
defaultLanguagePresets = null;
}
var presetNames = defaultLanguagePresets.ToHashSet(x => x.Name);

var isLanguageExists = false;
foreach (var languageSettings in settings.Languages)
Expand All @@ -95,7 +92,7 @@ public static Option ToOption(Settings.Settings settings)
foreach (var presetSettings in languageSettings.Presets)
{
// NOTE: skip CoCo default presets, they will be added below
if (presetNames.Contains(presetSettings.Name)) continue;
if (!(defaultLanguagePresets is null) && defaultLanguagePresets.ContainsKey(presetSettings.Name)) continue;

var preset = new Preset(presetSettings.Name);
FillClassifications(languageClassifications, presetSettings.Classifications, preset.Classifications);
Expand All @@ -106,7 +103,7 @@ public static Option ToOption(Settings.Settings settings)
}

// NOTE: add CoCo default presets
foreach (var defaultPreset in defaultLanguagePresets)
foreach (var defaultPreset in defaultLanguagePresets.Values)
{
var preset = new Preset(defaultPreset.Name);
FillClassifications(languageClassifications, defaultPreset.Classifications, preset.Classifications);
Expand Down
39 changes: 11 additions & 28 deletions src/vs15/CoCo/Services/PresetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ namespace CoCo.Services
{
public static class PresetService
{
private static Dictionary<string, List<PresetSettings>> _defaultPresets;
private static Dictionary<string, IReadOnlyDictionary<string, PresetSettings>> _defaultPresets;

/// <summary>
/// Returns the default CoCo settings that are grouped by languages
/// </summary>
public static IReadOnlyDictionary<string, List<PresetSettings>> GetDefaultPresets()
public static IReadOnlyDictionary<string, IReadOnlyDictionary<string, PresetSettings>> GetDefaultPresets()
{
if (!(_defaultPresets is null)) return _defaultPresets;

_defaultPresets = new Dictionary<string, List<PresetSettings>>();
_defaultPresets = new Dictionary<string, IReadOnlyDictionary<string, PresetSettings>>();

var defaulltIdentifierFormatting = FormattingService.GetDefaultIdentifierFormatting();

Expand All @@ -35,33 +35,29 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
return classification;
}

var presets = new List<PresetSettings>
var presets = new Dictionary<string, PresetSettings>
{
new PresetSettings
["CoCo light|blue theme"] = new PresetSettings
{
Name = "CoCo light|blue theme",
Classifications = new List<ClassificationSettings>
{
CreateClassification(CSharpNames.AliasNamespaceName, 220, 220, 220),
CreateClassification(CSharpNames.ConstantFieldName, 255, 157, 255),
CreateClassification(CSharpNames.ConstructorName, 220, 220, 220),
CreateClassification(CSharpNames.DestructorName, 220, 220, 220),
CreateClassification(CSharpNames.EnumFieldName, 0, 193, 193),
CreateClassification(CSharpNames.EventName, 220, 220, 220),
CreateClassification(CSharpNames.ExtensionMethodName, 233, 122, 0),
CreateClassification(CSharpNames.FieldName, 255, 157, 255),
CreateClassification(CSharpNames.LabelName, 120, 20, 0),
CreateClassification(CSharpNames.LocalMethodName, 187, 20, 0),
CreateClassification(CSharpNames.LocalVariableName, 128, 128, 0),
CreateClassification(CSharpNames.MethodName, 187, 54, 4),
CreateClassification(CSharpNames.NamespaceName, 220, 220, 220),
CreateClassification(CSharpNames.ParameterName, 128, 128, 128),
CreateClassification(CSharpNames.PropertyName, 255, 0, 255),
CreateClassification(CSharpNames.RangeVariableName, 128, 128, 0),
CreateClassification(CSharpNames.StaticMethodName, 154, 82, 0)
}
},
new PresetSettings

["CoCo dark theme"] = new PresetSettings
{
Name = "CoCo dark theme",
Classifications = new List<ClassificationSettings>
Expand All @@ -88,23 +84,20 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
};
_defaultPresets[Languages.CSharp] = presets;

presets = new List<PresetSettings>
presets = new Dictionary<string, PresetSettings>
{
new PresetSettings
["CoCo light|blue theme"] = new PresetSettings
{
Name = "CoCo light|blue theme",
Classifications = new List<ClassificationSettings>
{
CreateClassification(VisualBasicNames.AliasNamespaceName, 220, 220, 220),
CreateClassification(VisualBasicNames.ConstantFieldName, 255, 157, 255),
CreateClassification(VisualBasicNames.EnumFieldName, 0, 193, 193),
CreateClassification(VisualBasicNames.EventName, 220, 220, 220),
CreateClassification(VisualBasicNames.ExtensionMethodName, 233, 122, 0),
CreateClassification(VisualBasicNames.FieldName, 255, 157, 255),
CreateClassification(VisualBasicNames.FunctionName, 187, 54, 4),
CreateClassification(VisualBasicNames.FunctionVariableName, 128, 64, 0),
CreateClassification(VisualBasicNames.LocalVariableName, 128, 128, 0),
CreateClassification(VisualBasicNames.NamespaceName, 220, 220, 220),
CreateClassification(VisualBasicNames.ParameterName, 128, 128, 128),
CreateClassification(VisualBasicNames.PropertyName, 255, 0, 255),
CreateClassification(VisualBasicNames.RangeVariableName, 128, 128, 0),
Expand All @@ -114,7 +107,8 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)
CreateClassification(VisualBasicNames.WithEventsPropertyName, 255, 0, 128)
}
},
new PresetSettings

["CoCo dark theme"] = new PresetSettings
{
Name = "CoCo dark theme",
Classifications = new List<ClassificationSettings>
Expand Down Expand Up @@ -143,16 +137,5 @@ ClassificationSettings CreateClassification(string name, byte r, byte g, byte b)

return _defaultPresets;
}

public static IReadOnlyDictionary<string, ISet<string>> GetDefaultPresetsNames()
{
var presets = new HashSet<string> { "CoCo light|blue theme", "CoCo dark theme" };

return new Dictionary<string, ISet<string>>
{
[Languages.CSharp] = presets,
[Languages.VisualBasic] = presets,
};
}
}
}

0 comments on commit b451911

Please sign in to comment.