diff --git a/Microsoft.Toolkit.Future/Adorners/AdornerDecorator.cs b/Microsoft.Toolkit.Future/Adorners/AdornerDecorator.cs index 8e0cc0a..e4cde29 100644 --- a/Microsoft.Toolkit.Future/Adorners/AdornerDecorator.cs +++ b/Microsoft.Toolkit.Future/Adorners/AdornerDecorator.cs @@ -1,4 +1,4 @@ -// Licensed to the .NET Foundation under one or more agreements. +// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. @@ -11,7 +11,7 @@ namespace CommunityToolkit.WinUI.Controls.Future; /// /// Helper class to hold content with an . Use this to wrap another and direct where the should sit. This class is helpful to constrain the or in cases where an appropriate location for the layer can't be automatically determined. /// -[TemplatePart(Name = PartAdornerLayer, Type = typeof(AdornerLayer))] +[TemplatePart(Name = PartAdornerLayer, Type =typeof(AdornerLayer))] [ContentProperty(Name = nameof(Child))] public sealed class AdornerDecorator : Control { @@ -40,4 +40,4 @@ protected override void OnApplyTemplate() AdornerLayer = GetTemplateChild(PartAdornerLayer) as AdornerLayer; } -} \ No newline at end of file +} diff --git a/Microsoft.Toolkit.Future/Behaviors/ListViewItemSelectedBehavior.cs b/Microsoft.Toolkit.Future/Behaviors/ListViewItemSelectedBehavior.cs index 9cd7ec0..8188ecb 100644 --- a/Microsoft.Toolkit.Future/Behaviors/ListViewItemSelectedBehavior.cs +++ b/Microsoft.Toolkit.Future/Behaviors/ListViewItemSelectedBehavior.cs @@ -12,7 +12,11 @@ namespace CommunityToolkit.WinUI.Behaviors.Future; /// /// Behavior which allows for binding to the IsSelected property of a . /// +#if UNO +public class ListViewItemSelectedBehavior : CommunityToolkit.WinUI.Behaviors.BehaviorBase +#else public class ListViewItemSelectedBehavior : BehaviorBase +#endif { WeakReference? _parentContainer; diff --git a/Microsoft.Toolkit.Future/Converters/CollectionContainsConverter.cs b/Microsoft.Toolkit.Future/Converters/CollectionContainsConverter.cs index 49bb1ac..fe796b4 100644 --- a/Microsoft.Toolkit.Future/Converters/CollectionContainsConverter.cs +++ b/Microsoft.Toolkit.Future/Converters/CollectionContainsConverter.cs @@ -11,7 +11,7 @@ namespace Microsoft.Toolkit.Future.Converters; [Bindable] -public class CollectionContainsConverter : DependencyObject, IValueConverter // BoolToObjectConverter??? +public partial class CollectionContainsConverter : DependencyObject, IValueConverter // BoolToObjectConverter??? { public IEnumerable Collection { diff --git a/Microsoft.Toolkit.Future/Extensions/ListBox/ListBoxExtensions.cs b/Microsoft.Toolkit.Future/Extensions/ListBox/ListBoxExtensions.cs index 5e9efb2..62496da 100644 --- a/Microsoft.Toolkit.Future/Extensions/ListBox/ListBoxExtensions.cs +++ b/Microsoft.Toolkit.Future/Extensions/ListBox/ListBoxExtensions.cs @@ -56,7 +56,11 @@ private static void OnAllowDeselectionChanged(DependencyObject obj, DependencyPr } } + #if UNO + private static void OnTapped(object sender, Microsoft.UI.Xaml.Input.TappedRoutedEventArgs e) + #else private static void OnTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) + #endif { if (sender is ListBox listBox) { diff --git a/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotCloseButtonCommandConverter.cs b/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotCloseButtonCommandConverter.cs index cd7b134..551c2b6 100644 --- a/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotCloseButtonCommandConverter.cs +++ b/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotCloseButtonCommandConverter.cs @@ -17,7 +17,11 @@ public class GetPivotCloseButtonCommandConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, string language) { + #if UNO + var pivot = (value as DependencyObject)?.FindAscendant(); + #else var pivot = (value as DependencyObject)?.FindAscendant(); + #endif if (pivot != null) { diff --git a/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotItemConverter.cs b/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotItemConverter.cs index 5873c41..28499b1 100644 --- a/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotItemConverter.cs +++ b/Microsoft.Toolkit.Future/Extensions/Pivot/GetPivotItemConverter.cs @@ -23,7 +23,11 @@ public virtual object Convert(object value, Type targetType, object parameter, s var panel = pivotheader?.Parent as PivotHeaderPanel; var index = panel?.Children?.IndexOf(pivotheader); + #if UNO + var pivot = (value as DependencyObject)?.FindAscendant(); + #else var pivot = (value as DependencyObject)?.FindAscendant(); + #endif if (index != null) { diff --git a/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.Properties.cs b/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.Properties.cs index 0dfadb8..ad0fe2f 100644 --- a/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.Properties.cs +++ b/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.Properties.cs @@ -20,7 +20,11 @@ public partial class PivotExtensions /// /// The from which to get the associated instance /// The instance associated with the the or null + #if UNO + public static Style GetPivotHeaderItemStyle(Microsoft.UI.Xaml.Controls.Pivot obj) + #else public static Style GetPivotHeaderItemStyle(Windows.UI.Xaml.Controls.Pivot obj) + #endif { return (Style)obj.GetValue(PivotHeaderItemStyleProperty); } @@ -30,7 +34,11 @@ public static Style GetPivotHeaderItemStyle(Windows.UI.Xaml.Controls.Pivot obj) /// /// The to associated the instance to /// The instance to bind to the + #if UNO + public static void SetPivotHeaderItemStyle(Microsoft.UI.Xaml.Controls.Pivot obj, Style value) + #else public static void SetPivotHeaderItemStyle(Windows.UI.Xaml.Controls.Pivot obj, Style value) + #endif { obj.SetValue(PivotHeaderItemStyleProperty, value); } @@ -98,7 +106,11 @@ public static void SetImageSource(PivotItem obj, ImageSource value) /// /// Pivot to get value from. /// Command value for the MSEdgeTabStyle Close Button. + #if UNO + public static ICommand GetCloseButtonCommand(Microsoft.UI.Xaml.Controls.Pivot obj) + #else public static ICommand GetCloseButtonCommand(Windows.UI.Xaml.Controls.Pivot obj) // TODO: Should this be per PivotHeaderItem? Thinking no? + #endif { return (ICommand)obj.GetValue(CloseButtonCommandProperty); } @@ -108,7 +120,11 @@ public static ICommand GetCloseButtonCommand(Windows.UI.Xaml.Controls.Pivot obj) /// /// Pivot to set value for. /// Command value for the MSEdgeTabStyle Close Button. + #if UNO + public static void SetCloseButtonCommand(Microsoft.UI.Xaml.Controls.Pivot obj, ICommand value) + #else public static void SetCloseButtonCommand(Windows.UI.Xaml.Controls.Pivot obj, ICommand value) + #endif { obj.SetValue(CloseButtonCommandProperty, value); } @@ -124,7 +140,11 @@ public static void SetCloseButtonCommand(Windows.UI.Xaml.Controls.Pivot obj, ICo /// /// Pivot to get value from. /// False is content will be hidden. + #if UNO + public static bool GetIsContentVisible(Microsoft.UI.Xaml.Controls.Pivot obj) + #else public static bool GetIsContentVisible(Windows.UI.Xaml.Controls.Pivot obj) + #endif { return (bool)obj.GetValue(IsContentVisibleProperty); } @@ -134,7 +154,11 @@ public static bool GetIsContentVisible(Windows.UI.Xaml.Controls.Pivot obj) /// /// Pivot to set value for. /// Set to false to hide the PivotItemsPresenter. + #if UNO + public static void SetIsContentVisible(Microsoft.UI.Xaml.Controls.Pivot obj, bool value) + #else public static void SetIsContentVisible(Windows.UI.Xaml.Controls.Pivot obj, bool value) + #endif { obj.SetValue(IsContentVisibleProperty, value); } diff --git a/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.cs b/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.cs index 79fe264..7d9f423 100644 --- a/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.cs +++ b/Microsoft.Toolkit.Future/Extensions/Pivot/PivotExtensions.cs @@ -18,7 +18,11 @@ public partial class PivotExtensions { private static void InitPivotStyle(DependencyObject d, DependencyPropertyChangedEventArgs e) { + #if UNO + var pivot = d as Microsoft.UI.Xaml.Controls.Pivot; + #else var pivot = d as Windows.UI.Xaml.Controls.Pivot; + #endif if (pivot == null) { @@ -31,11 +35,18 @@ private static void InitPivotStyle(DependencyObject d, DependencyPropertyChanged private static void Pivot_Loaded(object sender, RoutedEventArgs e) { + #if UNO + var pivot = sender as Microsoft.UI.Xaml.Controls.Pivot; + #else var pivot = sender as Windows.UI.Xaml.Controls.Pivot; + #endif + #if UNO + var panels = pivot.FindDescendants().OfType().Where(panel => panel.FindAscendant() == pivot); + #else // Make sure we find the PivotHeaderPanels for just this Pivot (in case we have embedded pivots) var panels = pivot.FindDescendants().OfType().Where(panel => panel.FindAscendant() == pivot); - + #endif var style = GetPivotHeaderItemStyle(pivot); foreach (var panel in panels) @@ -74,7 +85,11 @@ private static void Pivot_Loaded(object sender, RoutedEventArgs e) private static void IsContentVisible_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e) { + #if UNO + var pivot = d as Microsoft.UI.Xaml.Controls.Pivot; + #else var pivot = d as Windows.UI.Xaml.Controls.Pivot; + #endif pivot.Loaded -= Pivot_Loaded; pivot.Loaded += Pivot_Loaded; @@ -85,7 +100,11 @@ private static void IsContentVisible_Changed(DependencyObject d, DependencyPrope } } + #if UNO + private static void SetContentVisible(Microsoft.UI.Xaml.Controls.Pivot pivot, bool value) + #else private static void SetContentVisible(Windows.UI.Xaml.Controls.Pivot pivot, bool value) + #endif { // Make sure we find the PivotHeaderPanels for just this Pivot (in case we have embedded pivots) var presenter = pivot.FindDescendant("PivotItemPresenter"); diff --git a/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlAutocompleteService.cs b/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlAutocompleteService.cs index b3512ea..4d39b54 100644 --- a/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlAutocompleteService.cs +++ b/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlAutocompleteService.cs @@ -62,7 +62,11 @@ public void AddDefaultSuggestions(List items, List t.IsSubclassOf(typeof(DependencyObject)))) { +#if UNO + items.Add(new CompletionItem(t.Name, "", CompletionItemKind.Class)); // TODO: +#else items.Add(new CompletionItem(t.Name, CompletionItemKind.Class)); +#endif } } } @@ -70,7 +74,11 @@ public void AddDefaultSuggestions(List items, List items, string prefix, L { foreach (var t in types.Where(t => t.IsSubclassOf(typeof(DependencyObject)))) { +#if UNO + items.Add(new CompletionItem(t.Name, "", CompletionItemKind.Class)); +#else items.Add(new CompletionItem(t.Name, CompletionItemKind.Class)); +#endif } } } @@ -101,8 +113,12 @@ public void AddPropertySuggestions(List items, string tagName) { foreach (var property in GetDependencyProperties(type)) { +#if UNO + items.Add(new CompletionItem(property.Name.Substring(0, property.Name.Length - 8), "", CompletionItemKind.Property)); +#else // Trim 'Property' off DependencyProperty name. items.Add(new CompletionItem(property.Name.Substring(0, property.Name.Length - 8), CompletionItemKind.Property)); +#endif } } } @@ -122,7 +138,11 @@ public void AddValueSuggestions(List items, string tagName, stri { foreach (var value in Enum.GetNames(prop.PropertyType)) { +#if UNO + items.Add(new CompletionItem(value, "", CompletionItemKind.Value)); +#else items.Add(new CompletionItem(value, CompletionItemKind.Value)); +#endif } } // FontWeights...grrr diff --git a/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlLanguageProvider.cs b/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlLanguageProvider.cs index c08cca5..7bd8c64 100644 --- a/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlLanguageProvider.cs +++ b/XamlStudio.Toolkit/Services/XamlAutocompleteService/XamlLanguageProvider.cs @@ -62,8 +62,12 @@ public IAsyncOperation ProvideCompletionItemsAsync(IModel model, { if (index >= 1 && text[index - 1] == '<') { +#if UNO + items.Add(new CompletionItem(parentTagName, "", CompletionItemKind.Class)); +#else // Only show suggestion if we're starting a close tag. items.Add(new CompletionItem(parentTagName, CompletionItemKind.Class)); +#endif } } else if (context.TriggerCharacter == ElementTrigger) @@ -101,7 +105,11 @@ public IAsyncOperation ProvideCompletionItemsAsync(IModel model, return new CompletionList() { +#if UNO + Suggestions = items.ToArray() +#else Items = items +#endif }; }); } @@ -110,4 +118,18 @@ public IAsyncOperation ResolveCompletionItemAsync(CompletionItem { throw new NotImplementedException(); } + +#if UNO + public async Task ProvideCompletionItemsAsync(IModel model, Position position, CompletionContext context) + { + // Forward to the WinRT-style implementation and unwrap the result + var op = ProvideCompletionItemsAsync((IModel)model, (IPosition)position, context); + return await op.AsTask().ConfigureAwait(false); + } + + public async Task ResolveCompletionItemAsync(IModel model, CompletionItem item) + { + throw new NotImplementedException(); + } +#endif } diff --git a/XamlStudio.Toolkit/Services/XamlXmlTreeCoordinator.cs b/XamlStudio.Toolkit/Services/XamlXmlTreeCoordinator.cs index 07351d7..59401bc 100644 --- a/XamlStudio.Toolkit/Services/XamlXmlTreeCoordinator.cs +++ b/XamlStudio.Toolkit/Services/XamlXmlTreeCoordinator.cs @@ -60,7 +60,9 @@ public class XamlXmlTreeCoordinator { nameof(UIElement.RenderTransformOrigin), UIElement.RenderTransformOriginProperty }, { nameof(UIElement.Shadow), UIElement.ShadowProperty }, { nameof(UIElement.Transform3D), UIElement.Transform3DProperty }, - { nameof(UIElement.Transitions), UIElement.TransitionsProperty }, +#if !UNO + { nameof(UIElement.Transitions), UIElement.TransitionsProperty }, // TODO: https://github.com/unoplatform/uno/issues/22288 +#endif { nameof(UIElement.UseLayoutRounding), UIElement.UseLayoutRoundingProperty }, { nameof(UIElement.Visibility), UIElement.VisibilityProperty }, { nameof(UIElement.XYFocusDownNavigationStrategy), UIElement.XYFocusDownNavigationStrategyProperty }, diff --git a/XamlStudio/App.xaml.cs b/XamlStudio/App.xaml.cs index f1f9323..5a351b8 100644 --- a/XamlStudio/App.xaml.cs +++ b/XamlStudio/App.xaml.cs @@ -43,7 +43,7 @@ public App() // Deferred execution until used. Check https://msdn.microsoft.com/library/dd642331(v=vs.110).aspx for further info on Lazy class. _activationService = new Lazy(CreateActivationService); - +#if !UNO try { AppCenter.SetCountryCode(new Windows.Globalization.GeographicRegion().CodeTwoLetter); @@ -54,15 +54,18 @@ public App() } AppCenter.Start("", typeof(Analytics)); AppCenter.Start("", typeof(Crashes)); +#endif } protected override async void OnLaunched(LaunchActivatedEventArgs args) { +#if !UNO if (!args.PrelaunchActivated) { AppLoggerService.LogInfo($"[AppActivation] Application activated by {args.Kind}"); await ActivationService.ActivateAsync(args); } +#endif } protected override async void OnActivated(IActivatedEventArgs args) @@ -70,12 +73,13 @@ protected override async void OnActivated(IActivatedEventArgs args) AppLoggerService.LogInfo($"[AppActivation] Application activated by {args.Kind}"); await ActivationService.ActivateAsync(args); } - +#if !UNO protected override async void OnFileActivated(FileActivatedEventArgs args) { AppLoggerService.LogInfo($"[AppActivation] Application activated by {args.Kind}"); await ActivationService.ActivateAsync(args); } +#endif private ActivationService CreateActivationService() { @@ -132,7 +136,11 @@ private void App_Resuming(object sender, object e) /// /// Handles the event of an unhandles exception bubbling up all the way to the App instance. /// +#if UNO + private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) +#else private void App_UnhandledException(object sender, Windows.UI.Xaml.UnhandledExceptionEventArgs e) +#endif { // TODO: Check if these are coming from a Render call and just ignore then.# (this is usually the case, but doesn't save us) e.Handled = true; diff --git a/XamlStudio/ViewModels/DocumentViewModel.cs b/XamlStudio/ViewModels/DocumentViewModel.cs index b266ffa..bacb81a 100644 --- a/XamlStudio/ViewModels/DocumentViewModel.cs +++ b/XamlStudio/ViewModels/DocumentViewModel.cs @@ -72,32 +72,56 @@ public AdvancedCollectionView BindingHistory private static CssLineStyle _errorLineStyle = new CssLineStyle() { +#if UNO + BackgroundColor = "#FFCA416A".ToColor() +#else BackgroundColor = new SolidColorBrush("#FFCA416A".ToColor()) +#endif }; private static CssInlineStyle _errorStyle = new CssInlineStyle() { +#if UNO + BackgroundColor = "#FFCA416A".ToColor(), + ForegroundColor = "#FFFFFFFF".ToColor(), +#else BackgroundColor = new SolidColorBrush("#FFCA416A".ToColor()), ForegroundColor = new SolidColorBrush("#FFFFFFFF".ToColor()), +#endif FontWeight = FontWeights.SemiBold }; private static CssInlineStyle _bindingStyleUnbound = new CssInlineStyle() { +#if UNO + BackgroundColor = "#FFB4EBEF".ToColor(), + ForegroundColor = "#FF333333".ToColor() +#else BackgroundColor = new SolidColorBrush("#FFB4EBEF".ToColor()), ForegroundColor = new SolidColorBrush("#FF333333".ToColor()) +#endif }; private static CssInlineStyle _bindingStyleSuccess = new CssInlineStyle() { +#if UNO + BackgroundColor = "#FFB9FEC1".ToColor(), + ForegroundColor = "#FF333333".ToColor() +#else BackgroundColor = new SolidColorBrush("#FFB9FEC1".ToColor()), ForegroundColor = new SolidColorBrush("#FF333333".ToColor()) +#endif }; private static CssInlineStyle _bindingStyleError = new CssInlineStyle() { +#if UNO + BackgroundColor = "#FFFFF689".ToColor(), + ForegroundColor = "#FF663333".ToColor(), +#else BackgroundColor = new SolidColorBrush("#FFFFF689".ToColor()), ForegroundColor = new SolidColorBrush("#FF663333".ToColor()), +#endif FontWeight = FontWeights.SemiBold }; diff --git a/XamlStudio/Views/Binding.xaml b/XamlStudio/Views/Binding.xaml index 1d3f94d..64bcc07 100644 --- a/XamlStudio/Views/Binding.xaml +++ b/XamlStudio/Views/Binding.xaml @@ -41,7 +41,7 @@ FontWeight="SemiBold" Text="{x:Bind}" /> - x + diff --git a/XamlStudio/Views/Document.Design.xaml.cs b/XamlStudio/Views/Document.Design.xaml.cs index 99df276..8c58956 100644 --- a/XamlStudio/Views/Document.Design.xaml.cs +++ b/XamlStudio/Views/Document.Design.xaml.cs @@ -149,9 +149,9 @@ public async void Receive(SelectedVisualElementMessage message) if (ViewModel.XamlCoordinator.TryGetXmlElement(message.Element, out var node) && node is XmlNodeSyntax xmlNode) { - var loc = CodeEditor.Text.GetLineColumnIndex(xmlNode.Span.Start); + // TODO: var loc = CodeEditor.Text.GetLineColumnIndex(xmlNode.Span.Start); - await CodeEditor.RevealPositionInCenterAsync(new Position((uint)loc.Line, (uint)loc.Column)); + // await CodeEditor.RevealPositionInCenterAsync(new Position((uint)loc.Line, (uint)loc.Column)); } } @@ -225,47 +225,47 @@ private void RemoveAdorner() public async void Receive(AddToXamlMessage message) { // TODO: We need to be modifying the Xml Document syntax and using that to modify text vs. text itself... - var text = CodeEditor.Text; - if (ViewModel.XamlCoordinator.TryGetXmlElement(message.Element, out var node) - && node is XmlNodeSyntax xmlNode) - { - var loc = text.GetLineColumnIndex(xmlNode.Span.Start); - - if (xmlNode is IXmlElementSyntax xmlElement) - { - var attribute = xmlElement.Attributes.FirstOrDefault((attr) => attr.Name == message.Property); - - if (attribute != null) - { - loc = text.GetLineColumnIndex(attribute.Span.Start); - } - } - - await CodeEditor.RevealPositionInCenterAsync(new Position((uint)loc.Line, (uint)loc.Column)); - - var lines = text.Split(Environment.NewLine); - - var targetLine = lines[loc.Line - 1]; - if (targetLine.Contains(message.Property)) - { - var sp = targetLine.IndexOf(message.Property + "=") + message.Property.Length + 2; - lines[loc.Line - 1] = targetLine.Substring(0, sp) + $"{message.Value}" + targetLine.Substring(targetLine.IndexOf("\"", sp + 1)); - } - else if (targetLine.Trim().EndsWith("/>")) - { - lines[loc.Line - 1] = targetLine.Substring(0, targetLine.Length - 2) + $" {message.Property}=\"{message.Value}\"/>"; - } - else if (targetLine.Trim().EndsWith(">")) - { - lines[loc.Line - 1] = targetLine.Substring(0, targetLine.Length - 1) + $" {message.Property}=\"{message.Value}\">"; - } - else - { - lines[loc.Line - 1] = targetLine + $" {message.Property}=\"{message.Value}\""; - } - - CodeEditor.Text = string.Join(Environment.NewLine, lines); - } + // TODO: var text = CodeEditor.Text; + // if (ViewModel.XamlCoordinator.TryGetXmlElement(message.Element, out var node) + // && node is XmlNodeSyntax xmlNode) + // { + // var loc = text.GetLineColumnIndex(xmlNode.Span.Start); + + // if (xmlNode is IXmlElementSyntax xmlElement) + // { + // var attribute = xmlElement.Attributes.FirstOrDefault((attr) => attr.Name == message.Property); + + // if (attribute != null) + // { + // loc = text.GetLineColumnIndex(attribute.Span.Start); + // } + // } + + // await CodeEditor.RevealPositionInCenterAsync(new Position((uint)loc.Line, (uint)loc.Column)); + + // var lines = text.Split(Environment.NewLine); + + // var targetLine = lines[loc.Line - 1]; + // if (targetLine.Contains(message.Property)) + // { + // var sp = targetLine.IndexOf(message.Property + "=") + message.Property.Length + 2; + // lines[loc.Line - 1] = targetLine.Substring(0, sp) + $"{message.Value}" + targetLine.Substring(targetLine.IndexOf("\"", sp + 1)); + // } + // else if (targetLine.Trim().EndsWith("/>")) + // { + // lines[loc.Line - 1] = targetLine.Substring(0, targetLine.Length - 2) + $" {message.Property}=\"{message.Value}\"/>"; + // } + // else if (targetLine.Trim().EndsWith(">")) + // { + // lines[loc.Line - 1] = targetLine.Substring(0, targetLine.Length - 1) + $" {message.Property}=\"{message.Value}\">"; + // } + // else + // { + // lines[loc.Line - 1] = targetLine + $" {message.Property}=\"{message.Value}\""; + // } + + // CodeEditor.Text = string.Join(Environment.NewLine, lines); + // } } private enum DesignerMode diff --git a/XamlStudio/Views/Document.xaml b/XamlStudio/Views/Document.xaml index c73d3e4..8bc5830 100644 --- a/XamlStudio/Views/Document.xaml +++ b/XamlStudio/Views/Document.xaml @@ -297,24 +297,7 @@ - - - - - - + @@ -334,7 +317,7 @@ - - + --> diff --git a/XamlStudio/Views/Document.xaml.cs b/XamlStudio/Views/Document.xaml.cs index 156a096..7dc3002 100644 --- a/XamlStudio/Views/Document.xaml.cs +++ b/XamlStudio/Views/Document.xaml.cs @@ -105,7 +105,7 @@ public Document() Loaded += Document_Loaded; Unloaded += Document_Unloaded; - CodeEditor.RegisterPropertyChangedCallback(CodeEditor.SelectedRangeProperty, CodeEditor_SelectedRangeChanged); + // TODO: CodeEditor.RegisterPropertyChangedCallback(CodeEditor.SelectedRangeProperty, CodeEditor_SelectedRangeChanged); } private void Document_Loaded(object sender, RoutedEventArgs e) @@ -142,7 +142,7 @@ private void InitializeViewModel(DocumentViewModel model) LoadedDocument = model.Document; - CodeEditor.Options.Folding = true; + // TODO: CodeEditor.Options.Folding = true; SetPaneOrientation(); SetPreviewAreaTheme(); @@ -172,45 +172,46 @@ private async void CodeEditor_Loading(object sender, RoutedEventArgs e) { var libserv = LibraryService.Instance; - var languages = new Monaco.LanguagesHelper(CodeEditor); - - await languages.RegisterCompletionItemProviderAsync("xml", new XamlLanguageProvider() - { - KnownNamespaces = SettingsService.Instance.KnownNamespaces.ToList() - }); - - await languages.RegisterHoverProviderAsync("xml", (model, position) => - { - return AsyncInfo.Run(async delegate (CancellationToken cancelationToken) - { - var word = await model.GetWordAtPositionAsync(position); - - if (word != null && !string.IsNullOrWhiteSpace(word.Word) && - XamlRenderService.GetTypeFromName(word.Word) is Type type && - libserv.LibrariesByNamespace.TryGetValue(type.Namespace, out LibraryInfo info)) - { - _lastHoverType = type; - return new Hover(new string[] - { - "**" + word.Word + "** - [" + type.FullName + "](" + - libserv.GetLinkForType(type, info) - + ")" - }, new Range(position.LineNumber, word.StartColumn, position.LineNumber, word.EndColumn)); - } - - return null; - }); - }); + // TODO: verify this + // var languages = new Monaco.LanguagesHelper(CodeEditor); + + // await languages.RegisterCompletionItemProviderAsync("xml", new XamlLanguageProvider() + // { + // KnownNamespaces = SettingsService.Instance.KnownNamespaces.ToList() + // }); + + // await languages.RegisterHoverProviderAsync("xml", (model, position) => + // { + // return AsyncInfo.Run(async delegate (CancellationToken cancelationToken) + // { + // var word = await model.GetWordAtPositionAsync(position); + + // if (word != null && !string.IsNullOrWhiteSpace(word.Word) && + // XamlRenderService.GetTypeFromName(word.Word) is Type type && + // libserv.LibrariesByNamespace.TryGetValue(type.Namespace, out LibraryInfo info)) + // { + // _lastHoverType = type; + // return new Hover(new string[] + // { + // "**" + word.Word + "** - [" + type.FullName + "](" + + // libserv.GetLinkForType(type, info) + // + ")" + // }, new Range(position.LineNumber, word.StartColumn, position.LineNumber, word.EndColumn)); + // } + + // return null; + // }); + // }); } public async void Receive(NavigateToLineMessage message) { - await CodeEditor.RevealLineInCenterIfOutsideViewportAsync(message.Line); + // TODO: await CodeEditor.RevealLineInCenterIfOutsideViewportAsync(message.Line); } public void Receive(InsertTextMessage message) { - CodeEditor.SelectedText = message.Text; + // TODO:CodeEditor.SelectedText = message.Text; DispatcherQueue.GetForCurrentThread().TryEnqueue(DispatcherQueuePriority.Low, () => { @@ -236,13 +237,13 @@ public async void Receive(RenderXamlMessage message) if (!keepcontent && newcontent.HasSuggestion) { - var pos = await CodeEditor.GetPositionAsync(); + // TODO: var pos = await CodeEditor.GetPositionAsync(); // Update our document with suggested changes. ViewModel.Document.Content = newcontent.SuggestedContent; // Restore cursor to where it was. - await CodeEditor.SetPositionAsync(pos); + // TODO: await CodeEditor.SetPositionAsync(pos); } if (!string.IsNullOrWhiteSpace(newcontent.DataContextSource)) @@ -405,7 +406,7 @@ private void CodeEditor_KeyDown(Monaco.CodeEditor sender, Monaco.Helpers.WebKeyE // That or the PropertyChanged isn't firing for somereason on SelectedText change. if (args.KeyCode == 116) // F5 { - ViewModel.SelectedText = CodeEditor.SelectedText; + // TODO: ViewModel.SelectedText = CodeEditor.SelectedText; } // Handle Shortcuts. https://keycode.info/ @@ -529,6 +530,7 @@ private void SetPreviewAreaTheme() } #region Share Button Code +#if !UNO private readonly Lazy _device = new Lazy(InitCanvas); private static CanvasDevice InitCanvas() @@ -537,11 +539,12 @@ private static CanvasDevice InitCanvas() } private CanvasBitmap _screenshotImage; - +#endif private async void ShareButton_Click(Microsoft.UI.Xaml.Controls.SplitButton sender, Microsoft.UI.Xaml.Controls.SplitButtonClickEventArgs args) { +#if !UNO _screenshotImage = await GetAppScreenshot(); - +#endif DataTransferManager.ShowShareUI(); } @@ -552,13 +555,15 @@ private void ShareMenuEntireWindow_Click(object sender, RoutedEventArgs e) private async void ShareMenuPreviewOnly_Click(object sender, RoutedEventArgs e) { +#if !UNO _screenshotImage = await GetPreviewScreenshot(); - +#endif DataTransferManager.ShowShareUI(); } private async void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args) { +#if !UNO // Provide updated bitmap data using delayed rendering if (_screenshotImage != null) { @@ -574,8 +579,9 @@ private async void DataTransferManager_DataRequested(DataTransferManager sender, deferral.Complete(); } +#endif } - +#if !UNO private async Task GetAppScreenshot() { var renderTarget = new RenderTargetBitmap(); @@ -601,6 +607,7 @@ private async Task GetPreviewScreenshot() var pixels = await renderTarget.GetPixelsAsync(); return CanvasBitmap.CreateFromBytes(_device.Value, pixels, renderTarget.PixelWidth, renderTarget.PixelHeight, DirectXPixelFormat.B8G8R8A8UIntNormalized); } +#endif #endregion #region BreadcrumbBar Events @@ -608,7 +615,7 @@ private async void BreadcrumbBar_ItemClicked(Microsoft.UI.Xaml.Controls.Breadcru { if (args.Item is BreadcrumbInfo info) { - await CodeEditor.RevealPositionInCenterAsync(info.Location); + // TODO:await CodeEditor.RevealPositionInCenterAsync(info.Location); } } @@ -619,11 +626,11 @@ private void CodeEditor_SelectedRangeChanged(DependencyObject sender, Dependency private async Task UpdateBreadcrumbs() { - var text = CodeEditor.Text; // This is hopefully in-sync so we don't round-trip again. - var position = await CodeEditor.GetPositionAsync(); // TODO: Should we just monitor and keep track of this vs. polling? - if (position == null) return; + // TODO: var text = CodeEditor.Text; // This is hopefully in-sync so we don't round-trip again. + // var position = await CodeEditor.GetPositionAsync(); // TODO: Should we just monitor and keep track of this vs. polling? + // if (position == null) return; - var index = text.GetCharacterIndex((int)position.LineNumber, (int)position.Column); + var index = -1; // TODO: text.GetCharacterIndex((int)position.LineNumber, (int)position.Column); if (index == -1) { @@ -631,34 +638,34 @@ private async Task UpdateBreadcrumbs() } // TODO: This is expensive, we should be doing this on a debounce and more globally as the document updates to be used elsewhere for visual tree sync, etc... as part of render loop - var _xmlRoot = ViewModel.HasCompiled ? ViewModel.Result.XmlDocument : Parser.ParseText(text); + // TODO: var _xmlRoot = ViewModel.HasCompiled ? ViewModel.Result.XmlDocument : Parser.ParseText(text); Breadcrumbs.Clear(); - var current = _xmlRoot.FindNode(index + 1); + // TODO: var current = _xmlRoot.FindNode(index + 1); - WeakReferenceMessenger.Default.Send(new(current.ParentElement)); + // WeakReferenceMessenger.Default.Send(new(current.ParentElement)); - foreach (var node in current.AncestorNodesAndSelf()) - { - if (node is IXmlElementSyntax element) - { - var loc = text.GetLineColumnIndex(node.Span.Start); - Breadcrumbs.Insert(0, new BreadcrumbInfo() - { - Name = element.Name, - Location = new Position((uint)loc.Line, (uint)loc.Column), - // TODO: Put child sister nodes in a list so that can have drop-down to navigate within document? - }); - } - } + // foreach (var node in current.AncestorNodesAndSelf()) + // { + // if (node is IXmlElementSyntax element) + // { + // // TODO: var loc = text.GetLineColumnIndex(node.Span.Start); + // // Breadcrumbs.Insert(0, new BreadcrumbInfo() + // // { + // // Name = element.Name, + // // Location = new Position((uint)loc.Line, (uint)loc.Column), + // // // TODO: Put child sister nodes in a list so that can have drop-down to navigate within document? + // // }); + // } + // } // Didn't want to re-write style yet, Workaround for https://github.com/microsoft/microsoft-ui-xaml/issues/7213 - Breadcrumbs.Add(new BreadcrumbInfo() - { - Name = $"Caret @ L{position.LineNumber} Ch{position.Column}", - Location = position, - }); + // TODO: Breadcrumbs.Add(new BreadcrumbInfo() + // { + // Name = $"Caret @ L{position.LineNumber} Ch{position.Column}", + // Location = position, + // }); } #endregion diff --git a/XamlStudio/Views/MainPage.xaml.cs b/XamlStudio/Views/MainPage.xaml.cs index 3d6c79d..88d7005 100644 --- a/XamlStudio/Views/MainPage.xaml.cs +++ b/XamlStudio/Views/MainPage.xaml.cs @@ -225,7 +225,11 @@ public void Receive(KeyDownMessage keyInfo) keyInfo.Reply(active); } +#if UNO + private async void MainPage_Loaded(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) +#else private async void MainPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) +#endif { // Offload from main thread to parallelize assembly loading. Task t = new Task(async () => diff --git a/XamlStudio/Views/Properties.xaml.cs b/XamlStudio/Views/Properties.xaml.cs index af8d413..69ed78b 100644 --- a/XamlStudio/Views/Properties.xaml.cs +++ b/XamlStudio/Views/Properties.xaml.cs @@ -45,7 +45,11 @@ public Properties() Unloaded += Properties_Unloaded; } +#if UNO + private void Properties_Loaded(object sender, RoutedEventArgs e) +#else private void Properties_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) +#endif { WeakReferenceMessenger.Default.UnregisterAll(this); WeakReferenceMessenger.Default.RegisterAll(this); @@ -57,7 +61,12 @@ private void Properties_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) } } +#if UNO + private void Properties_Unloaded(object sender, RoutedEventArgs e) +#else + private void Properties_Unloaded(object sender, Windows.UI.Xaml.RoutedEventArgs e) +#endif { if (Parent == null) { diff --git a/XamlStudio/Views/SettingsPanelPage.xaml.cs b/XamlStudio/Views/SettingsPanelPage.xaml.cs index de452f8..08f6c26 100644 --- a/XamlStudio/Views/SettingsPanelPage.xaml.cs +++ b/XamlStudio/Views/SettingsPanelPage.xaml.cs @@ -120,37 +120,43 @@ private async void ButtonOpenLogFolder_Click(object sender, RoutedEventArgs e) }); } +#if UNO + private async void DataGrid_RowEditEnded(object sender, WinUI.TableView.TableViewCellEditEndedEventArgs e) +#else private async void DataGrid_RowEditEnded(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridRowEditEndedEventArgs e) +#endif { // Save Namespaces after Edit. await ViewModel.Settings.SaveAsync(nameof(ViewModel.Settings.KnownNamespaces)); - +#if !UNO var ns = e.Row.DataContext as XmlnsNamespace; Analytics.TrackEvent("Settings_EditNamespaces", new Dictionary { { "Location", "Toolbox" }, { "Name", ns.Name }, { "Path", ns.Path }, }); +#endif } private void AddNamespaceButton_Click(object sender, RoutedEventArgs e) { - // Ensure grid is visible - KnownNamespacesExpander.IsExpanded = true; + // TODO: verify this + // // Ensure grid is visible + // KnownNamespacesExpander.IsExpanded = true; - // Add new Row and begin editing - ViewModel.Settings.KnownNamespaces.Insert(0, new Toolkit.Models.XmlnsNamespace(string.Empty, string.Empty)); + // // Add new Row and begin editing + // ViewModel.Settings.KnownNamespaces.Insert(0, new Toolkit.Models.XmlnsNamespace(string.Empty, string.Empty)); - _ = CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => - { - NamespaceDataGrid.SelectedIndex = 0; + // _ = CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => + // { + // NamespaceDataGrid.SelectedIndex = 0; - NamespaceDataGrid.ScrollIntoView(NamespaceDataGrid.SelectedItem, null); + // NamespaceDataGrid.ScrollIntoView(NamespaceDataGrid.SelectedItem, null); - NamespaceDataGrid.Focus(FocusState.Keyboard); + // NamespaceDataGrid.Focus(FocusState.Keyboard); - NamespaceDataGrid.BeginEdit(); - }); + // NamespaceDataGrid.BeginEdit(); + // }); } private async void RemoveNamespaceButton_Click(object sender, RoutedEventArgs e) @@ -172,7 +178,11 @@ private async void RemoveNamespaceButton_Click(object sender, RoutedEventArgs e) } } +#if UNO + private void NamespaceDataGrid_PreparingCellForEdit(object sender, WinUI.TableView.TableViewPreparingCellForEditEventArgs e) +#else private void NamespaceDataGrid_PreparingCellForEdit(object sender, Microsoft.Toolkit.Uwp.UI.Controls.DataGridPreparingCellForEditEventArgs e) +#endif { if (e.EditingElement is TextBox t) { diff --git a/XamlStudio/Views/Toolbox.xaml.cs b/XamlStudio/Views/Toolbox.xaml.cs index 2899a20..74435de 100644 --- a/XamlStudio/Views/Toolbox.xaml.cs +++ b/XamlStudio/Views/Toolbox.xaml.cs @@ -115,8 +115,11 @@ private void Favorite_Click(object sender, RoutedEventArgs e) ClearSelection(); } - +#if UNO + private void HyperlinkButton_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) +#else private void HyperlinkButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) +#endif { var fe = sender as FrameworkElement; if (fe != null)