Skip to content

A Swiss Army knife for developers.

Refactoring + Fix bug with Open in new window menu

Etienne Baudouxee2dc3df8647
diff --git a/src/dev/def/DevTools.Core/Constants.cs b/src/dev/def/DevTools.Core/Constants.cs
index 8ff37cd25..8eb79641f 100644
--- a/src/dev/def/DevTools.Core/Constants.cs
+++ b/src/dev/def/DevTools.Core/Constants.cs
@@ -3,7 +3,7 @@
public static class Constants
{
// URI Activation Protocol
- public const string UriActivationProtocolName = "devtools://";
+ public const string UriActivationProtocolName = "devtoys://";
public const string UriActivationProtocolToolArgument = "tool";
}
}
diff --git a/src/dev/def/DevTools.Core/Injection/IMefProvider.cs b/src/dev/def/DevTools.Core/Injection/IMefProvider.cs
index 86e8fa6cc..c1b196e11 100644
--- a/src/dev/def/DevTools.Core/Injection/IMefProvider.cs
+++ b/src/dev/def/DevTools.Core/Injection/IMefProvider.cs
@@ -3,7 +3,7 @@
namespace DevTools.Core.Injection
{
/// <summary>
- /// Provides a way to import MEF components on the fly/
+ /// Provides a way to import MEF components on the fly.
/// </summary>
public interface IMefProvider
{
diff --git a/src/dev/def/DevTools.Core/Navigation/NavigationParameter.cs b/src/dev/def/DevTools.Core/Navigation/NavigationParameter.cs
index 6970ff50c..0ae2e54a6 100644
--- a/src/dev/def/DevTools.Core/Navigation/NavigationParameter.cs
+++ b/src/dev/def/DevTools.Core/Navigation/NavigationParameter.cs
@@ -1,4 +1,5 @@
using DevTools.Core.Injection;
+using System.ComponentModel;
namespace DevTools.Core.Navigation
{
@@ -7,15 +8,31 @@ namespace DevTools.Core.Navigation
/// </summary>
public class NavigationParameter
{
+ /// <summary>
+ /// Gets the MEF exporter.
+ /// </summary>
public IMefProvider ExportProvider { get; }
+ /// <summary>
+ /// Gets the query used when opening the app through the URI protocol.
+ /// </summary>
public string? Query { get; }
- public object? ViewModel { get; }
+ /// <summary>
+ /// Gets the view model to apply to the page we navigate to.
+ /// </summary>
+ public INotifyPropertyChanged? ViewModel { get; }
+ /// <summary>
+ /// Gets the text that is in the clipboard. This value is used for the Smart Detection feature.
+ /// </summary>
public string? ClipBoardContent { get; }
- public NavigationParameter(IMefProvider exportProvider, object? viewModel, string? clipBoardContent = null, string? query = null)
+ public NavigationParameter(
+ IMefProvider exportProvider,
+ INotifyPropertyChanged? viewModel = null,
+ string? clipBoardContent = null,
+ string? query = null)
{
ExportProvider = Arguments.NotNull(exportProvider, nameof(exportProvider));
ViewModel = viewModel;
diff --git a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs
index 5fa96d7b8..d68a8cc65 100644
--- a/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs
+++ b/src/dev/impl/DevTools.Common/UI/Controls/FormattedTextBlock/CustomDelimiterChunker.cs
@@ -6,7 +6,7 @@ namespace DevTools.Common.UI.Controls.FormattedTextBlock
{
public class CustomDelimiterChunker : IChunker
{
- private readonly string[] delimiters;
+ private readonly string[] _delimiters;
public CustomDelimiterChunker(string[] delimiters)
{
@@ -15,57 +15,57 @@ namespace DevTools.Common.UI.Controls.FormattedTextBlock
throw new ArgumentException($"{nameof(delimiters)} cannot be null or empty.", nameof(delimiters));
}
- this.delimiters = delimiters;
+ _delimiters = delimiters;
}
- public string[] Chunk(string str)
+ public string[] Chunk(string inputString)
{
- var list = new List<string>();
+ var chunks = new List<string>();
int begin = 0;
- for (int i = 0; i < str.Length; i++)
+ for (int i = 0; i < inputString.Length; i++)
{
- var delimiterFound = IndexOfAnySubString(str, delimiters, i, out int delimiterLength);
+ int delimiterFound = IndexOfAnySubString(inputString, _delimiters, i, out int delimiterLength);
if (delimiterFound != -1)
{
- string word = str.Substring(begin, i - begin);
- string delimiter = str.Substring(i, delimiterLength);
+ string word = inputString.Substring(begin, i - begin);
+ string delimiter = inputString.Substring(i, delimiterLength);
if (!string.IsNullOrEmpty(word))
{
- list.Add(word);
+ chunks.Add(word);
}
if (!string.IsNullOrEmpty(delimiter))
{
- list.Add(delimiter);
+ chunks.Add(delimiter);
}
begin = i + delimiterLength;
i += delimiterLength - 1;
}
- else if (i == str.Length - 1)
+ else if (i == inputString.Length - 1)
{
- string lastWord = str.Substring(begin, str.Length - begin);
+ string lastWord = inputString.Substring(begin, inputString.Length - begin);
if (!string.IsNullOrEmpty(lastWord))
{
- list.Add(lastWord);
+ chunks.Add(lastWord);
}
}
}
- return list.ToArray();
+ return chunks.ToArray();
}
private int IndexOfAnySubString(string str, string[] delimiters, int startIndex, out int delimiterLength)
{
- var bestMatch = -1;
+ int bestMatch = -1;
delimiterLength = 0;
for (int i = 0; i < delimiters.Length; i++)
{
string delimiter = delimiters[i];
- var index = str.IndexOf(delimiter, startIndex);
+ int index = str.IndexOf(delimiter, startIndex);
if (index == startIndex && delimiter.Length > delimiterLength)
{
bestMatch = index;
diff --git a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
index 905475f79..f82235660 100644
--- a/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
+++ b/src/dev/impl/DevTools.Impl/ViewModels/MainPageViewModel.cs
@@ -25,6 +25,8 @@ using Microsoft.Toolkit.Mvvm.Messaging;
using Windows.UI.Xaml;
using DevTools.Core.Settings;
using ThreadPriority = DevTools.Core.Threading.ThreadPriority;
+using DevTools.Core.Navigation;
+using System.Diagnostics;
namespace DevTools.Impl.ViewModels
{
@@ -272,16 +274,16 @@ namespace DevTools.Impl.ViewModels
/// <summary>
/// Invoked when the Page is loaded and becomes the current source of a parent Frame.
/// </summary>
- internal async Task OnNavigatedToAsync(object? arguments)
+ internal async Task OnNavigatedToAsync(NavigationParameter parameters)
{
// Make sure the menu items exist.
await _firstUpdateMenuTask.ConfigureAwait(false);
MatchedToolProviderViewData? toolProviderViewDataToSelect = null;
- if (arguments is string argumentsString && !string.IsNullOrWhiteSpace(argumentsString))
+ if (!string.IsNullOrWhiteSpace(parameters.Query))
{
- NameValueCollection parameters = HttpUtility.ParseQueryString(argumentsString.ToLower(CultureInfo.CurrentCulture));
- string? toolProviderProtocolName = parameters.Get(Constants.UriActivationProtocolToolArgument);
+ NameValueCollection queryParameters = HttpUtility.ParseQueryString(parameters.Query!.ToLower(CultureInfo.CurrentCulture));
+ string? toolProviderProtocolName = queryParameters.Get(Constants.UriActivationProtocolToolArgument);
if (!string.IsNullOrWhiteSpace(toolProviderProtocolName))
{
diff --git a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml.cs b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml.cs
index 757b79ac9..5d7b1dede 100644
--- a/src/dev/impl/DevTools.Impl/Views/MainPage.xaml.cs
+++ b/src/dev/impl/DevTools.Impl/Views/MainPage.xaml.cs
@@ -7,6 +7,7 @@ using DevTools.Core.Threading;
using DevTools.Impl.Messages;
using DevTools.Impl.ViewModels;
using Microsoft.Toolkit.Mvvm.Messaging;
+using System.Diagnostics;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
@@ -57,7 +58,7 @@ namespace DevTools.Impl.Views
ViewModel = parameters.ExportProvider.Import<MainPageViewModel>();
DataContext = ViewModel;
- ViewModel.OnNavigatedToAsync(parameters.ViewModel).Forget();
+ ViewModel.OnNavigatedToAsync(parameters).Forget();
base.OnNavigatedTo(e);
}
@@ -79,7 +80,8 @@ namespace DevTools.Impl.Views
message.ViewModel.View,
new NavigationParameter(
_mefProvider!,
- message.ViewModel, message.ClipboardContentData ?? string.Empty),
+ message.ViewModel,
+ message.ClipboardContentData),
new EntranceNavigationTransitionInfo());
}
}
diff --git a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml.cs b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml.cs
index ff62e6ff9..c4fcf2bba 100644
--- a/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Impl/Views/Settings/SettingsToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Impl.Views.Settings
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (SettingsToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (SettingsToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
base.OnNavigatedTo(e);
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
index d106bfe19..03a678723 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/Base64EncoderDecoder/Base64EncoderDecoderToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Providers.Impl.Tools.Base64EncoderDecoder
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (Base64EncoderDecoderToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (Base64EncoderDecoderToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
if (!string.IsNullOrWhiteSpace(parameters.ClipBoardContent))
{
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/HashGenerator/HashGeneratorToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/HashGenerator/HashGeneratorToolPage.xaml.cs
index 69ecd5d73..828e0d176 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/HashGenerator/HashGeneratorToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/HashGenerator/HashGeneratorToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Providers.Impl.Tools.HashGenerator
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (HashGeneratorToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (HashGeneratorToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
base.OnNavigatedTo(e);
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolPage.xaml.cs
index 026e28c4f..a5dbee5c0 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/JsonFormatter/JsonFormatterToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Providers.Impl.Tools.JsonFormatter
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (JsonFormatterToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (JsonFormatterToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
ViewModel.OutputTextBlock = OutputTextBlock;
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/RegEx/RegExToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/RegEx/RegExToolPage.xaml.cs
index 95bd4bfa8..f2cdd1701 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/RegEx/RegExToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/RegEx/RegExToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Providers.Impl.Tools.RegEx
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (RegExToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (RegExToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
ViewModel.MatchTextBox = MatchTextBox;
diff --git a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs
index f6362640d..12a8fbce6 100644
--- a/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs
+++ b/src/dev/impl/DevTools.Providers.Impl/Tools/TextDiff/TextDiffToolPage.xaml.cs
@@ -1,5 +1,6 @@
#nullable enable
+using DevTools.Core;
using DevTools.Core.Navigation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
@@ -35,7 +36,8 @@ namespace DevTools.Providers.Impl.Tools.TextDiff
var parameters = (NavigationParameter)e.Parameter;
// Set the view model
- ViewModel = (TextDiffToolViewModel)parameters.ViewModel;
+ Assumes.NotNull(parameters.ViewModel, nameof(parameters.ViewModel));
+ ViewModel = (TextDiffToolViewModel)parameters.ViewModel!;
DataContext = ViewModel;
ViewModel.OutputTextBlock = OuputTextEditor;
diff --git a/src/dev/startup/DevTools/App.xaml.cs b/src/dev/startup/DevTools/App.xaml.cs
index 292d6d8bd..f8584fbe2 100644
--- a/src/dev/startup/DevTools/App.xaml.cs
+++ b/src/dev/startup/DevTools/App.xaml.cs
@@ -112,7 +112,6 @@ namespace DevTools
typeof(MainPage),
new NavigationParameter(
mefComposer.ExportProvider.GetExport<IMefProvider>(),
- viewModel: null,
query: e.Arguments));
}
@@ -139,7 +138,7 @@ namespace DevTools
typeof(MainPage),
new NavigationParameter(
mefComposer.ExportProvider.GetExport<IMefProvider>(),
- eventArgs.Uri.Query));
+ query: eventArgs.Uri.Query));
// Ensure the current window is active
Window.Current.Activate();