Skip to content

Commit

Permalink
catch theme loading exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Jul 25, 2021
1 parent 3f25ccd commit 0741289
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
45 changes: 37 additions & 8 deletions OneMore/Colorizer/Colorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,27 @@ public XElement Colorize(string source, XNamespace ns)
{
// plain text prior to capture
code = code.Replace("\t", " ");
var style = theme.GetStyle("plaintext");
builder.Append(style == null ? code : style.Apply(code));
if (theme != null)
{
var style = theme.GetStyle("plaintext");
builder.Append(style == null ? code : style.Apply(code));
}
else
{
builder.Append(code);
}
}
else
{
var style = theme.GetStyle(scope);
builder.Append(style == null ? code : style.Apply(code));
if (theme != null)
{
var style = theme.GetStyle(scope);
builder.Append(style == null ? code : style.Apply(code));
}
else
{
builder.Append(code);
}
}
}
});
Expand Down Expand Up @@ -113,13 +127,28 @@ public string ColorizeOne(string source)
// plain text prior to capture
// simple conversion of tabs to spaces (shouldn't be tabs in OneNote)
code = code.Replace("\t", " ");
var style = theme.GetStyle("plaintext");
builder.Append(style == null ? code : style.Apply(code));

if (theme != null)
{
var style = theme.GetStyle("plaintext");
builder.Append(style == null ? code : style.Apply(code));
}
else
{
builder.Append(code);
}
}
else
{
var style = theme.GetStyle(scope);
builder.Append(style == null ? code : style.Apply(code));
if (theme != null)
{
var style = theme.GetStyle(scope);
builder.Append(style == null ? code : style.Apply(code));
}
else
{
builder.Append(code);
}
}
}
});
Expand Down
12 changes: 10 additions & 2 deletions OneMore/Colorizer/Provider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ public static ITheme LoadTheme(string path)
{
var json = File.ReadAllText(path);
var serializer = new JavaScriptSerializer();
var theme = serializer.Deserialize<Theme>(json);
Theme theme = null;

theme.TranslateColorNames();
try
{
theme = serializer.Deserialize<Theme>(json);
theme.TranslateColorNames();
}
catch (Exception exc)
{
Logger.Current.WriteLine($"error loading theme {path}", exc);
}

return theme;
}
Expand Down

0 comments on commit 0741289

Please sign in to comment.