### 2023-02-21更新
------ #### SuperDesign V3.0.2302.2101 - *.[新增]全新文本编辑器,支持高亮、FTP查看和编辑、目录浏览,历史版本等众多功能。
This commit is contained in:
1 parent
c7b33920bd
commit
03bcb8c5fd
406 files changed
+312053
-48889
No files matched your search
+214
@@ -0,0 +1,214 @@
|
||||
#region License
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright(c) 2020 Petteri Kautonen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace VPKSoft.ScintillaLexers.ScintillaNotepadPlusPlus
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class to get the mark colors from the Notepad++ software XML lexer definition file.
|
||||
/// </summary>
|
||||
public class MarkColors
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the smart high highlighting foreground color.
|
||||
/// </summary>
|
||||
public Color SmartHighLightingForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the smart high highlighting background color.
|
||||
/// </summary>
|
||||
public Color SmartHighLightingBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the incremental highlight all foreground color.
|
||||
/// </summary>
|
||||
public Color IncrementalHighlightAllForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the incremental highlight all background color.
|
||||
/// </summary>
|
||||
public Color IncrementalHighlightAllBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark one foreground color.
|
||||
/// </summary>
|
||||
public Color MarkOneForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark one background color.
|
||||
/// </summary>
|
||||
public Color MarkOneBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark two foreground color.
|
||||
/// </summary>
|
||||
public Color MarkTwoForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark two background color.
|
||||
/// </summary>
|
||||
public Color MarkTwoBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark three foreground color.
|
||||
/// </summary>
|
||||
public Color MarkThreeForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark three background color.
|
||||
/// </summary>
|
||||
public Color MarkThreeBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark four foreground color.
|
||||
/// </summary>
|
||||
public Color MarkFourForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark four background color.
|
||||
/// </summary>
|
||||
public Color MarkFourBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark five foreground color.
|
||||
/// </summary>
|
||||
public Color MarkFiveForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the mark five background color.
|
||||
/// </summary>
|
||||
public Color MarkFiveBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current line background color.
|
||||
/// </summary>
|
||||
public Color CurrentLineBackground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current line background color.
|
||||
/// </summary>
|
||||
public Color CurrentLineForeground { get; set; } = Color.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color definitions from a XML style definition file.
|
||||
/// </summary>
|
||||
/// <param name="fileName">The name of the file.</param>
|
||||
/// <returns>An instance to this (<see cref="MarkColors"/>) class.</returns>
|
||||
public static MarkColors FromFile(string fileName)
|
||||
{
|
||||
return FromXDocument(XDocument.Load(fileName));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the color definitions from a XDocument style definition instance.
|
||||
/// </summary>
|
||||
/// <param name="document">The XDocument to document to get the styles from.</param>
|
||||
/// <returns>An instance to this (<see cref="MarkColors"/>) class.</returns>
|
||||
public static MarkColors FromXDocument(XDocument document)
|
||||
{
|
||||
try
|
||||
{
|
||||
MarkColors result = new MarkColors();
|
||||
var nodes = document.Descendants(XName.Get("WidgetStyle")).Where(f =>
|
||||
f.Attribute("name")?.Value == "Current line background colour" ||
|
||||
f.Attribute("name")?.Value == "Smart HighLighting" ||
|
||||
f.Attribute("name")?.Value == "Incremental highlight all" ||
|
||||
f.Attribute("name")?.Value == "Mark Style 1" ||
|
||||
f.Attribute("name")?.Value == "Mark Style 2" ||
|
||||
f.Attribute("name")?.Value == "Mark Style 3" ||
|
||||
f.Attribute("name")?.Value == "Mark Style 4" ||
|
||||
f.Attribute("name")?.Value == "Mark Style 5");
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var style = XmlStyleNotepadPlusPlusHelper.FromXElement(node);
|
||||
if (style.Name == "Mark Style 1")
|
||||
{
|
||||
result.MarkOneForeground = style.ColorForeground;
|
||||
result.MarkOneBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Mark Style 2")
|
||||
{
|
||||
result.MarkTwoForeground = style.ColorForeground;
|
||||
result.MarkTwoBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Mark Style 3")
|
||||
{
|
||||
result.MarkThreeForeground = style.ColorForeground;
|
||||
result.MarkThreeBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Mark Style 4")
|
||||
{
|
||||
result.MarkFourForeground = style.ColorForeground;
|
||||
result.MarkFourBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Mark Style 5")
|
||||
{
|
||||
result.MarkFiveForeground = style.ColorForeground;
|
||||
result.MarkFiveBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Smart HighLighting")
|
||||
{
|
||||
result.SmartHighLightingForeground = style.ColorForeground;
|
||||
result.SmartHighLightingBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Incremental highlight all")
|
||||
{
|
||||
result.IncrementalHighlightAllForeground = style.ColorForeground;
|
||||
result.IncrementalHighlightAllBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Incremental highlight all")
|
||||
{
|
||||
result.IncrementalHighlightAllForeground = style.ColorForeground;
|
||||
result.IncrementalHighlightAllBackground = style.ColorBackground;
|
||||
}
|
||||
|
||||
if (style.Name == "Current line background colour")
|
||||
{
|
||||
result.CurrentLineForeground = style.ColorForeground;
|
||||
result.CurrentLineBackground = style.ColorBackground;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return new MarkColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+301
@@ -0,0 +1,301 @@
|
||||
#region License
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright(c) 2020 Petteri Kautonen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using ScintillaNET;
|
||||
using VPKSoft.ScintillaLexers.CreateSpecificLexer;
|
||||
using VPKSoft.ScintillaLexers.HelperClasses;
|
||||
|
||||
namespace VPKSoft.ScintillaLexers.ScintillaNotepadPlusPlus
|
||||
{
|
||||
/// <summary>
|
||||
/// A class for loading global styles for the <see cref="Scintilla"/> from
|
||||
/// </summary>
|
||||
public class ScintillaNotepadPlusPlusStyles
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the global and default styles for the given <see cref="Scintilla"/> instance depending on the other parameters.
|
||||
/// </summary>
|
||||
/// <param name="document">A XML document containing the lexer style data.</param>
|
||||
/// <param name="scintilla">The scintilla instance of which style to set.</param>
|
||||
/// <param name="useGlobalOverride">if set to <c>true</c> the "Global override" style is read from the <paramref name="document"/>.</param>
|
||||
/// <param name="font">If set to <c>true</c> the font name and size is read from the <paramref name="document"/>..</param>
|
||||
/// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns>
|
||||
public static bool SetGlobalDefaultStyles(XDocument document, Scintilla scintilla, bool useGlobalOverride, bool font)
|
||||
{
|
||||
try
|
||||
{
|
||||
scintilla.StyleResetDefault();
|
||||
|
||||
var globalStyle =
|
||||
document.Descendants(XName.Get("WidgetStyle")).FirstOrDefault(f =>
|
||||
f.Attribute("name") != null &&
|
||||
f.Attribute("name").Value == "Global override");
|
||||
|
||||
if (globalStyle != null && useGlobalOverride)
|
||||
{
|
||||
SetStyle(scintilla, XmlStyleNotepadPlusPlusHelper.FromXElement(globalStyle), font);
|
||||
}
|
||||
|
||||
var defaultStyle =
|
||||
document.Descendants(XName.Get("WidgetStyle")).FirstOrDefault(f =>
|
||||
f.Attribute("name") != null &&
|
||||
f.Attribute("name").Value == "Default Style");
|
||||
|
||||
SetStyle(scintilla, XmlStyleNotepadPlusPlusHelper.FromXElement(defaultStyle), font);
|
||||
|
||||
scintilla.StyleClearAll();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the folding of a <see cref="Scintilla"/> based on the "Fold" style defined in the XML document.
|
||||
/// </summary>
|
||||
/// <param name="document">The XML document to read the folding style from.</param>
|
||||
/// <param name="scintilla">The instance to a scintilla of which folding style to set.</param>
|
||||
/// <returns><c>true</c> if the operation was successful, <c>false</c> otherwise.</returns>
|
||||
public static bool SetFolding(XDocument document, Scintilla scintilla)
|
||||
{
|
||||
try
|
||||
{
|
||||
var foldStyle = // <WidgetStyle name="Fold"...
|
||||
document.Descendants(XName.Get("WidgetStyle")).FirstOrDefault(f =>
|
||||
f.Attribute("name") != null &&
|
||||
f.Attribute("name").Value == "Fold");
|
||||
|
||||
if (foldStyle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var style = XmlStyleNotepadPlusPlusHelper.FromXElement(foldStyle);
|
||||
|
||||
// the default colors as in the example.. (C)::https://github.com/jacobslusser/ScintillaNET/wiki/Automatic-Code-Folding
|
||||
|
||||
// Instruct the lexer to calculate folding..
|
||||
LexerFoldProperties.FoldDefault(scintilla);
|
||||
|
||||
// Configure a margin to display folding symbols
|
||||
scintilla.Margins[2].Type = MarginType.Symbol;
|
||||
scintilla.Margins[2].Mask = Marker.MaskFolders;
|
||||
scintilla.Margins[2].Sensitive = true;
|
||||
scintilla.Margins[2].Width = 20;
|
||||
|
||||
// Set colors for all folding markers
|
||||
for (int i = 25; i <= 31; i++)
|
||||
{
|
||||
scintilla.Markers[i].SetForeColor(style.ColorBackground);
|
||||
scintilla.Markers[i].SetBackColor(style.ColorForeground);
|
||||
}
|
||||
|
||||
// Configure folding markers with respective symbols
|
||||
scintilla.Markers[Marker.Folder].Symbol = MarkerSymbol.BoxPlus;
|
||||
scintilla.Markers[Marker.FolderOpen].Symbol = MarkerSymbol.BoxMinus;
|
||||
scintilla.Markers[Marker.FolderEnd].Symbol = MarkerSymbol.BoxPlusConnected;
|
||||
scintilla.Markers[Marker.FolderMidTail].Symbol = MarkerSymbol.TCorner;
|
||||
scintilla.Markers[Marker.FolderOpenMid].Symbol = MarkerSymbol.BoxMinusConnected;
|
||||
scintilla.Markers[Marker.FolderSub].Symbol = MarkerSymbol.VLine;
|
||||
scintilla.Markers[Marker.FolderTail].Symbol = MarkerSymbol.LCorner;
|
||||
|
||||
// Enable automatic folding
|
||||
scintilla.AutomaticFold = (AutomaticFold.Show | AutomaticFold.Click | AutomaticFold.Change);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the style of a given <see cref="Scintilla"/> with a given style.
|
||||
/// </summary>
|
||||
/// <param name="scintilla">The scintilla instance of which style to set.</param>
|
||||
/// <param name="style">The style to set for the <paramref name="scintilla"/>.</param>
|
||||
/// <param name="font">If set to <c>true</c> the font is also set from the given style.</param>
|
||||
private static void SetStyle(Scintilla scintilla, XmlStyleNotepadPlusPlusHelper style, bool font)
|
||||
{
|
||||
if (style.ColorForeground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].ForeColor = style.ColorForeground;
|
||||
}
|
||||
|
||||
if (style.ColorBackground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].BackColor = style.ColorBackground;
|
||||
}
|
||||
|
||||
scintilla.Styles[style.StyleId].Italic = style.Italic;
|
||||
scintilla.Styles[style.StyleId].Bold = style.Bold;
|
||||
if (font)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].Font = style.FontName;
|
||||
scintilla.Styles[style.StyleId].Size = style.FontSize;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the Scintilla global styles from a Notepad++ style definition XML file.
|
||||
/// </summary>
|
||||
/// <param name="document">The XML document to read the global style from.</param>
|
||||
/// <param name="scintilla">The Scintilla of which global styles to set.</param>
|
||||
/// <param name="useWhiteSpace">A flag indicating whether to color the white space symbol.</param>
|
||||
/// <param name="useSelectionColors">A flag indicating whether to color the selection.</param>
|
||||
/// <param name="useMarginColors">A flag indicating whether to color the margin.</param>
|
||||
/// <returns><c>true</c> if the operations was successful, <c>false</c> otherwise.</returns>
|
||||
public static bool LoadScintillaStyleFromNotepadPlusXml(XDocument document, Scintilla scintilla,
|
||||
bool useWhiteSpace, bool useSelectionColors, bool useMarginColors)
|
||||
{
|
||||
try
|
||||
{
|
||||
var nodes = document.Descendants(XName.Get("WidgetStyle"));
|
||||
// loop through the color definition elements..
|
||||
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var style = XmlStyleNotepadPlusPlusHelper.FromXElement(node);
|
||||
|
||||
if (style.Name == "Indent guideline style" ||
|
||||
style.Name == "Brace highlight style" ||
|
||||
style.Name == "Bad brace colour" ||
|
||||
style.Name == "Find Mark Style" || // unknown (?): 31
|
||||
style.Name == "Line number margin" || // unknown (?): 33
|
||||
style.Name == "Smart HighLighting" || // unknown (?): 29
|
||||
style.Name == "Mark Style 1" || // unknown (?): 25
|
||||
style.Name == "Mark Style 2" || // unknown (?): 24
|
||||
style.Name == "Mark Style 3" || // unknown (?): 23
|
||||
style.Name == "Mark Style 4" || // unknown (?): 22
|
||||
style.Name == "Mark Style 5" || // unknown (?): 21
|
||||
style.Name == "Incremental highlight all" || // unknown (?): 28
|
||||
style.Name == "Tags match highlighting" || // unknown (?): 27
|
||||
style.Name == "ags attribute") // unknown (?): 26
|
||||
{
|
||||
if (style.ColorForeground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].ForeColor = style.ColorForeground;
|
||||
}
|
||||
|
||||
if (style.ColorBackground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].BackColor = style.ColorBackground;
|
||||
}
|
||||
|
||||
scintilla.Styles[style.StyleId].Italic = style.Italic;
|
||||
scintilla.Styles[style.StyleId].Bold = style.Bold;
|
||||
}
|
||||
else if (style.Name == "Current line background colour")
|
||||
{
|
||||
scintilla.CaretLineBackColor = style.ColorBackground;
|
||||
}
|
||||
else if (style.Name == "Selected text colour")
|
||||
{
|
||||
scintilla.SetSelectionForeColor(useSelectionColors, style.ColorForeground);
|
||||
scintilla.SetSelectionBackColor(useSelectionColors, style.ColorBackground);
|
||||
}
|
||||
else if (style.Name == "Caret colour")
|
||||
{
|
||||
scintilla.CaretForeColor = style.ColorForeground;
|
||||
//scintilla.Styles[style.StyleId].BackColor = style.ColorBackground;
|
||||
//scintilla.Styles[style.StyleId].ForeColor = style.ColorBackground;
|
||||
// caret background color not supported? StyleID: 2069
|
||||
}
|
||||
else if (style.Name == "Edge colour")
|
||||
{
|
||||
scintilla.EdgeColor = style.ColorForeground;
|
||||
}
|
||||
else if (style.Name == "Fold margin") // <WidgetStyle name="Fold margin"..
|
||||
{
|
||||
scintilla.SetFoldMarginHighlightColor(useMarginColors, style.ColorForeground);
|
||||
scintilla.SetFoldMarginColor(useMarginColors, style.ColorBackground);
|
||||
}
|
||||
else if (style.Name == "White space symbol") // <WidgetStyle name="White space symbol"..
|
||||
{
|
||||
scintilla.SetWhitespaceForeColor(useWhiteSpace, style.ColorForeground);
|
||||
scintilla.SetWhitespaceBackColor(useWhiteSpace, style.ColorBackground);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the styles for a <see cref="Scintilla"/> from the Notepad++'s XML style files for a given lexer.
|
||||
/// </summary>
|
||||
/// <param name="document">The XML document to read the lexer style from.</param>
|
||||
/// <param name="scintilla">The <see cref="Scintilla"/> which lexer style to set.</param>
|
||||
/// <param name="lexerType">A <see cref="LexerEnumerations.LexerType"/> enumeration.</param>
|
||||
/// <returns><c>true</c> if the operations was successful, <c>false</c> otherwise.</returns>
|
||||
public static bool LoadLexerStyleFromNotepadPlusXml(XDocument document, Scintilla scintilla,
|
||||
LexerEnumerations.LexerType lexerType)
|
||||
{
|
||||
try
|
||||
{
|
||||
var nodes = document.Descendants(XName.Get("LexerType")).Where(f =>
|
||||
f.Attribute("name")?.Value == LexerTypeName.GetLexerXmlName(lexerType)).Descendants();
|
||||
|
||||
// loop through the color definition elements..
|
||||
foreach (var node in nodes)
|
||||
{
|
||||
var style = XmlStyleNotepadPlusPlusHelper.FromXElement(node);
|
||||
|
||||
if (style.ColorForeground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].ForeColor = style.ColorForeground;
|
||||
}
|
||||
|
||||
if (style.ColorBackground != Color.Empty)
|
||||
{
|
||||
scintilla.Styles[style.StyleId].BackColor = style.ColorBackground;
|
||||
}
|
||||
|
||||
scintilla.Styles[style.StyleId].Bold = style.Bold;
|
||||
scintilla.Styles[style.StyleId].Italic = style.Italic;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// an error occurred so return false..
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+149
@@ -0,0 +1,149 @@
|
||||
#region License
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright(c) 2020 Petteri Kautonen
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace VPKSoft.ScintillaLexers.ScintillaNotepadPlusPlus
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper class for Notepad++ XML style definition files.
|
||||
/// </summary>
|
||||
public class XmlStyleNotepadPlusPlusHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the style definition.
|
||||
/// </summary>
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the style definition defines a fond as bold.
|
||||
/// </summary>
|
||||
public bool Bold { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether the style definition defines a fond as italic.
|
||||
/// </summary>
|
||||
public bool Italic { get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the style identifier from a style definition.
|
||||
/// </summary>
|
||||
public int StyleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the foreground color of a font from a style definition.
|
||||
/// </summary>
|
||||
public Color ColorForeground { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the background color of a font from a style definition.
|
||||
/// </summary>
|
||||
public Color ColorBackground { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the font from a style definition.
|
||||
/// </summary>
|
||||
public string FontName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the size of the font from a style definition.
|
||||
/// </summary>
|
||||
public int FontSize { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute value of a given <see cref="XElement"/>.
|
||||
/// </summary>
|
||||
/// <param name="element">The element to get the attribute from.</param>
|
||||
/// <param name="attributeName">Name of the attribute.</param>
|
||||
/// <param name="defaultValue">The default value for the attribute in case the attribute is null or the value is empty.</param>
|
||||
/// <returns>The <see cref="XAttribute"/> value based on given parameters if successful; otherwise <paramref name="defaultValue"/>.</returns>
|
||||
private static string GetAttributeValue(XElement element, string attributeName, string defaultValue = "")
|
||||
{
|
||||
var attribute = element.Attribute(attributeName);
|
||||
if (attribute == null)
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
if (attribute.Value.Trim() != string.Empty)
|
||||
{
|
||||
return attribute.Value.Trim();
|
||||
}
|
||||
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the attribute value of a given <see cref="XElement"/> as a <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="element">The element to get the color attribute from.</param>
|
||||
/// <param name="attributeName">Name of the attribute.</param>
|
||||
/// <returns>A color if the operation was successful; otherwise Color.Empty.</returns>
|
||||
private static Color GetAttributeAsColor(XElement element, string attributeName)
|
||||
{
|
||||
var attribute = element.Attribute(attributeName);
|
||||
if (attribute == null)
|
||||
{
|
||||
return Color.Empty;
|
||||
}
|
||||
|
||||
if (attribute.Value.Trim() == string.Empty)
|
||||
{
|
||||
return Color.Empty;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return ColorTranslator.FromHtml("#" + element.Attribute(attributeName)?.Value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
return Color.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of this class based on the given <see cref="XElement"/>
|
||||
/// </summary>
|
||||
/// <param name="element">The element to get the style definition from.</param>
|
||||
/// <returns>A <see cref="XmlStyleNotepadPlusPlusHelper"/> class instance filled with the style definition data.</returns>
|
||||
public static XmlStyleNotepadPlusPlusHelper FromXElement(XElement element)
|
||||
{
|
||||
return new XmlStyleNotepadPlusPlusHelper
|
||||
{
|
||||
Name = GetAttributeValue(element, "name", "None"),
|
||||
Bold = int.Parse(GetAttributeValue(element, "fontStyle", "0")) == 1,
|
||||
Italic = int.Parse(GetAttributeValue(element, "fontStyle", "0")) == 2,
|
||||
StyleId = int.Parse(GetAttributeValue(element, "styleID", "0")),
|
||||
ColorForeground = GetAttributeAsColor(element, "fgColor"),
|
||||
ColorBackground = GetAttributeAsColor(element, "bgColor"),
|
||||
FontName = GetAttributeValue(element, "fontName", "Consolas"),
|
||||
FontSize = int.Parse(GetAttributeValue(element, "fontSize", "10")),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user