diff --git a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.Properties.cs b/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.Properties.cs deleted file mode 100644 index e850f0775..000000000 --- a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.Properties.cs +++ /dev/null @@ -1,204 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/DropShadowPanel - -namespace Notepads.Controls -{ - using Windows.UI; - using Windows.UI.Composition; - using Windows.UI.Xaml; - - /// - /// The control allows the creation of a DropShadow for any Xaml FrameworkElement in markup - /// making it easier to add shadows to Xaml without having to directly drop down to Windows.UI.Composition APIs. - /// - public partial class DropShadowPanel - { - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty BlurRadiusProperty = - DependencyProperty.Register(nameof(BlurRadius), typeof(double), typeof(DropShadowPanel), new PropertyMetadata(9.0, OnBlurRadiusChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ColorProperty = - DependencyProperty.Register(nameof(Color), typeof(Color), typeof(DropShadowPanel), new PropertyMetadata(Colors.Black, OnColorChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty OffsetXProperty = - DependencyProperty.Register(nameof(OffsetX), typeof(double), typeof(DropShadowPanel), new PropertyMetadata(0.0, OnOffsetXChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty OffsetYProperty = - DependencyProperty.Register(nameof(OffsetY), typeof(double), typeof(DropShadowPanel), new PropertyMetadata(0.0, OnOffsetYChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty OffsetZProperty = - DependencyProperty.Register(nameof(OffsetZ), typeof(double), typeof(DropShadowPanel), new PropertyMetadata(0.0, OnOffsetZChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ShadowOpacityProperty = - DependencyProperty.Register(nameof(ShadowOpacity), typeof(double), typeof(DropShadowPanel), new PropertyMetadata(1.0, OnShadowOpacityChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty IsMaskedProperty = - DependencyProperty.Register(nameof(IsMasked), typeof(bool), typeof(DropShadowPanel), new PropertyMetadata(true, OnIsMaskedChanged)); - - /// - /// Gets DropShadow. Exposes the underlying composition object to allow custom Windows.UI.Composition animations. - /// - public DropShadow DropShadow => _dropShadow; - - /// - /// Gets or sets the mask of the underlying . - /// Allows for a custom to be set. - /// - public CompositionBrush Mask - { - get => _dropShadow?.Mask; - - set - { - if (_dropShadow != null) - { - _dropShadow.Mask = value; - } - } - } - - /// - /// Gets or sets the blur radius of the drop shadow. - /// - public double BlurRadius - { - get => (double)GetValue(BlurRadiusProperty); - set => SetValue(BlurRadiusProperty, value); - } - - /// - /// Gets or sets the color of the drop shadow. - /// - public Color Color - { - get => (Color)GetValue(ColorProperty); - set => SetValue(ColorProperty, value); - } - - /// - /// Gets or sets the x offset of the drop shadow. - /// - public double OffsetX - { - get => (double)GetValue(OffsetXProperty); - set => SetValue(OffsetXProperty, value); - } - - /// - /// Gets or sets the y offset of the drop shadow. - /// - public double OffsetY - { - get => (double)GetValue(OffsetYProperty); - set => SetValue(OffsetYProperty, value); - } - - /// - /// Gets or sets the z offset of the drop shadow. - /// - public double OffsetZ - { - get => (double)GetValue(OffsetZProperty); - set => SetValue(OffsetZProperty, value); - } - - /// - /// Gets or sets the opacity of the drop shadow. - /// - public double ShadowOpacity - { - get => (double)GetValue(ShadowOpacityProperty); - set => SetValue(ShadowOpacityProperty, value); - } - - /// - /// Gets or sets a value indicating whether the panel uses an alpha mask to create a more precise shadow vs. a quicker rectangle shape. - /// - /// - /// Turn this off to lose fidelity and gain performance of the panel. - /// - public bool IsMasked - { - get => (bool)GetValue(IsMaskedProperty); - set => SetValue(IsMaskedProperty, value); - } - - private static void OnBlurRadiusChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnBlurRadiusChanged((double)e.NewValue); - } - } - - private static void OnColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnColorChanged((Color)e.NewValue); - } - } - - private static void OnOffsetXChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnOffsetXChanged((double)e.NewValue); - } - } - - private static void OnOffsetYChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnOffsetYChanged((double)e.NewValue); - } - } - - private static void OnOffsetZChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnOffsetZChanged((double)e.NewValue); - } - } - - private static void OnShadowOpacityChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.OnShadowOpacityChanged((double)e.NewValue); - } - } - - private static void OnIsMaskedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (d is DropShadowPanel panel) - { - panel.UpdateShadowMask(); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.cs b/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.cs deleted file mode 100644 index 81a4ca10f..000000000 --- a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.cs +++ /dev/null @@ -1,191 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/DropShadowPanel - -namespace Notepads.Controls -{ - using System.Numerics; - using Windows.UI; - using Windows.UI.Composition; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Hosting; - using Windows.UI.Xaml.Shapes; - - /// - /// The control allows the creation of a DropShadow for any Xaml FrameworkElement in markup - /// making it easier to add shadows to Xaml without having to directly drop down to Windows.UI.Composition APIs. - /// - [TemplatePart(Name = PartShadow, Type = typeof(Border))] - public partial class DropShadowPanel : ContentControl - { - private const string PartShadow = "ShadowElement"; - - private readonly DropShadow _dropShadow; - private readonly SpriteVisual _shadowVisual; - private Border _border; - - /// - /// Initializes a new instance of the class. - /// - public DropShadowPanel() - { - DefaultStyleKey = typeof(DropShadowPanel); - - Compositor compositor = ElementCompositionPreview.GetElementVisual(this).Compositor; - - _shadowVisual = compositor.CreateSpriteVisual(); - - _dropShadow = compositor.CreateDropShadow(); - _shadowVisual.Shadow = _dropShadow; - } - - /// - /// Update the visual state of the control when its template is changed. - /// - protected override void OnApplyTemplate() - { - _border = GetTemplateChild(PartShadow) as Border; - - if (_border != null) - { - ElementCompositionPreview.SetElementChildVisual(_border, _shadowVisual); - } - - ConfigureShadowVisualForCastingElement(); - - base.OnApplyTemplate(); - } - - /// - protected override void OnContentChanged(object oldContent, object newContent) - { - if (oldContent != null) - { - if (oldContent is FrameworkElement oldElement) - { - oldElement.SizeChanged -= OnSizeChanged; - } - } - - if (newContent != null) - { - if (newContent is FrameworkElement newElement) - { - newElement.SizeChanged += OnSizeChanged; - } - } - - base.OnContentChanged(oldContent, newContent); - } - - private void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - UpdateShadowSize(); - } - - private void ConfigureShadowVisualForCastingElement() - { - UpdateShadowMask(); - UpdateShadowSize(); - } - - private void OnBlurRadiusChanged(double newValue) - { - if (_dropShadow != null) - { - _dropShadow.BlurRadius = (float)newValue; - } - } - - private void OnColorChanged(Color newValue) - { - if (_dropShadow != null) - { - _dropShadow.Color = newValue; - } - } - - private void OnOffsetXChanged(double newValue) - { - if (_dropShadow != null) - { - UpdateShadowOffset((float)newValue, _dropShadow.Offset.Y, _dropShadow.Offset.Z); - } - } - - private void OnOffsetYChanged(double newValue) - { - if (_dropShadow != null) - { - UpdateShadowOffset(_dropShadow.Offset.X, (float)newValue, _dropShadow.Offset.Z); - } - } - - private void OnOffsetZChanged(double newValue) - { - if (_dropShadow != null) - { - UpdateShadowOffset(_dropShadow.Offset.X, _dropShadow.Offset.Y, (float)newValue); - } - } - - private void OnShadowOpacityChanged(double newValue) - { - if (_dropShadow != null) - { - _dropShadow.Opacity = (float)newValue; - } - } - - private void UpdateShadowMask() - { - if (Content != null && IsMasked) - { - CompositionBrush mask = null; - - if (Content is Image image) - { - mask = image.GetAlphaMask(); - } - else if (Content is Shape shape) - { - mask = shape.GetAlphaMask(); - } - else if (Content is TextBlock textBlock) - { - mask = textBlock.GetAlphaMask(); - } - - _dropShadow.Mask = mask; - } - else - { - _dropShadow.Mask = null; - } - } - - private void UpdateShadowOffset(float x, float y, float z) - { - if (_dropShadow != null) - { - _dropShadow.Offset = new Vector3(x, y, z); - } - } - - private void UpdateShadowSize() - { - if (_shadowVisual != null) - { - Vector2 newSize = new Vector2(0, 0); - if (Content is FrameworkElement content) - { - newSize = new Vector2((float)content.ActualWidth, (float)content.ActualHeight); - } - - _shadowVisual.Size = newSize; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.xaml b/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.xaml deleted file mode 100644 index d56d2d6fd..000000000 --- a/src/Notepads.Controls/DropShadowPanel/DropShadowPanel.xaml +++ /dev/null @@ -1,30 +0,0 @@ - - - - diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.Data.cs b/src/Notepads.Controls/GridSplitter/GridSplitter.Data.cs deleted file mode 100644 index 2a2f72695..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.Data.cs +++ /dev/null @@ -1,158 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - /// - /// Represents the control that redistributes space between columns or rows of a Grid control. - /// - public partial class GridSplitter - { - /// - /// Enum to indicate whether GridSplitter resizes Columns or Rows - /// - public enum GridResizeDirection - { - /// - /// Determines whether to resize rows or columns based on its Alignment and - /// width compared to height - /// - Auto, - - /// - /// Resize columns when dragging Splitter. - /// - Columns, - - /// - /// Resize rows when dragging Splitter. - /// - Rows - } - - /// - /// Enum to indicate what Columns or Rows the GridSplitter resizes - /// - public enum GridResizeBehavior - { - /// - /// Determine which columns or rows to resize based on its Alignment. - /// - BasedOnAlignment, - - /// - /// Resize the current and next Columns or Rows. - /// - CurrentAndNext, - - /// - /// Resize the previous and current Columns or Rows. - /// - PreviousAndCurrent, - - /// - /// Resize the previous and next Columns or Rows. - /// - PreviousAndNext - } - - /// - /// Enum to indicate the supported gripper cursor types. - /// - public enum GripperCursorType - { - /// - /// Change the cursor based on the splitter direction - /// - Default = -1, - - /// - /// Standard Arrow cursor - /// - Arrow, - - /// - /// Standard Cross cursor - /// - Cross, - - /// - /// Standard Custom cursor - /// - Custom, - - /// - /// Standard Hand cursor - /// - Hand, - - /// - /// Standard Help cursor - /// - Help, - - /// - /// Standard IBeam cursor - /// - IBeam, - - /// - /// Standard SizeAll cursor - /// - SizeAll, - - /// - /// Standard SizeNortheastSouthwest cursor - /// - SizeNortheastSouthwest, - - /// - /// Standard SizeNorthSouth cursor - /// - SizeNorthSouth, - - /// - /// Standard SizeNorthwestSoutheast cursor - /// - SizeNorthwestSoutheast, - - /// - /// Standard SizeWestEast cursor - /// - SizeWestEast, - - /// - /// Standard UniversalNo cursor - /// - UniversalNo, - - /// - /// Standard UpArrow cursor - /// - UpArrow, - - /// - /// Standard Wait cursor - /// - Wait - } - - /// - /// Enum to indicate the behavior of window cursor on grid splitter hover - /// - public enum SplitterCursorBehavior - { - /// - /// Update window cursor on Grid Splitter hover - /// - ChangeOnSplitterHover, - - /// - /// Update window cursor on Grid Splitter Gripper hover - /// - ChangeOnGripperHover - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.Events.cs b/src/Notepads.Controls/GridSplitter/GridSplitter.Events.cs deleted file mode 100644 index b57cee22c..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.Events.cs +++ /dev/null @@ -1,302 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - using Windows.System; - using Windows.UI.Core; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Input; - using Windows.UI.Xaml.Media; - - /// - /// Represents the control that redistributes space between columns or rows of a Grid control. - /// - public partial class GridSplitter - { - // Symbols for GripperBar in Segoe MDL2 Assets - private const string GripperBarVertical = "\xE784"; - private const string GripperBarHorizontal = "\xE76F"; - private const string GripperDisplayFont = "Segoe MDL2 Assets"; - - private void GridSplitter_Loaded(object sender, RoutedEventArgs e) - { - _resizeDirection = GetResizeDirection(); - _resizeBehavior = GetResizeBehavior(); - - // Adding Grip to Grid Splitter - if (Element == default(UIElement)) - { - CreateGripperDisplay(); - Element = _gripperDisplay; - } - - if (_hoverWrapper == null) - { - var hoverWrapper = new GripperHoverWrapper( - CursorBehavior == SplitterCursorBehavior.ChangeOnSplitterHover - ? this - : Element, - _resizeDirection, - GripperCursor, - GripperCustomCursorResource); - ManipulationStarted += hoverWrapper.SplitterManipulationStarted; - ManipulationCompleted += hoverWrapper.SplitterManipulationCompleted; - - _hoverWrapper = hoverWrapper; - } - } - - private void CreateGripperDisplay() - { - if (_gripperDisplay == null) - { - _gripperDisplay = new TextBlock - { - FontFamily = new FontFamily(GripperDisplayFont), - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Foreground = GripperForeground, - Text = _resizeDirection == GridResizeDirection.Columns ? GripperBarVertical : GripperBarHorizontal - }; - } - } - - /// - protected override void OnKeyDown(KeyRoutedEventArgs e) - { - var step = 1; - var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); - if (ctrl.HasFlag(CoreVirtualKeyStates.Down)) - { - step = 5; - } - - if (_resizeDirection == GridResizeDirection.Columns) - { - if (e.Key == VirtualKey.Left) - { - HorizontalMove(-step); - } - else if (e.Key == VirtualKey.Right) - { - HorizontalMove(step); - } - else - { - return; - } - - e.Handled = true; - return; - } - - if (_resizeDirection == GridResizeDirection.Rows) - { - if (e.Key == VirtualKey.Up) - { - VerticalMove(-step); - } - else if (e.Key == VirtualKey.Down) - { - VerticalMove(step); - } - else - { - return; - } - - e.Handled = true; - } - - base.OnKeyDown(e); - } - - /// - protected override void OnManipulationStarted(ManipulationStartedRoutedEventArgs e) - { - // saving the previous state - PreviousCursor = Window.Current.CoreWindow.PointerCursor; - _resizeDirection = GetResizeDirection(); - _resizeBehavior = GetResizeBehavior(); - - if (_resizeDirection == GridResizeDirection.Columns) - { - Window.Current.CoreWindow.PointerCursor = ColumnsSplitterCursor; - } - else if (_resizeDirection == GridResizeDirection.Rows) - { - Window.Current.CoreWindow.PointerCursor = RowSplitterCursor; - } - - base.OnManipulationStarted(e); - } - - /// - protected override void OnManipulationCompleted(ManipulationCompletedRoutedEventArgs e) - { - Window.Current.CoreWindow.PointerCursor = PreviousCursor; - - base.OnManipulationCompleted(e); - } - - /// - protected override void OnManipulationDelta(ManipulationDeltaRoutedEventArgs e) - { - var horizontalChange = e.Delta.Translation.X; - var verticalChange = e.Delta.Translation.Y; - - if (_resizeDirection == GridResizeDirection.Columns) - { - if (HorizontalMove(horizontalChange)) - { - return; - } - } - else if (_resizeDirection == GridResizeDirection.Rows) - { - if (VerticalMove(verticalChange)) - { - return; - } - } - - base.OnManipulationDelta(e); - } - - private bool VerticalMove(double verticalChange) - { - if (CurrentRow == null || SiblingRow == null) - { - return true; - } - - // if current row has fixed height then resize it - if (!IsStarRow(CurrentRow)) - { - // No need to check for the row Min height because it is automatically respected - if (!SetRowHeight(CurrentRow, verticalChange, GridUnitType.Pixel)) - { - return true; - } - } - - // if sibling row has fixed width then resize it - else if (!IsStarRow(SiblingRow)) - { - // Would adding to this column make the current column violate the MinWidth? - if (IsValidRowHeight(CurrentRow, verticalChange) == false) - { - return false; - } - - if (!SetRowHeight(SiblingRow, verticalChange * -1, GridUnitType.Pixel)) - { - return true; - } - } - - // if both row haven't fixed height (auto *) - else - { - // change current row height to the new height with respecting the auto - // change sibling row height to the new height relative to current row - // respect the other star row height by setting it's height to it's actual height with stars - - // We need to validate current and sibling height to not cause any un expected behavior - if (!IsValidRowHeight(CurrentRow, verticalChange) || - !IsValidRowHeight(SiblingRow, verticalChange * -1)) - { - return true; - } - - foreach (var rowDefinition in Resizable.RowDefinitions) - { - if (rowDefinition == CurrentRow) - { - SetRowHeight(CurrentRow, verticalChange, GridUnitType.Star); - } - else if (rowDefinition == SiblingRow) - { - SetRowHeight(SiblingRow, verticalChange * -1, GridUnitType.Star); - } - else if (IsStarRow(rowDefinition)) - { - rowDefinition.Height = new GridLength(rowDefinition.ActualHeight, GridUnitType.Star); - } - } - } - - return false; - } - - private bool HorizontalMove(double horizontalChange) - { - if (CurrentColumn == null || SiblingColumn == null) - { - return true; - } - - // if current column has fixed width then resize it - if (!IsStarColumn(CurrentColumn)) - { - // No need to check for the Column Min width because it is automatically respected - if (!SetColumnWidth(CurrentColumn, horizontalChange, GridUnitType.Pixel)) - { - return true; - } - } - - // if sibling column has fixed width then resize it - else if (!IsStarColumn(SiblingColumn)) - { - // Would adding to this column make the current column violate the MinWidth? - if (IsValidColumnWidth(CurrentColumn, horizontalChange) == false) - { - return false; - } - - if (!SetColumnWidth(SiblingColumn, horizontalChange * -1, GridUnitType.Pixel)) - { - return true; - } - } - - // if both column haven't fixed width (auto *) - else - { - // change current column width to the new width with respecting the auto - // change sibling column width to the new width relative to current column - // respect the other star column width by setting it's width to it's actual width with stars - - // We need to validate current and sibling width to not cause any un expected behavior - if (!IsValidColumnWidth(CurrentColumn, horizontalChange) || - !IsValidColumnWidth(SiblingColumn, horizontalChange * -1)) - { - return true; - } - - foreach (var columnDefinition in Resizable.ColumnDefinitions) - { - if (columnDefinition == CurrentColumn) - { - SetColumnWidth(CurrentColumn, horizontalChange, GridUnitType.Star); - } - else if (columnDefinition == SiblingColumn) - { - SetColumnWidth(SiblingColumn, horizontalChange * -1, GridUnitType.Star); - } - else if (IsStarColumn(columnDefinition)) - { - columnDefinition.Width = new GridLength(columnDefinition.ActualWidth, GridUnitType.Star); - } - } - } - - return false; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.Helper.cs b/src/Notepads.Controls/GridSplitter/GridSplitter.Helper.cs deleted file mode 100644 index 1c53cf135..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.Helper.cs +++ /dev/null @@ -1,261 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - - /// - /// Represents the control that redistributes space between columns or rows of a Grid control. - /// - public partial class GridSplitter - { - private static bool IsStarColumn(ColumnDefinition definition) - { - return ((GridLength)definition.GetValue(ColumnDefinition.WidthProperty)).IsStar; - } - - private static bool IsStarRow(RowDefinition definition) - { - return ((GridLength)definition.GetValue(RowDefinition.HeightProperty)).IsStar; - } - - private bool SetColumnWidth(ColumnDefinition columnDefinition, double horizontalChange, GridUnitType unitType) - { - var newWidth = columnDefinition.ActualWidth + horizontalChange; - - var minWidth = columnDefinition.MinWidth; - if (!double.IsNaN(minWidth) && newWidth < minWidth) - { - newWidth = minWidth; - } - - var maxWidth = columnDefinition.MaxWidth; - if (!double.IsNaN(maxWidth) && newWidth > maxWidth) - { - newWidth = maxWidth; - } - - if (newWidth > ActualWidth) - { - columnDefinition.Width = new GridLength(newWidth, unitType); - return true; - } - - return false; - } - - private bool IsValidColumnWidth(ColumnDefinition columnDefinition, double horizontalChange) - { - var newWidth = columnDefinition.ActualWidth + horizontalChange; - - var minWidth = columnDefinition.MinWidth; - if (!double.IsNaN(minWidth) && newWidth < minWidth) - { - return false; - } - - var maxWidth = columnDefinition.MaxWidth; - if (!double.IsNaN(maxWidth) && newWidth > maxWidth) - { - return false; - } - - if (newWidth <= ActualWidth) - { - return false; - } - - return true; - } - - private bool SetRowHeight(RowDefinition rowDefinition, double verticalChange, GridUnitType unitType) - { - var newHeight = rowDefinition.ActualHeight + verticalChange; - - var minHeight = rowDefinition.MinHeight; - if (!double.IsNaN(minHeight) && newHeight < minHeight) - { - newHeight = minHeight; - } - - var maxWidth = rowDefinition.MaxHeight; - if (!double.IsNaN(maxWidth) && newHeight > maxWidth) - { - newHeight = maxWidth; - } - - if (newHeight > ActualHeight) - { - rowDefinition.Height = new GridLength(newHeight, unitType); - return true; - } - - return false; - } - - private bool IsValidRowHeight(RowDefinition rowDefinition, double verticalChange) - { - var newHeight = rowDefinition.ActualHeight + verticalChange; - - var minHeight = rowDefinition.MinHeight; - if (!double.IsNaN(minHeight) && newHeight < minHeight) - { - return false; - } - - var maxHeight = rowDefinition.MaxHeight; - if (!double.IsNaN(maxHeight) && newHeight > maxHeight) - { - return false; - } - - if (newHeight <= ActualHeight) - { - return false; - } - - return true; - } - - // Return the targeted Column based on the resize behavior - private int GetTargetedColumn() - { - var currentIndex = Grid.GetColumn(TargetControl); - return GetTargetIndex(currentIndex); - } - - // Return the sibling Row based on the resize behavior - private int GetTargetedRow() - { - var currentIndex = Grid.GetRow(TargetControl); - return GetTargetIndex(currentIndex); - } - - // Return the sibling Column based on the resize behavior - private int GetSiblingColumn() - { - var currentIndex = Grid.GetColumn(TargetControl); - return GetSiblingIndex(currentIndex); - } - - // Return the sibling Row based on the resize behavior - private int GetSiblingRow() - { - var currentIndex = Grid.GetRow(TargetControl); - return GetSiblingIndex(currentIndex); - } - - // Gets index based on resize behavior for first targeted row/column - private int GetTargetIndex(int currentIndex) - { - switch (_resizeBehavior) - { - case GridResizeBehavior.CurrentAndNext: - return currentIndex; - case GridResizeBehavior.PreviousAndNext: - return currentIndex - 1; - case GridResizeBehavior.PreviousAndCurrent: - return currentIndex - 1; - default: - return -1; - } - } - - // Gets index based on resize behavior for second targeted row/column - private int GetSiblingIndex(int currentIndex) - { - switch (_resizeBehavior) - { - case GridResizeBehavior.CurrentAndNext: - return currentIndex + 1; - case GridResizeBehavior.PreviousAndNext: - return currentIndex + 1; - case GridResizeBehavior.PreviousAndCurrent: - return currentIndex; - default: - return -1; - } - } - - // Checks the control alignment and Width/Height to detect the control resize direction columns/rows - private GridResizeDirection GetResizeDirection() - { - GridResizeDirection direction = ResizeDirection; - - if (direction == GridResizeDirection.Auto) - { - // When HorizontalAlignment is Left, Right or Center, resize Columns - if (HorizontalAlignment != HorizontalAlignment.Stretch) - { - direction = GridResizeDirection.Columns; - } - - // When VerticalAlignment is Top, Bottom or Center, resize Rows - else if (VerticalAlignment != VerticalAlignment.Stretch) - { - direction = GridResizeDirection.Rows; - } - - // Check Width vs Height - else if (ActualWidth <= ActualHeight) - { - direction = GridResizeDirection.Columns; - } - else - { - direction = GridResizeDirection.Rows; - } - } - - return direction; - } - - // Get the resize behavior (Which columns/rows should be resized) based on alignment and Direction - private GridResizeBehavior GetResizeBehavior() - { - GridResizeBehavior resizeBehavior = ResizeBehavior; - - if (resizeBehavior == GridResizeBehavior.BasedOnAlignment) - { - if (_resizeDirection == GridResizeDirection.Columns) - { - switch (HorizontalAlignment) - { - case HorizontalAlignment.Left: - resizeBehavior = GridResizeBehavior.PreviousAndCurrent; - break; - case HorizontalAlignment.Right: - resizeBehavior = GridResizeBehavior.CurrentAndNext; - break; - default: - resizeBehavior = GridResizeBehavior.PreviousAndNext; - break; - } - } - - // resize direction is vertical - else - { - switch (VerticalAlignment) - { - case VerticalAlignment.Top: - resizeBehavior = GridResizeBehavior.PreviousAndCurrent; - break; - case VerticalAlignment.Bottom: - resizeBehavior = GridResizeBehavior.CurrentAndNext; - break; - default: - resizeBehavior = GridResizeBehavior.PreviousAndNext; - break; - } - } - } - - return resizeBehavior; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.Options.cs b/src/Notepads.Controls/GridSplitter/GridSplitter.Options.cs deleted file mode 100644 index aab678ba4..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.Options.cs +++ /dev/null @@ -1,225 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - using Windows.UI.Core; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Media; - - /// - /// Represents the control that redistributes space between columns or rows of a Grid control. - /// - public partial class GridSplitter - { - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ElementProperty - = DependencyProperty.Register( - nameof(Element), - typeof(UIElement), - typeof(GridSplitter), - new PropertyMetadata(default(UIElement), OnElementPropertyChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ResizeDirectionProperty - = DependencyProperty.Register( - nameof(ResizeDirection), - typeof(GridResizeDirection), - typeof(GridSplitter), - new PropertyMetadata(GridResizeDirection.Auto)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ResizeBehaviorProperty - = DependencyProperty.Register( - nameof(ResizeBehavior), - typeof(GridResizeBehavior), - typeof(GridSplitter), - new PropertyMetadata(GridResizeBehavior.BasedOnAlignment)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty GripperForegroundProperty - = DependencyProperty.Register( - nameof(GripperForeground), - typeof(Brush), - typeof(GridSplitter), - new PropertyMetadata(default(Brush), OnGripperForegroundPropertyChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ParentLevelProperty - = DependencyProperty.Register( - nameof(ParentLevel), - typeof(int), - typeof(GridSplitter), - new PropertyMetadata(default(int))); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty GripperCursorProperty = - DependencyProperty.RegisterAttached( - nameof(GripperCursor), - typeof(CoreCursorType?), - typeof(GridSplitter), - new PropertyMetadata(GripperCursorType.Default, OnGripperCursorPropertyChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty GripperCustomCursorResourceProperty = - DependencyProperty.RegisterAttached( - nameof(GripperCustomCursorResource), - typeof(uint), - typeof(GridSplitter), - new PropertyMetadata(GripperCustomCursorDefaultResource, GripperCustomCursorResourcePropertyChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty CursorBehaviorProperty = - DependencyProperty.RegisterAttached( - nameof(CursorBehavior), - typeof(SplitterCursorBehavior), - typeof(GridSplitter), - new PropertyMetadata(SplitterCursorBehavior.ChangeOnSplitterHover, CursorBehaviorPropertyChanged)); - - /// - /// Gets or sets the visual content of this Grid Splitter - /// - public UIElement Element - { - get => (UIElement)GetValue(ElementProperty); - set => SetValue(ElementProperty, value); - } - - /// - /// Gets or sets whether the Splitter resizes the Columns, Rows, or Both. - /// - public GridResizeDirection ResizeDirection - { - get => (GridResizeDirection)GetValue(ResizeDirectionProperty); - set => SetValue(ResizeDirectionProperty, value); - } - - /// - /// Gets or sets which Columns or Rows the Splitter resizes. - /// - public GridResizeBehavior ResizeBehavior - { - get => (GridResizeBehavior)GetValue(ResizeBehaviorProperty); - set => SetValue(ResizeBehaviorProperty, value); - } - - /// - /// Gets or sets the foreground color of grid splitter grip - /// - public Brush GripperForeground - { - get => (Brush)GetValue(GripperForegroundProperty); - set => SetValue(GripperForegroundProperty, value); - } - - /// - /// Gets or sets the level of the parent grid to resize - /// - public int ParentLevel - { - get => (int)GetValue(ParentLevelProperty); - set => SetValue(ParentLevelProperty, value); - } - - /// - /// Gets or sets the gripper Cursor type - /// - public GripperCursorType GripperCursor - { - get => (GripperCursorType)GetValue(GripperCursorProperty); - set => SetValue(GripperCursorProperty, value); - } - - /// - /// Gets or sets the gripper Custom Cursor resource number - /// - public int GripperCustomCursorResource - { - get => (int)GetValue(GripperCustomCursorResourceProperty); - set => SetValue(GripperCustomCursorResourceProperty, value); - } - - /// - /// Gets or sets splitter cursor on hover behavior - /// - public SplitterCursorBehavior CursorBehavior - { - get => (SplitterCursorBehavior)GetValue(CursorBehaviorProperty); - set => SetValue(CursorBehaviorProperty, value); - } - - private static void OnGripperForegroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var gridSplitter = (GridSplitter)d; - - if (gridSplitter._gripperDisplay == null) - { - return; - } - - gridSplitter._gripperDisplay.Foreground = gridSplitter.GripperForeground; - } - - private static void OnGripperCursorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var gridSplitter = (GridSplitter)d; - - if (gridSplitter._hoverWrapper == null) - { - return; - } - - gridSplitter._hoverWrapper.GripperCursor = gridSplitter.GripperCursor; - } - - private static void GripperCustomCursorResourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var gridSplitter = (GridSplitter)d; - - if (gridSplitter._hoverWrapper == null) - { - return; - } - - gridSplitter._hoverWrapper.GripperCustomCursorResource = gridSplitter.GripperCustomCursorResource; - } - - private static void CursorBehaviorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var gridSplitter = (GridSplitter)d; - - gridSplitter._hoverWrapper?.UpdateHoverElement(gridSplitter.CursorBehavior == - SplitterCursorBehavior.ChangeOnSplitterHover - ? gridSplitter - : gridSplitter.Element); - } - - private static void OnElementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var gridSplitter = (GridSplitter)d; - - gridSplitter._hoverWrapper?.UpdateHoverElement(gridSplitter.CursorBehavior == - SplitterCursorBehavior.ChangeOnSplitterHover - ? gridSplitter - : gridSplitter.Element); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.cs b/src/Notepads.Controls/GridSplitter/GridSplitter.cs deleted file mode 100644 index e65946dc2..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.cs +++ /dev/null @@ -1,246 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - using Windows.UI.Core; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Automation; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Input; - - /// - /// Represents the control that redistributes space between columns or rows of a Grid control. - /// - public partial class GridSplitter : Control - { - internal const int GripperCustomCursorDefaultResource = -1; - internal static readonly CoreCursor ColumnsSplitterCursor = new CoreCursor(CoreCursorType.SizeWestEast, 1); - internal static readonly CoreCursor RowSplitterCursor = new CoreCursor(CoreCursorType.SizeNorthSouth, 1); - - internal CoreCursor PreviousCursor { get; set; } - - private GridResizeDirection _resizeDirection; - private GridResizeBehavior _resizeBehavior; - private GripperHoverWrapper _hoverWrapper; - private TextBlock _gripperDisplay; - - private bool _pressed = false; - private bool _dragging = false; - private bool _pointerEntered = false; - - /// - /// Gets the target parent grid from level - /// - private FrameworkElement TargetControl - { - get - { - if (ParentLevel == 0) - { - return this; - } - - var parent = Parent; - for (int i = 2; i < ParentLevel; i++) - { - if (parent is FrameworkElement frameworkElement) - { - parent = frameworkElement.Parent; - } - } - - return parent as FrameworkElement; - } - } - - /// - /// Gets GridSplitter Container Grid - /// - private Grid Resizable => TargetControl?.Parent as Grid; - - /// - /// Gets the current Column definition of the parent Grid - /// - private ColumnDefinition CurrentColumn - { - get - { - if (Resizable == null) - { - return null; - } - - var gridSplitterTargetedColumnIndex = GetTargetedColumn(); - - if ((gridSplitterTargetedColumnIndex >= 0) - && (gridSplitterTargetedColumnIndex < Resizable.ColumnDefinitions.Count)) - { - return Resizable.ColumnDefinitions[gridSplitterTargetedColumnIndex]; - } - - return null; - } - } - - /// - /// Gets the Sibling Column definition of the parent Grid - /// - private ColumnDefinition SiblingColumn - { - get - { - if (Resizable == null) - { - return null; - } - - var gridSplitterSiblingColumnIndex = GetSiblingColumn(); - - if ((gridSplitterSiblingColumnIndex >= 0) - && (gridSplitterSiblingColumnIndex < Resizable.ColumnDefinitions.Count)) - { - return Resizable.ColumnDefinitions[gridSplitterSiblingColumnIndex]; - } - - return null; - } - } - - /// - /// Gets the current Row definition of the parent Grid - /// - private RowDefinition CurrentRow - { - get - { - if (Resizable == null) - { - return null; - } - - var gridSplitterTargetedRowIndex = GetTargetedRow(); - - if ((gridSplitterTargetedRowIndex >= 0) - && (gridSplitterTargetedRowIndex < Resizable.RowDefinitions.Count)) - { - return Resizable.RowDefinitions[gridSplitterTargetedRowIndex]; - } - - return null; - } - } - - /// - /// Gets the Sibling Row definition of the parent Grid - /// - private RowDefinition SiblingRow - { - get - { - if (Resizable == null) - { - return null; - } - - var gridSplitterSiblingRowIndex = GetSiblingRow(); - - if ((gridSplitterSiblingRowIndex >= 0) - && (gridSplitterSiblingRowIndex < Resizable.RowDefinitions.Count)) - { - return Resizable.RowDefinitions[gridSplitterSiblingRowIndex]; - } - - return null; - } - } - - /// - /// Initializes a new instance of the class. - /// - public GridSplitter() - { - DefaultStyleKey = typeof(GridSplitter); - Loaded += GridSplitter_Loaded; - string automationName = "GridSpliter"; - AutomationProperties.SetName(this, automationName); - } - - /// - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - // Unhook registered events - Loaded -= GridSplitter_Loaded; - PointerEntered -= GridSplitter_PointerEntered; - PointerExited -= GridSplitter_PointerExited; - PointerPressed -= GridSplitter_PointerPressed; - PointerReleased -= GridSplitter_PointerReleased; - ManipulationStarted -= GridSplitter_ManipulationStarted; - ManipulationCompleted -= GridSplitter_ManipulationCompleted; - - _hoverWrapper?.UnhookEvents(); - - // Register Events - Loaded += GridSplitter_Loaded; - PointerEntered += GridSplitter_PointerEntered; - PointerExited += GridSplitter_PointerExited; - PointerPressed += GridSplitter_PointerPressed; - PointerReleased += GridSplitter_PointerReleased; - ManipulationStarted += GridSplitter_ManipulationStarted; - ManipulationCompleted += GridSplitter_ManipulationCompleted; - - _hoverWrapper?.UpdateHoverElement(Element); - - ManipulationMode = ManipulationModes.TranslateX | ManipulationModes.TranslateY; - } - - private void GridSplitter_PointerReleased(object sender, PointerRoutedEventArgs e) - { - _pressed = false; - VisualStateManager.GoToState(this, _pointerEntered ? "PointerOver" : "Normal", true); - } - - private void GridSplitter_PointerPressed(object sender, PointerRoutedEventArgs e) - { - _pressed = true; - VisualStateManager.GoToState(this, "Pressed", true); - } - - private void GridSplitter_PointerExited(object sender, PointerRoutedEventArgs e) - { - _pointerEntered = false; - - if (!_pressed && !_dragging) - { - VisualStateManager.GoToState(this, "Normal", true); - } - } - - private void GridSplitter_PointerEntered(object sender, PointerRoutedEventArgs e) - { - _pointerEntered = true; - - if (!_pressed && !_dragging) - { - VisualStateManager.GoToState(this, "PointerOver", true); - } - } - - private void GridSplitter_ManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) - { - _dragging = false; - _pressed = false; - VisualStateManager.GoToState(this, _pointerEntered ? "PointerOver" : "Normal", true); - } - - private void GridSplitter_ManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) - { - _dragging = true; - VisualStateManager.GoToState(this, "Pressed", true); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/GridSplitter/GridSplitter.xaml b/src/Notepads.Controls/GridSplitter/GridSplitter.xaml deleted file mode 100644 index 02242fe7d..000000000 --- a/src/Notepads.Controls/GridSplitter/GridSplitter.xaml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/src/Notepads.Controls/GridSplitter/GripperHoverWrapper.cs b/src/Notepads.Controls/GridSplitter/GripperHoverWrapper.cs deleted file mode 100644 index d806e268a..000000000 --- a/src/Notepads.Controls/GridSplitter/GripperHoverWrapper.cs +++ /dev/null @@ -1,154 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/GridSplitter - -namespace Notepads.Controls -{ - using Windows.UI.Core; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Input; - - internal class GripperHoverWrapper - { - private readonly GridSplitter.GridResizeDirection _gridSplitterDirection; - - private CoreCursor _splitterPreviousPointer; - private CoreCursor _previousCursor; - private GridSplitter.GripperCursorType _gripperCursor; - private int _gripperCustomCursorResource; - private bool _isDragging; - private UIElement _element; - - internal GridSplitter.GripperCursorType GripperCursor - { - get => _gripperCursor; - set => _gripperCursor = value; - } - - internal int GripperCustomCursorResource - { - get => _gripperCustomCursorResource; - set => _gripperCustomCursorResource = value; - } - - /// - /// Initializes a new instance of the class that add cursor change on hover functionality for GridSplitter. - /// - /// UI element to apply cursor change on hover - /// GridSplitter resize direction - /// GridSplitter gripper on hover cursor type - /// GridSplitter gripper custom cursor resource number - internal GripperHoverWrapper(UIElement element, GridSplitter.GridResizeDirection gridSplitterDirection, GridSplitter.GripperCursorType gripperCursor, int gripperCustomCursorResource) - { - _gridSplitterDirection = gridSplitterDirection; - _gripperCursor = gripperCursor; - _gripperCustomCursorResource = gripperCustomCursorResource; - _element = element; - UnhookEvents(); - _element.PointerEntered += Element_PointerEntered; - _element.PointerExited += Element_PointerExited; - } - - internal void UpdateHoverElement(UIElement element) - { - UnhookEvents(); - _element = element; - _element.PointerEntered += Element_PointerEntered; - _element.PointerExited += Element_PointerExited; - } - - private void Element_PointerExited(object sender, PointerRoutedEventArgs e) - { - if (_isDragging) - { - // if dragging don't update the curser just update the splitter cursor with the last window cursor, - // because the splitter is still using the arrow cursor and will revert to original case when drag completes - _splitterPreviousPointer = _previousCursor; - } - else - { - Window.Current.CoreWindow.PointerCursor = _previousCursor; - } - } - - private void Element_PointerEntered(object sender, PointerRoutedEventArgs e) - { - // if not dragging - if (!_isDragging) - { - _previousCursor = _splitterPreviousPointer = Window.Current.CoreWindow.PointerCursor; - UpdateDisplayCursor(); - } - - // if dragging - else - { - _previousCursor = _splitterPreviousPointer; - } - } - - private void UpdateDisplayCursor() - { - if (_gripperCursor == GridSplitter.GripperCursorType.Default) - { - if (_gridSplitterDirection == GridSplitter.GridResizeDirection.Columns) - { - Window.Current.CoreWindow.PointerCursor = GridSplitter.ColumnsSplitterCursor; - } - else if (_gridSplitterDirection == GridSplitter.GridResizeDirection.Rows) - { - Window.Current.CoreWindow.PointerCursor = GridSplitter.RowSplitterCursor; - } - } - else - { - var coreCursor = (CoreCursorType)((int)_gripperCursor); - if (_gripperCursor == GridSplitter.GripperCursorType.Custom) - { - if (_gripperCustomCursorResource > GridSplitter.GripperCustomCursorDefaultResource) - { - Window.Current.CoreWindow.PointerCursor = new CoreCursor(coreCursor, (uint)_gripperCustomCursorResource); - } - } - else - { - Window.Current.CoreWindow.PointerCursor = new CoreCursor(coreCursor, 1); - } - } - } - - internal void SplitterManipulationStarted(object sender, ManipulationStartedRoutedEventArgs e) - { - if (!(sender is GridSplitter splitter)) - { - return; - } - - _splitterPreviousPointer = splitter.PreviousCursor; - _isDragging = true; - } - - internal void SplitterManipulationCompleted(object sender, ManipulationCompletedRoutedEventArgs e) - { - if (!(sender is GridSplitter splitter)) - { - return; - } - - Window.Current.CoreWindow.PointerCursor = splitter.PreviousCursor = _splitterPreviousPointer; - _isDragging = false; - } - - internal void UnhookEvents() - { - if (_element == null) - { - return; - } - - _element.PointerEntered -= Element_PointerEntered; - _element.PointerExited -= Element_PointerExited; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/Helpers/DispatcherQueueHelper.cs b/src/Notepads.Controls/Helpers/DispatcherQueueHelper.cs deleted file mode 100644 index 5eb2f3478..000000000 --- a/src/Notepads.Controls/Helpers/DispatcherQueueHelper.cs +++ /dev/null @@ -1,250 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/8464f8e5263686c1484732bdea86ebba3f30a075/Microsoft.Toolkit.Uwp/Helpers/DispatcherQueueHelper.cs - -namespace Notepads.Controls.Helpers -{ - using System; - using System.Threading.Tasks; - using Windows.System; - - /// - /// This class provides static methods helper for executing code in a DispatcherQueue. - /// - public static class DispatcherQueueHelper - { - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// DispatcherQueue of a thread to run . - /// Function to be executed on the given dispatcher. - /// DispatcherQueue execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Action function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - /* Run the function directly when we have thread access. - * Also reuse Task.CompletedTask in case of success, - * to skip an unnecessary heap allocation for every invocation. */ - - // Ignoring for now, but need to map the CurrentThreadID for all dispatcher queue code we have - /* - if (dispatcher.HasThreadAccess) - { - try - { - function(); - - return Task.CompletedTask; - } - catch (Exception e) - { - return Task.FromException(e); - } - } - */ - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher?.TryEnqueue(priority, () => - { - try - { - function(); - - taskCompletionSource.SetResult(null); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Returned data type of the function. - /// DispatcherQueue of a thread to run . - /// Function to be executed on the given dispatcher. - /// DispatcherQueue execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Func function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - // Skip the dispatch, if possible - // Ignoring for now, but need to map the CurrentThreadID for all dispatcher queue code we have - /* - if (dispatcher.HasThreadAccess) - { - try - { - return Task.FromResult(function()); - } - catch (Exception e) - { - return Task.FromException(e); - } - } - */ - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher?.TryEnqueue(priority, () => - { - try - { - taskCompletionSource.SetResult(function()); - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// DispatcherQueue of a thread to run . - /// Asynchronous function to be executed on the given dispatcher. - /// DispatcherQueue execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Func function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - /* If we have thread access, we can retrieve the task directly. - * We don't use ConfigureAwait(false) in this case, in order - * to let the caller continue its execution on the same thread - * after awaiting the task returned by this function. */ - - // Ignoring for now, but need to map the CurrentThreadID for all dispatcher queue code we have - /* - if (dispatcher.HasThreadAccess) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } - - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - catch (Exception e) - { - return Task.FromException(e); - } - } - */ - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher?.TryEnqueue(priority, async () => - { - try - { - if (function() is Task awaitableResult) - { - await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(null); - } - else - { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }); - - return taskCompletionSource.Task; - } - - /// - /// Extension method for . Offering an actual awaitable with optional result that will be executed on the given dispatcher. - /// - /// Returned data type of the function. - /// DispatcherQueue of a thread to run . - /// Asynchronous function to be executed asynchronously on the given dispatcher. - /// DispatcherQueue execution priority, default is normal. - /// An awaitable for the operation. - /// If the current thread has UI access, will be invoked directly. - public static Task ExecuteOnUIThreadAsync(this DispatcherQueue dispatcher, Func> function, DispatcherQueuePriority priority = DispatcherQueuePriority.Normal) - { - if (function is null) - { - throw new ArgumentNullException(nameof(function)); - } - - // Skip the dispatch, if possible - // Ignoring for now, but need to map the CurrentThreadID for all dispatcher queue code we have - /* - if (dispatcher.HasThreadAccess) - { - try - { - if (function() is Task awaitableResult) - { - return awaitableResult; - } - - return Task.FromException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - catch (Exception e) - { - return Task.FromException(e); - } - } - */ - - var taskCompletionSource = new TaskCompletionSource(); - - _ = dispatcher?.TryEnqueue(priority, async () => - { - try - { - if (function() is Task awaitableResult) - { - var result = await awaitableResult.ConfigureAwait(false); - - taskCompletionSource.SetResult(result); - } - else - { - taskCompletionSource.SetException(new InvalidOperationException("The Task returned by function cannot be null.")); - } - } - catch (Exception e) - { - taskCompletionSource.SetException(e); - } - }); - - return taskCompletionSource.Task; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/Helpers/ThemeListener.cs b/src/Notepads.Controls/Helpers/ThemeListener.cs deleted file mode 100644 index c05b5c0ce..000000000 --- a/src/Notepads.Controls/Helpers/ThemeListener.cs +++ /dev/null @@ -1,144 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/8464f8e5263686c1484732bdea86ebba3f30a075/Microsoft.Toolkit.Uwp.UI/Helpers/ThemeListener.cs - -namespace Notepads.Controls.Helpers -{ - using System; - using System.Threading.Tasks; - using Windows.Foundation.Metadata; - using Windows.System; - using Windows.UI.ViewManagement; - using Windows.UI.Xaml; - - /// - /// The Delegate for a ThemeChanged Event. - /// - /// Sender ThemeListener - public delegate void ThemeChangedEvent(ThemeListener sender); - - /// - /// Class which listens for changes to Application Theme or High Contrast Modes - /// and Signals an Event when they occur. - /// - [AllowForWeb] - public sealed class ThemeListener : IDisposable - { - /// - /// Gets the Name of the Current Theme. - /// - public string CurrentThemeName => CurrentTheme.ToString(); - - /// - /// Gets or sets the Current Theme. - /// - public ApplicationTheme CurrentTheme { get; set; } - - /// - /// Gets or sets a value indicating whether the current theme is high contrast. - /// - public bool IsHighContrast { get; set; } - - /// - /// Gets or sets which DispatcherQueue is used to dispatch UI updates. - /// - public DispatcherQueue DispatcherQueue { get; set; } - - /// - /// An event that fires if the Theme changes. - /// - public event ThemeChangedEvent ThemeChanged; - - private readonly AccessibilitySettings _accessible = new AccessibilitySettings(); - private readonly UISettings _settings = new UISettings(); - - /// - /// Initializes a new instance of the class. - /// - /// The DispatcherQueue that should be used to dispatch UI updates, or null if this is being called from the UI thread. - public ThemeListener(DispatcherQueue dispatcherQueue = null) - { - CurrentTheme = Application.Current.RequestedTheme; - IsHighContrast = _accessible.HighContrast; - - DispatcherQueue = dispatcherQueue ?? DispatcherQueue.GetForCurrentThread(); - - _accessible.HighContrastChanged += Accessible_HighContrastChanged; - _settings.ColorValuesChanged += Settings_ColorValuesChanged; - - // Fallback in case either of the above fail, we'll check when we get activated next. - if (Window.Current != null) - { - Window.Current.CoreWindow.Activated += CoreWindow_Activated; - } - } - - private async void Accessible_HighContrastChanged(AccessibilitySettings sender, object args) - { - await DispatcherQueue.ExecuteOnUIThreadAsync(UpdateProperties, DispatcherQueuePriority.Normal); - } - - // Note: This can get called multiple times during HighContrast switch, do we care? - private async void Settings_ColorValuesChanged(UISettings sender, object args) - { - await OnColorValuesChanged(); - } - - internal Task OnColorValuesChanged() - { - // Getting called off thread, so we need to dispatch to request value. - return DispatcherQueue.ExecuteOnUIThreadAsync( - () => - { - // TODO: This doesn't stop the multiple calls if we're in our faked 'White' HighContrast Mode below. - if (CurrentTheme != Application.Current.RequestedTheme || - IsHighContrast != _accessible.HighContrast) - { - UpdateProperties(); - } - }, DispatcherQueuePriority.Normal); - } - - private void CoreWindow_Activated(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowActivatedEventArgs args) - { - if (CurrentTheme != Application.Current.RequestedTheme || - IsHighContrast != _accessible.HighContrast) - { - UpdateProperties(); - } - } - - /// - /// Set our current properties and fire a change notification. - /// - private void UpdateProperties() - { - // TODO: Not sure if HighContrastScheme names are localized? - if (_accessible.HighContrast && _accessible.HighContrastScheme.IndexOf("white", StringComparison.OrdinalIgnoreCase) != -1) - { - IsHighContrast = false; - CurrentTheme = ApplicationTheme.Light; - } - else - { - // Otherwise, we just set to what's in the system as we'd expect. - IsHighContrast = _accessible.HighContrast; - CurrentTheme = Application.Current.RequestedTheme; - } - - ThemeChanged?.Invoke(this); - } - - /// - public void Dispose() - { - _accessible.HighContrastChanged -= Accessible_HighContrastChanged; - _settings.ColorValuesChanged -= Settings_ColorValuesChanged; - if (Window.Current != null) - { - Window.Current.CoreWindow.Activated -= CoreWindow_Activated; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.AttachedProperties.cs b/src/Notepads.Controls/InAppNotification/InAppNotification.AttachedProperties.cs deleted file mode 100644 index c8effb5a7..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.AttachedProperties.cs +++ /dev/null @@ -1,58 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Media.Animation; - - /// - /// In App Notification defines a control to show local notification in the app. - /// - public partial class InAppNotification - { - /// - /// Gets the value of the KeyFrameDuration attached Property - /// - /// the KeyFrame where the duration is set - /// Value of KeyFrameDuration - public static TimeSpan GetKeyFrameDuration(DependencyObject obj) - { - return (TimeSpan)obj.GetValue(KeyFrameDurationProperty); - } - - /// - /// Sets the value of the KeyFrameDuration attached property - /// - /// The KeyFrame object where the property is attached - /// The TimeSpan value to be set as duration - public static void SetKeyFrameDuration(DependencyObject obj, TimeSpan value) - { - obj.SetValue(KeyFrameDurationProperty, value); - } - - /// - /// Using a DependencyProperty as the backing store for KeyFrameDuration. This enables animation, styling, binding, etc - /// - public static readonly DependencyProperty KeyFrameDurationProperty = - DependencyProperty.RegisterAttached("KeyFrameDuration", typeof(TimeSpan), typeof(InAppNotification), new PropertyMetadata(0, OnKeyFrameAnimationChanged)); - - private static void OnKeyFrameAnimationChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - if (e.NewValue is TimeSpan ts) - { - if (d is DoubleKeyFrame dkf) - { - dkf.KeyTime = KeyTime.FromTimeSpan(ts); - } - else if (d is ObjectKeyFrame okf) - { - okf.KeyTime = KeyTime.FromTimeSpan(ts); - } - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.Constants.cs b/src/Notepads.Controls/InAppNotification/InAppNotification.Constants.cs deleted file mode 100644 index d1e4dd986..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.Constants.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - /// - /// In App Notification defines a control to show local notification in the app. - /// - public partial class InAppNotification - { - /// - /// Key of the VisualStateGroup that show/dismiss content - /// - private const string GroupContent = "State"; - - /// - /// Key of the VisualState when content is showed - /// - private const string StateContentVisible = "Visible"; - - /// - /// Key of the VisualState when content is dismissed - /// - private const string StateContentCollapsed = "Collapsed"; - - /// - /// Key of the UI Element that dismiss the control - /// - private const string DismissButtonPart = "PART_DismissButton"; - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.Events.cs b/src/Notepads.Controls/InAppNotification/InAppNotification.Events.cs deleted file mode 100644 index ae6cbfae7..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.Events.cs +++ /dev/null @@ -1,87 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Automation; - using Windows.UI.Xaml.Automation.Peers; - - /// - /// In App Notification defines a control to show local notification in the app. - /// - public partial class InAppNotification - { - /// - /// Event raised when the notification is opening - /// - public event InAppNotificationOpeningEventHandler Opening; - - /// - /// Event raised when the notification is opened - /// - public event EventHandler Opened; - - /// - /// Event raised when the notification is closing - /// - public event InAppNotificationClosingEventHandler Closing; - - /// - /// Event raised when the notification is closed - /// - public event InAppNotificationClosedEventHandler Closed; - - private AutomationPeer peer; - - private void DismissButton_Click(object sender, RoutedEventArgs e) - { - Dismiss(InAppNotificationDismissKind.User); - } - - private void DismissTimer_Tick(object sender, object e) - { - Dismiss(InAppNotificationDismissKind.Timeout); - } - - private void OpenAnimationTimer_Tick(object sender, object e) - { - lock (_openAnimationTimer) - { - _openAnimationTimer.Stop(); - Opened?.Invoke(this, EventArgs.Empty); - SetValue(AutomationProperties.NameProperty, "Notification"); - peer = FrameworkElementAutomationPeer.CreatePeerForElement(ContentTemplateRoot); - if (Content?.GetType() == typeof(string)) - { - AutomateTextNotification(Content.ToString()); - } - } - } - - private void AutomateTextNotification(string message) - { - if (peer != null) - { - peer.SetFocus(); - peer.RaiseNotificationEvent( - AutomationNotificationKind.Other, - AutomationNotificationProcessing.ImportantMostRecent, - "New notification" + message, - Guid.NewGuid().ToString()); - } - } - - private void ClosingAnimationTimer_Tick(object sender, object e) - { - lock (_closingAnimationTimer) - { - _closingAnimationTimer.Stop(); - Closed?.Invoke(this, new InAppNotificationClosedEventArgs(_lastDismissKind)); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.Properties.cs b/src/Notepads.Controls/InAppNotification/InAppNotification.Properties.cs deleted file mode 100644 index 3f7431a1b..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.Properties.cs +++ /dev/null @@ -1,102 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - using Windows.UI.Xaml; - - /// - /// In App Notification defines a control to show local notification in the app. - /// - public partial class InAppNotification - { - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty ShowDismissButtonProperty = - DependencyProperty.Register(nameof(ShowDismissButton), typeof(bool), typeof(InAppNotification), new PropertyMetadata(true, OnShowDismissButtonChanged)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty AnimationDurationProperty = - DependencyProperty.Register(nameof(AnimationDuration), typeof(TimeSpan), typeof(InAppNotification), new PropertyMetadata(TimeSpan.FromMilliseconds(100))); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty VerticalOffsetProperty = - DependencyProperty.Register(nameof(VerticalOffset), typeof(double), typeof(InAppNotification), new PropertyMetadata(100)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty HorizontalOffsetProperty = - DependencyProperty.Register(nameof(HorizontalOffset), typeof(double), typeof(InAppNotification), new PropertyMetadata(0)); - - /// - /// Identifies the dependency property. - /// - public static readonly DependencyProperty StackModeProperty = - DependencyProperty.Register(nameof(StackMode), typeof(StackMode), typeof(InAppNotification), new PropertyMetadata(StackMode.Replace)); - - /// - /// Gets or sets a value indicating whether to show the Dismiss button of the control. - /// - public bool ShowDismissButton - { - get => (bool)GetValue(ShowDismissButtonProperty); - set => SetValue(ShowDismissButtonProperty, value); - } - - /// - /// Gets or sets a value indicating the duration of the popup animation (in milliseconds). - /// - public TimeSpan AnimationDuration - { - get => (TimeSpan)GetValue(AnimationDurationProperty); - set => SetValue(AnimationDurationProperty, value); - } - - /// - /// Gets or sets a value indicating the vertical offset of the popup animation. - /// - public double VerticalOffset - { - get => (double)GetValue(VerticalOffsetProperty); - set => SetValue(VerticalOffsetProperty, value); - } - - /// - /// Gets or sets a value indicating the horizontal offset of the popup animation. - /// - public double HorizontalOffset - { - get => (double)GetValue(HorizontalOffsetProperty); - set => SetValue(HorizontalOffsetProperty, value); - } - - /// - /// Gets or sets a value indicating the stack mode of the notifications. - /// - public StackMode StackMode - { - get => (StackMode)GetValue(StackModeProperty); - set => SetValue(StackModeProperty, value); - } - - private static void OnShowDismissButtonChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var inApNotification = d as InAppNotification; - - if (inApNotification._dismissButton != null) - { - bool showDismissButton = (bool)e.NewValue; - inApNotification._dismissButton.Visibility = showDismissButton ? Visibility.Visible : Visibility.Collapsed; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.cs b/src/Notepads.Controls/InAppNotification/InAppNotification.cs deleted file mode 100644 index 667b4651a..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.cs +++ /dev/null @@ -1,274 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - - /// - /// In App Notification defines a control to show local notification in the app. - /// - [TemplateVisualState(Name = StateContentVisible, GroupName = GroupContent)] - [TemplateVisualState(Name = StateContentCollapsed, GroupName = GroupContent)] - [TemplatePart(Name = DismissButtonPart, Type = typeof(Button))] - public partial class InAppNotification : ContentControl - { - private InAppNotificationDismissKind _lastDismissKind; - private readonly DispatcherTimer _openAnimationTimer = new DispatcherTimer(); - private readonly DispatcherTimer _closingAnimationTimer = new DispatcherTimer(); - private readonly DispatcherTimer _dismissTimer = new DispatcherTimer(); - private Button _dismissButton; - //private VisualStateGroup _visualStateGroup; - private readonly List _stackedNotificationOptions = new List(); - - /// - /// Initializes a new instance of the class. - /// - public InAppNotification() - { - DefaultStyleKey = typeof(InAppNotification); - - _dismissTimer.Tick += DismissTimer_Tick; - _openAnimationTimer.Tick += OpenAnimationTimer_Tick; - _closingAnimationTimer.Tick += ClosingAnimationTimer_Tick; - } - - /// - protected override void OnApplyTemplate() - { - if (_dismissButton != null) - { - _dismissButton.Click -= DismissButton_Click; - } - - _dismissButton = (Button)GetTemplateChild(DismissButtonPart); - //_visualStateGroup = (VisualStateGroup)GetTemplateChild(GroupContent); - - if (_dismissButton != null) - { - _dismissButton.Visibility = ShowDismissButton ? Visibility.Visible : Visibility.Collapsed; - _dismissButton.Click += DismissButton_Click; - } - - if (Visibility == Visibility.Visible) - { - VisualStateManager.GoToState(this, StateContentVisible, true); - } - else - { - VisualStateManager.GoToState(this, StateContentCollapsed, true); - } - - base.OnApplyTemplate(); - } - - /// - /// Show notification using the current template - /// - /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) - public void Show(int duration = 0) - { - lock (_openAnimationTimer) - lock (_closingAnimationTimer) - lock (_dismissTimer) - { - _openAnimationTimer.Stop(); - _closingAnimationTimer.Stop(); - _dismissTimer.Stop(); - - var eventArgs = new InAppNotificationOpeningEventArgs(); - Opening?.Invoke(this, eventArgs); - - if (eventArgs.Cancel) - { - return; - } - - Visibility = Visibility.Visible; - VisualStateManager.GoToState(this, StateContentVisible, true); - - _openAnimationTimer.Interval = AnimationDuration; - _openAnimationTimer.Start(); - - if (duration > 0) - { - _dismissTimer.Interval = TimeSpan.FromMilliseconds(duration); - _dismissTimer.Start(); - } - } - } - - /// - /// Show notification using text as the content of the notification - /// - /// Text used as the content of the notification - /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) - public void Show(string text, int duration = 0) - { - var notificationOptions = new NotificationOptions - { - Duration = duration, - Content = text - }; - Show(notificationOptions); - } - - /// - /// Show notification using UIElement as the content of the notification - /// - /// UIElement used as the content of the notification - /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) - public void Show(UIElement element, int duration = 0) - { - var notificationOptions = new NotificationOptions - { - Duration = duration, - Content = element - }; - Show(notificationOptions); - } - - /// - /// Show notification using DataTemplate as the content of the notification - /// - /// DataTemplate used as the content of the notification - /// Displayed duration of the notification in ms (less or equal 0 means infinite duration) - public void Show(DataTemplate dataTemplate, int duration = 0) - { - var notificationOptions = new NotificationOptions - { - Duration = duration, - Content = dataTemplate - }; - Show(notificationOptions); - } - - /// - /// Dismiss the notification - /// - public void Dismiss() - { - Dismiss(InAppNotificationDismissKind.Programmatic); - } - - /// - /// Dismiss the notification - /// - /// Kind of action that triggered dismiss event - private void Dismiss(InAppNotificationDismissKind dismissKind) - { - lock (_openAnimationTimer) - lock (_closingAnimationTimer) - lock (_dismissTimer) - { - if (Visibility == Visibility.Visible) - { - _dismissTimer.Stop(); - - // Continue to display notification if on remaining stacked notification - if (_stackedNotificationOptions.Any()) - { - _stackedNotificationOptions.RemoveAt(0); - - if (_stackedNotificationOptions.Any()) - { - var notificationOptions = _stackedNotificationOptions[0]; - - UpdateContent(notificationOptions); - - if (notificationOptions.Duration > 0) - { - _dismissTimer.Interval = TimeSpan.FromMilliseconds(notificationOptions.Duration); - _dismissTimer.Start(); - } - - return; - } - } - - _openAnimationTimer.Stop(); - _closingAnimationTimer.Stop(); - - var closingEventArgs = new InAppNotificationClosingEventArgs(dismissKind); - Closing?.Invoke(this, closingEventArgs); - - if (closingEventArgs.Cancel) - { - return; - } - - VisualStateManager.GoToState(this, StateContentCollapsed, true); - - _lastDismissKind = dismissKind; - - _closingAnimationTimer.Interval = AnimationDuration; - _closingAnimationTimer.Start(); - } - } - } - - /// - /// Informs if the notification should be displayed immediately (based on the StackMode) - /// - /// True if notification should be displayed immediately - private bool ShouldDisplayImmediately() - { - return StackMode != StackMode.QueueBehind || - (StackMode == StackMode.QueueBehind && _stackedNotificationOptions.Count == 0); - } - - /// - /// Update the Content of the notification - /// - /// Information about the notification to display - private void UpdateContent(NotificationOptions notificationOptions) - { - switch (notificationOptions.Content) - { - case string text: - ContentTemplate = null; - Content = text; - break; - case UIElement element: - ContentTemplate = null; - Content = element; - break; - case DataTemplate dataTemplate: - ContentTemplate = dataTemplate; - Content = null; - break; - } - } - - /// - /// Handle the display of the notification based on the current StackMode - /// - /// Information about the notification to display - private void Show(NotificationOptions notificationOptions) - { - bool shouldDisplayImmediately = ShouldDisplayImmediately(); - - if (StackMode == StackMode.QueueBehind) - { - _stackedNotificationOptions.Add(notificationOptions); - } - - if (StackMode == StackMode.StackInFront) - { - _stackedNotificationOptions.Insert(0, notificationOptions); - } - - if (shouldDisplayImmediately) - { - UpdateContent(notificationOptions); - Show(notificationOptions.Duration); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotification.xaml b/src/Notepads.Controls/InAppNotification/InAppNotification.xaml deleted file mode 100644 index 459ff026f..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotification.xaml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - diff --git a/src/Notepads.Controls/InAppNotification/InAppNotificationClosedEventArgs.cs b/src/Notepads.Controls/InAppNotification/InAppNotificationClosedEventArgs.cs deleted file mode 100644 index bfe6fe09a..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotificationClosedEventArgs.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - - /// - /// A delegate for dismissing. - /// - /// The sender. - /// The event arguments. - public delegate void InAppNotificationClosedEventHandler(object sender, InAppNotificationClosedEventArgs e); - - /// - /// Provides data for the Dismissing event. - /// - public class InAppNotificationClosedEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// Dismiss kind that triggered the closing event - public InAppNotificationClosedEventArgs(InAppNotificationDismissKind dismissKind) - { - DismissKind = dismissKind; - } - - /// - /// Gets the kind of action for the closing event. - /// - public InAppNotificationDismissKind DismissKind { get; private set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotificationClosingEventArgs.cs b/src/Notepads.Controls/InAppNotification/InAppNotificationClosingEventArgs.cs deleted file mode 100644 index b2ba76084..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotificationClosingEventArgs.cs +++ /dev/null @@ -1,41 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - - /// - /// A delegate for dismissing. - /// - /// The sender. - /// The event arguments. - public delegate void InAppNotificationClosingEventHandler(object sender, InAppNotificationClosingEventArgs e); - - /// - /// Provides data for the Dismissing event. - /// - public class InAppNotificationClosingEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// Dismiss kind that triggered the closing event - public InAppNotificationClosingEventArgs(InAppNotificationDismissKind dismissKind) - { - DismissKind = dismissKind; - } - - /// - /// Gets the kind of action for the closing event. - /// - public InAppNotificationDismissKind DismissKind { get; private set; } - - /// - /// Gets or sets a value indicating whether the notification should be closed. - /// - public bool Cancel { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotificationDismissKind.cs b/src/Notepads.Controls/InAppNotification/InAppNotificationDismissKind.cs deleted file mode 100644 index f6d335501..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotificationDismissKind.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - /// - /// Enumeration to describe how an InAppNotification was dismissed - /// - public enum InAppNotificationDismissKind - { - /// - /// When the system dismissed the notification. - /// - Programmatic, - - /// - /// When user explicitly dismissed the notification. - /// - User, - - /// - /// When the system dismissed the notification after timeout. - /// - Timeout - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/InAppNotificationOpeningEventArgs.cs b/src/Notepads.Controls/InAppNotification/InAppNotificationOpeningEventArgs.cs deleted file mode 100644 index 78e39cc4a..000000000 --- a/src/Notepads.Controls/InAppNotification/InAppNotificationOpeningEventArgs.cs +++ /dev/null @@ -1,34 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using System; - - /// - /// A delegate for opening. - /// - /// The sender. - /// The event arguments. - public delegate void InAppNotificationOpeningEventHandler(object sender, InAppNotificationOpeningEventArgs e); - - /// - /// Provides data for the Dismissing event. - /// - public class InAppNotificationOpeningEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - public InAppNotificationOpeningEventArgs() - { - } - - /// - /// Gets or sets a value indicating whether the notification should be opened. - /// - public bool Cancel { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/NotificationOptions.cs b/src/Notepads.Controls/InAppNotification/NotificationOptions.cs deleted file mode 100644 index ca67a8d50..000000000 --- a/src/Notepads.Controls/InAppNotification/NotificationOptions.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - - /// - /// Base class that contains options of notification - /// - internal class NotificationOptions - { - /// - /// Gets or sets duration of the stacked notification - /// - public int Duration { get; set; } - - /// - /// Gets or sets Content of the notification - /// Could be either a or a or a - /// - public object Content { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/StackMode.cs b/src/Notepads.Controls/InAppNotification/StackMode.cs deleted file mode 100644 index e619a1080..000000000 --- a/src/Notepads.Controls/InAppNotification/StackMode.cs +++ /dev/null @@ -1,28 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/InAppNotification - -namespace Notepads.Controls -{ - /// - /// The Stack mode of an in-app notification. - /// - public enum StackMode - { - /// - /// Each notification will replace the previous one - /// - Replace, - - /// - /// Opening a notification will display it immediately, remaining notifications will appear when a notification is dismissed - /// - StackInFront, - - /// - /// Dismissing a notification will show the next one in the queue - /// - QueueBehind - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml b/src/Notepads.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml deleted file mode 100644 index a560dc3b8..000000000 --- a/src/Notepads.Controls/InAppNotification/Styles/MSEdgeNotificationStyle.xaml +++ /dev/null @@ -1,200 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Visible - - - - - Collapsed - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Notepads.Controls/MarkdownTextBlock/CodeBlockResolvingEventArgs.cs b/src/Notepads.Controls/MarkdownTextBlock/CodeBlockResolvingEventArgs.cs deleted file mode 100644 index ef0136348..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/CodeBlockResolvingEventArgs.cs +++ /dev/null @@ -1,47 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - using Windows.UI.Xaml.Documents; - - /// - /// Arguments for the event when a Code Block is being rendered. - /// - public class CodeBlockResolvingEventArgs : EventArgs - { - internal CodeBlockResolvingEventArgs(InlineCollection inlineCollection, string text, string codeLanguage) - { - InlineCollection = inlineCollection; - Text = text; - CodeLanguage = codeLanguage; - } - - /// - /// Gets the language of the Code Block, as specified by ```{Language} on the first line of the block, - /// e.g. - /// ```C# - /// public void Method(); - /// ``` - /// - public string CodeLanguage { get; } - - /// - /// Gets the raw code block text - /// - public string Text { get; } - - /// - /// Gets Collection to add formatted Text to. - /// - public InlineCollection InlineCollection { get; } - - /// - /// Gets or sets a value indicating whether this event was handled successfully. - /// - public bool Handled { get; set; } = false; - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/ImageResolvingEventArgs.cs b/src/Notepads.Controls/MarkdownTextBlock/ImageResolvingEventArgs.cs deleted file mode 100644 index 601b77abb..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/ImageResolvingEventArgs.cs +++ /dev/null @@ -1,73 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Threading.Tasks; - using Windows.Foundation; - using Windows.UI.Xaml.Media; - - /// - /// Arguments for the event which is called when a url needs to be resolved to a . - /// - public class ImageResolvingEventArgs : EventArgs - { - private readonly IList> _deferrals; - - internal ImageResolvingEventArgs(string url, string tooltip) - { - _deferrals = new List>(); - Url = url; - Tooltip = tooltip; - } - - /// - /// Gets the url of the image in the markdown document. - /// - public string Url { get; } - - /// - /// Gets the tooltip of the image in the markdown document. - /// - public string Tooltip { get; } - - /// - /// Gets or sets a value indicating whether this event was handled successfully. - /// - public bool Handled { get; set; } - - /// - /// Gets or sets the image to display in the . - /// - public ImageSource Image { get; set; } - - /// - /// Informs the that the event handler might run asynchronously. - /// - /// Deferral - public Deferral GetDeferral() - { - var task = new TaskCompletionSource(); - _deferrals.Add(task); - - return new Deferral(() => - { - task.SetResult(null); - }); - } - - /// - /// Returns a that completes when all s have completed. - /// - /// A representing the asynchronous operation. - internal Task WaitForDeferrals() - { - return Task.WhenAll(_deferrals.Select(f => f.Task)); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/LinkClickedEventArgs.cs b/src/Notepads.Controls/MarkdownTextBlock/LinkClickedEventArgs.cs deleted file mode 100644 index 8a83e2b82..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/LinkClickedEventArgs.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - - /// - /// Arguments for the OnLinkClicked event which is fired then the user presses a link. - /// - public class LinkClickedEventArgs : EventArgs - { - internal LinkClickedEventArgs(string link) - { - Link = link; - } - - /// - /// Gets the link that was tapped. - /// - public string Link { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/CodeBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/CodeBlock.cs deleted file mode 100644 index 79abd1490..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/CodeBlock.cs +++ /dev/null @@ -1,196 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System.Text; - - /// - /// Represents a block of text that is displayed in a fixed-width font. Inline elements and - /// escape sequences are ignored inside the code block. - /// - public class CodeBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public CodeBlock() - : base(MarkdownBlockType.Code) - { - } - - /// - /// Gets or sets the source code to display. - /// - public string Text { get; set; } - - /// - /// Gets or sets the Language specified in prefix, e.g. ```c# (Github Style Parsing). - /// This does not guarantee that the Code Block has a language, or no language, some valid code might not have been prefixed, and this will still return null. - /// To ensure all Code is Highlighted (If desired), you might have to determine the language from the provided string, such as looking for key words. - /// - public string CodeLanguage { get; set; } - - /// - /// Parses a code block. - /// - /// The markdown text. - /// The location of the first character in the block. - /// The location to stop parsing. - /// The current nesting level for block quoting. - /// Set to the end of the block when the return value is non-null. - /// A parsed code block, or null if this is not a code block. - internal static CodeBlock Parse(string markdown, int start, int maxEnd, int quoteDepth, out int actualEnd) - { - StringBuilder code = null; - actualEnd = start; - bool insideCodeBlock = false; - string codeLanguage = string.Empty; - - /* - Two options here: - Either every line starts with a tab character or at least 4 spaces - Or the code block starts and ends with ``` - */ - - foreach (var lineInfo in Common.ParseLines(markdown, start, maxEnd, quoteDepth)) - { - int pos = lineInfo.StartOfLine; - if (pos < maxEnd && markdown[pos] == '`') - { - var backTickCount = 0; - while (pos < maxEnd && backTickCount < 3) - { - if (markdown[pos] == '`') - { - backTickCount++; - } - else - { - break; - } - - pos++; - } - - if (backTickCount == 3) - { - insideCodeBlock = !insideCodeBlock; - - if (!insideCodeBlock) - { - actualEnd = lineInfo.StartOfNextLine; - break; - } - else - { - // Collects the Programming Language from the end of the starting ticks. - while (pos < lineInfo.EndOfLine) - { - codeLanguage += markdown[pos]; - pos++; - } - } - } - } - - if (!insideCodeBlock) - { - // Add every line that starts with a tab character or at least 4 spaces. - if (pos < maxEnd && markdown[pos] == '\t') - { - pos++; - } - else - { - int spaceCount = 0; - while (pos < maxEnd && spaceCount < 4) - { - if (markdown[pos] == ' ') - { - spaceCount++; - } - else if (markdown[pos] == '\t') - { - spaceCount += 4; - } - else - { - break; - } - - pos++; - } - - if (spaceCount < 4) - { - // We found a line that doesn't start with a tab or 4 spaces. - // But don't end the code block until we find a non-blank line. - if (lineInfo.IsLineBlank == false) - { - break; - } - } - } - } - - // Separate each line of the code text. - if (code == null) - { - code = new StringBuilder(); - } - else - { - code.AppendLine(); - } - - if (lineInfo.IsLineBlank == false) - { - // Append the code text, excluding the first tab/4 spaces, and convert tab characters into spaces. - string lineText = markdown.Substring(pos, lineInfo.EndOfLine - pos); - int startOfLinePos = code.Length; - for (int i = 0; i < lineText.Length; i++) - { - char c = lineText[i]; - if (c == '\t') - { - code.Append(' ', 4 - ((code.Length - startOfLinePos) % 4)); - } - else - { - code.Append(c); - } - } - } - - // Update the end position. - actualEnd = lineInfo.StartOfNextLine; - } - - if (code == null) - { - // Not a valid code block. - actualEnd = start; - return null; - } - - // Blank lines should be trimmed from the start and end. - return new CodeBlock() - { - Text = code.ToString().Trim('\r', '\n'), - CodeLanguage = !string.IsNullOrWhiteSpace(codeLanguage) ? codeLanguage.Trim() : null - }; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - return Text; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HeaderBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HeaderBlock.cs deleted file mode 100644 index a4dd874fb..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HeaderBlock.cs +++ /dev/null @@ -1,166 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - - /// - /// Represents a heading. - /// Single-Line Header CommonMark Spec - /// Two-Line Header CommonMark Spec - /// - public class HeaderBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public HeaderBlock() - : base(MarkdownBlockType.Header) - { - } - - private int _headerLevel; - - /// - /// Gets or sets the header level (1-6). 1 is the most important header, 6 is the least important. - /// - public int HeaderLevel - { - get => _headerLevel; - - set - { - if (value < 1 || value > 6) - { - throw new ArgumentOutOfRangeException("HeaderLevel", "The header level must be between 1 and 6 (inclusive)."); - } - - _headerLevel = value; - } - } - - /// - /// Gets or sets the contents of the block. - /// - public IList Inlines { get; set; } - - /// - /// Parses a header that starts with a hash. - /// - /// The markdown text. - /// The location of the first hash character. - /// The location of the end of the line. - /// A parsed header block, or null if this is not a header. - internal static HeaderBlock ParseHashPrefixedHeader(string markdown, int start, int end) - { - // This type of header starts with one or more '#' characters, followed by the header - // text, optionally followed by any number of hash characters. - var result = new HeaderBlock(); - - // Figure out how many consecutive hash characters there are. - int pos = start; - while (pos < end && markdown[pos] == '#' && pos - start < 6) - { - pos++; - } - - result.HeaderLevel = pos - start; - if (result.HeaderLevel == 0) - { - return null; - } - - // Ignore any hashes at the end of the line. - while (pos < end && markdown[end - 1] == '#') - { - end--; - } - - // Parse the inline content. - result.Inlines = Common.ParseInlineChildren(markdown, pos, end); - return result; - } - - /// - /// Parses a two-line header. - /// - /// The markdown text. - /// The location of the start of the first line. - /// The location of the end of the first line. - /// The location of the start of the second line. - /// The location of the end of the second line. - /// A parsed header block, or null if this is not a header. - internal static HeaderBlock ParseUnderlineStyleHeader(string markdown, int firstLineStart, int firstLineEnd, int secondLineStart, int secondLineEnd) - { - // This type of header starts with some text on the first line, followed by one or more - // underline characters ('=' or '-') on the second line. - // The second line can have whitespace after the underline characters, but not before - // or between each character. - - // Check the second line is valid. - if (secondLineEnd <= secondLineStart) - { - return null; - } - - // Figure out what the underline character is ('=' or '-'). - char underlineChar = markdown[secondLineStart]; - if (underlineChar != '=' && underlineChar != '-') - { - return null; - } - - // Read past consecutive underline characters. - int pos = secondLineStart + 1; - for (; pos < secondLineEnd; pos++) - { - char c = markdown[pos]; - if (c != underlineChar) - { - break; - } - - pos++; - } - - // The rest of the line must be whitespace. - for (; pos < secondLineEnd; pos++) - { - char c = markdown[pos]; - if (c != ' ' && c != '\t') - { - return null; - } - - pos++; - } - - var result = new HeaderBlock - { - HeaderLevel = underlineChar == '=' ? 1 : 2, - - // Parse the inline content. - Inlines = Common.ParseInlineChildren(markdown, firstLineStart, firstLineEnd) - }; - return result; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return string.Join(string.Empty, Inlines); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HorizontalRuleBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HorizontalRuleBlock.cs deleted file mode 100644 index 1dd9a35c6..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/HorizontalRuleBlock.cs +++ /dev/null @@ -1,73 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - /// - /// Represents a horizontal line. - /// - public class HorizontalRuleBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public HorizontalRuleBlock() - : base(MarkdownBlockType.HorizontalRule) - { - } - - /// - /// Parses a horizontal rule. - /// - /// The markdown text. - /// The location of the start of the line. - /// The location of the end of the line. - /// A parsed horizontal rule block, or null if this is not a horizontal rule. - internal static HorizontalRuleBlock Parse(string markdown, int start, int end) - { - // A horizontal rule is a line with at least 3 stars, optionally separated by spaces - // OR a line with at least 3 dashes, optionally separated by spaces - // OR a line with at least 3 underscores, optionally separated by spaces. - char hrChar = '\0'; - int hrCharCount = 0; - int pos = start; - while (pos < end) - { - char c = markdown[pos++]; - if (c == '*' || c == '-' || c == '_') - { - // All of the non-whitespace characters on the line must match. - if (hrCharCount > 0 && c != hrChar) - { - return null; - } - - hrChar = c; - hrCharCount++; - } - else if (c == '\n') - { - break; - } - else if (!ParseHelpers.IsMarkdownWhiteSpace(c)) - { - return null; - } - } - - // Hopefully there were at least 3 stars/dashes/underscores. - return hrCharCount >= 3 ? new HorizontalRuleBlock() : null; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - return "---"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/LinkReferenceBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/LinkReferenceBlock.cs deleted file mode 100644 index 98c1bb402..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/LinkReferenceBlock.cs +++ /dev/null @@ -1,170 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - /// - /// Represents the target of a reference ([ref][]). - /// - public class LinkReferenceBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public LinkReferenceBlock() - : base(MarkdownBlockType.LinkReference) - { - } - - /// - /// Gets or sets the reference ID. - /// - public string Id { get; set; } - - /// - /// Gets or sets the link URL. - /// - public string Url { get; set; } - - /// - /// Gets or sets a tooltip to display on hover. - /// - public string Tooltip { get; set; } - - /// - /// Attempts to parse a reference e.g. "[example]: http://www.reddit.com 'title'". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed markdown link, or null if this is not a markdown link. - internal static LinkReferenceBlock Parse(string markdown, int start, int end) - { - // Expect a '[' character. - if (start >= end || markdown[start] != '[') - { - return null; - } - - // Find the ']' character - int pos = start + 1; - while (pos < end) - { - if (markdown[pos] == ']') - { - break; - } - - pos++; - } - - if (pos == end) - { - return null; - } - - // Extract the ID. - string id = markdown.Substring(start + 1, pos - (start + 1)); - - // Expect the ':' character. - pos++; - if (pos == end || markdown[pos] != ':') - { - return null; - } - - // Skip whitespace - pos++; - while (pos < end && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - if (pos == end) - { - return null; - } - - // Extract the URL. - int urlStart = pos; - while (pos < end && !ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - string url = TextRunInline.ResolveEscapeSequences(markdown, urlStart, pos); - - // Ignore leading '<' and trailing '>'. - url = url.TrimStart('<').TrimEnd('>'); - - // Skip whitespace. - pos++; - while (pos < end && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - string tooltip = null; - if (pos < end) - { - // Extract the tooltip. - char tooltipEndChar; - switch (markdown[pos]) - { - case '(': - tooltipEndChar = ')'; - break; - - case '"': - case '\'': - tooltipEndChar = markdown[pos]; - break; - - default: - return null; - } - - pos++; - int tooltipStart = pos; - while (pos < end && markdown[pos] != tooltipEndChar) - { - pos++; - } - - if (pos == end) - { - return null; // No end character. - } - - tooltip = markdown.Substring(tooltipStart, pos - tooltipStart); - - // Check there isn't any trailing text. - pos++; - while (pos < end && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - if (pos < end) - { - return null; - } - } - - // We found something! - var result = new LinkReferenceBlock { Id = id, Url = url, Tooltip = tooltip }; - return result; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - return $"[{Id}]: {Url} {Tooltip}"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBlock.cs deleted file mode 100644 index a65adc6b5..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBlock.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks/List - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// This specifies the Content of the List element. - /// - public class ListItemBlock - { - /// - /// Gets or sets the contents of the list item. - /// - public IList Blocks { get; set; } - - internal ListItemBlock() - { - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBuilder.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBuilder.cs deleted file mode 100644 index 93c9fe928..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemBuilder.cs +++ /dev/null @@ -1,19 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks/List - -namespace Notepads.Controls.Markdown -{ - using System.Text; - - internal class ListItemBuilder : MarkdownBlock - { - public StringBuilder Builder { get; } = new StringBuilder(); - - public ListItemBuilder() - : base(MarkdownBlockType.ListItemBuilder) - { - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemPreamble.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemPreamble.cs deleted file mode 100644 index cef7a13ed..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/ListItemPreamble.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks/List - -namespace Notepads.Controls.Markdown -{ - internal class ListItemPreamble - { - public ListStyle Style { get; set; } - - public int ContentStartPos { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/NestedListInfo.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/NestedListInfo.cs deleted file mode 100644 index e1f88bab7..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/List/NestedListInfo.cs +++ /dev/null @@ -1,15 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks/List - -namespace Notepads.Controls.Markdown -{ - internal class NestedListInfo - { - public ListBlock List { get; set; } - - // The number of spaces at the start of the line the list first appeared. - public int SpaceCount { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ListBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ListBlock.cs deleted file mode 100644 index 241701c54..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ListBlock.cs +++ /dev/null @@ -1,402 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - using System.Text.RegularExpressions; - - /// - /// Represents a list, with each list item proceeded by either a number or a bullet. - /// - public class ListBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public ListBlock() - : base(MarkdownBlockType.List) - { - } - - /// - /// Gets or sets the list items. - /// - public IList Items { get; set; } - - /// - /// Gets or sets the style of the list, either numbered or bulleted. - /// - public ListStyle Style { get; set; } - - /// - /// Parses a list block. - /// - /// The markdown text. - /// The location of the first character in the block. - /// The location to stop parsing. - /// The current nesting level for block quoting. - /// Set to the end of the block when the return value is non-null. - /// A parsed list block, or null if this is not a list block. - internal static ListBlock Parse(string markdown, int start, int maxEnd, int quoteDepth, out int actualEnd) - { - var russianDolls = new List(); - int russianDollIndex = -1; - bool previousLineWasBlank = false; - bool inCodeBlock = false; - ListItemBlock currentListItem = null; - actualEnd = start; - - foreach (var lineInfo in Common.ParseLines(markdown, start, maxEnd, quoteDepth)) - { - // Is this line blank? - if (lineInfo.IsLineBlank) - { - // The line is blank, which means the next line which contains text may end the list (or it may not...). - previousLineWasBlank = true; - } - else - { - // Does the line contain a list item? - ListItemPreamble listItemPreamble = null; - if (lineInfo.FirstNonWhitespaceChar - lineInfo.StartOfLine < (russianDollIndex + 2) * 4) - { - listItemPreamble = ParseItemPreamble(markdown, lineInfo.FirstNonWhitespaceChar, lineInfo.EndOfLine); - } - - if (listItemPreamble != null) - { - // Yes, this line contains a list item. - - // Determining the nesting level is done as follows: - // 1. If this is the first line, then the list is not nested. - // 2. If the number of spaces at the start of the line is equal to that of - // an existing list, then the nesting level is the same as that list. - // 3. Otherwise, if the number of spaces is 0-4, then the nesting level - // is one level deep. - // 4. Otherwise, if the number of spaces is 5-8, then the nesting level - // is two levels deep (but no deeper than one level more than the - // previous list item). - // 5. Etcetera. - ListBlock listToAddTo = null; - int spaceCount = lineInfo.FirstNonWhitespaceChar - lineInfo.StartOfLine; - russianDollIndex = russianDolls.FindIndex(rd => rd.SpaceCount == spaceCount); - if (russianDollIndex >= 0) - { - // Add the new list item to an existing list. - listToAddTo = russianDolls[russianDollIndex].List; - - // Don't add new list items to items higher up in the list. - russianDolls.RemoveRange(russianDollIndex + 1, russianDolls.Count - (russianDollIndex + 1)); - } - else - { - russianDollIndex = Math.Max(1, 1 + ((spaceCount - 1) / 4)); - if (russianDollIndex < russianDolls.Count) - { - // Add the new list item to an existing list. - listToAddTo = russianDolls[russianDollIndex].List; - - // Don't add new list items to items higher up in the list. - russianDolls.RemoveRange(russianDollIndex + 1, russianDolls.Count - (russianDollIndex + 1)); - } - else - { - // Create a new list. - listToAddTo = new ListBlock { Style = listItemPreamble.Style, Items = new List() }; - if (russianDolls.Count > 0) - { - currentListItem.Blocks.Add(listToAddTo); - } - - russianDollIndex = russianDolls.Count; - russianDolls.Add(new NestedListInfo { List = listToAddTo, SpaceCount = spaceCount }); - } - } - - // Add a new list item. - currentListItem = new ListItemBlock() { Blocks = new List() }; - listToAddTo.Items.Add(currentListItem); - - // Add the rest of the line to the builder. - AppendTextToListItem(currentListItem, markdown, listItemPreamble.ContentStartPos, lineInfo.EndOfLine); - } - else - { - // No, this line contains text. - - // Is there even a list in progress? - if (currentListItem == null) - { - actualEnd = start; - return null; - } - - // This is the start of a new paragraph. - int spaceCount = lineInfo.FirstNonWhitespaceChar - lineInfo.StartOfLine; - if (spaceCount == 0) - { - break; - } - - russianDollIndex = Math.Min(russianDollIndex, (spaceCount - 1) / 4); - int lineStart = Math.Min(lineInfo.FirstNonWhitespaceChar, lineInfo.StartOfLine + ((russianDollIndex + 1) * 4)); - - // 0 spaces = end of the list. - // 1-4 spaces = first level. - // 5-8 spaces = second level, etc. - if (previousLineWasBlank) - { - ListBlock listToAddTo = russianDolls[russianDollIndex].List; - currentListItem = listToAddTo.Items[listToAddTo.Items.Count - 1]; - - ListItemBuilder builder; - - // Prevents new Block creation if still in a Code Block. - if (!inCodeBlock) - { - builder = new ListItemBuilder(); - currentListItem.Blocks.Add(builder); - } - else - { - // This can only ever be a ListItemBuilder, so it is not a null reference. - builder = currentListItem.Blocks.Last() as ListItemBuilder; - - // Make up for the escaped NewLines. - builder.Builder.AppendLine(); - builder.Builder.AppendLine(); - } - - AppendTextToListItem(currentListItem, markdown, lineStart, lineInfo.EndOfLine); - } - else - { - // Inline text. Ignores the 4 spaces that are used to continue the list. - AppendTextToListItem(currentListItem, markdown, lineStart, lineInfo.EndOfLine, true); - } - } - - // Check for Closing Code Blocks. - if (currentListItem.Blocks.Last() is ListItemBuilder currentBlock) - { - var blockmatchcount = Regex.Matches(currentBlock.Builder.ToString(), "```").Count; - if (blockmatchcount > 0 && blockmatchcount % 2 != 0) - { - inCodeBlock = true; - } - else - { - inCodeBlock = false; - } - } - - // The line was not blank. - previousLineWasBlank = false; - } - - // Go to the next line. - actualEnd = lineInfo.EndOfLine; - } - - var result = russianDolls[0].List; - ReplaceStringBuilders(result); - return result; - } - - /// - /// Parsing helper method. - /// - /// Returns a ListItemPreamble - private static ListItemPreamble ParseItemPreamble(string markdown, int start, int maxEnd) - { - // There are two types of lists. - // A numbered list starts with a number, then a period ('.'), then a space. - // A bulleted list starts with a star ('*'), dash ('-') or plus ('+'), then a period, then a space. - ListStyle style; - if (markdown[start] == '*' || markdown[start] == '-' || markdown[start] == '+') - { - style = ListStyle.Bulleted; - start++; - } - else if (markdown[start] >= '0' && markdown[start] <= '9') - { - style = ListStyle.Numbered; - start++; - - // Skip any other digits. - while (start < maxEnd) - { - char c = markdown[start]; - if (c < '0' || c > '9') - { - break; - } - - start++; - } - - // Next should be a period ('.'). - if (start == maxEnd || markdown[start] != '.') - { - return null; - } - - start++; - } - else - { - return null; - } - - // Next should be a space. - if (start == maxEnd || (markdown[start] != ' ' && markdown[start] != '\t')) - { - return null; - } - - start++; - - // This is a valid list item. - return new ListItemPreamble { Style = style, ContentStartPos = start }; - } - - /// - /// Parsing helper method. - /// - private static void AppendTextToListItem(ListItemBlock listItem, string markdown, int start, int end, bool newLine = false) - { - ListItemBuilder listItemBuilder = null; - if (listItem.Blocks.Count > 0) - { - listItemBuilder = listItem.Blocks[listItem.Blocks.Count - 1] as ListItemBuilder; - } - - if (listItemBuilder == null) - { - // Add a new block. - listItemBuilder = new ListItemBuilder(); - listItem.Blocks.Add(listItemBuilder); - } - - var builder = listItemBuilder.Builder; - if (builder.Length >= 2 && - ParseHelpers.IsMarkdownWhiteSpace(builder[builder.Length - 2]) && - ParseHelpers.IsMarkdownWhiteSpace(builder[builder.Length - 1])) - { - builder.Length -= 2; - builder.AppendLine(); - } - else if (builder.Length > 0) - { - builder.Append(' '); - } - - if (newLine) - { - builder.Append(Environment.NewLine); - } - - builder.Append(markdown.Substring(start, end - start)); - } - - /// - /// Parsing helper. - /// - /// true if any of the list items were parsed using the block parser. - private static bool ReplaceStringBuilders(ListBlock list) - { - bool usedBlockParser = false; - foreach (var listItem in list.Items) - { - // Use the inline parser if there is one paragraph, use the block parser otherwise. - var useBlockParser = listItem.Blocks.Count(block => block.Type == MarkdownBlockType.ListItemBuilder) > 1; - - // Recursively replace any child lists. - foreach (var block in listItem.Blocks) - { - if (block is ListBlock listBlock && ReplaceStringBuilders(listBlock)) - { - useBlockParser = true; - } - } - - // Parse the text content of the list items. - var newBlockList = new List(); - foreach (var block in listItem.Blocks) - { - if (block is ListItemBuilder) - { - var blockText = ((ListItemBuilder)block).Builder.ToString(); - if (useBlockParser) - { - // Parse the list item as a series of blocks. - newBlockList.AddRange(MarkdownDocument.Parse(blockText, 0, blockText.Length, quoteDepth: 0, actualEnd: out var actualEnd)); - usedBlockParser = true; - } - else - { - // Don't allow blocks. - var paragraph = new ParagraphBlock - { - Inlines = Common.ParseInlineChildren(blockText, 0, blockText.Length) - }; - newBlockList.Add(paragraph); - } - } - else - { - newBlockList.Add(block); - } - } - - listItem.Blocks = newBlockList; - } - - return usedBlockParser; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Items == null) - { - return base.ToString(); - } - - var result = new StringBuilder(); - for (int i = 0; i < Items.Count; i++) - { - if (result.Length > 0) - { - result.AppendLine(); - } - - switch (Style) - { - case ListStyle.Bulleted: - result.Append("* "); - break; - - case ListStyle.Numbered: - result.Append(i + 1); - result.Append("."); - break; - } - - result.Append(" "); - result.Append(string.Join("\r\n", Items[i].Blocks)); - } - - return result.ToString(); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ParagraphBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ParagraphBlock.cs deleted file mode 100644 index 310c84618..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/ParagraphBlock.cs +++ /dev/null @@ -1,52 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a block of text that is displayed as a single paragraph. - /// - public class ParagraphBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public ParagraphBlock() - : base(MarkdownBlockType.Paragraph) - { - } - - /// - /// Gets or sets the contents of the block. - /// - public IList Inlines { get; set; } - - /// - /// Parses paragraph text. - /// - /// The markdown text. - /// A parsed paragraph. - internal static ParagraphBlock Parse(string markdown) - { - return new ParagraphBlock { Inlines = Common.ParseInlineChildren(markdown, 0, markdown.Length) }; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return string.Join(string.Empty, Inlines); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/QuoteBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/QuoteBlock.cs deleted file mode 100644 index c541fbf8b..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/QuoteBlock.cs +++ /dev/null @@ -1,49 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a block that is displayed using a quote style. Quotes are used to indicate - /// that the text originated elsewhere (e.g. a previous comment). - /// - public class QuoteBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public QuoteBlock() - : base(MarkdownBlockType.Quote) - { - } - - /// - /// Gets or sets the contents of the block. - /// - public IList Blocks { get; set; } - - /// - /// Parses a quote block. - /// - /// The markdown text. - /// The location of the start of the line. - /// The location to stop parsing. - /// The current nesting level of quotes. - /// Set to the end of the block when the return value is non-null. - /// A parsed quote block. - internal static QuoteBlock Parse(string markdown, int startOfLine, int maxEnd, int quoteDepth, out int actualEnd) - { - var result = new QuoteBlock - { - // Recursively call into the markdown block parser. - Blocks = MarkdownDocument.Parse(markdown, startOfLine, maxEnd, quoteDepth: quoteDepth + 1, actualEnd: out actualEnd) - }; - - return result; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/TableBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/TableBlock.cs deleted file mode 100644 index ea73e1392..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/TableBlock.cs +++ /dev/null @@ -1,329 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - - /// - /// Represents a block which contains tabular data. - /// - public class TableBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public TableBlock() - : base(MarkdownBlockType.Table) - { - } - - /// - /// Gets or sets the table rows. - /// - public IList Rows { get; set; } - - /// - /// Gets or sets describes the columns in the table. Rows can have more or less cells than the number - /// of columns. Rows with fewer cells should be padded with empty cells. For rows with - /// more cells, the extra cells should be hidden. - /// - public IList ColumnDefinitions { get; set; } - - /// - /// Parses a table block. - /// - /// The markdown text. - /// The location of the first character in the block. - /// The location of the end of the first line. - /// The location to stop parsing. - /// The current nesting level for block quoting. - /// Set to the end of the block when the return value is non-null. - /// A parsed table block, or null if this is not a table block. - internal static TableBlock Parse(string markdown, int start, int endOfFirstLine, int maxEnd, int quoteDepth, out int actualEnd) - { - // A table is a line of text, with at least one vertical bar (|), followed by a line of - // of text that consists of alternating dashes (-) and vertical bars (|) and optionally - // vertical bars at the start and end. The second line must have at least as many - // interior vertical bars as there are interior vertical bars on the first line. - actualEnd = start; - - // First thing to do is to check if there is a vertical bar on the line. - var barSections = markdown.Substring(start, endOfFirstLine - start).Split('|'); - - var allBarsEscaped = true; - - // we can skip the last section, because there is no bar at the end of it - for (var i = 0; i < barSections.Length - 1; i++) - { - var barSection = barSections[i]; - if (!barSection.EndsWith("\\", StringComparison.Ordinal)) - { - allBarsEscaped = false; - break; - } - } - - if (allBarsEscaped) - { - return null; - } - - var rows = new List(); - - // Parse the first row. - var firstRow = new TableRow(); - start = firstRow.Parse(markdown, start, maxEnd, quoteDepth); - rows.Add(firstRow); - - // Parse the contents of the second row. - var secondRowContents = new List(); - start = TableRow.ParseContents( - markdown, - start, - maxEnd, - quoteDepth, - requireVerticalBar: false, - contentParser: (start2, end2) => secondRowContents.Add(markdown.Substring(start2, end2 - start2))); - - // There must be at least as many columns in the second row as in the first row. - if (secondRowContents.Count < firstRow.Cells.Count) - { - return null; - } - - // Check each column definition. - // Note: excess columns past firstRowColumnCount are ignored and can contain anything. - var columnDefinitions = new List(firstRow.Cells.Count); - for (int i = 0; i < firstRow.Cells.Count; i++) - { - var cellContent = secondRowContents[i]; - if (cellContent.Length == 0) - { - return null; - } - - // The first and last characters can be '-' or ':'. - if (cellContent[0] != ':' && cellContent[0] != '-') - { - return null; - } - - if (cellContent[cellContent.Length - 1] != ':' && cellContent[cellContent.Length - 1] != '-') - { - return null; - } - - // Every other character must be '-'. - for (int j = 1; j < cellContent.Length - 1; j++) - { - if (cellContent[j] != '-') - { - return null; - } - } - - // Record the alignment. - var columnDefinition = new TableColumnDefinition(); - if (cellContent.Length > 1 && cellContent[0] == ':' && cellContent[cellContent.Length - 1] == ':') - { - columnDefinition.Alignment = ColumnAlignment.Center; - } - else if (cellContent[0] == ':') - { - columnDefinition.Alignment = ColumnAlignment.Left; - } - else if (cellContent[cellContent.Length - 1] == ':') - { - columnDefinition.Alignment = ColumnAlignment.Right; - } - - columnDefinitions.Add(columnDefinition); - } - - // Parse additional rows. - while (start < maxEnd) - { - var row = new TableRow(); - start = row.Parse(markdown, start, maxEnd, quoteDepth); - if (row.Cells.Count == 0) - { - break; - } - - rows.Add(row); - } - - actualEnd = start; - return new TableBlock { ColumnDefinitions = columnDefinitions, Rows = rows }; - } - - /// - /// Describes a column in the markdown table. - /// - public class TableColumnDefinition - { - /// - /// Gets or sets the alignment of content in a table column. - /// - public ColumnAlignment Alignment { get; set; } - } - - /// - /// Represents a single row in the table. - /// - public class TableRow - { - /// - /// Gets or sets the table cells. - /// - public IList Cells { get; set; } - - /// - /// Parses the contents of the row, ignoring whitespace at the beginning and end of each cell. - /// - /// The markdown text. - /// The position of the start of the row. - /// The maximum position of the end of the row - /// The current nesting level for block quoting. - /// Indicates whether the line must contain a vertical bar. - /// Called for each cell. - /// The position of the start of the next line. - internal static int ParseContents(string markdown, int startingPos, int maxEndingPos, int quoteDepth, bool requireVerticalBar, Action contentParser) - { - // Skip quote characters. - int pos = Common.SkipQuoteCharacters(markdown, startingPos, maxEndingPos, quoteDepth); - - // If the line starts with a '|' character, skip it. - bool lineHasVerticalBar = false; - if (pos < maxEndingPos && markdown[pos] == '|') - { - lineHasVerticalBar = true; - pos++; - } - - while (pos < maxEndingPos) - { - // Ignore any whitespace at the start of the cell (except for a newline character). - while (pos < maxEndingPos && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos]) && markdown[pos] != '\n' && markdown[pos] != '\r') - { - pos++; - } - - int startOfCellContent = pos; - - // Find the end of the cell. - bool endOfLineFound = true; - while (pos < maxEndingPos) - { - char c = markdown[pos]; - if (c == '|' && (pos == 0 || markdown[pos - 1] != '\\')) - { - lineHasVerticalBar = true; - endOfLineFound = false; - break; - } - - if (c == '\n') - { - break; - } - - if (c == '\r') - { - if (pos < maxEndingPos && markdown[pos + 1] == '\n') - { - pos++; // Swallow the complete linefeed. - } - - break; - } - - pos++; - } - - int endOfCell = pos; - - // If a vertical bar is required, and none was found, then exit early. - if (endOfLineFound && !lineHasVerticalBar && requireVerticalBar) - { - return startingPos; - } - - // Ignore any whitespace at the end of the cell. - if (endOfCell > startOfCellContent) - { - while (ParseHelpers.IsMarkdownWhiteSpace(markdown[pos - 1])) - { - pos--; - } - } - - int endOfCellContent = pos; - - if (endOfLineFound == false || endOfCellContent > startOfCellContent) - { - // Parse the contents of the cell. - contentParser(startOfCellContent, endOfCellContent); - } - - // End of input? - if (pos == maxEndingPos) - { - break; - } - - // Move to the next cell, or the next line. - pos = endOfCell + 1; - - // End of the line? - if (endOfLineFound) - { - break; - } - } - - return pos; - } - - /// - /// Called when this block type should parse out the goods. Given the markdown, a starting point, and a max ending point - /// the block should find the start of the block, find the end and parse out the middle. The end most of the time will not be - /// the max ending pos, but it sometimes can be. The function will return where it ended parsing the block in the markdown. - /// - /// the postiion parsed to - internal int Parse(string markdown, int startingPos, int maxEndingPos, int quoteDepth) - { - Cells = new List(); - return ParseContents( - markdown, - startingPos, - maxEndingPos, - quoteDepth, - requireVerticalBar: true, - contentParser: (startingPos2, maxEndingPos2) => - { - var cell = new TableCell - { - Inlines = Common.ParseInlineChildren(markdown, startingPos2, maxEndingPos2) - }; - Cells.Add(cell); - }); - } - } - - /// - /// Represents a cell in the table. - /// - public class TableCell - { - /// - /// Gets or sets the cell contents. - /// - public IList Inlines { get; set; } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/YamlHeaderBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/YamlHeaderBlock.cs deleted file mode 100644 index d4e979033..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Blocks/YamlHeaderBlock.cs +++ /dev/null @@ -1,164 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Blocks - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - - /// - /// Yaml Header. use for blog. - /// e.g. - /// --- - /// title: something - /// tag: something - /// --- - /// - public class YamlHeaderBlock : MarkdownBlock - { - /// - /// Initializes a new instance of the class. - /// - public YamlHeaderBlock() - : base(MarkdownBlockType.YamlHeader) - { - } - - /// - /// Gets or sets yaml header properties - /// - public Dictionary Children { get; set; } - - /// - /// Parse yaml header - /// - /// The markdown text. - /// The location of the first hash character. - /// The location of the end of the line. - /// The location of the actual end of the aprse. - /// Parsed class - internal static YamlHeaderBlock Parse(string markdown, int start, int end, out int realEndIndex) - { - // As yaml header, must be start a line with "---" - // and end with a line "---" - realEndIndex = start; - int lineStart = start; - if (end - start < 3) - { - return null; - } - - if (lineStart != 0 || markdown.Substring(start, 3) != "---") - { - return null; - } - - int startUnderlineIndex = Common.FindNextSingleNewLine(markdown, lineStart, end, out int startOfNextLine); - if (startUnderlineIndex - lineStart != 3) - { - return null; - } - - bool lockedFinalUnderline = false; - - // if current line not contain the ": ", check it is end of parse, if not, exit - // if next line is the end, exit - int pos = startOfNextLine; - List elements = new List(); - while (pos < end) - { - int nextUnderLineIndex = Common.FindNextSingleNewLine(markdown, pos, end, out startOfNextLine); - bool haveSeparator = markdown.Substring(pos, nextUnderLineIndex - pos).Contains(": ", StringComparison.Ordinal); - if (haveSeparator) - { - elements.Add(markdown.Substring(pos, nextUnderLineIndex - pos)); - } - else if (end - pos >= 3 && markdown.Substring(pos, 3) == "---") - { - lockedFinalUnderline = true; - realEndIndex = pos + 3; - break; - } - else if (startOfNextLine == pos + 1) - { - pos = startOfNextLine; - continue; - } - else - { - return null; - } - - pos = startOfNextLine; - } - - // if not have the end, return - if (!lockedFinalUnderline) - { - return null; - } - - // parse yaml header properties - if (elements.Count < 1) - { - return null; - } - - var result = new YamlHeaderBlock - { - Children = new Dictionary() - }; - foreach (var item in elements) - { - string[] splits = item.Split(new string[] { ": " }, StringSplitOptions.None); - if (splits.Length < 2) - { - continue; - } - else - { - string key = splits[0]; - string value = splits[1]; - if (key.Trim().Length == 0) - { - continue; - } - - value = string.IsNullOrEmpty(value.Trim()) ? string.Empty : value; - result.Children.Add(key, value); - } - } - - if (result.Children == null) - { - return null; - } - - return result; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Children == null) - { - return base.ToString(); - } - else - { - string result = string.Empty; - foreach (KeyValuePair item in Children) - { - result += item.Key + ": " + item.Value + "\n"; - } - - return result.TrimEnd('\n'); - } - } - } -} diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/IParser.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/IParser.cs deleted file mode 100644 index c43875485..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/IParser.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Parsers/Core - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Parser interface. - /// - /// Type to parse into. - public interface IParser - where T : SchemaBase - { - /// - /// Parse method which all classes must implement. - /// - /// Data to parse. - /// Strong typed parsed data. - IEnumerable Parse(string data); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/ParseHelpers.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/ParseHelpers.cs deleted file mode 100644 index 5c9e63f0a..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/ParseHelpers.cs +++ /dev/null @@ -1,39 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Parsers/Core - -namespace Notepads.Controls.Markdown -{ - /// - /// This class offers helpers for Parsing. - /// - public static class ParseHelpers - { - /// - /// Determines if a Markdown string is blank or comprised entirely of whitespace characters. - /// - /// true if blank or white space - public static bool IsMarkdownBlankOrWhiteSpace(string str) - { - for (int i = 0; i < str.Length; i++) - { - if (!IsMarkdownWhiteSpace(str[i])) - { - return false; - } - } - - return true; - } - - /// - /// Determines if a character is a Markdown whitespace character. - /// - /// true if is white space - public static bool IsMarkdownWhiteSpace(char c) - { - return c == ' ' || c == '\t' || c == '\r' || c == '\n'; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/SchemaBase.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/SchemaBase.cs deleted file mode 100644 index 84a3baade..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/SchemaBase.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Parsers/Core - -namespace Notepads.Controls.Markdown -{ - /// - /// Strong typed schema base class. - /// - public abstract class SchemaBase - { - /// - /// Gets or sets identifier for strong typed record. - /// - public string InternalID { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/StringValueAttribute.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/StringValueAttribute.cs deleted file mode 100644 index 766dfc0b5..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Core/StringValueAttribute.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Parsers/Core - -namespace Notepads.Controls.Markdown -{ - using System; - - /// - /// The StringValue attribute is used as a helper to decorate enum values with string representations. - /// - [AttributeUsage(AttributeTargets.Field)] - public sealed class StringValueAttribute : Attribute - { - /// - /// Initializes a new instance of the class. - /// Constructor accepting string value. - /// - /// String value - public StringValueAttribute(string value) - { - Value = value; - } - - /// - /// Gets property for string value. - /// - public string Value { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ColumnAlignment.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ColumnAlignment.cs deleted file mode 100644 index 216a590ed..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ColumnAlignment.cs +++ /dev/null @@ -1,33 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - /// - /// The alignment of content in a table column. - /// - public enum ColumnAlignment - { - /// - /// The alignment was not specified. - /// - Unspecified, - - /// - /// Content should be left aligned. - /// - Left, - - /// - /// Content should be right aligned. - /// - Right, - - /// - /// Content should be centered. - /// - Center, - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/HyperlinkType.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/HyperlinkType.cs deleted file mode 100644 index de1ce31d5..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/HyperlinkType.cs +++ /dev/null @@ -1,43 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - /// - /// Specifies the type of Hyperlink that is used. - /// - public enum HyperlinkType - { - /// - /// A hyperlink surrounded by angle brackets (e.g. "http://www.reddit.com"). - /// - BracketedUrl, - - /// - /// A fully qualified hyperlink (e.g. "http://www.reddit.com"). - /// - FullUrl, - - /// - /// A URL without a scheme (e.g. "www.reddit.com"). - /// - PartialUrl, - - /// - /// An email address (e.g. "test@reddit.com"). - /// - Email, - - /// - /// A subreddit link (e.g. "/r/news"). - /// - Subreddit, - - /// - /// A user link (e.g. "/u/quinbd"). - /// - User, - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/InlineParseMethod.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/InlineParseMethod.cs deleted file mode 100644 index d3c7fd8cb..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/InlineParseMethod.cs +++ /dev/null @@ -1,95 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - internal enum InlineParseMethod - { - /// - /// A Comment text - /// - Comment, - - /// - /// A Link Reference - /// - LinkReference, - - /// - /// A bold element - /// - Bold, - - /// - /// An bold and italic block - /// - BoldItalic, - - /// - /// A code element - /// - Code, - - /// - /// An italic block - /// - Italic, - - /// - /// A link block - /// - MarkdownLink, - - /// - /// An angle bracket link. - /// - AngleBracketLink, - - /// - /// A url block - /// - Url, - - /// - /// A reddit style link - /// - RedditLink, - - /// - /// An in line text link - /// - PartialLink, - - /// - /// An email element - /// - Email, - - /// - /// strike through element - /// - Strikethrough, - - /// - /// Super script element. - /// - Superscript, - - /// - /// Sub script element. - /// - Subscript, - - /// - /// Image element. - /// - Image, - - /// - /// Emoji element. - /// - Emoji - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ListStyle.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ListStyle.cs deleted file mode 100644 index 9bbaf1156..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/ListStyle.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - /// - /// This specifies the type of style the List will be. - /// - public enum ListStyle - { - /// - /// A list with bullets - /// - Bulleted, - - /// - /// A numbered list - /// - Numbered, - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownBlockType.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownBlockType.cs deleted file mode 100644 index 439fa9360..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownBlockType.cs +++ /dev/null @@ -1,68 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - /// - /// Determines the type of Block the Block element is. - /// - public enum MarkdownBlockType - { - /// - /// The root element - /// - Root, - - /// - /// A paragraph element. - /// - Paragraph, - - /// - /// A quote block - /// - Quote, - - /// - /// A code block - /// - Code, - - /// - /// A header block - /// - Header, - - /// - /// A list block - /// - List, - - /// - /// A list item block - /// - ListItemBuilder, - - /// - /// a horizontal rule block - /// - HorizontalRule, - - /// - /// A table block - /// - Table, - - /// - /// A link block - /// - LinkReference, - - /// - /// A Yaml header block - /// - YamlHeader - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownInlineType.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownInlineType.cs deleted file mode 100644 index ee2427e9f..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Enums/MarkdownInlineType.cs +++ /dev/null @@ -1,83 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Enums - -namespace Notepads.Controls.Markdown -{ - /// - /// Determines the type of Inline the Inline Element is. - /// - public enum MarkdownInlineType - { - /// - /// A comment - /// - Comment, - - /// - /// A text run - /// - TextRun, - - /// - /// A bold run - /// - Bold, - - /// - /// An italic run - /// - Italic, - - /// - /// A link in markdown syntax - /// - MarkdownLink, - - /// - /// A raw hyper link - /// - RawHyperlink, - - /// - /// A raw subreddit link - /// - RawSubreddit, - - /// - /// A strike through run - /// - Strikethrough, - - /// - /// A superscript run - /// - Superscript, - - /// - /// A subscript run - /// - Subscript, - - /// - /// A code run - /// - Code, - - /// - /// An image - /// - Image, - - /// - /// Emoji - /// - Emoji, - - /// - /// Link Reference - /// - LinkReference - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/Common.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/Common.cs deleted file mode 100644 index 04afb131b..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/Common.cs +++ /dev/null @@ -1,535 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Helpers - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Linq; - - /// - /// Helpers for Markdown. - /// - internal class Common - { - private static readonly List _triggerList = new List(); - private static readonly char[] _tripCharacters; - - static Common() - { - BoldItalicTextInline.AddTripChars(_triggerList); - BoldTextInline.AddTripChars(_triggerList); - ItalicTextInline.AddTripChars(_triggerList); - MarkdownLinkInline.AddTripChars(_triggerList); - HyperlinkInline.AddTripChars(_triggerList); - CommentInline.AddTripChars(_triggerList); - StrikethroughTextInline.AddTripChars(_triggerList); - SuperscriptTextInline.AddTripChars(_triggerList); - SubscriptTextInline.AddTripChars(_triggerList); - CodeInline.AddTripChars(_triggerList); - ImageInline.AddTripChars(_triggerList); - EmojiInline.AddTripChars(_triggerList); - LinkAnchorInline.AddTripChars(_triggerList); - - // Create an array of characters to search against using IndexOfAny. - _tripCharacters = _triggerList.Select(trigger => trigger.FirstChar).Distinct().ToArray(); - } - - /// - /// This function can be called by any element parsing. Given a start and stopping point this will - /// parse all found elements out of the range. - /// - /// A list of parsed inlines. - public static List ParseInlineChildren(string markdown, int startingPos, int maxEndingPos, bool ignoreLinks = false) - { - int currentParsePosition = startingPos; - - var inlines = new List(); - while (currentParsePosition < maxEndingPos) - { - // Find the next inline element. - var parseResult = FindNextInlineElement(markdown, currentParsePosition, maxEndingPos, ignoreLinks); - - // If the element we found doesn't start at the position we are looking for there - // is text between the element and the start of the parsed element. We need to wrap - // it into a text run. - if (parseResult.Start != currentParsePosition) - { - var textRun = TextRunInline.Parse(markdown, currentParsePosition, parseResult.Start); - inlines.Add(textRun); - } - - // Add the parsed element. - inlines.Add(parseResult.ParsedElement); - - // Update the current position. - currentParsePosition = parseResult.End; - } - - return inlines; - } - - /// - /// Finds the next inline element by matching trip chars and verifying the match. - /// - /// The markdown text to parse. - /// The position to start parsing. - /// The position to stop parsing. - /// Indicates whether to parse links. - /// Returns the next element - private static InlineParseResult FindNextInlineElement(string markdown, int start, int end, bool ignoreLinks) - { - // Search for the next inline sequence. - for (int pos = start; pos < end; pos++) - { - // IndexOfAny should be the fastest way to skip characters we don't care about. - pos = markdown.IndexOfAny(_tripCharacters, pos, end - pos); - if (pos < 0) - { - break; - } - - // Find the trigger(s) that matched. - char currentChar = markdown[pos]; - foreach (InlineTripCharHelper currentTripChar in _triggerList) - { - // Check if our current char matches the suffix char. - if (currentChar == currentTripChar.FirstChar) - { - // Don't match if the previous character was a backslash. - if (pos > start && markdown[pos - 1] == '\\') - { - continue; - } - - // If we are here we have a possible match. Call into the inline class to verify. - InlineParseResult parseResult = null; - switch (currentTripChar.Method) - { - case InlineParseMethod.BoldItalic: - parseResult = BoldItalicTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Comment: - parseResult = CommentInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.LinkReference: - parseResult = LinkAnchorInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Bold: - parseResult = BoldTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Italic: - parseResult = ItalicTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.MarkdownLink: - if (!ignoreLinks) - { - parseResult = MarkdownLinkInline.Parse(markdown, pos, end); - } - - break; - - case InlineParseMethod.AngleBracketLink: - if (!ignoreLinks) - { - parseResult = HyperlinkInline.ParseAngleBracketLink(markdown, pos, end); - } - - break; - - case InlineParseMethod.Url: - if (!ignoreLinks) - { - parseResult = HyperlinkInline.ParseUrl(markdown, pos, end); - } - - break; - - case InlineParseMethod.RedditLink: - if (!ignoreLinks) - { - parseResult = HyperlinkInline.ParseRedditLink(markdown, pos, end); - } - - break; - - case InlineParseMethod.PartialLink: - if (!ignoreLinks) - { - parseResult = HyperlinkInline.ParsePartialLink(markdown, pos, end); - } - - break; - - case InlineParseMethod.Email: - if (!ignoreLinks) - { - parseResult = HyperlinkInline.ParseEmailAddress(markdown, start, pos, end); - } - - break; - - case InlineParseMethod.Strikethrough: - parseResult = StrikethroughTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Superscript: - parseResult = SuperscriptTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Subscript: - parseResult = SubscriptTextInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Code: - parseResult = CodeInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Image: - parseResult = ImageInline.Parse(markdown, pos, end); - break; - - case InlineParseMethod.Emoji: - parseResult = EmojiInline.Parse(markdown, pos, end); - break; - } - - if (parseResult != null) - { - return parseResult; - } - } - } - } - - // If we didn't find any elements we have a normal text block. - // Let us consume the entire range. - return new InlineParseResult(TextRunInline.Parse(markdown, start, end), start, end); - } - - /// - /// Returns the next \n or \r\n in the markdown. - /// - /// the next single line - public static int FindNextSingleNewLine(string markdown, int startingPos, int endingPos, out int startOfNextLine) - { - // A line can end with CRLF (\r\n) or just LF (\n). - int lineFeedPos = markdown.IndexOf('\n', startingPos); - if (lineFeedPos == -1) - { - // Trying with /r now - lineFeedPos = markdown.IndexOf('\r', startingPos); - if (lineFeedPos == -1) - { - startOfNextLine = endingPos; - return endingPos; - } - } - - startOfNextLine = lineFeedPos + 1; - - // Check if it was a CRLF. - if (lineFeedPos > startingPos && markdown[lineFeedPos - 1] == '\r') - { - return lineFeedPos - 1; - } - - return lineFeedPos; - } - - /// - /// Helper function for index of with a start and an ending. - /// - /// Pos of the searched for item - public static int IndexOf(string markdown, string search, int startingPos, int endingPos, bool reverseSearch = false) - { - // Check the ending isn't out of bounds. - if (endingPos > markdown.Length) - { - endingPos = markdown.Length; - DebuggingReporter.ReportCriticalError("IndexOf endingPos > string length"); - } - - // Figure out how long to go - int count = endingPos - startingPos; - if (count < 0) - { - return -1; - } - - // Make sure we don't go too far. - int remainingCount = markdown.Length - startingPos; - if (count > remainingCount) - { - DebuggingReporter.ReportCriticalError("IndexOf count > remaing count"); - count = remainingCount; - } - - // Check the ending. Since we use inclusive ranges we need to -1 from this for - // reverses searches. - if (reverseSearch && endingPos > 0) - { - endingPos -= 1; - } - - return reverseSearch ? markdown.LastIndexOf(search, endingPos, count, StringComparison.OrdinalIgnoreCase) : markdown.IndexOf(search, startingPos, count, StringComparison.OrdinalIgnoreCase); - } - - /// - /// Helper function for index of with a start and an ending. - /// - /// Pos of the searched for item - public static int IndexOf(string markdown, char search, int startingPos, int endingPos, bool reverseSearch = false) - { - // Check the ending isn't out of bounds. - if (endingPos > markdown.Length) - { - endingPos = markdown.Length; - DebuggingReporter.ReportCriticalError("IndexOf endingPos > string length"); - } - - // Figure out how long to go - int count = endingPos - startingPos; - if (count < 0) - { - return -1; - } - - // Make sure we don't go too far. - int remainingCount = markdown.Length - startingPos; - if (count > remainingCount) - { - DebuggingReporter.ReportCriticalError("IndexOf count > remaing count"); - count = remainingCount; - } - - // Check the ending. Since we use inclusive ranges we need to -1 from this for - // reverses searches. - if (reverseSearch && endingPos > 0) - { - endingPos -= 1; - } - - return reverseSearch ? markdown.LastIndexOf(search, endingPos, count) : markdown.IndexOf(search, startingPos, count); - } - - /// - /// Finds the next whitespace in a range. - /// - /// pos of the white space - public static int FindNextWhiteSpace(string markdown, int startingPos, int endingPos, bool ifNotFoundReturnLength) - { - int currentPos = startingPos; - while (currentPos < markdown.Length && currentPos < endingPos) - { - if (char.IsWhiteSpace(markdown[currentPos])) - { - return currentPos; - } - - currentPos++; - } - - return ifNotFoundReturnLength ? endingPos : -1; - } - - /// - /// Parses lines. - /// - /// LineInfo - public static IEnumerable ParseLines(string markdown, int start, int end, int quoteDepth) - { - int pos = start; - bool lineStartsNewParagraph = true; - - while (pos < end) - { - int startOfLine = pos; - int expectedQuotesRemaining = quoteDepth; - int nonSpacePos = pos; - char nonSpaceChar = '\0'; - while (true) - { - // Find the next non-space char. - while (nonSpacePos < end) - { - char c = markdown[nonSpacePos]; - if (c == '\r' || c == '\n') - { - // The line is either entirely whitespace, or is empty. - break; - } - - if (c != ' ' && c != '\t') - { - // The line has content. - nonSpaceChar = c; - break; - } - - nonSpacePos++; - } - - // When parsing blocks in a blockquote context, we need to count the number of - // quote characters ('>'). If there are less than expected AND this is the - // start of a new paragraph, then stop parsing. - if (expectedQuotesRemaining == 0) - { - break; - } - - if (nonSpaceChar == '>') - { - // Expected block quote characters should be ignored. - expectedQuotesRemaining--; - nonSpacePos++; - nonSpaceChar = '\0'; - startOfLine = nonSpacePos; - - // Ignore the first space after the quote character, if there is one. - if (startOfLine < end && markdown[startOfLine] == ' ') - { - startOfLine++; - nonSpacePos++; - } - } - else - { - // There were less block quote characters than expected. - // But it doesn't matter if this is not the start of a new paragraph. - if (!lineStartsNewParagraph || nonSpaceChar == '\0') - { - break; - } - - // This must be the end of the blockquote. End the current paragraph, if any. - yield break; - } - } - - // Find the end of the current line. - int endOfLine = FindNextSingleNewLine(markdown, nonSpacePos, end, out int startOfNextLine); - - // Return the line info to the caller. - yield return new LineInfo - { - StartOfLine = startOfLine, - FirstNonWhitespaceChar = nonSpacePos, - EndOfLine = endOfLine, - StartOfNextLine = startOfNextLine, - }; - - if (nonSpaceChar == '\0') - { - // The line is empty or nothing but whitespace. - lineStartsNewParagraph = true; - } - - // Repeat. - pos = startOfNextLine; - } - } - - /// - /// Skips a certain number of quote characters (>). - /// - /// Skip Quote Chars - public static int SkipQuoteCharacters(string markdown, int start, int end, int quoteDepth) - { - if (quoteDepth == 0) - { - return start; - } - - int startOfLine = start; - int nonSpacePos = start; - char nonSpaceChar = '\0'; - - while (true) - { - // Find the next non-space char. - while (nonSpacePos < end) - { - char c = markdown[nonSpacePos]; - if (c == '\r' || c == '\n') - { - // The line is either entirely whitespace, or is empty. - break; - } - - if (c != ' ' && c != '\t') - { - // The line has content. - nonSpaceChar = c; - break; - } - - nonSpacePos++; - } - - // When parsing blocks in a blockquote context, we need to count the number of - // quote characters ('>'). If there are less than expected AND this is the - // start of a new paragraph, then stop parsing. - if (quoteDepth == 0) - { - break; - } - - if (nonSpaceChar == '>') - { - // Expected block quote characters should be ignored. - quoteDepth--; - nonSpacePos++; - nonSpaceChar = '\0'; - startOfLine = nonSpacePos; - - // Ignore the first space after the quote character, if there is one. - if (startOfLine < end && markdown[startOfLine] == ' ') - { - startOfLine++; - nonSpacePos++; - } - } - else - { - // There were less block quote characters than expected. - break; - } - } - - return startOfLine; - } - - /// - /// Checks if the given URL is allowed in a markdown link. - /// - /// The URL to check. - /// true if the URL is valid; false otherwise. - public static bool IsUrlValid(string url) - { - // URLs can be relative. - if (!Uri.TryCreate(url, UriKind.Absolute, out Uri result)) - { - return true; - } - - // Check the scheme is allowed. - foreach (var scheme in MarkdownDocument.KnownSchemes) - { - if (result.Scheme.Equals(scheme, StringComparison.Ordinal)) - { - return true; - } - } - - return false; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/DebuggingReporter.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/DebuggingReporter.cs deleted file mode 100644 index 671717452..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/DebuggingReporter.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Helpers - -namespace Notepads.Controls.Markdown -{ - using System.Diagnostics; - - /// - /// Reports an error during debugging. - /// - internal class DebuggingReporter - { - /// - /// Reports a critical error. - /// - public static void ReportCriticalError(string errorText) - { - Debug.WriteLine(errorText); - if (Debugger.IsAttached) - { - Debugger.Break(); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineParseResult.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineParseResult.cs deleted file mode 100644 index 1a799ddee..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineParseResult.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Helpers - -namespace Notepads.Controls.Markdown -{ - /// - /// Represents the result of parsing an inline element. - /// - internal class InlineParseResult - { - public InlineParseResult(MarkdownInline parsedElement, int start, int end) - { - ParsedElement = parsedElement; - Start = start; - End = end; - } - - /// - /// Gets the element that was parsed (can be null). - /// - public MarkdownInline ParsedElement { get; } - - /// - /// Gets the position of the first character in the parsed element. - /// - public int Start { get; } - - /// - /// Gets the position of the character after the last character in the parsed element. - /// - public int End { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineTripCharHelper.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineTripCharHelper.cs deleted file mode 100644 index 3aff1f7bb..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/InlineTripCharHelper.cs +++ /dev/null @@ -1,22 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Helpers - -namespace Notepads.Controls.Markdown -{ - /// - /// A helper class for the trip chars. This is an optimization. If we ask each class to go - /// through the rage and look for itself we end up looping through the range n times, once - /// for each inline. This class represent a character that an inline needs to have a - /// possible match. We will go through the range once and look for everyone's trip chars, - /// and if they can make a match from the trip char then we will commit to them. - /// - internal class InlineTripCharHelper - { - // Note! Everything in first char and suffix should be lower case! - public char FirstChar { get; set; } - - public InlineParseMethod Method { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/LineInfo.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/LineInfo.cs deleted file mode 100644 index 914250bc6..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Helpers/LineInfo.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Helpers - -namespace Notepads.Controls.Markdown -{ - internal class LineInfo - { - public int StartOfLine { get; set; } - - public int FirstNonWhitespaceChar { get; set; } - - public int EndOfLine { get; set; } - - public bool IsLineBlank => FirstNonWhitespaceChar == EndOfLine; - - public int StartOfNextLine { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldItalicTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldItalicTextInline.cs deleted file mode 100644 index 2937346e2..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldItalicTextInline.cs +++ /dev/null @@ -1,118 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing bold italic text. - /// - internal class BoldItalicTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public BoldItalicTextInline() - : base(MarkdownInlineType.Bold) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '*', Method = InlineParseMethod.BoldItalic }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '_', Method = InlineParseMethod.BoldItalic }); - } - - /// - /// Attempts to parse a bold text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed bold text span, or null if this is not a bold text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - if (start >= maxEnd - 1) - { - return null; - } - - if (markdown == null || markdown.Length < 6 || start + 6 >= maxEnd) - { - return null; - } - - // Check the start sequence. - string startSequence = markdown.Substring(start, 3); - if (startSequence != "***" && startSequence != "___") - { - return null; - } - - // Find the end of the span. The end sequence (either '***' or '___') must be the same - // as the start sequence. - var innerStart = start + 3; - int innerEnd = Common.IndexOf(markdown, startSequence, innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // The first character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart])) - { - return null; - } - - // The last character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - var bold = new BoldTextInline - { - Inlines = new List - { - new ItalicTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - } - } - }; - return new InlineParseResult(bold, start, innerEnd + 3); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "***" + string.Join(string.Empty, Inlines) + "***"; - } - } -} diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldTextInline.cs deleted file mode 100644 index 314d6d2bc..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/BoldTextInline.cs +++ /dev/null @@ -1,107 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span that contains bold text. - /// - public class BoldTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public BoldTextInline() - : base(MarkdownInlineType.Bold) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '*', Method = InlineParseMethod.Bold }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '_', Method = InlineParseMethod.Bold }); - } - - /// - /// Attempts to parse a bold text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed bold text span, or null if this is not a bold text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - if (start >= maxEnd - 1) - { - return null; - } - - // Check the start sequence. - string startSequence = markdown.Substring(start, 2); - if (startSequence != "**" && startSequence != "__") - { - return null; - } - - // Find the end of the span. The end sequence (either '**' or '__') must be the same - // as the start sequence. - var innerStart = start + 2; - int innerEnd = Common.IndexOf(markdown, startSequence, innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // The first character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart])) - { - return null; - } - - // The last character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - var result = new BoldTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, innerEnd + 2); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "**" + string.Join(string.Empty, Inlines) + "**"; - } - } -} diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CodeInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CodeInline.cs deleted file mode 100644 index c5b8ffabb..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CodeInline.cs +++ /dev/null @@ -1,112 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing code, or other text that is to be displayed using a - /// fixed-width font. - /// - public class CodeInline : MarkdownInline, IInlineLeaf - { - /// - /// Initializes a new instance of the class. - /// - public CodeInline() - : base(MarkdownInlineType.Code) - { - } - - /// - /// Gets or sets the text to display as code. - /// - public string Text { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '`', Method = InlineParseMethod.Code }); - } - - /// - /// Attempts to parse an inline code span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed inline code span, or null if this is not an inline code span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Check the first char. - if (start == maxEnd || markdown[start] != '`') - { - return null; - } - - // There is an alternate syntax that starts and ends with two backticks. - // e.g. ``sdf`sdf`` would be "sdf`sdf". - int innerStart = start + 1; - int innerEnd, end; - if (innerStart < maxEnd && markdown[innerStart] == '`') - { - // Alternate double back-tick syntax. - innerStart++; - - // Find the end of the span. - innerEnd = Common.IndexOf(markdown, "``", innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - end = innerEnd + 2; - } - else - { - // Standard single backtick syntax. - - // Find the end of the span. - innerEnd = Common.IndexOf(markdown, '`', innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - end = innerEnd + 1; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // We found something! - var result = new CodeInline - { - Text = markdown.Substring(innerStart, innerEnd - innerStart).Trim(' ', '\t', '\r', '\n') - }; - return new InlineParseResult(result, start, end); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Text == null) - { - return base.ToString(); - } - - return "`" + Text + "`"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CommentInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CommentInline.cs deleted file mode 100644 index c2cb6b3b6..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/CommentInline.cs +++ /dev/null @@ -1,85 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - - /// - /// Represents a span that contains comment. - /// - internal class CommentInline : MarkdownInline, IInlineLeaf - { - /// - /// Initializes a new instance of the class. - /// - public CommentInline() - : base(MarkdownInlineType.Comment) - { - } - - /// - /// Gets or sets the Content of the Comment. - /// - public string Text { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '<', Method = InlineParseMethod.Comment }); - } - - /// - /// Attempts to parse a comment span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed bold text span, or null if this is not a bold text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - if (start >= maxEnd - 1) - { - return null; - } - - string startSequence = markdown.Substring(start); - if (!startSequence.StartsWith("') - var innerStart = start + 4; - int innerEnd = Common.IndexOf(markdown, "-->", innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - var length = innerEnd - innerStart; - var contents = markdown.Substring(innerStart, length); - - var result = new CommentInline - { - Text = contents - }; - - return new InlineParseResult(result, start, innerEnd + 3); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - return ""; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.EmojiCodes.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.EmojiCodes.cs deleted file mode 100644 index 40d08da48..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.EmojiCodes.cs +++ /dev/null @@ -1,846 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing emoji symbol. - /// - public partial class EmojiInline - { - // Codes taken from https://gist.github.com/rxaviers/7360908 - // Ignoring not implented symbols in Segoe UI Emoji font (e.g. :bowtie:) - private static readonly Dictionary _emojiCodesDictionary = new Dictionary - { - { "smile", 0x1f604 }, - { "laughing", 0x1f606 }, - { "blush", 0x1f60a }, - { "smiley", 0x1f603 }, - { "relaxed", 0x263a }, - { "smirk", 0x1f60f }, - { "heart_eyes", 0x1f60d }, - { "kissing_heart", 0x1f618 }, - { "kissing_closed_eyes", 0x1f61a }, - { "flushed", 0x1f633 }, - { "relieved", 0x1f60c }, - { "satisfied", 0x1f606 }, - { "grin", 0x1f601 }, - { "wink", 0x1f609 }, - { "stuck_out_tongue_winking_eye", 0x1f61c }, - { "stuck_out_tongue_closed_eyes", 0x1f61d }, - { "grinning", 0x1f600 }, - { "kissing", 0x1f617 }, - { "kissing_smiling_eyes", 0x1f619 }, - { "stuck_out_tongue", 0x1f61b }, - { "sleeping", 0x1f634 }, - { "worried", 0x1f61f }, - { "frowning", 0x1f626 }, - { "anguished", 0x1f627 }, - { "open_mouth", 0x1f62e }, - { "grimacing", 0x1f62c }, - { "confused", 0x1f615 }, - { "hushed", 0x1f62f }, - { "expressionless", 0x1f611 }, - { "unamused", 0x1f612 }, - { "sweat_smile", 0x1f605 }, - { "sweat", 0x1f613 }, - { "disappointed_relieved", 0x1f625 }, - { "weary", 0x1f629 }, - { "pensive", 0x1f614 }, - { "disappointed", 0x1f61e }, - { "confounded", 0x1f616 }, - { "fearful", 0x1f628 }, - { "cold_sweat", 0x1f630 }, - { "persevere", 0x1f623 }, - { "cry", 0x1f622 }, - { "sob", 0x1f62d }, - { "joy", 0x1f602 }, - { "astonished", 0x1f632 }, - { "scream", 0x1f631 }, - { "tired_face", 0x1f62b }, - { "angry", 0x1f620 }, - { "rage", 0x1f621 }, - { "triumph", 0x1f624 }, - { "sleepy", 0x1f62a }, - { "yum", 0x1f60b }, - { "mask", 0x1f637 }, - { "sunglasses", 0x1f60e }, - { "dizzy_face", 0x1f635 }, - { "imp", 0x1f47f }, - { "smiling_imp", 0x1f608 }, - { "neutral_face", 0x1f610 }, - { "no_mouth", 0x1f636 }, - { "innocent", 0x1f607 }, - { "alien", 0x1f47d }, - { "yellow_heart", 0x1f49b }, - { "blue_heart", 0x1f499 }, - { "purple_heart", 0x1f49c }, - { "heart", 0x2764 }, - { "green_heart", 0x1f49a }, - { "broken_heart", 0x1f494 }, - { "heartbeat", 0x1f493 }, - { "heartpulse", 0x1f497 }, - { "two_hearts", 0x1f495 }, - { "revolving_hearts", 0x1f49e }, - { "cupid", 0x1f498 }, - { "sparkling_heart", 0x1f496 }, - { "sparkles", 0x2728 }, - { "star", 0x2b50 }, - { "star2", 0x1f31f }, - { "dizzy", 0x1f4ab }, - { "boom", 0x1f4a5 }, - { "collision", 0x1f4a5 }, - { "anger", 0x1f4a2 }, - { "exclamation", 0x2757 }, - { "question", 0x2753 }, - { "grey_exclamation", 0x2755 }, - { "grey_question", 0x2754 }, - { "zzz", 0x1f4a4 }, - { "dash", 0x1f4a8 }, - { "sweat_drops", 0x1f4a6 }, - { "notes", 0x1f3b6 }, - { "musical_note", 0x1f3b5 }, - { "fire", 0x1f525 }, - { "hankey", 0x1f4a9 }, - { "poop", 0x1f4a9 }, - { "+1", 0x1f44d }, - { "thumbsup", 0x1f44d }, - { "-1", 0x1f44e }, - { "thumbsdown", 0x1f44e }, - { "ok_hand", 0x1f44c }, - { "punch", 0x1f44a }, - { "facepunch", 0x1f44a }, - { "fist", 0x270a }, - { "v", 0x270c }, - { "wave", 0x1f44b }, - { "hand", 0x270b }, - { "raised_hand", 0x270b }, - { "open_hands", 0x1f450 }, - { "point_up", 0x261d }, - { "point_down", 0x1f447 }, - { "point_left", 0x1f448 }, - { "point_right", 0x1f449 }, - { "raised_hands", 0x1f64c }, - { "pray", 0x1f64f }, - { "point_up_2", 0x1f446 }, - { "clap", 0x1f44f }, - { "muscle", 0x1f4aa }, - { "metal", 0x1f918 }, - { "walking", 0x1f6b6 }, - { "runner", 0x1f3c3 }, - { "running", 0x1f3c3 }, - { "couple", 0x1f46b }, - { "family", 0x1f46a }, - { "two_men_holding_hands", 0x1f46c }, - { "two_women_holding_hands", 0x1f46d }, - { "dancer", 0x1f483 }, - { "dancers", 0x1f46f }, - { "ok_woman", 0x1f646 }, - { "no_good", 0x1f645 }, - { "information_desk_person", 0x1f481 }, - { "raising_hand", 0x1f64b }, - { "bride_with_veil", 0x1f470 }, - { "person_with_pouting_face", 0x1f64e }, - { "person_frowning", 0x1f64d }, - { "bow", 0x1f647 }, - { "couple_with_heart", 0x1f491 }, - { "massage", 0x1f486 }, - { "haircut", 0x1f487 }, - { "nail_care", 0x1f485 }, - { "boy", 0x1f466 }, - { "girl", 0x1f467 }, - { "woman", 0x1f469 }, - { "man", 0x1f468 }, - { "baby", 0x1f476 }, - { "older_woman", 0x1f475 }, - { "older_man", 0x1f474 }, - { "person_with_blond_hair", 0x1f471 }, - { "man_with_gua_pi_mao", 0x1f472 }, - { "man_with_turban", 0x1f473 }, - { "construction_worker", 0x1f477 }, - { "cop", 0x1f46e }, - { "angel", 0x1f47c }, - { "princess", 0x1f478 }, - { "smiley_cat", 0x1f63a }, - { "smile_cat", 0x1f638 }, - { "heart_eyes_cat", 0x1f63b }, - { "kissing_cat", 0x1f63d }, - { "smirk_cat", 0x1f63c }, - { "scream_cat", 0x1f640 }, - { "crying_cat_face", 0x1f63f }, - { "joy_cat", 0x1f639 }, - { "pouting_cat", 0x1f63e }, - { "japanese_ogre", 0x1f479 }, - { "japanese_goblin", 0x1f47a }, - { "see_no_evil", 0x1f648 }, - { "hear_no_evil", 0x1f649 }, - { "speak_no_evil", 0x1f64a }, - { "guardsman", 0x1f482 }, - { "skull", 0x1f480 }, - { "feet", 0x1f43e }, - { "lips", 0x1f444 }, - { "kiss", 0x1f48b }, - { "droplet", 0x1f4a7 }, - { "ear", 0x1f442 }, - { "eyes", 0x1f440 }, - { "nose", 0x1f443 }, - { "tongue", 0x1f445 }, - { "love_letter", 0x1f48c }, - { "bust_in_silhouette", 0x1f464 }, - { "busts_in_silhouette", 0x1f465 }, - { "speech_balloon", 0x1f4ac }, - { "thought_balloon", 0x1f4ad }, - { "sunny", 0x2600 }, - { "umbrella", 0x2614 }, - { "cloud", 0x2601 }, - { "snowflake", 0x2744 }, - { "snowman", 0x26c4 }, - { "zap", 0x26a1 }, - { "cyclone", 0x1f300 }, - { "foggy", 0x1f301 }, - { "ocean", 0x1f30a }, - { "cat", 0x1f431 }, - { "dog", 0x1f436 }, - { "mouse", 0x1f42d }, - { "hamster", 0x1f439 }, - { "rabbit", 0x1f430 }, - { "wolf", 0x1f43a }, - { "frog", 0x1f438 }, - { "tiger", 0x1f42f }, - { "koala", 0x1f428 }, - { "bear", 0x1f43b }, - { "pig", 0x1f437 }, - { "pig_nose", 0x1f43d }, - { "cow", 0x1f42e }, - { "boar", 0x1f417 }, - { "monkey_face", 0x1f435 }, - { "monkey", 0x1f412 }, - { "horse", 0x1f434 }, - { "racehorse", 0x1f40e }, - { "camel", 0x1f42b }, - { "sheep", 0x1f411 }, - { "elephant", 0x1f418 }, - { "panda_face", 0x1f43c }, - { "snake", 0x1f40d }, - { "bird", 0x1f426 }, - { "baby_chick", 0x1f424 }, - { "hatched_chick", 0x1f425 }, - { "hatching_chick", 0x1f423 }, - { "chicken", 0x1f414 }, - { "penguin", 0x1f427 }, - { "turtle", 0x1f422 }, - { "bug", 0x1f41b }, - { "honeybee", 0x1f41d }, - { "ant", 0x1f41c }, - { "beetle", 0x1f41e }, - { "snail", 0x1f40c }, - { "octopus", 0x1f419 }, - { "tropical_fish", 0x1f420 }, - { "fish", 0x1f41f }, - { "whale", 0x1f433 }, - { "whale2", 0x1f40b }, - { "dolphin", 0x1f42c }, - { "cow2", 0x1f404 }, - { "ram", 0x1f40f }, - { "rat", 0x1f400 }, - { "water_buffalo", 0x1f403 }, - { "tiger2", 0x1f405 }, - { "rabbit2", 0x1f407 }, - { "dragon", 0x1f409 }, - { "goat", 0x1f410 }, - { "rooster", 0x1f413 }, - { "dog2", 0x1f415 }, - { "pig2", 0x1f416 }, - { "mouse2", 0x1f401 }, - { "ox", 0x1f402 }, - { "dragon_face", 0x1f432 }, - { "blowfish", 0x1f421 }, - { "crocodile", 0x1f40a }, - { "dromedary_camel", 0x1f42a }, - { "leopard", 0x1f406 }, - { "cat2", 0x1f408 }, - { "poodle", 0x1f429 }, - { "paw_prints", 0x1f43e }, - { "bouquet", 0x1f490 }, - { "cherry_blossom", 0x1f338 }, - { "tulip", 0x1f337 }, - { "four_leaf_clover", 0x1f340 }, - { "rose", 0x1f339 }, - { "sunflower", 0x1f33b }, - { "hibiscus", 0x1f33a }, - { "maple_leaf", 0x1f341 }, - { "leaves", 0x1f343 }, - { "fallen_leaf", 0x1f342 }, - { "herb", 0x1f33f }, - { "mushroom", 0x1f344 }, - { "cactus", 0x1f335 }, - { "palm_tree", 0x1f334 }, - { "evergreen_tree", 0x1f332 }, - { "deciduous_tree", 0x1f333 }, - { "chestnut", 0x1f330 }, - { "seedling", 0x1f331 }, - { "blossom", 0x1f33c }, - { "ear_of_rice", 0x1f33e }, - { "shell", 0x1f41a }, - { "globe_with_meridians", 0x1f310 }, - { "sun_with_face", 0x1f31e }, - { "full_moon_with_face", 0x1f31d }, - { "new_moon_with_face", 0x1f31a }, - { "new_moon", 0x1f311 }, - { "waxing_crescent_moon", 0x1f312 }, - { "first_quarter_moon", 0x1f313 }, - { "waxing_gibbous_moon", 0x1f314 }, - { "full_moon", 0x1f315 }, - { "waning_gibbous_moon", 0x1f316 }, - { "last_quarter_moon", 0x1f317 }, - { "waning_crescent_moon", 0x1f318 }, - { "last_quarter_moon_with_face", 0x1f31c }, - { "first_quarter_moon_with_face", 0x1f31b }, - { "moon", 0x1f314 }, - { "earth_africa", 0x1f30d }, - { "earth_americas", 0x1f30e }, - { "earth_asia", 0x1f30f }, - { "volcano", 0x1f30b }, - { "milky_way", 0x1f30c }, - { "partly_sunny", 0x26c5 }, - { "bamboo", 0x1f38d }, - { "gift_heart", 0x1f49d }, - { "dolls", 0x1f38e }, - { "school_satchel", 0x1f392 }, - { "mortar_board", 0x1f393 }, - { "flags", 0x1f38f }, - { "fireworks", 0x1f386 }, - { "sparkler", 0x1f387 }, - { "wind_chime", 0x1f390 }, - { "rice_scene", 0x1f391 }, - { "jack_o_lantern", 0x1f383 }, - { "ghost", 0x1f47b }, - { "santa", 0x1f385 }, - { "christmas_tree", 0x1f384 }, - { "gift", 0x1f381 }, - { "bell", 0x1f514 }, - { "no_bell", 0x1f515 }, - { "tanabata_tree", 0x1f38b }, - { "tada", 0x1f389 }, - { "confetti_ball", 0x1f38a }, - { "balloon", 0x1f388 }, - { "crystal_ball", 0x1f52e }, - { "cd", 0x1f4bf }, - { "dvd", 0x1f4c0 }, - { "floppy_disk", 0x1f4be }, - { "camera", 0x1f4f7 }, - { "video_camera", 0x1f4f9 }, - { "movie_camera", 0x1f3a5 }, - { "computer", 0x1f4bb }, - { "tv", 0x1f4fa }, - { "iphone", 0x1f4f1 }, - { "phone", 0x260e }, - { "telephone", 0x260e }, - { "telephone_receiver", 0x1f4de }, - { "pager", 0x1f4df }, - { "fax", 0x1f4e0 }, - { "minidisc", 0x1f4bd }, - { "vhs", 0x1f4fc }, - { "sound", 0x1f509 }, - { "speaker", 0x1f508 }, - { "mute", 0x1f507 }, - { "loudspeaker", 0x1f4e2 }, - { "mega", 0x1f4e3 }, - { "hourglass", 0x231b }, - { "hourglass_flowing_sand", 0x23f3 }, - { "alarm_clock", 0x23f0 }, - { "watch", 0x231a }, - { "radio", 0x1f4fb }, - { "satellite", 0x1f4e1 }, - { "loop", 0x27bf }, - { "mag", 0x1f50d }, - { "mag_right", 0x1f50e }, - { "unlock", 0x1f513 }, - { "lock", 0x1f512 }, - { "lock_with_ink_pen", 0x1f50f }, - { "closed_lock_with_key", 0x1f510 }, - { "key", 0x1f511 }, - { "bulb", 0x1f4a1 }, - { "flashlight", 0x1f526 }, - { "high_brightness", 0x1f506 }, - { "low_brightness", 0x1f505 }, - { "electric_plug", 0x1f50c }, - { "battery", 0x1f50b }, - { "calling", 0x1f4f2 }, - { "email", 0x2709 }, - { "mailbox", 0x1f4eb }, - { "postbox", 0x1f4ee }, - { "bath", 0x1f6c0 }, - { "bathtub", 0x1f6c1 }, - { "shower", 0x1f6bf }, - { "toilet", 0x1f6bd }, - { "wrench", 0x1f527 }, - { "nut_and_bolt", 0x1f529 }, - { "hammer", 0x1f528 }, - { "seat", 0x1f4ba }, - { "moneybag", 0x1f4b0 }, - { "yen", 0x1f4b4 }, - { "dollar", 0x1f4b5 }, - { "pound", 0x1f4b7 }, - { "euro", 0x1f4b6 }, - { "credit_card", 0x1f4b3 }, - { "money_with_wings", 0x1f4b8 }, - { "e-mail", 0x1f4e7 }, - { "inbox_tray", 0x1f4e5 }, - { "outbox_tray", 0x1f4e4 }, - { "envelope", 0x2709 }, - { "incoming_envelope", 0x1f4e8 }, - { "postal_horn", 0x1f4ef }, - { "mailbox_closed", 0x1f4ea }, - { "mailbox_with_mail", 0x1f4ec }, - { "mailbox_with_no_mail", 0x1f4ed }, - { "door", 0x1f6aa }, - { "smoking", 0x1f6ac }, - { "bomb", 0x1f4a3 }, - { "gun", 0x1f52b }, - { "hocho", 0x1f52a }, - { "pill", 0x1f48a }, - { "syringe", 0x1f489 }, - { "page_facing_up", 0x1f4c4 }, - { "page_with_curl", 0x1f4c3 }, - { "bookmark_tabs", 0x1f4d1 }, - { "bar_chart", 0x1f4ca }, - { "chart_with_upwards_trend", 0x1f4c8 }, - { "chart_with_downwards_trend", 0x1f4c9 }, - { "scroll", 0x1f4dc }, - { "clipboard", 0x1f4cb }, - { "calendar", 0x1f4c6 }, - { "date", 0x1f4c5 }, - { "card_index", 0x1f4c7 }, - { "file_folder", 0x1f4c1 }, - { "open_file_folder", 0x1f4c2 }, - { "scissors", 0x2702 }, - { "pushpin", 0x1f4cc }, - { "paperclip", 0x1f4ce }, - { "black_nib", 0x2712 }, - { "pencil2", 0x270f }, - { "straight_ruler", 0x1f4cf }, - { "triangular_ruler", 0x1f4d0 }, - { "closed_book", 0x1f4d5 }, - { "green_book", 0x1f4d7 }, - { "blue_book", 0x1f4d8 }, - { "orange_book", 0x1f4d9 }, - { "notebook", 0x1f4d3 }, - { "notebook_with_decorative_cover", 0x1f4d4 }, - { "ledger", 0x1f4d2 }, - { "books", 0x1f4da }, - { "bookmark", 0x1f516 }, - { "name_badge", 0x1f4db }, - { "microscope", 0x1f52c }, - { "telescope", 0x1f52d }, - { "newspaper", 0x1f4f0 }, - { "football", 0x1f3c8 }, - { "basketball", 0x1f3c0 }, - { "soccer", 0x26bd }, - { "baseball", 0x26be }, - { "tennis", 0x1f3be }, - { "8ball", 0x1f3b1 }, - { "rugby_football", 0x1f3c9 }, - { "bowling", 0x1f3b3 }, - { "golf", 0x26f3 }, - { "mountain_bicyclist", 0x1f6b5 }, - { "bicyclist", 0x1f6b4 }, - { "horse_racing", 0x1f3c7 }, - { "snowboarder", 0x1f3c2 }, - { "swimmer", 0x1f3ca }, - { "surfer", 0x1f3c4 }, - { "ski", 0x1f3bf }, - { "spades", 0x2660 }, - { "hearts", 0x2665 }, - { "clubs", 0x2663 }, - { "diamonds", 0x2666 }, - { "gem", 0x1f48e }, - { "ring", 0x1f48d }, - { "trophy", 0x1f3c6 }, - { "musical_score", 0x1f3bc }, - { "musical_keyboard", 0x1f3b9 }, - { "violin", 0x1f3bb }, - { "space_invader", 0x1f47e }, - { "video_game", 0x1f3ae }, - { "black_joker", 0x1f0cf }, - { "flower_playing_cards", 0x1f3b4 }, - { "game_die", 0x1f3b2 }, - { "dart", 0x1f3af }, - { "mahjong", 0x1f004 }, - { "clapper", 0x1f3ac }, - { "memo", 0x1f4dd }, - { "pencil", 0x1f4dd }, - { "book", 0x1f4d6 }, - { "art", 0x1f3a8 }, - { "microphone", 0x1f3a4 }, - { "headphones", 0x1f3a7 }, - { "trumpet", 0x1f3ba }, - { "saxophone", 0x1f3b7 }, - { "guitar", 0x1f3b8 }, - { "shoe", 0x1f45e }, - { "sandal", 0x1f461 }, - { "high_heel", 0x1f460 }, - { "lipstick", 0x1f484 }, - { "boot", 0x1f462 }, - { "shirt", 0x1f455 }, - { "tshirt", 0x1f455 }, - { "necktie", 0x1f454 }, - { "womans_clothes", 0x1f45a }, - { "dress", 0x1f457 }, - { "running_shirt_with_sash", 0x1f3bd }, - { "jeans", 0x1f456 }, - { "kimono", 0x1f458 }, - { "bikini", 0x1f459 }, - { "ribbon", 0x1f380 }, - { "tophat", 0x1f3a9 }, - { "crown", 0x1f451 }, - { "womans_hat", 0x1f452 }, - { "mans_shoe", 0x1f45e }, - { "closed_umbrella", 0x1f302 }, - { "briefcase", 0x1f4bc }, - { "handbag", 0x1f45c }, - { "pouch", 0x1f45d }, - { "purse", 0x1f45b }, - { "eyeglasses", 0x1f453 }, - { "fishing_pole_and_fish", 0x1f3a3 }, - { "coffee", 0x2615 }, - { "tea", 0x1f375 }, - { "sake", 0x1f376 }, - { "baby_bottle", 0x1f37c }, - { "beer", 0x1f37a }, - { "beers", 0x1f37b }, - { "cocktail", 0x1f378 }, - { "tropical_drink", 0x1f379 }, - { "wine_glass", 0x1f377 }, - { "fork_and_knife", 0x1f374 }, - { "pizza", 0x1f355 }, - { "hamburger", 0x1f354 }, - { "fries", 0x1f35f }, - { "poultry_leg", 0x1f357 }, - { "meat_on_bone", 0x1f356 }, - { "spaghetti", 0x1f35d }, - { "curry", 0x1f35b }, - { "fried_shrimp", 0x1f364 }, - { "bento", 0x1f371 }, - { "sushi", 0x1f363 }, - { "fish_cake", 0x1f365 }, - { "rice_ball", 0x1f359 }, - { "rice_cracker", 0x1f358 }, - { "rice", 0x1f35a }, - { "ramen", 0x1f35c }, - { "stew", 0x1f372 }, - { "oden", 0x1f362 }, - { "dango", 0x1f361 }, - { "egg", 0x1f95a }, - { "bread", 0x1f35e }, - { "doughnut", 0x1f369 }, - { "custard", 0x1f36e }, - { "icecream", 0x1f366 }, - { "ice_cream", 0x1f368 }, - { "shaved_ice", 0x1f367 }, - { "birthday", 0x1f382 }, - { "cake", 0x1f370 }, - { "cookie", 0x1f36a }, - { "chocolate_bar", 0x1f36b }, - { "candy", 0x1f36c }, - { "lollipop", 0x1f36d }, - { "honey_pot", 0x1f36f }, - { "apple", 0x1f34e }, - { "green_apple", 0x1f34f }, - { "tangerine", 0x1f34a }, - { "lemon", 0x1f34b }, - { "cherries", 0x1f352 }, - { "grapes", 0x1f347 }, - { "watermelon", 0x1f349 }, - { "strawberry", 0x1f353 }, - { "peach", 0x1f351 }, - { "melon", 0x1f348 }, - { "banana", 0x1f34c }, - { "pear", 0x1f350 }, - { "pineapple", 0x1f34d }, - { "sweet_potato", 0x1f360 }, - { "eggplant", 0x1f346 }, - { "tomato", 0x1f345 }, - { "corn", 0x1f33d }, - { "house", 0x1f3e0 }, - { "house_with_garden", 0x1f3e1 }, - { "school", 0x1f3eb }, - { "office", 0x1f3e2 }, - { "post_office", 0x1f3e3 }, - { "hospital", 0x1f3e5 }, - { "bank", 0x1f3e6 }, - { "convenience_store", 0x1f3ea }, - { "love_hotel", 0x1f3e9 }, - { "hotel", 0x1f3e8 }, - { "wedding", 0x1f492 }, - { "church", 0x26ea }, - { "department_store", 0x1f3ec }, - { "european_post_office", 0x1f3e4 }, - { "city_sunrise", 0x1f307 }, - { "city_sunset", 0x1f306 }, - { "japanese_castle", 0x1f3ef }, - { "european_castle", 0x1f3f0 }, - { "tent", 0x26fa }, - { "factory", 0x1f3ed }, - { "tokyo_tower", 0x1f5fc }, - { "japan", 0x1f5fe }, - { "mount_fuji", 0x1f5fb }, - { "sunrise_over_mountains", 0x1f304 }, - { "sunrise", 0x1f305 }, - { "stars", 0x1f320 }, - { "statue_of_liberty", 0x1f5fd }, - { "bridge_at_night", 0x1f309 }, - { "carousel_horse", 0x1f3a0 }, - { "rainbow", 0x1f308 }, - { "ferris_wheel", 0x1f3a1 }, - { "fountain", 0x26f2 }, - { "roller_coaster", 0x1f3a2 }, - { "ship", 0x1f6a2 }, - { "speedboat", 0x1f6a4 }, - { "boat", 0x26f5 }, - { "sailboat", 0x26f5 }, - { "rowboat", 0x1f6a3 }, - { "anchor", 0x2693 }, - { "rocket", 0x1f680 }, - { "airplane", 0x2708 }, - { "helicopter", 0x1f681 }, - { "steam_locomotive", 0x1f682 }, - { "tram", 0x1f68a }, - { "mountain_railway", 0x1f69e }, - { "bike", 0x1f6b2 }, - { "aerial_tramway", 0x1f6a1 }, - { "suspension_railway", 0x1f69f }, - { "mountain_cableway", 0x1f6a0 }, - { "tractor", 0x1f69c }, - { "blue_car", 0x1f699 }, - { "oncoming_automobile", 0x1f698 }, - { "car", 0x1f697 }, - { "red_car", 0x1f697 }, - { "taxi", 0x1f695 }, - { "oncoming_taxi", 0x1f696 }, - { "articulated_lorry", 0x1f69b }, - { "bus", 0x1f68c }, - { "oncoming_bus", 0x1f68d }, - { "rotating_light", 0x1f6a8 }, - { "police_car", 0x1f693 }, - { "oncoming_police_car", 0x1f694 }, - { "fire_engine", 0x1f692 }, - { "ambulance", 0x1f691 }, - { "minibus", 0x1f690 }, - { "truck", 0x1f69a }, - { "train", 0x1f68b }, - { "station", 0x1f689 }, - { "train2", 0x1f686 }, - { "bullettrain_front", 0x1f685 }, - { "bullettrain_side", 0x1f684 }, - { "light_rail", 0x1f688 }, - { "monorail", 0x1f69d }, - { "railway_car", 0x1f683 }, - { "trolleybus", 0x1f68e }, - { "ticket", 0x1f3ab }, - { "fuelpump", 0x26fd }, - { "vertical_traffic_light", 0x1f6a6 }, - { "traffic_light", 0x1f6a5 }, - { "warning", 0x26a0 }, - { "construction", 0x1f6a7 }, - { "beginner", 0x1f530 }, - { "atm", 0x1f3e7 }, - { "slot_machine", 0x1f3b0 }, - { "busstop", 0x1f68f }, - { "barber", 0x1f488 }, - { "hotsprings", 0x2668 }, - { "checkered_flag", 0x1f3c1 }, - { "crossed_flags", 0x1f38c }, - { "izakaya_lantern", 0x1f3ee }, - { "moyai", 0x1f5ff }, - { "circus_tent", 0x1f3aa }, - { "performing_arts", 0x1f3ad }, - { "round_pushpin", 0x1f4cd }, - { "triangular_flag_on_post", 0x1f6a9 }, - { "keycap_ten", 0x1f51f }, - { "1234", 0x1f522 }, - { "symbols", 0x1f523 }, - { "arrow_backward", 0x25c0 }, - { "arrow_down", 0x2b07 }, - { "arrow_forward", 0x25b6 }, - { "arrow_left", 0x2b05 }, - { "capital_abcd", 0x1f520 }, - { "abcd", 0x1f521 }, - { "abc", 0x1f524 }, - { "arrow_lower_left", 0x2199 }, - { "arrow_lower_right", 0x2198 }, - { "arrow_right", 0x27a1 }, - { "arrow_up", 0x2b06 }, - { "arrow_upper_left", 0x2196 }, - { "arrow_upper_right", 0x2197 }, - { "arrow_double_down", 0x23ec }, - { "arrow_double_up", 0x23eb }, - { "arrow_down_small", 0x1f53d }, - { "arrow_heading_down", 0x2935 }, - { "arrow_heading_up", 0x2934 }, - { "leftwards_arrow_with_hook", 0x21a9 }, - { "arrow_right_hook", 0x21aa }, - { "left_right_arrow", 0x2194 }, - { "arrow_up_down", 0x2195 }, - { "arrow_up_small", 0x1f53c }, - { "arrows_clockwise", 0x1f503 }, - { "arrows_counterclockwise", 0x1f504 }, - { "rewind", 0x23ea }, - { "fast_forward", 0x23e9 }, - { "information_source", 0x2139 }, - { "ok", 0x1f197 }, - { "twisted_rightwards_arrows", 0x1f500 }, - { "repeat", 0x1f501 }, - { "repeat_one", 0x1f502 }, - { "new", 0x1f195 }, - { "top", 0x1f51d }, - { "up", 0x1f199 }, - { "cool", 0x1f192 }, - { "free", 0x1f193 }, - { "ng", 0x1f196 }, - { "cinema", 0x1f3a6 }, - { "koko", 0x1f201 }, - { "signal_strength", 0x1f4f6 }, - { "u5272", 0x1f239 }, - { "u5408", 0x1f234 }, - { "u55b6", 0x1f23a }, - { "u6307", 0x1f22f }, - { "u6708", 0x1f237 }, - { "u6709", 0x1f236 }, - { "u6e80", 0x1f235 }, - { "u7121", 0x1f21a }, - { "u7533", 0x1f238 }, - { "u7a7a", 0x1f233 }, - { "u7981", 0x1f232 }, - { "sa", 0x1f202 }, - { "restroom", 0x1f6bb }, - { "mens", 0x1f6b9 }, - { "womens", 0x1f6ba }, - { "baby_symbol", 0x1f6bc }, - { "no_smoking", 0x1f6ad }, - { "parking", 0x1f17f }, - { "wheelchair", 0x267f }, - { "metro", 0x1f687 }, - { "baggage_claim", 0x1f6c4 }, - { "accept", 0x1f251 }, - { "wc", 0x1f6be }, - { "potable_water", 0x1f6b0 }, - { "put_litter_in_its_place", 0x1f6ae }, - { "secret", 0x3299 }, - { "congratulations", 0x3297 }, - { "m", 0x24c2 }, - { "passport_control", 0x1f6c2 }, - { "left_luggage", 0x1f6c5 }, - { "customs", 0x1f6c3 }, - { "ideograph_advantage", 0x1f250 }, - { "cl", 0x1f191 }, - { "sos", 0x1f198 }, - { "id", 0x1f194 }, - { "no_entry_sign", 0x1f6ab }, - { "underage", 0x1f51e }, - { "no_mobile_phones", 0x1f4f5 }, - { "do_not_litter", 0x1f6af }, - { "non-potable_water", 0x1f6b1 }, - { "no_bicycles", 0x1f6b3 }, - { "no_pedestrians", 0x1f6b7 }, - { "children_crossing", 0x1f6b8 }, - { "no_entry", 0x26d4 }, - { "eight_spoked_asterisk", 0x2733 }, - { "eight_pointed_black_star", 0x2734 }, - { "heart_decoration", 0x1f49f }, - { "vs", 0x1f19a }, - { "vibration_mode", 0x1f4f3 }, - { "mobile_phone_off", 0x1f4f4 }, - { "chart", 0x1f4b9 }, - { "currency_exchange", 0x1f4b1 }, - { "aries", 0x2648 }, - { "taurus", 0x2649 }, - { "gemini", 0x264a }, - { "cancer", 0x264b }, - { "leo", 0x264c }, - { "virgo", 0x264d }, - { "libra", 0x264e }, - { "scorpius", 0x264f }, - { "sagittarius", 0x2650 }, - { "capricorn", 0x2651 }, - { "aquarius", 0x2652 }, - { "pisces", 0x2653 }, - { "ophiuchus", 0x26ce }, - { "six_pointed_star", 0x1f52f }, - { "negative_squared_cross_mark", 0x274e }, - { "a", 0x1f170 }, - { "b", 0x1f171 }, - { "ab", 0x1f18e }, - { "o2", 0x1f17e }, - { "diamond_shape_with_a_dot_inside", 0x1f4a0 }, - { "recycle", 0x267b }, - { "end", 0x1f51a }, - { "on", 0x1f51b }, - { "soon", 0x1f51c }, - { "clock1", 0x1f550 }, - { "clock130", 0x1f55c }, - { "clock10", 0x1f559 }, - { "clock1030", 0x1f565 }, - { "clock11", 0x1f55a }, - { "clock1130", 0x1f566 }, - { "clock12", 0x1f55b }, - { "clock1230", 0x1f567 }, - { "clock2", 0x1f551 }, - { "clock230", 0x1f55d }, - { "clock3", 0x1f552 }, - { "clock330", 0x1f55e }, - { "clock4", 0x1f553 }, - { "clock430", 0x1f55f }, - { "clock5", 0x1f554 }, - { "clock530", 0x1f560 }, - { "clock6", 0x1f555 }, - { "clock630", 0x1f561 }, - { "clock7", 0x1f556 }, - { "clock730", 0x1f562 }, - { "clock8", 0x1f557 }, - { "clock830", 0x1f563 }, - { "clock9", 0x1f558 }, - { "clock930", 0x1f564 }, - { "heavy_dollar_sign", 0x1f4b2 }, - { "copyright", 0x00a9 }, - { "registered", 0x00ae }, - { "tm", 0x2122 }, - { "x", 0x274c }, - { "heavy_exclamation_mark", 0x2757 }, - { "bangbang", 0x203c }, - { "interrobang", 0x2049 }, - { "o", 0x2b55 }, - { "heavy_multiplication_x", 0x2716 }, - { "heavy_plus_sign", 0x2795 }, - { "heavy_minus_sign", 0x2796 }, - { "heavy_division_sign", 0x2797 }, - { "white_flower", 0x1f4ae }, - { "100", 0x1f4af }, - { "heavy_check_mark", 0x2714 }, - { "ballot_box_with_check", 0x2611 }, - { "radio_button", 0x1f518 }, - { "link", 0x1f517 }, - { "curly_loop", 0x27b0 }, - { "wavy_dash", 0x3030 }, - { "part_alternation_mark", 0x303d }, - { "trident", 0x1f531 }, - { "white_check_mark", 0x2705 }, - { "black_square_button", 0x1f532 }, - { "white_square_button", 0x1f533 }, - { "black_circle", 0x26ab }, - { "white_circle", 0x26aa }, - { "red_circle", 0x1f534 }, - { "large_blue_circle", 0x1f535 }, - { "large_blue_diamond", 0x1f537 }, - { "large_orange_diamond", 0x1f536 }, - { "small_blue_diamond", 0x1f539 }, - { "small_orange_diamond", 0x1f538 }, - { "small_red_triangle", 0x1f53a }, - { "small_red_triangle_down", 0x1f53b }, - }; - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.cs deleted file mode 100644 index e79011132..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/EmojiInline.cs +++ /dev/null @@ -1,85 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing emoji symbol. - /// - public partial class EmojiInline : MarkdownInline, IInlineLeaf - { - /// - /// Initializes a new instance of the class. - /// - public EmojiInline() - : base(MarkdownInlineType.Emoji) - { - } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = ':', Method = InlineParseMethod.Emoji }); - } - - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - if (start >= maxEnd - 1) - { - return null; - } - - // Check the start sequence. - string startSequence = markdown.Substring(start, 1); - if (startSequence != ":") - { - return null; - } - - // Find the end of the span. - var innerStart = start + 1; - int innerEnd = Common.IndexOf(markdown, startSequence, innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // The first character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart])) - { - return null; - } - - // The last character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - var emojiName = markdown.Substring(innerStart, innerEnd - innerStart); - - if (_emojiCodesDictionary.TryGetValue(emojiName, out var emojiCode)) - { - var result = new EmojiInline { Text = char.ConvertFromUtf32(emojiCode), Type = MarkdownInlineType.Emoji }; - return new InlineParseResult(result, start, innerEnd + 1); - } - - return null; - } - - /// - public string Text { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/HyperlinkInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/HyperlinkInline.cs deleted file mode 100644 index 9ccb5b442..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/HyperlinkInline.cs +++ /dev/null @@ -1,477 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Linq; - - /// - /// Represents a type of hyperlink where the text and the target URL cannot be controlled - /// independently. - /// - public class HyperlinkInline : MarkdownInline, IInlineLeaf, ILinkElement - { - /// - /// Initializes a new instance of the class. - /// - public HyperlinkInline() - : base(MarkdownInlineType.RawHyperlink) - { - } - - /// - /// Gets or sets the text to display. - /// - public string Text { get; set; } - - /// - /// Gets or sets the URL to link to. - /// - public string Url { get; set; } - - /// - /// Gets this type of hyperlink does not have a tooltip. - /// - string ILinkElement.Tooltip => null; - - /// - /// Gets or sets the type of hyperlink. - /// - public HyperlinkType LinkType { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '<', Method = InlineParseMethod.AngleBracketLink }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = ':', Method = InlineParseMethod.Url }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '/', Method = InlineParseMethod.RedditLink }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '.', Method = InlineParseMethod.PartialLink }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '@', Method = InlineParseMethod.Email }); - } - - /// - /// Attempts to parse a URL within angle brackets e.g. "http://www.reddit.com". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed URL, or null if this is not a URL. - internal static InlineParseResult ParseAngleBracketLink(string markdown, int start, int maxEnd) - { - int innerStart = start + 1; - - // Check for a known scheme e.g. "https://". - int pos = -1; - foreach (var scheme in MarkdownDocument.KnownSchemes) - { - if (maxEnd - innerStart >= scheme.Length && string.Equals(markdown.Substring(innerStart, scheme.Length), scheme, StringComparison.OrdinalIgnoreCase)) - { - // URL scheme found. - pos = innerStart + scheme.Length; - break; - } - } - - if (pos == -1) - { - return null; - } - - // Angle bracket links should not have any whitespace. - int innerEnd = markdown.IndexOfAny(new char[] { ' ', '\t', '\r', '\n', '>' }, pos, maxEnd - pos); - if (innerEnd == -1 || markdown[innerEnd] != '>') - { - return null; - } - - // There should be at least one character after the http://. - if (innerEnd == pos) - { - return null; - } - - var url = markdown.Substring(innerStart, innerEnd - innerStart); - return new InlineParseResult(new HyperlinkInline { Url = url, Text = url, LinkType = HyperlinkType.BracketedUrl }, start, innerEnd + 1); - } - - /// - /// Attempts to parse a URL e.g. "http://www.reddit.com". - /// - /// The markdown text. - /// The location of the colon character. - /// The location to stop parsing. - /// A parsed URL, or null if this is not a URL. - internal static InlineParseResult ParseUrl(string markdown, int tripPos, int maxEnd) - { - int start = -1; - - // Check for a known scheme e.g. "https://". - foreach (var scheme in MarkdownDocument.KnownSchemes) - { - int schemeStart = tripPos - scheme.Length; - if (schemeStart >= 0 && schemeStart <= maxEnd - scheme.Length && string.Equals(markdown.Substring(schemeStart, scheme.Length), scheme, StringComparison.OrdinalIgnoreCase)) - { - // URL scheme found. - start = schemeStart; - break; - } - } - - if (start == -1) - { - return null; - } - - // The previous character must be non-alphanumeric i.e. "ahttp://t.co" is not a valid URL. - if (start > 0 && char.IsLetter(markdown[start - 1])) - { - return null; - } - - // The URL must have at least one character after the http:// and at least one dot. - int pos = tripPos + 3; - if (pos > maxEnd) - { - return null; - } - - int dotIndex = markdown.IndexOf('.', pos, maxEnd - pos); - if (dotIndex == -1 || dotIndex == pos) - { - return null; - } - - // Find the end of the URL. - int end = FindUrlEnd(markdown, dotIndex + 1, maxEnd); - - var url = markdown.Substring(start, end - start); - return new InlineParseResult(new HyperlinkInline { Url = url, Text = url, LinkType = HyperlinkType.FullUrl }, start, end); - } - - /// - /// Attempts to parse a subreddit link e.g. "/r/news" or "r/news". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed subreddit or user link, or null if this is not a subreddit link. - internal static InlineParseResult ParseRedditLink(string markdown, int start, int maxEnd) - { - var result = ParseDoubleSlashLink(markdown, start, maxEnd); - if (result != null) - { - return result; - } - - return ParseSingleSlashLink(markdown, start, maxEnd); - } - - /// - /// Parse a link of the form "/r/news" or "/u/quinbd". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed subreddit or user link, or null if this is not a subreddit link. - private static InlineParseResult ParseDoubleSlashLink(string markdown, int start, int maxEnd) - { - // The minimum length is 4 characters ("/u/u"). - if (start > maxEnd - 4) - { - return null; - } - - // Determine the type of link (subreddit or user). - HyperlinkType linkType; - if (markdown[start + 1] == 'r') - { - linkType = HyperlinkType.Subreddit; - } - else if (markdown[start + 1] == 'u') - { - linkType = HyperlinkType.User; - } - else - { - return null; - } - - // Check that there is another slash. - if (markdown[start + 2] != '/') - { - return null; - } - - // Find the end of the link. - int end = FindEndOfRedditLink(markdown, start + 3, maxEnd); - - // Subreddit names must be at least two characters long, users at least one. - if (end - start < (linkType == HyperlinkType.User ? 4 : 5)) - { - return null; - } - - // We found something! - var text = markdown.Substring(start, end - start); - return new InlineParseResult(new HyperlinkInline { Text = text, Url = text, LinkType = linkType }, start, end); - } - - /// - /// Parse a link of the form "r/news" or "u/quinbd". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed subreddit or user link, or null if this is not a subreddit link. - private static InlineParseResult ParseSingleSlashLink(string markdown, int start, int maxEnd) - { - // The minimum length is 3 characters ("u/u"). - start--; - if (start < 0 || start > maxEnd - 3) - { - return null; - } - - // Determine the type of link (subreddit or user). - HyperlinkType linkType; - if (markdown[start] == 'r') - { - linkType = HyperlinkType.Subreddit; - } - else if (markdown[start] == 'u') - { - linkType = HyperlinkType.User; - } - else - { - return null; - } - - // If the link doesn't start with '/', then the previous character must be - // non-alphanumeric i.e. "bear/trap" is not a valid subreddit link. - if (start >= 1 && (char.IsLetterOrDigit(markdown[start - 1]) || markdown[start - 1] == '/')) - { - return null; - } - - // Find the end of the link. - int end = FindEndOfRedditLink(markdown, start + 2, maxEnd); - - // Subreddit names must be at least two characters long, users at least one. - if (end - start < (linkType == HyperlinkType.User ? 3 : 4)) - { - return null; - } - - // We found something! - var text = markdown.Substring(start, end - start); - return new InlineParseResult(new HyperlinkInline { Text = text, Url = "/" + text, LinkType = linkType }, start, end); - } - - /// - /// Attempts to parse a URL without a scheme e.g. "www.reddit.com". - /// - /// The markdown text. - /// The location of the dot character. - /// The location to stop parsing. - /// A parsed URL, or null if this is not a URL. - internal static InlineParseResult ParsePartialLink(string markdown, int tripPos, int maxEnd) - { - int start = tripPos - 3; - if (start < 0 || markdown[start] != 'w' || markdown[start + 1] != 'w' || markdown[start + 2] != 'w') - { - return null; - } - - // The character before the "www" must be non-alphanumeric i.e. "bwww.reddit.com" is not a valid URL. - if (start >= 1 && (char.IsLetterOrDigit(markdown[start - 1]) || markdown[start - 1] == '<')) - { - return null; - } - - // The URL must have at least one character after the www. - if (start >= maxEnd - 4) - { - return null; - } - - // Find the end of the URL. - int end = FindUrlEnd(markdown, start + 4, maxEnd); - - var url = markdown.Substring(start, end - start); - return new InlineParseResult(new HyperlinkInline { Url = "http://" + url, Text = url, LinkType = HyperlinkType.PartialUrl }, start, end); - } - - /// - /// Attempts to parse an email address e.g. "test@reddit.com". - /// - /// The markdown text. - /// The minimum start position to return. - /// The location of the at character. - /// The location to stop parsing. - /// A parsed URL, or null if this is not a URL. - internal static InlineParseResult ParseEmailAddress(string markdown, int minStart, int tripPos, int maxEnd) - { - // Search backwards until we find a character which is not a letter, digit, or one of - // these characters: '+', '-', '_', '.'. - // Note: it is intended that this code match the reddit.com markdown parser; there are - // many characters which are legal in email addresses but which aren't picked up by - // reddit (for example: '$' and '!'). - - // Special characters as per https://en.wikipedia.org/wiki/Email_address#Local-part allowed - char[] allowedchars = new char[] { '!', '#', '$', '%', '&', '\'', '*', '+', '-', '/', '=', '?', '^', '_', '`', '{', '|', '}', '~' }; - - int start = tripPos; - while (start > minStart) - { - char c = markdown[start - 1]; - if ((c < 'a' || c > 'z') && - (c < 'A' || c > 'Z') && - (c < '0' || c > '9') && - !allowedchars.Contains(c)) - { - break; - } - - start--; - } - - // There must be at least one character before the '@'. - if (start == tripPos) - { - return null; - } - - // Search forwards until we find a character which is not a letter, digit, or one of - // these characters: '-', '_'. - // Note: it is intended that this code match the reddit.com markdown parser; - // technically underscores ('_') aren't allowed in a host name. - int dotIndex = tripPos + 1; - while (dotIndex < maxEnd) - { - char c = markdown[dotIndex]; - if ((c < 'a' || c > 'z') && - (c < 'A' || c > 'Z') && - (c < '0' || c > '9') && - c != '-' && c != '_') - { - break; - } - - dotIndex++; - } - - // We are expecting a dot. - if (dotIndex == maxEnd || markdown[dotIndex] != '.') - { - return null; - } - - // Search forwards until we find a character which is not a letter, digit, or one of - // these characters: '.', '-', '_'. - // Note: it is intended that this code match the reddit.com markdown parser; - // technically underscores ('_') aren't allowed in a host name. - int end = dotIndex + 1; - while (end < maxEnd) - { - char c = markdown[end]; - if ((c < 'a' || c > 'z') && - (c < 'A' || c > 'Z') && - (c < '0' || c > '9') && - c != '.' && c != '-' && c != '_') - { - break; - } - - end++; - } - - // There must be at least one character after the dot. - if (end == dotIndex + 1) - { - return null; - } - - // We found an email address! - var emailAddress = markdown.Substring(start, end - start); - return new InlineParseResult(new HyperlinkInline { Url = "mailto:" + emailAddress, Text = emailAddress, LinkType = HyperlinkType.Email }, start, end); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Text == null) - { - return base.ToString(); - } - - return Text; - } - - /// - /// Finds the next character that is not a letter, digit or underscore in a range. - /// - /// The markdown text. - /// The location to start searching. - /// The location to stop searching. - /// The location of the next character that is not a letter, digit or underscore. - private static int FindEndOfRedditLink(string markdown, int start, int end) - { - int pos = start; - while (pos < markdown.Length && pos < end) - { - char c = markdown[pos]; - if ((c < 'a' || c > 'z') && - (c < 'A' || c > 'Z') && - (c < '0' || c > '9') && - c != '_' && c != '/') - { - return pos; - } - - pos++; - } - - return end; - } - - /// - /// Finds the end of a URL. - /// - /// The markdown text. - /// The location to start searching. - /// The location to stop searching. - /// The location of the end of the URL. - private static int FindUrlEnd(string markdown, int start, int maxEnd) - { - // For some reason a less than character ends a URL... - int end = markdown.IndexOfAny(new char[] { ' ', '\t', '\r', '\n', '<' }, start, maxEnd - start); - if (end == -1) - { - end = maxEnd; - } - - // URLs can't end on a punctuation character. - while (end - 1 > start) - { - if (Array.IndexOf(new char[] { ')', '}', ']', '!', ';', '.', '?', ',' }, markdown[end - 1]) < 0) - { - break; - } - - end--; - } - - return end; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineContainer.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineContainer.cs deleted file mode 100644 index 88fa2e3f1..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineContainer.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Initializes a new instance of the class. - /// - public interface IInlineContainer - { - /// - /// Gets or sets the contents of the inline. - /// - IList Inlines { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineLeaf.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineLeaf.cs deleted file mode 100644 index adeaea01d..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/IInlineLeaf.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - /// - /// Initializes a new instance of the class. - /// - public interface IInlineLeaf - { - /// - /// Gets or sets the text for this run. - /// - string Text { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ILinkElement.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ILinkElement.cs deleted file mode 100644 index 5dabbadd7..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ILinkElement.cs +++ /dev/null @@ -1,25 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - /// - /// Implemented by all inline link elements. - /// - internal interface ILinkElement - { - /// - /// Gets the link URL. This can be a relative URL, but note that subreddit links will always - /// have the leading slash (i.e. the Url will be "/r/baconit" even if the text is - /// "r/baconit"). - /// - string Url { get; } - - /// - /// Gets a tooltip to display on hover. Can be null. - /// - string Tooltip { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ImageInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ImageInline.cs deleted file mode 100644 index bec1687b9..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ImageInline.cs +++ /dev/null @@ -1,258 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - - /// - /// Represents an embedded image. - /// - public class ImageInline : MarkdownInline, IInlineLeaf - { - /// - /// Initializes a new instance of the class. - /// - public ImageInline() - : base(MarkdownInlineType.Image) - { - } - - /// - /// Gets or sets the image URL. - /// - public string Url { get; set; } - - /// - /// Gets or sets the image Render URL. - /// - public string RenderUrl { get; set; } - - /// - /// Gets or sets a text to display on hover. - /// - public string Tooltip { get; set; } - - /// - public string Text { get; set; } = string.Empty; - - /// - /// Gets or sets the ID of a reference, if this is a reference-style link. - /// - public string ReferenceId { get; set; } - - /// - /// Gets image width - /// If value is greater than 0, ImageStretch is set to UniformToFill - /// If both ImageWidth and ImageHeight are greater than 0, ImageStretch is set to Fill - /// - public int ImageWidth { get; internal set; } - - /// - /// Gets image height - /// If value is greater than 0, ImageStretch is set to UniformToFill - /// If both ImageWidth and ImageHeight are greater than 0, ImageStretch is set to Fill - /// - public int ImageHeight { get; internal set; } - - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '!', Method = InlineParseMethod.Image }); - } - - /// - /// Attempts to parse an image e.g. "![Toolkit logo](https://raw.githubusercontent.com/windows-toolkit/WindowsCommunityToolkit/master/Microsoft.Toolkit.Uwp.SampleApp/Assets/ToolkitLogo.png)". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed markdown image, or null if this is not a markdown image. - internal static InlineParseResult Parse(string markdown, int start, int end) - { - // Expect a '!' character. - if (start >= end || markdown[start] != '!') - { - return null; - } - - int pos = start + 1; - - // Then a '[' character - if (pos >= end || markdown[pos] != '[') - { - return null; - } - - pos++; - - // Find the ']' character - while (pos < end) - { - if (markdown[pos] == ']') - { - break; - } - - pos++; - } - - if (pos == end) - { - return null; - } - - // Extract the alt. - string tooltip = markdown.Substring(start + 2, pos - (start + 2)); - - // Expect the '(' character. - pos++; - - string reference = string.Empty; - string url = string.Empty; - int imageWidth = 0; - int imageHeight = 0; - - if (pos < end && markdown[pos] == '[') - { - int refstart = pos; - - // Find the reference ']' character - while (pos < end) - { - if (markdown[pos] == ']') - { - break; - } - - pos++; - } - - reference = markdown.Substring(refstart + 1, pos - refstart - 1); - } - else if (pos < end && markdown[pos] == '(') - { - while (pos < end && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - // Extract the URL. - int urlStart = pos; - while (pos < end && markdown[pos] != ')') - { - pos++; - } - - var imageDimensionsPos = markdown.IndexOf(" =", urlStart, pos - urlStart, StringComparison.Ordinal); - - url = imageDimensionsPos > 0 - ? TextRunInline.ResolveEscapeSequences(markdown, urlStart + 1, imageDimensionsPos) - : TextRunInline.ResolveEscapeSequences(markdown, urlStart + 1, pos); - - if (imageDimensionsPos > 0) - { - // trying to find 'x' which separates image width and height - var dimensionsSepatorPos = markdown.IndexOf("x", imageDimensionsPos + 2, pos - imageDimensionsPos - 1, StringComparison.Ordinal); - - // didn't find separator, trying to parse value as imageWidth - if (dimensionsSepatorPos == -1) - { - var imageWidthStr = markdown.Substring(imageDimensionsPos + 2, pos - imageDimensionsPos - 2); - - _ = int.TryParse(imageWidthStr, out imageWidth); - } - else - { - var dimensions = markdown.Substring(imageDimensionsPos + 2, pos - imageDimensionsPos - 2).Split('x'); - - // got width and height - if (dimensions.Length == 2) - { - _ = int.TryParse(dimensions[0], out imageWidth); - _ = int.TryParse(dimensions[1], out imageHeight); - } - } - } - } - - if (pos == end) - { - return null; - } - - // We found something! - var result = new ImageInline - { - Tooltip = tooltip, - RenderUrl = url, - ReferenceId = reference, - Url = url, - Text = markdown.Substring(start, pos + 1 - start), - ImageWidth = imageWidth, - ImageHeight = imageHeight - }; - return new InlineParseResult(result, start, pos + 1); - } - - /// - /// If this is a reference-style link, attempts to converts it to a regular link. - /// - /// The document containing the list of references. - internal void ResolveReference(MarkdownDocument document) - { - if (document == null) - { - throw new ArgumentNullException(nameof(document)); - } - - if (ReferenceId == null) - { - return; - } - - // Look up the reference ID. - var reference = document.LookUpReference(ReferenceId); - if (reference == null) - { - return; - } - - // The reference was found. Check the URL is valid. - if (!Common.IsUrlValid(reference.Url)) - { - return; - } - - // Everything is cool when you're part of a team. - RenderUrl = reference.Url; - ReferenceId = null; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (ImageWidth > 0 && ImageHeight > 0) - { - return $"![{Tooltip}]: {Url} (Width: {ImageWidth}, Height: {ImageHeight})"; - } - - if (ImageWidth > 0) - { - return $"![{Tooltip}]: {Url} (Width: {ImageWidth})"; - } - - if (ImageHeight > 0) - { - return $"![{Tooltip}]: {Url} (Height: {ImageHeight})"; - } - - return $"![{Tooltip}]: {Url}"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ItalicTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ItalicTextInline.cs deleted file mode 100644 index fa7a26b09..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/ItalicTextInline.cs +++ /dev/null @@ -1,102 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing italic text. - /// - public class ItalicTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public ItalicTextInline() - : base(MarkdownInlineType.Italic) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '*', Method = InlineParseMethod.Italic }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '_', Method = InlineParseMethod.Italic }); - } - - /// - /// Attempts to parse a italic text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed italic text span, or null if this is not a italic text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Check the first char. - char startChar = markdown[start]; - if (start == maxEnd || (startChar != '*' && startChar != '_')) - { - return null; - } - - // Find the end of the span. The end character (either '*' or '_') must be the same as - // the start character. - var innerStart = start + 1; - int innerEnd = Common.IndexOf(markdown, startChar, start + 1, maxEnd); - if (innerEnd == -1) - { - return null; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // The first character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart])) - { - return null; - } - - // The last character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - var result = new ItalicTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, innerEnd + 1); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "*" + string.Join(string.Empty, Inlines) + "*"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/LinkAnchorInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/LinkAnchorInline.cs deleted file mode 100644 index 30310d0b6..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/LinkAnchorInline.cs +++ /dev/null @@ -1,124 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - using System.Xml.Linq; - - /// - /// Represents a span that contains a reference for links to point to. - /// - public class LinkAnchorInline : MarkdownInline - { - internal LinkAnchorInline() - : base(MarkdownInlineType.LinkReference) - { - } - - /// - /// Gets or sets the Name of this Link Reference. - /// - public string Link { get; set; } - - /// - /// Gets or sets the raw Link Reference. - /// - public string Raw { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '<', Method = InlineParseMethod.LinkReference }); - } - - /// - /// Attempts to parse a comment span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed bold text span, or null if this is not a bold text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - if (start >= maxEnd - 1) - { - return null; - } - - // Check the start sequence. - string startSequence = markdown.Substring(start, 2); - if (startSequence != "') - var innerStart = start + 2; - int innerEnd = Common.IndexOf(markdown, "", innerStart, maxEnd); - int trueEnd = innerEnd + 4; - if (innerEnd == -1) - { - innerEnd = Common.IndexOf(markdown, "/>", innerStart, maxEnd); - trueEnd = innerEnd + 2; - if (innerEnd == -1) - { - return null; - } - } - - // This link Reference wasn't closed properly if the next link starts before a close. - var nextLink = Common.IndexOf(markdown, " -1 && nextLink < innerEnd) - { - return null; - } - - var length = trueEnd - start; - var contents = markdown.Substring(start, length); - - string link = null; - - try - { - var xml = XElement.Parse(contents); - var attr = xml.Attribute("name"); - if (attr != null) - { - link = attr.Value; - } - } - catch - { - // Attempting to fetch link failed, ignore and continue. - } - - // Remove whitespace if it exists. - if (trueEnd + 1 <= maxEnd && markdown[trueEnd] == ' ') - { - trueEnd += 1; - } - - // We found something! - var result = new LinkAnchorInline - { - Raw = contents, - Link = link - }; - return new InlineParseResult(result, start, trueEnd); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - return Raw; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/MarkdownLinkInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/MarkdownLinkInline.cs deleted file mode 100644 index dffa7770d..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/MarkdownLinkInline.cs +++ /dev/null @@ -1,290 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using Microsoft.Toolkit.Extensions; - - /// - /// Represents a type of hyperlink where the text can be different from the target URL. - /// - public class MarkdownLinkInline : MarkdownInline, IInlineContainer, ILinkElement - { - /// - /// Initializes a new instance of the class. - /// - public MarkdownLinkInline() - : base(MarkdownInlineType.MarkdownLink) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Gets or sets the link URL. - /// - public string Url { get; set; } - - /// - /// Gets or sets a tooltip to display on hover. - /// - public string Tooltip { get; set; } - - /// - /// Gets or sets the ID of a reference, if this is a reference-style link. - /// - public string ReferenceId { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '[', Method = InlineParseMethod.MarkdownLink }); - } - - /// - /// Attempts to parse a markdown link e.g. "[](http://www.reddit.com)". - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed markdown link, or null if this is not a markdown link. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Expect a '[' character. - if (start == maxEnd || markdown[start] != '[') - { - return null; - } - - // Find the ']' character, keeping in mind that [test [0-9]](http://www.test.com) is allowed. - int linkTextOpen = start + 1; - int pos = linkTextOpen; - int linkTextClose; - int openSquareBracketCount = 0; - while (true) - { - linkTextClose = markdown.IndexOfAny(new char[] { '[', ']' }, pos, maxEnd - pos); - if (linkTextClose == -1) - { - return null; - } - - if (markdown[linkTextClose] == '[') - { - openSquareBracketCount++; - } - else if (openSquareBracketCount > 0) - { - openSquareBracketCount--; - } - else - { - break; - } - - pos = linkTextClose + 1; - } - - // Skip whitespace. - pos = linkTextClose + 1; - while (pos < maxEnd && ParseHelpers.IsMarkdownWhiteSpace(markdown[pos])) - { - pos++; - } - - if (pos == maxEnd) - { - return null; - } - - // Expect the '(' character or the '[' character. - int linkOpen = pos; - if (markdown[pos] == '(') - { - // Skip whitespace. - linkOpen++; - while (linkOpen < maxEnd && ParseHelpers.IsMarkdownWhiteSpace(markdown[linkOpen])) - { - linkOpen++; - } - - // Find the ')' character. - pos = linkOpen; - int linkClose = -1; - var openParenthesis = 0; - while (pos < maxEnd) - { - if (markdown[pos] == ')') - { - if (openParenthesis == 0) - { - linkClose = pos; - break; - } - else - { - openParenthesis--; - } - } - - if (markdown[pos] == '(') - { - openParenthesis++; - } - - pos++; - } - - if (pos >= maxEnd) - { - return null; - } - - int end = linkClose + 1; - - // Skip whitespace backwards. - while (linkClose > linkOpen && ParseHelpers.IsMarkdownWhiteSpace(markdown[linkClose - 1])) - { - linkClose--; - } - - // If there is no text whatsoever, then this is not a valid link. - if (linkOpen == linkClose) - { - return null; - } - - // Check if there is tooltip text. - string url; - string tooltip = null; - bool lastUrlCharIsDoubleQuote = markdown[linkClose - 1] == '"'; - int tooltipStart = Common.IndexOf(markdown, " \"", linkOpen, linkClose - 1); - if (tooltipStart == linkOpen) - { - return null; - } - - if (lastUrlCharIsDoubleQuote && tooltipStart != -1) - { - // Extract the URL (resolving any escape sequences). - url = TextRunInline.ResolveEscapeSequences(markdown, linkOpen, tooltipStart).TrimEnd(' ', '\t', '\r', '\n'); - tooltip = markdown.Substring(tooltipStart + 2, (linkClose - 1) - (tooltipStart + 2)); - } - else - { - // Extract the URL (resolving any escape sequences). - url = TextRunInline.ResolveEscapeSequences(markdown, linkOpen, linkClose); - } - - // Check the URL is okay. - if (!url.IsEmail()) - { - if (!Common.IsUrlValid(url)) - { - return null; - } - } - else - { - tooltip = url = $"mailto:{url}"; - } - - // We found a regular stand-alone link. - var result = new MarkdownLinkInline - { - Inlines = Common.ParseInlineChildren(markdown, linkTextOpen, linkTextClose, ignoreLinks: true), - Url = url.Replace(" ", "%20", StringComparison.Ordinal), - Tooltip = tooltip - }; - return new InlineParseResult(result, start, end); - } - else if (markdown[pos] == '[') - { - // Find the ']' character. - int linkClose = Common.IndexOf(markdown, ']', pos + 1, maxEnd); - if (linkClose == -1) - { - return null; - } - - // We found a reference-style link. - var result = new MarkdownLinkInline - { - Inlines = Common.ParseInlineChildren(markdown, linkTextOpen, linkTextClose, ignoreLinks: true), - ReferenceId = markdown.Substring(linkOpen + 1, linkClose - (linkOpen + 1)) - }; - if (string.IsNullOrEmpty(result.ReferenceId)) - { - result.ReferenceId = markdown.Substring(linkTextOpen, linkTextClose - linkTextOpen); - } - - return new InlineParseResult(result, start, linkClose + 1); - } - - return null; - } - - /// - /// If this is a reference-style link, attempts to converts it to a regular link. - /// - /// The document containing the list of references. - internal void ResolveReference(MarkdownDocument document) - { - if (document == null) - { - throw new ArgumentNullException(nameof(document)); - } - - if (ReferenceId == null) - { - return; - } - - // Look up the reference ID. - var reference = document.LookUpReference(ReferenceId); - if (reference == null) - { - return; - } - - // The reference was found. Check the URL is valid. - if (!Common.IsUrlValid(reference.Url)) - { - return; - } - - // Everything is cool when you're part of a team. - Url = reference.Url; - Tooltip = reference.Tooltip; - ReferenceId = null; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null || Url == null) - { - return base.ToString(); - } - - if (ReferenceId != null) - { - return $"[{string.Join(string.Empty, Inlines)}][{ReferenceId}]"; - } - - return $"[{string.Join(string.Empty, Inlines)}]({Url})"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/StrikethroughTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/StrikethroughTextInline.cs deleted file mode 100644 index e99719405..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/StrikethroughTextInline.cs +++ /dev/null @@ -1,99 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing strikethrough text. - /// - public class StrikethroughTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public StrikethroughTextInline() - : base(MarkdownInlineType.Strikethrough) - { - } - - /// - /// Gets or sets The contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '~', Method = InlineParseMethod.Strikethrough }); - } - - /// - /// Attempts to parse a strikethrough text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed strikethrough text span, or null if this is not a strikethrough text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Check the start sequence. - if (start >= maxEnd - 1 || markdown.Substring(start, 2) != "~~") - { - return null; - } - - // Find the end of the span. - var innerStart = start + 2; - int innerEnd = Common.IndexOf(markdown, "~~", innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - // The span must contain at least one character. - if (innerStart == innerEnd) - { - return null; - } - - // The first character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart])) - { - return null; - } - - // The last character inside the span must NOT be a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - var result = new StrikethroughTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, innerEnd + 2); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "~~" + string.Join(string.Empty, Inlines) + "~~"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SubscriptTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SubscriptTextInline.cs deleted file mode 100644 index c20d79c40..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SubscriptTextInline.cs +++ /dev/null @@ -1,94 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing subscript text. - /// - public class SubscriptTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public SubscriptTextInline() - : base(MarkdownInlineType.Subscript) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '<', Method = InlineParseMethod.Subscript }); - } - - /// - /// Attempts to parse a subscript text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed subscript text span, or null if this is not a subscript text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Check the first character. - // e.g. "……" - if (maxEnd - start < 5) - { - return null; - } - - if (markdown.Substring(start, 5) != "") - { - return null; - } - - int innerStart = start + 5; - int innerEnd = Common.IndexOf(markdown, "", innerStart, maxEnd); - - // if don't have the end character or no character between start and end - if (innerEnd == -1 || innerEnd == innerStart) - { - return null; - } - - // No match if the character after the caret is a space. - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]) || ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - var result = new SubscriptTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, innerEnd + 6); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "" + string.Join(string.Empty, Inlines) + ""; - } - } -} diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SuperscriptTextInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SuperscriptTextInline.cs deleted file mode 100644 index d9c4ba858..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/SuperscriptTextInline.cs +++ /dev/null @@ -1,150 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - - /// - /// Represents a span containing superscript text. - /// - public class SuperscriptTextInline : MarkdownInline, IInlineContainer - { - /// - /// Initializes a new instance of the class. - /// - public SuperscriptTextInline() - : base(MarkdownInlineType.Superscript) - { - } - - /// - /// Gets or sets the contents of the inline. - /// - public IList Inlines { get; set; } - - /// - /// Returns the chars that if found means we might have a match. - /// - internal static void AddTripChars(List tripCharHelpers) - { - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '^', Method = InlineParseMethod.Superscript }); - tripCharHelpers.Add(new InlineTripCharHelper() { FirstChar = '<', Method = InlineParseMethod.Superscript }); - } - - /// - /// Attempts to parse a superscript text span. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed superscript text span, or null if this is not a superscript text span. - internal static InlineParseResult Parse(string markdown, int start, int maxEnd) - { - // Check the first character. - bool isHTMLSequence = false; - if (start == maxEnd || (markdown[start] != '^' && markdown[start] != '<')) - { - return null; - } - - if (markdown[start] != '^') - { - if (maxEnd - start < 5) - { - return null; - } - else if (markdown.Substring(start, 5) != "") - { - return null; - } - else - { - isHTMLSequence = true; - } - } - - if (isHTMLSequence) - { - int innerStart = start + 5; - int innerEnd, end; - innerEnd = Common.IndexOf(markdown, "", innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - if (innerEnd == innerStart) - { - return null; - } - - if (ParseHelpers.IsMarkdownWhiteSpace(markdown[innerStart]) || ParseHelpers.IsMarkdownWhiteSpace(markdown[innerEnd - 1])) - { - return null; - } - - // We found something! - end = innerEnd + 6; - var result = new SuperscriptTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, end); - } - else - { - // The content might be enclosed in parentheses. - int innerStart = start + 1; - int innerEnd, end; - if (innerStart < maxEnd && markdown[innerStart] == '(') - { - // Find the end parenthesis. - innerStart++; - innerEnd = Common.IndexOf(markdown, ')', innerStart, maxEnd); - if (innerEnd == -1) - { - return null; - } - - end = innerEnd + 1; - } - else - { - // Search for the next whitespace character. - innerEnd = Common.FindNextWhiteSpace(markdown, innerStart, maxEnd, ifNotFoundReturnLength: true); - if (innerEnd == innerStart) - { - // No match if the character after the caret is a space. - return null; - } - - end = innerEnd; - } - - // We found something! - var result = new SuperscriptTextInline - { - Inlines = Common.ParseInlineChildren(markdown, innerStart, innerEnd) - }; - return new InlineParseResult(result, start, end); - } - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Inlines == null) - { - return base.ToString(); - } - - return "^(" + string.Join(string.Empty, Inlines) + ")"; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/TextRunInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/TextRunInline.cs deleted file mode 100644 index 786c9daef..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Inlines/TextRunInline.cs +++ /dev/null @@ -1,470 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Inlines - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Text; - - /// - /// Represents a span containing plain text. - /// - public class TextRunInline : MarkdownInline, IInlineLeaf - { - /// - /// Initializes a new instance of the class. - /// - public TextRunInline() - : base(MarkdownInlineType.TextRun) - { - } - - /// - /// Gets or sets the text for this run. - /// - public string Text { get; set; } - - // A list of supported HTML entity names, along with their corresponding code points. - private static readonly Dictionary _entities = new Dictionary - { - { "quot", 0x0022 }, // " - { "amp", 0x0026 }, // & - { "apos", 0x0027 }, // ' - { "lt", 0x003C }, // < - { "gt", 0x003E }, // > - { "nbsp", 0x00A0 }, // - { "#160", 0x00A0 }, // ? - { "iexcl", 0x00A1 }, // ¡ - { "cent", 0x00A2 }, // ¢ - { "pound", 0x00A3 }, // £ - { "curren", 0x00A4 }, // ¤ - { "yen", 0x00A5 }, // ¥ - { "brvbar", 0x00A6 }, // ¦ - { "sect", 0x00A7 }, // § - { "uml", 0x00A8 }, // ¨ - { "copy", 0x00A9 }, // © - { "ordf", 0x00AA }, // ª - { "laquo", 0x00AB }, // « - { "not", 0x00AC }, // ¬ - { "shy", 0x00AD }, // ? - { "reg", 0x00AE }, // ® - { "macr", 0x00AF }, // ¯ - { "deg", 0x00B0 }, // ° - { "plusmn", 0x00B1 }, // ± - { "sup2", 0x00B2 }, // ² - { "sup3", 0x00B3 }, // ³ - { "acute", 0x00B4 }, // ´ - { "micro", 0x00B5 }, // µ - { "para", 0x00B6 }, // ¶ - { "middot", 0x00B7 }, // · - { "cedil", 0x00B8 }, // ¸ - { "sup1", 0x00B9 }, // ¹ - { "ordm", 0x00BA }, // º - { "raquo", 0x00BB }, // » - { "frac14", 0x00BC }, // ¼ - { "frac12", 0x00BD }, // ½ - { "frac34", 0x00BE }, // ¾ - { "iquest", 0x00BF }, // ¿ - { "Agrave", 0x00C0 }, // À - { "Aacute", 0x00C1 }, // Á - { "Acirc", 0x00C2 }, //  - { "Atilde", 0x00C3 }, // à - { "Auml", 0x00C4 }, // Ä - { "Aring", 0x00C5 }, // Å - { "AElig", 0x00C6 }, // Æ - { "Ccedil", 0x00C7 }, // Ç - { "Egrave", 0x00C8 }, // È - { "Eacute", 0x00C9 }, // É - { "Ecirc", 0x00CA }, // Ê - { "Euml", 0x00CB }, // Ë - { "Igrave", 0x00CC }, // Ì - { "Iacute", 0x00CD }, // Í - { "Icirc", 0x00CE }, // Î - { "Iuml", 0x00CF }, // Ï - { "ETH", 0x00D0 }, // Ð - { "Ntilde", 0x00D1 }, // Ñ - { "Ograve", 0x00D2 }, // Ò - { "Oacute", 0x00D3 }, // Ó - { "Ocirc", 0x00D4 }, // Ô - { "Otilde", 0x00D5 }, // Õ - { "Ouml", 0x00D6 }, // Ö - { "times", 0x00D7 }, // × - { "Oslash", 0x00D8 }, // Ø - { "Ugrave", 0x00D9 }, // Ù - { "Uacute", 0x00DA }, // Ú - { "Ucirc", 0x00DB }, // Û - { "Uuml", 0x00DC }, // Ü - { "Yacute", 0x00DD }, // Ý - { "THORN", 0x00DE }, // Þ - { "szlig", 0x00DF }, // ß - { "agrave", 0x00E0 }, // à - { "aacute", 0x00E1 }, // á - { "acirc", 0x00E2 }, // â - { "atilde", 0x00E3 }, // ã - { "auml", 0x00E4 }, // ä - { "aring", 0x00E5 }, // å - { "aelig", 0x00E6 }, // æ - { "ccedil", 0x00E7 }, // ç - { "egrave", 0x00E8 }, // è - { "eacute", 0x00E9 }, // é - { "ecirc", 0x00EA }, // ê - { "euml", 0x00EB }, // ë - { "igrave", 0x00EC }, // ì - { "iacute", 0x00ED }, // í - { "icirc", 0x00EE }, // î - { "iuml", 0x00EF }, // ï - { "eth", 0x00F0 }, // ð - { "ntilde", 0x00F1 }, // ñ - { "ograve", 0x00F2 }, // ò - { "oacute", 0x00F3 }, // ó - { "ocirc", 0x00F4 }, // ô - { "otilde", 0x00F5 }, // õ - { "ouml", 0x00F6 }, // ö - { "divide", 0x00F7 }, // ÷ - { "oslash", 0x00F8 }, // ø - { "ugrave", 0x00F9 }, // ù - { "uacute", 0x00FA }, // ú - { "ucirc", 0x00FB }, // û - { "uuml", 0x00FC }, // ü - { "yacute", 0x00FD }, // ý - { "thorn", 0x00FE }, // þ - { "yuml", 0x00FF }, // ÿ - { "OElig", 0x0152 }, // Œ - { "oelig", 0x0153 }, // œ - { "Scaron", 0x0160 }, // Š - { "scaron", 0x0161 }, // š - { "Yuml", 0x0178 }, // Ÿ - { "fnof", 0x0192 }, // ƒ - { "circ", 0x02C6 }, // ˆ - { "tilde", 0x02DC }, // ˜ - { "Alpha", 0x0391 }, // Α - { "Beta", 0x0392 }, // Β - { "Gamma", 0x0393 }, // Γ - { "Delta", 0x0394 }, // Δ - { "Epsilon", 0x0395 }, // Ε - { "Zeta", 0x0396 }, // Ζ - { "Eta", 0x0397 }, // Η - { "Theta", 0x0398 }, // Θ - { "Iota", 0x0399 }, // Ι - { "Kappa", 0x039A }, // Κ - { "Lambda", 0x039B }, // Λ - { "Mu", 0x039C }, // Μ - { "Nu", 0x039D }, // Ν - { "Xi", 0x039E }, // Ξ - { "Omicron", 0x039F }, // Ο - { "Pi", 0x03A0 }, // Π - { "Rho", 0x03A1 }, // Ρ - { "Sigma", 0x03A3 }, // Σ - { "Tau", 0x03A4 }, // Τ - { "Upsilon", 0x03A5 }, // Υ - { "Phi", 0x03A6 }, // Φ - { "Chi", 0x03A7 }, // Χ - { "Psi", 0x03A8 }, // Ψ - { "Omega", 0x03A9 }, // Ω - { "alpha", 0x03B1 }, // α - { "beta", 0x03B2 }, // β - { "gamma", 0x03B3 }, // γ - { "delta", 0x03B4 }, // δ - { "epsilon", 0x03B5 }, // ε - { "zeta", 0x03B6 }, // ζ - { "eta", 0x03B7 }, // η - { "theta", 0x03B8 }, // θ - { "iota", 0x03B9 }, // ι - { "kappa", 0x03BA }, // κ - { "lambda", 0x03BB }, // λ - { "mu", 0x03BC }, // μ - { "nu", 0x03BD }, // ν - { "xi", 0x03BE }, // ξ - { "omicron", 0x03BF }, // ο - { "pi", 0x03C0 }, // π - { "rho", 0x03C1 }, // ρ - { "sigmaf", 0x03C2 }, // ς - { "sigma", 0x03C3 }, // σ - { "tau", 0x03C4 }, // τ - { "upsilon", 0x03C5 }, // υ - { "phi", 0x03C6 }, // φ - { "chi", 0x03C7 }, // χ - { "psi", 0x03C8 }, // ψ - { "omega", 0x03C9 }, // ω - { "thetasym", 0x03D1 }, // ϑ - { "upsih", 0x03D2 }, // ϒ - { "piv", 0x03D6 }, // ϖ - { "ensp", 0x2002 }, //  ? - { "emsp", 0x2003 }, //  ? - { "thinsp", 0x2009 }, //  ? - { "zwnj", 0x200C }, // ? - { "zwj", 0x200D }, // ? - { "lrm", 0x200E }, // ? - { "rlm", 0x200F }, // ? - { "ndash", 0x2013 }, // – - { "mdash", 0x2014 }, // — - { "lsquo", 0x2018 }, // ‘ - { "rsquo", 0x2019 }, // ’ - { "sbquo", 0x201A }, // ‚ - { "ldquo", 0x201C }, // “ - { "rdquo", 0x201D }, // ” - { "bdquo", 0x201E }, // „ - { "dagger", 0x2020 }, // † - { "Dagger", 0x2021 }, // ‡ - { "bull", 0x2022 }, // • - { "hellip", 0x2026 }, // … - { "permil", 0x2030 }, // ‰ - { "prime", 0x2032 }, // ′ - { "Prime", 0x2033 }, // ″ - { "lsaquo", 0x2039 }, // ‹ - { "rsaquo", 0x203A }, // › - { "oline", 0x203E }, // ‾ - { "frasl", 0x2044 }, // ⁄ - { "euro", 0x20AC }, // € - { "image", 0x2111 }, // ℑ - { "weierp", 0x2118 }, // ℘ - { "real", 0x211C }, // ℜ - { "trade", 0x2122 }, // ™ - { "alefsym", 0x2135 }, // ℵ - { "larr", 0x2190 }, // ← - { "uarr", 0x2191 }, // ↑ - { "rarr", 0x2192 }, // → - { "darr", 0x2193 }, // ↓ - { "harr", 0x2194 }, // ↔ - { "crarr", 0x21B5 }, // ↵ - { "lArr", 0x21D0 }, // ⇐ - { "uArr", 0x21D1 }, // ⇑ - { "rArr", 0x21D2 }, // ⇒ - { "dArr", 0x21D3 }, // ⇓ - { "hArr", 0x21D4 }, // ⇔ - { "forall", 0x2200 }, // ∀ - { "part", 0x2202 }, // ∂ - { "exist", 0x2203 }, // ∃ - { "empty", 0x2205 }, // ∅ - { "nabla", 0x2207 }, // ∇ - { "isin", 0x2208 }, // ∈ - { "notin", 0x2209 }, // ∉ - { "ni", 0x220B }, // ∋ - { "prod", 0x220F }, // ∏ - { "sum", 0x2211 }, // ∑ - { "minus", 0x2212 }, // − - { "lowast", 0x2217 }, // ∗ - { "radic", 0x221A }, // √ - { "prop", 0x221D }, // ∝ - { "infin", 0x221E }, // ∞ - { "ang", 0x2220 }, // ∠ - { "and", 0x2227 }, // ∧ - { "or", 0x2228 }, // ∨ - { "cap", 0x2229 }, // ∩ - { "cup", 0x222A }, // ∪ - { "int", 0x222B }, // ∫ - { "there4", 0x2234 }, // ∴ - { "sim", 0x223C }, // ∼ - { "cong", 0x2245 }, // ≅ - { "asymp", 0x2248 }, // ≈ - { "ne", 0x2260 }, // ≠ - { "equiv", 0x2261 }, // ≡ - { "le", 0x2264 }, // ≤ - { "ge", 0x2265 }, // ≥ - { "sub", 0x2282 }, // ⊂ - { "sup", 0x2283 }, // ⊃ - { "nsub", 0x2284 }, // ⊄ - { "sube", 0x2286 }, // ⊆ - { "supe", 0x2287 }, // ⊇ - { "oplus", 0x2295 }, // ⊕ - { "otimes", 0x2297 }, // ⊗ - { "perp", 0x22A5 }, // ⊥ - { "sdot", 0x22C5 }, // ⋅ - { "lceil", 0x2308 }, // ⌈ - { "rceil", 0x2309 }, // ⌉ - { "lfloor", 0x230A }, // ⌊ - { "rfloor", 0x230B }, // ⌋ - { "lang", 0x2329 }, // 〈 - { "rang", 0x232A }, // 〉 - { "loz", 0x25CA }, // ◊ - { "spades", 0x2660 }, // ♠ - { "clubs", 0x2663 }, // ♣ - { "hearts", 0x2665 }, // ♥ - { "diams", 0x2666 }, // ♦ - }; - - // A list of characters that can be escaped. - private static readonly char[] _escapeCharacters = new char[] { '\\', '`', '*', '_', '{', '}', '[', ']', '(', ')', '#', '+', '-', '.', '!', '|', '~', '^', '&', ':', '<', '>', '/' }; - - /// - /// Parses unformatted text. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed text span. - internal static TextRunInline Parse(string markdown, int start, int end) - { - // Handle escape sequences and entities. - // Note: this code is designed to be as fast as possible in the case where there are no - // escape sequences and no entities (expected to be the common case). - StringBuilder result = null; - int textPos = start; - int searchPos = start; - while (searchPos < end) - { - // Look for the next backslash. - int sequenceStartIndex = markdown.IndexOfAny(new char[] { '\\', '&' }, searchPos, end - searchPos); - if (sequenceStartIndex == -1) - { - break; - } - - searchPos = sequenceStartIndex + 1; - - char decodedChar; - if (markdown[sequenceStartIndex] == '\\') - { - // This is an escape sequence, with one more character expected. - if (sequenceStartIndex >= end - 1) - { - break; - } - - // Check if the character after the backslash can be escaped. - decodedChar = markdown[sequenceStartIndex + 1]; - if (Array.IndexOf(_escapeCharacters, decodedChar) < 0) - { - // This character cannot be escaped. - continue; - } - - // This here's an escape sequence! - if (result == null) - { - result = new StringBuilder(end - start); - } - - result.Append(markdown.Substring(textPos, sequenceStartIndex - textPos)); - result.Append(decodedChar); - searchPos = textPos = sequenceStartIndex + 2; - } - else if (markdown[sequenceStartIndex] == '&') - { - // This is an entity e.g. " ". - - // Look for the semicolon. - int semicolonIndex = markdown.IndexOf(';', sequenceStartIndex + 1, end - (sequenceStartIndex + 1)); - - // Unterminated entity. - if (semicolonIndex == -1) - { - continue; - } - - // Okay, we have an entity, but is it one we recognize? - string entityName = markdown.Substring(sequenceStartIndex + 1, semicolonIndex - (sequenceStartIndex + 1)); - - // Unrecognized entity. - if (_entities.ContainsKey(entityName) == false) - { - continue; - } - - // This here's an escape sequence! - if (result == null) - { - result = new StringBuilder(end - start); - } - - result.Append(markdown.Substring(textPos, sequenceStartIndex - textPos)); - result.Append((char)_entities[entityName]); - searchPos = textPos = semicolonIndex + 1; - } - } - - if (result != null) - { - result.Append(markdown.Substring(textPos, end - textPos)); - return new TextRunInline { Text = result.ToString() }; - } - - var length = end - start; - - // HACK: in case end < start happens - if (length <= 0) - { - return new TextRunInline { Text = string.Empty }; - } - - return new TextRunInline { Text = markdown.Substring(start, length) }; - } - - /// - /// Parses unformatted text. - /// - /// The markdown text. - /// The location to start parsing. - /// The location to stop parsing. - /// A parsed text span. - internal static string ResolveEscapeSequences(string markdown, int start, int end) - { - // Handle escape sequences only. - // Note: this code is designed to be as fast as possible in the case where there are no - // escape sequences (expected to be the common case). - StringBuilder result = null; - int textPos = start; - int searchPos = start; - while (searchPos < end) - { - // Look for the next backslash. - int sequenceStartIndex = markdown.IndexOf('\\', searchPos, end - searchPos); - if (sequenceStartIndex == -1) - { - break; - } - - searchPos = sequenceStartIndex + 1; - - // This is an escape sequence, with one more character expected. - if (sequenceStartIndex >= end - 1) - { - break; - } - - // Check if the character after the backslash can be escaped. - char decodedChar = markdown[sequenceStartIndex + 1]; - if (Array.IndexOf(_escapeCharacters, decodedChar) < 0) - { - // This character cannot be escaped. - continue; - } - - // This here's an escape sequence! - if (result == null) - { - result = new StringBuilder(end - start); - } - - result.Append(markdown.Substring(textPos, sequenceStartIndex - textPos)); - result.Append(decodedChar); - searchPos = textPos = sequenceStartIndex + 2; - } - - if (result != null) - { - result.Append(markdown.Substring(textPos, end - textPos)); - return result.ToString(); - } - - return markdown.Substring(start, end - start); - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Text == null) - { - return base.ToString(); - } - - return Text; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownBlock.cs deleted file mode 100644 index 2b5d3342d..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownBlock.cs +++ /dev/null @@ -1,50 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown - -namespace Notepads.Controls.Markdown -{ - /// - /// A Block Element is an element that is a container for other structures. - /// - public abstract class MarkdownBlock : MarkdownElement - { - /// - /// Gets or sets tells us what type this element is. - /// - public MarkdownBlockType Type { get; set; } - - /// - /// Initializes a new instance of the class. - /// - internal MarkdownBlock(MarkdownBlockType type) - { - Type = type; - } - - /// - /// Determines whether the specified object is equal to the current object. - /// - /// The object to compare with the current object. - /// true if the specified object is equal to the current object; otherwise, false. - public override bool Equals(object obj) - { - if (!base.Equals(obj) || !(obj is MarkdownBlock)) - { - return false; - } - - return Type == ((MarkdownBlock)obj).Type; - } - - /// - /// Serves as the default hash function. - /// - /// A hash code for the current object. - public override int GetHashCode() - { - return base.GetHashCode() ^ Type.GetHashCode(); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownDocument.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownDocument.cs deleted file mode 100644 index 934780aab..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownDocument.cs +++ /dev/null @@ -1,417 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Linq; - using System.Text; - - /// - /// Represents a Markdown Document. - /// Initialize an instance and call to parse the Raw Markdown Text. - /// - public class MarkdownDocument : MarkdownBlock - { - /// - /// Gets a list of URL schemes. - /// - public static List KnownSchemes { get; private set; } = new List() - { - "http", - "https", - "ftp", - "steam", - "irc", - "news", - "mumble", - "ssh", - "ms-windows-store", - "sip" - }; - - private Dictionary _references; - - /// - /// Initializes a new instance of the class. - /// - public MarkdownDocument() - : base(MarkdownBlockType.Root) - { - } - - /// - /// Gets or sets the list of block elements. - /// - public IList Blocks { get; set; } - - /// - /// Parses markdown document text. - /// - /// The markdown text. - public void Parse(string markdownText) - { - Blocks = Parse(markdownText, 0, markdownText.Length, quoteDepth: 0, actualEnd: out _); - - // Remove any references from the list of blocks, and add them to a dictionary. - for (int i = Blocks.Count - 1; i >= 0; i--) - { - if (Blocks[i].Type == MarkdownBlockType.LinkReference) - { - var reference = (LinkReferenceBlock)Blocks[i]; - if (_references == null) - { - _references = new Dictionary(StringComparer.OrdinalIgnoreCase); - } - - if (!_references.ContainsKey(reference.Id)) - { - _references.Add(reference.Id, reference); - } - - Blocks.RemoveAt(i); - } - } - } - - /// - /// Parses a markdown document. - /// - /// The markdown text. - /// The position to start parsing. - /// The position to stop parsing. - /// The current nesting level for block quoting. - /// Set to the position at which parsing ended. This can be - /// different from when the parser is being called recursively. - /// - /// A list of parsed blocks. - internal static List Parse(string markdown, int start, int end, int quoteDepth, out int actualEnd) - { - // We need to parse out the list of blocks. - // Some blocks need to start on a new paragraph (code, lists and tables) while other - // blocks can start on any line (headers, horizontal rules and quotes). - // Text that is outside of any other block becomes a paragraph. - var blocks = new List(); - int startOfLine = start; - bool lineStartsNewParagraph = true; - var paragraphText = new StringBuilder(); - - // These are needed to parse underline-style header blocks. - int previousRealtStartOfLine = start; - int previousStartOfLine = start; - int previousEndOfLine = start; - - // Go line by line. - while (startOfLine < end) - { - // Find the first non-whitespace character. - int nonSpacePos = startOfLine; - char nonSpaceChar = '\0'; - int realStartOfLine = startOfLine; // i.e. including quotes. - int expectedQuotesRemaining = quoteDepth; - while (true) - { - while (nonSpacePos < end) - { - char c = markdown[nonSpacePos]; - if (c == '\r' || c == '\n') - { - // The line is either entirely whitespace, or is empty. - break; - } - - if (c != ' ' && c != '\t') - { - // The line has content. - nonSpaceChar = c; - break; - } - - nonSpacePos++; - } - - // When parsing blocks in a blockquote context, we need to count the number of - // quote characters ('>'). If there are less than expected AND this is the - // start of a new paragraph, then stop parsing. - if (expectedQuotesRemaining == 0) - { - break; - } - - if (nonSpaceChar == '>') - { - // Expected block quote characters should be ignored. - expectedQuotesRemaining--; - nonSpacePos++; - nonSpaceChar = '\0'; - startOfLine = nonSpacePos; - - // Ignore the first space after the quote character, if there is one. - if (startOfLine < end && markdown[startOfLine] == ' ') - { - startOfLine++; - nonSpacePos++; - } - } - else - { - int lastIndentation = 0; - string lastline = null; - - // Determines how many Quote levels were in the last line. - if (realStartOfLine > 0) - { - lastline = markdown.Substring(previousRealtStartOfLine, previousEndOfLine - previousRealtStartOfLine); - lastIndentation = lastline.Count(c => c == '>'); - } - - var currentEndOfLine = Common.FindNextSingleNewLine(markdown, nonSpacePos, end, out _); - var currentline = markdown.Substring(realStartOfLine, currentEndOfLine - realStartOfLine); - var currentIndentation = currentline.Count(c => c == '>'); - var firstChar = markdown[realStartOfLine]; - - // This is a quote that doesn't start with a Quote marker, but carries on from the last line. - if (lastIndentation == 1) - { - if (nonSpaceChar != '\0' && firstChar != '>') - { - break; - } - } - - // Collapse down a level of quotes if the current indentation is greater than the last indentation. - // Only if the last indentation is greater than 1, and the current indentation is greater than 0 - if (lastIndentation > 1 && currentIndentation > 0 && currentIndentation < lastIndentation) - { - break; - } - - // This must be the end of the blockquote. End the current paragraph, if any. - actualEnd = realStartOfLine; - - if (paragraphText.Length > 0) - { - blocks.Add(ParagraphBlock.Parse(paragraphText.ToString())); - } - - return blocks; - } - } - - // Find the end of the current line. - int endOfLine = Common.FindNextSingleNewLine(markdown, nonSpacePos, end, out int startOfNextLine); - - if (nonSpaceChar == '\0') - { - // The line is empty or nothing but whitespace. - lineStartsNewParagraph = true; - - // End the current paragraph. - if (paragraphText.Length > 0) - { - blocks.Add(ParagraphBlock.Parse(paragraphText.ToString())); - paragraphText.Clear(); - } - } - else - { - // This is a header if the line starts with a hash character, - // or if the line starts with '-' or a '=' character and has no other characters. - // Or a quote if the line starts with a greater than character (optionally preceded by whitespace). - // Or a horizontal rule if the line contains nothing but 3 '*', '-' or '_' characters (with optional whitespace). - MarkdownBlock newBlockElement = null; - if (nonSpaceChar == '-' && nonSpacePos == startOfLine) - { - // Yaml Header - newBlockElement = YamlHeaderBlock.Parse(markdown, startOfLine, markdown.Length, out startOfLine); - if (newBlockElement != null) - { - realStartOfLine = startOfLine; - endOfLine = startOfLine + 3; - startOfNextLine = Common.FindNextSingleNewLine(markdown, startOfLine, end, out startOfNextLine); - - paragraphText.Clear(); - } - } - - if (newBlockElement == null && nonSpaceChar == '#' && nonSpacePos == startOfLine) - { - // Hash-prefixed header. - newBlockElement = HeaderBlock.ParseHashPrefixedHeader(markdown, startOfLine, endOfLine); - } - else if ((nonSpaceChar == '-' || nonSpaceChar == '=') && nonSpacePos == startOfLine && paragraphText.Length > 0) - { - // Underline style header. These are weird because you don't know you've - // got one until you've gone past it. - // Note: we intentionally deviate from reddit here in that we only - // recognize this type of header if the previous line is part of a - // paragraph. For example if you have this, the header at the bottom is - // ignored: - // a|b - // -|- - // 1|2 - // === - newBlockElement = HeaderBlock.ParseUnderlineStyleHeader(markdown, previousStartOfLine, previousEndOfLine, startOfLine, endOfLine); - - if (newBlockElement != null) - { - // We're going to have to remove the header text from the pending - // paragraph by prematurely ending the current paragraph. - // We already made sure that there is a paragraph in progress. - paragraphText.Length -= (previousEndOfLine - previousStartOfLine); - } - } - - // These characters overlap with the underline-style header - this check should go after that one. - if (newBlockElement == null && (nonSpaceChar == '*' || nonSpaceChar == '-' || nonSpaceChar == '_')) - { - newBlockElement = HorizontalRuleBlock.Parse(markdown, startOfLine, endOfLine); - } - - if (newBlockElement == null && lineStartsNewParagraph) - { - // Some block elements must start on a new paragraph (tables, lists and code). - int endOfBlock = startOfNextLine; - if (nonSpaceChar == '*' || nonSpaceChar == '+' || nonSpaceChar == '-' || (nonSpaceChar >= '0' && nonSpaceChar <= '9')) - { - newBlockElement = ListBlock.Parse(markdown, realStartOfLine, end, quoteDepth, out endOfBlock); - } - - if (newBlockElement == null && (nonSpacePos > startOfLine || nonSpaceChar == '`')) - { - newBlockElement = CodeBlock.Parse(markdown, realStartOfLine, end, quoteDepth, out endOfBlock); - } - - if (newBlockElement == null) - { - newBlockElement = TableBlock.Parse(markdown, realStartOfLine, endOfLine, end, quoteDepth, out endOfBlock); - } - - if (newBlockElement != null) - { - startOfNextLine = endOfBlock; - } - } - - // This check needs to go after the code block check. - if (newBlockElement == null && nonSpaceChar == '>') - { - newBlockElement = QuoteBlock.Parse(markdown, realStartOfLine, end, quoteDepth, out startOfNextLine); - } - - // This check needs to go after the code block check. - if (newBlockElement == null && nonSpaceChar == '[') - { - newBlockElement = LinkReferenceBlock.Parse(markdown, startOfLine, endOfLine); - } - - // Block elements start new paragraphs. - lineStartsNewParagraph = newBlockElement != null; - - if (newBlockElement == null) - { - // The line contains paragraph text. - if (paragraphText.Length > 0) - { - // If the previous two characters were both spaces, then append a line break. - if (paragraphText.Length > 2 && paragraphText[paragraphText.Length - 1] == ' ' && paragraphText[paragraphText.Length - 2] == ' ') - { - // Replace the two spaces with a line break. - paragraphText[paragraphText.Length - 2] = '\r'; - paragraphText[paragraphText.Length - 1] = '\n'; - } - else - { - paragraphText.Append(" "); - } - } - - // Add the last paragraph if we are at the end of the input text. - if (startOfNextLine >= end) - { - if (paragraphText.Length == 0) - { - // Optimize for single line paragraphs. - blocks.Add(ParagraphBlock.Parse(markdown.Substring(startOfLine, endOfLine - startOfLine))); - } - else - { - // Slow path. - paragraphText.Append(markdown.Substring(startOfLine, endOfLine - startOfLine)); - blocks.Add(ParagraphBlock.Parse(paragraphText.ToString())); - } - } - else - { - paragraphText.Append(markdown.Substring(startOfLine, endOfLine - startOfLine)); - } - } - else - { - // The line contained a block. End the current paragraph, if any. - if (paragraphText.Length > 0) - { - blocks.Add(ParagraphBlock.Parse(paragraphText.ToString())); - paragraphText.Clear(); - } - - blocks.Add(newBlockElement); - } - } - - // Repeat. - previousRealtStartOfLine = realStartOfLine; - previousStartOfLine = startOfLine; - previousEndOfLine = endOfLine; - startOfLine = startOfNextLine; - } - - actualEnd = startOfLine; - return blocks; - } - - /// - /// Looks up a reference using the ID. - /// A reference is a line that looks like this: - /// [foo]: http://example.com/ - /// - /// The ID of the reference (case insensitive). - /// The reference details, or null if the reference wasn't found. - public LinkReferenceBlock LookUpReference(string id) - { - if (id == null) - { - throw new ArgumentNullException(nameof(id)); - } - - if (_references == null) - { - return null; - } - - if (_references.TryGetValue(id, out LinkReferenceBlock result)) - { - return result; - } - - return null; - } - - /// - /// Converts the object into it's textual representation. - /// - /// The textual representation of this object. - public override string ToString() - { - if (Blocks == null) - { - return base.ToString(); - } - - return string.Join("\r\n", Blocks); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownElement.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownElement.cs deleted file mode 100644 index d01e7fa2f..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownElement.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown - -namespace Notepads.Controls.Markdown -{ - /// - /// This is a class used as the base class of all markdown elements. - /// - public abstract class MarkdownElement - { - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownInline.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownInline.cs deleted file mode 100644 index 29cff9116..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/MarkdownInline.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown - -namespace Notepads.Controls.Markdown -{ - /// - /// An internal class that is the base class for all inline elements. - /// - public abstract class MarkdownInline : MarkdownElement - { - /// - /// Gets or sets this element is. - /// - public MarkdownInlineType Type { get; set; } - - /// - /// Initializes a new instance of the class. - /// - internal MarkdownInline(MarkdownInlineType type) - { - Type = type; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ICodeBlockResolver.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ICodeBlockResolver.cs deleted file mode 100644 index 1b6dbaf27..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ICodeBlockResolver.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Xaml.Documents; - - /// - /// A Parser to parse code strings into Syntax Highlighted text. - /// - public interface ICodeBlockResolver - { - /// - /// Parses Code Block text into Rich text. - /// - /// Block to add formatted Text to. - /// The raw code block text - /// The language of the Code Block, as specified by ```{Language} on the first line of the block, - /// e.g. - /// ```C# - /// public void Method(); - /// ``` - /// - /// Parsing was handled Successfully - bool ParseSyntax(InlineCollection inlineCollection, string text, string codeLanguage); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IImageResolver.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IImageResolver.cs deleted file mode 100644 index df6913498..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IImageResolver.cs +++ /dev/null @@ -1,24 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System.Threading.Tasks; - using Windows.UI.Xaml.Media; - - /// - /// An interface used to resolve images in the markdown. - /// - public interface IImageResolver - { - /// - /// Resolves an Image from a Url. - /// - /// Url to Resolve. - /// Tooltip for Image. - /// Image - Task ResolveImageAsync(string url, string tooltip); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ILinkRegister.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ILinkRegister.cs deleted file mode 100644 index 61ba9362a..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/ILinkRegister.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - - /// - /// An interface used to handle links in the markdown. - /// - public interface ILinkRegister - { - /// - /// Registers a Hyperlink with a LinkUrl. - /// - /// Hyperlink to Register. - /// Url to Register. - void RegisterNewHyperLink(Hyperlink newHyperlink, string linkUrl); - - /// - /// Registers a Hyperlink with a LinkUrl. - /// - /// ImageLink to Register. - /// Url to Register. - /// Is Image an IsHyperlink. - void RegisterNewHyperLink(Image newImagelink, string linkUrl, bool isHyperLink); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IRenderContext.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IRenderContext.cs deleted file mode 100644 index 0ab994b18..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/IRenderContext.cs +++ /dev/null @@ -1,29 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Render - -namespace Notepads.Controls.Markdown -{ - /// - /// Helper for holding persistent state of Renderer. - /// - public interface IRenderContext - { - /// - /// Gets or sets a value indicating whether to trim whitespace. - /// - bool TrimLeadingWhitespace { get; set; } - - /// - /// Gets or sets the parent Element for this Context. - /// - object Parent { get; set; } - - /// - /// Clones the Context. - /// - /// Clone - IRenderContext Clone(); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/InlineRenderContext.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/InlineRenderContext.cs deleted file mode 100644 index 4961f01a2..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/InlineRenderContext.cs +++ /dev/null @@ -1,55 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Xaml.Documents; - - /// - /// The Context of the Current Document Rendering. - /// - public class InlineRenderContext : RenderContext - { - internal InlineRenderContext(InlineCollection inlineCollection, IRenderContext context) - { - InlineCollection = inlineCollection; - TrimLeadingWhitespace = context.TrimLeadingWhitespace; - Parent = context.Parent; - - if (context is RenderContext localcontext) - { - Foreground = localcontext.Foreground; - OverrideForeground = localcontext.OverrideForeground; - } - - if (context is InlineRenderContext inlinecontext) - { - WithinBold = inlinecontext.WithinBold; - WithinItalics = inlinecontext.WithinItalics; - WithinHyperlink = inlinecontext.WithinHyperlink; - } - } - - /// - /// Gets or sets a value indicating whether the Current Element is being rendered inside an Italics Run. - /// - public bool WithinItalics { get; set; } - - /// - /// Gets or sets a value indicating whether the Current Element is being rendered inside a Bold Run. - /// - public bool WithinBold { get; set; } - - /// - /// Gets or sets a value indicating whether the Current Element is being rendered inside a Link. - /// - public bool WithinHyperlink { get; set; } - - /// - /// Gets or sets the list to add to. - /// - public InlineCollection InlineCollection { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Blocks.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Blocks.cs deleted file mode 100644 index b1fcae1d0..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Blocks.cs +++ /dev/null @@ -1,475 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using Windows.UI.Text; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - using Windows.UI.Xaml.Shapes; - - /// - /// Block UI Methods for UWP UI Creation. - /// - public partial class MarkdownRenderer - { - /// - /// Renders a list of block elements. - /// - protected override void RenderBlocks(IEnumerable blockElements, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - base.RenderBlocks(blockElements, context); - - // Remove the top margin from the first block element, the bottom margin from the last block element, - // and collapse adjacent margins. - FrameworkElement previousFrameworkElement = null; - for (int i = 0; i < blockUIElementCollection.Count; i++) - { - var frameworkElement = blockUIElementCollection[i] as FrameworkElement; - if (frameworkElement != null) - { - if (i == 0) - { - // Remove the top margin. - frameworkElement.Margin = new Thickness( - frameworkElement.Margin.Left, - 0, - frameworkElement.Margin.Right, - frameworkElement.Margin.Bottom); - } - else if (previousFrameworkElement != null) - { - // Remove the bottom margin. - frameworkElement.Margin = new Thickness( - frameworkElement.Margin.Left, - Math.Max(frameworkElement.Margin.Top, previousFrameworkElement.Margin.Bottom), - frameworkElement.Margin.Right, - frameworkElement.Margin.Bottom); - previousFrameworkElement.Margin = new Thickness( - previousFrameworkElement.Margin.Left, - previousFrameworkElement.Margin.Top, - previousFrameworkElement.Margin.Right, - 0); - } - } - - previousFrameworkElement = frameworkElement; - } - } - - /// - /// Renders a paragraph element. - /// - protected override void RenderParagraph(ParagraphBlock element, IRenderContext context) - { - var paragraph = new Paragraph - { - Margin = ParagraphMargin, - LineHeight = ParagraphLineHeight - }; - - var childContext = new InlineRenderContext(paragraph.Inlines, context) - { - Parent = paragraph - }; - - RenderInlineChildren(element.Inlines, childContext); - - var textBlock = CreateOrReuseRichTextBlock(context); - textBlock.Blocks.Add(paragraph); - } - - /// - /// Renders a yaml header element. - /// - protected override void RenderYamlHeader(YamlHeaderBlock element, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - var table = new MarkdownTable(element.Children.Count, 2, YamlBorderThickness, YamlBorderBrush) - { - HorizontalAlignment = HorizontalAlignment.Left, - Margin = TableMargin - }; - - // Split key and value - string[] childrenKeys = new string[element.Children.Count]; - string[] childrenValues = new string[element.Children.Count]; - element.Children.Keys.CopyTo(childrenKeys, 0); - element.Children.Values.CopyTo(childrenValues, 0); - - // Add each column - for (int i = 0; i < element.Children.Count; i++) - { - // Add each cell - var keyCell = new TextBlock - { - Text = childrenKeys[i], - Foreground = Foreground, - TextAlignment = TextAlignment.Center, - FontWeight = FontWeights.Bold, - Margin = TableCellPadding - }; - var valueCell = new TextBlock - { - Text = childrenValues[i], - Foreground = Foreground, - TextAlignment = TextAlignment.Left, - Margin = TableCellPadding, - TextWrapping = TextWrapping.Wrap - }; - Grid.SetRow(keyCell, 0); - Grid.SetColumn(keyCell, i); - Grid.SetRow(valueCell, 1); - Grid.SetColumn(valueCell, i); - table.Children.Add(keyCell); - table.Children.Add(valueCell); - } - - blockUIElementCollection.Add(table); - } - - /// - /// Renders a header element. - /// - protected override void RenderHeader(HeaderBlock element, IRenderContext context) - { - var textBlock = CreateOrReuseRichTextBlock(context); - - var paragraph = new Paragraph(); - var childInlines = paragraph.Inlines; - switch (element.HeaderLevel) - { - case 1: - paragraph.Margin = Header1Margin; - paragraph.FontSize = Header1FontSize; - paragraph.FontWeight = Header1FontWeight; - paragraph.Foreground = Header1Foreground; - break; - - case 2: - paragraph.Margin = Header2Margin; - paragraph.FontSize = Header2FontSize; - paragraph.FontWeight = Header2FontWeight; - paragraph.Foreground = Header2Foreground; - break; - - case 3: - paragraph.Margin = Header3Margin; - paragraph.FontSize = Header3FontSize; - paragraph.FontWeight = Header3FontWeight; - paragraph.Foreground = Header3Foreground; - break; - - case 4: - paragraph.Margin = Header4Margin; - paragraph.FontSize = Header4FontSize; - paragraph.FontWeight = Header4FontWeight; - paragraph.Foreground = Header4Foreground; - break; - - case 5: - paragraph.Margin = Header5Margin; - paragraph.FontSize = Header5FontSize; - paragraph.FontWeight = Header5FontWeight; - paragraph.Foreground = Header5Foreground; - break; - - case 6: - paragraph.Margin = Header6Margin; - paragraph.FontSize = Header6FontSize; - paragraph.FontWeight = Header6FontWeight; - paragraph.Foreground = Header6Foreground; - - var underline = new Underline(); - childInlines = underline.Inlines; - paragraph.Inlines.Add(underline); - break; - } - - // Render the children into the para inline. - var childContext = new InlineRenderContext(childInlines, context) - { - Parent = paragraph, - TrimLeadingWhitespace = true - }; - - RenderInlineChildren(element.Inlines, childContext); - - // Add it to the blocks - textBlock.Blocks.Add(paragraph); - } - - /// - /// Renders a list element. - /// - protected override void RenderListElement(ListBlock element, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - // Create a grid with two columns. - Grid grid = new Grid - { - Margin = ListMargin - }; - - // The first column for the bullet (or number) and the second for the text. - grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(ListGutterWidth) }); - grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) }); - - for (int rowIndex = 0; rowIndex < element.Items.Count; rowIndex++) - { - var listItem = element.Items[rowIndex]; - - // Add a row definition. - grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); - - // Add the bullet or number. - var bullet = CreateTextBlock(localContext); - bullet.Margin = ParagraphMargin; - switch (element.Style) - { - case ListStyle.Bulleted: - bullet.Text = "•"; - break; - - case ListStyle.Numbered: - bullet.Text = $"{rowIndex + 1}."; - break; - } - - bullet.HorizontalAlignment = HorizontalAlignment.Right; - bullet.Margin = new Thickness(0, 0, ListBulletSpacing, 0); - Grid.SetRow(bullet, rowIndex); - grid.Children.Add(bullet); - - // Add the list item content. - var content = new StackPanel(); - var childContext = new UIElementCollectionRenderContext(content.Children, localContext); - RenderBlocks(listItem.Blocks, childContext); - Grid.SetColumn(content, 1); - Grid.SetRow(content, rowIndex); - grid.Children.Add(content); - } - - blockUIElementCollection.Add(grid); - } - - /// - /// Renders a horizontal rule element. - /// - protected override void RenderHorizontalRule(IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - var brush = localContext.Foreground; - if (HorizontalRuleBrush != null && !localContext.OverrideForeground) - { - brush = HorizontalRuleBrush; - } - - var rectangle = new Rectangle - { - HorizontalAlignment = HorizontalAlignment.Stretch, - Height = HorizontalRuleThickness, - Fill = brush, - Margin = HorizontalRuleMargin - }; - - blockUIElementCollection.Add(rectangle); - } - - /// - /// Renders a quote element. - /// - protected override void RenderQuote(QuoteBlock element, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - var stackPanel = new StackPanel(); - var childContext = new UIElementCollectionRenderContext(stackPanel.Children, context) - { - Parent = stackPanel - }; - - if (QuoteForeground != null && !localContext.OverrideForeground) - { - childContext.Foreground = QuoteForeground; - } - - RenderBlocks(element.Blocks, childContext); - - var border = new Border - { - Margin = QuoteMargin, - Background = QuoteBackground, - BorderBrush = childContext.OverrideForeground ? childContext.Foreground : QuoteBorderBrush ?? childContext.Foreground, - BorderThickness = QuoteBorderThickness, - Padding = QuotePadding, - Child = stackPanel - }; - - blockUIElementCollection.Add(border); - } - - /// - /// Renders a code element. - /// - protected override void RenderCode(CodeBlock element, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - var brush = localContext.Foreground; - if (CodeForeground != null && !localContext.OverrideForeground) - { - brush = CodeForeground; - } - - var textBlock = new RichTextBlock - { - FontFamily = CodeFontFamily ?? FontFamily, - Foreground = brush, - LineHeight = FontSize * 1.4, - FlowDirection = FlowDirection - }; - - textBlock.PointerWheelChanged += Preventative_PointerWheelChanged; - - var paragraph = new Paragraph(); - textBlock.Blocks.Add(paragraph); - - // Allows external Syntax Highlighting - var hasCustomSyntax = CodeBlockResolver.ParseSyntax(paragraph.Inlines, element.Text, element.CodeLanguage); - if (!hasCustomSyntax) - { - paragraph.Inlines.Add(new Run { Text = element.Text }); - } - - // Ensures that Code has Horizontal Scroll and doesn't wrap. - var viewer = new ScrollViewer - { - Background = CodeBackground, - BorderBrush = CodeBorderBrush, - BorderThickness = CodeBorderThickness, - Padding = CodePadding, - Margin = CodeMargin, - Content = textBlock - }; - - if (!WrapCodeBlock) - { - viewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; - viewer.HorizontalScrollMode = ScrollMode.Auto; - viewer.VerticalScrollMode = ScrollMode.Disabled; - viewer.VerticalScrollBarVisibility = ScrollBarVisibility.Disabled; - } - - // Add it to the blocks - blockUIElementCollection.Add(viewer); - } - - /// - /// Renders a table element. - /// - protected override void RenderTable(TableBlock element, IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - var table = new MarkdownTable(element.ColumnDefinitions.Count, element.Rows.Count, TableBorderThickness, TableBorderBrush) - { - HorizontalAlignment = HorizontalAlignment.Left, - Margin = TableMargin - }; - - // Add each row. - for (int rowIndex = 0; rowIndex < element.Rows.Count; rowIndex++) - { - var row = element.Rows[rowIndex]; - - // Add each cell. - for (int cellIndex = 0; cellIndex < Math.Min(element.ColumnDefinitions.Count, row.Cells.Count); cellIndex++) - { - var cell = row.Cells[cellIndex]; - - // Cell content. - var cellContent = CreateOrReuseRichTextBlock(new UIElementCollectionRenderContext(null, context)); - cellContent.Margin = TableCellPadding; - Grid.SetRow(cellContent, rowIndex); - Grid.SetColumn(cellContent, cellIndex); - switch (element.ColumnDefinitions[cellIndex].Alignment) - { - case ColumnAlignment.Center: - cellContent.TextAlignment = TextAlignment.Center; - break; - - case ColumnAlignment.Right: - cellContent.TextAlignment = TextAlignment.Right; - break; - } - - if (rowIndex == 0) - { - cellContent.FontWeight = FontWeights.Bold; - } - - var paragraph = new Paragraph(); - - var childContext = new InlineRenderContext(paragraph.Inlines, context) - { - Parent = paragraph, - TrimLeadingWhitespace = true - }; - - RenderInlineChildren(cell.Inlines, childContext); - - cellContent.Blocks.Add(paragraph); - table.Children.Add(cellContent); - } - } - - blockUIElementCollection.Add(table); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Dimensions.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Dimensions.cs deleted file mode 100644 index 343a97193..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Dimensions.cs +++ /dev/null @@ -1,227 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Text; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Media; - - /// - /// Measurement Properties for elements in the Markdown. - /// - public partial class MarkdownRenderer - { - /// - /// Gets or sets the distance between the border and its child object. - /// - public Thickness Padding { get; set; } - - /// - /// Gets or sets the border thickness of a control. - /// - public Thickness BorderThickness { get; set; } - - /// - /// Gets or sets the thickness of the border around code blocks. - /// - public Thickness CodeBorderThickness { get; set; } - - /// - /// Gets or sets the thickness of the border around inline code. - /// - public Thickness InlineCodeBorderThickness { get; set; } - - /// - /// Gets or sets the space outside of code blocks. - /// - public Thickness CodeMargin { get; set; } - - /// - /// Gets or sets the space between the code border and the text. - /// - public Thickness CodePadding { get; set; } - - /// - /// Gets or sets the space between the code border and the text. - /// - public Thickness InlineCodePadding { get; set; } - - /// - /// Gets or sets the margin of inline code. - /// - public Thickness InlineCodeMargin { get; set; } - - /// - /// Gets or sets the font size for level 1 headers. - /// - public double Header1FontSize { get; set; } - - /// - /// Gets or sets the margin for level 1 headers. - /// - public Thickness Header1Margin { get; set; } - - /// - /// Gets or sets the font size for level 2 headers. - /// - public double Header2FontSize { get; set; } - - /// - /// Gets or sets the margin for level 2 headers. - /// - public Thickness Header2Margin { get; set; } - - /// - /// Gets or sets the font size for level 3 headers. - /// - public double Header3FontSize { get; set; } - - /// - /// Gets or sets the margin for level 3 headers. - /// - public Thickness Header3Margin { get; set; } - - /// - /// Gets or sets the font size for level 4 headers. - /// - public double Header4FontSize { get; set; } - - /// - /// Gets or sets the margin for level 4 headers. - /// - public Thickness Header4Margin { get; set; } - - /// - /// Gets or sets the font size for level 5 headers. - /// - public double Header5FontSize { get; set; } - - /// - /// Gets or sets the margin for level 5 headers. - /// - public Thickness Header5Margin { get; set; } - - /// - /// Gets or sets the font size for level 6 headers. - /// - public double Header6FontSize { get; set; } - - /// - /// Gets or sets the margin for level 6 headers. - /// - public Thickness Header6Margin { get; set; } - - /// - /// Gets or sets the margin used for horizontal rules. - /// - public Thickness HorizontalRuleMargin { get; set; } - - /// - /// Gets or sets the vertical thickness of the horizontal rule. - /// - public double HorizontalRuleThickness { get; set; } - - /// - /// Gets or sets the margin used by lists. - /// - public Thickness ListMargin { get; set; } - - /// - /// Gets or sets the width of the space used by list item bullets/numbers. - /// - public double ListGutterWidth { get; set; } - - /// - /// Gets or sets the space between the list item bullets/numbers and the list item content. - /// - public double ListBulletSpacing { get; set; } - - /// - /// Gets or sets the margin used for paragraphs. - /// - public Thickness ParagraphMargin { get; set; } - - /// - /// Gets or sets the line height used for paragraphs. - /// - public int ParagraphLineHeight { get; set; } - - /// - /// Gets or sets the thickness of quote borders. - /// - public Thickness QuoteBorderThickness { get; set; } - - /// - /// Gets or sets the space outside of quote borders. - /// - public Thickness QuoteMargin { get; set; } - - /// - /// Gets or sets the space between the quote border and the text. - /// - public Thickness QuotePadding { get; set; } - - /// - /// Gets or sets the thickness of any table borders. - /// - public double TableBorderThickness { get; set; } - - /// - /// Gets or sets the thickness of any yaml header borders. - /// - public double YamlBorderThickness { get; set; } - - /// - /// Gets or sets the padding inside each cell. - /// - public Thickness TableCellPadding { get; set; } - - /// - /// Gets or sets the margin used by tables. - /// - public Thickness TableMargin { get; set; } - - /// - /// Gets or sets the size of the text in this control. - /// - public double FontSize { get; set; } - - /// - /// Gets or sets the uniform spacing between characters, in units of 1/1000 of an em. - /// - public int CharacterSpacing { get; set; } - - /// - /// Gets or sets the word wrapping behavior. - /// - public TextWrapping TextWrapping { get; set; } - - /// - /// Gets or sets the degree to which a font is condensed or expanded on the screen. - /// - public FontStretch FontStretch { get; set; } - - /// - /// Gets or sets the stretch used for images. - /// - public Stretch ImageStretch { get; set; } - - /// - /// Gets or sets the MaxHeight for images. - /// - public double ImageMaxHeight { get; set; } - - /// - /// Gets or sets the MaxWidth for images. - /// - public double ImageMaxWidth { get; set; } - - /// - /// Gets or sets a value indicating whether to wrap text in the Code Block, or use Horizontal Scroll. - /// - public bool WrapCodeBlock { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Inlines.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Inlines.cs deleted file mode 100644 index f40472fec..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Inlines.cs +++ /dev/null @@ -1,595 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - using System.Text; - using Windows.UI.Text; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - using Windows.UI.Xaml.Media; - - /// - /// Inline UI Methods for UWP UI Creation. - /// - public partial class MarkdownRenderer - { - /// - /// Renders Emoji element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderEmoji(EmojiInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var inlineCollection = localContext.InlineCollection; - - var emoji = new Run - { - FontFamily = EmojiFontFamily ?? DefaultEmojiFont, - Text = element.Text - }; - - inlineCollection.Add(emoji); - } - - /// - /// Renders a text run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderTextRun(TextRunInline element, IRenderContext context) - { - InternalRenderTextRun(element, context); - } - - private Run InternalRenderTextRun(TextRunInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var inlineCollection = localContext.InlineCollection; - - // Create the text run - Run textRun = new Run - { - Text = CollapseWhitespace(context, element.Text) - }; - - // Add it - inlineCollection.Add(textRun); - return textRun; - } - - /// - /// Renders a bold run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderBoldRun(BoldTextInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - // Create the text run - Span boldSpan = new Span - { - FontWeight = FontWeights.Bold - }; - - var childContext = new InlineRenderContext(boldSpan.Inlines, context) - { - Parent = boldSpan, - WithinBold = true - }; - - // Render the children into the bold inline. - RenderInlineChildren(element.Inlines, childContext); - - // Add it to the current inline collection - localContext.InlineCollection.Add(boldSpan); - } - - /// - /// Renders a link element - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderMarkdownLink(MarkdownLinkInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - // HACK: Superscript is not allowed within a hyperlink. But if we switch it around, so - // that the superscript is outside the hyperlink, then it will render correctly. - // This assumes that the entire hyperlink is to be rendered as superscript. - if (AllTextIsSuperscript(element) == false) - { - // Regular ol' hyperlink. - var link = new Hyperlink(); - - // Register the link - LinkRegister.RegisterNewHyperLink(link, element.Url); - - // Remove superscripts. - RemoveSuperscriptRuns(element, insertCaret: true); - - // Render the children into the link inline. - var childContext = new InlineRenderContext(link.Inlines, context) - { - Parent = link, - WithinHyperlink = true - }; - - if (localContext.OverrideForeground) - { - link.Foreground = localContext.Foreground; - } - else if (LinkForeground != null) - { - link.Foreground = LinkForeground; - } - - RenderInlineChildren(element.Inlines, childContext); - context.TrimLeadingWhitespace = childContext.TrimLeadingWhitespace; - - ToolTipService.SetToolTip(link, element.Tooltip ?? element.Url); - - // Add it to the current inlines - localContext.InlineCollection.Add(link); - } - else - { - // THE HACK IS ON! - - // Create a fake superscript element. - var fakeSuperscript = new SuperscriptTextInline - { - Inlines = new List - { - element - } - }; - - // Remove superscripts. - RemoveSuperscriptRuns(element, insertCaret: false); - - // Now render it. - RenderSuperscriptRun(fakeSuperscript, context); - } - } - - /// - /// Renders a raw link element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderHyperlink(HyperlinkInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var link = new Hyperlink(); - - // Register the link - LinkRegister.RegisterNewHyperLink(link, element.Url); - - var brush = localContext.Foreground; - if (LinkForeground != null && !localContext.OverrideForeground) - { - brush = LinkForeground; - } - - // Make a text block for the link - Run linkText = new Run - { - Text = CollapseWhitespace(context, element.Text), - Foreground = brush - }; - - link.Inlines.Add(linkText); - - try - { - //Add it to the current inline collection - localContext.InlineCollection.Add(link); - } - catch // Invalid hyperlink - { - link.Inlines.Clear(); - } - } - - /// - /// Renders an image element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override async void RenderImage(ImageInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var inlineCollection = localContext.InlineCollection; - - var placeholder = InternalRenderTextRun(new TextRunInline { Text = element.Text, Type = MarkdownInlineType.TextRun }, context); - var resolvedImage = await ImageResolver.ResolveImageAsync(element.RenderUrl, element.Tooltip); - - // if image can not be resolved we have to return - if (resolvedImage == null) - { - return; - } - - var image = new Image - { - Source = resolvedImage, - HorizontalAlignment = HorizontalAlignment.Left, - VerticalAlignment = VerticalAlignment.Top, - Stretch = ImageStretch - }; - - HyperlinkButton hyperlinkButton = new HyperlinkButton() - { - Content = image - }; - - var viewbox = new Viewbox - { - Child = hyperlinkButton, - StretchDirection = StretchDirection.DownOnly - }; - - viewbox.PointerWheelChanged += Preventative_PointerWheelChanged; - - var scrollViewer = new ScrollViewer - { - Content = viewbox, - VerticalScrollMode = ScrollMode.Disabled, - VerticalScrollBarVisibility = ScrollBarVisibility.Disabled - }; - - var imageContainer = new InlineUIContainer() { Child = scrollViewer }; - - bool ishyperlink = element.RenderUrl != element.Url; - - LinkRegister.RegisterNewHyperLink(image, element.Url, ishyperlink); - - if (ImageMaxHeight > 0) - { - viewbox.MaxHeight = ImageMaxHeight; - } - - if (ImageMaxWidth > 0) - { - viewbox.MaxWidth = ImageMaxWidth; - } - - if (element.ImageWidth > 0) - { - image.Width = element.ImageWidth; - image.Stretch = Stretch.UniformToFill; - } - - if (element.ImageHeight > 0) - { - if (element.ImageWidth == 0) - { - image.Width = element.ImageHeight; - } - - image.Height = element.ImageHeight; - image.Stretch = Stretch.UniformToFill; - } - - if (element.ImageHeight > 0 && element.ImageWidth > 0) - { - image.Stretch = Stretch.Fill; - } - - // If image size is given then scroll to view overflown part - if (element.ImageHeight > 0 || element.ImageWidth > 0) - { - scrollViewer.HorizontalScrollMode = ScrollMode.Auto; - scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; - } - - // Else resize the image - else - { - scrollViewer.HorizontalScrollMode = ScrollMode.Disabled; - scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; - } - - ToolTipService.SetToolTip(image, element.Tooltip); - - // Try to add it to the current inlines - // Could fail because some containers like Hyperlink cannot have inlined images - try - { - var placeholderIndex = inlineCollection.IndexOf(placeholder); - inlineCollection.Remove(placeholder); - inlineCollection.Insert(placeholderIndex, imageContainer); - } - catch - { - // Ignore error - } - } - - /// - /// Renders a text run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderItalicRun(ItalicTextInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - // Create the text run - Span italicSpan = new Span - { - FontStyle = FontStyle.Italic - }; - - var childContext = new InlineRenderContext(italicSpan.Inlines, context) - { - Parent = italicSpan, - WithinItalics = true - }; - - // Render the children into the italic inline. - RenderInlineChildren(element.Inlines, childContext); - - // Add it to the current inlines - localContext.InlineCollection.Add(italicSpan); - } - - /// - /// Renders a strike-through element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderStrikethroughRun(StrikethroughTextInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - Span span = new Span(); - - if (TextDecorationsSupported) - { - span.TextDecorations = TextDecorations.Strikethrough; - } - else - { - span.FontFamily = new FontFamily("Consolas"); - } - - var childContext = new InlineRenderContext(span.Inlines, context) - { - Parent = span - }; - - // Render the children into the inline. - RenderInlineChildren(element.Inlines, childContext); - - if (!TextDecorationsSupported) - { - AlterChildRuns(span, (parentSpan, run) => - { - var text = run.Text; - var builder = new StringBuilder(text.Length * 2); - foreach (var c in text) - { - builder.Append((char)0x0336); - builder.Append(c); - } - - run.Text = builder.ToString(); - }); - } - - // Add it to the current inlines - localContext.InlineCollection.Add(span); - } - - /// - /// Renders a superscript element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderSuperscriptRun(SuperscriptTextInline element, IRenderContext context) - { - var localContext = context as InlineRenderContext; - var parent = localContext?.Parent as TextElement; - if (localContext == null && parent == null) - { - throw new RenderContextIncorrectException(); - } - - // Le , InlineUIContainers are not allowed within hyperlinks. - if (localContext.WithinHyperlink) - { - RenderInlineChildren(element.Inlines, context); - return; - } - - var paragraph = new Paragraph - { - FontSize = parent.FontSize * 0.8, - FontFamily = parent.FontFamily, - FontStyle = parent.FontStyle, - FontWeight = parent.FontWeight - }; - - var childContext = new InlineRenderContext(paragraph.Inlines, context) - { - Parent = paragraph - }; - - RenderInlineChildren(element.Inlines, childContext); - - var richTextBlock = CreateOrReuseRichTextBlock(new UIElementCollectionRenderContext(null, context)); - richTextBlock.Blocks.Add(paragraph); - - var border = new Border - { - Padding = new Thickness(0, 0, 0, paragraph.FontSize * 0.2), - Child = richTextBlock - }; - - var inlineUIContainer = new InlineUIContainer - { - Child = border - }; - - // Add it to the current inlines - localContext.InlineCollection.Add(inlineUIContainer); - } - - /// - /// Renders a subscript element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderSubscriptRun(SubscriptTextInline element, IRenderContext context) - { - var localContext = context as InlineRenderContext; - var parent = localContext?.Parent as TextElement; - if (localContext == null && parent == null) - { - throw new RenderContextIncorrectException(); - } - - var paragraph = new Paragraph - { - FontSize = parent.FontSize * 0.7, - FontFamily = parent.FontFamily, - FontStyle = parent.FontStyle, - FontWeight = parent.FontWeight - }; - - var childContext = new InlineRenderContext(paragraph.Inlines, context) - { - Parent = paragraph - }; - - RenderInlineChildren(element.Inlines, childContext); - - var richTextBlock = CreateOrReuseRichTextBlock(new UIElementCollectionRenderContext(null, context)); - richTextBlock.Blocks.Add(paragraph); - - var border = new Border - { - Margin = new Thickness(0, 0, 0, (-1) * (paragraph.FontSize * 0.6)), - Child = richTextBlock - }; - - var inlineUIContainer = new InlineUIContainer - { - Child = border - }; - - // Add it to the current inlines - localContext.InlineCollection.Add(inlineUIContainer); - } - - /// - /// Renders a code element - /// - /// The parsed inline element to render. - /// Persistent state. - protected override void RenderCodeRun(CodeInline element, IRenderContext context) - { - if (!(context is InlineRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var text = CreateTextBlock(localContext); - text.Text = CollapseWhitespace(context, element.Text); - text.FontFamily = InlineCodeFontFamily ?? FontFamily; - text.Foreground = InlineCodeForeground ?? Foreground; - - if (localContext.WithinItalics) - { - text.FontStyle = FontStyle.Italic; - } - - if (localContext.WithinBold) - { - text.FontWeight = FontWeights.Bold; - } - - var borderthickness = InlineCodeBorderThickness; - var padding = InlineCodePadding; - - var border = new Border - { - BorderThickness = borderthickness, - BorderBrush = InlineCodeBorderBrush, - Background = InlineCodeBackground, - Child = text, - Padding = padding, - Margin = InlineCodeMargin - }; - - // Aligns content in InlineUI, see https://social.msdn.microsoft.com/Forums/silverlight/en-US/48b5e91e-efc5-4768-8eaf-f897849fcf0b/richtextbox-inlineuicontainer-vertical-alignment-issue?forum=silverlightarchieve - border.RenderTransform = new TranslateTransform - { - Y = 4 - }; - - var inlineUIContainer = new InlineUIContainer - { - Child = border, - }; - - try - { - // Add it to the current inline collection - localContext.InlineCollection.Add(inlineUIContainer); - } - catch // Fallback - { - Run run = new Run - { - Text = text.Text, - FontFamily = InlineCodeFontFamily ?? FontFamily, - Foreground = InlineCodeForeground ?? Foreground - }; - - // Additional formatting - if (localContext.WithinItalics) run.FontStyle = FontStyle.Italic; - if (localContext.WithinBold) run.FontWeight = FontWeights.Bold; - - // Add the fallback block - localContext.InlineCollection.Add(run); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Properties.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Properties.cs deleted file mode 100644 index bc9c2a43c..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.Properties.cs +++ /dev/null @@ -1,245 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System.Reflection; - using Windows.Foundation.Metadata; - using Windows.UI.Text; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - - /// - /// Properties for the UWP Markdown Renderer - /// - public partial class MarkdownRenderer - { - private static bool? _textDecorationsSupported = null; - - private static bool TextDecorationsSupported => (bool)(_textDecorationsSupported ?? - (_textDecorationsSupported = ApiInformation.IsTypePresent("Windows.UI.Text.TextDecorations"))); - - /// - /// Super Hack to retain inertia and passing the Scroll data onto the Parent ScrollViewer. - /// - private static readonly MethodInfo pointerWheelChanged = typeof(ScrollViewer).GetMethod("OnPointerWheelChanged", BindingFlags.NonPublic | BindingFlags.Instance); - - /// - /// Gets or sets the Root Framework Element. - /// - private FrameworkElement RootElement { get; set; } - - /// - /// Gets the interface that is used to register hyperlinks. - /// - protected ILinkRegister LinkRegister { get; } - - /// - /// Gets the interface that is used to resolve images. - /// - protected IImageResolver ImageResolver { get; } - - /// - /// Gets the Parser to parse code strings into Syntax Highlighted text. - /// - protected ICodeBlockResolver CodeBlockResolver { get; } - - /// - /// Gets the Default Emoji Font. - /// - protected FontFamily DefaultEmojiFont { get; } - - /// - /// Gets or sets a brush that provides the background of the control. - /// - public Brush Background { get; set; } - - /// - /// Gets or sets a brush that describes the border fill of a control. - /// - public Brush BorderBrush { get; set; } - - /// - /// Gets or sets the of the markdown. - /// - public FlowDirection FlowDirection { get; set; } - - /// - /// Gets or sets the font used to display text in the control. - /// - public FontFamily FontFamily { get; set; } - - /// - /// Gets or sets the style in which the text is rendered. - /// - public FontStyle FontStyle { get; set; } - - /// - /// Gets or sets the thickness of the specified font. - /// - public FontWeight FontWeight { get; set; } - - /// - /// Gets or sets a brush that describes the foreground color. - /// - public Brush Foreground { get; set; } - - /// - /// Gets or sets a value indicating whether text selection is enabled. - /// - public bool IsTextSelectionEnabled { get; set; } - - /// - /// Gets or sets the brush used to fill the background of a code block. - /// - public Brush CodeBackground { get; set; } - - /// - /// Gets or sets the brush used to fill the background of inline code. - /// - public Brush InlineCodeBackground { get; set; } - - /// - /// Gets or sets the brush used to fill the foreground of inline code. - /// - public Brush InlineCodeForeground { get; set; } - - /// - /// Gets or sets the brush used to fill the border of inline code. - /// - public Brush InlineCodeBorderBrush { get; set; } - - /// - /// Gets or sets the brush used to render the border fill of a code block. - /// - public Brush CodeBorderBrush { get; set; } - - /// - /// Gets or sets the brush used to render the text inside a code block. If this is - /// null, then is used. - /// - public Brush CodeForeground { get; set; } - - /// - /// Gets or sets the font used to display code. If this is null, then - /// is used. - /// - public FontFamily CodeFontFamily { get; set; } - - /// - /// Gets or sets the font used to display code. If this is null, then - /// is used. - /// - public FontFamily InlineCodeFontFamily { get; set; } - - /// - /// Gets or sets the font used to display emojis. If this is null, then - /// Segoe UI Emoji font is used. - /// - public FontFamily EmojiFontFamily { get; set; } - - /// - /// Gets or sets the font weight to use for level 1 headers. - /// - public FontWeight Header1FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 1 headers. - /// - public Brush Header1Foreground { get; set; } - - /// - /// Gets or sets the font weight to use for level 2 headers. - /// - public FontWeight Header2FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 2 headers. - /// - public Brush Header2Foreground { get; set; } - - /// - /// Gets or sets the font weight to use for level 3 headers. - /// - public FontWeight Header3FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 3 headers. - /// - public Brush Header3Foreground { get; set; } - - /// - /// Gets or sets the font weight to use for level 4 headers. - /// - public FontWeight Header4FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 4 headers. - /// - public Brush Header4Foreground { get; set; } - - /// - /// Gets or sets the font weight to use for level 5 headers. - /// - public FontWeight Header5FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 5 headers. - /// - public Brush Header5Foreground { get; set; } - - /// - /// Gets or sets the font weight to use for level 6 headers. - /// - public FontWeight Header6FontWeight { get; set; } - - /// - /// Gets or sets the foreground brush for level 6 headers. - /// - public Brush Header6Foreground { get; set; } - - /// - /// Gets or sets the brush used to render a horizontal rule. If this is null, then - /// is used. - /// - public Brush HorizontalRuleBrush { get; set; } - - /// - /// Gets or sets the brush used to fill the background of a quote block. - /// - public Brush QuoteBackground { get; set; } - - /// - /// Gets or sets the brush used to render a quote border. If this is null, then - /// is used. - /// - public Brush QuoteBorderBrush { get; set; } - - /// - /// Gets or sets the brush used to render the text inside a quote block. If this is - /// null, then is used. - /// - public Brush QuoteForeground { get; set; } - - /// - /// Gets or sets the brush used to render table borders. If this is null, then - /// is used. - /// - public Brush TableBorderBrush { get; set; } - - /// - /// Gets or sets the brush used to render table borders. If this is null, then - /// is used. - /// - public Brush YamlBorderBrush { get; set; } - - /// - /// Gets or sets the brush used to render links. If this is null, then - /// is used. - /// - public Brush LinkForeground { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.cs deleted file mode 100644 index c7f28c75f..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRenderer.cs +++ /dev/null @@ -1,221 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System; - using Microsoft.Toolkit.Uwp.UI.Extensions; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - using Windows.UI.Xaml.Media; - - /// - /// Generates Framework Elements for the UWP Markdown Textblock. - /// - public partial class MarkdownRenderer : MarkdownRendererBase - { - /// - /// Initializes a new instance of the class. - /// - /// The Document to Render. - /// The LinkRegister, will use itself. - /// The Image Resolver, will use itself. - /// The Code Block Resolver, will use itself. - public MarkdownRenderer(MarkdownDocument document, ILinkRegister linkRegister, IImageResolver imageResolver, ICodeBlockResolver codeBlockResolver) - : base(document) - { - LinkRegister = linkRegister; - ImageResolver = imageResolver; - CodeBlockResolver = codeBlockResolver; - DefaultEmojiFont = new FontFamily("Segoe UI Emoji"); - } - - /// - /// Called externally to render markdown to a text block. - /// - /// A XAML UI element. - public UIElement Render() - { - var stackPanel = new StackPanel(); - RootElement = stackPanel; - Render(new UIElementCollectionRenderContext(stackPanel.Children) { Foreground = Foreground }); - - // Set background and border properties. - stackPanel.Background = Background; - stackPanel.BorderBrush = BorderBrush; - stackPanel.BorderThickness = BorderThickness; - stackPanel.Padding = Padding; - - return stackPanel; - } - - /// - /// Creates a new RichTextBlock, if the last element of the provided collection isn't already a RichTextBlock. - /// - /// The rich text block - protected RichTextBlock CreateOrReuseRichTextBlock(IRenderContext context) - { - if (!(context is UIElementCollectionRenderContext localContext)) - { - throw new RenderContextIncorrectException(); - } - - var blockUIElementCollection = localContext.BlockUIElementCollection; - - // Reuse the last RichTextBlock, if possible. - if (blockUIElementCollection != null && blockUIElementCollection.Count > 0 && blockUIElementCollection[blockUIElementCollection.Count - 1] is RichTextBlock) - { - return (RichTextBlock)blockUIElementCollection[blockUIElementCollection.Count - 1]; - } - - var result = new RichTextBlock - { - CharacterSpacing = CharacterSpacing, - FontFamily = FontFamily, - FontSize = FontSize, - FontStretch = FontStretch, - FontStyle = FontStyle, - FontWeight = FontWeight, - Foreground = localContext.Foreground, - IsTextSelectionEnabled = IsTextSelectionEnabled, - TextWrapping = TextWrapping, - FlowDirection = FlowDirection - }; - localContext.BlockUIElementCollection?.Add(result); - - return result; - } - - /// - /// Creates a new TextBlock, with default settings. - /// - /// The created TextBlock - protected TextBlock CreateTextBlock(RenderContext context) - { - var result = new TextBlock - { - CharacterSpacing = CharacterSpacing, - FontFamily = FontFamily, - FontSize = FontSize, - FontStretch = FontStretch, - FontStyle = FontStyle, - FontWeight = FontWeight, - Foreground = context.Foreground, - IsTextSelectionEnabled = IsTextSelectionEnabled, - TextWrapping = TextWrapping, - FlowDirection = FlowDirection - }; - return result; - } - - /// - /// Performs an action against any runs that occur within the given span. - /// - protected void AlterChildRuns(Span parentSpan, Action action) - { - foreach (var inlineElement in parentSpan.Inlines) - { - if (inlineElement is Span span) - { - AlterChildRuns(span, action); - } - else if (inlineElement is Run) - { - action(parentSpan, (Run)inlineElement); - } - } - } - - /// - /// Checks if all text elements inside the given container are superscript. - /// - /// true if all text is superscript (level 1); false otherwise. - private bool AllTextIsSuperscript(IInlineContainer container, int superscriptLevel = 0) - { - foreach (var inline in container.Inlines) - { - if (inline is SuperscriptTextInline textInline) - { - // Remove any nested superscripts. - if (AllTextIsSuperscript(textInline, superscriptLevel + 1) == false) - { - return false; - } - } - else if (inline is IInlineContainer inlineContainer) - { - // Remove any superscripts. - if (AllTextIsSuperscript(inlineContainer, superscriptLevel) == false) - { - return false; - } - } - else if (inline is IInlineLeaf leaf && superscriptLevel != 1) - { - if (!ParseHelpers.IsMarkdownBlankOrWhiteSpace(leaf.Text) || string.IsNullOrWhiteSpace(leaf.Text)) - { - return false; - } - } - } - - return true; - } - - /// - /// Removes all superscript elements from the given container. - /// - private void RemoveSuperscriptRuns(IInlineContainer container, bool insertCaret) - { - for (int i = 0; i < container.Inlines.Count; i++) - { - var inline = container.Inlines[i]; - if (inline is SuperscriptTextInline textInline) - { - // Remove any nested superscripts. - RemoveSuperscriptRuns(textInline, insertCaret); - - // Remove the superscript element, insert all the children. - container.Inlines.RemoveAt(i); - if (insertCaret) - { - container.Inlines.Insert(i++, new TextRunInline { Text = "^" }); - } - - foreach (var superscriptInline in textInline.Inlines) - { - container.Inlines.Insert(i++, superscriptInline); - } - - i--; - } - else if (inline is IInlineContainer) - { - // Remove any superscripts. - RemoveSuperscriptRuns((IInlineContainer)inline, insertCaret); - } - } - } - - private void Preventative_PointerWheelChanged(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e) - { - var pointerPoint = e.GetCurrentPoint((UIElement)sender); - - if (pointerPoint.Properties.IsHorizontalMouseWheel) - { - e.Handled = false; - return; - } - - var rootViewer = VisualTree.FindAscendant(RootElement); - if (rootViewer != null) - { - pointerWheelChanged?.Invoke(rootViewer, new object[] { e }); - e.Handled = true; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Blocks.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Blocks.cs deleted file mode 100644 index b46746fc7..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Blocks.cs +++ /dev/null @@ -1,53 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Render - -namespace Notepads.Controls.Markdown -{ - /// - /// Block Rendering Methods. - /// - public partial class MarkdownRendererBase - { - /// - /// Renders a paragraph element. - /// - protected abstract void RenderParagraph(ParagraphBlock element, IRenderContext context); - - /// - /// Renders a yaml header element. - /// - protected abstract void RenderYamlHeader(YamlHeaderBlock element, IRenderContext context); - - /// - /// Renders a header element. - /// - protected abstract void RenderHeader(HeaderBlock element, IRenderContext context); - - /// - /// Renders a list element. - /// - protected abstract void RenderListElement(ListBlock element, IRenderContext context); - - /// - /// Renders a horizontal rule element. - /// - protected abstract void RenderHorizontalRule(IRenderContext context); - - /// - /// Renders a quote element. - /// - protected abstract void RenderQuote(QuoteBlock element, IRenderContext context); - - /// - /// Renders a code element. - /// - protected abstract void RenderCode(CodeBlock element, IRenderContext context); - - /// - /// Renders a table element. - /// - protected abstract void RenderTable(TableBlock element, IRenderContext context); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Inlines.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Inlines.cs deleted file mode 100644 index 9d7121aab..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.Inlines.cs +++ /dev/null @@ -1,90 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Render - -namespace Notepads.Controls.Markdown -{ - /// - /// Inline Rendering Methods. - /// - public partial class MarkdownRendererBase - { - /// - /// Renders emoji element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderEmoji(EmojiInline element, IRenderContext context); - - /// - /// Renders a text run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderTextRun(TextRunInline element, IRenderContext context); - - /// - /// Renders a bold run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderBoldRun(BoldTextInline element, IRenderContext context); - - /// - /// Renders a link element - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderMarkdownLink(MarkdownLinkInline element, IRenderContext context); - - /// - /// Renders an image element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderImage(ImageInline element, IRenderContext context); - - /// - /// Renders a raw link element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderHyperlink(HyperlinkInline element, IRenderContext context); - - /// - /// Renders a text run element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderItalicRun(ItalicTextInline element, IRenderContext context); - - /// - /// Renders a strikethrough element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderStrikethroughRun(StrikethroughTextInline element, IRenderContext context); - - /// - /// Renders a superscript element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderSuperscriptRun(SuperscriptTextInline element, IRenderContext context); - - /// - /// Renders a subscript element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderSubscriptRun(SubscriptTextInline element, IRenderContext context); - - /// - /// Renders a code element - /// - /// The parsed inline element to render. - /// Persistent state. - protected abstract void RenderCodeRun(CodeInline element, IRenderContext context); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.cs deleted file mode 100644 index fd20461c5..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownRendererBase.cs +++ /dev/null @@ -1,250 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Parsers/Markdown/Render - -namespace Notepads.Controls.Markdown -{ - using System.Collections.Generic; - using System.Text; - - /// - /// A base renderer for Rendering Markdown into Controls. - /// - public abstract partial class MarkdownRendererBase - { - /// - /// Initializes a new instance of the class. - /// - /// Markdown Document to Render - protected MarkdownRendererBase(MarkdownDocument document) - { - Document = document; - } - - /// - /// Renders all Content to the Provided Parent UI. - /// - /// UI Context - public virtual void Render(IRenderContext context) - { - RenderBlocks(Document.Blocks, context); - } - - /// - /// Renders a list of block elements. - /// - protected virtual void RenderBlocks(IEnumerable blockElements, IRenderContext context) - { - foreach (MarkdownBlock element in blockElements) - { - RenderBlock(element, context); - } - } - - /// - /// Called to render a block element. - /// - protected void RenderBlock(MarkdownBlock element, IRenderContext context) - { - { - switch (element.Type) - { - case MarkdownBlockType.Paragraph: - RenderParagraph((ParagraphBlock)element, context); - break; - - case MarkdownBlockType.Quote: - RenderQuote((QuoteBlock)element, context); - break; - - case MarkdownBlockType.Code: - RenderCode((CodeBlock)element, context); - break; - - case MarkdownBlockType.Header: - RenderHeader((HeaderBlock)element, context); - break; - - case MarkdownBlockType.List: - RenderListElement((ListBlock)element, context); - break; - - case MarkdownBlockType.HorizontalRule: - RenderHorizontalRule(context); - break; - - case MarkdownBlockType.Table: - RenderTable((TableBlock)element, context); - break; - - case MarkdownBlockType.YamlHeader: - RenderYamlHeader((YamlHeaderBlock)element, context); - break; - } - } - } - - /// - /// Renders all of the children for the given element. - /// - /// The parsed inline elements to render. - /// Persistent state. - protected void RenderInlineChildren(IList inlineElements, IRenderContext context) - { - foreach (MarkdownInline element in inlineElements) - { - switch (element.Type) - { - case MarkdownInlineType.Comment: - case MarkdownInlineType.LinkReference: - break; - - default: - RenderInline(element, context); - break; - } - } - } - - /// - /// Called to render an inline element. - /// - /// The parsed inline element to render. - /// Persistent state. - protected void RenderInline(MarkdownInline element, IRenderContext context) - { - switch (element.Type) - { - case MarkdownInlineType.TextRun: - RenderTextRun((TextRunInline)element, context); - break; - - case MarkdownInlineType.Italic: - RenderItalicRun((ItalicTextInline)element, context); - break; - - case MarkdownInlineType.Bold: - RenderBoldRun((BoldTextInline)element, context); - break; - - case MarkdownInlineType.MarkdownLink: - CheckRenderMarkdownLink((MarkdownLinkInline)element, context); - break; - - case MarkdownInlineType.RawHyperlink: - RenderHyperlink((HyperlinkInline)element, context); - break; - - case MarkdownInlineType.Strikethrough: - RenderStrikethroughRun((StrikethroughTextInline)element, context); - break; - - case MarkdownInlineType.Superscript: - RenderSuperscriptRun((SuperscriptTextInline)element, context); - break; - - case MarkdownInlineType.Subscript: - RenderSubscriptRun((SubscriptTextInline)element, context); - break; - - case MarkdownInlineType.Code: - RenderCodeRun((CodeInline)element, context); - break; - - case MarkdownInlineType.Image: - RenderImage((ImageInline)element, context); - break; - - case MarkdownInlineType.Emoji: - RenderEmoji((EmojiInline)element, context); - break; - } - } - - /// - /// Removes leading whitespace, but only if this is the first run in the block. - /// - /// The corrected string - protected static string CollapseWhitespace(IRenderContext context, string text) - { - bool dontOutputWhitespace = context.TrimLeadingWhitespace; - StringBuilder result = null; - for (int i = 0; i < text.Length; i++) - { - char c = text[i]; - if (c == ' ' || c == '\t') - { - if (dontOutputWhitespace) - { - if (result == null) - { - result = new StringBuilder(text.Substring(0, i), text.Length); - } - } - else - { - result?.Append(c); - - dontOutputWhitespace = true; - } - } - else - { - result?.Append(c); - - dontOutputWhitespace = false; - } - } - - context.TrimLeadingWhitespace = false; - return result == null ? text : result.ToString(); - } - - /// - /// Verifies if the link is valid, before processing into a link, or plain text. - /// - /// The parsed inline element to render. - /// Persistent state. - protected void CheckRenderMarkdownLink(MarkdownLinkInline element, IRenderContext context) - { - // Avoid processing when link text is empty. - if (element.Inlines.Count == 0) - { - return; - } - - // Attempt to resolve references. - element.ResolveReference(Document); - if (element.Url == null) - { - // The element couldn't be resolved, just render it as text. - RenderInlineChildren(element.Inlines, context); - return; - } - - foreach (MarkdownInline inline in element.Inlines) - { - if (inline is ImageInline imageInline) - { - // this is an image, create Image. - if (!string.IsNullOrEmpty(imageInline.ReferenceId)) - { - imageInline.ResolveReference(Document); - } - - imageInline.Url = element.Url; - RenderImage(imageInline, context); - return; - } - } - - RenderMarkdownLink(element, context); - } - - /// - /// Gets the markdown document that will be rendered. - /// - protected MarkdownDocument Document { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownTable.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownTable.cs deleted file mode 100644 index b87d001d1..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/MarkdownTable.cs +++ /dev/null @@ -1,217 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System; - using System.Collections.Generic; - using System.Linq; - using Windows.Foundation; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - using Windows.UI.Xaml.Shapes; - - /// - /// A custom panel control that arranges elements similar to how an HTML table would. - /// - internal class MarkdownTable : Panel - { - private readonly int _columnCount; - private readonly int _rowCount; - private readonly double _borderThickness; - private double[] _columnWidths; - private double[] _rowHeights; - - public MarkdownTable(int columnCount, int rowCount, double borderThickness, Brush borderBrush) - { - _columnCount = columnCount; - _rowCount = rowCount; - _borderThickness = borderThickness; - for (int col = 0; col < columnCount + 1; col++) - { - Children.Add(new Rectangle { Fill = borderBrush }); - } - - for (int row = 0; row < rowCount + 1; row++) - { - Children.Add(new Rectangle { Fill = borderBrush }); - } - } - - // Helper method to enumerate FrameworkElements instead of UIElements. - private IEnumerable ContentChildren - { - get - { - for (int i = _columnCount + _rowCount + 2; i < Children.Count; i++) - { - yield return (FrameworkElement)Children[i]; - } - } - } - - // Helper method to get table vertical edges. - private IEnumerable VerticalLines - { - get - { - for (int i = 0; i < _columnCount + 1; i++) - { - yield return (Rectangle)Children[i]; - } - } - } - - // Helper method to get table horizontal edges. - private IEnumerable HorizontalLines - { - get - { - for (int i = _columnCount + 1; i < _columnCount + _rowCount + 2; i++) - { - yield return (Rectangle)Children[i]; - } - } - } - - protected override Size MeasureOverride(Size availableSize) - { - // Measure the width of each column, with no horizontal width restrictions. - var naturalColumnWidths = new double[_columnCount]; - foreach (var child in ContentChildren) - { - var columnIndex = Grid.GetColumn(child); - child.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); - naturalColumnWidths[columnIndex] = Math.Max(naturalColumnWidths[columnIndex], child.DesiredSize.Width); - } - - // Now figure out the actual column widths. - var remainingContentWidth = availableSize.Width - ((_columnCount + 1) * _borderThickness); - _columnWidths = new double[_columnCount]; - int remainingColumnCount = _columnCount; - while (remainingColumnCount > 0) - { - // Calculate the fair width of all columns. - double fairWidth = Math.Max(0, remainingContentWidth / remainingColumnCount); - - // Are there any columns less than that? If so, they get what they are asking for. - bool recalculationNeeded = false; - for (int i = 0; i < _columnCount; i++) - { - if (_columnWidths[i] == 0 && naturalColumnWidths[i] < fairWidth) - { - _columnWidths[i] = naturalColumnWidths[i]; - remainingColumnCount--; - remainingContentWidth -= _columnWidths[i]; - recalculationNeeded = true; - } - } - - // If there are no columns less than the fair width, every remaining column gets that width. - if (recalculationNeeded == false) - { - for (int i = 0; i < _columnCount; i++) - { - if (_columnWidths[i] == 0) - { - _columnWidths[i] = fairWidth; - } - } - - break; - } - } - - // TODO: we can skip this step if none of the column widths changed, and just re-use - // the row heights we obtained earlier. - - // Now measure row heights. - _rowHeights = new double[_rowCount]; - foreach (var child in ContentChildren) - { - var columnIndex = Grid.GetColumn(child); - var rowIndex = Grid.GetRow(child); - child.Measure(new Size(_columnWidths[columnIndex], double.PositiveInfinity)); - _rowHeights[rowIndex] = Math.Max(_rowHeights[rowIndex], child.DesiredSize.Height); - } - - return new Size( - _columnWidths.Sum() + (_borderThickness * (_columnCount + 1)), - _rowHeights.Sum() + ((_rowCount + 1) * _borderThickness)); - } - - protected override Size ArrangeOverride(Size finalSize) - { - if (_columnWidths == null || _rowHeights == null) - { - throw new InvalidOperationException("Expected Measure to be called first."); - } - - // Arrange content. - foreach (var child in ContentChildren) - { - var columnIndex = Grid.GetColumn(child); - var rowIndex = Grid.GetRow(child); - - var rect = new Rect(0, 0, 0, 0) - { - X = _borderThickness - }; - - for (int col = 0; col < columnIndex; col++) - { - rect.X += _borderThickness + _columnWidths[col]; - } - - rect.Y = _borderThickness; - for (int row = 0; row < rowIndex; row++) - { - rect.Y += _borderThickness + _rowHeights[row]; - } - - rect.Width = _columnWidths[columnIndex]; - rect.Height = _rowHeights[rowIndex]; - child.Arrange(rect); - } - - // Arrange vertical border elements. - { - int colIndex = 0; - double x = 0; - foreach (var borderLine in VerticalLines) - { - borderLine.Arrange(new Rect(x, 0, _borderThickness, finalSize.Height)); - if (colIndex >= _columnWidths.Length) - { - break; - } - - x += _borderThickness + _columnWidths[colIndex]; - colIndex++; - } - } - - // Arrange horizontal border elements. - { - int rowIndex = 0; - double y = 0; - foreach (var borderLine in HorizontalLines) - { - borderLine.Arrange(new Rect(0, y, finalSize.Width, _borderThickness)); - if (rowIndex >= _rowHeights.Length) - { - break; - } - - y += _borderThickness + _rowHeights[rowIndex]; - rowIndex++; - } - } - - return finalSize; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContext.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContext.cs deleted file mode 100644 index f796b6395..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContext.cs +++ /dev/null @@ -1,37 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Xaml.Media; - - /// - /// The Context of the Current Position - /// - public abstract class RenderContext : IRenderContext - { - /// - /// Gets or sets the Foreground of the Current Context. - /// - public Brush Foreground { get; set; } - - /// - public bool TrimLeadingWhitespace { get; set; } - - /// - public object Parent { get; set; } - - /// - /// Gets or sets a value indicating whether to override the Foreground Property. - /// - public bool OverrideForeground { get; set; } - - /// - public IRenderContext Clone() - { - return (IRenderContext)MemberwiseClone(); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContextIncorrectException.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContextIncorrectException.cs deleted file mode 100644 index 776196d24..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/RenderContextIncorrectException.cs +++ /dev/null @@ -1,27 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using System; - - /// - /// An Exception that occurs when the Render Context is Incorrect. - /// - public class RenderContextIncorrectException : Exception - { - internal RenderContextIncorrectException() : base("Markdown Render Context missing or incorrect.") - { - } - - public RenderContextIncorrectException(string message) : base(message) - { - } - - public RenderContextIncorrectException(string message, Exception innerException) : base(message, innerException) - { - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/UIElementCollectionRenderContext.cs b/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/UIElementCollectionRenderContext.cs deleted file mode 100644 index 6068039b8..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/Markdown/Render/UIElementCollectionRenderContext.cs +++ /dev/null @@ -1,38 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock/Render - -namespace Notepads.Controls.Markdown -{ - using Windows.UI.Xaml.Controls; - - /// - /// The Context of the Current Document Rendering. - /// - public class UIElementCollectionRenderContext : RenderContext - { - internal UIElementCollectionRenderContext(UIElementCollection blockUIElementCollection) - { - BlockUIElementCollection = blockUIElementCollection; - } - - internal UIElementCollectionRenderContext(UIElementCollection blockUIElementCollection, IRenderContext context) - : this(blockUIElementCollection) - { - TrimLeadingWhitespace = context.TrimLeadingWhitespace; - Parent = context.Parent; - - if (context is RenderContext localcontext) - { - Foreground = localcontext.Foreground; - OverrideForeground = localcontext.OverrideForeground; - } - } - - /// - /// Gets or sets the list to add to. - /// - public UIElementCollection BlockUIElementCollection { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownRenderedEventArgs.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownRenderedEventArgs.cs deleted file mode 100644 index faeb1aeec..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownRenderedEventArgs.cs +++ /dev/null @@ -1,26 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - - /// - /// Arguments for the OnMarkdownRendered event which indicates when the markdown has been - /// rendered. - /// - public class MarkdownRenderedEventArgs : EventArgs - { - internal MarkdownRenderedEventArgs(Exception ex) - { - Exception = ex; - } - - /// - /// Gets the exception if there was one. If the exception is null there was no error. - /// - public Exception Exception { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Dimensions.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Dimensions.cs deleted file mode 100644 index 0e09a7f26..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Dimensions.cs +++ /dev/null @@ -1,667 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - using Windows.UI.Xaml.Media; - - /// - /// Measurement Properties for elements in the Markdown. - /// - public partial class MarkdownTextBlock - { - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodePaddingProperty = - DependencyProperty.Register( - nameof(InlineCodePadding), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeMarginProperty = - DependencyProperty.Register( - nameof(InlineCodeMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeBorderThicknessProperty = - DependencyProperty.Register( - nameof(InlineCodeBorderThickness), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ImageStretchProperty = DependencyProperty.Register( - nameof(ImageStretch), - typeof(Stretch), - typeof(MarkdownTextBlock), - new PropertyMetadata(Stretch.None, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeBorderThicknessProperty = DependencyProperty.Register( - nameof(CodeBorderThickness), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeMarginProperty = DependencyProperty.Register( - nameof(CodeMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodePaddingProperty = DependencyProperty.Register( - nameof(CodePadding), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header1FontSizeProperty = DependencyProperty.Register( - nameof(Header1FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header1MarginProperty = DependencyProperty.Register( - nameof(Header1Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header2FontSizeProperty = DependencyProperty.Register( - nameof(Header2FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header2MarginProperty = DependencyProperty.Register( - nameof(Header2Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header3FontSizeProperty = DependencyProperty.Register( - nameof(Header3FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header3MarginProperty = DependencyProperty.Register( - nameof(Header3Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header4FontSizeProperty = DependencyProperty.Register( - nameof(Header4FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header4MarginProperty = DependencyProperty.Register( - nameof(Header4Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header5FontSizeProperty = DependencyProperty.Register( - nameof(Header5FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header5MarginProperty = DependencyProperty.Register( - nameof(Header5Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header6MarginProperty = DependencyProperty.Register( - nameof(Header6Margin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header6FontSizeProperty = DependencyProperty.Register( - nameof(Header6FontSize), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty HorizontalRuleMarginProperty = DependencyProperty.Register( - nameof(HorizontalRuleMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty HorizontalRuleThicknessProperty = DependencyProperty.Register( - nameof(HorizontalRuleThickness), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ListMarginProperty = DependencyProperty.Register( - nameof(ListMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ListGutterWidthProperty = DependencyProperty.Register( - nameof(ListGutterWidth), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ListBulletSpacingProperty = DependencyProperty.Register( - nameof(ListBulletSpacing), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ParagraphMarginProperty = DependencyProperty.Register( - nameof(ParagraphMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty ParagraphLineHeightProperty = DependencyProperty.Register( - nameof(ParagraphLineHeight), - typeof(int), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuoteBorderThicknessProperty = DependencyProperty.Register( - nameof(QuoteBorderThickness), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuoteMarginProperty = DependencyProperty.Register( - nameof(QuoteMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuotePaddingProperty = DependencyProperty.Register( - nameof(QuotePadding), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty YamlBorderThicknessProperty = DependencyProperty.Register( - nameof(YamlBorderThickness), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TableBorderThicknessProperty = DependencyProperty.Register( - nameof(TableBorderThickness), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TableCellPaddingProperty = DependencyProperty.Register( - nameof(TableCellPadding), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TableMarginProperty = DependencyProperty.Register( - nameof(TableMargin), - typeof(Thickness), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TextWrappingProperty = DependencyProperty.Register( - nameof(TextWrapping), - typeof(TextWrapping), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for - /// - public static readonly DependencyProperty ImageMaxHeightProperty = DependencyProperty.Register( - nameof(ImageMaxHeight), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(0.0, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for - /// - public static readonly DependencyProperty ImageMaxWidthProperty = DependencyProperty.Register( - nameof(ImageMaxWidth), - typeof(double), - typeof(MarkdownTextBlock), - new PropertyMetadata(0.0, OnPropertyChangedStatic)); - - /// - /// Gets or sets the MaxWidth for images. - /// - public double ImageMaxWidth - { - get => (double)GetValue(ImageMaxWidthProperty); - set => SetValue(ImageMaxWidthProperty, value); - } - - /// - /// Gets or sets the MaxHeight for images. - /// - public double ImageMaxHeight - { - get => (double)GetValue(ImageMaxHeightProperty); - set => SetValue(ImageMaxHeightProperty, value); - } - - /// - /// Gets or sets the stretch used for images. - /// - public Stretch ImageStretch - { - get => (Stretch)GetValue(ImageStretchProperty); - set => SetValue(ImageStretchProperty, value); - } - - /// - /// Gets or sets the thickness of the border around code blocks. - /// - public Thickness CodeBorderThickness - { - get => (Thickness)GetValue(CodeBorderThicknessProperty); - set => SetValue(CodeBorderThicknessProperty, value); - } - - /// - /// Gets or sets the thickness of the border for inline code. - /// - public Thickness InlineCodeBorderThickness - { - get => (Thickness)GetValue(InlineCodeBorderThicknessProperty); - set => SetValue(InlineCodeBorderThicknessProperty, value); - } - - /// - /// Gets or sets the space between the code border and the text. - /// - public Thickness InlineCodePadding - { - get => (Thickness)GetValue(InlineCodePaddingProperty); - set => SetValue(InlineCodePaddingProperty, value); - } - - /// - /// Gets or sets the margin for inline code. - /// - public Thickness InlineCodeMargin - { - get => (Thickness)GetValue(InlineCodeMarginProperty); - set => SetValue(InlineCodeMarginProperty, value); - } - - /// - /// Gets or sets the space between the code border and the text. - /// - public Thickness CodeMargin - { - get => (Thickness)GetValue(CodeMarginProperty); - set => SetValue(CodeMarginProperty, value); - } - - /// - /// Gets or sets space between the code border and the text. - /// - public Thickness CodePadding - { - get => (Thickness)GetValue(CodePaddingProperty); - set => SetValue(CodePaddingProperty, value); - } - - /// - /// Gets or sets the font size for level 1 headers. - /// - public double Header1FontSize - { - get => (double)GetValue(Header1FontSizeProperty); - set => SetValue(Header1FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 1 headers. - /// - public Thickness Header1Margin - { - get => (Thickness)GetValue(Header1MarginProperty); - set => SetValue(Header1MarginProperty, value); - } - - /// - /// Gets or sets the font size for level 2 headers. - /// - public double Header2FontSize - { - get => (double)GetValue(Header2FontSizeProperty); - set => SetValue(Header2FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 2 headers. - /// - public Thickness Header2Margin - { - get => (Thickness)GetValue(Header2MarginProperty); - set => SetValue(Header2MarginProperty, value); - } - - /// - /// Gets or sets the font size for level 3 headers. - /// - public double Header3FontSize - { - get => (double)GetValue(Header3FontSizeProperty); - set => SetValue(Header3FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 3 headers. - /// - public Thickness Header3Margin - { - get => (Thickness)GetValue(Header3MarginProperty); - set => SetValue(Header3MarginProperty, value); - } - - /// - /// Gets or sets the font size for level 4 headers. - /// - public double Header4FontSize - { - get => (double)GetValue(Header4FontSizeProperty); - set => SetValue(Header4FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 4 headers. - /// - public Thickness Header4Margin - { - get => (Thickness)GetValue(Header4MarginProperty); - set => SetValue(Header4MarginProperty, value); - } - - /// - /// Gets or sets the font size for level 5 headers. - /// - public double Header5FontSize - { - get => (double)GetValue(Header5FontSizeProperty); - set => SetValue(Header5FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 5 headers. - /// - public Thickness Header5Margin - { - get => (Thickness)GetValue(Header5MarginProperty); - set => SetValue(Header5MarginProperty, value); - } - - /// - /// Gets or sets the font size for level 6 headers. - /// - public double Header6FontSize - { - get => (double)GetValue(Header6FontSizeProperty); - set => SetValue(Header6FontSizeProperty, value); - } - - /// - /// Gets or sets the margin for level 6 headers. - /// - public Thickness Header6Margin - { - get => (Thickness)GetValue(Header6MarginProperty); - set => SetValue(Header6MarginProperty, value); - } - - /// - /// Gets or sets the margin used for horizontal rules. - /// - public Thickness HorizontalRuleMargin - { - get => (Thickness)GetValue(HorizontalRuleMarginProperty); - set => SetValue(HorizontalRuleMarginProperty, value); - } - - /// - /// Gets or sets the vertical thickness of the horizontal rule. - /// - public double HorizontalRuleThickness - { - get => (double)GetValue(HorizontalRuleThicknessProperty); - set => SetValue(HorizontalRuleThicknessProperty, value); - } - - /// - /// Gets or sets the margin used by lists. - /// - public Thickness ListMargin - { - get => (Thickness)GetValue(ListMarginProperty); - set => SetValue(ListMarginProperty, value); - } - - /// - /// Gets or sets the width of the space used by list item bullets/numbers. - /// - public double ListGutterWidth - { - get => (double)GetValue(ListGutterWidthProperty); - set => SetValue(ListGutterWidthProperty, value); - } - - /// - /// Gets or sets the space between the list item bullets/numbers and the list item content. - /// - public double ListBulletSpacing - { - get => (double)GetValue(ListBulletSpacingProperty); - set => SetValue(ListBulletSpacingProperty, value); - } - - /// - /// Gets or sets the margin used for paragraphs. - /// - public Thickness ParagraphMargin - { - get => (Thickness)GetValue(ParagraphMarginProperty); - set => SetValue(ParagraphMarginProperty, value); - } - - /// - /// Gets or sets the line height used for paragraphs. - /// - public int ParagraphLineHeight - { - get => (int)GetValue(ParagraphLineHeightProperty); - set => SetValue(ParagraphLineHeightProperty, value); - } - - /// - /// Gets or sets the thickness of quote borders. - /// - public Thickness QuoteBorderThickness - { - get => (Thickness)GetValue(QuoteBorderThicknessProperty); - set => SetValue(QuoteBorderThicknessProperty, value); - } - - /// - /// Gets or sets the space outside of quote borders. - /// - public Thickness QuoteMargin - { - get => (Thickness)GetValue(QuoteMarginProperty); - set => SetValue(QuoteMarginProperty, value); - } - - /// - /// Gets or sets the space between the quote border and the text. - /// - public Thickness QuotePadding - { - get => (Thickness)GetValue(QuotePaddingProperty); - set => SetValue(QuotePaddingProperty, value); - } - - /// - /// Gets or sets the thickness of any yaml header borders. - /// - public double YamlBorderThickness - { - get => (double)GetValue(YamlBorderThicknessProperty); - set => SetValue(YamlBorderThicknessProperty, value); - } - - /// - /// Gets or sets the thickness of any table borders. - /// - public double TableBorderThickness - { - get => (double)GetValue(TableBorderThicknessProperty); - set => SetValue(TableBorderThicknessProperty, value); - } - - /// - /// Gets or sets the padding inside each cell. - /// - public Thickness TableCellPadding - { - get => (Thickness)GetValue(TableCellPaddingProperty); - set => SetValue(TableCellPaddingProperty, value); - } - - /// - /// Gets or sets the margin used by tables. - /// - public Thickness TableMargin - { - get => (Thickness)GetValue(TableMarginProperty); - set => SetValue(TableMarginProperty, value); - } - - /// - /// Gets or sets the word wrapping behavior. - /// - public TextWrapping TextWrapping - { - get => (TextWrapping)GetValue(TextWrappingProperty); - set => SetValue(TextWrappingProperty, value); - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Events.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Events.cs deleted file mode 100644 index fca584065..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Events.cs +++ /dev/null @@ -1,84 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - - /// - /// An efficient and extensible control that can parse and render markdown. - /// - public partial class MarkdownTextBlock - { - /// - /// Calls OnPropertyChanged. - /// - private static void OnPropertyChangedStatic(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var instance = d as MarkdownTextBlock; - - // Defer to the instance method. - instance?.OnPropertyChanged(d, e.Property); - } - - /// - /// Fired when the value of a DependencyProperty is changed. - /// - private void OnPropertyChanged(DependencyObject d, DependencyProperty prop) - { - RenderMarkdown(); - } - - /// - /// Fired when a user taps one of the link elements - /// - private void Hyperlink_Click(Hyperlink sender, HyperlinkClickEventArgs args) - { - LinkHandled((string)sender.GetValue(HyperlinkUrlProperty), true); - } - - /// - /// Fired when a user taps one of the image elements - /// - private void NewImagelink_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) - { - string hyperLink = (string)(sender as Image).GetValue(HyperlinkUrlProperty); - bool isHyperLink = (bool)(sender as Image).GetValue(IsHyperlinkProperty); - LinkHandled(hyperLink, isHyperLink); - } - - /// - /// Fired when the text is done parsing and formatting. Fires each time the markdown is rendered. - /// - public event EventHandler MarkdownRendered; - - /// - /// Fired when a link element in the markdown was tapped. - /// - public event EventHandler LinkClicked; - - /// - /// Fired when an image element in the markdown was tapped. - /// - public event EventHandler ImageClicked; - - /// - /// Fired when an image from the markdown document needs to be resolved. - /// The default implementation is basically new BitmapImage(new Uri(e.Url));. - /// You must set to true in order to process your changes. - /// - public event EventHandler ImageResolving; - - /// - /// Fired when a Code Block is being Rendered. - /// The default implementation is to output the CodeBlock as Plain Text. - /// You must set to true in order to process your changes. - /// - public event EventHandler CodeBlockResolving; - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Methods.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Methods.cs deleted file mode 100644 index a5ede2de5..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Methods.cs +++ /dev/null @@ -1,376 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Threading.Tasks; - using ColorCode; - using Windows.UI.Core; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Documents; - using Windows.UI.Xaml.Media; - using Windows.UI.Xaml.Media.Imaging; - using Notepads.Controls.Markdown; - - /// - /// An efficient and extensible control that can parse and render markdown. - /// - public partial class MarkdownTextBlock - { - /// - /// Sets the Markdown Renderer for Rendering the UI. - /// - /// The Inherited Markdown Render - public void SetRenderer() - where T : MarkdownRenderer - { - renderertype = typeof(T); - } - - /// - /// Called to preform a render of the current Markdown. - /// - private void RenderMarkdown() - { - // Leave if we don't have our root yet. - if (_rootElement == null) - { - return; - } - - // Disconnect from OnClick handlers. - UnhookListeners(); - - // Clear everything that exists. - _listeningHyperlinks.Clear(); - - var markdownRenderedArgs = new MarkdownRenderedEventArgs(null); - - // Make sure we have something to parse. - if (string.IsNullOrWhiteSpace(Text)) - { - _rootElement.Child = null; - } - else - { - try - { - // Try to parse the markdown. - MarkdownDocument markdown = new MarkdownDocument(); - foreach (string str in SchemeList.Split(',').ToList()) - { - if (!string.IsNullOrEmpty(str)) - { - MarkdownDocument.KnownSchemes.Add(str); - } - } - - markdown.Parse(Text); - - // Now try to display it - if (!(Activator.CreateInstance(renderertype, markdown, this, this, this) is MarkdownRenderer renderer)) - { - throw new Exception("Markdown Renderer was not of the correct type."); - } - - renderer.Background = Background; - renderer.BorderBrush = BorderBrush; - renderer.BorderThickness = BorderThickness; - renderer.CharacterSpacing = CharacterSpacing; - renderer.FontFamily = FontFamily; - renderer.FontSize = FontSize; - renderer.FontStretch = FontStretch; - renderer.FontStyle = FontStyle; - renderer.FontWeight = FontWeight; - renderer.Foreground = Foreground; - renderer.IsTextSelectionEnabled = IsTextSelectionEnabled; - renderer.Padding = Padding; - renderer.CodeBackground = CodeBackground; - renderer.CodeBorderBrush = CodeBorderBrush; - renderer.CodeBorderThickness = CodeBorderThickness; - renderer.InlineCodeBorderThickness = InlineCodeBorderThickness; - renderer.InlineCodeBackground = InlineCodeBackground; - renderer.InlineCodeBorderBrush = InlineCodeBorderBrush; - renderer.InlineCodePadding = InlineCodePadding; - renderer.InlineCodeFontFamily = InlineCodeFontFamily; - renderer.InlineCodeForeground = InlineCodeForeground; - renderer.CodeForeground = CodeForeground; - renderer.CodeFontFamily = CodeFontFamily; - renderer.CodePadding = CodePadding; - renderer.CodeMargin = CodeMargin; - renderer.EmojiFontFamily = EmojiFontFamily; - renderer.Header1FontSize = Header1FontSize; - renderer.Header1FontWeight = Header1FontWeight; - renderer.Header1Margin = Header1Margin; - renderer.Header1Foreground = Header1Foreground; - renderer.Header2FontSize = Header2FontSize; - renderer.Header2FontWeight = Header2FontWeight; - renderer.Header2Margin = Header2Margin; - renderer.Header2Foreground = Header2Foreground; - renderer.Header3FontSize = Header3FontSize; - renderer.Header3FontWeight = Header3FontWeight; - renderer.Header3Margin = Header3Margin; - renderer.Header3Foreground = Header3Foreground; - renderer.Header4FontSize = Header4FontSize; - renderer.Header4FontWeight = Header4FontWeight; - renderer.Header4Margin = Header4Margin; - renderer.Header4Foreground = Header4Foreground; - renderer.Header5FontSize = Header5FontSize; - renderer.Header5FontWeight = Header5FontWeight; - renderer.Header5Margin = Header5Margin; - renderer.Header5Foreground = Header5Foreground; - renderer.Header6FontSize = Header6FontSize; - renderer.Header6FontWeight = Header6FontWeight; - renderer.Header6Margin = Header6Margin; - renderer.Header6Foreground = Header6Foreground; - renderer.HorizontalRuleBrush = HorizontalRuleBrush; - renderer.HorizontalRuleMargin = HorizontalRuleMargin; - renderer.HorizontalRuleThickness = HorizontalRuleThickness; - renderer.ListMargin = ListMargin; - renderer.ListGutterWidth = ListGutterWidth; - renderer.ListBulletSpacing = ListBulletSpacing; - renderer.ParagraphMargin = ParagraphMargin; - renderer.ParagraphLineHeight = ParagraphLineHeight; - renderer.QuoteBackground = QuoteBackground; - renderer.QuoteBorderBrush = QuoteBorderBrush; - renderer.QuoteBorderThickness = QuoteBorderThickness; - renderer.QuoteForeground = QuoteForeground; - renderer.QuoteMargin = QuoteMargin; - renderer.QuotePadding = QuotePadding; - renderer.TableBorderBrush = TableBorderBrush; - renderer.TableBorderThickness = TableBorderThickness; - renderer.YamlBorderBrush = YamlBorderBrush; - renderer.YamlBorderThickness = YamlBorderThickness; - renderer.TableCellPadding = TableCellPadding; - renderer.TableMargin = TableMargin; - renderer.TextWrapping = TextWrapping; - renderer.LinkForeground = LinkForeground; - renderer.ImageStretch = ImageStretch; - renderer.ImageMaxHeight = ImageMaxHeight; - renderer.ImageMaxWidth = ImageMaxWidth; - renderer.WrapCodeBlock = WrapCodeBlock; - renderer.FlowDirection = FlowDirection; - - _rootElement.Child = renderer.Render(); - } - catch (Exception ex) - { - Debug.WriteLine("Error while parsing and rendering: " + ex.Message); - if (Debugger.IsAttached) - { - Debugger.Break(); - } - - markdownRenderedArgs = new MarkdownRenderedEventArgs(ex); - } - } - - // Indicate that the parse is done. - MarkdownRendered?.Invoke(this, markdownRenderedArgs); - } - - private void HookListeners() - { - // Re-hook all hyper link events we currently have - foreach (object link in _listeningHyperlinks) - { - if (link is Hyperlink hyperlink) - { - hyperlink.Click -= Hyperlink_Click; - hyperlink.Click += Hyperlink_Click; - } - else if (link is Image image) - { - image.Tapped -= NewImagelink_Tapped; - image.Tapped += NewImagelink_Tapped; - } - } - } - - private void UnhookListeners() - { - // Unhook any hyper link events if we have any - foreach (object link in _listeningHyperlinks) - { - if (link is Hyperlink hyperlink) - { - hyperlink.Click -= Hyperlink_Click; - } - else if (link is Image image) - { - image.Tapped -= NewImagelink_Tapped; - } - } - } - - /// - /// Called when the render has a link we need to listen to. - /// - public void RegisterNewHyperLink(Hyperlink newHyperlink, string linkUrl) - { - // Setup a listener for clicks. - newHyperlink.Click += Hyperlink_Click; - - // Associate the URL with the hyperlink. - newHyperlink.SetValue(HyperlinkUrlProperty, linkUrl); - - // Add it to our list - _listeningHyperlinks.Add(newHyperlink); - } - - /// - /// Called when the render has a link we need to listen to. - /// - public void RegisterNewHyperLink(Image newImagelink, string linkUrl, bool isHyperLink) - { - // Setup a listener for clicks. - newImagelink.Tapped += NewImagelink_Tapped; - - // Associate the URL with the hyperlink. - newImagelink.SetValue(HyperlinkUrlProperty, linkUrl); - - // Set if the Image is HyperLink or not - newImagelink.SetValue(IsHyperlinkProperty, isHyperLink); - - // Add it to our list - _listeningHyperlinks.Add(newImagelink); - } - - /// - /// Called when the renderer needs to display a image. - /// - /// A representing the asynchronous operation. - async Task IImageResolver.ResolveImageAsync(string url, string tooltip) - { - if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri)) - { - if (!string.IsNullOrEmpty(UriPrefix)) - { - url = $"{UriPrefix}{url}"; - } - } - - var eventArgs = new ImageResolvingEventArgs(url, tooltip); - ImageResolving?.Invoke(this, eventArgs); - - await eventArgs.WaitForDeferrals(); - - try - { - return eventArgs.Handled - ? eventArgs.Image - : GetImageSource(new Uri(url)); - } - catch (Exception) - { - return null; - } - - ImageSource GetImageSource(Uri imageUrl) - { - if (_isSvgImageSupported) - { - if (Path.GetExtension(imageUrl.AbsolutePath)?.ToLowerInvariant() == ".svg") - { - return new SvgImageSource(imageUrl); - } - } - - return new BitmapImage(imageUrl); - } - } - - /// - /// Called when a Code Block is being rendered. - /// - /// Parsing was handled Successfully - bool ICodeBlockResolver.ParseSyntax(InlineCollection inlineCollection, string text, string codeLanguage) - { - var eventArgs = new CodeBlockResolvingEventArgs(inlineCollection, text, codeLanguage); - CodeBlockResolving?.Invoke(this, eventArgs); - - try - { - var result = eventArgs.Handled; - if (UseSyntaxHighlighting && !result && codeLanguage != null) - { - var language = Languages.FindById(codeLanguage); - if (language != null) - { - RichTextBlockFormatter formatter; - if (CodeStyling != null) - { - formatter = new RichTextBlockFormatter(CodeStyling); - } - else - { - //var theme = themeListener.CurrentTheme == ApplicationTheme.Dark ? ElementTheme.Dark : ElementTheme.Light; - //if (RequestedTheme != ElementTheme.Default) - //{ - // theme = RequestedTheme; - //} - - var theme = ActualTheme; - if (RequestedTheme != ElementTheme.Default) - { - theme = RequestedTheme; - } - - formatter = new RichTextBlockFormatter(theme); - } - - formatter.FormatInlines(text, language, inlineCollection); - return true; - } - } - - return result; - } - catch - { - return false; - } - } - - /// - /// Called when a link needs to be handled - /// - internal async void LinkHandled(string url, bool isHyperlink) - { - // Links that are nested within superscript elements cause the Click event to fire multiple times. - // e.g. this markdown "[^bot](http://www.reddit.com/r/youtubefactsbot/wiki/index)" - // Therefore we detect and ignore multiple clicks. - if (multiClickDetectionTriggered) - { - return; - } - - multiClickDetectionTriggered = true; - await Dispatcher.RunAsync(CoreDispatcherPriority.High, () => multiClickDetectionTriggered = false); - - // Get the hyperlink URL. - if (url == null) - { - return; - } - - // Fire off the event. - var eventArgs = new LinkClickedEventArgs(url); - if (isHyperlink) - { - LinkClicked?.Invoke(this, eventArgs); - } - else - { - ImageClicked?.Invoke(this, eventArgs); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Properties.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Properties.cs deleted file mode 100644 index ae95a32ac..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.Properties.cs +++ /dev/null @@ -1,692 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using System; - using System.Collections.Generic; - using ColorCode.Styling; - using Windows.Foundation.Metadata; - using Windows.UI.Text; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - using Notepads.Controls.Markdown; - - /// - /// An efficient and extensible control that can parse and render markdown. - /// - public partial class MarkdownTextBlock - { - // SvgImageSource was introduced in Creators Update (15063) - private static readonly bool _isSvgImageSupported = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4); - - // Used to attach the URL to hyperlinks. - private static readonly DependencyProperty HyperlinkUrlProperty = - DependencyProperty.RegisterAttached("HyperlinkUrl", typeof(string), typeof(MarkdownTextBlock), new PropertyMetadata(null)); - - // Checks if clicked image is a hyperlink or not. - private static readonly DependencyProperty IsHyperlinkProperty = - DependencyProperty.RegisterAttached("IsHyperLink", typeof(string), typeof(MarkdownTextBlock), new PropertyMetadata(null)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeStylingProperty = - DependencyProperty.Register( - nameof(CodeStyling), - typeof(StyleDictionary), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty UseSyntaxHighlightingProperty = - DependencyProperty.Register( - nameof(UseSyntaxHighlighting), - typeof(bool), - typeof(MarkdownTextBlock), - new PropertyMetadata(true, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty WrapCodeBlockProperty = - DependencyProperty.Register(nameof(WrapCodeBlock), typeof(bool), typeof(MarkdownTextBlock), new PropertyMetadata(false)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - nameof(Text), - typeof(string), - typeof(MarkdownTextBlock), - new PropertyMetadata(string.Empty, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeBackgroundProperty = - DependencyProperty.Register( - nameof(InlineCodeBackground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeForegroundProperty = - DependencyProperty.Register( - nameof(InlineCodeForeground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeBorderBrushProperty = - DependencyProperty.Register( - nameof(InlineCodeBorderBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty IsTextSelectionEnabledProperty = DependencyProperty.Register( - nameof(IsTextSelectionEnabled), - typeof(bool), - typeof(MarkdownTextBlock), - new PropertyMetadata(true, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty LinkForegroundProperty = DependencyProperty.Register( - nameof(LinkForeground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeBackgroundProperty = DependencyProperty.Register( - nameof(CodeBackground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeBorderBrushProperty = DependencyProperty.Register( - nameof(CodeBorderBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeForegroundProperty = DependencyProperty.Register( - nameof(CodeForeground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty CodeFontFamilyProperty = DependencyProperty.Register( - nameof(CodeFontFamily), - typeof(FontFamily), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty InlineCodeFontFamilyProperty = DependencyProperty.Register( - nameof(InlineCodeFontFamily), - typeof(FontFamily), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty EmojiFontFamilyProperty = DependencyProperty.Register( - nameof(EmojiFontFamily), - typeof(FontFamily), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header1FontWeightProperty = DependencyProperty.Register( - nameof(Header1FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header1ForegroundProperty = DependencyProperty.Register( - nameof(Header1Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header2FontWeightProperty = DependencyProperty.Register( - nameof(Header2FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header2ForegroundProperty = DependencyProperty.Register( - nameof(Header2Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header3FontWeightProperty = DependencyProperty.Register( - nameof(Header3FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header3ForegroundProperty = DependencyProperty.Register( - nameof(Header3Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header4FontWeightProperty = DependencyProperty.Register( - nameof(Header4FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header4ForegroundProperty = DependencyProperty.Register( - nameof(Header4Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header5FontWeightProperty = DependencyProperty.Register( - nameof(Header5FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header5ForegroundProperty = DependencyProperty.Register( - nameof(Header5Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header6FontWeightProperty = DependencyProperty.Register( - nameof(Header6FontWeight), - typeof(FontWeight), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty Header6ForegroundProperty = DependencyProperty.Register( - nameof(Header6Foreground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty HorizontalRuleBrushProperty = DependencyProperty.Register( - nameof(HorizontalRuleBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuoteBackgroundProperty = DependencyProperty.Register( - nameof(QuoteBackground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuoteBorderBrushProperty = DependencyProperty.Register( - nameof(QuoteBorderBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty QuoteForegroundProperty = DependencyProperty.Register( - nameof(QuoteForeground), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty TableBorderBrushProperty = DependencyProperty.Register( - nameof(TableBorderBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty YamlBorderBrushProperty = DependencyProperty.Register( - nameof(YamlBorderBrush), - typeof(Brush), - typeof(MarkdownTextBlock), - new PropertyMetadata(null, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty UriPrefixProperty = DependencyProperty.Register( - nameof(UriPrefix), - typeof(string), - typeof(MarkdownTextBlock), - new PropertyMetadata(string.Empty, OnPropertyChangedStatic)); - - /// - /// Gets the dependency property for . - /// - public static readonly DependencyProperty SchemeListProperty = DependencyProperty.Register( - nameof(SchemeList), - typeof(string), - typeof(MarkdownTextBlock), - new PropertyMetadata(string.Empty, OnPropertyChangedStatic)); - - /// - /// Gets or sets the markdown text to display. - /// - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - /// - /// Gets or sets a value indicating whether to use Syntax Highlighting on Code. - /// - public bool UseSyntaxHighlighting - { - get => (bool)GetValue(UseSyntaxHighlightingProperty); - set => SetValue(UseSyntaxHighlightingProperty, value); - } - - /// - /// Gets or sets a value indicating whether to Wrap the Code Block or use a Horizontal Scroll. - /// - public bool WrapCodeBlock - { - get => (bool)GetValue(WrapCodeBlockProperty); - set => SetValue(WrapCodeBlockProperty, value); - } - - /// - /// Gets or sets the Default Code Styling for Code Blocks. - /// - public StyleDictionary CodeStyling - { - get => (StyleDictionary)GetValue(CodeStylingProperty); - set => SetValue(CodeStylingProperty, value); - } - - /// - /// Gets or sets a value indicating whether text selection is enabled. - /// - public bool IsTextSelectionEnabled - { - get => (bool)GetValue(IsTextSelectionEnabledProperty); - set => SetValue(IsTextSelectionEnabledProperty, value); - } - - /// - /// Gets or sets the brush used to render links. If this is - /// null, then Foreground is used. - /// - public Brush LinkForeground - { - get => (Brush)GetValue(LinkForegroundProperty); - set => SetValue(LinkForegroundProperty, value); - } - - /// - /// Gets or sets the brush used to fill the background of a code block. - /// - public Brush CodeBackground - { - get => (Brush)GetValue(CodeBackgroundProperty); - set => SetValue(CodeBackgroundProperty, value); - } - - /// - /// Gets or sets the brush used to render the border fill of a code block. - /// - public Brush CodeBorderBrush - { - get => (Brush)GetValue(CodeBorderBrushProperty); - set => SetValue(CodeBorderBrushProperty, value); - } - - /// - /// Gets or sets the brush used to render the text inside a code block. If this is - /// null, then Foreground is used. - /// - public Brush CodeForeground - { - get => (Brush)GetValue(CodeForegroundProperty); - set => SetValue(CodeForegroundProperty, value); - } - - /// - /// Gets or sets the font used to display code. If this is null, then - /// is used. - /// - public FontFamily CodeFontFamily - { - get => (FontFamily)GetValue(CodeFontFamilyProperty); - set => SetValue(CodeFontFamilyProperty, value); - } - - /// - /// Gets or sets the font used to display code. If this is null, then - /// is used. - /// - public FontFamily InlineCodeFontFamily - { - get => (FontFamily)GetValue(InlineCodeFontFamilyProperty); - set => SetValue(InlineCodeFontFamilyProperty, value); - } - - /// - /// Gets or sets the background brush for inline code. - /// - public Brush InlineCodeBackground - { - get => (Brush)GetValue(InlineCodeBackgroundProperty); - set => SetValue(InlineCodeBackgroundProperty, value); - } - - /// - /// Gets or sets the foreground brush for inline code. - /// - public Brush InlineCodeForeground - { - get => (Brush)GetValue(InlineCodeForegroundProperty); - set => SetValue(InlineCodeForegroundProperty, value); - } - - /// - /// Gets or sets the border brush for inline code. - /// - public Brush InlineCodeBorderBrush - { - get => (Brush)GetValue(InlineCodeBorderBrushProperty); - set => SetValue(InlineCodeBorderBrushProperty, value); - } - - /// - /// Gets or sets the font used to display emojis. If this is null, then - /// Segoe UI Emoji font is used. - /// - public FontFamily EmojiFontFamily - { - get => (FontFamily)GetValue(EmojiFontFamilyProperty); - set => SetValue(EmojiFontFamilyProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 1 headers. - /// - public FontWeight Header1FontWeight - { - get => (FontWeight)GetValue(Header1FontWeightProperty); - set => SetValue(Header1FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 1 headers. - /// - public Brush Header1Foreground - { - get => (Brush)GetValue(Header1ForegroundProperty); - set => SetValue(Header1ForegroundProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 2 headers. - /// - public FontWeight Header2FontWeight - { - get => (FontWeight)GetValue(Header2FontWeightProperty); - set => SetValue(Header2FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 2 headers. - /// - public Brush Header2Foreground - { - get => (Brush)GetValue(Header2ForegroundProperty); - set => SetValue(Header2ForegroundProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 3 headers. - /// - public FontWeight Header3FontWeight - { - get => (FontWeight)GetValue(Header3FontWeightProperty); - set => SetValue(Header3FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 3 headers. - /// - public Brush Header3Foreground - { - get => (Brush)GetValue(Header3ForegroundProperty); - set => SetValue(Header3ForegroundProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 4 headers. - /// - public FontWeight Header4FontWeight - { - get => (FontWeight)GetValue(Header4FontWeightProperty); - set => SetValue(Header4FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 4 headers. - /// - public Brush Header4Foreground - { - get => (Brush)GetValue(Header4ForegroundProperty); - set => SetValue(Header4ForegroundProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 5 headers. - /// - public FontWeight Header5FontWeight - { - get => (FontWeight)GetValue(Header5FontWeightProperty); - set => SetValue(Header5FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 5 headers. - /// - public Brush Header5Foreground - { - get => (Brush)GetValue(Header5ForegroundProperty); - set => SetValue(Header5ForegroundProperty, value); - } - - /// - /// Gets or sets the font weight to use for level 6 headers. - /// - public FontWeight Header6FontWeight - { - get => (FontWeight)GetValue(Header6FontWeightProperty); - set => SetValue(Header6FontWeightProperty, value); - } - - /// - /// Gets or sets the foreground brush for level 6 headers. - /// - public Brush Header6Foreground - { - get => (Brush)GetValue(Header6ForegroundProperty); - set => SetValue(Header6ForegroundProperty, value); - } - - /// - /// Gets or sets the brush used to render a horizontal rule. If this is null, then - /// is used. - /// - public Brush HorizontalRuleBrush - { - get => (Brush)GetValue(HorizontalRuleBrushProperty); - set => SetValue(HorizontalRuleBrushProperty, value); - } - - /// - /// Gets or sets the brush used to fill the background of a quote block. - /// - public Brush QuoteBackground - { - get => (Brush)GetValue(QuoteBackgroundProperty); - set => SetValue(QuoteBackgroundProperty, value); - } - - /// - /// Gets or sets the brush used to render a quote border. If this is null, then - /// is used. - /// - public Brush QuoteBorderBrush - { - get => (Brush)GetValue(QuoteBorderBrushProperty); - set => SetValue(QuoteBorderBrushProperty, value); - } - - /// - /// Gets or sets the brush used to render the text inside a quote block. If this is - /// null, then Foreground is used. - /// - public Brush QuoteForeground - { - get => (Brush)GetValue(QuoteForegroundProperty); - set => SetValue(QuoteForegroundProperty, value); - } - - /// - /// Gets or sets the brush used to render table borders. If this is null, then - /// is used. - /// - public Brush TableBorderBrush - { - get => (Brush)GetValue(TableBorderBrushProperty); - set => SetValue(TableBorderBrushProperty, value); - } - - /// - /// Gets or sets the brush used to render yaml borders. If this is null, then - /// is used. - /// - public Brush YamlBorderBrush - { - get => (Brush)GetValue(TableBorderBrushProperty); - set => SetValue(TableBorderBrushProperty, value); - } - - /// - /// Gets or sets the Prefix of Uri. - /// - public string UriPrefix - { - get => (string)GetValue(UriPrefixProperty); - set => SetValue(UriPrefixProperty, value); - } - - /// - /// Gets or sets the SchemeList. - /// - public string SchemeList - { - get => (string)GetValue(SchemeListProperty); - set => SetValue(SchemeListProperty, value); - } - - /// - /// Holds a list of hyperlinks we are listening to. - /// - private readonly List _listeningHyperlinks = new List(); - - /// - /// The root element for our rendering. - /// - private Border _rootElement; - - private bool multiClickDetectionTriggered; - - private Type renderertype = typeof(MarkdownRenderer); - - //private ThemeListener themeListener; - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.cs b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.cs deleted file mode 100644 index c39cec77c..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.cs +++ /dev/null @@ -1,130 +0,0 @@ -// 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. -// Source: https://github.com/windows-toolkit/WindowsCommunityToolkit/tree/master/Microsoft.Toolkit.Uwp.UI.Controls/MarkdownTextBlock - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Notepads.Controls.Markdown; - - /// - /// An efficient and extensible control that can parse and render markdown. - /// - public partial class MarkdownTextBlock : Control, ILinkRegister, IImageResolver, ICodeBlockResolver - { - private long _fontSizePropertyToken; - private long _flowDirectionPropertyToken; - private long _backgroundPropertyToken; - private long _borderBrushPropertyToken; - private long _borderThicknessPropertyToken; - private long _characterSpacingPropertyToken; - private long _fontFamilyPropertyToken; - private long _fontStretchPropertyToken; - private long _fontStylePropertyToken; - private long _fontWeightPropertyToken; - private long _foregroundPropertyToken; - private long _paddingPropertyToken; - private long _requestedThemePropertyToken; - - /// - /// Initializes a new instance of the class. - /// - public MarkdownTextBlock() - { - // Set our style. - DefaultStyleKey = typeof(MarkdownTextBlock); - - Loaded += OnLoaded; - Unloaded += OnUnloaded; - } - - //private void ThemeListener_ThemeChanged(Helpers.ThemeListener sender) - //{ - // if (ToElementTheme(sender.CurrentTheme) != RequestedTheme) - // { - // RenderMarkdown(); - // } - //} - - private void OnLoaded(object sender, RoutedEventArgs e) - { - RegisterThemeChangedHandler(); - HookListeners(); - - // Register for property callbacks that are owned by our parent class. - _fontSizePropertyToken = RegisterPropertyChangedCallback(FontSizeProperty, OnPropertyChanged); - _flowDirectionPropertyToken = RegisterPropertyChangedCallback(FlowDirectionProperty, OnPropertyChanged); - _backgroundPropertyToken = RegisterPropertyChangedCallback(BackgroundProperty, OnPropertyChanged); - _borderBrushPropertyToken = RegisterPropertyChangedCallback(BorderBrushProperty, OnPropertyChanged); - _borderThicknessPropertyToken = RegisterPropertyChangedCallback(BorderThicknessProperty, OnPropertyChanged); - _characterSpacingPropertyToken = RegisterPropertyChangedCallback(CharacterSpacingProperty, OnPropertyChanged); - _fontFamilyPropertyToken = RegisterPropertyChangedCallback(FontFamilyProperty, OnPropertyChanged); - _fontStretchPropertyToken = RegisterPropertyChangedCallback(FontStretchProperty, OnPropertyChanged); - _fontStylePropertyToken = RegisterPropertyChangedCallback(FontStyleProperty, OnPropertyChanged); - _fontWeightPropertyToken = RegisterPropertyChangedCallback(FontWeightProperty, OnPropertyChanged); - _foregroundPropertyToken = RegisterPropertyChangedCallback(ForegroundProperty, OnPropertyChanged); - _paddingPropertyToken = RegisterPropertyChangedCallback(PaddingProperty, OnPropertyChanged); - _requestedThemePropertyToken = RegisterPropertyChangedCallback(RequestedThemeProperty, OnPropertyChanged); - } - - private void OnUnloaded(object sender, RoutedEventArgs e) - { - //if (themeListener != null) - //{ - // UnhookListeners(); - // themeListener.ThemeChanged -= ThemeListener_ThemeChanged; - // themeListener.Dispose(); - // themeListener = null; - //} - - // Register for property callbacks that are owned by our parent class. - UnregisterPropertyChangedCallback(FontSizeProperty, _fontSizePropertyToken); - UnregisterPropertyChangedCallback(FlowDirectionProperty, _flowDirectionPropertyToken); - UnregisterPropertyChangedCallback(BackgroundProperty, _backgroundPropertyToken); - UnregisterPropertyChangedCallback(BorderBrushProperty, _borderBrushPropertyToken); - UnregisterPropertyChangedCallback(BorderThicknessProperty, _borderThicknessPropertyToken); - UnregisterPropertyChangedCallback(CharacterSpacingProperty, _characterSpacingPropertyToken); - UnregisterPropertyChangedCallback(FontFamilyProperty, _fontFamilyPropertyToken); - UnregisterPropertyChangedCallback(FontStretchProperty, _fontStretchPropertyToken); - UnregisterPropertyChangedCallback(FontStyleProperty, _fontStylePropertyToken); - UnregisterPropertyChangedCallback(FontWeightProperty, _fontWeightPropertyToken); - UnregisterPropertyChangedCallback(ForegroundProperty, _foregroundPropertyToken); - UnregisterPropertyChangedCallback(PaddingProperty, _paddingPropertyToken); - UnregisterPropertyChangedCallback(RequestedThemeProperty, _requestedThemePropertyToken); - } - - /// - protected override void OnApplyTemplate() - { - RegisterThemeChangedHandler(); - - // Grab our root - _rootElement = GetTemplateChild("RootElement") as Border; - - // And make sure to render any markdown we have. - RenderMarkdown(); - } - - private void RegisterThemeChangedHandler() - { - //themeListener = themeListener ?? new ThemeListener(); - //themeListener.ThemeChanged -= ThemeListener_ThemeChanged; - //themeListener.ThemeChanged += ThemeListener_ThemeChanged; - } - - //public static ElementTheme ToElementTheme(ApplicationTheme theme) - //{ - // switch (theme) - // { - // case ApplicationTheme.Light: - // return ElementTheme.Light; - // case ApplicationTheme.Dark: - // return ElementTheme.Dark; - // default: - // return ElementTheme.Default; - // } - //} - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.xaml b/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.xaml deleted file mode 100644 index c6e00ded2..000000000 --- a/src/Notepads.Controls/MarkdownTextBlock/MarkdownTextBlock.xaml +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Notepads.Controls/Notepads.Controls.csproj b/src/Notepads.Controls/Notepads.Controls.csproj deleted file mode 100644 index 6a72409b5..000000000 --- a/src/Notepads.Controls/Notepads.Controls.csproj +++ /dev/null @@ -1,338 +0,0 @@ - - - - - Debug - AnyCPU - {7AA5E631-B663-420E-A08F-002CD81DF855} - Library - Properties - Notepads.Controls - Notepads.Controls - en-US - UAP - 10.0.19041.0 - 10.0.17763.0 - 14 - 512 - {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Production\ - TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - x86 - true - bin\x86\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - x86 - bin\x86\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - x86 - bin\x86\Production\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM - true - bin\ARM\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - ARM - bin\ARM\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM - bin\ARM\Production\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM64 - true - bin\ARM64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - ARM64 - bin\ARM64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM64 - bin\ARM64\Production\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - x64 - true - bin\x64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - x64 - bin\x64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - x64 - bin\x64\Production\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - PackageReference - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 2.0.8 - - - 6.2.12 - - - 6.1.1 - - - 1.25.0 - - - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - MSBuild:Compile - Designer - - - Designer - MSBuild:Compile - - - - - 14.0 - - - - \ No newline at end of file diff --git a/src/Notepads.Controls/Properties/AssemblyInfo.cs b/src/Notepads.Controls/Properties/AssemblyInfo.cs deleted file mode 100644 index 62afbfb43..000000000 --- a/src/Notepads.Controls/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Notepads.Controls")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Notepads.Controls")] -[assembly: AssemblyCopyright("Copyright © 2020")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: ComVisible(false)] \ No newline at end of file diff --git a/src/Notepads.Controls/Properties/Notepads.Controls.rd.xml b/src/Notepads.Controls/Properties/Notepads.Controls.rd.xml deleted file mode 100644 index 49f7e139e..000000000 --- a/src/Notepads.Controls/Properties/Notepads.Controls.rd.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/src/Notepads.Controls/SetsView/SetClosingEventArgs.cs b/src/Notepads.Controls/SetsView/SetClosingEventArgs.cs deleted file mode 100644 index c09a24721..000000000 --- a/src/Notepads.Controls/SetsView/SetClosingEventArgs.cs +++ /dev/null @@ -1,40 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - - /// - /// Event arguments for event. - /// - public class SetClosingEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// Item being closed. - /// container being closed. - public SetClosingEventArgs(object item, SetsViewItem set) - { - Item = item; - Set = set; - } - - /// - /// Gets the Item being closed. - /// - public object Item { get; } - - /// - /// Gets the Set being closed. - /// - public SetsViewItem Set { get; } - - /// - /// Gets or sets a value indicating whether the notification should be closed. - /// - public bool Cancel { get; set; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetDraggedOutsideEventArgs.cs b/src/Notepads.Controls/SetsView/SetDraggedOutsideEventArgs.cs deleted file mode 100644 index 058bc07f2..000000000 --- a/src/Notepads.Controls/SetsView/SetDraggedOutsideEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - - /// - /// A class used by the TabDraggedOutside Event - /// - public class SetDraggedOutsideEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// data context of element dragged - /// container being dragged. - public SetDraggedOutsideEventArgs(object item, SetsViewItem set) - { - Item = item; - Set = set; - } - - /// - /// Gets or sets the Item/Data Context of the item being dragged outside of the . - /// - public object Item { get; set; } - - /// - /// Gets the Set being dragged outside of the . - /// - public SetsViewItem Set { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetSelectedEventArgs.cs b/src/Notepads.Controls/SetsView/SetSelectedEventArgs.cs deleted file mode 100644 index b42981e19..000000000 --- a/src/Notepads.Controls/SetsView/SetSelectedEventArgs.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - - /// - /// Event arguments for event. - /// - public class SetSelectedEventArgs : EventArgs - { - /// - /// Initializes a new instance of the class. - /// - /// Selected item. - /// Selected set. - public SetSelectedEventArgs(object item, SetsViewItem set) - { - Item = item; - Set = set; - } - - /// - /// Gets the Selected Item. - /// - public object Item { get; } - - /// - /// Gets the Selected Set. - /// - public SetsViewItem Set { get; } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsView.HeaderLayout.cs b/src/Notepads.Controls/SetsView/SetsView.HeaderLayout.cs deleted file mode 100644 index 27707bdda..000000000 --- a/src/Notepads.Controls/SetsView/SetsView.HeaderLayout.cs +++ /dev/null @@ -1,220 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - using System.Linq; - using Windows.UI.Xaml; - - /// - /// SetsView methods related to calculating the width of the Headers. - /// - public partial class SetsView - { - // Attached property for storing widths of sets if set by other means during layout. - private static double GetOriginalWidth(SetsViewItem obj) - { - return (double)obj.GetValue(OriginalWidthProperty); - } - - private static void SetOriginalWidth(SetsViewItem obj, double value) - { - obj.SetValue(OriginalWidthProperty, value); - } - - // Using a DependencyProperty as the backing store for MyProperty. This enables animation, styling, binding, etc... - private static readonly DependencyProperty OriginalWidthProperty = - DependencyProperty.RegisterAttached("OriginalWidth", typeof(double), typeof(SetsView), new PropertyMetadata(null)); - - private static void OnLayoutEffectingPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) - { - if (sender is SetsView setsView && setsView._hasLoaded) - { - setsView.SetsView_SizeChanged(setsView, null); - } - } - - private void SetsView_SizeChanged(object sender, SizeChangedEventArgs e) - { - // We need to do this calculation here in Size Changed as the - // Columns don't have their Actual Size calculated in Measure or Arrange. - if (_hasLoaded && _setsViewContainer != null) - { - // Look for our special columns to calculate size of other 'stuff' - var taken = _setsViewContainer.ColumnDefinitions.Sum(cd => GetIgnoreColumn(cd) ? 0 : cd.ActualWidth); - - // Get the column we want to work on for available space - var setc = _setsViewContainer.ColumnDefinitions.FirstOrDefault(cd => GetConstrainColumn(cd)); - if (setc != null) - { - var available = ActualWidth - taken; - var required = 0.0; - var minsetwidth = double.MaxValue; - - if (SetsWidthBehavior == SetsWidthMode.Actual) - { - if (_setsScroller != null) - { - // If we have a scroll container, get its size. - required = _setsScroller.ExtentWidth; - } - - // Restore original widths - foreach (var item in Items) - { - if (!(ContainerFromItem(item) is SetsViewItem set)) - { - continue; // container not generated yet - } - - if (set.ReadLocalValue(OriginalWidthProperty) != DependencyProperty.UnsetValue) - { - set.Width = GetOriginalWidth(set); - } - } - } - else if (available > 0) - { - // Calculate the width for each set from the provider and determine how much space they take. - foreach (var item in Items) - { - if (!(ContainerFromItem(item) is SetsViewItem set)) - { - continue; // container not generated yet - } - - minsetwidth = Math.Min(minsetwidth, set.MinWidth); - - double width = double.NaN; - - switch (SetsWidthBehavior) - { - case SetsWidthMode.Equal: - width = ProvideEqualWidth(set, available); - break; - case SetsWidthMode.Compact: - width = ProvideCompactWidth(set); - break; - } - - if (set.ReadLocalValue(OriginalWidthProperty) == DependencyProperty.UnsetValue) - { - SetOriginalWidth(set, set.Width); - } - - if (width > double.Epsilon) - { - set.Width = width; - required += Math.Max(Math.Min(width, set.MaxWidth), set.MinWidth); - } - else - { - set.Width = GetOriginalWidth(set); - required += set.ActualWidth; - } - } - } - else - { - // Fix negative bounds. - available = 0.0; - - // Still need to determine a 'minimum' width (if available) - // TODO: Consolidate this logic with above better? - foreach (var item in Items) - { - if (!(ContainerFromItem(item) is SetsViewItem set)) - { - continue; // container not generated yet - } - - minsetwidth = Math.Min(minsetwidth, set.MinWidth); - } - } - - if (!(minsetwidth < double.MaxValue)) - { - minsetwidth = 0.0; // No Containers, no visual, 0 size. - } - - if (available > minsetwidth) - { - // Constrain the column based on our required and available space - setc.MaxWidth = available; - } - - //// TODO: If it's less, should we move the selected set to only be the one shown by default? - - if (available <= minsetwidth || Math.Abs(available - minsetwidth) < double.Epsilon) - { - setc.Width = new GridLength(minsetwidth); - } - else if (required >= available) - { - // Fix size as we don't have enough space for all the sets. - setc.Width = new GridLength(available); - } - else - { - // We haven't filled up our space, so we want to expand to take as much as needed. - setc.Width = GridLength.Auto; - } - } - UpdateScrollViewerShadows(); - UpdateScrollViewerNavigateButtons(); - UpdateSetSeparators(); - } - } - - private double ProvideEqualWidth(SetsViewItem set, double availableWidth) - { - if (double.IsNaN(SelectedSetWidth)) - { - if (Items.Count <= 1) - { - return availableWidth; - } - - return Math.Max(set.MinWidth, availableWidth / Items.Count); - } - else if (Items.Count() <= 1) - { - // Default case of a single set, make it full size. - return Math.Min(SelectedSetWidth, availableWidth); - } - else - { - var width = (availableWidth - SelectedSetWidth) / (Items.Count - 1); - - // Constrain between Min and Selected (Max) - if (width < set.MinWidth) - { - width = set.MinWidth; - } - else if (width > SelectedSetWidth) - { - width = SelectedSetWidth; - } - - // If it's selected make it full size, otherwise whatever the size should be. - return set.IsSelected - ? Math.Min(SelectedSetWidth, availableWidth) - : width; - } - } - - private double ProvideCompactWidth(SetsViewItem set) - { - // If we're selected and have a value for that, then just return that. - if (set.IsSelected && !double.IsNaN(SelectedSetWidth)) - { - return SelectedSetWidth; - } - - // Otherwise use min size. - return set.MinWidth; - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsView.ItemSources.cs b/src/Notepads.Controls/SetsView/SetsView.ItemSources.cs deleted file mode 100644 index 7ae0cecb0..000000000 --- a/src/Notepads.Controls/SetsView/SetsView.ItemSources.cs +++ /dev/null @@ -1,114 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System.Reflection; - using Windows.Foundation.Collections; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls.Primitives; - - /// - /// SetsView methods related to tracking Items and ItemsSource changes. - /// - public partial class SetsView - { - // Temporary tracking of previous collections for removing events. - private MethodInfo _removeItemsSourceMethod; - - /// - protected override void OnItemsChanged(object e) - { - IVectorChangedEventArgs args = (IVectorChangedEventArgs)e; - - base.OnItemsChanged(e); - - if (args?.CollectionChange == CollectionChange.ItemRemoved && SelectedIndex == -1) - { - // If we remove the selected item we should select the previous item - int startIndex = (int)args.Index + 1; - if (startIndex > Items?.Count) - { - startIndex = 0; - } - - SelectedIndex = FindNextSetIndex(startIndex, -1); - } - - // Update Sizing (in case there are less items now) - SetsView_SizeChanged(this, null); - } - - private void ItemContainerGenerator_ItemsChanged(object sender, ItemsChangedEventArgs e) - { - var action = (CollectionChange)e.Action; - if (action == CollectionChange.Reset) - { - // Reset collection to reload later. - _hasLoaded = false; - } - } - - private void SetInitialSelection() - { - if (SelectedItem == null) - { - // If we have an index, but didn't get the selection, make the selection - if (SelectedIndex >= 0 && SelectedIndex < Items.Count) - { - SelectedItem = Items[SelectedIndex]; - } - - // Otherwise, select the first item by default - else if (Items.Count >= 1) - { - SelectedItem = Items[0]; - } - } - } - - // Finds the next visible & enabled set index. - private int FindNextSetIndex(int startIndex, int direction) - { - int index = startIndex; - if (direction != 0) - { - for (int i = 0; i < Items.Count; i++) - { - index += direction; - - if (index >= Items.Count) - { - index = 0; - } - else if (index < 0) - { - index = Items.Count - 1; - } - - if (ContainerFromIndex(index) is SetsViewItem setItem && setItem.IsEnabled && setItem.Visibility == Visibility.Visible) - { - break; - } - } - } - - return index; - } - - private void ItemsSource_PropertyChanged(DependencyObject sender, DependencyProperty dp) - { - // Use reflection to store a 'Remove' method of any possible collection in ItemsSource - // Cache for efficiency later. - if (ItemsSource != null) - { - _removeItemsSourceMethod = ItemsSource.GetType().GetMethod("Remove"); - } - else - { - _removeItemsSourceMethod = null; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsView.Properties.cs b/src/Notepads.Controls/SetsView/SetsView.Properties.cs deleted file mode 100644 index 9b9a2702e..000000000 --- a/src/Notepads.Controls/SetsView/SetsView.Properties.cs +++ /dev/null @@ -1,277 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - - /// - /// SetsView properties. - /// - public partial class SetsView - { - /// - /// Gets or sets the content to appear to the left or above the set strip. - /// - public object SetsStartHeader - { - get => GetValue(SetsStartHeaderProperty); - set => SetValue(SetsStartHeaderProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsStartHeaderProperty = - DependencyProperty.Register(nameof(SetsStartHeader), typeof(object), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the for the . - /// - public DataTemplate SetsStartHeaderTemplate - { - get => (DataTemplate)GetValue(SetsStartHeaderTemplateProperty); - set => SetValue(SetsStartHeaderTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsStartHeaderTemplateProperty = - DependencyProperty.Register(nameof(SetsStartHeaderTemplate), typeof(DataTemplate), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the content to appear next to the set strip. - /// - public object SetsActionHeader - { - get => GetValue(SetsActionHeaderProperty); - set => SetValue(SetsActionHeaderProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsActionHeaderProperty = - DependencyProperty.Register(nameof(SetsActionHeader), typeof(object), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the for the . - /// - public DataTemplate SetsActionHeaderTemplate - { - get => (DataTemplate)GetValue(SetsActionHeaderTemplateProperty); - set => SetValue(SetsActionHeaderTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsActionHeaderTemplateProperty = - DependencyProperty.Register(nameof(SetsActionHeaderTemplate), typeof(DataTemplate), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the content to appear to the right or below the action header. - /// - public object SetsPaddingHeader - { - get => GetValue(SetsPaddingHeaderProperty); - set => SetValue(SetsPaddingHeaderProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsPaddingHeaderProperty = - DependencyProperty.Register(nameof(SetsPaddingHeader), typeof(object), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the for the . - /// - public DataTemplate SetsPaddingHeaderTemplate - { - get => (DataTemplate)GetValue(SetsPaddingHeaderTemplateProperty); - set => SetValue(SetsPaddingHeaderTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsPaddingHeaderTemplateProperty = - DependencyProperty.Register(nameof(SetsPaddingHeaderTemplate), typeof(DataTemplate), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the content to appear to the right or below the set strip. - /// - public object SetsEndHeader - { - get => GetValue(SetsEndHeaderProperty); - set => SetValue(SetsEndHeaderProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsEndHeaderProperty = - DependencyProperty.Register(nameof(SetsEndHeader), typeof(object), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the for the . - /// - public DataTemplate SetsEndHeaderTemplate - { - get => (DataTemplate)GetValue(SetsEndHeaderTemplateProperty); - set => SetValue(SetsEndHeaderTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsEndHeaderTemplateProperty = - DependencyProperty.Register(nameof(SetsEndHeaderTemplate), typeof(DataTemplate), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the default for the . - /// - public DataTemplate ItemHeaderTemplate - { - get => (DataTemplate)GetValue(ItemHeaderTemplateTemplateProperty); - set => SetValue(ItemHeaderTemplateTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty ItemHeaderTemplateTemplateProperty = - DependencyProperty.Register(nameof(ItemHeaderTemplate), typeof(DataTemplate), typeof(SetsView), new PropertyMetadata(null, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets a value indicating whether by default a Set can be closed or not if no value to is provided. - /// - public bool CanCloseSets - { - get => (bool)GetValue(CanCloseSetsProperty); - set => SetValue(CanCloseSetsProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty CanCloseSetsProperty = - DependencyProperty.Register(nameof(CanCloseSets), typeof(bool), typeof(SetsView), new PropertyMetadata(false, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets a value indicating whether a Close Button should be included in layout calculations. - /// - public bool IsCloseButtonOverlay - { - get => (bool)GetValue(IsCloseButtonOverlayProperty); - set => SetValue(IsCloseButtonOverlayProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty IsCloseButtonOverlayProperty = - DependencyProperty.Register(nameof(IsCloseButtonOverlay), typeof(bool), typeof(SetsView), new PropertyMetadata(false, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets a value indicating the size of the selected set. By default this is set to Auto and the selected set size doesn't change. - /// - public double SelectedSetWidth - { - get => (double)GetValue(SelectedSetWidthProperty); - set => SetValue(SelectedSetWidthProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SelectedSetWidthProperty = - DependencyProperty.Register(nameof(SelectedSetWidth), typeof(double), typeof(SetsView), new PropertyMetadata(double.NaN, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets or sets the current which determins how set headers' width behave. - /// - public SetsWidthMode SetsWidthBehavior - { - get => (SetsWidthMode)GetValue(SetsWidthBehaviorProperty); - set => SetValue(SetsWidthBehaviorProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SetsWidthBehaviorProperty = - DependencyProperty.Register(nameof(SetsWidthBehavior), typeof(SetsWidthMode), typeof(SetsView), new PropertyMetadata(SetsWidthMode.Actual, OnLayoutEffectingPropertyChanged)); - - /// - /// Gets the attached property value to indicate if this grid column should be ignored when calculating header sizes. - /// - /// Grid Column. - /// Boolean indicating if this column is ignored by SetsViewHeader logic. - public static bool GetIgnoreColumn(ColumnDefinition obj) - { - return (bool)obj.GetValue(IgnoreColumnProperty); - } - - /// - /// Sets the attached property value for - /// - /// Grid Column. - /// Boolean value - public static void SetIgnoreColumn(ColumnDefinition obj, bool value) - { - obj?.SetValue(IgnoreColumnProperty, value); - } - - /// - /// Identifies the attached property. - /// - /// The identifier for the IgnoreColumn attached property. - public static readonly DependencyProperty IgnoreColumnProperty = - DependencyProperty.RegisterAttached("IgnoreColumn", typeof(bool), typeof(SetsView), new PropertyMetadata(false)); - - /// - /// Gets the attached value indicating this column should be restricted for the headers. - /// - /// Grid Column. - /// True if this column should be constrained. - public static bool GetConstrainColumn(ColumnDefinition obj) - { - return (bool)obj.GetValue(ConstrainColumnProperty); - } - - /// - /// Sets the attached property value for the - /// - /// Grid Column. - /// Boolean value. - public static void SetConstrainColumn(ColumnDefinition obj, bool value) - { - obj?.SetValue(ConstrainColumnProperty, value); - } - - /// - /// Identifies the attached property. - /// - /// The identifier for the ConstrainColumn attached property. - public static readonly DependencyProperty ConstrainColumnProperty = - DependencyProperty.RegisterAttached("ConstrainColumn", typeof(bool), typeof(SetsView), new PropertyMetadata(false)); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsView.cs b/src/Notepads.Controls/SetsView/SetsView.cs deleted file mode 100644 index c5e400f1f..000000000 --- a/src/Notepads.Controls/SetsView/SetsView.cs +++ /dev/null @@ -1,547 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - using System.Linq; - using Microsoft.Toolkit.Uwp.UI.Extensions; - using Windows.ApplicationModel.DataTransfer; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Controls.Primitives; - using Windows.UI.Xaml.Data; - using Windows.UI.Xaml.Input; - - /// - /// SetsView is a control for displaying a set of sets and their content. - /// - [TemplatePart(Name = SetsContentPresenterName, Type = typeof(ContentPresenter))] - [TemplatePart(Name = SetsViewContainerName, Type = typeof(Grid))] - [TemplatePart(Name = SetsItemsPresenterName, Type = typeof(ItemsPresenter))] - [TemplatePart(Name = SetsScrollViewerName, Type = typeof(ScrollViewer))] - [TemplatePart(Name = SetsScrollBackButtonName, Type = typeof(ButtonBase))] - [TemplatePart(Name = SetsScrollForwardButtonName, Type = typeof(ButtonBase))] - [TemplatePart(Name = SetsItemsScrollViewerLeftSideShadowName, Type = typeof(DropShadowPanel))] - [TemplatePart(Name = SetsItemsScrollViewerRightSideShadowName, Type = typeof(DropShadowPanel))] - public partial class SetsView : ListViewBase - { - private const int ScrollAmount = 50; // TODO: Should this be based on SetsWidthMode - - private const string SetsContentPresenterName = "SetsContentPresenter"; - private const string SetsViewContainerName = "SetsViewContainer"; - private const string SetsItemsPresenterName = "SetsItemsPresenter"; - private const string SetsScrollViewerName = "ScrollViewer"; - private const string SetsItemsScrollViewerLeftSideShadowName = "SetsItemsScrollViewerLeftSideShadow"; - private const string SetsItemsScrollViewerRightSideShadowName = "SetsItemsScrollViewerRightSideShadow"; - private const string SetsScrollBackButtonName = "SetsScrollBackButton"; - private const string SetsScrollForwardButtonName = "SetsScrollForwardButton"; - - private ContentPresenter _setsContentPresenter; - private Grid _setsViewContainer; - private ItemsPresenter _setItemsPresenter; - private ScrollViewer _setsScroller; - private DropShadowPanel _setsItemsScrollViewerLeftSideShadow; - private DropShadowPanel _setsItemsScrollViewerRightSideShadow; - private ButtonBase _setsScrollBackButton; - private ButtonBase _setsScrollForwardButton; - - private bool _hasLoaded; - private bool _isDragging; - - private double _scrollViewerHorizontalOffset = .0f; - public double ScrollViewerHorizontalOffset => _scrollViewerHorizontalOffset; - - /// - /// Initializes a new instance of the class. - /// - public SetsView() - { - DefaultStyleKey = typeof(SetsView); - - // Container Generation Hooks - RegisterPropertyChangedCallback(ItemsSourceProperty, ItemsSource_PropertyChanged); - ItemContainerGenerator.ItemsChanged += ItemContainerGenerator_ItemsChanged; - - // Drag and Layout Hooks - DragItemsStarting += SetsView_DragItemsStarting; - DragItemsCompleted += SetsView_DragItemsCompleted; - SizeChanged += SetsView_SizeChanged; - - // Selection Hook - SelectionChanged += SetsView_SelectionChanged; - } - - /// - /// Occurs when a set is dragged by the user outside of the . Generally, this paradigm is used to create a new-window with the torn-off set. - /// The creation and handling of the new-window is left to the app's developer. - /// - public event EventHandler SetDraggedOutside; - - /// - /// Occurs when a set's Close button is clicked. Set to true to prevent automatic Set Closure. - /// - public event EventHandler SetClosing; - - /// - /// Occurs when a set is selected in . - /// - public event EventHandler SetSelected; - - /// - /// Occurs when a set is tapped in . - /// - public event EventHandler SetTapped; - - /// - /// Occurs when a set is double tapped in . - /// - public event EventHandler SetDoubleTapped; - - /// - protected override DependencyObject GetContainerForItemOverride() - { - return new SetsViewItem(); - } - - /// - protected override bool IsItemItsOwnContainerOverride(object item) - { - return item is SetsViewItem; - } - - /// - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (_setItemsPresenter != null) - { - _setItemsPresenter.SizeChanged -= SetsView_SizeChanged; - } - - if (_setsScroller != null) - { - _setsScroller.Loaded -= SetsScrollViewer_Loaded; - _setsScroller.ViewChanged -= SetsScrollViewer_ViewChanged; - } - - _setsContentPresenter = GetTemplateChild(SetsContentPresenterName) as ContentPresenter; - _setsViewContainer = GetTemplateChild(SetsViewContainerName) as Grid; - _setItemsPresenter = GetTemplateChild(SetsItemsPresenterName) as ItemsPresenter; - _setsScroller = GetTemplateChild(SetsScrollViewerName) as ScrollViewer; - - if (_setItemsPresenter != null) - { - _setItemsPresenter.SizeChanged += SetsView_SizeChanged; - } - - if (_setsScroller != null) - { - _setsScroller.Loaded += SetsScrollViewer_Loaded; - _setsScroller.ViewChanged += SetsScrollViewer_ViewChanged; - } - } - - private void SetsScrollViewer_Loaded(object sender, RoutedEventArgs e) - { - _setsScroller.Loaded -= SetsScrollViewer_Loaded; - - if (_setsScrollBackButton != null) - { - _setsScrollBackButton.Click -= ScrollSetBackButton_Click; - } - - if (_setsScrollForwardButton != null) - { - _setsScrollForwardButton.Click -= ScrollSetForwardButton_Click; - } - - _setsScrollBackButton = _setsScroller.FindDescendantByName(SetsScrollBackButtonName) as ButtonBase; - _setsScrollForwardButton = _setsScroller.FindDescendantByName(SetsScrollForwardButtonName) as ButtonBase; - _setsItemsScrollViewerLeftSideShadow = _setsScroller.FindDescendantByName(SetsItemsScrollViewerLeftSideShadowName) as DropShadowPanel; - _setsItemsScrollViewerRightSideShadow = _setsScroller.FindDescendantByName(SetsItemsScrollViewerRightSideShadowName) as DropShadowPanel; - - if (_setsScrollBackButton != null) - { - _setsScrollBackButton.Click += ScrollSetBackButton_Click; - } - - if (_setsScrollForwardButton != null) - { - _setsScrollForwardButton.Click += ScrollSetForwardButton_Click; - } - } - - private void ScrollSetBackButton_Click(object sender, RoutedEventArgs e) - { - _setsScroller.ChangeView(Math.Max(0, _setsScroller.HorizontalOffset - ScrollAmount), null, null); - } - - private void ScrollSetForwardButton_Click(object sender, RoutedEventArgs e) - { - _setsScroller.ChangeView(Math.Min(_setsScroller.ScrollableWidth, _setsScroller.HorizontalOffset + ScrollAmount), null, null); - } - - private void SetsView_SelectionChanged(object sender, SelectionChangedEventArgs e) - { - if (_isDragging) - { - // Skip if we're dragging, we'll reset when we're done. - return; - } - - if (_setsContentPresenter != null) - { - if (SelectedItem == null) - { - _setsContentPresenter.Content = null; - _setsContentPresenter.ContentTemplate = null; - } - else - { - if (ContainerFromItem(SelectedItem) is SetsViewItem container) - { - _setsContentPresenter.Content = container.Content; - _setsContentPresenter.ContentTemplate = container.ContentTemplate; - - if (e != null) _setsContentPresenter.Loaded += SetsContentPresenter_Loaded; - } - } - - UpdateScrollViewerShadows(); - UpdateSetSeparators(); - } - - // If our width can be effected by the selection, need to run algorithm. - if (!double.IsNaN(SelectedSetWidth)) - { - SetsView_SizeChanged(sender, null); - } - } - - private void UpdateSetSeparators() - { - if (SelectedIndex > 0) - { - (ContainerFromIndex(0) as SetsViewItem)?.ShowLeftSideSeparator(); - } - else - { - (ContainerFromIndex(0) as SetsViewItem)?.HideLeftSideSeparator(); - } - - for (int i = 0; i < Items?.Count; i++) - { - if (i != SelectedIndex && i != SelectedIndex - 1) - { - (ContainerFromIndex(i) as SetsViewItem)?.ShowRightSideSeparator(); - } - else - { - (ContainerFromIndex(i) as SetsViewItem)?.HideRightSideSeparator(); - } - } - } - - private void SetsContentPresenter_Loaded(object sender, RoutedEventArgs e) - { - _setsContentPresenter.Loaded -= SetsContentPresenter_Loaded; - var args = new SetSelectedEventArgs(((SetsViewItem)ContainerFromItem(SelectedItem))?.Content, (SetsViewItem)ContainerFromItem(SelectedItem)); - SetSelected?.Invoke(this, args); - } - - /// - protected override void PrepareContainerForItemOverride(DependencyObject element, object item) - { - base.PrepareContainerForItemOverride(element, item); - - if (!(element is SetsViewItem setItem)) return; - - setItem.Loaded -= SetsViewItem_Loaded; - setItem.Closing -= SetsViewItem_Closing; - setItem.Tapped -= SetsViewItem_Tapped; - setItem.DoubleTapped -= SetsViewItem_DoubleTapped; - setItem.PointerEntered -= SetItem_PointerEntered; - setItem.PointerExited -= SetItem_PointerExited; - setItem.Loaded += SetsViewItem_Loaded; - setItem.Closing += SetsViewItem_Closing; - setItem.Tapped += SetsViewItem_Tapped; - setItem.DoubleTapped += SetsViewItem_DoubleTapped; - setItem.PointerEntered += SetItem_PointerEntered; - setItem.PointerExited += SetItem_PointerExited; - - if (setItem.Header == null) - { - setItem.Header = item; - } - - if (setItem.HeaderTemplate == null) - { - var headertemplatebinding = new Binding() - { - Source = this, - Path = new PropertyPath(nameof(ItemHeaderTemplate)), - Mode = BindingMode.OneWay - }; - setItem.SetBinding(SetsViewItem.HeaderTemplateProperty, headertemplatebinding); - } - - if (setItem.IsClosable != true && setItem.ReadLocalValue(SetsViewItem.IsClosableProperty) == - DependencyProperty.UnsetValue) - { - var iscloseablebinding = new Binding() - { - Source = this, - Path = new PropertyPath(nameof(CanCloseSets)), - Mode = BindingMode.OneWay, - }; - setItem.SetBinding(SetsViewItem.IsClosableProperty, iscloseablebinding); - } - } - - private void SetItem_PointerEntered(object sender, PointerRoutedEventArgs e) - { - if (sender is SetsViewItem set) - { - set.HideRightSideSeparator(); - var index = IndexFromContainer(set); - if (index > 0) - { - (ContainerFromIndex(index - 1) as SetsViewItem)?.HideRightSideSeparator(); - } - - set.HideLeftSideSeparator(); - } - } - - private void SetItem_PointerExited(object sender, PointerRoutedEventArgs e) - { - if (sender is SetsViewItem set) - { - var index = IndexFromContainer(set); - - if (index == 0 && SelectedIndex != index) - { - set.ShowLeftSideSeparator(); - } - - if (SelectedIndex == index - 1) - { - set.ShowRightSideSeparator(); - } - else if (SelectedIndex == index + 1) - { - if (index > 0) - { - (ContainerFromIndex(index - 1) as SetsViewItem)?.ShowRightSideSeparator(); - } - } - else if (SelectedIndex != index) - { - set.ShowRightSideSeparator(); - if (index > 0) - { - (ContainerFromIndex(index - 1) as SetsViewItem)?.ShowRightSideSeparator(); - } - } - } - } - - private void SetsViewItem_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) - { - var args = new SetSelectedEventArgs(((SetsViewItem)ContainerFromItem(SelectedItem))?.Content, (SetsViewItem)ContainerFromItem(SelectedItem)); - SetDoubleTapped?.Invoke(sender, args); - } - - private void SetsViewItem_Tapped(object sender, TappedRoutedEventArgs e) - { - var args = new SetSelectedEventArgs(((SetsViewItem)ContainerFromItem(SelectedItem))?.Content, (SetsViewItem)ContainerFromItem(SelectedItem)); - SetTapped?.Invoke(sender, args); - } - - private void SetsViewItem_Loaded(object sender, RoutedEventArgs e) - { - var setItem = sender as SetsViewItem; - - setItem.Loaded -= SetsViewItem_Loaded; - - // Only need to do this once. - if (!_hasLoaded) - { - _hasLoaded = true; - - // Need to set a set's selection on load, otherwise ListView resets to null. - SetInitialSelection(); - - // Need to make sure ContentPresenter is set to content based on selection. - SetsView_SelectionChanged(this, null); - - // Need to make sure we've registered our removal method. - ItemsSource_PropertyChanged(this, null); - - // Make sure we complete layout now. - SetsView_SizeChanged(this, null); - } - } - - private void SetsViewItem_Closing(object sender, SetClosingEventArgs e) - { - var item = ItemFromContainer(e.Set); - - var args = new SetClosingEventArgs(item, e.Set); - SetClosing?.Invoke(this, args); - - if (!args.Cancel) - { - e.Set.PrepareForClosing(); - if (ItemsSource != null) - { - _removeItemsSourceMethod?.Invoke(ItemsSource, new object[] { item }); - } - else - { - Items?.Remove(item); - } - } - } - - private void SetsView_DragItemsStarting(object sender, DragItemsStartingEventArgs e) - { - // Keep track of drag so we don't modify content until done. - _isDragging = true; - - _setsItemsScrollViewerLeftSideShadow.Visibility = Visibility.Collapsed; - _setsItemsScrollViewerRightSideShadow.Visibility = Visibility.Collapsed; - } - - private void SetsView_DragItemsCompleted(ListViewBase sender, DragItemsCompletedEventArgs args) - { - _isDragging = false; - - // args.DropResult == None when outside of area (e.g. create new window) - if (args.DropResult == DataPackageOperation.None) - { - var item = args.Items.FirstOrDefault(); - var set = ContainerFromItem(item) as SetsViewItem; - - if (set == null && item is FrameworkElement fe) - { - set = fe.FindParent(); - } - - if (set == null) - { - // We still don't have a SetsViewItem, most likely is a static SetsViewItem in the template being dragged and not selected. - // This is a fallback scenario for static sets. - // Note: This can be wrong if two SetsViewItems share the exact same Content (i.e. a string), this should be unlikely in any practical scenario. - for (int i = 0; i < Items.Count; i++) - { - var setItem = ContainerFromIndex(i) as SetsViewItem; - if (ReferenceEquals(setItem.Content, item)) - { - set = setItem; - break; - } - } - } - - SetDraggedOutside?.Invoke(this, new SetDraggedOutsideEventArgs(item, set)); - - UpdateScrollViewerShadows(); - } - else - { - // If dragging the active set, there's an issue with the CP blanking. - SetsView_SelectionChanged(this, null); - } - } - - private void SetsScrollViewer_ViewChanged(object sender, ScrollViewerViewChangedEventArgs e) - { - _scrollViewerHorizontalOffset = _setsScroller.HorizontalOffset; - UpdateScrollViewerShadows(); - UpdateScrollViewerNavigateButtons(); - } - - public void ScrollToLastSet() - { - ScrollTo(double.MaxValue); - } - - public void ScrollTo(double offset) - { - try - { - _setsScroller?.UpdateLayout(); - _setsScroller?.ChangeView(offset, 0.0f, 1.0f); - } - catch (Exception ex) - { - throw new Exception($"SetsView failed to scroll to offset: {(long)offset}, Exception: {ex}"); - } - } - - // HACK: Simulate left most and right most (tab) edge shadow - // since I am too lazy to figure out the "right way" to make shadow visible on scroll viewer edges - /// TODO This method should be removed when better solution is available in the future - private void UpdateScrollViewerShadows() - { - if (_setsItemsScrollViewerLeftSideShadow == null || - _setsItemsScrollViewerRightSideShadow == null) - { - return; - } - - if (Items?.Count == 1) - { - _setsItemsScrollViewerLeftSideShadow.Visibility = Visibility.Visible; - _setsItemsScrollViewerRightSideShadow.Visibility = Visibility.Visible; - return; - } - - if (SelectedIndex == 0) - { - if (Math.Abs(_scrollViewerHorizontalOffset) < 3) - { - _setsItemsScrollViewerLeftSideShadow.Visibility = Visibility.Visible; - _setsItemsScrollViewerRightSideShadow.Visibility = Visibility.Collapsed; - return; - } - } - else if (SelectedIndex == Items?.Count - 1) - { - var offset = _setsScroller.ExtentWidth - _setsScroller.ViewportWidth - _scrollViewerHorizontalOffset; - if (Math.Abs(offset) < 3) - { - _setsItemsScrollViewerLeftSideShadow.Visibility = Visibility.Collapsed; - _setsItemsScrollViewerRightSideShadow.Visibility = Visibility.Visible; - return; - } - } - - _setsItemsScrollViewerLeftSideShadow.Visibility = Visibility.Collapsed; - _setsItemsScrollViewerRightSideShadow.Visibility = Visibility.Collapsed; - } - - private void UpdateScrollViewerNavigateButtons() - { - if (Math.Abs(_setsScroller.HorizontalOffset - _setsScroller.ScrollableWidth) < 0.1) - { - _setsScrollBackButton.IsEnabled = true; - _setsScrollForwardButton.IsEnabled = false; - } - else if (Math.Abs(_setsScroller.HorizontalOffset) < 0.1) - { - _setsScrollBackButton.IsEnabled = false; - _setsScrollForwardButton.IsEnabled = true; - } - else - { - _setsScrollBackButton.IsEnabled = true; - _setsScrollForwardButton.IsEnabled = true; - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsView.xaml b/src/Notepads.Controls/SetsView/SetsView.xaml deleted file mode 100644 index aec7dccde..000000000 --- a/src/Notepads.Controls/SetsView/SetsView.xaml +++ /dev/null @@ -1,1063 +0,0 @@ - - - - - - - - - - - - - - - - - 0.55 - - - - - - - - - - - - - - - - - 0.7 - - - - - - - - - - - - - - - - - 0.0 - - - - - 0 - 0,2,6,0 - 0,1,0,0 - 0,1,0,0 - 10 - 48 - 40 - NaN - 24 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/Notepads.Controls/SetsView/SetsViewItem.Properties.cs b/src/Notepads.Controls/SetsView/SetsViewItem.Properties.cs deleted file mode 100644 index 2a01fd140..000000000 --- a/src/Notepads.Controls/SetsView/SetsViewItem.Properties.cs +++ /dev/null @@ -1,96 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - - /// - /// Item Container for a . - /// - public partial class SetsViewItem - { - /// - /// Gets or sets the header content for the set. - /// - public object Header - { - get => GetValue(HeaderProperty); - set => SetValue(HeaderProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty HeaderProperty = - DependencyProperty.Register(nameof(Header), typeof(object), typeof(SetsViewItem), new PropertyMetadata(null)); - - /// - /// Gets or sets the icon to appear in the set header. - /// - public IconElement Icon - { - get => (IconElement)GetValue(IconProperty); - set => SetValue(IconProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty IconProperty = - DependencyProperty.Register(nameof(Icon), typeof(IconElement), typeof(SetsViewItem), new PropertyMetadata(null)); - - /// - /// Gets or sets the template to override for the set header. - /// - public DataTemplate HeaderTemplate - { - get => (DataTemplate)GetValue(HeaderTemplateProperty); - set => SetValue(HeaderTemplateProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty HeaderTemplateProperty = - DependencyProperty.Register(nameof(HeaderTemplate), typeof(DataTemplate), typeof(SetsViewItem), new PropertyMetadata(null)); - - /// - /// Gets or sets a value indicating whether the set can be closed by the user with the close button. - /// - public bool IsClosable - { - get => (bool)GetValue(IsClosableProperty); - set => SetValue(IsClosableProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty IsClosableProperty = - DependencyProperty.Register(nameof(IsClosable), typeof(bool), typeof(SetsViewItem), new PropertyMetadata(null)); - - /// - /// Gets or sets the selection indicator brush - /// - public Brush SelectionIndicatorForeground - { - get => (Brush)GetValue(SelectionIndicatorForegroundProperty); - set => SetValue(SelectionIndicatorForegroundProperty, value); - } - - /// - /// Identifies the dependency property. - /// - /// The identifier for the dependency property. - public static readonly DependencyProperty SelectionIndicatorForegroundProperty = - DependencyProperty.Register(nameof(SelectionIndicatorForeground), typeof(Brush), typeof(SetsViewItem), new PropertyMetadata(null)); - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsViewItem.cs b/src/Notepads.Controls/SetsView/SetsViewItem.cs deleted file mode 100644 index 51b840645..000000000 --- a/src/Notepads.Controls/SetsView/SetsViewItem.cs +++ /dev/null @@ -1,183 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using System; - using Windows.Devices.Input; - using Windows.System; - using Windows.UI; - using Windows.UI.Core; - using Windows.UI.Input; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Controls.Primitives; - using Windows.UI.Xaml.Input; - using Windows.UI.Xaml.Media; - using Windows.UI.Xaml.Shapes; - - /// - /// Item Container for a . - /// - [TemplatePart(Name = SetCloseButtonName, Type = typeof(ButtonBase))] - [TemplatePart(Name = SetLeftSideSeparatorName, Type = typeof(Border))] - [TemplatePart(Name = SetRightSideSeparatorName, Type = typeof(Border))] - [TemplatePart(Name = SetSelectionIndicatorName, Type = typeof(Rectangle))] - public partial class SetsViewItem : ListViewItem - { - private const string SetCloseButtonName = "CloseButton"; - - private const string SetLeftSideSeparatorName = "LeftSideSeparator"; - - private const string SetRightSideSeparatorName = "RightSideSeparator"; - - private const string SetSelectionIndicatorName = "SelectionIndicator"; - - private ButtonBase _setCloseButton; - - private Border _setLeftSideSeparator; - - private Border _setRightSideSeparator; - - private Rectangle _setSelectionIndicator; - - private bool _isMiddleClick; - - /// - /// Initializes a new instance of the class. - /// - public SetsViewItem() - { - DefaultStyleKey = typeof(SetsViewItem); - } - - /// - /// Fired when the Set's close button is clicked. - /// - public event EventHandler Closing; - - public void ShowLeftSideSeparator() - { - if (_setLeftSideSeparator != null) - { - _setLeftSideSeparator.Visibility = Visibility.Visible; - } - } - - public void HideLeftSideSeparator() - { - if (_setLeftSideSeparator != null) - { - _setLeftSideSeparator.Visibility = Visibility.Collapsed; - } - } - - public void ShowRightSideSeparator() - { - if (_setRightSideSeparator != null) - { - _setRightSideSeparator.Visibility = Visibility.Visible; - } - } - - public void HideRightSideSeparator() - { - if (_setRightSideSeparator != null) - { - _setRightSideSeparator.Visibility = Visibility.Collapsed; - } - } - - /// - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - if (_setCloseButton != null) - { - _setCloseButton.Click -= SetCloseButton_Click; - } - - _setCloseButton = GetTemplateChild(SetCloseButtonName) as ButtonBase; - - if (_setCloseButton != null) - { - _setCloseButton.Click += SetCloseButton_Click; - } - - _setLeftSideSeparator = GetTemplateChild(SetLeftSideSeparatorName) as Border; - _setRightSideSeparator = GetTemplateChild(SetRightSideSeparatorName) as Border; - _setSelectionIndicator = GetTemplateChild(SetSelectionIndicatorName) as Rectangle; - } - - /// - protected override void OnPointerPressed(PointerRoutedEventArgs e) - { - _isMiddleClick = false; - - if (e?.Pointer.PointerDeviceType == PointerDeviceType.Mouse) - { - PointerPoint pointerPoint = e.GetCurrentPoint(this); - - // Record if middle button is pressed - if (pointerPoint.Properties.IsMiddleButtonPressed) - { - _isMiddleClick = true; - } - - // Disable unwanted behaviour inherited by ListViewItem: - // Disable "Ctrl + Left click" to deselect tab - // Or variant like "Ctrl + Shift + Left click" - // Or "Ctrl + Alt + Left click" - if (pointerPoint.Properties.IsLeftButtonPressed) - { - var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control); - if (ctrl.HasFlag(CoreVirtualKeyStates.Down)) - { - // return here so the event won't be picked up by the base class - // but keep this event unhandled so it can be picked up further - return; - } - } - } - - base.OnPointerPressed(e); - } - - /// - protected override void OnPointerReleased(PointerRoutedEventArgs e) - { - base.OnPointerReleased(e); - - // Close on Middle-Click - if (_isMiddleClick) - { - SetCloseButton_Click(this, null); - } - - _isMiddleClick = false; - } - - public void PrepareForClosing() - { - _setSelectionIndicator.Fill = new SolidColorBrush(Colors.Transparent); - } - - public void Close() - { - if (IsClosable) - { - Closing?.Invoke(this, new SetClosingEventArgs(Content, this)); - } - } - - private void SetCloseButton_Click(object sender, RoutedEventArgs e) - { - if (IsClosable) - { - Closing?.Invoke(this, new SetClosingEventArgs(Content, this)); - } - } - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/SetsView/SetsWidthMode.cs b/src/Notepads.Controls/SetsView/SetsWidthMode.cs deleted file mode 100644 index ead2b759a..000000000 --- a/src/Notepads.Controls/SetsView/SetsWidthMode.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -namespace Notepads.Controls -{ - using Windows.UI.Xaml; - - /// - /// Possible modes for how to layout a Header's Width in the . - /// - public enum SetsWidthMode - { - /// - /// Each set header takes up as much space as it needs. This is similar to how WPF and Visual Studio Code behave. - /// Suggest to keep set to false. - /// is ignored. - /// In this scenario, set width behavior is effectively turned off. This can be useful when using custom styling or a custom panel for layout of as well. - /// - Actual, - - /// - /// Each set header will use the minimal space set by on the . - /// Suggest to set the to show more content for the selected item. - /// - Compact, - - /// - /// Each set header will fill to fit the available space. If is set, that will be used as a Maximum Width. - /// This is similar to how Microsoft Edge behaves when used with the . - /// Suggest to set to true. - /// Suggest to set to 200 and the SetsViewItemHeaderMinWidth Resource to 90. - /// - Equal, - } -} \ No newline at end of file diff --git a/src/Notepads.Controls/Themes/Generic.xaml b/src/Notepads.Controls/Themes/Generic.xaml deleted file mode 100644 index 31a484fa8..000000000 --- a/src/Notepads.Controls/Themes/Generic.xaml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - diff --git a/src/Notepads.sln b/src/Notepads.sln index fad9f03e9..723e20ed0 100644 --- a/src/Notepads.sln +++ b/src/Notepads.sln @@ -4,11 +4,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 VisualStudioVersion = 16.0.28803.352 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notepads", "Notepads\Notepads.csproj", "{99274932-9E86-480C-8142-38525F80007D}" - ProjectSection(ProjectDependencies) = postProject - {7AA5E631-B663-420E-A08F-002CD81DF855} = {7AA5E631-B663-420E-A08F-002CD81DF855} - EndProjectSection -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Notepads.Controls", "Notepads.Controls\Notepads.Controls.csproj", "{7AA5E631-B663-420E-A08F-002CD81DF855}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{FE6A4F54-39DC-40E3-8BFB-5B1962DED402}" ProjectSection(SolutionItems) = preProject @@ -20,12 +15,12 @@ Global Debug|ARM64 = Debug|ARM64 Debug|x64 = Debug|x64 Debug|x86 = Debug|x86 - Release|ARM64 = Release|ARM64 - Release|x64 = Release|x64 - Release|x86 = Release|x86 Production|ARM64 = Production|ARM64 Production|x64 = Production|x64 Production|x86 = Production|x86 + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {99274932-9E86-480C-8142-38525F80007D}.Debug|ARM64.ActiveCfg = Debug|ARM64 @@ -37,15 +32,6 @@ Global {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.ActiveCfg = Debug|x86 {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.Build.0 = Debug|x86 {99274932-9E86-480C-8142-38525F80007D}.Debug|x86.Deploy.0 = Debug|x86 - {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.ActiveCfg = Release|ARM64 - {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Build.0 = Release|ARM64 - {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Deploy.0 = Release|ARM64 - {99274932-9E86-480C-8142-38525F80007D}.Release|x64.ActiveCfg = Release|x64 - {99274932-9E86-480C-8142-38525F80007D}.Release|x64.Build.0 = Release|x64 - {99274932-9E86-480C-8142-38525F80007D}.Release|x64.Deploy.0 = Release|x64 - {99274932-9E86-480C-8142-38525F80007D}.Release|x86.ActiveCfg = Release|x86 - {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Build.0 = Release|x86 - {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Deploy.0 = Release|x86 {99274932-9E86-480C-8142-38525F80007D}.Production|ARM64.ActiveCfg = Production|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Production|ARM64.Build.0 = Production|ARM64 {99274932-9E86-480C-8142-38525F80007D}.Production|ARM64.Deploy.0 = Production|ARM64 @@ -55,24 +41,15 @@ Global {99274932-9E86-480C-8142-38525F80007D}.Production|x86.ActiveCfg = Production|x86 {99274932-9E86-480C-8142-38525F80007D}.Production|x86.Build.0 = Production|x86 {99274932-9E86-480C-8142-38525F80007D}.Production|x86.Deploy.0 = Production|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM64.ActiveCfg = Debug|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|ARM64.Build.0 = Debug|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x64.ActiveCfg = Debug|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x64.Build.0 = Debug|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x86.ActiveCfg = Debug|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Debug|x86.Build.0 = Debug|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM64.ActiveCfg = Release|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|ARM64.Build.0 = Release|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x64.ActiveCfg = Release|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x64.Build.0 = Release|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x86.ActiveCfg = Release|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Release|x86.Build.0 = Release|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|ARM64.ActiveCfg = Production|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|ARM64.Build.0 = Production|ARM64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|x64.ActiveCfg = Production|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|x64.Build.0 = Production|x64 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|x86.ActiveCfg = Production|x86 - {7AA5E631-B663-420E-A08F-002CD81DF855}.Production|x86.Build.0 = Production|x86 + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.ActiveCfg = Release|ARM64 + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Build.0 = Release|ARM64 + {99274932-9E86-480C-8142-38525F80007D}.Release|ARM64.Deploy.0 = Release|ARM64 + {99274932-9E86-480C-8142-38525F80007D}.Release|x64.ActiveCfg = Release|x64 + {99274932-9E86-480C-8142-38525F80007D}.Release|x64.Build.0 = Release|x64 + {99274932-9E86-480C-8142-38525F80007D}.Release|x64.Deploy.0 = Release|x64 + {99274932-9E86-480C-8142-38525F80007D}.Release|x86.ActiveCfg = Release|x86 + {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Build.0 = Release|x86 + {99274932-9E86-480C-8142-38525F80007D}.Release|x86.Deploy.0 = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/Notepads/App.xaml b/src/Notepads/App.xaml index af23eda27..773fe11a7 100644 --- a/src/Notepads/App.xaml +++ b/src/Notepads/App.xaml @@ -1,47 +1,22 @@  + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls"> - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Notepads/App.xaml.cs b/src/Notepads/App.xaml.cs index c56ee5d4b..db619daf6 100644 --- a/src/Notepads/App.xaml.cs +++ b/src/Notepads/App.xaml.cs @@ -106,8 +106,8 @@ private async Task ActivateAsync(IActivatedEventArgs e) var appLaunchSettings = new Dictionary() { - { "OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString() }, - { "OSVersion", $"{SystemInformation.OperatingSystemVersion.Major}.{SystemInformation.OperatingSystemVersion.Minor}.{SystemInformation.OperatingSystemVersion.Build}" }, + { "OSArchitecture", SystemInformation.Instance.OperatingSystemArchitecture.ToString() }, + { "OSVersion", $"{SystemInformation.Instance.OperatingSystemVersion.Major}.{SystemInformation.Instance.OperatingSystemVersion.Minor}.{SystemInformation.Instance.OperatingSystemVersion.Build}" }, { "UseWindowsTheme", ThemeSettingsService.UseWindowsTheme.ToString() }, { "ThemeMode", ThemeSettingsService.ThemeMode.ToString() }, { "UseWindowsAccentColor", ThemeSettingsService.UseWindowsAccentColor.ToString() }, @@ -229,11 +229,11 @@ private static void OnUnhandledException(object sender, Windows.UI.Xaml.Unhandle { { "Message", e.Message }, { "Exception", e.Exception?.ToString() }, - { "Culture", SystemInformation.Culture.EnglishName }, - { "AvailableMemory", SystemInformation.AvailableMemory.ToString("F0") }, - { "FirstUseTimeUTC", SystemInformation.FirstUseTime.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss") }, - { "OSArchitecture", SystemInformation.OperatingSystemArchitecture.ToString() }, - { "OSVersion", SystemInformation.OperatingSystemVersion.ToString() }, + { "Culture", SystemInformation.Instance.Culture.EnglishName }, + { "AvailableMemory", SystemInformation.Instance.AvailableMemory.ToString("F0") }, + { "FirstUseTimeUTC", SystemInformation.Instance.FirstUseTime.ToUniversalTime().ToString("MM/dd/yyyy HH:mm:ss") }, + { "OSArchitecture", SystemInformation.Instance.OperatingSystemArchitecture.ToString() }, + { "OSVersion", SystemInformation.Instance.OperatingSystemVersion.ToString() }, { "IsShadowWindow", (!IsPrimaryInstance && !IsGameBarWidget).ToString() }, { "IsGameBarWidget", IsGameBarWidget.ToString() } }; diff --git a/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs b/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs index 281d0edaf..dc6decb92 100644 --- a/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs +++ b/src/Notepads/Brushes/HostBackdropAcrylicBrush.cs @@ -21,7 +21,7 @@ using Microsoft.Graphics.Canvas; using Microsoft.Graphics.Canvas.Effects; using Microsoft.Graphics.Canvas.UI.Composition; - using Notepads.Controls.Helpers; + using Microsoft.Toolkit.Uwp; public sealed class HostBackdropAcrylicBrush : XamlCompositionBrushBase, IDisposable { @@ -162,7 +162,7 @@ private async Task BuildInternalAsync() private async void OnEnergySaverStatusChanged(object sender, object e) { - await _dispatcherQueue.ExecuteOnUIThreadAsync(async () => + await _dispatcherQueue.EnqueueAsync(async () => { await BuildInternalAsync(); }); @@ -170,7 +170,7 @@ await _dispatcherQueue.ExecuteOnUIThreadAsync(async () => private async void OnAdvancedEffectsEnabledChanged(UISettings sender, object args) { - await _dispatcherQueue.ExecuteOnUIThreadAsync(async () => + await _dispatcherQueue.EnqueueAsync(async () => { await BuildInternalAsync(); }); diff --git a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs deleted file mode 100644 index 47f7745c0..000000000 --- a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.cs +++ /dev/null @@ -1,24 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - using System; - using Windows.UI; - using Windows.UI.Xaml; - - public class AppCloseSaveReminderDialog : NotepadsDialog - { - public AppCloseSaveReminderDialog(Action saveAndExitAction, Action discardAndExitAction, Action cancelAction) - { - Title = ResourceLoader.GetString("AppCloseSaveReminderDialog_Title"); - HorizontalAlignment = HorizontalAlignment.Center; - Content = ResourceLoader.GetString("AppCloseSaveReminderDialog_Content"); - PrimaryButtonText = ResourceLoader.GetString("AppCloseSaveReminderDialog_PrimaryButtonText"); - SecondaryButtonText = ResourceLoader.GetString("AppCloseSaveReminderDialog_SecondaryButtonText"); - CloseButtonText = ResourceLoader.GetString("AppCloseSaveReminderDialog_CloseButtonText"); - PrimaryButtonStyle = GetButtonStyle(Color.FromArgb(255, 38, 114, 201)); - - PrimaryButtonClick += (dialog, eventArgs) => saveAndExitAction(); - SecondaryButtonClick += (dialog, eventArgs) => discardAndExitAction(); - CloseButtonClick += (dialog, eventArgs) => cancelAction(); - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml new file mode 100644 index 000000000..2cc8e8a84 --- /dev/null +++ b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml @@ -0,0 +1,20 @@ + diff --git a/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml.cs b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml.cs new file mode 100644 index 000000000..2f9d6ad41 --- /dev/null +++ b/src/Notepads/Controls/Dialog/AppCloseSaveReminderDialog.xaml.cs @@ -0,0 +1,38 @@ +namespace Notepads.Controls.Dialog +{ + using System; + using Windows.UI.Xaml.Controls; + + public sealed partial class AppCloseSaveReminderDialog : ContentDialog, INotepadsDialog + { + public bool IsAborted { get; set; } + + private readonly Action _saveAndExitAction; + private readonly Action _discardAndExitAction; + private readonly Action _cancelAction; + + public AppCloseSaveReminderDialog(Action saveAndExitAction, Action discardAndExitAction, Action cancelAction) + { + InitializeComponent(); + + _saveAndExitAction = saveAndExitAction; + _discardAndExitAction = discardAndExitAction; + _cancelAction = cancelAction; + } + + private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _saveAndExitAction?.Invoke(); + } + + private void ContentDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _discardAndExitAction?.Invoke(); + } + + private void ContentDialog_CloseButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _cancelAction?.Invoke(); + } + } +} diff --git a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs deleted file mode 100644 index 35f58da75..000000000 --- a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - public class FileOpenErrorDialog : NotepadsDialog - { - public FileOpenErrorDialog(string filePath, string errorMsg) - { - Title = ResourceLoader.GetString("FileOpenErrorDialog_Title"); - Content = string.IsNullOrEmpty(filePath) ? errorMsg : string.Format(ResourceLoader.GetString("FileOpenErrorDialog_Content"), filePath, errorMsg); - PrimaryButtonText = ResourceLoader.GetString("FileOpenErrorDialog_PrimaryButtonText"); - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml new file mode 100644 index 000000000..2fa941033 --- /dev/null +++ b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml @@ -0,0 +1,13 @@ + diff --git a/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml.cs b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml.cs new file mode 100644 index 000000000..d1064cd23 --- /dev/null +++ b/src/Notepads/Controls/Dialog/FileOpenErrorDialog.xaml.cs @@ -0,0 +1,19 @@ +namespace Notepads.Controls.Dialog +{ + using Windows.ApplicationModel.Resources; + using Windows.UI.Xaml.Controls; + + public sealed partial class FileOpenErrorDialog : ContentDialog, INotepadsDialog + { + public bool IsAborted { get; set; } + + public FileOpenErrorDialog(string filePath, string errorMsg) + { + InitializeComponent(); + + Content = string.IsNullOrEmpty(filePath) + ? errorMsg + : string.Format(ResourceLoader.GetForCurrentView().GetString("FileOpenErrorDialog_Content"), filePath, errorMsg); + } + } +} diff --git a/src/Notepads/Controls/Dialog/FileRenameDialog.xaml b/src/Notepads/Controls/Dialog/FileRenameDialog.xaml new file mode 100644 index 000000000..e2a5ee491 --- /dev/null +++ b/src/Notepads/Controls/Dialog/FileRenameDialog.xaml @@ -0,0 +1,37 @@ + + + + + + + + + diff --git a/src/Notepads/Controls/Dialog/FileRenameDialog.cs b/src/Notepads/Controls/Dialog/FileRenameDialog.xaml.cs similarity index 51% rename from src/Notepads/Controls/Dialog/FileRenameDialog.cs rename to src/Notepads/Controls/Dialog/FileRenameDialog.xaml.cs index 6c4764890..68a701132 100644 --- a/src/Notepads/Controls/Dialog/FileRenameDialog.cs +++ b/src/Notepads/Controls/Dialog/FileRenameDialog.xaml.cs @@ -1,67 +1,38 @@ namespace Notepads.Controls.Dialog { + using Microsoft.AppCenter.Analytics; + using Notepads.Services; + using Notepads.Utilities; using System; using System.Collections.Generic; + using Windows.ApplicationModel.Resources; using Windows.System; - using Windows.UI; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - using Notepads.Services; - using Notepads.Utilities; - using Microsoft.AppCenter.Analytics; + using Windows.UI.Xaml.Input; - public class FileRenameDialog : NotepadsDialog + public sealed partial class FileRenameDialog : ContentDialog, INotepadsDialog { - private readonly TextBox _fileNameTextBox; - - private readonly TextBlock _errorMessageTextBlock; - - private readonly Action _confirmedAction; + public bool IsAborted { get; set; } + private readonly ResourceLoader _resourceLoader = ResourceLoader.GetForCurrentView(); private readonly string _originalFilename; - private readonly bool _fileExists; + private readonly Action _confirmedAction; public FileRenameDialog(string filename, bool fileExists, Action confirmedAction) { - _originalFilename = filename; - _fileExists = fileExists; - _confirmedAction = confirmedAction; + InitializeComponent(); - _fileNameTextBox = new TextBox - { - Style = (Style)Application.Current.Resources["TransparentTextBoxStyle"], - Text = filename, - IsSpellCheckEnabled = false, - AcceptsReturn = false, - SelectionStart = 0, - SelectionLength = filename.Contains(".") ? filename.LastIndexOf(".", StringComparison.Ordinal) : filename.Length, - Height = 35, - }; - - _errorMessageTextBlock = new TextBlock() - { - Visibility = Visibility.Collapsed, - Margin = new Thickness(4, 10, 4, 0), - FontSize = Math.Clamp(_fileNameTextBox.FontSize - 2, 1, Double.PositiveInfinity), - TextWrapping = TextWrapping.Wrap - }; - - var contentStack = new StackPanel(); - contentStack.Children.Add(_fileNameTextBox); - contentStack.Children.Add(_errorMessageTextBlock); + FileNameBox.Text = filename; + FileNameBox.SelectionStart = 0; + FileNameBox.SelectionLength = filename.Contains(".") ? filename.LastIndexOf(".", StringComparison.Ordinal) : filename.Length; - Title = ResourceLoader.GetString("FileRenameDialog_Title"); - Content = contentStack; - PrimaryButtonText = ResourceLoader.GetString("FileRenameDialog_PrimaryButtonText"); - CloseButtonText = ResourceLoader.GetString("FileRenameDialog_CloseButtonText"); - IsPrimaryButtonEnabled = false; + ErrorMessageBlock.FontSize = Math.Clamp(FileNameBox.FontSize - 2, 1, Double.PositiveInfinity); - _fileNameTextBox.TextChanging += OnTextChanging; - _fileNameTextBox.KeyDown += OnKeyDown; - - PrimaryButtonClick += (sender, args) => TryRename(); + _originalFilename = filename; + _fileExists = fileExists; + _confirmedAction = confirmedAction; Analytics.TrackEvent("FileRenameDialogOpened", new Dictionary() { @@ -71,7 +42,7 @@ public FileRenameDialog(string filename, bool fileExists, Action confirm private bool TryRename() { - var newFileName = _fileNameTextBox.Text; + var newFileName = FileNameBox.Text; if (string.Compare(_originalFilename, newFileName, StringComparison.OrdinalIgnoreCase) == 0) { @@ -92,18 +63,12 @@ private bool TryRename() return true; } - private void OnKeyDown(object sender, Windows.UI.Xaml.Input.KeyRoutedEventArgs e) + private void FileRenameDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { - if (e.Key == VirtualKey.Enter) - { - if (TryRename()) - { - Hide(); - } - } + TryRename(); } - private void OnTextChanging(TextBox sender, TextBoxTextChangingEventArgs args) + private void FileNameBox_TextChanging(TextBox sender, TextBoxTextChangingEventArgs args) { if (!args.IsContentChanging) return; @@ -126,24 +91,35 @@ private void OnTextChanging(TextBox sender, TextBoxTextChangingEventArgs args) if (!isFilenameValid) { - _errorMessageTextBlock.Foreground = new SolidColorBrush(Colors.Red); - _errorMessageTextBlock.Text = ResourceLoader.GetString($"InvalidFilenameError_{error}"); - _errorMessageTextBlock.Visibility = Visibility.Visible; + //ErrorMessageBlock.Foreground = new SolidColorBrush(Colors.Red); + ErrorMessageBlock.Text = _resourceLoader.GetString($"InvalidFilenameError_{error}"); + ErrorMessageBlock.Visibility = Visibility.Visible; } else if (!isExtensionSupported) { - _errorMessageTextBlock.Foreground = new SolidColorBrush(Colors.OrangeRed); - _errorMessageTextBlock.Text = string.IsNullOrEmpty(fileExtension) - ? string.Format(ResourceLoader.GetString("FileRenameError_EmptyFileExtension")) - : string.Format(ResourceLoader.GetString("FileRenameError_UnsupportedFileExtension"), fileExtension); - _errorMessageTextBlock.Visibility = Visibility.Visible; + //ErrorMessageBlock.Foreground = new SolidColorBrush(Colors.OrangeRed); + ErrorMessageBlock.Text = string.IsNullOrEmpty(fileExtension) + ? string.Format(_resourceLoader.GetString("FileRenameError_EmptyFileExtension")) + : string.Format(_resourceLoader.GetString("FileRenameError_UnsupportedFileExtension"), fileExtension); + ErrorMessageBlock.Visibility = Visibility.Visible; } else { - _errorMessageTextBlock.Visibility = Visibility.Collapsed; + ErrorMessageBlock.Visibility = Visibility.Collapsed; } IsPrimaryButtonEnabled = isFilenameValid && nameChanged && isExtensionSupported; } + + private void FileNameBox_KeyDown(object sender, KeyRoutedEventArgs e) + { + if (e.Key == VirtualKey.Enter) + { + if (TryRename()) + { + Hide(); + } + } + } } -} \ No newline at end of file +} diff --git a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs deleted file mode 100644 index e772af232..000000000 --- a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - public class FileSaveErrorDialog : NotepadsDialog - { - public FileSaveErrorDialog(string filePath, string errorMsg) - { - var content = string.IsNullOrEmpty(filePath) ? errorMsg : string.Format(ResourceLoader.GetString("FileSaveErrorDialog_Content"), filePath, errorMsg); - Title = ResourceLoader.GetString("FileSaveErrorDialog_Title"); - Content = content; - PrimaryButtonText = ResourceLoader.GetString("FileSaveErrorDialog_PrimaryButtonText"); - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml new file mode 100644 index 000000000..6e267ffa5 --- /dev/null +++ b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml @@ -0,0 +1,13 @@ + diff --git a/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml.cs b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml.cs new file mode 100644 index 000000000..34483ecc9 --- /dev/null +++ b/src/Notepads/Controls/Dialog/FileSaveErrorDialog.xaml.cs @@ -0,0 +1,19 @@ +namespace Notepads.Controls.Dialog +{ + using Windows.ApplicationModel.Resources; + using Windows.UI.Xaml.Controls; + + public sealed partial class FileSaveErrorDialog : ContentDialog, INotepadsDialog + { + public bool IsAborted { get; set; } + + public FileSaveErrorDialog(string filePath, string errorMsg) + { + InitializeComponent(); + + Content = string.IsNullOrEmpty(filePath) + ? errorMsg + : string.Format(ResourceLoader.GetForCurrentView().GetString("FileSaveErrorDialog_Content"), filePath, errorMsg); + } + } +} diff --git a/src/Notepads/Controls/Dialog/INotepadsDialog.cs b/src/Notepads/Controls/Dialog/INotepadsDialog.cs new file mode 100644 index 000000000..40fc5987b --- /dev/null +++ b/src/Notepads/Controls/Dialog/INotepadsDialog.cs @@ -0,0 +1,14 @@ +namespace Notepads.Controls.Dialog +{ + using Windows.Foundation; + using Windows.UI.Xaml.Controls; + + public interface INotepadsDialog + { + bool IsAborted { get; set; } + object Title { get; set; } + + void Hide(); + IAsyncOperation ShowAsync(); + } +} diff --git a/src/Notepads/Controls/Dialog/NotepadsDialog.cs b/src/Notepads/Controls/Dialog/NotepadsDialog.cs deleted file mode 100644 index bb27e1b9c..000000000 --- a/src/Notepads/Controls/Dialog/NotepadsDialog.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - using Windows.ApplicationModel.Resources; - using Windows.UI; - using Windows.UI.Xaml; - using Windows.UI.Xaml.Controls; - using Windows.UI.Xaml.Media; - using Notepads.Services; - using Microsoft.Toolkit.Uwp.Helpers; - - public class NotepadsDialog : ContentDialog - { - public bool IsAborted = false; - - private readonly SolidColorBrush _darkModeBackgroundBrush = new SolidColorBrush("#101010".ToColor()); - private readonly SolidColorBrush _lightModeBackgroundBrush = new SolidColorBrush(Colors.White); - - public NotepadsDialog() - { - RequestedTheme = ThemeSettingsService.ThemeMode; - Background = ThemeSettingsService.ThemeMode == ElementTheme.Dark - ? _darkModeBackgroundBrush - : _lightModeBackgroundBrush; - - ActualThemeChanged += NotepadsDialog_ActualThemeChanged; - } - - private void NotepadsDialog_ActualThemeChanged(FrameworkElement sender, object args) - { - Background = ActualTheme == ElementTheme.Dark - ? _darkModeBackgroundBrush - : _lightModeBackgroundBrush; - } - - internal readonly ResourceLoader ResourceLoader = ResourceLoader.GetForCurrentView(); - - internal static Style GetButtonStyle(Color backgroundColor) - { - var buttonStyle = new Windows.UI.Xaml.Style(typeof(Button)); - buttonStyle.Setters.Add(new Setter(Control.BackgroundProperty, backgroundColor)); - buttonStyle.Setters.Add(new Setter(Control.ForegroundProperty, Colors.White)); - return buttonStyle; - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs deleted file mode 100644 index 949d5409c..000000000 --- a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - using System; - - public class RevertAllChangesConfirmationDialog : NotepadsDialog - { - public RevertAllChangesConfirmationDialog(string fileNameOrPath, Action confirmedAction) - { - Title = ResourceLoader.GetString("RevertAllChangesConfirmationDialog_Title"); - Content = string.Format(ResourceLoader.GetString("RevertAllChangesConfirmationDialog_Content"), fileNameOrPath); - PrimaryButtonText = ResourceLoader.GetString("RevertAllChangesConfirmationDialog_PrimaryButtonText"); - CloseButtonText = ResourceLoader.GetString("RevertAllChangesConfirmationDialog_CloseButtonText"); - - PrimaryButtonClick += (dialog, args) => { confirmedAction(); }; - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml new file mode 100644 index 000000000..48d5cd7fb --- /dev/null +++ b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml @@ -0,0 +1,16 @@ + diff --git a/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml.cs b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml.cs new file mode 100644 index 000000000..3af60af2d --- /dev/null +++ b/src/Notepads/Controls/Dialog/RevertAllChangesConfirmationDialog.xaml.cs @@ -0,0 +1,26 @@ +namespace Notepads.Controls.Dialog +{ + using System; + using Windows.ApplicationModel.Resources; + using Windows.UI.Xaml.Controls; + + public sealed partial class RevertAllChangesConfirmationDialog : ContentDialog, INotepadsDialog + { + public bool IsAborted { get; set; } + + private readonly Action _confirmedAction; + + public RevertAllChangesConfirmationDialog(string fileNameOrPath, Action confirmedAction) + { + InitializeComponent(); + + Content = string.Format(ResourceLoader.GetForCurrentView().GetString("RevertAllChangesConfirmationDialog_Content"), fileNameOrPath); + _confirmedAction = confirmedAction; + } + + private void RevertAllChangesConfirmationDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _confirmedAction?.Invoke(); + } + } +} diff --git a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs deleted file mode 100644 index ff152444f..000000000 --- a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace Notepads.Controls.Dialog -{ - using System; - - public class SetCloseSaveReminderDialog : NotepadsDialog - { - public SetCloseSaveReminderDialog(string fileNameOrPath, Action saveAction, Action skipSavingAction) - { - Title = ResourceLoader.GetString("SetCloseSaveReminderDialog_Title"); - Content = string.Format(ResourceLoader.GetString("SetCloseSaveReminderDialog_Content"), fileNameOrPath); - PrimaryButtonText = ResourceLoader.GetString("SetCloseSaveReminderDialog_PrimaryButtonText"); - SecondaryButtonText = ResourceLoader.GetString("SetCloseSaveReminderDialog_SecondaryButtonText"); - CloseButtonText = ResourceLoader.GetString("SetCloseSaveReminderDialog_CloseButtonText"); - - PrimaryButtonClick += (dialog, args) => { saveAction(); }; - SecondaryButtonClick += (dialog, args) => { skipSavingAction(); }; - } - } -} \ No newline at end of file diff --git a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml new file mode 100644 index 000000000..d3939b3ef --- /dev/null +++ b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml @@ -0,0 +1,18 @@ + diff --git a/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml.cs b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml.cs new file mode 100644 index 000000000..9bbc074a8 --- /dev/null +++ b/src/Notepads/Controls/Dialog/SetCloseSaveReminderDialog.xaml.cs @@ -0,0 +1,33 @@ +namespace Notepads.Controls.Dialog +{ + using System; + using Windows.ApplicationModel.Resources; + using Windows.UI.Xaml.Controls; + + public sealed partial class SetCloseSaveReminderDialog : ContentDialog, INotepadsDialog + { + public bool IsAborted { get; set; } + + private readonly Action _saveAction; + private readonly Action _skipSavingAction; + + public SetCloseSaveReminderDialog(string fileNameOrPath, Action saveAction, Action skipSavingAction) + { + InitializeComponent(); + + Content = string.Format(ResourceLoader.GetForCurrentView().GetString("SetCloseSaveReminderDialog_Content"), fileNameOrPath); + _saveAction = saveAction; + _skipSavingAction = skipSavingAction; + } + + private void SetCloseSaveReminderDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _saveAction?.Invoke(); + } + + private void SetCloseSaveReminderDialog_SecondaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) + { + _skipSavingAction?.Invoke(); + } + } +} diff --git a/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml b/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml index 75cdd1464..5637bfd65 100644 --- a/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml +++ b/src/Notepads/Controls/DiffViewer/SideBySideDiffViewer.xaml @@ -4,113 +4,85 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" - Background="{ThemeResource SystemControlForegroundTransparentBrush}"> + Background="{ThemeResource SystemControlForegroundTransparentBrush}" + mc:Ignorable="d"> - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - + - + - + - - + + - - - + + - + - + diff --git a/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml b/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml index b4cc714b3..ef5de7473 100644 --- a/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml +++ b/src/Notepads/Controls/FindAndReplace/FindAndReplaceControl.xaml @@ -3,14 +3,13 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:findAndReplace="using:Notepads.Controls.FindAndReplace" - mc:Ignorable="d" + xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" d:DesignHeight="72" - d:DesignWidth="250"> + d:DesignWidth="250" + mc:Ignorable="d"> - @@ -22,71 +21,96 @@ - - + + - - + - diff --git a/src/Notepads/Controls/FindAndReplace/FindAndReplacePlaceHolder.xaml b/src/Notepads/Controls/FindAndReplace/FindAndReplacePlaceHolder.xaml deleted file mode 100644 index 1e28862ce..000000000 --- a/src/Notepads/Controls/FindAndReplace/FindAndReplacePlaceHolder.xaml +++ /dev/null @@ -1,111 +0,0 @@ - - - - - diff --git a/src/Notepads/Controls/GoTo/GoToControl.xaml b/src/Notepads/Controls/GoTo/GoToControl.xaml index 296793793..715807987 100644 --- a/src/Notepads/Controls/GoTo/GoToControl.xaml +++ b/src/Notepads/Controls/GoTo/GoToControl.xaml @@ -4,11 +4,16 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - mc:Ignorable="d" - d:DesignWidth="250" Height="36"> + d:DesignHeight="36" + d:DesignWidth="250" + mc:Ignorable="d"> + + - - @@ -16,49 +21,56 @@ - + - + - + + --> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/Notepads/Resource/CustomSplitViewStyle.xaml b/src/Notepads/Resource/NotepadsSplitViewStyle.xaml similarity index 75% rename from src/Notepads/Resource/CustomSplitViewStyle.xaml rename to src/Notepads/Resource/NotepadsSplitViewStyle.xaml index 04c27c01d..181e43d0e 100644 --- a/src/Notepads/Resource/CustomSplitViewStyle.xaml +++ b/src/Notepads/Resource/NotepadsSplitViewStyle.xaml @@ -1,575 +1,706 @@  + xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:local="using:Notepads"> - + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Notepads/Resource/Theme.xaml b/src/Notepads/Resource/Theme.xaml new file mode 100644 index 000000000..21cf61b22 --- /dev/null +++ b/src/Notepads/Resource/Theme.xaml @@ -0,0 +1,841 @@ + + + + + + + + 4,4,4,4 + 8,8,8,8 + + + + #E4000000 + #9E000000 + #72000000 + #5C000000 + #FFFFFF + + #5C000000 + + #FFFFFF + + #FFFFFF + #B3FFFFFF + #FFFFFF + + #B3FFFFFF + #80F9F9F9 + #4DF9F9F9 + #4DF9F9F9 + #00FFFFFF + #FFFFFF + + #72000000 + #51000000 + + #FFFFFF + + #00FFFFFF + #09000000 + #06000000 + #00FFFFFF + + #00FFFFFF + #06000000 + #0F000000 + #18000000 + #00FFFFFF + + #C9FFFFFF + #F3F3F3 + #EBEBEB + #00FFFFFF + + #37000000 + + #0F000000 + #29000000 + #14FFFFFF + #66000000 + #37000000 + #0F000000 + + #59FFFFFF + + #0F000000 + #EBEBEB + + #72000000 + #37000000 + + #66757575 + #0F000000 + #15FFFFFF + + #0F000000 + + #E4000000 + #B3FFFFFF + + #B3FFFFFF + #80F6F6F6 + + #4D000000 + + #80FFFFFF + #FFFFFF + #40FFFFFF + #40FFFFFF + + #F3F3F3 + #EEEEEE + #F9F9F9 + #FFFFFF + #00F3F3F3 + + #0F7B0F + #9D5D00 + #C42B1C + #72000000 + #8A8A8A + #80F6F6F6 + #DFF6DD + #FFF4CE + #FDE7E9 + #06000000 + #F7F7F7 + #F3F3F3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4,4,4,4 + 8,8,8,8 + + + + #FFFFFF + #C5FFFFFF + #87FFFFFF + #5DFFFFFF + #E4000000 + + #5DFFFFFF + #FFFFFF + #000000 + #80000000 + #87FFFFFF + + #0FFFFFFF + #15FFFFFF + #08FFFFFF + #0BFFFFFF + #00FFFFFF + #B31E1E1E + + #8BFFFFFF + #3FFFFFFF + + #454545 + + #00FFFFFF + #0FFFFFFF + #0AFFFFFF + #00FFFFFF + + #00FFFFFF + #19000000 + #0BFFFFFF + #12FFFFFF + #00FFFFFF + + #B31C1C1C + #1A1A1A + #131313 + #1E1E1E + + #28FFFFFF + + #12FFFFFF + #18FFFFFF + #14FFFFFF + #23000000 + #37000000 + #33000000 + + #6B000000 + + #19000000 + #1C1C1C + + #8BFFFFFF + #28FFFFFF + + #66757575 + #33000000 + #0F000000 + + #15FFFFFF + + #FFFFFF + #B3000000 + + #0DFFFFFF + #08FFFFFF + + #4D000000 + + #4C3A3A3A + #0DFFFFFF + #09FFFFFF + #09FFFFFF + + #202020 + #1C1C1C + #282828 + #2C2C2C + #00202020 + + #6CCB5F + #FCE100 + #FF99A4 + #8BFFFFFF + #9D9D9D + #08FFFFFF + #393D1B + #433519 + #442726 + #08FFFFFF + #2E2E2E + #2E2E2E + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 4,4,4,4 + 8,8,8,8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + #FF0000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0,0,0,1 + + 00:00:00.250 + 00:00:00.167 + 00:00:00.168 + 00:00:00.083 + + diff --git a/src/Notepads/Resource/TransparentTextBoxStyle.xaml b/src/Notepads/Resource/TransparentTextBoxStyle.xaml index 5ecb5ebf4..8a3011d28 100644 --- a/src/Notepads/Resource/TransparentTextBoxStyle.xaml +++ b/src/Notepads/Resource/TransparentTextBoxStyle.xaml @@ -1,124 +1,489 @@  + + + + - + + + + + + + + + + + + + + + + + + + + #5C010101 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + #5DFEFEFE + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + #5C010101 + 2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0,0,0,8 + 0,4,4,4 + 12 + + --> + - - - + + + + + + + + + + + + + + + + + - + + + - + - + - + - + - + + + - + - + - + - + + - + - + - + + - + + + + - - - - - - diff --git a/src/Notepads/Services/FileExtensionProvider.cs b/src/Notepads/Services/FileExtensionProvider.cs index dd983548a..f3ae1c067 100644 --- a/src/Notepads/Services/FileExtensionProvider.cs +++ b/src/Notepads/Services/FileExtensionProvider.cs @@ -200,7 +200,7 @@ public static bool IsFileExtensionSupported(string fileExtension) { // Windows 10 2004 (build 19041) enables support for handling any kind of file // https://github.com/microsoft/ProjectReunion/issues/27 - if (SystemInformation.OperatingSystemVersion.Build >= 19041) + if (SystemInformation.Instance.OperatingSystemVersion.Build >= 19041) { return true; } diff --git a/src/Notepads/Services/ThemeSettingsService.cs b/src/Notepads/Services/ThemeSettingsService.cs index c1a438b81..04b7452f9 100644 --- a/src/Notepads/Services/ThemeSettingsService.cs +++ b/src/Notepads/Services/ThemeSettingsService.cs @@ -2,10 +2,12 @@ { using System; using Microsoft.Toolkit.Uwp.Helpers; + using Microsoft.Toolkit.Uwp.UI.Helpers; using Notepads.Brushes; - using Notepads.Controls.Helpers; + using Notepads.Extensions; using Notepads.Settings; using Notepads.Utilities; + using Windows.ApplicationModel.Core; using Windows.UI; using Windows.UI.ViewManagement; using Windows.UI.Xaml; @@ -126,7 +128,7 @@ private static void InitializeAppAccentColor() UISettings.ColorValuesChanged += UiSettings_ColorValuesChanged; - _appAccentColor = UISettings.GetColorValue(Windows.UI.ViewManagement.UIColorType.Accent); + _appAccentColor = UISettings.GetColorValue(UIColorType.Accent); if (!UseWindowsAccentColor) { @@ -149,11 +151,20 @@ private static void InitializeCustomAccentColor() } } - private static void UiSettings_ColorValuesChanged(UISettings sender, object args) + private static async void UiSettings_ColorValuesChanged(UISettings sender, object args) { if (UseWindowsAccentColor) { AppAccentColor = sender.GetColorValue(UIColorType.Accent); + await CoreApplication.MainView.CoreWindow.Dispatcher.CallOnUIThreadAsync(() => + { + Application.Current.Resources["SystemAccentColorLight1"] = sender.GetColorValue(UIColorType.AccentLight1); + Application.Current.Resources["SystemAccentColorLight2"] = sender.GetColorValue(UIColorType.AccentLight2); + Application.Current.Resources["SystemAccentColorLight3"] = sender.GetColorValue(UIColorType.AccentLight3); + Application.Current.Resources["SystemAccentColorDark1"] = sender.GetColorValue(UIColorType.AccentDark1); + Application.Current.Resources["SystemAccentColorDark2"] = sender.GetColorValue(UIColorType.AccentDark2); + Application.Current.Resources["SystemAccentColorDark3"] = sender.GetColorValue(UIColorType.AccentDark3); + }); } } @@ -239,7 +250,7 @@ public static void SetRequestedTheme(Panel backgroundPanel, UIElement currentCon if (DialogManager.ActiveDialog != null) { - DialogManager.ActiveDialog.RequestedTheme = ThemeMode; + //DialogManager.ActiveDialog.RequestedTheme = ThemeMode; } // Set accent color @@ -294,36 +305,36 @@ public static void ApplyThemeForTitleBarButtons(ApplicationViewTitleBar titleBar if (theme == ElementTheme.Dark) { // Set active window colors - titleBar.ButtonForegroundColor = Windows.UI.Colors.White; - titleBar.ButtonBackgroundColor = Windows.UI.Colors.Transparent; - titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.White; + titleBar.ButtonForegroundColor = Colors.White; + titleBar.ButtonBackgroundColor = Colors.Transparent; + titleBar.ButtonHoverForegroundColor = Colors.White; titleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 90, 90, 90); - titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.White; + titleBar.ButtonPressedForegroundColor = Colors.White; titleBar.ButtonPressedBackgroundColor = Color.FromArgb(255, 120, 120, 120); // Set inactive window colors - titleBar.InactiveForegroundColor = Windows.UI.Colors.Gray; - titleBar.InactiveBackgroundColor = Windows.UI.Colors.Transparent; - titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.Gray; - titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent; + titleBar.InactiveForegroundColor = Colors.Gray; + titleBar.InactiveBackgroundColor = Colors.Transparent; + titleBar.ButtonInactiveForegroundColor = Colors.Gray; + titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; titleBar.BackgroundColor = Color.FromArgb(255, 45, 45, 45); } else if (theme == ElementTheme.Light) { // Set active window colors - titleBar.ButtonForegroundColor = Windows.UI.Colors.Black; - titleBar.ButtonBackgroundColor = Windows.UI.Colors.Transparent; - titleBar.ButtonHoverForegroundColor = Windows.UI.Colors.Black; + titleBar.ButtonForegroundColor = Colors.Black; + titleBar.ButtonBackgroundColor = Colors.Transparent; + titleBar.ButtonHoverForegroundColor = Colors.Black; titleBar.ButtonHoverBackgroundColor = Color.FromArgb(255, 180, 180, 180); - titleBar.ButtonPressedForegroundColor = Windows.UI.Colors.Black; + titleBar.ButtonPressedForegroundColor = Colors.Black; titleBar.ButtonPressedBackgroundColor = Color.FromArgb(255, 150, 150, 150); // Set inactive window colors - titleBar.InactiveForegroundColor = Windows.UI.Colors.DimGray; - titleBar.InactiveBackgroundColor = Windows.UI.Colors.Transparent; - titleBar.ButtonInactiveForegroundColor = Windows.UI.Colors.DimGray; - titleBar.ButtonInactiveBackgroundColor = Windows.UI.Colors.Transparent; + titleBar.InactiveForegroundColor = Colors.DimGray; + titleBar.InactiveBackgroundColor = Colors.Transparent; + titleBar.ButtonInactiveForegroundColor = Colors.DimGray; + titleBar.ButtonInactiveBackgroundColor = Colors.Transparent; titleBar.BackgroundColor = Color.FromArgb(255, 210, 210, 210); } diff --git a/src/Notepads/Strings/ar-YE/Resources.resw b/src/Notepads/Strings/ar-YE/Resources.resw index 3696d494f..48c25d628 100644 --- a/src/Notepads/Strings/ar-YE/Resources.resw +++ b/src/Notepads/Strings/ar-YE/Resources.resw @@ -1,17 +1,17 @@  - @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + إلغاء AppCloseSaveReminderDialog: CloseButtonText. - + توجد تغييرات غير محفوظة. AppCloseSaveReminderDialog: "Content" display text. - + حفظ الكل ثم الخروج AppCloseSaveReminderDialog: PrimaryButtonText. - + إلغاء التغييرات ثم الخروج AppCloseSaveReminderDialog: SecondaryButtonText. - + هل تريد حفظ التغييرات؟ AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ عذراً, الملف "{0}" تعذّر فتحه: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + موافق FileOpenErrorDialog: PrimaryButtonText. - + خطأ فتح ملف FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ عذراً, الملف "{0}" تعذّر حفظه: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + موافق FileSaveErrorDialog: PrimaryButtonText. - + خطأ حفظ ملف FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ الإعدادات MainMenu: "Settings" button display text. - + إلغاء RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ جميع التغييرات مثل النص ونهاية السطر ووضع الترميز التي تمت على "{0}" سوف تعاد! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + نعم RevertAllChangesConfirmationDialog: PrimaryButtonText. - + هل تريد بالفعل إعادة التغييرات؟ RevertAllChangesConfirmationDialog: "Title" display text. - + إلغاء SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ هل تريد حفظ الملف "{0}"؟ SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + حفظ SetCloseSaveReminderDialog: PrimaryButtonText. - + عدم الحفظ SetCloseSaveReminderDialog: SecondaryButtonText. - + هل تريد حفظ التغييرات؟ SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ نحيل FontWeight: "Thin" - + إلغاء FileRenameDialog: CloseButtonText. - + حفظ FileRenameDialog: PrimaryButtonText. - + إعادة التسمية FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/ar-YE/Settings.resw b/src/Notepads/Strings/ar-YE/Settings.resw index 83a5b8bbc..e4f7c702b 100644 --- a/src/Notepads/Strings/ar-YE/Settings.resw +++ b/src/Notepads/Strings/ar-YE/Settings.resw @@ -153,7 +153,7 @@ بيان سياسة الخصوصية AboutPage PrivacyStatementTitle display text. - + عن البرنامج AboutPage Title display text. @@ -169,7 +169,7 @@ إعدادات شريط الحالة AdvancedPage StatusBarSettings Title display text. - + خيارات متقدمة AdvancedPage Title display text. @@ -209,7 +209,7 @@ استخدم نمط Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + التخصيص PersonalizationPage Title display text. @@ -285,7 +285,7 @@ التفاف الكلمة TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + النص والمحرر TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/bg-BG/Resources.resw b/src/Notepads/Strings/bg-BG/Resources.resw index 5f2020026..39e919f67 100644 --- a/src/Notepads/Strings/bg-BG/Resources.resw +++ b/src/Notepads/Strings/bg-BG/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Затвори AppCloseSaveReminderDialog: CloseButtonText. - + Има незапазени промени. AppCloseSaveReminderDialog: "Content" display text. - + Запазване на всички и изход AppCloseSaveReminderDialog: PrimaryButtonText. - + Изхвърлете и излезте AppCloseSaveReminderDialog: SecondaryButtonText. - + Искате ли да запазите промените? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ За съжаление файлът "{0}" не може да бъде отворен: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ок FileOpenErrorDialog: PrimaryButtonText. - + Грешка при отваряне на файл FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ За съжаление файлът "{0}" не може да бъде запазен: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ок FileSaveErrorDialog: PrimaryButtonText. - + Грешка при запазване на файл FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Настройки MainMenu: "Settings" button display text. - + Отказ RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Всички промени, включително текст, край на реда и кодиране, направени на "{0}", ще бъдат възстановени! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Да RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Сигурни ли сте да възстановите всички промени? RevertAllChangesConfirmationDialog: "Title" display text. - + Отказ SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Запазване на файла "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Запазване SetCloseSaveReminderDialog: PrimaryButtonText. - + Не запазвай SetCloseSaveReminderDialog: SecondaryButtonText. - + Запази промените? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/bg-BG/Settings.resw b/src/Notepads/Strings/bg-BG/Settings.resw index f4bca8f9d..3bd22c246 100644 --- a/src/Notepads/Strings/bg-BG/Settings.resw +++ b/src/Notepads/Strings/bg-BG/Settings.resw @@ -153,7 +153,7 @@ Декларация за поверителност AboutPage PrivacyStatementTitle display text. - + За AboutPage Title display text. @@ -169,7 +169,7 @@ Настройки на лентата на състоянието AdvancedPage StatusBarSettings Title display text. - + Разширени AdvancedPage Title display text. @@ -209,7 +209,7 @@ Използвай моя режим Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Персонализация PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Пренеси дума TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Текст и редактор TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/cs-CZ/Resources.resw b/src/Notepads/Strings/cs-CZ/Resources.resw index ba8fc058e..35e151cd0 100644 --- a/src/Notepads/Strings/cs-CZ/Resources.resw +++ b/src/Notepads/Strings/cs-CZ/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Zrušit AppCloseSaveReminderDialog: CloseButtonText. - + Máte neuložené změny. AppCloseSaveReminderDialog: "Content" display text. - + Uložit vše a Zavřít AppCloseSaveReminderDialog: PrimaryButtonText. - + Zahodit a Zavřít AppCloseSaveReminderDialog: SecondaryButtonText. - + Chcete uložit změny? AppCloseSaveReminderDialog: "Title" display text. @@ -173,11 +173,11 @@ Omlouváme se, soubor "{0}" nemohl být otevřen: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Chyba při otevírání souboru FileOpenErrorDialog: "Title" display text. @@ -185,11 +185,11 @@ Omlouváme se, soubor "{0}" nemohl být uložen: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Chyba při ukládání souboru FileSaveErrorDialog: "Title" display text. @@ -269,7 +269,7 @@ Nastavení MainMenu: "Settings" button display text. - + Zrušit RevertAllChangesConfirmationDialog: CloseButtonText. @@ -277,15 +277,15 @@ Všechny změny včetně textu, ukončení řádků a kódování udělaných v "{0}" budou vráceny zpět! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Ano RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Opravdu chcete vrátit všechny změny? RevertAllChangesConfirmationDialog: "Title" display text. - + Zrušit SetCloseSaveReminderDialog: CloseButtonText. @@ -293,15 +293,15 @@ Uložit soubor "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Uložit SetCloseSaveReminderDialog: PrimaryButtonText. - + Neukládat SetCloseSaveReminderDialog: SecondaryButtonText. - + Přejete si uložit změny? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Štíhlý FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Uložit FileRenameDialog: PrimaryButtonText. - + Přejumenovat FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/cs-CZ/Settings.resw b/src/Notepads/Strings/cs-CZ/Settings.resw index a153bef69..8f48b1a60 100644 --- a/src/Notepads/Strings/cs-CZ/Settings.resw +++ b/src/Notepads/Strings/cs-CZ/Settings.resw @@ -153,7 +153,7 @@ Prohlášení o zásadách ochrany osobních údajů AboutPage PrivacyStatementTitle display text. - + O programu AboutPage Title display text. @@ -185,7 +185,7 @@ Nastavení Stavového Řádku AdvancedPage StatusBarSettings Title display text. - + Pokročilé AdvancedPage Title display text. @@ -225,7 +225,7 @@ Použít Windows motiv PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Přizpůsobení PersonalizationPage Title display text. @@ -301,7 +301,7 @@ Zalamovat text TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Text a Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/de-CH/Resources.resw b/src/Notepads/Strings/de-CH/Resources.resw index c06bbe7ac..c0987f144 100644 --- a/src/Notepads/Strings/de-CH/Resources.resw +++ b/src/Notepads/Strings/de-CH/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Abbrechen AppCloseSaveReminderDialog: CloseButtonText. - + Es exisitieren nicht gespeicherte Änderungen. AppCloseSaveReminderDialog: "Content" display text. - + Speichern AppCloseSaveReminderDialog: PrimaryButtonText. - + Nicht speichern AppCloseSaveReminderDialog: SecondaryButtonText. - + Änderungen speichern? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Die Datei "{0}" konnte leider nicht geöffnet werden: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Fehler beim öffnen der Datei FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Die Datei "{0}" konnte leider nicht gespeichert werden: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Fehler beim speichern der Datei FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Einstellungen MainMenu: "Settings" button display text. - + Abbrechen RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Alle Änderungen, inklusive Text, Zeilenumbrüche und Zeichenkodierung, an "{0}" werden rückgängig gemacht! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Ja RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Alle Änderungen rückgängig machen? RevertAllChangesConfirmationDialog: "Title" display text. - + Abbrechen SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Datei "{0}" speichern? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Speichern SetCloseSaveReminderDialog: PrimaryButtonText. - + Nicht speichern SetCloseSaveReminderDialog: SecondaryButtonText. - + Änderungen speichern? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Abbrechen FileRenameDialog: CloseButtonText. - + Speichern FileRenameDialog: PrimaryButtonText. - + Umbennen FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/de-CH/Settings.resw b/src/Notepads/Strings/de-CH/Settings.resw index 5a84e9fd6..64b3701a6 100644 --- a/src/Notepads/Strings/de-CH/Settings.resw +++ b/src/Notepads/Strings/de-CH/Settings.resw @@ -153,7 +153,7 @@ Datenschutzerklärung AboutPage PrivacyStatementTitle display text. - + Über AboutPage Title display text. @@ -169,7 +169,7 @@ Statusleisteneinstellungen AdvancedPage StatusBarSettings Title display text. - + Erweitert AdvancedPage Title display text. @@ -209,7 +209,7 @@ Windows Modus verwenden PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalisierung PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Wörter umbrechen TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Text & Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/de-DE/Resources.resw b/src/Notepads/Strings/de-DE/Resources.resw index bc47ee231..a4387651c 100644 --- a/src/Notepads/Strings/de-DE/Resources.resw +++ b/src/Notepads/Strings/de-DE/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Abbrechen AppCloseSaveReminderDialog: CloseButtonText. - + Es exisitieren nicht gespeicherte Änderungen. AppCloseSaveReminderDialog: "Content" display text. - + Speichern AppCloseSaveReminderDialog: PrimaryButtonText. - + Nicht speichern AppCloseSaveReminderDialog: SecondaryButtonText. - + Änderungen speichern? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Die Datei „{0}“ konnte leider nicht geöffnet werden: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Fehler beim öffnen der Datei FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Die Datei „{0}“ konnte leider nicht gespeichert werden: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Fehler beim speichern der Datei FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Einstellungen MainMenu: "Settings" button display text. - + Abbrechen RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Alle Änderungen, inklusive Text, Zeilenumbrüche und Zeichenkodierung, an „{0}“ werden rückgängig gemacht! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Ja RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Alle Änderungen rückgängig machen? RevertAllChangesConfirmationDialog: "Title" display text. - + Abbrechen SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Datei „{0}“ speichern? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Speichern SetCloseSaveReminderDialog: PrimaryButtonText. - + Nicht speichern SetCloseSaveReminderDialog: SecondaryButtonText. - + Änderungen speichern? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Abbrechen FileRenameDialog: CloseButtonText. - + Speichern FileRenameDialog: PrimaryButtonText. - + Umbennen FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/de-DE/Settings.resw b/src/Notepads/Strings/de-DE/Settings.resw index ef052933f..692f8140d 100644 --- a/src/Notepads/Strings/de-DE/Settings.resw +++ b/src/Notepads/Strings/de-DE/Settings.resw @@ -153,7 +153,7 @@ Datenschutzerklärung AboutPage PrivacyStatementTitle display text. - + Über AboutPage Title display text. @@ -169,7 +169,7 @@ Statusleisteneinstellungen AdvancedPage StatusBarSettings Title display text. - + Erweitert AdvancedPage Title display text. @@ -209,7 +209,7 @@ Windows Modus verwenden PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalisierung PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Wörter umbrechen TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Text & Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/en-US/Resources.resw b/src/Notepads/Strings/en-US/Resources.resw index 3a480c07e..6dc040051 100644 --- a/src/Notepads/Strings/en-US/Resources.resw +++ b/src/Notepads/Strings/en-US/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Cancel AppCloseSaveReminderDialog: CloseButtonText. - + There are unsaved changes. AppCloseSaveReminderDialog: "Content" display text. - + Save All & Exit AppCloseSaveReminderDialog: PrimaryButtonText. - + Discard & Exit AppCloseSaveReminderDialog: SecondaryButtonText. - + Do you want to save the changes? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Sorry, file "{0}" couldn't be opened: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + File Open Error FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Sorry, file "{0}" couldn't be saved: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + File Save Error FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Settings MainMenu: "Settings" button display text. - + Cancel RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ All changes including text, line ending and encoding made to "{0}" will be reverted! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Yes RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Are you sure to revert all changes? RevertAllChangesConfirmationDialog: "Title" display text. - + Cancel SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Save file "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Save SetCloseSaveReminderDialog: PrimaryButtonText. - + Don't Save SetCloseSaveReminderDialog: SecondaryButtonText. - + Save your changes? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/en-US/Settings.resw b/src/Notepads/Strings/en-US/Settings.resw index fa358b94f..04c4331be 100644 --- a/src/Notepads/Strings/en-US/Settings.resw +++ b/src/Notepads/Strings/en-US/Settings.resw @@ -153,7 +153,7 @@ Privacy Statement AboutPage PrivacyStatementTitle display text. - + About AboutPage Title display text. @@ -169,7 +169,7 @@ Status Bar Settings AdvancedPage StatusBarSettings Title display text. - + Advanced AdvancedPage Title display text. @@ -209,7 +209,7 @@ Use my Windows mode PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalization PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Wrap word TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Text & Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/es-ES/Resources.resw b/src/Notepads/Strings/es-ES/Resources.resw index df7efae62..5bece75ae 100644 --- a/src/Notepads/Strings/es-ES/Resources.resw +++ b/src/Notepads/Strings/es-ES/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Cancelar AppCloseSaveReminderDialog: CloseButtonText. - + Hay cambios sin guardar. AppCloseSaveReminderDialog: "Content" display text. - + Guardar Todo & Salir AppCloseSaveReminderDialog: PrimaryButtonText. - + Descartar & Salir AppCloseSaveReminderDialog: SecondaryButtonText. - + Quieres Guardar los Cambios? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Lo sentimos, el archivo "{0}" no pudo ser abierto: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Eror al Abrir Archivo FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Lo sentimos, el archivo "{0}" no pudo ser guardado: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Error al Guardar Archivo FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Ajustes MainMenu: "Settings" button display text. - + Cancelar RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Todos los cambios incluyendo texto, fin de línea y codificación hechos a ¨{0}" serán revertidos! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Está seguro de revertir todos los cambios? RevertAllChangesConfirmationDialog: "Title" display text. - + Cancelar SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Guardar Archivo "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Guardar SetCloseSaveReminderDialog: PrimaryButtonText. - + No Guardar SetCloseSaveReminderDialog: SecondaryButtonText. - + Guardar Cambios? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Delgado FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/es-ES/Settings.resw b/src/Notepads/Strings/es-ES/Settings.resw index fa3f7fea9..4aa3bc2ed 100644 --- a/src/Notepads/Strings/es-ES/Settings.resw +++ b/src/Notepads/Strings/es-ES/Settings.resw @@ -153,7 +153,7 @@ Declaración de Privacidad AboutPage PrivacyStatementTitle display text. - + Información AboutPage Title display text. @@ -169,7 +169,7 @@ Ajusted de Barra de Estado AdvancedPage StatusBarSettings Title display text. - + Avanzado AdvancedPage Title display text. @@ -209,7 +209,7 @@ Usar el modo de Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalización PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Ajuste Automático TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Texto y Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/fi-FI/Resources.resw b/src/Notepads/Strings/fi-FI/Resources.resw index 69e871860..cefd0b950 100644 --- a/src/Notepads/Strings/fi-FI/Resources.resw +++ b/src/Notepads/Strings/fi-FI/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Peruuta AppCloseSaveReminderDialog: CloseButtonText. - + Tiedostossa on tallentamattomia muutoksia. AppCloseSaveReminderDialog: "Content" display text. - + Tallenna kaikki & poistu AppCloseSaveReminderDialog: PrimaryButtonText. - + Hylkää & poistu AppCloseSaveReminderDialog: SecondaryButtonText. - + Haluatko tallentaa muutokset? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Tiedostoa "{0}" ei voitu avata: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Virhe avattaessa tiedostoa FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Tiedostoa "{0}" ei voitu tallentaa: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Virhe tallennettaessa tiedostoa FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Asetukset MainMenu: "Settings" button display text. - + Cancel RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ All changes including text, line ending and encoding made to "{0}" will be reverted! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Yes RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Are you sure to revert all changes? RevertAllChangesConfirmationDialog: "Title" display text. - + Peruuta SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Tallennetaanko tiedosto "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Tallenna SetCloseSaveReminderDialog: PrimaryButtonText. - + Älä tallenna SetCloseSaveReminderDialog: SecondaryButtonText. - + Tallennetaanko muutoksesi? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/fi-FI/Settings.resw b/src/Notepads/Strings/fi-FI/Settings.resw index 53257b56a..4e2a75da1 100644 --- a/src/Notepads/Strings/fi-FI/Settings.resw +++ b/src/Notepads/Strings/fi-FI/Settings.resw @@ -153,7 +153,7 @@ Privacy Statement AboutPage PrivacyStatementTitle display text. - + About AboutPage Title display text. @@ -169,7 +169,7 @@ Status Bar Settings AdvancedPage StatusBarSettings Title display text. - + Advanced AdvancedPage Title display text. @@ -209,7 +209,7 @@ Use my Windows mode PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalization PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Wrap word TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Text & Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/fr-FR/Resources.resw b/src/Notepads/Strings/fr-FR/Resources.resw index 4cce35570..3ec1a18e7 100644 --- a/src/Notepads/Strings/fr-FR/Resources.resw +++ b/src/Notepads/Strings/fr-FR/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Annuler AppCloseSaveReminderDialog: CloseButtonText. - + Certaines modifications n'ont pas été enregistrées. AppCloseSaveReminderDialog: "Content" display text. - + Enregistrer tout AppCloseSaveReminderDialog: PrimaryButtonText. - + Ne pas enregistrer AppCloseSaveReminderDialog: SecondaryButtonText. - + Voulez-vous enregistrer les modifications ? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Désolé, le fichier "{0}" ne peut pas être ouvert : {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + OK FileOpenErrorDialog: PrimaryButtonText. - + Erreur lors de l'ouverture du fichier. FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Désolé, le fichier "{0}" ne peut pas être enregistré : {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + OK FileSaveErrorDialog: PrimaryButtonText. - + Erreur lors de l'enregistrement du fichier. FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Paramètres MainMenu: "Settings" button display text. - + Annuler RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Toutes les modifications du texte, des fins de lignes et de l'encodage apportées à "{0}" seront annulées ! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Oui RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Êtes-vous sûr de vouloir annuler toutes les modifications ? RevertAllChangesConfirmationDialog: "Title" display text. - + Annuler SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Enregistrer le fichier "{0}" ? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Enregistrer SetCloseSaveReminderDialog: PrimaryButtonText. - + Ne pas enregistrer SetCloseSaveReminderDialog: SecondaryButtonText. - + Enregistrer les modifications ? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Mince FontWeight: "Thin" - + Annuler FileRenameDialog: CloseButtonText. - + Sauvegarder FileRenameDialog: PrimaryButtonText. - + Renommer FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/fr-FR/Settings.resw b/src/Notepads/Strings/fr-FR/Settings.resw index 6eddf8e18..b18e9a630 100644 --- a/src/Notepads/Strings/fr-FR/Settings.resw +++ b/src/Notepads/Strings/fr-FR/Settings.resw @@ -153,7 +153,7 @@ Déclaration de confidentialité AboutPage PrivacyStatementTitle display text. - + À propos AboutPage Title display text. @@ -169,7 +169,7 @@ Paramètres de la barre d'état AdvancedPage StatusBarSettings Title display text. - + Avancé AdvancedPage Title display text. @@ -209,7 +209,7 @@ Utiliser mon thème Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalisation PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Retour automatique à la ligne TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Texte & éditeur TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/hi-IN/Resources.resw b/src/Notepads/Strings/hi-IN/Resources.resw index da3003cdc..6b76f1565 100644 --- a/src/Notepads/Strings/hi-IN/Resources.resw +++ b/src/Notepads/Strings/hi-IN/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + रद्द करें AppCloseSaveReminderDialog: CloseButtonText. - + असेव परिवर्तन मौजूद हैं। AppCloseSaveReminderDialog: "Content" display text. - + सभी सेव करें और निकास AppCloseSaveReminderDialog: PrimaryButtonText. - + छोड़ें और निकास AppCloseSaveReminderDialog: SecondaryButtonText. - + क्या आप परिवर्तनों को सेव करना चाहते हैं? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ क्षमा करें, दस्तावेज़ "{0}" नहीं खोला जा सकता है: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ठीक FileOpenErrorDialog: PrimaryButtonText. - + दस्तावेज़ खोलनेका त्रुटि FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ क्षमा करें, दस्तावेज़ "{0}" सेव नहीं जा सकता है: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ठीक FileSaveErrorDialog: PrimaryButtonText. - + दस्तावेज़ सेव त्रुटि FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ सेटिंग्स MainMenu: "Settings" button display text. - + रद्द करें RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ पाठ, लाइन एंडींग और एन्कोडिंग सहित "{0}" मे किए गए सभी परिवर्तन वापस आ जाएंगे! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + हाँ RevertAllChangesConfirmationDialog: PrimaryButtonText. - + क्या आप सभी परिवर्तनों को वापस करने के लिए सुनिश्चित हैं? RevertAllChangesConfirmationDialog: "Title" display text. - + रद्द करें SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ दस्तावेज़ "{0}" को सेव करें? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + सेव करें SetCloseSaveReminderDialog: PrimaryButtonText. - + सेव ना करें SetCloseSaveReminderDialog: SecondaryButtonText. - + अपने परिवर्तनों का सेव करें SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ पतला FontWeight: "Thin" - + रद्द करें FileRenameDialog: CloseButtonText. - + सेव करें FileRenameDialog: PrimaryButtonText. - + नाम बदलें FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/hi-IN/Settings.resw b/src/Notepads/Strings/hi-IN/Settings.resw index 8ee1e57f0..a8b47e3ab 100644 --- a/src/Notepads/Strings/hi-IN/Settings.resw +++ b/src/Notepads/Strings/hi-IN/Settings.resw @@ -153,7 +153,7 @@ गोपनीयता विवरण AboutPage PrivacyStatementTitle display text. - + करीबन AboutPage Title display text. @@ -169,7 +169,7 @@ स्टेटस बार सेटिंग्स AdvancedPage StatusBarSettings Title display text. - + वरिष्ठ AdvancedPage Title display text. @@ -209,7 +209,7 @@ मेरे Windows मोड का उपयोग करें PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + वैयक्तिकरण PersonalizationPage Title display text. @@ -285,7 +285,7 @@ रैप वर्ड TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + पाठ और संपादक TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/hr-HR/Resources.resw b/src/Notepads/Strings/hr-HR/Resources.resw index ea5a874d8..53c2b800e 100644 --- a/src/Notepads/Strings/hr-HR/Resources.resw +++ b/src/Notepads/Strings/hr-HR/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Odustani AppCloseSaveReminderDialog: CloseButtonText. - + Postoje nespremljene promjene. AppCloseSaveReminderDialog: "Content" display text. - + Spremi i zatvori AppCloseSaveReminderDialog: PrimaryButtonText. - + Odbaci i zatvori AppCloseSaveReminderDialog: SecondaryButtonText. - + Spremiti promjene? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Nažalost se datoteka „{0}” ne može otvoriti: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + U redu FileOpenErrorDialog: PrimaryButtonText. - + Greška pri otvaranju datoteke FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Nažalost se datoteka „{0}” ne može spremiti: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + U redu FileSaveErrorDialog: PrimaryButtonText. - + Greška pri spremanju datoteke FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Postavke MainMenu: "Settings" button display text. - + Odustani RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Poništit će se sve promjene u datoteci „{0}” – uključujući tekst, prijelome redaka i kodiranje! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Da RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Sve promjene poništiti? RevertAllChangesConfirmationDialog: "Title" display text. - + Odustani SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Spremiti datoteku „{0}”? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Spremi SetCloseSaveReminderDialog: PrimaryButtonText. - + Nemoj spremiti SetCloseSaveReminderDialog: SecondaryButtonText. - + Spremiti promjene? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/hr-HR/Settings.resw b/src/Notepads/Strings/hr-HR/Settings.resw index c8ea886f8..de4b7212d 100644 --- a/src/Notepads/Strings/hr-HR/Settings.resw +++ b/src/Notepads/Strings/hr-HR/Settings.resw @@ -153,7 +153,7 @@ Izjava o privatnosti AboutPage PrivacyStatementTitle display text. - + Informacije AboutPage Title display text. @@ -169,7 +169,7 @@ Postavke za traku stanja AdvancedPage StatusBarSettings Title display text. - + Napredno AdvancedPage Title display text. @@ -209,7 +209,7 @@ Koristi modus Windowsa PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Postavke PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Prelomi riječi TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Tekst i uređivanje TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/hu-HU/Resources.resw b/src/Notepads/Strings/hu-HU/Resources.resw index 7a5229de5..1e14ec144 100644 --- a/src/Notepads/Strings/hu-HU/Resources.resw +++ b/src/Notepads/Strings/hu-HU/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Mégse AppCloseSaveReminderDialog: CloseButtonText. - + Önnek nem mentett módosításai vannak. AppCloseSaveReminderDialog: "Content" display text. - + Mentés & Kilépés AppCloseSaveReminderDialog: PrimaryButtonText. - + Elvetés & Kilépés AppCloseSaveReminderDialog: SecondaryButtonText. - + El akarod menteni a módosításokat? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Sajnos a(z) "{0}" nem nyitható meg: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Fájl Megnyitási Hiba FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Sajnos a fájl "{0}" nem menthető el: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Fájl Mentési Hiba FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Beállítások MainMenu: "Settings" button display text. - + Mégse RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Minden szöveg, sor végződés és kódolás-i módosítás "{0}"-ről vissza lesz vonva! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Igen RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Biztosan visszavonja az összes módosítást? RevertAllChangesConfirmationDialog: "Title" display text. - + Mégse SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Elmenti a(z) "{0}" fájlt? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Mentés SetCloseSaveReminderDialog: PrimaryButtonText. - + Ne Mentsen SetCloseSaveReminderDialog: SecondaryButtonText. - + El szeretné menteni a módosításokat? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Kicsi FontWeight: "Thin" - + Törlés FileRenameDialog: CloseButtonText. - + Mentés FileRenameDialog: PrimaryButtonText. - + Átnevezés FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/hu-HU/Settings.resw b/src/Notepads/Strings/hu-HU/Settings.resw index bb6c542ce..69c008e50 100644 --- a/src/Notepads/Strings/hu-HU/Settings.resw +++ b/src/Notepads/Strings/hu-HU/Settings.resw @@ -153,7 +153,7 @@ Adatvédelmi Nyilatkozat AboutPage PrivacyStatementTitle display text. - + Névjegy AboutPage Title display text. @@ -169,7 +169,7 @@ Állapotsor Beállítások AdvancedPage StatusBarSettings Title display text. - + Haladó AdvancedPage Title display text. @@ -209,7 +209,7 @@ Rendszerbeállítás használata PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Testreszabás PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Sortörés TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Szöveg & Szerkesztő TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/it-IT/Resources.resw b/src/Notepads/Strings/it-IT/Resources.resw index fb0d98d29..b86c5560f 100644 --- a/src/Notepads/Strings/it-IT/Resources.resw +++ b/src/Notepads/Strings/it-IT/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Annulla AppCloseSaveReminderDialog: CloseButtonText. - + Ci sono modifiche non salvate. AppCloseSaveReminderDialog: "Content" display text. - + Salva tutto & Esci AppCloseSaveReminderDialog: PrimaryButtonText. - + Non salvare & Esci AppCloseSaveReminderDialog: SecondaryButtonText. - + Salvare le modifiche? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Spiacenti, il file "{0}" non può essere aperto: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Errore nell'apertura del file FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Spiacenti, il file "{0}" non può essere salvato: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Errore nel salvataggio del file FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Opzioni MainMenu: "Settings" button display text. - + No RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Tutte le modifiche inclusi testi, ritorni a capo e codifica apportate a "{0}" verranno annullate! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Si RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Annullare tutte le modifiche? RevertAllChangesConfirmationDialog: "Title" display text. - + Annulla SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Salvare il file "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Salva SetCloseSaveReminderDialog: PrimaryButtonText. - + Non salvare SetCloseSaveReminderDialog: SecondaryButtonText. - + Salvare le modifiche? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Sottile FontWeight: "Thin" - + Annulla FileRenameDialog: CloseButtonText. - + Salva FileRenameDialog: PrimaryButtonText. - + Rinomina FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/it-IT/Settings.resw b/src/Notepads/Strings/it-IT/Settings.resw index 2cd6c957e..dc23dc43b 100644 --- a/src/Notepads/Strings/it-IT/Settings.resw +++ b/src/Notepads/Strings/it-IT/Settings.resw @@ -153,7 +153,7 @@ Informativa sulla Privacy AboutPage PrivacyStatementTitle display text. - + Informazioni AboutPage Title display text. @@ -169,7 +169,7 @@ Impostazioni della barra di stato AdvancedPage StatusBarSettings Title display text. - + Avanzate AdvancedPage Title display text. @@ -209,7 +209,7 @@ Usa l'impostazione di sistema PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalizzazione PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Manda a capo le parole TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Testi & Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/ja-JP/Resources.resw b/src/Notepads/Strings/ja-JP/Resources.resw index 3d1710b80..cf8621fef 100644 --- a/src/Notepads/Strings/ja-JP/Resources.resw +++ b/src/Notepads/Strings/ja-JP/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + キャンセル AppCloseSaveReminderDialog: CloseButtonText. - + 保存していない変更があります。 AppCloseSaveReminderDialog: "Content" display text. - + 全て保存して終了 AppCloseSaveReminderDialog: PrimaryButtonText. - + 破棄して終了 AppCloseSaveReminderDialog: SecondaryButtonText. - + 変更内容を保存しますか? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ ファイル "{0}" を開けませんでした: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + ファイルオープンエラー FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ ファイル "{0}" を保存できませんでした: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + ファイル保存エラー FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ 設定 MainMenu: "Settings" button display text. - + キャンセル RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ ファイル "{0}" に加えられた全ての文章・行末・エンコーディングの変更は元に戻ります! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + はい RevertAllChangesConfirmationDialog: PrimaryButtonText. - + 本当に全ての変更を元に戻しますか? RevertAllChangesConfirmationDialog: "Title" display text. - + キャンセル SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ ファイル"{0}"に保存しますか? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + 保存 SetCloseSaveReminderDialog: PrimaryButtonText. - + 保存しない SetCloseSaveReminderDialog: SecondaryButtonText. - + 変更を保存しますか? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/ja-JP/Settings.resw b/src/Notepads/Strings/ja-JP/Settings.resw index a842e5cce..3f8c11dbc 100644 --- a/src/Notepads/Strings/ja-JP/Settings.resw +++ b/src/Notepads/Strings/ja-JP/Settings.resw @@ -153,7 +153,7 @@ プライバシーについて AboutPage PrivacyStatementTitle display text. - + このアプリについて AboutPage Title display text. @@ -169,7 +169,7 @@ ステータス バー AdvancedPage StatusBarSettings Title display text. - + 詳細設定 AdvancedPage Title display text. @@ -209,7 +209,7 @@ Windows の設定を使う PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + 個人用設定 PersonalizationPage Title display text. @@ -285,7 +285,7 @@ 単語で折り返す TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + テキストとエディター TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/ka-GE/Resources.resw b/src/Notepads/Strings/ka-GE/Resources.resw index aa36f44d2..60bf3e4cc 100644 --- a/src/Notepads/Strings/ka-GE/Resources.resw +++ b/src/Notepads/Strings/ka-GE/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + გაუქმება AppCloseSaveReminderDialog: CloseButtonText. - + ცვლილებები შენახული არ არის. AppCloseSaveReminderDialog: "Content" display text. - + შეინახე ყველაფერი & გამოდი AppCloseSaveReminderDialog: PrimaryButtonText. - + არ შეინახო AppCloseSaveReminderDialog: SecondaryButtonText. - + გსურთ ცვლილებების შენახვა? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ სამწუხაროდ ფაილი "{0}"-ის გახსნა შეუძლებელია: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + კარგი FileOpenErrorDialog: PrimaryButtonText. - + ფაილის გახსნის შეცდომა FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ სამწუხაროდ ფაილი "{0}"-ის შენახვა შეუძლებელია: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + კარგი FileSaveErrorDialog: PrimaryButtonText. - + ფაილის შენახვის შეცდომა FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ სეთინგები MainMenu: "Settings" button display text. - + შეწყვეტა RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ ყველა ცვლილება ტექსტის, ხაზის დაბოლოების და ენკოდინგის ჩათვლით გათებეული "{0}"-ს მიხედვით, იქნება უკუშექცეული! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + დიახ RevertAllChangesConfirmationDialog: PrimaryButtonText. - + ნამდვილად გსურთ ყველაფრის უკან დაბრუნება? RevertAllChangesConfirmationDialog: "Title" display text. - + შეწყვეტა SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ შეინახე ფაილი "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + შეინახე SetCloseSaveReminderDialog: PrimaryButtonText. - + არ შეინახო SetCloseSaveReminderDialog: SecondaryButtonText. - + გსურთ თქვენი ფაილების შენახვა? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Cancel FileRenameDialog: CloseButtonText. - + Save FileRenameDialog: PrimaryButtonText. - + Rename FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/ka-GE/Settings.resw b/src/Notepads/Strings/ka-GE/Settings.resw index e9e4312f1..77512e5eb 100644 --- a/src/Notepads/Strings/ka-GE/Settings.resw +++ b/src/Notepads/Strings/ka-GE/Settings.resw @@ -153,7 +153,7 @@ კონფედენციალურობის შესახებგანცხადება AboutPage PrivacyStatementTitle display text. - + შესახებ AboutPage Title display text. @@ -169,7 +169,7 @@ სტატუს ბარის სეთინგები AdvancedPage StatusBarSettings Title display text. - + გაფართოებული AdvancedPage Title display text. @@ -209,7 +209,7 @@ გამოიყენე ჩემი Windows-ის რეჟიმი PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + პერსონალიზაცია PersonalizationPage Title display text. @@ -285,7 +285,7 @@ ტექსტის შეფუთვა TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + ტექსტი & ედიტორი TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/ko-KR/Resources.resw b/src/Notepads/Strings/ko-KR/Resources.resw index dc859f29c..bfafac82f 100644 --- a/src/Notepads/Strings/ko-KR/Resources.resw +++ b/src/Notepads/Strings/ko-KR/Resources.resw @@ -1,17 +1,17 @@  - @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 취소 AppCloseSaveReminderDialog: CloseButtonText. - + 저장하지 않은 변경 사항이 있습니다. AppCloseSaveReminderDialog: "Content" display text. - + 모두 저장 AppCloseSaveReminderDialog: PrimaryButtonText. - + 저장하지 않고 종료 AppCloseSaveReminderDialog: SecondaryButtonText. - + 변경 사항을 저장하시겠습니까? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ 파일 "{0}" 을 열 수 없습니다: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 확인 FileOpenErrorDialog: PrimaryButtonText. - + 파일 열기 오류 FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ 파일 "{0}" 을 저장할 수 없습니다: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 확인 FileSaveErrorDialog: PrimaryButtonText. - + 파일 저장 오류 FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ 설정 MainMenu: "Settings" button display text. - + 취소 RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ 파일 "{0}" 의 모든 변경 사항이 원래대로 돌아갑니다! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + 확인 RevertAllChangesConfirmationDialog: PrimaryButtonText. - + 정말 모든 변경 사항을 취소하시겠습니까? RevertAllChangesConfirmationDialog: "Title" display text. - + 취소 SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ "{0}"에 저장하시겠습니까? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + 저장 SetCloseSaveReminderDialog: PrimaryButtonText. - + 저장하지 않음 SetCloseSaveReminderDialog: SecondaryButtonText. - + 변경 사항을 저장하시겠습니까? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + 취소 FileRenameDialog: CloseButtonText. - + 저장 FileRenameDialog: PrimaryButtonText. - + 이름 변경 FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/ko-KR/Settings.resw b/src/Notepads/Strings/ko-KR/Settings.resw index 7d3519b5e..517b7cbdd 100644 --- a/src/Notepads/Strings/ko-KR/Settings.resw +++ b/src/Notepads/Strings/ko-KR/Settings.resw @@ -153,7 +153,7 @@ 개인정보 보호 정책 AboutPage PrivacyStatementTitle display text. - + 애플리케이션 정보 AboutPage Title display text. @@ -169,7 +169,7 @@ 상태표시줄 설정 AdvancedPage StatusBarSettings Title display text. - + 고급 AdvancedPage Title display text. @@ -209,7 +209,7 @@ 기본 Windows 모드 사용 PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + 개인 설정 PersonalizationPage Title display text. @@ -285,7 +285,7 @@ 단어 단위로 자동 개행 TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + 에디터 설정 TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/or-IN/Resources.resw b/src/Notepads/Strings/or-IN/Resources.resw index 980e3ec9d..90bbadc65 100644 --- a/src/Notepads/Strings/or-IN/Resources.resw +++ b/src/Notepads/Strings/or-IN/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + ବାତିଲ୍ କରନ୍ତୁ AppCloseSaveReminderDialog: CloseButtonText. - + ଅସଞ୍ଚିତ ପରିବର୍ତ୍ତନଗୁଡିକ ଅଛି। AppCloseSaveReminderDialog: "Content" display text. - + ସମସ୍ତ ସଞ୍ଚୟ କରି ପ୍ରସ୍ଥାନ AppCloseSaveReminderDialog: PrimaryButtonText. - + ପରିତ୍ୟାଗ ଏବଂ ପ୍ରସ୍ଥାନ AppCloseSaveReminderDialog: SecondaryButtonText. - + ଆପଣ ପରିବର୍ତ୍ତନଗୁଡିକ ସଞ୍ଚୟ କରିବାକୁ ଚାହୁଁଛନ୍ତି କି? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ ଦୁଃଖିତ, ଫାଇଲ୍ "{0}" ଖୋଲାଯାଇ ପାରିଲା ନାହିଁ: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ଠିକ୍ ଅଛି FileOpenErrorDialog: PrimaryButtonText. - + ଫାଇଲ୍ ଖୋଲା ତ୍ରୁଟି FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ ଦୁଃଖିତ, ଫାଇଲ୍ "{0}" ସଞ୍ଚୟ ହୋଇପାରିଲା ନାହିଁ: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ଠିକ୍ ଅଛି FileSaveErrorDialog: PrimaryButtonText. - + ଫାଇଲ ସଞ୍ଚୟ ତ୍ରୁଟି FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ ସେଟିଙ୍ଗ୍ସ MainMenu: "Settings" button display text. - + ବାତିଲ୍ କରନ୍ତୁ RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ ଟେକ୍ସଟ୍, ଲାଇନ୍ ଏଣ୍ଡିଙ୍ଗ୍ ଏବଂ ଏନକୋଡିଂ ସହିତ "{0}" ର ସମସ୍ତ ପରିବର୍ତ୍ତନ ଫେରସ୍ତ ହେବ! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + ହଁ RevertAllChangesConfirmationDialog: PrimaryButtonText. - + ଆପଣ ସମସ୍ତ ପରିବର୍ତ୍ତନକୁ ଫେରାଇବାକୁ ନିଶ୍ଚିତ କି? RevertAllChangesConfirmationDialog: "Title" display text. - + ବାତିଲ୍ କରନ୍ତୁ SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ ଫାଇଲ୍ "{0}" ସଞ୍ଚୟ କରନ୍ତୁ? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + ସଞ୍ଚୟ କରନ୍ତୁ SetCloseSaveReminderDialog: PrimaryButtonText. - + ସଞ୍ଚୟ କରନ୍ତୁ ନାହିଁ SetCloseSaveReminderDialog: SecondaryButtonText. - + ଆପଣଙ୍କର ପରିବର୍ତ୍ତନଗୁଡିକ ସଞ୍ଚୟ କରନ୍ତୁ SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ ପତଳା FontWeight: "Thin" - + ବାତିଲ୍ କରନ୍ତୁ FileRenameDialog: CloseButtonText. - + ସଞ୍ଚୟ କରନ୍ତୁ FileRenameDialog: PrimaryButtonText. - + ନାମବଦଳ FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/or-IN/Settings.resw b/src/Notepads/Strings/or-IN/Settings.resw index cb8dc7ebd..a1aadf26c 100644 --- a/src/Notepads/Strings/or-IN/Settings.resw +++ b/src/Notepads/Strings/or-IN/Settings.resw @@ -153,7 +153,7 @@ ଗୋପନୀୟତା ବିବୃତ୍ତି AboutPage PrivacyStatementTitle display text. - + ବିଷୟରେ AboutPage Title display text. @@ -169,7 +169,7 @@ ଷ୍ଟାଟସ୍ ବାର୍ ସେଟିଙ୍ଗ୍ସ AdvancedPage StatusBarSettings Title display text. - + ଅଭିନବ AdvancedPage Title display text. @@ -209,7 +209,7 @@ ମୋ Windows ମୋଡ୍ ବ୍ୟବହାର କରନ୍ତୁ PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + ବ୍ୟକ୍ତିଗତକରଣ PersonalizationPage Title display text. @@ -285,7 +285,7 @@ ରାପ୍ ୱର୍ଡ TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + ପାଠ ଏବଂ ସମ୍ପାଦକ TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/pl-PL/Resources.resw b/src/Notepads/Strings/pl-PL/Resources.resw index 45d27992a..9978bf074 100644 --- a/src/Notepads/Strings/pl-PL/Resources.resw +++ b/src/Notepads/Strings/pl-PL/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Anuluj AppCloseSaveReminderDialog: CloseButtonText. - + Zmiany nie zostały zapisane. AppCloseSaveReminderDialog: "Content" display text. - + Zapisz AppCloseSaveReminderDialog: PrimaryButtonText. - + Nie zapisuj AppCloseSaveReminderDialog: SecondaryButtonText. - + Czy chcesz zapisać zmiany w pliku? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Niestety, plik "{0}" nie może zostać otworzony: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + OK FileOpenErrorDialog: PrimaryButtonText. - + Nie można otworzyć pliku FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Niestety, plik "{0}" nie może zostać zapisany: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + OK FileSaveErrorDialog: PrimaryButtonText. - + Błąd zapisu pliku FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Ustawienia MainMenu: "Settings" button display text. - + Anuluj RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Wszystkie zmiany takie jak: wpisany tekst, zakończenia lini oraz kodowanie dokonane w pliku "{0}" zostaną wycofane! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Tak RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Czy chcesz wycofać wszystkie zmiany? RevertAllChangesConfirmationDialog: "Title" display text. - + Anuluj SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Zmiany w pliku "{0}" nie zostały zapisane? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Zapisz SetCloseSaveReminderDialog: PrimaryButtonText. - + Nie zapisuj SetCloseSaveReminderDialog: SecondaryButtonText. - + Zapisać dokonane zmiany? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Anuluj FileRenameDialog: CloseButtonText. - + Zapisz FileRenameDialog: PrimaryButtonText. - + Zmień nazwę FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/pl-PL/Settings.resw b/src/Notepads/Strings/pl-PL/Settings.resw index 72dd70183..d6f69c206 100644 --- a/src/Notepads/Strings/pl-PL/Settings.resw +++ b/src/Notepads/Strings/pl-PL/Settings.resw @@ -153,7 +153,7 @@ Polityka prywatności AboutPage PrivacyStatementTitle display text. - + O programie AboutPage Title display text. @@ -169,7 +169,7 @@ Pasek stanu AdvancedPage StatusBarSettings Title display text. - + Zaawansowane AdvancedPage Title display text. @@ -209,7 +209,7 @@ Użyj motywu systemu Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalizacja PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Zawijaj wiersze TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Tekst i edytor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/pt-BR/Resources.resw b/src/Notepads/Strings/pt-BR/Resources.resw index 38d16d4a1..5ce411403 100644 --- a/src/Notepads/Strings/pt-BR/Resources.resw +++ b/src/Notepads/Strings/pt-BR/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Cancelar AppCloseSaveReminderDialog: CloseButtonText. - + Há alterações não salvas. AppCloseSaveReminderDialog: "Content" display text. - + Salvar Todos AppCloseSaveReminderDialog: PrimaryButtonText. - + Descartar AppCloseSaveReminderDialog: SecondaryButtonText. - + Você deseja salvar as alterações? AppCloseSaveReminderDialog: "Title" display text. @@ -153,11 +153,11 @@ Desculpe, o arquivo "{0}" não pôde ser aberto: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Erro ao abrir o arquivo FileOpenErrorDialog: "Title" display text. @@ -165,11 +165,11 @@ Desculpe, o arquivo "{0}" não pôde ser salvo: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Erro ao salvar o arquivo FileSaveErrorDialog: "Title" display text. @@ -249,7 +249,7 @@ Configurações MainMenu: "Settings" button display text. - + Cancelar RevertAllChangesConfirmationDialog: CloseButtonText. @@ -257,15 +257,15 @@ Todas as alterações incluindo texto, terminação e codificação de linha feitas no "{0}" serão revertidas! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Sim RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Reverter todas as alterações? RevertAllChangesConfirmationDialog: "Title" display text. - + Cancelar SetCloseSaveReminderDialog: CloseButtonText. @@ -273,15 +273,15 @@ Salvar o arquivo "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Salvar SetCloseSaveReminderDialog: PrimaryButtonText. - + Não Salvar SetCloseSaveReminderDialog: SecondaryButtonText. - + Salvar as alterações? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Fina FontWeight: "Thin" - + Cancelar FileRenameDialog: CloseButtonText. - + Salvar FileRenameDialog: PrimaryButtonText. - + Renomear FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/pt-BR/Settings.resw b/src/Notepads/Strings/pt-BR/Settings.resw index 0221f33da..e23261a6f 100644 --- a/src/Notepads/Strings/pt-BR/Settings.resw +++ b/src/Notepads/Strings/pt-BR/Settings.resw @@ -153,7 +153,7 @@ Declaração de privacidade AboutPage PrivacyStatementTitle display text. - + Sobre AboutPage Title display text. @@ -169,7 +169,7 @@ Configurações da barra de status AdvancedPage StatusBarSettings Title display text. - + Avançado AdvancedPage Title display text. @@ -209,7 +209,7 @@ Usar configuração do sistema PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalização PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Desativar quebra de linha TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Editor e texto TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/pt-PT/Resources.resw b/src/Notepads/Strings/pt-PT/Resources.resw index 929bdf6ac..7dba7d121 100644 --- a/src/Notepads/Strings/pt-PT/Resources.resw +++ b/src/Notepads/Strings/pt-PT/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Cancelar AppCloseSaveReminderDialog: CloseButtonText. - + Há alterações não guardadas. AppCloseSaveReminderDialog: "Content" display text. - + Guardar Todos AppCloseSaveReminderDialog: PrimaryButtonText. - + Descartar AppCloseSaveReminderDialog: SecondaryButtonText. - + Você deseja guardar as alterações? AppCloseSaveReminderDialog: "Title" display text. @@ -153,11 +153,11 @@ Desculpe, o ficheiro "{0}" não pôde ser aberto: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileOpenErrorDialog: PrimaryButtonText. - + Erro ao abrir o ficheiro FileOpenErrorDialog: "Title" display text. @@ -165,11 +165,11 @@ Desculpe, o ficheiro "{0}" não pôde ser guardado: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Ok FileSaveErrorDialog: PrimaryButtonText. - + Erro ao guardar o ficheiro FileSaveErrorDialog: "Title" display text. @@ -249,7 +249,7 @@ Configurações MainMenu: "Settings" button display text. - + Cancelar RevertAllChangesConfirmationDialog: CloseButtonText. @@ -257,15 +257,15 @@ Todas as alterações incluindo texto, terminação e codificação de linha feitas no "{0}" serão revertidas! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Sim RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Reverter todas as alterações? RevertAllChangesConfirmationDialog: "Title" display text. - + Cancelar SetCloseSaveReminderDialog: CloseButtonText. @@ -273,15 +273,15 @@ Guardar o ficheiro "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Guardar SetCloseSaveReminderDialog: PrimaryButtonText. - + Não Guardar SetCloseSaveReminderDialog: SecondaryButtonText. - + Guardar as alterações? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Fina FontWeight: "Thin" - + Cancelar FileRenameDialog: CloseButtonText. - + Guardar FileRenameDialog: PrimaryButtonText. - + Renomear FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/pt-PT/Settings.resw b/src/Notepads/Strings/pt-PT/Settings.resw index 80ff35a64..86b7eba63 100644 --- a/src/Notepads/Strings/pt-PT/Settings.resw +++ b/src/Notepads/Strings/pt-PT/Settings.resw @@ -153,7 +153,7 @@ Declaração de privacidade AboutPage PrivacyStatementTitle display text. - + Acerca AboutPage Title display text. @@ -169,7 +169,7 @@ Configurações da barra de estado AdvancedPage StatusBarSettings Title display text. - + Avançado AdvancedPage Title display text. @@ -209,7 +209,7 @@ Usar configuração do sistema PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Personalização PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Desativar quebra de linha TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Editor e texto TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/ru-RU/Resources.resw b/src/Notepads/Strings/ru-RU/Resources.resw index b5f9dc079..fa0675b70 100644 --- a/src/Notepads/Strings/ru-RU/Resources.resw +++ b/src/Notepads/Strings/ru-RU/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Отмена AppCloseSaveReminderDialog: CloseButtonText. - + У вас есть не сохраненные изменения. AppCloseSaveReminderDialog: "Content" display text. - + Сохранить все AppCloseSaveReminderDialog: PrimaryButtonText. - + Не сохранять AppCloseSaveReminderDialog: SecondaryButtonText. - + Вы хотите сохранить изменения? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Извините, файл "{0}" не может быть открыт: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ОК FileOpenErrorDialog: PrimaryButtonText. - + Ошибка открытия файла FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Извините, файл "{0}" не может быть сохранен: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ОК FileSaveErrorDialog: PrimaryButtonText. - + Ошибка сохранения файла FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Настройки MainMenu: "Settings" button display text. - + Отмена RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Все внесенные изменения, включая текст, разрыв страки и кодировку, сделанные в "{0}" будут отменены! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Да RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Вы действительно хотите отменить все изменения? RevertAllChangesConfirmationDialog: "Title" display text. - + Отмена SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Сохранить файл "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Сохранить SetCloseSaveReminderDialog: PrimaryButtonText. - + Не сохранять SetCloseSaveReminderDialog: SecondaryButtonText. - + Сохранить изменения? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Отмена FileRenameDialog: CloseButtonText. - + Сохранить FileRenameDialog: PrimaryButtonText. - + Переименовать FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/ru-RU/Settings.resw b/src/Notepads/Strings/ru-RU/Settings.resw index 802ef5b0d..ef8de57ff 100644 --- a/src/Notepads/Strings/ru-RU/Settings.resw +++ b/src/Notepads/Strings/ru-RU/Settings.resw @@ -153,7 +153,7 @@ Заявление о конфиденциальности AboutPage PrivacyStatementTitle display text. - + О программе AboutPage Title display text. @@ -169,7 +169,7 @@ Строка состояния AdvancedPage StatusBarSettings Title display text. - + Дополнительно AdvancedPage Title display text. @@ -209,7 +209,7 @@ Стандартная Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Персонализация PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Перенос по словам TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Текст и редактирование TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/tr-TR/Resources.resw b/src/Notepads/Strings/tr-TR/Resources.resw index 107a0796e..5def71ed7 100755 --- a/src/Notepads/Strings/tr-TR/Resources.resw +++ b/src/Notepads/Strings/tr-TR/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + İptal Et AppCloseSaveReminderDialog: CloseButtonText. - + Kaydedilmemiş değişiklikler var. AppCloseSaveReminderDialog: "Content" display text. - + Tümünü Kaydet ve Çık AppCloseSaveReminderDialog: PrimaryButtonText. - + İptal Et ve Çık AppCloseSaveReminderDialog: SecondaryButtonText. - + Değişiklikleri kaydetmek istiyor musunuz? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Üzgünüm, "{0}" dosyası açılamıyor: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Tamam FileOpenErrorDialog: PrimaryButtonText. - + Dosya Açma Hatası FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Üzgünüm, "{0}" dosyası kaydedilemedi: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + Tamam FileSaveErrorDialog: PrimaryButtonText. - + Dosya Kaydetme Hatası FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Ayarlar MainMenu: "Settings" button display text. - + İptal Et RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ "{0}" dosyasına yapılan tüm değişiklikler geri alınacak! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Evet RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Tüm değişiklikleri geri almak istediğinizden emin misiniz? RevertAllChangesConfirmationDialog: "Title" display text. - + İptal Et SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ "{0}" dosyası kaydedilsin mi? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Kaydet SetCloseSaveReminderDialog: PrimaryButtonText. - + Kaydetme SetCloseSaveReminderDialog: SecondaryButtonText. - + Değişiklikler kaydedilsin mi? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ İnce FontWeight: "Thin" - + İptal Et FileRenameDialog: CloseButtonText. - + Kaydet FileRenameDialog: PrimaryButtonText. - + Yeniden Adlandır FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/tr-TR/Settings.resw b/src/Notepads/Strings/tr-TR/Settings.resw index 31f680e1e..54d6b3817 100755 --- a/src/Notepads/Strings/tr-TR/Settings.resw +++ b/src/Notepads/Strings/tr-TR/Settings.resw @@ -153,7 +153,7 @@ Gizlilik Beyanı AboutPage PrivacyStatementTitle display text. - + Hakkında AboutPage Title display text. @@ -169,7 +169,7 @@ Durum Çubuğu Ayarları AdvancedPage StatusBarSettings Title display text. - + Gelişmiş AdvancedPage Title display text. @@ -209,7 +209,7 @@ Windows rengini kullan PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Kişiselleştirme PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Sözcük kaydır TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Metin ve Editor TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/uk-UA/Resources.resw b/src/Notepads/Strings/uk-UA/Resources.resw index b46ad6662..035ee63b7 100644 --- a/src/Notepads/Strings/uk-UA/Resources.resw +++ b/src/Notepads/Strings/uk-UA/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + Скасувати AppCloseSaveReminderDialog: CloseButtonText. - + У вас є незбережені зміни. AppCloseSaveReminderDialog: "Content" display text. - + Зберегти AppCloseSaveReminderDialog: PrimaryButtonText. - + Не зберігати AppCloseSaveReminderDialog: SecondaryButtonText. - + Хочете зберегти зміни? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ Вибачте, файл "{0}" не може бути відкритий: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ОК FileOpenErrorDialog: PrimaryButtonText. - + Помилка відкриття файлу FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ Вибачте, файл "{0}" не може бути збережений: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + ОК FileSaveErrorDialog: PrimaryButtonText. - + Помилка збереження файлу FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ Настройки MainMenu: "Settings" button display text. - + Ні RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ Усі зміни, включаючи текст, закінчення рядків та кодування, внесені до файлу "{0}" будуть cкасовані! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + Так RevertAllChangesConfirmationDialog: PrimaryButtonText. - + Ви впевнені, що хочете скасувати всі зміни? RevertAllChangesConfirmationDialog: "Title" display text. - + Скасувати SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ Зберегти файл "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + Зберегти SetCloseSaveReminderDialog: PrimaryButtonText. - + Не зберігати SetCloseSaveReminderDialog: SecondaryButtonText. - + Зберегти зміни? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + Скасувати FileRenameDialog: CloseButtonText. - + Зберегти FileRenameDialog: PrimaryButtonText. - + Перейменування FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/uk-UA/Settings.resw b/src/Notepads/Strings/uk-UA/Settings.resw index b4c29d7e8..8d6061a01 100644 --- a/src/Notepads/Strings/uk-UA/Settings.resw +++ b/src/Notepads/Strings/uk-UA/Settings.resw @@ -153,7 +153,7 @@ Конфіденційність AboutPage PrivacyStatementTitle display text. - + Про програму AboutPage Title display text. @@ -169,7 +169,7 @@ Налаштування рядка стану AdvancedPage StatusBarSettings Title display text. - + Додатково AdvancedPage Title display text. @@ -209,7 +209,7 @@ Використовувати тему Windows PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + Персоналізація PersonalizationPage Title display text. @@ -285,7 +285,7 @@ Переносити слова TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + Текст і редактор TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/zh-CN/Resources.resw b/src/Notepads/Strings/zh-CN/Resources.resw index 30305b89d..d3e4c8b1a 100644 --- a/src/Notepads/Strings/zh-CN/Resources.resw +++ b/src/Notepads/Strings/zh-CN/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 取消 AppCloseSaveReminderDialog: CloseButtonText. - + 您有尚未保存的内容。 AppCloseSaveReminderDialog: "Content" display text. - + 全部保存并退出 AppCloseSaveReminderDialog: PrimaryButtonText. - + 退出不保存 AppCloseSaveReminderDialog: SecondaryButtonText. - + 是否保存更改? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ 抱歉,文件 "{0}" 打开失败: {1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 明白 FileOpenErrorDialog: PrimaryButtonText. - + 文件打开失败 FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ 抱歉,文件 "{0}" 保存失败: {1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 明白 FileSaveErrorDialog: PrimaryButtonText. - + 文件保存失败 FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ 设置 MainMenu: "Settings" button display text. - + 取消 RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ 所有对 "{0}" 的改动包括文字,换行符和编码将会被撤消! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + 是的 RevertAllChangesConfirmationDialog: PrimaryButtonText. - + 是否撤消所有改动? RevertAllChangesConfirmationDialog: "Title" display text. - + 取消 SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ 是否将更改保存到 "{0}"? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + 保存 SetCloseSaveReminderDialog: PrimaryButtonText. - + 不保存 SetCloseSaveReminderDialog: SecondaryButtonText. - + 是否保存更改? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ Thin FontWeight: "Thin" - + 取消 FileRenameDialog: CloseButtonText. - + 确认 FileRenameDialog: PrimaryButtonText. - + 重命名 FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/zh-CN/Settings.resw b/src/Notepads/Strings/zh-CN/Settings.resw index 2b9dcbd0a..e42302b7d 100644 --- a/src/Notepads/Strings/zh-CN/Settings.resw +++ b/src/Notepads/Strings/zh-CN/Settings.resw @@ -153,7 +153,7 @@ 隐私声明 AboutPage PrivacyStatementTitle display text. - + 关于 AboutPage Title display text. @@ -169,7 +169,7 @@ 状态栏设置 AdvancedPage StatusBarSettings Title display text. - + 高级 AdvancedPage Title display text. @@ -209,7 +209,7 @@ 使用我的Windows模式 PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + 个性化 PersonalizationPage Title display text. @@ -285,7 +285,7 @@ 自动换行 TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + 文本与编辑器 TextAndEditorPage Title display text. diff --git a/src/Notepads/Strings/zh-TW/Resources.resw b/src/Notepads/Strings/zh-TW/Resources.resw index 568f4dd84..d06abad4c 100644 --- a/src/Notepads/Strings/zh-TW/Resources.resw +++ b/src/Notepads/Strings/zh-TW/Resources.resw @@ -117,23 +117,23 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + 取消 AppCloseSaveReminderDialog: CloseButtonText. - + 尚還有未儲存的內容。 AppCloseSaveReminderDialog: "Content" display text. - + 全部儲存並退出 AppCloseSaveReminderDialog: PrimaryButtonText. - + 退出不儲存 AppCloseSaveReminderDialog: SecondaryButtonText. - + 您要儲存這些變更嗎? AppCloseSaveReminderDialog: "Title" display text. @@ -157,11 +157,11 @@ 抱歉,檔案「{0}」開啟時發生錯誤:{1} FileOpenErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 確定 FileOpenErrorDialog: PrimaryButtonText. - + 檔案開啟錯誤 FileOpenErrorDialog: "Title" display text. @@ -169,11 +169,11 @@ 抱歉,檔案「{0}」儲存時發生錯誤:{1} FileSaveErrorDialog: "Content" display text, {0} stands for file path, {1} stands for error message. You can change the order but DO NOT REMOVE them from the string. - + 確定 FileSaveErrorDialog: PrimaryButtonText. - + 檔案儲存錯誤 FileSaveErrorDialog: "Title" display text. @@ -253,7 +253,7 @@ 設定 MainMenu: "Settings" button display text. - + 取消 RevertAllChangesConfirmationDialog: CloseButtonText. @@ -261,15 +261,15 @@ 所有對「{0}」的變更包括文字、行尾以及編碼將會被還原! RevertAllChangesConfirmationDialog: "Content" display text, {0} stands for file name. You can change the order but DO NOT REMOVE it from the string. - + RevertAllChangesConfirmationDialog: PrimaryButtonText. - + 您確定要還原所有變更嗎? RevertAllChangesConfirmationDialog: "Title" display text. - + 取消 SetCloseSaveReminderDialog: CloseButtonText. @@ -277,15 +277,15 @@ 要儲存對「{0}」的變更嗎? SetCloseSaveReminderDialog: "Content" display text. {0} stands for file name/path. You can change the order but DO NOT REMOVE it from the string. - + 儲存 SetCloseSaveReminderDialog: PrimaryButtonText. - + 不要儲存 SetCloseSaveReminderDialog: SecondaryButtonText. - + 是否儲存變更? SetCloseSaveReminderDialog: "Title" display text. @@ -641,15 +641,15 @@ 細體 FontWeight: "Thin" - + 取消 FileRenameDialog: CloseButtonText. - + 確定 FileRenameDialog: PrimaryButtonText. - + 重新命名 FileRenameDialog: "Title" display text. diff --git a/src/Notepads/Strings/zh-TW/Settings.resw b/src/Notepads/Strings/zh-TW/Settings.resw index 9a3d4533f..ac075e1a9 100644 --- a/src/Notepads/Strings/zh-TW/Settings.resw +++ b/src/Notepads/Strings/zh-TW/Settings.resw @@ -153,7 +153,7 @@ 隱私權聲明 AboutPage PrivacyStatementTitle display text. - + 關於 AboutPage Title display text. @@ -169,7 +169,7 @@ 狀態列設定 AdvancedPage StatusBarSettings Title display text. - + 進階設定 AdvancedPage Title display text. @@ -209,7 +209,7 @@ 使用 Windows 設定 PersonalizationPage ThemeModeSettings WindowsModeRadioButton content display text. - + 個人化 PersonalizationPage Title display text. @@ -285,7 +285,7 @@ 自動換行 TextAndEditorPage TextWrappingSettings ToggleSwitch On display text. - + 文字與編輯器 TextAndEditorPage Title display text. diff --git a/src/Notepads/Utilities/BehaviorUtility.cs b/src/Notepads/Utilities/BehaviorUtility.cs new file mode 100644 index 000000000..b746324de --- /dev/null +++ b/src/Notepads/Utilities/BehaviorUtility.cs @@ -0,0 +1,47 @@ +namespace Notepads.Utilities +{ + using System; + using Windows.UI.Xaml; + using Microsoft.Xaml.Interactivity; + + public static class BehaviorUtility + { + public static DataTemplate GetAttachedBehaviors(DependencyObject obj) + { + return (DataTemplate)obj.GetValue(AttachedBehaviorsProperty); + } + + public static void SetAttachedBehaviors(DependencyObject obj, DataTemplate value) + { + obj.SetValue(AttachedBehaviorsProperty, value); + } + + public static readonly DependencyProperty AttachedBehaviorsProperty = + DependencyProperty.RegisterAttached( + "AttachedBehaviors", + typeof(DataTemplate), + typeof(BehaviorUtility), + new PropertyMetadata(null, Callback) + ); + + private static void Callback(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + BehaviorCollection collection = null; + var value = (e.NewValue as DataTemplate)?.LoadContent(); + + switch (value) + { + case BehaviorCollection behaviors: + collection = behaviors; + break; + case IBehavior _: + collection = new BehaviorCollection { value }; + break; + default: + throw new Exception($"AttachedBehaviors should be a BehaviorCollection or an IBehavior."); + } + // collection may be null here, if e.NewValue is null + Interaction.SetBehaviors(d, collection); + } + } +} diff --git a/src/Notepads/Utilities/DialogManager.cs b/src/Notepads/Utilities/DialogManager.cs index f3728635b..0d51e996d 100644 --- a/src/Notepads/Utilities/DialogManager.cs +++ b/src/Notepads/Utilities/DialogManager.cs @@ -9,11 +9,11 @@ public static class DialogManager { - public static NotepadsDialog ActiveDialog; + public static INotepadsDialog ActiveDialog; private static TaskCompletionSource _dialogAwaiter = new TaskCompletionSource(); - public static async Task OpenDialogAsync(NotepadsDialog dialog, bool awaitPreviousDialog) + public static async Task OpenDialogAsync(INotepadsDialog dialog, bool awaitPreviousDialog) { try { @@ -43,7 +43,7 @@ public static class DialogManager return null; } - private static async Task OpenDialog(NotepadsDialog dialog, bool awaitPreviousDialog) + private static async Task OpenDialog(INotepadsDialog dialog, bool awaitPreviousDialog) { TaskCompletionSource currentAwaiter = _dialogAwaiter; TaskCompletionSource nextAwaiter = new TaskCompletionSource(); diff --git a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml index 4ea5550b2..c3afcbd97 100644 --- a/src/Notepads/Views/MainPage/NotepadsMainPage.xaml +++ b/src/Notepads/Views/MainPage/NotepadsMainPage.xaml @@ -2,15 +2,17 @@ x:Class="Notepads.Views.MainPage.NotepadsMainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:Core="using:Microsoft.Xaml.Interactions.Core" + xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:controls="using:Notepads.Controls" - xmlns:extensions="using:Microsoft.Toolkit.Uwp.UI.Extensions" - xmlns:Interactivity="using:Microsoft.Xaml.Interactivity" - xmlns:Core="using:Microsoft.Xaml.Interactions.Core" - mc:Ignorable="d" + xmlns:muxc="using:Microsoft.UI.Xaml.Controls" + xmlns:muxca="using:Microsoft.UI.Xaml.Controls.AnimatedVisuals" + xmlns:wctc="using:Microsoft.Toolkit.Uwp.UI.Controls" + xmlns:wctui="using:Microsoft.Toolkit.Uwp.UI" + Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" NavigationCacheMode="Required" - Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + mc:Ignorable="d"> @@ -18,35 +20,38 @@ - - - + + + - + - + - - 32 - 90 - 210 - - - - + - + - - + + - - - + - -