Skip to content

Commit

Permalink
Updated to new version.
Browse files Browse the repository at this point in the history
  • Loading branch information
azchohfi committed Jun 16, 2020
1 parent 3a34d5d commit d3c968c
Show file tree
Hide file tree
Showing 30 changed files with 2,267 additions and 441 deletions.
78 changes: 57 additions & 21 deletions MonacoEditorComponent.sln
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2008
# Visual Studio Version 16
VisualStudioVersion = 16.0.30030.7
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonacoEditorComponent", "MonacoEditorComponent\MonacoEditorComponent.csproj", "{DD49485C-2D9B-4824-B64E-52193B43E4CB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonacoEditorComponent", "MonacoEditorComponent\MonacoEditorComponent.csproj", "{DD49485C-2D9B-4824-B64E-52193B43E4CB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonacoEditorTestApp", "MonacoEditorTestApp\MonacoEditorTestApp.csproj", "{854C0817-09CA-4052-8C6F-0717C2721063}"
EndProject
Expand All @@ -14,40 +14,47 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{C7167F0D-BC9F-4E6E-AFE1-012C56B48DB5}") = "MonacoEditorTestApp.Package", "MonacoEditorTestApp.Package\MonacoEditorTestApp.Package.wapproj", "{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM.ActiveCfg = Debug|ARM
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM.Build.0 = Debug|ARM
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x64.ActiveCfg = Debug|x64
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x64.Build.0 = Debug|x64
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x86.ActiveCfg = Debug|x86
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x86.Build.0 = Debug|x86
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM.ActiveCfg = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM.Build.0 = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|ARM64.Build.0 = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x64.ActiveCfg = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x64.Build.0 = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x86.ActiveCfg = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Debug|x86.Build.0 = Debug|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|Any CPU.Build.0 = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM.ActiveCfg = Release|ARM
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM.Build.0 = Release|ARM
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x64.ActiveCfg = Release|x64
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x64.Build.0 = Release|x64
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x86.ActiveCfg = Release|x86
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x86.Build.0 = Release|x86
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM.ActiveCfg = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM.Build.0 = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM64.ActiveCfg = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|ARM64.Build.0 = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x64.ActiveCfg = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x64.Build.0 = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x86.ActiveCfg = Release|Any CPU
{DD49485C-2D9B-4824-B64E-52193B43E4CB}.Release|x86.Build.0 = Release|Any CPU
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|Any CPU.ActiveCfg = Debug|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|Any CPU.Build.0 = Debug|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|Any CPU.Deploy.0 = Debug|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|ARM.ActiveCfg = Debug|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|ARM.Build.0 = Debug|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|ARM.Deploy.0 = Debug|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|ARM.ActiveCfg = Debug|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|ARM64.ActiveCfg = Debug|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|x64.ActiveCfg = Debug|x64
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|x64.Build.0 = Debug|x64
{854C0817-09CA-4052-8C6F-0717C2721063}.Debug|x64.Deploy.0 = Debug|x64
Expand All @@ -57,15 +64,44 @@ Global
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|Any CPU.ActiveCfg = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|Any CPU.Build.0 = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|Any CPU.Deploy.0 = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|ARM.ActiveCfg = Release|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|ARM.Build.0 = Release|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|ARM.Deploy.0 = Release|ARM
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|ARM.ActiveCfg = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|ARM64.ActiveCfg = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x64.ActiveCfg = Release|x64
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x64.Build.0 = Release|x64
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x64.Deploy.0 = Release|x64
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x86.ActiveCfg = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x86.Build.0 = Release|x86
{854C0817-09CA-4052-8C6F-0717C2721063}.Release|x86.Deploy.0 = Release|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM.ActiveCfg = Debug|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM.Build.0 = Debug|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM.Deploy.0 = Debug|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM64.Build.0 = Debug|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|ARM64.Deploy.0 = Debug|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x64.ActiveCfg = Debug|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x64.Build.0 = Debug|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x64.Deploy.0 = Debug|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x86.ActiveCfg = Debug|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x86.Build.0 = Debug|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Debug|x86.Deploy.0 = Debug|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|Any CPU.Build.0 = Release|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|Any CPU.Deploy.0 = Release|Any CPU
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM.ActiveCfg = Release|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM.Build.0 = Release|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM.Deploy.0 = Release|ARM
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM64.ActiveCfg = Release|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM64.Build.0 = Release|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|ARM64.Deploy.0 = Release|ARM64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x64.ActiveCfg = Release|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x64.Build.0 = Release|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x64.Deploy.0 = Release|x64
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x86.ActiveCfg = Release|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x86.Build.0 = Release|x86
{A8D3A7B3-CFA7-4D98-B2CF-A37722FD3A41}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 4 additions & 2 deletions MonacoEditorComponent/CodeEditor/CodeEditor.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private async void WebView_NavigationCompleted(WebView2 sender, WebView2Navigati
// If we're supposed to have focus, make sure we try and refocus on our now loaded webview.
if (FocusManager.GetFocusedElement() == this)
{
_view.Focus(FocusState.Programmatic);
_ = FocusManager.TryFocusAsync(_view, FocusState.Programmatic);
}

Loaded?.Invoke(this, new RoutedEventArgs());
Expand All @@ -73,6 +73,8 @@ private async void WebView_NavigationCompleted(WebView2 sender, WebView2Navigati

private void WebView_NavigationStarting(WebView2 sender, WebView2NavigationStartingEventArgs args)
{
_initialized = true;

#if DEBUG
Debug.WriteLine("Navigation Starting");
#endif
Expand Down Expand Up @@ -259,7 +261,7 @@ protected override void OnGotFocus(RoutedEventArgs e)
if (_view != null && FocusManager.GetFocusedElement() == this)
{
// Forward Focus onto our inner WebView
_view.Focus(FocusState.Programmatic);
_ = FocusManager.TryFocusAsync(_view, FocusState.Programmatic);
}
}
}
Expand Down
94 changes: 31 additions & 63 deletions MonacoEditorComponent/CodeEditor/CodeEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
using Monaco.Extensions;
using Monaco.Helpers;
using System;
using System.Reflection;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.Storage;
using Windows.ApplicationModel;
using System.IO;

// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235

Expand All @@ -25,7 +25,6 @@ public sealed partial class CodeEditor : Control, INotifyPropertyChanged, IDispo
private bool _initialized;
private WebView2 _view;
private ModelHelper _model;
private Border _layoutRootBorder;

public event PropertyChangedEventHandler PropertyChanged;

Expand Down Expand Up @@ -83,53 +82,29 @@ private async void Options_PropertyChanged(object sender, PropertyChangedEventAr
await ExecuteScriptAsync("updateOptions", options);
}

private async void CodeEditor_Loaded(object sender, RoutedEventArgs e)
private void CodeEditor_Loaded(object sender, RoutedEventArgs e)
{
_model = new ModelHelper(this);

_parentAccessor = new ParentAccessor(this);
_parentAccessor.AddAssemblyForTypeLookup(typeof(Range).GetTypeInfo().Assembly);
_parentAccessor.RegisterAction("Loaded", CodeEditorLoaded);

_themeListener = new ThemeListener();
_themeListener.ThemeChanged += ThemeListener_ThemeChanged;
_themeToken = RegisterPropertyChangedCallback(RequestedThemeProperty, RequestedTheme_PropertyChanged);

_keyboardListener = new KeyboardListener(this);

_allowedObject.Clear();

AddWebAllowedObject("Parent", _parentAccessor);
AddWebAllowedObject("Theme", _themeListener);
AddWebAllowedObject("Keyboard", _keyboardListener);

Options.PropertyChanged += Options_PropertyChanged;

Decorations.VectorChanged += Decorations_VectorChanged;
Markers.VectorChanged += Markers_VectorChanged;

//_view.NewWindowRequested += WebView_NewWindowRequested;

await Task.Delay(100);
// Do this the 2nd time around.
if (_model == null && _view != null)
{
_model = new ModelHelper(this);

_initialized = true;
Options.PropertyChanged += Options_PropertyChanged;

_view = new WebView2();
_layoutRootBorder.Child = _view;
Decorations.VectorChanged += Decorations_VectorChanged;
Markers.VectorChanged += Markers_VectorChanged;

_view.NavigationStarting += WebView_NavigationStarting;
//_view.DOMContentLoaded += WebView_DOMContentLoaded;
_view.NavigationCompleted += WebView_NavigationCompleted;
//_view.NewWindowRequested += WebView_NewWindowRequested;
_view.WebMessageReceived += WebView_WebMessageReceived;
//_view.NewWindowRequested += WebView_NewWindowRequested;

_view.UriSource = new System.Uri(@"file:///" + (await StorageFile.GetFileFromApplicationUriAsync(new System.Uri("ms-appx:///Monaco/CodeEditor/CodeEditor.html"))).Path);
_initialized = true;

Loading?.Invoke(this, new RoutedEventArgs());
Loading?.Invoke(this, new RoutedEventArgs());

Unloaded += CodeEditor_Unloaded;
Unloaded -= CodeEditor_Unloaded;
Unloaded += CodeEditor_Unloaded;

Loaded?.Invoke(this, new RoutedEventArgs());
Loaded?.Invoke(this, new RoutedEventArgs());
}
}

private void CodeEditor_Unloaded(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -174,27 +149,20 @@ protected override void OnApplyTemplate()
_initialized = false;
}

_layoutRootBorder = (Border)GetTemplateChild("LayoutRootBorder");
/*<controls:WebView2 x:Name="View"
Margin="{TemplateBinding Padding}"
Visibility="{Binding IsLoaded,RelativeSource={RelativeSource TemplatedParent}}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
*/

//_view = (WebView2)GetTemplateChild("View");

//base.OnApplyTemplate();

//if (_view != null)
//{
// _view.NavigationStarting += WebView_NavigationStarting;
// //_view.DOMContentLoaded += WebView_DOMContentLoaded;
// _view.NavigationCompleted += WebView_NavigationCompleted;
// //_view.NewWindowRequested += WebView_NewWindowRequested;
// _view.WebMessageReceived += WebView_WebMessageReceived;
// _view.UriSource = new Uri("ms-appx-web:///Monaco/MonacoEditor.html");
//}
_view = (WebView2)GetTemplateChild("View");

if (_view != null)
{
_view.NavigationStarting += WebView_NavigationStarting;
//_view.DOMContentLoaded += WebView_DOMContentLoaded;
_view.NavigationCompleted += WebView_NavigationCompleted;
//_view.NewWindowRequested += WebView_NewWindowRequested;
_view.WebMessageReceived += WebView_WebMessageReceived;

_view.Source = new System.Uri(@"file:///" + Path.Combine(Package.Current.InstalledLocation.Path, @"MonacoEditorComponent/CodeEditor/CodeEditor.html"));
}

base.OnApplyTemplate();
}

internal async Task SendScriptAsync(string script,
Expand Down
2 changes: 1 addition & 1 deletion MonacoEditorComponent/Extensions/WebViewExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static async Task<T> RunScriptAsync<T>(
var start = "try {\n";
if (typeof(T) != typeof(object))
{
script = script.Trim(';');
script = script.Trim(';');
start += "JSON.stringify(" + script + ");";
}
else
Expand Down
Loading

0 comments on commit d3c968c

Please sign in to comment.