Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1e87dab
commit 1e604b9
Showing
7 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
EditorExtensions/Classifications/SVG/SvgContentTypeDefinition.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.ComponentModel.Composition; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace MadsKristensen.EditorExtensions | ||
{ | ||
/// <summary> | ||
/// Exports the Svg content type and file extension | ||
/// </summary> | ||
public class SvgContentTypeDefinition | ||
{ | ||
public const string SvgContentType = "svg"; | ||
|
||
/// <summary> | ||
/// Exports the Svg HTML content type | ||
/// </summary> | ||
[Export(typeof(ContentTypeDefinition))] | ||
[Name(SvgContentType)] | ||
[BaseDefinition("xml")] | ||
public ContentTypeDefinition ISvgContentType { get; set; } | ||
|
||
[Export(typeof(FileExtensionToContentTypeDefinition))] | ||
[ContentType(SvgContentType)] | ||
[FileExtension(".svg")] | ||
public FileExtensionToContentTypeDefinition SvgFileExtension { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System.IO; | ||
using System.Windows; | ||
using System.Windows.Controls; | ||
using Microsoft.VisualStudio.Text; | ||
using Microsoft.VisualStudio.Text.Editor; | ||
|
||
namespace MadsKristensen.EditorExtensions | ||
{ | ||
internal class SvgMargin : MarginBase | ||
{ | ||
public const string MarginName = "SvgMargin"; | ||
private WebBrowser _browser; | ||
private string _fileName; | ||
|
||
public SvgMargin(string contentType, string source, bool showMargin, ITextDocument document) | ||
: base(source, MarginName, contentType, showMargin, document) | ||
{ | ||
_fileName = document.FilePath; | ||
} | ||
|
||
protected override void StartCompiler(string source) | ||
{ | ||
if (_browser != null && File.Exists(_fileName)) | ||
{ | ||
_browser.Navigate(_fileName); | ||
} | ||
} | ||
|
||
protected override void CreateControls(IWpfTextViewHost host, string source) | ||
{ | ||
int width = WESettings.GetInt(SettingsKey); | ||
width = width == -1 ? 400 : width; | ||
|
||
_browser = new WebBrowser(); | ||
_browser.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; | ||
|
||
Grid grid = new Grid(); | ||
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(0, GridUnitType.Star) }); | ||
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(5, GridUnitType.Pixel) }); | ||
grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(width) }); | ||
grid.RowDefinitions.Add(new RowDefinition()); | ||
|
||
grid.Children.Add(_browser); | ||
this.Children.Add(grid); | ||
|
||
Grid.SetColumn(_browser, 2); | ||
Grid.SetRow(_browser, 0); | ||
|
||
GridSplitter splitter = new GridSplitter(); | ||
splitter.Width = 5; | ||
splitter.ResizeDirection = GridResizeDirection.Columns; | ||
splitter.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; | ||
splitter.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; | ||
splitter.DragCompleted += splitter_DragCompleted; | ||
|
||
grid.Children.Add(splitter); | ||
Grid.SetColumn(splitter, 1); | ||
Grid.SetRow(splitter, 0); | ||
} | ||
|
||
void splitter_DragCompleted(object sender, System.Windows.Controls.Primitives.DragCompletedEventArgs e) | ||
{ | ||
Settings.SetValue(SettingsKey, (int)this.ActualWidth); | ||
Settings.Save(); | ||
} | ||
|
||
public override void MinifyFile(string fileName, string source) | ||
{ | ||
// Nothing to minify | ||
} | ||
|
||
public override bool IsSaveFileEnabled | ||
{ | ||
get { return false; } | ||
} | ||
|
||
protected override bool CanWriteToDisk(string source) | ||
{ | ||
return false; | ||
} | ||
|
||
public override bool CompileEnabled | ||
{ | ||
get { return true; } | ||
} | ||
|
||
public override string CompileToLocation | ||
{ | ||
get { return string.Empty; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters