Skip to content

Commit

Permalink
v3.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasr committed Aug 7, 2017
2 parents b0ef8cc + 46a2a03 commit d54435c
Show file tree
Hide file tree
Showing 89 changed files with 2,010 additions and 677 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Windows.Media;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Winterdom.Viasfora.Classifications {

internal static class CodeClassificationDefinitions {
[Export, Name(Constants.KEYWORD_CLASSIF_NAME)]
public static class CodeClassificationDefinitions {
[Export, Name(Constants.FLOW_CONTROL_CLASSIF_NAME)]
internal static ClassificationTypeDefinition FlowControlClassificationType = null;

[Export, Name(Constants.LINQ_CLASSIF_NAME)]
Expand All @@ -25,6 +21,9 @@ internal static class CodeClassificationDefinitions {
[Export, Name(Constants.VISIBILITY_CLASSIF_NAME)]
internal static ClassificationTypeDefinition VisibilityKeywordClassificationType = null;

[Export, Name(Constants.LINE_HIGHLIGHT)]
internal static ClassificationTypeDefinition CurrentLineClassificationType = null;

[Export, Name(Constants.COLUMN_HIGHLIGHT)]
internal static ClassificationTypeDefinition CurrentColumnClassificationType = null;

Expand Down
16 changes: 8 additions & 8 deletions src/Viasfora.Core/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

namespace Winterdom.Viasfora {
public static class Constants {
public const String KEYWORD_CLASSIF_NAME = "Viasfora Flow Control Keyword";
public const String LINQ_CLASSIF_NAME = "Viasfora Query Operator";
public const String VISIBILITY_CLASSIF_NAME = "Viasfora Visibility Keyword";
public const String STRING_ESCAPE_CLASSIF_NAME = "Viasfora String Escape Sequence";
public const String FORMAT_SPECIFIER_NAME = "viasfora.format.specifier";
public const String LINE_HIGHLIGHT = "Viasfora Current Line";
public const String COLUMN_HIGHLIGHT = "Viasfora Current Column";
public const String FLOW_CONTROL_CLASSIF_NAME = "viasfora.keyword.flowcontrol";
public const String LINQ_CLASSIF_NAME = "viasfora.keyword.linq";
public const String VISIBILITY_CLASSIF_NAME = "viasfora.keyword.visibility";
public const String STRING_ESCAPE_CLASSIF_NAME = "viasfora.string.escape_sequence";
public const String FORMAT_SPECIFIER_NAME = "viasfora.string.format.specifier";
public const String LINE_HIGHLIGHT = "viasfora.line.current";
public const String COLUMN_HIGHLIGHT = "viasfora.column.current";
public const String DEV_MARGIN = "viasfora.dev.margin";

public const String OBFUSCATED_TEXT = "viasfora.text.obfuscated";
Expand All @@ -19,7 +19,7 @@ public static class Constants {
// Languages
public const String Cpp = "Cpp";
public const String CSharp = "CSharp";
public const String XLang = "XLANG/s";
public const String XLang = "XLANGs";
public const String Css = "CSS";
public const String FSharp = "FSharp";
public const String JS = "JScript";
Expand Down
13 changes: 3 additions & 10 deletions src/Viasfora.Core/Contracts/ILanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@

namespace Winterdom.Viasfora.Contracts {
public interface ILanguage {
String[] ControlFlow { get; set; }
String[] Linq { get; set; }
String[] Visibility { get; set; }
String KeyName { get; }
bool Enabled { get; set; }

ILanguageSettings Settings { get; }
T GetService<T>();
IStringScanner NewStringScanner(String text);
bool IsControlFlowKeyword(String text);
bool IsVisibilityKeyword(String text);
bool IsLinqKeyword(String text);
IStringScanner NewStringScanner(String classificationName, String text);
bool MatchesContentType(IContentType contentType);
bool IsKeywordClassification(IClassificationType classificationType);
Func<String, String> NormalizationFunction { get; }
}
}
2 changes: 2 additions & 0 deletions src/Viasfora.Core/Contracts/ILanguageFactory.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using System;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Utilities;
using System.Collections.Generic;

namespace Winterdom.Viasfora.Contracts {
public interface ILanguageFactory {
IEnumerable<ILanguage> GetAllLanguages();
ILanguage TryCreateLanguage(IContentType contentType);
ILanguage TryCreateLanguage(ITextBuffer textBuffer);
ILanguage TryCreateLanguage(ITextSnapshot snapshot);
Expand Down
13 changes: 13 additions & 0 deletions src/Viasfora.Core/Contracts/ILanguageSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Winterdom.Viasfora.Contracts {
public interface ILanguageSettings {
String KeyName { get; }
String[] ControlFlow { get; set; }
String[] Linq { get; set; }
String[] Visibility { get; set; }
bool Enabled { get; set; }
void Load();
void Save();
}
}
1 change: 1 addition & 0 deletions src/Viasfora.Core/EditorFormats/CurrentColumnFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Winterdom.Viasfora.EditorFormats {
[Order(Before = Priority.Default)]
sealed class CurrentColumnFormat : ClassificationFormatDefinition {
public CurrentColumnFormat() {
this.DisplayName = "Viasfora Current Column";
this.ForegroundColor = Colors.LightGray;
this.ForegroundOpacity = 0.3;
this.BackgroundOpacity = 0.3;
Expand Down
20 changes: 20 additions & 0 deletions src/Viasfora.Core/EditorFormats/CurrentLineFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.ComponentModel.Composition;
using System.Windows.Media;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Utilities;

namespace Winterdom.Viasfora.EditorFormats {
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = Constants.LINE_HIGHLIGHT)]
[Name(Constants.LINE_HIGHLIGHT)]
[UserVisible(true)]
[Order(Before = Priority.Default)]
sealed class CurrentLineFormat : ClassificationFormatDefinition {
public CurrentLineFormat() {
this.ForegroundColor = Colors.LightGray;
this.ForegroundOpacity = 0.3;
this.BackgroundOpacity = 0.3;
}
}
}
6 changes: 3 additions & 3 deletions src/Viasfora.Core/EditorFormats/FlowControlFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

namespace Winterdom.Viasfora.EditorFormats {
[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = Constants.KEYWORD_CLASSIF_NAME)]
[Name(Constants.KEYWORD_CLASSIF_NAME)]
[ClassificationType(ClassificationTypeNames = Constants.FLOW_CONTROL_CLASSIF_NAME)]
[Name(Constants.FLOW_CONTROL_CLASSIF_NAME)]
[UserVisible(true)]
[Order(After = Priority.High)]
public sealed class FlowControlFormat : ClassificationFormatDefinition {
public FlowControlFormat() {
this.DisplayName = Constants.KEYWORD_CLASSIF_NAME;
this.DisplayName = "Viasfora Flow Control Keyword";
this.ForegroundColor = Colors.OrangeRed;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Viasfora.Core/EditorFormats/LinqKeywordFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Winterdom.Viasfora.EditorFormats {
[Order(After = Priority.High)]
public sealed class LinqKeywordFormat : ClassificationFormatDefinition {
public LinqKeywordFormat() {
this.DisplayName = Constants.LINQ_CLASSIF_NAME;
this.DisplayName = "Viasfora Query Operator";
this.ForegroundColor = Colors.MediumSeaGreen;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Winterdom.Viasfora.EditorFormats {
[Order(After = Priority.High)]
public sealed class StringEscapeSequenceFormat : ClassificationFormatDefinition {
public StringEscapeSequenceFormat() {
this.DisplayName = Constants.STRING_ESCAPE_CLASSIF_NAME;
this.DisplayName = "Viasfora String Escape Sequence";
this.ForegroundColor = Colors.Magenta;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Viasfora.Core/EditorFormats/VisibilityKeywordFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Winterdom.Viasfora.EditorFormats {
[Order(After = Priority.High)]
public sealed class VisibilityKeywordFormat : ClassificationFormatDefinition {
public VisibilityKeywordFormat() {
this.DisplayName = Constants.VISIBILITY_CLASSIF_NAME;
this.DisplayName = "Viasfora Visibility Keyword";
this.ForegroundColor = Colors.DimGray;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Viasfora.Core/Guids.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace Winterdom.Viasfora {
public static class Guids {
public const String VSPackage = "3338742c-7926-4949-9e57-3fcbb8d0a976";
public const String GeneralOptions = "5da0604d-ba54-43dc-b874-526f43144ee2";
public const String MainOptions = "773f9f3b-1205-4606-9dbc-b7173519e4ff";
public const String RainbowOptions = "89406e01-38f0-4db2-9f73-70da7c5a6f72";
public const String PresentationModeOptions = "e23141d9-f9fa-4780-9f07-d7cb5b6ebb17";
public const String AllLanguagesOptions = "af004378-3762-4f4c-9619-1fbcfbc77078";
Expand Down
8 changes: 1 addition & 7 deletions src/Viasfora.Core/IVsfSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface IVsfSettings : IUpdatableSettings {
bool FlowControlUseItalics { get; set; }
bool EscapeSequencesEnabled { get; set; }

bool CurrentLineHighlightEnabled { get; set; }
bool CurrentColumnHighlightEnabled { get; set; }
ColumnStyle CurrentColumnHighlightStyle { get; set; }
double HighlightLineWidth { get; set; }
Expand All @@ -25,13 +26,6 @@ public interface IVsfSettings : IUpdatableSettings {
String TextObfuscationRegexes { get; set; }
bool TelemetryEnabled { get; set; }

String GetValue(String name, String defaultValue);
bool GetBoolean(String name, bool defval);
int GetInt32(String name, int defval);
long GetInt64(String name, long defval);
double GetDouble(String name, double defval);
T GetEnum<T>(String name, T defval) where T : struct;
void SetValue(String name, object value);
void Load();
void Save();
}
Expand Down
19 changes: 19 additions & 0 deletions src/Viasfora.Core/LanguageExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using System.Linq;
using Winterdom.Viasfora.Contracts;

namespace Winterdom.Viasfora {
public static class LanguageExtensions {
private static StringComparer comparer = StringComparer.CurrentCultureIgnoreCase;

public static bool IsControlFlowKeyword(this ILanguage lang, String text) {
return lang.Settings.ControlFlow.Contains(lang.NormalizationFunction(text), comparer);
}
public static bool IsVisibilityKeyword(this ILanguage lang, String text) {
return lang.Settings.Visibility.Contains(lang.NormalizationFunction(text), comparer);
}
public static bool IsLinqKeyword(this ILanguage lang, String text) {
return lang.Settings.Linq.Contains(lang.NormalizationFunction(text), comparer);
}
}
}
1 change: 1 addition & 0 deletions src/Viasfora.Core/Settings/GlobalXmlSettingsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Xml.Linq;

namespace Winterdom.Viasfora.Settings {
[PartCreationPolicy(CreationPolicy.Shared)]
[Export(typeof(ISettingsStore))]
public class GlobalXmlSettingsStore : ISettingsStore {
const String FILE_NAME = "viasfora.xml";
Expand Down
8 changes: 8 additions & 0 deletions src/Viasfora.Core/Settings/ICustomExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System;
using System.Collections.Generic;

namespace Winterdom.Viasfora.Settings {
public interface ICustomExport {
IDictionary<String, object> Export();
}
}
10 changes: 10 additions & 0 deletions src/Viasfora.Core/Settings/ISettingsExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Winterdom.Viasfora.Settings {
public interface ISettingsExport {
void Export<T>(T settingsObject) where T : class;
void Import(ISettingsStore store);
void Load(String sourcePath);
void Save(String targetPath);
}
}
13 changes: 13 additions & 0 deletions src/Viasfora.Core/Settings/IStorageConversions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Winterdom.Viasfora.Settings {
public interface IStorageConversions {
bool ToBoolean(String value);
int ToInt32(String value);
long ToInt64(String value);
double ToDouble(String value);
bool ToEnum<T>(String value, out T result) where T : struct;
String[] ToList(String value);
String ToString(object value);
}
}
14 changes: 14 additions & 0 deletions src/Viasfora.Core/Settings/ITypedSettingsStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace Winterdom.Viasfora.Settings {
public interface ITypedSettingsStore : ISettingsStore, IUpdatableSettings {
String GetString(String name, String defaultValue);
bool GetBoolean(String name, bool defaultValue);
int GetInt32(String name, int defaultValue);
long GetInt64(String name, long defaultValue);
double GetDouble(String name, double defaultValue);
T GetEnum<T>(String name, T defaultValue) where T : struct;
String[] GetList(String name, String[] defaultValue);
void SetValue(String name, object value);
}
}
25 changes: 25 additions & 0 deletions src/Viasfora.Core/Settings/SettingsBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;

namespace Winterdom.Viasfora.Settings {
public abstract class SettingsBase : IUpdatableSettings {
protected ITypedSettingsStore Store { get; private set; }
public event EventHandler SettingsChanged;

public SettingsBase(ITypedSettingsStore store) {
this.Store = store;
this.Store.SettingsChanged += OnStoreChanged;
}

public void Load() {
this.Store.Load();
}

public void Save() {
this.Store.Save();
}

private void OnStoreChanged(object sender, EventArgs e) {
SettingsChanged?.Invoke(this, EventArgs.Empty);
}
}
}
76 changes: 76 additions & 0 deletions src/Viasfora.Core/Settings/SettingsExporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;

namespace Winterdom.Viasfora.Settings {
[Export(typeof(ISettingsExport))]
public class SettingsExporter : ISettingsExport {
private IDictionary<String, String> settings = new Dictionary<String, String>();
private IStorageConversions converter;

[ImportingConstructor]
public SettingsExporter(IStorageConversions converter) {
this.converter = converter;
}

public void Load(String sourcePath) {
settings.Clear();
XDocument doc = XDocument.Load(sourcePath);
foreach ( var element in doc.Root.Elements() ) {
settings[element.Name.LocalName] = element.Value;
}
}

public void Save(String targetPath) {
using ( var xw = XmlWriter.Create(targetPath) ) {
xw.WriteStartElement("viasfora");
foreach ( String key in settings.Keys ) {
String value = settings[key];
if ( value != null ) {
xw.WriteElementString(key, settings[key]);
}
}
xw.WriteEndElement();
}
}

public void Export<T>(T settingsObject) where T : class {
ICustomExport exporter = settingsObject as ICustomExport;
if ( exporter != null ) {
CustomExport(exporter);
} else {
var type = typeof(T);
var props = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach ( var prop in props ) {
var value = prop.GetValue(settingsObject);
if ( value == null ) {
this.settings[prop.Name] = null;
} else {
this.settings[prop.Name] = this.converter.ToString(value);
}
}
}
}

public void Import(ISettingsStore store) {
foreach ( var key in this.settings.Keys ) {
store.Set(key, this.settings[key]);
}
}

private void CustomExport(ICustomExport exporter) {
var props = exporter.Export();
foreach ( var key in props.Keys ) {
var value = props[key];
if ( value == null ) {
this.settings[key] = null;
} else {
this.settings[key] = this.converter.ToString(value);
}
}
}
}
}
Loading

0 comments on commit d54435c

Please sign in to comment.