Compare commits

..

8 Commits

Author SHA1 Message Date
Christian Gaarden Gaardmark
13e0d10048 Merge branch 'microsoft:main' into New+feature-37545-option-to-disable-existing-new 2025-08-15 21:13:36 -07:00
Christian Gaarden Gaardmark
4a129bbc6a Merge remote-tracking branch 'upstream/main' into New+feature-37545-option-to-disable-existing-new 2025-08-15 07:02:39 -07:00
Christian Gaarden Gaardmark
e2a376f637 Merge branch 'microsoft:main' into New+feature-37545-option-to-disable-existing-new 2025-06-13 09:22:36 +02:00
Christian Gaarden Gaardmark
1a3d19b23a Update src/settings-ui/Settings.UI/ViewModels/NewPlusViewModel.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
2025-06-11 13:26:53 +02:00
Christian Gaarden Gaardmark
79c0946d34 More changes 2025-06-01 18:41:38 +02:00
Christian Gaarden Gaardmark
8b6ce32a6d Merge remote-tracking branch 'upstream/main' into New+feature-37545-option-to-disable-existing-new 2025-06-01 13:30:48 +02:00
Christian Gaarden Gaardmark
3e6eba342e Minor 2025-06-01 11:00:06 +02:00
Christian Gaarden Gaardmark
d29e01f188 Initial version
Tested on Windows 11 x64
2025-05-30 18:13:25 +02:00
178 changed files with 704 additions and 1167 deletions

View File

@@ -115,7 +115,6 @@ bigbar
bigobj
binlog
binres
binskim
BITMAPFILEHEADER
bitmapimage
BITMAPINFO
@@ -256,7 +255,6 @@ Corpor
cotaskmem
COULDNOT
countof
covrun
cpcontrols
cph
cplusplus
@@ -637,7 +635,6 @@ hmodule
hmonitor
homies
homljgmgpmcbpjbnjpfijnhipfkiclkd
HOOKPROC
HORZRES
HORZSIZE
Hostbackdropbrush
@@ -972,7 +969,6 @@ msc
mscorlib
msctls
msdata
msdia
MSDL
MSGFLT
MSHCTX

View File

@@ -64,10 +64,6 @@ extends:
tsa:
enabled: true
configFile: '$(Build.SourcesDirectory)\.pipelines\tsa.json'
binskim:
enabled: true
# Exclude every dll/exe in tests/*, as well as all msdia*, covrun* and vcruntime*
analyzeTargetGlob: +:file|$(Build.ArtifactStagingDirectory)/**/*.dll;+:file|$(Build.ArtifactStagingDirectory)/**/*.exe;-:file:regex|tests.*\.(dll|exe)$;-:file:regex|(covrun.*)\.dll$;-:file:regex|(msdia.*)\.dll$;-:file:regex|(vcruntime.*)\.dll$
stages:
- stage: Build

View File

@@ -52,7 +52,7 @@ Once you've discussed your proposed feature/fix/etc. with a team member, and an
## Rules
- **Follow the pattern of what you already see in the code.**
- [Coding style](style.md).
- [Coding style](development/style.md).
- Try to package new functionality/components into libraries that have nicely defined interfaces.
- Package new functionality into classes or refactor existing functionality into a class as you extend the code.
- When adding new classes/methods/changing existing code, add new unit tests or update the existing tests.

View File

@@ -206,6 +206,11 @@
<!-- Clean Video Conference Mute registry keys that might be around from previous installations. We've deprecated this utility since then. -->
<Custom Action="CleanVideoConferenceRegistry" Before="InstallFinalize">NOT Installed</Custom>
<!-- User may have disabled the built-in New context menu via New+ -->
<Custom Action="RestoreBuiltInNewContextMenu" Before="RemoveFiles">
Installed AND (REMOVE="ALL")
</Custom>
</InstallExecuteSequence>
<CustomAction Id="SetLaunchPowerToysParam"
@@ -462,6 +467,14 @@
DllEntry="InstallCmdPalPackageCA"
/>
<CustomAction Id="RestoreBuiltInNewContextMenu"
Return="ignore"
Impersonate="yes"
Execute="deferred"
BinaryKey="PTCustomActions"
DllEntry="RestoreBuiltInNewContextMenuCA"
/>
<!-- Close 'PowerToys.exe' before uninstall-->
<Property Id="MSIRESTARTMANAGERCONTROL" Value="DisableShutdown" />
<Property Id="MSIFASTINSTALL" Value="DisableShutdown" />

View File

@@ -11,7 +11,7 @@
<Fragment>
<!-- Resource directories should be added only if the installer is built on the build farm -->
<?ifdef env.IsPipeline?>
<?foreach ParentDirectory in INSTALLFOLDER;WinUI3AppsInstallFolder;HistoryPluginFolder;CalculatorPluginFolder;FolderPluginFolder;ProgramPluginFolder;ShellPluginFolder;IndexerPluginFolder;UnitConverterPluginFolder;ValueGeneratorPluginFolder;UriPluginFolder;WindowWalkerPluginFolder;OneNotePluginFolder;RegistryPluginFolder;VSCodeWorkspacesPluginFolder;ServicePluginFolder;SystemPluginFolder;TimeDatePluginFolder;WindowsSettingsPluginFolder;WindowsTerminalPluginFolder;WebSearchPluginFolder;PowerToysPluginFolder?>
<?foreach ParentDirectory in INSTALLFOLDER;HistoryPluginFolder;CalculatorPluginFolder;FolderPluginFolder;ProgramPluginFolder;ShellPluginFolder;IndexerPluginFolder;UnitConverterPluginFolder;ValueGeneratorPluginFolder;UriPluginFolder;WindowWalkerPluginFolder;OneNotePluginFolder;RegistryPluginFolder;VSCodeWorkspacesPluginFolder;ServicePluginFolder;SystemPluginFolder;TimeDatePluginFolder;WindowsSettingsPluginFolder;WindowsTerminalPluginFolder;WebSearchPluginFolder;PowerToysPluginFolder?>
<DirectoryRef Id="$(var.ParentDirectory)">
<!-- Resource file directories -->
<?foreach Language in $(var.LocLanguageList)?>
@@ -181,7 +181,7 @@
</Component>
<Component
Id="ImageResizer_$(var.IdSafeLanguage)_Component"
Directory="Resource$(var.IdSafeLanguage)WinUI3AppsInstallFolder"
Directory="Resource$(var.IdSafeLanguage)INSTALLFOLDER"
Guid="$(var.CompGUIDPrefix)02">
<RegistryKey Root="$(var.RegistryScope)" Key="Software\Classes\powertoys\components">
<RegistryValue Type="string" Name="ImageResizer_$(var.IdSafeLanguage)_Component" Value="" KeyPath="yes"/>
@@ -553,7 +553,6 @@
<RemoveFolder Id="RemoveFolderResourcesResource$(var.IdSafeLanguage)HistoryPluginFolder" Directory="Resource$(var.IdSafeLanguage)HistoryPluginFolder" On="uninstall"/>
<RemoveFolder Id="RemoveFolderResourcesResource$(var.IdSafeLanguage)PowerToysPluginFolder" Directory="Resource$(var.IdSafeLanguage)PowerToysPluginFolder" On="uninstall"/>
<RemoveFolder Id="RemoveFolderResourcesResource$(var.IdSafeLanguage)ValueGeneratorPluginFolder" Directory="Resource$(var.IdSafeLanguage)ValueGeneratorPluginFolder" On="uninstall"/>
<RemoveFolder Id="RemoveFolderResourcesResource$(var.IdSafeLanguage)WinUI3AppsInstallFolder" Directory="Resource$(var.IdSafeLanguage)WinUI3AppsInstallFolder" On="uninstall"/>
<?undef IdSafeLanguage?>
<?endforeach?>
</Component>

View File

@@ -1153,6 +1153,65 @@ UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
return WcaFinalize(er);
}
UINT __stdcall RestoreBuiltInNewContextMenuCA(MSIHANDLE hInstall)
{
// Must be run as administrator to open and modify the registry.
HRESULT hr = S_OK;
UINT er = ERROR_SUCCESS;
hr = WcaInitialize(hInstall, "RestoreBuiltInNewContextMenuCA");
try
{
const std::wstring builtInNewRegistryPath = LR"(Directory\Background\shellex\ContextMenuHandlers\New)";
const std::wstring newDisabledValuePrefix = L"0_";
auto regDeleter = [](HKEY* regKeyHandle) { if (regKeyHandle && *regKeyHandle) RegCloseKey(*regKeyHandle); delete regKeyHandle; };
std::unique_ptr<HKEY, decltype(regDeleter)> regKeyHandle(new HKEY(nullptr), regDeleter);
const LONG openStatus = RegOpenKeyExW(HKEY_CLASSES_ROOT, builtInNewRegistryPath.c_str(), 0, KEY_READ | KEY_WRITE, regKeyHandle.get());
if (openStatus != ERROR_SUCCESS)
{
throw std::runtime_error("Failed to open New context menu registry key.");
}
wchar_t buffer[256];
DWORD bufferSize = sizeof(buffer);
const LONG queryStatus = RegQueryValueExW(*regKeyHandle, nullptr, nullptr, nullptr, reinterpret_cast<LPBYTE>(buffer), &bufferSize);
if (queryStatus != ERROR_SUCCESS)
{
throw std::runtime_error("Failed to read New context menu registry key.");
}
const std::wstring builtInNewHandlerValue(buffer);
const bool startsWithPrefix = builtInNewHandlerValue.find(newDisabledValuePrefix) == 0;
if (!startsWithPrefix)
{
return ERROR_SUCCESS;
}
const std::wstring builtInNewEnabledValue = builtInNewHandlerValue.substr(newDisabledValuePrefix.length());
const LONG setStatus = RegSetValueExW(*regKeyHandle, nullptr, 0, REG_SZ, reinterpret_cast<const BYTE*>(builtInNewEnabledValue.c_str()), static_cast<DWORD>((builtInNewEnabledValue.length() + 1)) * sizeof(wchar_t));
if (setStatus != ERROR_SUCCESS)
{
throw std::runtime_error("Failed to update/restore the New context menu shell extension in the registry.");
}
}
catch (const std::exception& e)
{
std::string errorMessage{ "Exception thrown while trying to restore built-in New: " };
errorMessage += e.what();
Logger::error(errorMessage);
er = ERROR_INSTALL_FAILURE;
}
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
return WcaFinalize(er);
}
UINT __stdcall TerminateProcessesCA(MSIHANDLE hInstall)
{
HRESULT hr = S_OK;

View File

@@ -28,3 +28,4 @@ EXPORTS
UninstallCommandNotFoundModuleCA
UpgradeCommandNotFoundModuleCA
UnsetAdvancedPasteAPIKeyCA
RestoreBuiltInNewContextMenuCA

View File

@@ -298,34 +298,5 @@ namespace Hosts.Tests
var hidden = fileSystem.FileInfo.New(service.HostsFilePath).Attributes.HasFlag(FileAttributes.Hidden);
Assert.IsTrue(hidden);
}
[TestMethod]
public async Task NoLeadingSpaces_Disabled_RemovesIndent()
{
var content =
@"10.1.1.1 host host.local # comment
10.1.1.2 host2 host2.local # another comment
";
var expected =
@"10.1.1.1 host host.local # comment
10.1.1.2 host2 host2.local # another comment
# 10.1.1.30 host30 host30.local # new entry
";
var fs = new CustomMockFileSystem();
var settings = new Mock<IUserSettings>();
settings.Setup(s => s.NoLeadingSpaces).Returns(true);
var svc = new HostsService(fs, settings.Object, _elevationHelper.Object);
fs.AddFile(svc.HostsFilePath, new MockFileData(content));
var data = await svc.ReadAsync();
var entries = data.Entries.ToList();
entries.Add(new Entry(0, "10.1.1.30", "host30 host30.local", "new entry", false));
await svc.WriteAsync(data.AdditionalLines, entries);
var result = fs.GetFile(svc.HostsFilePath);
Assert.AreEqual(expected, result.TextContents);
}
}
}

View File

@@ -26,8 +26,6 @@ namespace Hosts.Settings
private bool _loopbackDuplicates;
public bool NoLeadingSpaces { get; private set; }
public bool LoopbackDuplicates
{
get => _loopbackDuplicates;
@@ -90,7 +88,6 @@ namespace Hosts.Settings
AdditionalLinesPosition = (HostsAdditionalLinesPosition)settings.Properties.AdditionalLinesPosition;
Encoding = (HostsEncoding)settings.Properties.Encoding;
LoopbackDuplicates = settings.Properties.LoopbackDuplicates;
NoLeadingSpaces = settings.Properties.NoLeadingSpaces;
}
retry = false;

View File

@@ -157,7 +157,7 @@ namespace HostsUILib.Helpers
{
lineBuilder.Append('#').Append(' ');
}
else if (anyDisabled && !_userSettings.NoLeadingSpaces)
else if (anyDisabled)
{
lineBuilder.Append(' ').Append(' ');
}

View File

@@ -19,7 +19,5 @@ namespace HostsUILib.Settings
event EventHandler LoopbackDuplicatesChanged;
public delegate void OpenSettingsFunction();
public bool NoLeadingSpaces { get; }
}
}

View File

@@ -1,66 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Runtime.InteropServices;
namespace Microsoft.CmdPal.Common.Helpers;
/// <summary>
/// Provides utility methods for building diagnostic and error messages.
/// </summary>
public static class DiagnosticsHelper
{
/// <summary>
/// Builds a comprehensive exception message with timestamp and detailed diagnostic information.
/// </summary>
/// <param name="exception">The exception that occurred.</param>
/// <param name="extensionHint">A hint about which extension caused the exception to help with debugging.</param>
/// <returns>A string containing the exception details, timestamp, and source information for diagnostic purposes.</returns>
public static string BuildExceptionMessage(Exception exception, string? extensionHint)
{
var locationHint = string.IsNullOrWhiteSpace(extensionHint) ? "application" : $"'{extensionHint}' extension";
// let's try to get a message from the exception or inferred it from the HRESULT
// to show at least something
var message = exception.Message;
if (string.IsNullOrWhiteSpace(message))
{
var temp = Marshal.GetExceptionForHR(exception.HResult)?.Message;
if (!string.IsNullOrWhiteSpace(temp))
{
message = temp + $" (inferred from HRESULT 0x{exception.HResult:X8})";
}
}
if (string.IsNullOrWhiteSpace(message))
{
message = "[No message available]";
}
// note: keep date time kind and format consistent with the log
return $"""
============================================================
😢 An unexpected error occurred in the {locationHint}.
Summary:
Message: {message}
Type: {exception.GetType().FullName}
Source: {exception.Source ?? "N/A"}
Time: {DateTimeOffset.Now:yyyy-MM-dd HH:mm:ss.fffffff}
HRESULT: 0x{exception.HResult:X8} ({exception.HResult})
Stack Trace:
{exception.StackTrace ?? "[No stack trace available]"}
------------------ Full Exception Details ------------------
{exception}
If you need further assistance, please include this information in your support request.
Before sending, take a quick look to make sure it doesn't contain any personal or sensitive information.
============================================================
""";
}
}

View File

@@ -24,7 +24,7 @@ public partial class ExtensionHostInstance
/// <param name="message">The log message to send</param>
public void LogMessage(ILogMessage message)
{
if (Host is not null)
if (Host != null)
{
_ = Task.Run(async () =>
{
@@ -47,7 +47,7 @@ public partial class ExtensionHostInstance
public void ShowStatus(IStatusMessage message, StatusContext context)
{
if (Host is not null)
if (Host != null)
{
_ = Task.Run(async () =>
{
@@ -64,7 +64,7 @@ public partial class ExtensionHostInstance
public void HideStatus(IStatusMessage message)
{
if (Host is not null)
if (Host != null)
{
_ = Task.Run(async () =>
{

View File

@@ -36,7 +36,7 @@ public abstract partial class AppExtensionHost : IExtensionHost
public IAsyncAction HideStatus(IStatusMessage? message)
{
if (message is null)
if (message == null)
{
return Task.CompletedTask.AsAsyncAction();
}
@@ -55,7 +55,7 @@ public abstract partial class AppExtensionHost : IExtensionHost
public IAsyncAction LogMessage(ILogMessage? message)
{
if (message is null)
if (message == null)
{
return Task.CompletedTask.AsAsyncAction();
}
@@ -80,7 +80,7 @@ public abstract partial class AppExtensionHost : IExtensionHost
try
{
var vm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault();
if (vm is not null)
if (vm != null)
{
StatusMessages.Remove(vm);
}
@@ -113,7 +113,7 @@ public abstract partial class AppExtensionHost : IExtensionHost
{
// If this message is already in the list of messages, just bring it to the top
var oldVm = StatusMessages.Where(messageVM => messageVM.Model.Unsafe == message).FirstOrDefault();
if (oldVm is not null)
if (oldVm != null)
{
Task.Factory.StartNew(
() =>
@@ -142,7 +142,7 @@ public abstract partial class AppExtensionHost : IExtensionHost
public IAsyncAction ShowStatus(IStatusMessage? message, StatusContext context)
{
if (message is null)
if (message == null)
{
return Task.CompletedTask.AsAsyncAction();
}

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.Core.ViewModels.Messages;
@@ -34,13 +35,13 @@ public partial class CommandBarViewModel : ObservableObject,
[NotifyPropertyChangedFor(nameof(HasPrimaryCommand))]
public partial CommandItemViewModel? PrimaryCommand { get; set; }
public bool HasPrimaryCommand => PrimaryCommand is not null && PrimaryCommand.ShouldBeVisible;
public bool HasPrimaryCommand => PrimaryCommand != null && PrimaryCommand.ShouldBeVisible;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasSecondaryCommand))]
public partial CommandItemViewModel? SecondaryCommand { get; set; }
public bool HasSecondaryCommand => SecondaryCommand is not null;
public bool HasSecondaryCommand => SecondaryCommand != null;
[ObservableProperty]
public partial bool ShouldShowContextMenu { get; set; } = false;
@@ -57,14 +58,14 @@ public partial class CommandBarViewModel : ObservableObject,
private void SetSelectedItem(ICommandBarContext? value)
{
if (value is not null)
if (value != null)
{
PrimaryCommand = value.PrimaryCommand;
value.PropertyChanged += SelectedItemPropertyChanged;
}
else
{
if (SelectedItem is not null)
if (SelectedItem != null)
{
SelectedItem.PropertyChanged -= SelectedItemPropertyChanged;
}
@@ -87,7 +88,7 @@ public partial class CommandBarViewModel : ObservableObject,
private void UpdateContextItems()
{
if (SelectedItem is null)
if (SelectedItem == null)
{
SecondaryCommand = null;
ShouldShowContextMenu = false;
@@ -126,13 +127,13 @@ public partial class CommandBarViewModel : ObservableObject,
public ContextKeybindingResult CheckKeybinding(bool ctrl, bool alt, bool shift, bool win, VirtualKey key)
{
var keybindings = SelectedItem?.Keybindings();
if (keybindings is not null)
if (keybindings != null)
{
// Does the pressed key match any of the keybindings?
var pressedKeyChord = KeyChordHelpers.FromModifiers(ctrl, alt, shift, win, key, 0);
if (keybindings.TryGetValue(pressedKeyChord, out var matchedItem))
{
return matchedItem is not null ? PerformCommand(matchedItem) : ContextKeybindingResult.Unhandled;
return matchedItem != null ? PerformCommand(matchedItem) : ContextKeybindingResult.Unhandled;
}
}
@@ -141,7 +142,7 @@ public partial class CommandBarViewModel : ObservableObject,
private ContextKeybindingResult PerformCommand(CommandItemViewModel? command)
{
if (command is null)
if (command == null)
{
return ContextKeybindingResult.Unhandled;
}

View File

@@ -20,7 +20,7 @@ public partial class CommandContextItemViewModel(ICommandContextItem contextItem
public KeyChord? RequestedShortcut { get; private set; }
public bool HasRequestedShortcut => RequestedShortcut is not null && (RequestedShortcut.Value != nullKeyChord);
public bool HasRequestedShortcut => RequestedShortcut != null && (RequestedShortcut.Value != nullKeyChord);
public override void InitializeProperties()
{
@@ -32,7 +32,7 @@ public partial class CommandContextItemViewModel(ICommandContextItem contextItem
base.InitializeProperties();
var contextItem = Model.Unsafe;
if (contextItem is null)
if (contextItem == null)
{
return; // throw?
}

View File

@@ -68,7 +68,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
{
get
{
List<IContextItemViewModel> l = _defaultCommandContextItem is null ?
List<IContextItemViewModel> l = _defaultCommandContextItem == null ?
new() :
[_defaultCommandContextItem];
@@ -100,7 +100,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
}
var model = _commandItemModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -128,7 +128,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
}
var model = _commandItemModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -136,7 +136,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
Command.InitializeProperties();
var listIcon = model.Icon;
if (listIcon is not null)
if (listIcon != null)
{
_listItemIcon = new(listIcon);
_listItemIcon.InitializeProperties();
@@ -172,13 +172,13 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
}
var model = _commandItemModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}
var more = model.MoreCommands;
if (more is not null)
if (more != null)
{
MoreCommands = more
.Select(item =>
@@ -300,7 +300,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
protected virtual void FetchProperty(string propertyName)
{
var model = this._commandItemModel.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -308,7 +308,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
switch (propertyName)
{
case nameof(Command):
if (Command is not null)
if (Command != null)
{
Command.PropertyChanged -= Command_PropertyChanged;
}
@@ -339,7 +339,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
case nameof(model.MoreCommands):
var more = model.MoreCommands;
if (more is not null)
if (more != null)
{
var newContextMenu = more
.Select(item =>
@@ -394,7 +394,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
// Extensions based on Command Palette SDK < 0.3 CommandItem class won't notify when Title changes because Command
// or Command.Name change. This is a workaround to ensure that the Title is always up-to-date for extensions with old SDK.
var model = _commandItemModel.Unsafe;
if (model is not null)
if (model != null)
{
_itemTitle = model.Title;
}
@@ -430,7 +430,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
Command.SafeCleanup();
var model = _commandItemModel.Unsafe;
if (model is not null)
if (model != null)
{
model.PropChanged -= Model_PropChanged;
}

View File

@@ -44,7 +44,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel
}
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -67,13 +67,13 @@ public partial class CommandViewModel : ExtensionObjectViewModel
}
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
var ico = model.Icon;
if (ico is not null)
if (ico != null)
{
Icon = new(ico);
Icon.InitializeProperties();
@@ -98,7 +98,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel
protected void FetchProperty(string propertyName)
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -125,7 +125,7 @@ public partial class CommandViewModel : ExtensionObjectViewModel
Icon = new(null); // necessary?
var model = Model.Unsafe;
if (model is not null)
if (model != null)
{
model.PropChanged -= Model_PropChanged;
}

View File

@@ -25,7 +25,7 @@ public partial class ConfirmResultViewModel(IConfirmationArgs _args, WeakReferen
public override void InitializeProperties()
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -28,7 +28,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
public DetailsViewModel? Details { get; private set; }
[MemberNotNullWhen(true, nameof(Details))]
public bool HasDetails => Details is not null;
public bool HasDetails => Details != null;
/////// ICommandBarContext ///////
public IEnumerable<IContextItemViewModel> MoreCommands => Commands.Skip(1);
@@ -67,7 +67,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
foreach (var item in newItems)
{
var viewModel = ViewModelFromContent(item, PageContext);
if (viewModel is not null)
if (viewModel != null)
{
viewModel.InitializeProperties();
newContent.Add(viewModel);
@@ -104,7 +104,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
base.InitializeProperties();
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -133,7 +133,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
});
var extensionDetails = model.Details;
if (extensionDetails is not null)
if (extensionDetails != null)
{
Details = new(extensionDetails, PageContext);
Details.InitializeProperties();
@@ -156,7 +156,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
base.FetchProperty(propertyName);
var model = this._model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -166,7 +166,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
case nameof(Commands):
var more = model.Commands;
if (more is not null)
if (more != null)
{
var newContextMenu = more
.ToList()
@@ -216,7 +216,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
break;
case nameof(Details):
var extensionDetails = model.Details;
Details = extensionDetails is not null ? new(extensionDetails, PageContext) : null;
Details = extensionDetails != null ? new(extensionDetails, PageContext) : null;
UpdateDetails();
break;
}
@@ -248,7 +248,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
[RelayCommand]
private void InvokePrimaryCommand(ContentPageViewModel page)
{
if (PrimaryCommand is not null)
if (PrimaryCommand != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(PrimaryCommand.Command.Model, PrimaryCommand.Model));
}
@@ -258,7 +258,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
[RelayCommand]
private void InvokeSecondaryCommand(ContentPageViewModel page)
{
if (SecondaryCommand is not null)
if (SecondaryCommand != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(SecondaryCommand.Command.Model, SecondaryCommand.Model));
}
@@ -285,7 +285,7 @@ public abstract partial class ContentPageViewModel : PageViewModel, ICommandBarC
Content.Clear();
var model = _model.Unsafe;
if (model is not null)
if (model != null)
{
model.ItemsChanged -= Model_ItemsChanged;
}

View File

@@ -8,6 +8,7 @@ using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.Core.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.Diagnostics.Utilities;
using Windows.System;
namespace Microsoft.CmdPal.Core.ViewModels;
@@ -50,7 +51,7 @@ public partial class ContextMenuViewModel : ObservableObject,
public void UpdateContextItems()
{
if (SelectedItem is not null)
if (SelectedItem != null)
{
if (SelectedItem.MoreCommands.Count() > 1)
{
@@ -67,14 +68,14 @@ public partial class ContextMenuViewModel : ObservableObject,
return;
}
if (SelectedItem is null)
if (SelectedItem == null)
{
return;
}
_lastSearchText = searchText;
if (CurrentContextMenu is null)
if (CurrentContextMenu == null)
{
ListHelpers.InPlaceUpdateList(FilteredItems, []);
return;
@@ -123,7 +124,7 @@ public partial class ContextMenuViewModel : ObservableObject,
/// that have a shortcut key set.</returns>
public Dictionary<KeyChord, CommandContextItemViewModel> Keybindings()
{
if (CurrentContextMenu is null)
if (CurrentContextMenu == null)
{
return [];
}
@@ -139,7 +140,7 @@ public partial class ContextMenuViewModel : ObservableObject,
public ContextKeybindingResult? CheckKeybinding(bool ctrl, bool alt, bool shift, bool win, VirtualKey key)
{
var keybindings = Keybindings();
if (keybindings is not null)
if (keybindings != null)
{
// Does the pressed key match any of the keybindings?
var pressedKeyChord = KeyChordHelpers.FromModifiers(ctrl, alt, shift, win, key, 0);
@@ -189,7 +190,7 @@ public partial class ContextMenuViewModel : ObservableObject,
OnPropertyChanging(nameof(CurrentContextMenu));
OnPropertyChanged(nameof(CurrentContextMenu));
if (CurrentContextMenu is not null)
if (CurrentContextMenu != null)
{
ListHelpers.InPlaceUpdateList(FilteredItems, [.. CurrentContextMenu!]);
}
@@ -197,7 +198,7 @@ public partial class ContextMenuViewModel : ObservableObject,
public ContextKeybindingResult InvokeCommand(CommandItemViewModel? command)
{
if (command is null)
if (command == null)
{
return ContextKeybindingResult.Unhandled;
}

View File

@@ -22,7 +22,7 @@ public partial class DetailsCommandsViewModel(
{
base.InitializeProperties();
var model = _dataModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -16,7 +16,7 @@ public abstract partial class DetailsElementViewModel(IDetailsElement _detailsEl
public override void InitializeProperties()
{
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -18,7 +18,7 @@ public partial class DetailsLinkViewModel(
public Uri? Link { get; private set; }
public bool IsLink => Link is not null;
public bool IsLink => Link != null;
public bool IsText => !IsLink;
@@ -26,14 +26,14 @@ public partial class DetailsLinkViewModel(
{
base.InitializeProperties();
var model = _dataModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}
Text = model.Text ?? string.Empty;
Link = model.Link;
if (string.IsNullOrEmpty(Text) && Link is not null)
if (string.IsNullOrEmpty(Text) && Link != null)
{
Text = Link.ToString();
}

View File

@@ -22,7 +22,7 @@ public partial class DetailsTagsViewModel(
{
base.InitializeProperties();
var model = _dataModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -26,7 +26,7 @@ public partial class DetailsViewModel(IDetails _details, WeakReference<IPageCont
public override void InitializeProperties()
{
var model = _detailsModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -41,7 +41,7 @@ public partial class DetailsViewModel(IDetails _details, WeakReference<IPageCont
UpdateProperty(nameof(HeroImage));
var meta = model.Metadata;
if (meta is not null)
if (meta != null)
{
foreach (var element in meta)
{
@@ -53,7 +53,7 @@ public partial class DetailsViewModel(IDetails _details, WeakReference<IPageCont
IDetailsTags => new DetailsTagsViewModel(element, this.PageContext),
_ => null,
};
if (vm is not null)
if (vm != null)
{
vm.InitializeProperties();
Metadata.Add(vm);

View File

@@ -16,7 +16,7 @@ public partial class IconDataViewModel : ObservableObject, IIconData
// If the extension previously gave us a Data, then died, the data will
// throw if we actually try to read it, but the pointer itself won't be
// null, so this is relatively safe.
public bool HasIcon => !string.IsNullOrEmpty(Icon) || Data.Unsafe is not null;
public bool HasIcon => !string.IsNullOrEmpty(Icon) || Data.Unsafe != null;
// Locally cached properties from IIconData.
public string Icon { get; private set; } = string.Empty;
@@ -36,7 +36,7 @@ public partial class IconDataViewModel : ObservableObject, IIconData
public void InitializeProperties()
{
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -26,7 +26,7 @@ public partial class IconInfoViewModel : ObservableObject, IIconInfo
public bool HasIcon(bool light) => IconForTheme(light).HasIcon;
public bool IsSet => _model.Unsafe is not null;
public bool IsSet => _model.Unsafe != null;
IIconData? IIconInfo.Dark => Dark;
@@ -43,7 +43,7 @@ public partial class IconInfoViewModel : ObservableObject, IIconInfo
public void InitializeProperties()
{
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -27,7 +27,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
public DetailsViewModel? Details { get; private set; }
[MemberNotNullWhen(true, nameof(Details))]
public bool HasDetails => Details is not null;
public bool HasDetails => Details != null;
public override void InitializeProperties()
{
@@ -40,7 +40,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
base.InitializeProperties();
var li = Model.Unsafe;
if (li is null)
if (li == null)
{
return; // throw?
}
@@ -50,7 +50,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
TextToSuggest = li.TextToSuggest;
Section = li.Section ?? string.Empty;
var extensionDetails = li.Details;
if (extensionDetails is not null)
if (extensionDetails != null)
{
Details = new(extensionDetails, PageContext);
Details.InitializeProperties();
@@ -67,7 +67,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
base.FetchProperty(propertyName);
var model = this.Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -85,7 +85,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
break;
case nameof(Details):
var extensionDetails = model.Details;
Details = extensionDetails is not null ? new(extensionDetails, PageContext) : null;
Details = extensionDetails != null ? new(extensionDetails, PageContext) : null;
Details?.InitializeProperties();
UpdateProperty(nameof(Details));
UpdateProperty(nameof(HasDetails));
@@ -136,7 +136,7 @@ public partial class ListItemViewModel(IListItem model, WeakReference<IPageConte
Details?.SafeCleanup();
var model = Model.Unsafe;
if (model is not null)
if (model != null)
{
// We don't need to revoke the PropChanged event handler here,
// because we are just overriding CommandItem's FetchProperty and

View File

@@ -298,11 +298,11 @@ public partial class ListViewModel : PageViewModel, IDisposable
[RelayCommand]
private void InvokeItem(ListItemViewModel? item)
{
if (item is not null)
if (item != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item.Command.Model, item.Model));
}
else if (ShowEmptyContent && EmptyContent.PrimaryCommand?.Model.Unsafe is not null)
else if (ShowEmptyContent && EmptyContent.PrimaryCommand?.Model.Unsafe != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(
EmptyContent.PrimaryCommand.Command.Model,
@@ -314,14 +314,14 @@ public partial class ListViewModel : PageViewModel, IDisposable
[RelayCommand]
private void InvokeSecondaryCommand(ListItemViewModel? item)
{
if (item is not null)
if (item != null)
{
if (item.SecondaryCommand is not null)
if (item.SecondaryCommand != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item.SecondaryCommand.Command.Model, item.Model));
}
}
else if (ShowEmptyContent && EmptyContent.SecondaryCommand?.Model.Unsafe is not null)
else if (ShowEmptyContent && EmptyContent.SecondaryCommand?.Model.Unsafe != null)
{
WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(
EmptyContent.SecondaryCommand.Command.Model,
@@ -332,12 +332,12 @@ public partial class ListViewModel : PageViewModel, IDisposable
[RelayCommand]
private void UpdateSelectedItem(ListItemViewModel? item)
{
if (_lastSelectedItem is not null)
if (_lastSelectedItem != null)
{
_lastSelectedItem.PropertyChanged -= SelectedItemPropertyChanged;
}
if (item is not null)
if (item != null)
{
SetSelectedItem(item);
}
@@ -383,7 +383,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
private void SelectedItemPropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
var item = _lastSelectedItem;
if (item is null)
if (item == null)
{
return;
}
@@ -438,7 +438,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
base.InitializeProperties();
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -465,7 +465,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
public void LoadMoreIfNeeded()
{
var model = this._model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -509,7 +509,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
base.FetchProperty(propertyName);
var model = this._model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -540,7 +540,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
private void UpdateEmptyContent()
{
UpdateProperty(nameof(ShowEmptyContent));
if (!ShowEmptyContent || EmptyContent.Model.Unsafe is null)
if (!ShowEmptyContent || EmptyContent.Model.Unsafe == null)
{
return;
}
@@ -588,7 +588,7 @@ public partial class ListViewModel : PageViewModel, IDisposable
}
var model = _model.Unsafe;
if (model is not null)
if (model != null)
{
model.ItemsChanged -= Model_ItemsChanged;
}

View File

@@ -22,7 +22,7 @@ public partial class LogMessageViewModel : ExtensionObjectViewModel
public override void InitializeProperties()
{
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}

View File

@@ -5,7 +5,6 @@
using System.Collections.ObjectModel;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using Microsoft.CmdPal.Common.Helpers;
using Microsoft.CmdPal.Core.ViewModels.Models;
using Microsoft.CommandPalette.Extensions;
@@ -46,7 +45,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
[ObservableProperty]
public partial AppExtensionHost ExtensionHost { get; private set; }
public bool HasStatusMessage => MostRecentStatusMessage is not null;
public bool HasStatusMessage => MostRecentStatusMessage != null;
[ObservableProperty]
[NotifyPropertyChangedFor(nameof(HasStatusMessage))]
@@ -133,7 +132,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
public override void InitializeProperties()
{
var page = _pageModel.Unsafe;
if (page is null)
if (page == null)
{
return; // throw?
}
@@ -178,7 +177,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
protected virtual void FetchProperty(string propertyName)
{
var model = this._pageModel.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -224,10 +223,9 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
extensionHint ??= ExtensionHost.GetExtensionDisplayName() ?? Title;
Task.Factory.StartNew(
() =>
{
var message = DiagnosticsHelper.BuildExceptionMessage(ex, extensionHint);
ErrorMessage += message;
},
{
ErrorMessage += $"A bug occurred in {$"the \"{extensionHint}\"" ?? "an unknown's"} extension's code:\n{ex.Message}\n{ex.Source}\n{ex.StackTrace}\n\n";
},
CancellationToken.None,
TaskCreationOptions.None,
Scheduler);
@@ -242,7 +240,7 @@ public partial class PageViewModel : ExtensionObjectViewModel, IPageContext
ExtensionHost.StatusMessages.CollectionChanged -= StatusMessages_CollectionChanged;
var model = _pageModel.Unsafe;
if (model is not null)
if (model != null)
{
model.PropChanged -= Model_PropChanged;
}

View File

@@ -24,7 +24,7 @@ public partial class ProgressViewModel : ExtensionObjectViewModel
public override void InitializeProperties()
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -50,7 +50,7 @@ public partial class ProgressViewModel : ExtensionObjectViewModel
protected virtual void FetchProperty(string propertyName)
{
var model = this.Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}

View File

@@ -120,7 +120,7 @@ public partial class ShellViewModel : ObservableObject,
////LoadedState = ViewModelLoadedState.Loading;
if (!viewModel.IsInitialized
&& viewModel.InitializeCommand is not null)
&& viewModel.InitializeCommand != null)
{
_ = Task.Run(async () =>
{
@@ -185,7 +185,7 @@ public partial class ShellViewModel : ObservableObject,
private void PerformCommand(PerformCommandMessage message)
{
var command = message.Command.Unsafe;
if (command is null)
if (command == null)
{
return;
}
@@ -205,7 +205,7 @@ public partial class ShellViewModel : ObservableObject,
// Construct our ViewModel of the appropriate type and pass it the UI Thread context.
var pageViewModel = _pageViewModelFactory.TryCreatePageViewModel(page, _isNested, host);
if (pageViewModel is null)
if (pageViewModel == null)
{
Logger.LogError($"Failed to create ViewModel for page {page.GetType().Name}");
throw new NotSupportedException();
@@ -240,7 +240,7 @@ public partial class ShellViewModel : ObservableObject,
// TODO GH #525 This needs more better locking.
lock (_invokeLock)
{
if (_handleInvokeTask is not null)
if (_handleInvokeTask != null)
{
// do nothing - a command is already doing a thing
}
@@ -280,7 +280,7 @@ public partial class ShellViewModel : ObservableObject,
private void UnsafeHandleCommandResult(ICommandResult? result)
{
if (result is null)
if (result == null)
{
// No result, nothing to do.
return;

View File

@@ -17,7 +17,7 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel
public ProgressViewModel? Progress { get; private set; }
public bool HasProgress => Progress is not null;
public bool HasProgress => Progress != null;
public StatusMessageViewModel(IStatusMessage message, WeakReference<IPageContext> context)
: base(context)
@@ -28,7 +28,7 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel
public override void InitializeProperties()
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -36,7 +36,7 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel
Message = model.Message;
State = model.State;
var modelProgress = model.Progress;
if (modelProgress is not null)
if (modelProgress != null)
{
Progress = new(modelProgress, this.PageContext);
Progress.InitializeProperties();
@@ -61,7 +61,7 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel
protected virtual void FetchProperty(string propertyName)
{
var model = this.Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -76,7 +76,7 @@ public partial class StatusMessageViewModel : ExtensionObjectViewModel
break;
case nameof(Progress):
var modelProgress = model.Progress;
if (modelProgress is not null)
if (modelProgress != null)
{
Progress = new(modelProgress, this.PageContext);
Progress.InitializeProperties();

View File

@@ -28,7 +28,7 @@ public partial class TagViewModel(ITag _tag, WeakReference<IPageContext> context
public override void InitializeProperties()
{
var model = _tagModel.Unsafe;
if (model is null)
if (model == null)
{
return;
}

View File

@@ -35,7 +35,7 @@ public partial class AliasManager : ObservableObject
try
{
var topLevelCommand = _topLevelCommandManager.LookupCommand(alias.CommandId);
if (topLevelCommand is not null)
if (topLevelCommand != null)
{
WeakReferenceMessenger.Default.Send<ClearSearchMessage>();
@@ -88,7 +88,7 @@ public partial class AliasManager : ObservableObject
}
// If we already have _this exact alias_, do nothing
if (newAlias is not null &&
if (newAlias != null &&
_aliases.TryGetValue(newAlias.SearchPrefix, out var existingAlias))
{
if (existingAlias.CommandId == commandId)
@@ -113,7 +113,7 @@ public partial class AliasManager : ObservableObject
_aliases.Remove(alias.SearchPrefix);
}
if (newAlias is not null)
if (newAlias != null)
{
AddAlias(newAlias);
}

View File

@@ -55,7 +55,7 @@ public partial class AppStateModel : ObservableObject
var loaded = JsonSerializer.Deserialize<AppStateModel>(jsonContent, JsonSerializationContext.Default.AppStateModel);
Debug.WriteLine(loaded is not null ? "Loaded settings file" : "Failed to parse");
Debug.WriteLine(loaded != null ? "Loaded settings file" : "Failed to parse");
return loaded ?? new();
}

View File

@@ -15,7 +15,7 @@ namespace Microsoft.CmdPal.UI.ViewModels;
public sealed class CommandProviderWrapper
{
public bool IsExtension => Extension is not null;
public bool IsExtension => Extension != null;
private readonly bool isValid;
@@ -188,14 +188,14 @@ public sealed class CommandProviderWrapper
return topLevelViewModel;
};
if (commands is not null)
if (commands != null)
{
TopLevelItems = commands
.Select(c => makeAndAdd(c, false))
.ToArray();
}
if (fallbacks is not null)
if (fallbacks != null)
{
FallbackItems = fallbacks
.Select(c => makeAndAdd(c, true))

View File

@@ -18,18 +18,18 @@ public partial class CommandSettingsViewModel(ICommandSettings? _unsafeSettings,
public bool Initialized { get; private set; }
public bool HasSettings =>
_model.Unsafe is not null && // We have a settings model AND
(!Initialized || SettingsPage is not null); // we weren't initialized, OR we were, and we do have a settings page
_model.Unsafe != null && // We have a settings model AND
(!Initialized || SettingsPage != null); // we weren't initialized, OR we were, and we do have a settings page
private void UnsafeInitializeProperties()
{
var model = _model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
if (model.SettingsPage is not null)
if (model.SettingsPage != null)
{
SettingsPage = new CommandPaletteContentPageViewModel(model.SettingsPage, mainThread, provider.ExtensionHost);
SettingsPage.InitializeProperties();

View File

@@ -30,7 +30,7 @@ internal sealed partial class CreatedExtensionForm : NewExtensionFormBase
public override ICommandResult SubmitForm(string inputs, string data)
{
var dataInput = JsonNode.Parse(data)?.AsObject();
if (dataInput is null)
if (dataInput == null)
{
return CommandResult.KeepOpen();
}

View File

@@ -23,7 +23,7 @@ public partial class LogMessagesPage : ListPage
private void LogMessages_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems is not null)
if (e.Action == NotifyCollectionChangedAction.Add && e.NewItems != null)
{
foreach (var item in e.NewItems)
{

View File

@@ -203,7 +203,7 @@ public partial class MainListPage : DynamicListPage,
// If we don't have any previous filter results to work with, start
// with a list of all our commands & apps.
if (_filteredItems is null)
if (_filteredItems == null)
{
_filteredItems = commands;
_filteredItemsIncludesApps = _includeApps;

View File

@@ -98,7 +98,7 @@ internal sealed partial class NewExtensionForm : NewExtensionFormBase
public override CommandResult SubmitForm(string payload)
{
var formInput = JsonNode.Parse(payload)?.AsObject();
if (formInput is null)
if (formInput == null)
{
return CommandResult.KeepOpen();
}

View File

@@ -14,7 +14,7 @@ public partial class NewExtensionPage : ContentPage
public override IContent[] GetContent()
{
return _resultForm is not null ? [_resultForm] : [_inputForm];
return _resultForm != null ? [_resultForm] : [_inputForm];
}
public NewExtensionPage()
@@ -28,13 +28,13 @@ public partial class NewExtensionPage : ContentPage
private void FormSubmitted(NewExtensionFormBase sender, NewExtensionFormBase? args)
{
if (_resultForm is not null)
if (_resultForm != null)
{
_resultForm.FormSubmitted -= FormSubmitted;
}
_resultForm = args;
if (_resultForm is not null)
if (_resultForm != null)
{
_resultForm.FormSubmitted += FormSubmitted;
}

View File

@@ -20,7 +20,7 @@ public partial class ContentMarkdownViewModel(IMarkdownContent _markdown, WeakRe
public override void InitializeProperties()
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
@@ -47,7 +47,7 @@ public partial class ContentMarkdownViewModel(IMarkdownContent _markdown, WeakRe
protected void FetchProperty(string propertyName)
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -66,7 +66,7 @@ public partial class ContentMarkdownViewModel(IMarkdownContent _markdown, WeakRe
{
base.UnsafeCleanup();
var model = Model.Unsafe;
if (model is not null)
if (model != null)
{
model.PropChanged -= Model_PropChanged;
}

View File

@@ -30,13 +30,13 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
public override void InitializeProperties()
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return;
}
var root = model.RootContent;
if (root is not null)
if (root != null)
{
RootContent = ViewModelFromContent(root, PageContext);
RootContent?.InitializeProperties();
@@ -82,7 +82,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
protected void FetchProperty(string propertyName)
{
var model = Model.Unsafe;
if (model is null)
if (model == null)
{
return; // throw?
}
@@ -91,7 +91,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
{
case nameof(RootContent):
var root = model.RootContent;
if (root is not null)
if (root != null)
{
RootContent = ViewModelFromContent(root, PageContext);
}
@@ -119,7 +119,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
foreach (var item in newItems)
{
var viewModel = ViewModelFromContent(item, PageContext);
if (viewModel is not null)
if (viewModel != null)
{
viewModel.InitializeProperties();
newContent.Add(viewModel);
@@ -153,7 +153,7 @@ public partial class ContentTreeViewModel(ITreeContent _tree, WeakReference<IPag
Children.Clear();
var model = Model.Unsafe;
if (model is not null)
if (model != null)
{
model.PropChanged -= Model_PropChanged;
model.ItemsChanged -= Model_ItemsChanged;

View File

@@ -29,7 +29,7 @@ public partial class HotkeyManager : ObservableObject
}
}
_commandHotkeys.RemoveAll(item => item.Hotkey is null);
_commandHotkeys.RemoveAll(item => item.Hotkey == null);
foreach (var item in _commandHotkeys)
{

View File

@@ -90,7 +90,7 @@ public partial class ExtensionService : IExtensionService, IDisposable
}).Result;
var isExtension = isCmdPalExtensionResult.IsExtension;
var extension = isCmdPalExtensionResult.Extension;
if (isExtension && extension is not null)
if (isExtension && extension != null)
{
CommandPaletteHost.Instance.DebugLog($"Installed new extension app {extension.DisplayName}");
@@ -152,7 +152,7 @@ public partial class ExtensionService : IExtensionService, IDisposable
{
var (cmdPalProvider, classId) = await GetCmdPalExtensionPropertiesAsync(extension);
return new(cmdPalProvider is not null && classId.Count != 0, extension);
return new(cmdPalProvider != null && classId.Count != 0, extension);
}
}
@@ -237,7 +237,7 @@ public partial class ExtensionService : IExtensionService, IDisposable
{
var (cmdPalProvider, classIds) = await GetCmdPalExtensionPropertiesAsync(extension);
if (cmdPalProvider is null || classIds.Count == 0)
if (cmdPalProvider == null || classIds.Count == 0)
{
return [];
}
@@ -352,12 +352,12 @@ public partial class ExtensionService : IExtensionService, IDisposable
{
var propSetList = new List<string>();
var singlePropertySet = GetSubPropertySet(activationPropSet, CreateInstanceProperty);
if (singlePropertySet is not null)
if (singlePropertySet != null)
{
var classId = GetProperty(singlePropertySet, ClassIdProperty);
// If the instance has a classId as a single string, then it's only supporting a single instance.
if (classId is not null)
if (classId != null)
{
propSetList.Add(classId);
}
@@ -365,7 +365,7 @@ public partial class ExtensionService : IExtensionService, IDisposable
else
{
var propertySetArray = GetSubPropertySetArray(activationPropSet, CreateInstanceProperty);
if (propertySetArray is not null)
if (propertySetArray != null)
{
foreach (var prop in propertySetArray)
{
@@ -375,7 +375,7 @@ public partial class ExtensionService : IExtensionService, IDisposable
}
var classId = GetProperty(propertySet, ClassIdProperty);
if (classId is not null)
if (classId != null)
{
propSetList.Add(classId);
}

View File

@@ -35,7 +35,7 @@ public class ProviderSettings
public void Connect(CommandProviderWrapper wrapper)
{
ProviderId = wrapper.ProviderId;
IsBuiltin = wrapper.Extension is null;
IsBuiltin = wrapper.Extension == null;
ProviderDisplayName = wrapper.DisplayName;

View File

@@ -33,7 +33,7 @@ public partial class ProviderSettingsViewModel(
Resources.builtin_disabled_extension;
[MemberNotNullWhen(true, nameof(Extension))]
public bool IsFromExtension => _provider.Extension is not null;
public bool IsFromExtension => _provider.Extension != null;
public IExtensionWrapper? Extension => _provider.Extension;
@@ -76,7 +76,7 @@ public partial class ProviderSettingsViewModel(
{
get
{
if (_provider.Settings is null)
if (_provider.Settings == null)
{
return false;
}
@@ -100,7 +100,7 @@ public partial class ProviderSettingsViewModel(
{
get
{
if (_provider.Settings is null)
if (_provider.Settings == null)
{
return null;
}
@@ -126,7 +126,7 @@ public partial class ProviderSettingsViewModel(
{
get
{
if (field is null)
if (field == null)
{
field = BuildTopLevelViewModels();
}
@@ -149,7 +149,7 @@ public partial class ProviderSettingsViewModel(
{
get
{
if (field is null)
if (field == null)
{
field = BuildFallbackViewModels();
}
@@ -173,7 +173,7 @@ public partial class ProviderSettingsViewModel(
private void InitializeSettingsPage()
{
if (_provider.Settings is null)
if (_provider.Settings == null)
{
return;
}

View File

@@ -30,7 +30,7 @@ public partial class RecentCommandsManager : ObservableObject
// These numbers are vaguely scaled so that "VS" will make "Visual Studio" the
// match after one use.
// Usually it has a weight of 84, compared to 109 for the VS cmd prompt
if (entry.Item is not null)
if (entry.Item != null)
{
var index = entry.Index;
@@ -61,7 +61,7 @@ public partial class RecentCommandsManager : ObservableObject
var entry = History
.Where(item => item.CommandId == commandId)
.FirstOrDefault();
if (entry is null)
if (entry == null)
{
var newitem = new HistoryItem() { CommandId = commandId, Uses = 1 };
History.Insert(0, newitem);

View File

@@ -95,7 +95,7 @@ public partial class SettingsModel : ObservableObject
var loaded = JsonSerializer.Deserialize<SettingsModel>(jsonContent, JsonSerializationContext.Default.SettingsModel);
Debug.WriteLine(loaded is not null ? "Loaded settings file" : "Failed to parse");
Debug.WriteLine(loaded != null ? "Loaded settings file" : "Failed to parse");
return loaded ?? new();
}

View File

@@ -249,7 +249,7 @@ public partial class TopLevelCommandManager : ObservableObject,
_extensionCommandProviders.Clear();
}
if (extensions is not null)
if (extensions != null)
{
await StartExtensionsAndGetCommands(extensions);
}
@@ -283,7 +283,7 @@ public partial class TopLevelCommandManager : ObservableObject,
var startTasks = extensions.Select(StartExtensionWithTimeoutAsync);
// Wait for all extensions to start
var wrappers = (await Task.WhenAll(startTasks)).Where(wrapper => wrapper is not null).Select(w => w!).ToList();
var wrappers = (await Task.WhenAll(startTasks)).Where(wrapper => wrapper != null).Select(w => w!).ToList();
lock (_commandProvidersLock)
{
@@ -293,7 +293,7 @@ public partial class TopLevelCommandManager : ObservableObject,
// Load the commands from the providers in parallel
var loadTasks = wrappers.Select(LoadCommandsWithTimeoutAsync);
var commandSets = (await Task.WhenAll(loadTasks)).Where(results => results is not null).Select(r => r!).ToList();
var commandSets = (await Task.WhenAll(loadTasks)).Where(results => results != null).Select(r => r!).ToList();
lock (TopLevelCommands)
{
@@ -410,8 +410,8 @@ public partial class TopLevelCommandManager : ObservableObject,
void IPageContext.ShowException(Exception ex, string? extensionHint)
{
var message = DiagnosticsHelper.BuildExceptionMessage(ex, extensionHint ?? "TopLevelCommandManager");
CommandPaletteHost.Instance.Log(message);
var errorMessage = $"A bug occurred in {$"the \"{extensionHint}\"" ?? "an unknown's"} extension's code:\n{ex.Message}\n{ex.Source}\n{ex.StackTrace}\n\n";
CommandPaletteHost.Instance.Log(errorMessage);
}
internal bool IsProviderActive(string id)

View File

@@ -240,7 +240,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
private void FetchAliasFromAliasManager()
{
var am = _serviceProvider.GetService<AliasManager>();
if (am is not null)
if (am != null)
{
var commandAlias = am.AliasFromId(Id);
if (commandAlias is not null)
@@ -254,7 +254,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
private void UpdateHotkey()
{
var hotkey = _settings.CommandHotkeys.Where(hk => hk.CommandId == Id).FirstOrDefault();
if (hotkey is not null)
if (hotkey != null)
{
_hotkey = hotkey.Hotkey;
}
@@ -264,12 +264,12 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
{
List<Tag> tags = [];
if (Hotkey is not null)
if (Hotkey != null)
{
tags.Add(new Tag() { Text = Hotkey.ToString() });
}
if (Alias is not null)
if (Alias != null)
{
tags.Add(new Tag() { Text = Alias.SearchPrefix });
}

View File

@@ -47,8 +47,7 @@
<Flyout
x:Name="ContextMenuFlyout"
FlyoutPresenterStyle="{StaticResource ContextMenuFlyoutStyle}"
Opened="ContextMenuFlyout_Opened"
ShouldConstrainToRootBounds="False">
Opened="ContextMenuFlyout_Opened">
<cpcontrols:ContextMenu x:Name="ContextControl" />
</Flyout>

View File

@@ -10,6 +10,7 @@ using Microsoft.CmdPal.UI.Views;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Input;
using Windows.System;
namespace Microsoft.CmdPal.UI.Controls;
@@ -49,7 +50,7 @@ public sealed partial class CommandBar : UserControl,
return;
}
if (message.Element is null)
if (message.Element == null)
{
_ = DispatcherQueue.TryEnqueue(
() =>

View File

@@ -44,7 +44,7 @@ public sealed partial class ContentFormControl : UserControl
// 5% BODGY: if we set this multiple times over the lifetime of the app,
// then the second call will explode, because "CardOverrideStyles is already the child of another element".
// SO only set this once.
if (_renderer.OverrideStyles is null)
if (_renderer.OverrideStyles == null)
{
_renderer.OverrideStyles = CardOverrideStyles;
}
@@ -55,19 +55,19 @@ public sealed partial class ContentFormControl : UserControl
private void AttachViewModel(ContentFormViewModel? vm)
{
if (_viewModel is not null)
if (_viewModel != null)
{
_viewModel.PropertyChanged -= ViewModel_PropertyChanged;
}
_viewModel = vm;
if (_viewModel is not null)
if (_viewModel != null)
{
_viewModel.PropertyChanged += ViewModel_PropertyChanged;
var c = _viewModel.Card;
if (c is not null)
if (c != null)
{
DisplayCard(c);
}
@@ -76,7 +76,7 @@ public sealed partial class ContentFormControl : UserControl
private void ViewModel_PropertyChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (ViewModel is null)
if (ViewModel == null)
{
return;
}
@@ -84,7 +84,7 @@ public sealed partial class ContentFormControl : UserControl
if (e.PropertyName == nameof(ViewModel.Card))
{
var c = ViewModel.Card;
if (c is not null)
if (c != null)
{
DisplayCard(c);
}
@@ -95,7 +95,7 @@ public sealed partial class ContentFormControl : UserControl
{
_renderedCard = _renderer.RenderAdaptiveCard(result.AdaptiveCard);
ContentGrid.Children.Clear();
if (_renderedCard.FrameworkElement is not null)
if (_renderedCard.FrameworkElement != null)
{
ContentGrid.Children.Add(_renderedCard.FrameworkElement);
@@ -148,7 +148,7 @@ public sealed partial class ContentFormControl : UserControl
// Recursively check children
var result = FindFirstFocusableElement(child);
if (result is not null)
if (result != null)
{
return result;
}

View File

@@ -31,7 +31,7 @@ public sealed partial class ContextMenu : UserControl,
WeakReferenceMessenger.Default.Register<UpdateCommandBarMessage>(this);
WeakReferenceMessenger.Default.Register<TryCommandKeybindingMessage>(this);
if (ViewModel is not null)
if (ViewModel != null)
{
ViewModel.PropertyChanged += ViewModel_PropertyChanged;
}

View File

@@ -91,7 +91,7 @@ public partial class IconBox : ContentControl
{
if (d is IconBox @this)
{
if (e.NewValue is null)
if (e.NewValue == null)
{
@this.Source = null;
}
@@ -104,7 +104,7 @@ public partial class IconBox : ContentControl
var requestedTheme = @this.ActualTheme;
var eventArgs = new SourceRequestedEventArgs(e.NewValue, requestedTheme);
if (@this.SourceRequested is not null)
if (@this.SourceRequested != null)
{
await @this.SourceRequested.InvokeAsync(@this, eventArgs);
@@ -142,7 +142,7 @@ public partial class IconBox : ContentControl
iconData = requestedTheme == ElementTheme.Light ? info.Light : info.Dark;
}
if (iconData is not null &&
if (iconData != null &&
@this.Source is FontIconSource)
{
if (!string.IsNullOrEmpty(iconData.Icon) && iconData.Icon.Length <= 2)

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.CmdPal.UI;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Markup;
@@ -79,12 +80,12 @@ public sealed partial class KeyVisual : Control
private void Update()
{
if (_keyVisual is null)
if (_keyVisual == null)
{
return;
}
if (_keyVisual.Content is not null)
if (_keyVisual.Content != null)
{
if (_keyVisual.Content.GetType() == typeof(string))
{

View File

@@ -51,13 +51,13 @@ public sealed partial class SearchBar : UserControl,
//// TODO: If the Debounce timer hasn't fired, we may want to store the current Filter in the OldValue/prior VM, but we don't want that to go actually do work...
var @this = (SearchBar)d;
if (@this is not null
if (@this != null
&& e.OldValue is PageViewModel old)
{
old.PropertyChanged -= @this.Page_PropertyChanged;
}
if (@this is not null
if (@this != null
&& e.NewValue is PageViewModel page)
{
// TODO: In some cases we probably want commands to clear a filter
@@ -85,7 +85,7 @@ public sealed partial class SearchBar : UserControl,
{
this.FilterBox.Text = string.Empty;
if (CurrentPageViewModel is not null)
if (CurrentPageViewModel != null)
{
CurrentPageViewModel.Filter = string.Empty;
}
@@ -143,7 +143,7 @@ public sealed partial class SearchBar : UserControl,
FilterBox.Text = string.Empty;
// hack TODO GH #245
if (CurrentPageViewModel is not null)
if (CurrentPageViewModel != null)
{
CurrentPageViewModel.Filter = FilterBox.Text;
}
@@ -154,7 +154,7 @@ public sealed partial class SearchBar : UserControl,
else if (e.Key == VirtualKey.Back)
{
// hack TODO GH #245
if (CurrentPageViewModel is not null)
if (CurrentPageViewModel != null)
{
CurrentPageViewModel.Filter = FilterBox.Text;
}
@@ -318,7 +318,7 @@ public sealed partial class SearchBar : UserControl,
}
// Actually plumb Filtering to the view model
if (CurrentPageViewModel is not null)
if (CurrentPageViewModel != null)
{
CurrentPageViewModel.Filter = FilterBox.Text;
}

View File

@@ -39,13 +39,13 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
private static void OnAllowDisableChanged(DependencyObject d, DependencyPropertyChangedEventArgs? e)
{
var me = d as ShortcutControl;
if (me is null)
if (me == null)
{
return;
}
var description = me.c?.FindDescendant<TextBlock>();
if (description is null)
if (description == null)
{
return;
}
@@ -431,7 +431,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
private void ShortcutDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args)
{
if (lastValidSettings is not null && ComboIsValid(lastValidSettings))
if (lastValidSettings != null && ComboIsValid(lastValidSettings))
{
HotkeySettings = lastValidSettings with { };
}
@@ -458,7 +458,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
private static bool ComboIsValid(HotkeySettings? settings)
{
return settings is not null && (settings.IsValid() || settings.IsEmpty());
return settings != null && (settings.IsValid() || settings.IsEmpty());
}
public void Receive(WindowActivatedEventArgs message) => DoWindowActivated(message);
@@ -466,12 +466,12 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
private void DoWindowActivated(WindowActivatedEventArgs args)
{
args.Handled = true;
if (args.WindowActivationState != WindowActivationState.Deactivated && (hook is null || hook.GetDisposedState() == true))
if (args.WindowActivationState != WindowActivationState.Deactivated && (hook == null || hook.GetDisposedState() == true))
{
// If the PT settings window gets focussed/activated again, we enable the keyboard hook to catch the keyboard input.
hook = new HotkeySettingsControlHook(Hotkey_KeyDown, Hotkey_KeyUp, Hotkey_IsActive, FilterAccessibleKeyboardEvents);
}
else if (args.WindowActivationState == WindowActivationState.Deactivated && hook is not null && hook.GetDisposedState() == false)
else if (args.WindowActivationState == WindowActivationState.Deactivated && hook != null && hook.GetDisposedState() == false)
{
// If the PT settings window lost focus/activation, we disable the keyboard hook to allow keyboard input on other windows.
hook.Dispose();
@@ -490,7 +490,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
{
if (disposing)
{
if (hook is not null)
if (hook != null)
{
hook.Dispose();
}

View File

@@ -84,7 +84,7 @@ public partial class Tag : Control
return;
}
if (tag.ForegroundColor is not null &&
if (tag.ForegroundColor != null &&
OptionalColorBrushCacheProvider.Convert(tag.ForegroundColor.Value) is SolidColorBrush brush)
{
tag.Foreground = brush;
@@ -114,7 +114,7 @@ public partial class Tag : Control
return;
}
if (tag.BackgroundColor is not null &&
if (tag.BackgroundColor != null &&
OptionalColorBrushCacheProvider.Convert(tag.BackgroundColor.Value) is SolidColorBrush brush)
{
tag.Background = brush;

View File

@@ -34,14 +34,8 @@ public sealed partial class ContentPage : Page,
public ContentPage()
{
this.InitializeComponent();
this.Unloaded += OnUnloaded;
}
private void OnUnloaded(object sender, RoutedEventArgs e)
{
// Unhook from everything to ensure nothing can reach us
// between this point and our complete and utter destruction.
WeakReferenceMessenger.Default.UnregisterAll(this);
WeakReferenceMessenger.Default.Register<ActivateSelectedListItemMessage>(this);
WeakReferenceMessenger.Default.Register<ActivateSecondaryCommandMessage>(this);
}
protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -51,16 +45,6 @@ public sealed partial class ContentPage : Page,
ViewModel = vm;
}
if (!WeakReferenceMessenger.Default.IsRegistered<ActivateSelectedListItemMessage>(this))
{
WeakReferenceMessenger.Default.Register<ActivateSelectedListItemMessage>(this);
}
if (!WeakReferenceMessenger.Default.IsRegistered<ActivateSecondaryCommandMessage>(this))
{
WeakReferenceMessenger.Default.Register<ActivateSecondaryCommandMessage>(this);
}
base.OnNavigatedTo(e);
}

View File

@@ -15,7 +15,6 @@ using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Windows.System;
namespace Microsoft.CmdPal.UI;
@@ -25,8 +24,6 @@ public sealed partial class ListPage : Page,
IRecipient<ActivateSelectedListItemMessage>,
IRecipient<ActivateSecondaryCommandMessage>
{
private InputSource _lastInputSource;
private ListViewModel? ViewModel
{
get => (ListViewModel?)GetValue(ViewModelProperty);
@@ -42,8 +39,6 @@ public sealed partial class ListPage : Page,
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Disabled;
this.ItemsList.Loaded += ItemsList_Loaded;
this.ItemsList.PreviewKeyDown += ItemsList_PreviewKeyDown;
this.ItemsList.PointerPressed += ItemsList_PointerPressed;
}
protected override void OnNavigatedTo(NavigationEventArgs e)
@@ -79,7 +74,7 @@ public sealed partial class ListPage : Page,
WeakReferenceMessenger.Default.Unregister<ActivateSelectedListItemMessage>(this);
WeakReferenceMessenger.Default.Unregister<ActivateSecondaryCommandMessage>(this);
if (ViewModel is not null)
if (ViewModel != null)
{
ViewModel.PropertyChanged -= ViewModel_PropertyChanged;
ViewModel.ItemsUpdated -= Page_ItemsUpdated;
@@ -103,12 +98,6 @@ public sealed partial class ListPage : Page,
{
if (e.ClickedItem is ListItemViewModel item)
{
if (_lastInputSource == InputSource.Keyboard)
{
ViewModel?.InvokeItemCommand.Execute(item);
return;
}
var settings = App.Current.Services.GetService<SettingsModel>()!;
if (settings.SingleClickActivates)
{
@@ -153,13 +142,13 @@ public sealed partial class ListPage : Page,
// here, then in Page_ItemsUpdated trying to select that cached item if
// it's in the list (otherwise, clear the cache), but that seems
// aggressively BODGY for something that mostly just works today.
if (ItemsList.SelectedItem is not null)
if (ItemsList.SelectedItem != null)
{
ItemsList.ScrollIntoView(ItemsList.SelectedItem);
// Automation notification for screen readers
var listViewPeer = Microsoft.UI.Xaml.Automation.Peers.ListViewAutomationPeer.CreatePeerForElement(ItemsList);
if (listViewPeer is not null && li is not null)
if (listViewPeer != null && li != null)
{
var notificationText = li.Title;
listViewPeer.RaiseNotificationEvent(
@@ -176,7 +165,7 @@ public sealed partial class ListPage : Page,
// Find the ScrollViewer in the ListView
var listViewScrollViewer = FindScrollViewer(this.ItemsList);
if (listViewScrollViewer is not null)
if (listViewScrollViewer != null)
{
listViewScrollViewer.ViewChanged += ListViewScrollViewer_ViewChanged;
}
@@ -185,7 +174,7 @@ public sealed partial class ListPage : Page,
private void ListViewScrollViewer_ViewChanged(object? sender, ScrollViewerViewChangedEventArgs e)
{
var scrollView = sender as ScrollViewer;
if (scrollView is null)
if (scrollView == null)
{
return;
}
@@ -267,7 +256,7 @@ public sealed partial class ListPage : Page,
page.PropertyChanged += @this.ViewModel_PropertyChanged;
page.ItemsUpdated += @this.Page_ItemsUpdated;
}
else if (e.NewValue is null)
else if (e.NewValue == null)
{
Logger.LogDebug("cleared view model");
}
@@ -285,7 +274,7 @@ public sealed partial class ListPage : Page,
// ItemsList_SelectionChanged again to give us another chance to change
// the selection from null -> something. Better to just update the
// selection once, at the end of all the updating.
if (ItemsList.SelectedItem is null)
if (ItemsList.SelectedItem == null)
{
ItemsList.SelectedIndex = 0;
}
@@ -318,7 +307,7 @@ public sealed partial class ListPage : Page,
{
var child = VisualTreeHelper.GetChild(parent, i);
var result = FindScrollViewer(child);
if (result is not null)
if (result != null)
{
return result;
}
@@ -340,7 +329,7 @@ public sealed partial class ListPage : Page,
_ => (null, null),
};
if (item is null || element is null)
if (item == null || element == null)
{
return;
}
@@ -374,21 +363,4 @@ public sealed partial class ListPage : Page,
{
_ = DispatcherQueue.TryEnqueue(() => WeakReferenceMessenger.Default.Send<CloseContextMenuMessage>());
}
private void ItemsList_PointerPressed(object sender, PointerRoutedEventArgs e) => _lastInputSource = InputSource.Pointer;
private void ItemsList_PreviewKeyDown(object sender, KeyRoutedEventArgs e)
{
if (e.Key is VirtualKey.Enter or VirtualKey.Space)
{
_lastInputSource = InputSource.Keyboard;
}
}
private enum InputSource
{
None,
Keyboard,
Pointer,
}
}

View File

@@ -2,6 +2,13 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.Bookmarks;
using Microsoft.UI.Xaml.Documents;
using Microsoft.Win32;
namespace Microsoft.CmdPal.UI.Helpers;
@@ -56,7 +63,7 @@ internal static class GpoValueChecker
{
using (RegistryKey? key = rootKey.OpenSubKey(subKeyPath, false))
{
if (key is null)
if (key == null)
{
return null;
}

View File

@@ -4,6 +4,7 @@
using Microsoft.CmdPal.Core.ViewModels;
using Microsoft.CmdPal.UI.Controls;
using Microsoft.CmdPal.UI.Helpers;
namespace Microsoft.CmdPal.UI.Helpers;
@@ -18,7 +19,7 @@ public static partial class IconCacheProvider
public static async void SourceRequested(IconBox sender, SourceRequestedEventArgs args)
#pragma warning restore IDE0060 // Remove unused parameter
{
if (args.Key is null)
if (args.Key == null)
{
return;
}

View File

@@ -28,7 +28,7 @@ public sealed class IconCacheService(DispatcherQueue dispatcherQueue)
var source = IconPathConverter.IconSourceMUX(icon.Icon, false);
return source;
}
else if (icon.Data is not null)
else if (icon.Data != null)
{
try
{
@@ -49,7 +49,7 @@ public sealed class IconCacheService(DispatcherQueue dispatcherQueue)
private async Task<IconSource?> StreamToIconSource(IRandomAccessStreamReference iconStreamRef)
{
if (iconStreamRef is null)
if (iconStreamRef == null)
{
return null;
}

View File

@@ -1,157 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using ManagedCommon;
using Windows.System;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.UI.WindowsAndMessaging;
namespace Microsoft.CmdPal.UI.Helpers;
/// <summary>
/// A class that listens for local keyboard events using a Windows hook.
/// </summary>
internal sealed class LocalKeyboardListener : IDisposable
{
/// <summary>
/// Event that is raised when a key is pressed down.
/// </summary>
public event EventHandler<LocalKeyboardListenerKeyPressedEventArgs>? KeyPressed;
private bool _disposed;
private UnhookWindowsHookExSafeHandle? _handle;
private HOOKPROC? _hookProc; // Keep reference to prevent GC collection
/// <summary>
/// Registers a global keyboard hook to listen for key down events.
/// </summary>
/// <exception cref="InvalidOperationException">
/// Throws if the hook could not be registered, which may happen if the system is unable to set the hook.
/// </exception>
public void RegisterKeyboardHook()
{
ObjectDisposedException.ThrowIf(_disposed, this);
if (_handle is not null && !_handle.IsInvalid)
{
// Hook is already set
return;
}
_hookProc = KeyEventHook;
if (!SetWindowKeyHook(_hookProc))
{
throw new InvalidOperationException("Failed to register keyboard hook.");
}
}
/// <summary>
/// Attempts to register a global keyboard hook to listen for key down events.
/// </summary>
/// <returns>
/// <see langword="true"/> if the keyboard hook was successfully registered; otherwise, <see langword="false"/>.
/// </returns>
public bool Start()
{
if (_disposed)
{
return false;
}
try
{
RegisterKeyboardHook();
return true;
}
catch (Exception ex)
{
Logger.LogError("Failed to register hook", ex);
return false;
}
}
private void UnregisterKeyboardHook()
{
if (_handle is not null && !_handle.IsInvalid)
{
// The SafeHandle should automatically call UnhookWindowsHookEx when disposed
_handle.Dispose();
_handle = null;
}
_hookProc = null;
}
private bool SetWindowKeyHook(HOOKPROC hookProc)
{
if (_handle is not null && !_handle.IsInvalid)
{
// Hook is already set
return false;
}
_handle = PInvoke.SetWindowsHookEx(
WINDOWS_HOOK_ID.WH_KEYBOARD,
hookProc,
PInvoke.GetModuleHandle(null),
PInvoke.GetCurrentThreadId());
// Check if the hook was successfully set
return _handle is not null && !_handle.IsInvalid;
}
private static bool IsKeyDownHook(LPARAM lParam)
{
// The 30th bit tells what the previous key state is with 0 being the "UP" state
// For more info see https://learn.microsoft.com/windows/win32/winmsg/keyboardproc#lparam-in
return ((lParam.Value >> 30) & 1) == 0;
}
private LRESULT KeyEventHook(int nCode, WPARAM wParam, LPARAM lParam)
{
try
{
if (nCode >= 0 && IsKeyDownHook(lParam))
{
InvokeKeyDown((VirtualKey)wParam.Value);
}
}
catch (Exception ex)
{
Logger.LogError("Failed when invoking key down keyboard hook event", ex);
}
// Call next hook in chain - pass null as first parameter for current hook
return PInvoke.CallNextHookEx(null, nCode, wParam, lParam);
}
private void InvokeKeyDown(VirtualKey virtualKey)
{
if (!_disposed)
{
KeyPressed?.Invoke(this, new LocalKeyboardListenerKeyPressedEventArgs(virtualKey));
}
}
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
UnregisterKeyboardHook();
}
_disposed = true;
}
}
}

View File

@@ -1,12 +0,0 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Windows.System;
namespace Microsoft.CmdPal.UI.Helpers;
public class LocalKeyboardListenerKeyPressedEventArgs(VirtualKey key) : EventArgs
{
public VirtualKey Key { get; } = key;
}

View File

@@ -50,7 +50,7 @@ internal sealed partial class TrayIconService
{
if (showSystemTrayIcon ?? _settingsModel.ShowSystemTrayIcon)
{
if (_window is null)
if (_window == null)
{
_window = new Window();
_hwnd = new HWND(WindowNative.GetWindowHandle(_window));
@@ -64,7 +64,7 @@ internal sealed partial class TrayIconService
_originalWndProc = Marshal.GetDelegateForFunctionPointer<WNDPROC>(PInvoke.SetWindowLongPtr(_hwnd, WINDOW_LONG_PTR_INDEX.GWL_WNDPROC, hotKeyPrcPointer));
}
if (_trayIconData is null)
if (_trayIconData == null)
{
// We need to stash this handle, so it doesn't clean itself up. If
// explorer restarts, we'll come back through here, and we don't
@@ -88,7 +88,7 @@ internal sealed partial class TrayIconService
// Add the notification icon
PInvoke.Shell_NotifyIcon(NOTIFY_ICON_MESSAGE.NIM_ADD, in d);
if (_popupMenu is null)
if (_popupMenu == null)
{
_popupMenu = PInvoke.CreatePopupMenu_SafeHandle();
PInvoke.InsertMenu(_popupMenu, 0, MENU_ITEM_FLAGS.MF_BYPOSITION | MENU_ITEM_FLAGS.MF_STRING, PInvoke.WM_USER + 1, RS_.GetString("TrayMenu_Settings"));
@@ -103,7 +103,7 @@ internal sealed partial class TrayIconService
public void Destroy()
{
if (_trayIconData is not null)
if (_trayIconData != null)
{
var d = (NOTIFYICONDATAW)_trayIconData;
if (PInvoke.Shell_NotifyIcon(NOTIFY_ICON_MESSAGE.NIM_DELETE, in d))
@@ -112,19 +112,19 @@ internal sealed partial class TrayIconService
}
}
if (_popupMenu is not null)
if (_popupMenu != null)
{
_popupMenu.Close();
_popupMenu = null;
}
if (_largeIcon is not null)
if (_largeIcon != null)
{
_largeIcon.Close();
_largeIcon = null;
}
if (_window is not null)
if (_window != null)
{
_window.Close();
_window = null;
@@ -167,7 +167,7 @@ internal sealed partial class TrayIconService
// WM_WINDOWPOSCHANGING which is always received on explorer startup sequence.
case PInvoke.WM_WINDOWPOSCHANGING:
{
if (_trayIconData is null)
if (_trayIconData == null)
{
SetupTrayIcon();
}
@@ -189,7 +189,7 @@ internal sealed partial class TrayIconService
{
case PInvoke.WM_RBUTTONUP:
{
if (_popupMenu is not null)
if (_popupMenu != null)
{
PInvoke.GetCursorPos(out var cursorPos);
PInvoke.SetForegroundWindow(_hwnd);

View File

@@ -46,7 +46,7 @@ public static class TypedEventHandlerExtensions
#pragma warning restore CA1715 // Identifiers should have correct prefix
where R : DeferredEventArgs
{
if (eventHandler is null)
if (eventHandler == null)
{
return Task.CompletedTask;
}

View File

@@ -13,7 +13,7 @@ internal sealed partial class WindowHelper
UserNotificationState state;
// https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ne-shellapi-query_user_notification_state
if (Marshal.GetExceptionForHR(NativeMethods.SHQueryUserNotificationState(out state)) is null)
if (Marshal.GetExceptionForHR(NativeMethods.SHQueryUserNotificationState(out state)) == null)
{
if (state == UserNotificationState.QUNS_RUNNING_D3D_FULL_SCREEN ||
state == UserNotificationState.QUNS_BUSY ||

View File

@@ -27,7 +27,6 @@ using Microsoft.Windows.AppLifecycle;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Graphics;
using Windows.System;
using Windows.UI;
using Windows.UI.WindowManagement;
using Windows.Win32;
@@ -45,8 +44,7 @@ public sealed partial class MainWindow : WindowEx,
IRecipient<DismissMessage>,
IRecipient<ShowWindowMessage>,
IRecipient<HideWindowMessage>,
IRecipient<QuitMessage>,
IDisposable
IRecipient<QuitMessage>
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1310:Field names should not contain underscore", Justification = "Stylistically, window messages are WM_")]
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.NamingRules", "SA1306:Field names should begin with lower-case letter", Justification = "Stylistically, window messages are WM_")]
@@ -56,7 +54,6 @@ public sealed partial class MainWindow : WindowEx,
private readonly WNDPROC? _originalWndProc;
private readonly List<TopLevelHotkey> _hotkeys = [];
private readonly KeyboardListener _keyboardListener;
private readonly LocalKeyboardListener _localKeyboardListener;
private bool _ignoreHotKeyWhenFullScreen = true;
private DesktopAcrylicController? _acrylicController;
@@ -119,18 +116,6 @@ public sealed partial class MainWindow : WindowEx,
{
Summon(string.Empty);
});
_localKeyboardListener = new LocalKeyboardListener();
_localKeyboardListener.KeyPressed += LocalKeyboardListener_OnKeyPressed;
_localKeyboardListener.Start();
}
private static void LocalKeyboardListener_OnKeyPressed(object? sender, LocalKeyboardListenerKeyPressedEventArgs e)
{
if (e.Key == VirtualKey.GoBack)
{
WeakReferenceMessenger.Default.Send(new GoBackMessage());
}
}
private void SettingsChangedHandler(SettingsModel sender, object? args) => HotReloadSettings();
@@ -391,7 +376,6 @@ public sealed partial class MainWindow : WindowEx,
// WinUI bug is causing a crash on shutdown when FailFastOnErrors is set to true (#51773592).
// Workaround by turning it off before shutdown.
App.Current.DebugSettings.FailFastOnErrors = false;
_localKeyboardListener.Dispose();
DisposeAcrylic();
_keyboardListener.Stop();
@@ -400,7 +384,7 @@ public sealed partial class MainWindow : WindowEx,
private void DisposeAcrylic()
{
if (_acrylicController is not null)
if (_acrylicController != null)
{
_acrylicController.Dispose();
_acrylicController = null!;
@@ -475,7 +459,7 @@ public sealed partial class MainWindow : WindowEx,
PowerToysTelemetry.Log.WriteEvent(new CmdPalDismissedOnLostFocus());
}
if (_configurationSource is not null)
if (_configurationSource != null)
{
_configurationSource.IsInputActive = args.WindowActivationState != WindowActivationState.Deactivated;
}
@@ -483,7 +467,7 @@ public sealed partial class MainWindow : WindowEx,
public void HandleLaunch(AppActivationArguments? activatedEventArgs)
{
if (activatedEventArgs is null)
if (activatedEventArgs == null)
{
Summon(string.Empty);
return;
@@ -551,7 +535,7 @@ public sealed partial class MainWindow : WindowEx,
UnregisterHotkeys();
var globalHotkey = settings.Hotkey;
if (globalHotkey is not null)
if (globalHotkey != null)
{
if (settings.UseLowLevelGlobalHotkey)
{
@@ -581,7 +565,7 @@ public sealed partial class MainWindow : WindowEx,
{
var key = commandHotkey.Hotkey;
if (key is not null)
if (key != null)
{
if (settings.UseLowLevelGlobalHotkey)
{
@@ -698,10 +682,4 @@ public sealed partial class MainWindow : WindowEx,
return PInvoke.CallWindowProc(_originalWndProc, hwnd, uMsg, wParam, lParam);
}
public void Dispose()
{
_localKeyboardListener.Dispose();
DisposeAcrylic();
}
}

View File

@@ -47,10 +47,4 @@ DWM_CLOAKED_APP
CoWaitForMultipleObjects
INFINITE
CWMO_FLAGS
GetCurrentThreadId
SetWindowsHookEx
UnhookWindowsHookEx
CallNextHookEx
GetModuleHandle
CWMO_FLAGS

View File

@@ -24,7 +24,7 @@ public sealed partial class LoadingPage : Page
protected override void OnNavigatedTo(NavigationEventArgs e)
{
if (e.Parameter is ShellViewModel shellVM
&& shellVM.LoadCommand is not null)
&& shellVM.LoadCommand != null)
{
// This will load the built-in commands, then navigate to the main page.
// Once the mainpage loads, we'll start loading extensions.

View File

@@ -171,7 +171,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
// This gets called from the UI thread
private async Task HandleConfirmArgsOnUiThread(IConfirmationArgs? args)
{
if (args is null)
if (args == null)
{
return;
}
@@ -236,7 +236,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
public void OpenSettings()
{
if (_settingsWindow is null)
if (_settingsWindow == null)
{
_settingsWindow = new SettingsWindow();
}
@@ -324,7 +324,7 @@ public sealed partial class ShellPage : Microsoft.UI.Xaml.Controls.Page,
// command from our list of toplevel commands.
var tlcManager = App.Current.Services.GetService<TopLevelCommandManager>()!;
var topLevelCommand = tlcManager.LookupCommand(commandId);
if (topLevelCommand is not null)
if (topLevelCommand != null)
{
var command = topLevelCommand.CommandViewModel.Model.Unsafe;
var isPage = command is not IInvokableCommand;

View File

@@ -100,7 +100,7 @@ internal sealed class PowerToysRootPageService : IRootPageService
_activeExtension = extension;
var extensionWinRtObject = _activeExtension?.GetExtensionObject();
if (extensionWinRtObject is not null)
if (extensionWinRtObject != null)
{
try
{

View File

@@ -105,8 +105,6 @@ public sealed partial class SettingsWindow : WindowEx,
private void Window_Closed(object sender, WindowEventArgs args)
{
WeakReferenceMessenger.Default.Send<SettingsWindowClosedMessage>();
WeakReferenceMessenger.Default.UnregisterAll(this);
}
private void PaneToggleBtn_Click(object sender, RoutedEventArgs e)

View File

@@ -18,8 +18,8 @@ public class NumberTranslatorTests
public void Create_ThrowError_WhenCalledNullOrEmpty(string sourceCultureName, string targetCultureName)
{
// Arrange
CultureInfo sourceCulture = sourceCultureName is not null ? new CultureInfo(sourceCultureName) : null;
CultureInfo targetCulture = targetCultureName is not null ? new CultureInfo(targetCultureName) : null;
CultureInfo sourceCulture = sourceCultureName != null ? new CultureInfo(sourceCultureName) : null;
CultureInfo targetCulture = targetCultureName != null ? new CultureInfo(targetCultureName) : null;
// Act
Assert.ThrowsException<ArgumentNullException>(() => NumberTranslator.Create(sourceCulture, targetCulture));

View File

@@ -45,7 +45,7 @@ public class TimeAndDateHelperTests
var result = TimeAndDateHelper.GetCalendarWeekRule(setting);
// Assert
if (valueExpected is null)
if (valueExpected == null)
{
// falls back to system setting.
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.CalendarWeekRule, result);
@@ -72,7 +72,7 @@ public class TimeAndDateHelperTests
var result = TimeAndDateHelper.GetFirstDayOfWeek(setting);
// Assert
if (valueExpected is null)
if (valueExpected == null)
{
// falls back to system setting.
Assert.AreEqual(DateTimeFormatInfo.CurrentInfo.FirstDayOfWeek, result);

View File

@@ -2,12 +2,16 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Commands;
using Microsoft.CmdPal.Ext.Apps.Programs;
using Microsoft.CmdPal.Ext.Apps.Properties;
using Microsoft.CmdPal.Ext.Apps.State;
@@ -141,7 +145,7 @@ public sealed partial class AllAppsPage : ListPage
*/
var existingAppItem = allApps.FirstOrDefault(f => f.AppIdentifier == e.AppIdentifier);
if (existingAppItem is not null)
if (existingAppItem != null)
{
var appListItem = new AppListItem(existingAppItem, true, e.IsPinned);

View File

@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CmdPal.Ext.Apps.Programs;
@@ -65,7 +66,7 @@ public sealed partial class AppCache : IDisposable
private void UpdateUWPIconPath(Theme theme)
{
if (_packageRepository is not null)
if (_packageRepository != null)
{
foreach (UWPApplication app in _packageRepository)
{

View File

@@ -72,7 +72,7 @@ internal sealed partial class AppListItem : ListItem
try
{
var stream = await ThumbnailHelper.GetThumbnail(_app.ExePath, true);
if (stream is not null)
if (stream != null)
{
heroImage = IconInfo.FromStream(stream);
}
@@ -106,7 +106,7 @@ internal sealed partial class AppListItem : ListItem
try
{
var stream = await ThumbnailHelper.GetThumbnail(_app.ExePath);
if (stream is not null)
if (stream != null)
{
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
icon = new IconInfo(data, data);

View File

@@ -6,7 +6,9 @@ using System;
using System.Collections.Generic;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Utils;
using Microsoft.UI.Xaml.Controls;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Storage.Packaging.Appx;
using Windows.Win32.System.Com;
@@ -49,14 +51,14 @@ public static class AppxPackageHelper
{
result.Add((IntPtr)manifestApp);
}
else if (manifestApp is not null)
else if (manifestApp != null)
{
manifestApp->Release();
}
}
catch (Exception ex)
{
if (manifestApp is not null)
if (manifestApp != null)
{
manifestApp->Release();
}

View File

@@ -22,11 +22,11 @@ public class PackageManagerWrapper : IPackageManager
{
var user = WindowsIdentity.GetCurrent().User;
if (user is not null)
if (user != null)
{
var pkgs = _packageManager.FindPackagesForUser(user.Value);
return pkgs.Select(PackageWrapper.GetWrapperFromPackage).Where(package => package is not null);
return pkgs.Select(PackageWrapper.GetWrapperFromPackage).Where(package => package != null);
}
return Enumerable.Empty<IPackage>();

View File

@@ -11,7 +11,9 @@ using System.Threading.Tasks;
using System.Xml.Linq;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Utils;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.Storage.Packaging.Appx;
using Windows.Win32.System.Com;
@@ -97,7 +99,7 @@ public partial class UWP
private static string[] XmlNamespaces(string path)
{
var z = XDocument.Load(path);
if (z.Root is not null)
if (z.Root != null)
{
var namespaces = z.Root.Attributes().
Where(a => a.IsNamespaceDeclaration).

View File

@@ -308,7 +308,7 @@ public class UWPApplication : IProgram
private bool SetScaleIcons(string path, string colorscheme, bool highContrast = false)
{
var extension = Path.GetExtension(path);
if (extension is not null)
if (extension != null)
{
var end = path.Length - extension.Length;
var prefix = path.Substring(0, end);
@@ -363,7 +363,7 @@ public class UWPApplication : IProgram
private bool SetTargetSizeIcon(string path, string colorscheme, bool highContrast = false)
{
var extension = Path.GetExtension(path);
if (extension is not null)
if (extension != null)
{
var end = path.Length - extension.Length;
var prefix = path.Substring(0, end);
@@ -576,7 +576,7 @@ public class UWPApplication : IProgram
var group = new DrawingGroup();
var converted = ColorConverter.ConvertFromString(currentBackgroundColor);
if (converted is not null)
if (converted != null)
{
var color = (Color)converted;
var brush = new SolidColorBrush(color);

View File

@@ -170,7 +170,7 @@ public class Win32Program : IProgram
public bool QueryEqualsNameForRunCommands(string query)
{
if (query is not null && AppType == ApplicationType.RunCommand)
if (query != null && AppType == ApplicationType.RunCommand)
{
// Using OrdinalIgnoreCase since this is used internally
if (!query.Equals(Name, StringComparison.OrdinalIgnoreCase) && !query.Equals(ExecutableName, StringComparison.OrdinalIgnoreCase))
@@ -667,7 +667,7 @@ public class Win32Program : IProgram
var paths = new List<string>();
using (var root = Registry.LocalMachine.OpenSubKey(appPaths))
{
if (root is not null)
if (root != null)
{
paths.AddRange(GetPathsFromRegistry(root));
}
@@ -675,7 +675,7 @@ public class Win32Program : IProgram
using (var root = Registry.CurrentUser.OpenSubKey(appPaths))
{
if (root is not null)
if (root != null)
{
paths.AddRange(GetPathsFromRegistry(root));
}
@@ -700,7 +700,7 @@ public class Win32Program : IProgram
{
using (var key = root.OpenSubKey(subkey))
{
if (key is null)
if (key == null)
{
return string.Empty;
}
@@ -742,13 +742,13 @@ public class Win32Program : IProgram
public bool Equals(Win32Program? app1, Win32Program? app2)
{
if (app1 is null && app2 is null)
if (app1 == null && app2 == null)
{
return true;
}
return app1 is not null
&& app2 is not null
return app1 != null
&& app2 != null
&& (app1.Name?.ToUpperInvariant(), app1.ExecutableName?.ToUpperInvariant(), app1.FullPath?.ToUpperInvariant())
.Equals((app2.Name?.ToUpperInvariant(), app2.ExecutableName?.ToUpperInvariant(), app2.FullPath?.ToUpperInvariant()));
}
@@ -908,7 +908,7 @@ public class Win32Program : IProgram
Parallel.ForEach(paths, source =>
{
var program = GetProgramFromPath(source);
if (program is not null)
if (program != null)
{
programsList.Add(program);
}
@@ -918,7 +918,7 @@ public class Win32Program : IProgram
Parallel.ForEach(runCommandPaths, source =>
{
var program = GetRunCommandProgramFromPath(source);
if (program is not null)
if (program != null)
{
runCommandProgramsList.Add(program);
}

View File

@@ -19,7 +19,7 @@ public sealed partial class FileSystemWatcherWrapper : FileSystemWatcher, IFileS
get => this.Filters;
set
{
if (value is not null)
if (value != null)
{
foreach (var filter in value)
{

View File

@@ -10,6 +10,7 @@ using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
using ManagedCommon;
using Microsoft.CmdPal.Ext.Apps.Programs;
using Win32Program = Microsoft.CmdPal.Ext.Apps.Programs.Win32Program;
namespace Microsoft.CmdPal.Ext.Apps.Storage;
@@ -52,7 +53,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
if (!string.IsNullOrEmpty(appPath))
{
Win32Program? app = Win32Program.GetAppFromPath(appPath);
if (app is not null)
if (app != null)
{
Add(app);
_isDirty = true;
@@ -136,7 +137,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
}
// To remove the old app which has been renamed and to add the new application.
if (oldApp is not null)
if (oldApp != null)
{
if (string.IsNullOrWhiteSpace(oldApp.Name) || string.IsNullOrWhiteSpace(oldApp.ExecutableName) || string.IsNullOrWhiteSpace(oldApp.FullPath))
{
@@ -148,7 +149,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
}
}
if (newApp is not null)
if (newApp != null)
{
Add(newApp);
_isDirty = true;
@@ -176,7 +177,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
if (extension.Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
{
app = GetAppWithSameLnkFilePath(path);
if (app is null)
if (app == null)
{
// Cancelled links won't have a resolved path.
app = GetAppWithSameNameAndExecutable(Path.GetFileNameWithoutExtension(path), Path.GetFileName(path));
@@ -196,7 +197,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
Logger.LogError(ex.Message);
}
if (app is not null)
if (app != null)
{
Remove(app);
_isDirty = true;
@@ -243,7 +244,7 @@ internal sealed partial class Win32ProgramRepository : ListRepository<Programs.W
if (!Path.GetExtension(path).Equals(UrlExtension, StringComparison.OrdinalIgnoreCase) && !Path.GetExtension(path).Equals(LnkExtension, StringComparison.OrdinalIgnoreCase))
{
Programs.Win32Program? app = Programs.Win32Program.GetAppFromPath(path);
if (app is not null)
if (app != null)
{
Add(app);
_isDirty = true;

View File

@@ -2,6 +2,7 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
@@ -26,7 +27,7 @@ public static class ComFreeHelper
public static unsafe void ComObjectRelease<T>(T* comPtr)
where T : unmanaged
{
if (comPtr is not null)
if (comPtr != null)
{
((IUnknown*)comPtr)->Release();
}

View File

@@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Text;
using ManagedCommon;
using Windows.Win32;
using Windows.Win32.Foundation;
using Windows.Win32.System.Com;
@@ -35,7 +37,7 @@ public class ShellLinkHelper : IShellLinkHelper
IPersistFile* persistFile = null;
Guid iid = typeof(IPersistFile).GUID;
((IUnknown*)link)->QueryInterface(&iid, (void**)&persistFile);
if (persistFile is not null)
if (persistFile != null)
{
using var persistFileHandle = new SafeComHandle((IntPtr)persistFile);
try

View File

@@ -45,7 +45,7 @@ public class ShellLocalization
var filename = ComFreeHelper.GetStringAndFree(hr, filenamePtr);
if (filename is null)
if (filename == null)
{
return string.Empty;
}

View File

@@ -32,7 +32,7 @@ public static class ThemeHelper
// Retrieve the registry value, which is a DWORD (0 or 1)
var registryValueObj = Registry.GetValue(registryKey, registryValue, null);
if (registryValueObj is not null)
if (registryValueObj != null)
{
// 0 = Dark mode, 1 = Light mode
var isLightMode = Convert.ToBoolean((int)registryValueObj, CultureInfo.InvariantCulture);

View File

@@ -63,7 +63,7 @@ internal sealed partial class AddBookmarkForm : FormContent
public override CommandResult SubmitForm(string payload)
{
var formInput = JsonNode.Parse(payload);
if (formInput is null)
if (formInput == null)
{
return CommandResult.GoHome();
}

View File

@@ -73,7 +73,7 @@ internal sealed partial class BookmarkPlaceholderForm : FormContent
// parse the submitted JSON and then open the link
var formInput = JsonNode.Parse(payload);
var formObject = formInput?.AsObject();
if (formObject is null)
if (formObject == null)
{
return CommandResult.GoHome();
}

View File

@@ -49,7 +49,7 @@ public partial class BookmarksCommandProvider : CommandProvider
private void SaveAndUpdateCommands()
{
if (_bookmarks is not null)
if (_bookmarks != null)
{
var jsonPath = BookmarksCommandProvider.StateJsonPath();
Bookmarks.WriteToFile(jsonPath, _bookmarks);
@@ -64,12 +64,12 @@ public partial class BookmarksCommandProvider : CommandProvider
List<CommandItem> collected = [];
collected.Add(new CommandItem(_addNewCommand));
if (_bookmarks is null)
if (_bookmarks == null)
{
LoadBookmarksFromFile();
}
if (_bookmarks is not null)
if (_bookmarks != null)
{
collected.AddRange(_bookmarks.Data.Select(BookmarkToCommandItem));
}
@@ -93,7 +93,7 @@ public partial class BookmarksCommandProvider : CommandProvider
Logger.LogError(ex.Message);
}
if (_bookmarks is null)
if (_bookmarks == null)
{
_bookmarks = new();
}
@@ -134,7 +134,7 @@ public partial class BookmarksCommandProvider : CommandProvider
name: Resources.bookmarks_delete_name,
action: () =>
{
if (_bookmarks is not null)
if (_bookmarks != null)
{
ExtensionHost.LogMessage($"Deleting bookmark ({bookmark.Name},{bookmark.Bookmark})");

View File

@@ -73,7 +73,7 @@ public partial class UrlCommand : InvokableCommand
if (string.IsNullOrEmpty(args))
{
var uri = GetUri(exe);
if (uri is not null)
if (uri != null)
{
_ = Launcher.LaunchUriAsync(uri);
}
@@ -109,7 +109,7 @@ public partial class UrlCommand : InvokableCommand
// First, try to get the icon from the thumbnail helper
// This works for local files and folders
icon = await MaybeGetIconForPath(target);
if (icon is not null)
if (icon != null)
{
return icon;
}
@@ -142,7 +142,7 @@ public partial class UrlCommand : InvokableCommand
{
// If the executable exists, try to get the icon from the file
icon = await MaybeGetIconForPath(fullExePath);
if (icon is not null)
if (icon != null)
{
return icon;
}
@@ -154,7 +154,7 @@ public partial class UrlCommand : InvokableCommand
try
{
var uri = GetUri(baseString);
if (uri is not null)
if (uri != null)
{
var hostname = uri.Host;
var faviconUrl = $"{uri.Scheme}://{hostname}/favicon.ico";
@@ -176,7 +176,7 @@ public partial class UrlCommand : InvokableCommand
try
{
var stream = await ThumbnailHelper.GetThumbnail(target);
if (stream is not null)
if (stream != null)
{
var data = new IconData(RandomAccessStreamReference.CreateFromStream(stream));
return new IconInfo(data, data);

Some files were not shown because too many files have changed in this diff Show More