mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-01-12 07:16:44 +01:00
Merge pull request #42 from zadjii-msft/dev/crutkas/sdkRefactorPart3
Dev/crutkas/sdk refactor part3
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
using Microsoft.CmdPal.Extensions;
|
||||
using Microsoft.CmdPal.Extensions.Helpers;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
|
||||
namespace SpongebotExtension;
|
||||
|
||||
@@ -20,7 +21,11 @@ public class CopyTextAction : InvokableCommand
|
||||
|
||||
public override ICommandResult Invoke()
|
||||
{
|
||||
ClipboardHelper.SetText(Text);
|
||||
var dataPackage = new DataPackage();
|
||||
dataPackage.SetText(Text);
|
||||
Clipboard.SetContent(dataPackage);
|
||||
|
||||
// ClipboardHelper.SetText(Text);
|
||||
return ActionResult.KeepOpen();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class Action : BaseObservable, ICommand
|
||||
{
|
||||
|
||||
@@ -1,20 +1,42 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class ActionResult : ICommandResult
|
||||
{
|
||||
private ICommandResultArgs _Args = null;
|
||||
private CommandResultKind _Kind = CommandResultKind.Dismiss;
|
||||
public ICommandResultArgs Args => _Args;
|
||||
public CommandResultKind Kind => _Kind;
|
||||
public static ActionResult Dismiss() {
|
||||
return new ActionResult() { _Kind = CommandResultKind.Dismiss };
|
||||
// TODO: is Args needed?
|
||||
private ICommandResultArgs? _args;
|
||||
private CommandResultKind _kind = CommandResultKind.Dismiss;
|
||||
|
||||
// TODO: is Args needed?
|
||||
public ICommandResultArgs? Args => _args;
|
||||
|
||||
public CommandResultKind Kind => _kind;
|
||||
|
||||
public static ActionResult Dismiss()
|
||||
{
|
||||
return new ActionResult()
|
||||
{
|
||||
_kind = CommandResultKind.Dismiss
|
||||
};
|
||||
}
|
||||
|
||||
public static ActionResult GoHome()
|
||||
{
|
||||
return new ActionResult() { _Kind = CommandResultKind.GoHome };
|
||||
return new ActionResult()
|
||||
{
|
||||
_kind = CommandResultKind.GoHome,
|
||||
_args = null,
|
||||
};
|
||||
}
|
||||
public static ActionResult KeepOpen()
|
||||
{
|
||||
return new ActionResult() { _Kind = CommandResultKind.KeepOpen };
|
||||
return new ActionResult()
|
||||
{
|
||||
_kind = CommandResultKind.KeepOpen,
|
||||
_args = null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
// 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.Foundation;
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
@@ -11,6 +15,8 @@ public class BaseObservable : INotifyPropChanged
|
||||
protected void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
if (PropChanged != null)
|
||||
PropChanged.Invoke(this, new Microsoft.CmdPal.Extensions.PropChangedEventArgs(propertyName));
|
||||
{
|
||||
PropChanged.Invoke(this, new PropChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -25,11 +26,12 @@ public static partial class ClipboardHelper
|
||||
return _internalClipboard ?? string.Empty;
|
||||
}
|
||||
|
||||
string tool = string.Empty;
|
||||
string args = string.Empty;
|
||||
string clipboardText = string.Empty;
|
||||
ExecuteOnStaThread(() => GetTextImpl(out clipboardText));
|
||||
return clipboardText;
|
||||
var tool = string.Empty;
|
||||
var args = string.Empty;
|
||||
var clipboardText = string.Empty;
|
||||
|
||||
ExecuteOnStaThread(() => GetTextImpl(out clipboardText));
|
||||
return clipboardText;
|
||||
}
|
||||
|
||||
public static void SetText(string text)
|
||||
@@ -40,10 +42,10 @@ public static partial class ClipboardHelper
|
||||
return;
|
||||
}
|
||||
|
||||
string tool = string.Empty;
|
||||
string args = string.Empty;
|
||||
ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
|
||||
return;
|
||||
var tool = string.Empty;
|
||||
var args = string.Empty;
|
||||
ExecuteOnStaThread(() => SetClipboardData(Tuple.Create(text, CF_UNICODETEXT)));
|
||||
return;
|
||||
}
|
||||
|
||||
public static void SetRtf(string plainText, string rtfText)
|
||||
@@ -120,7 +122,7 @@ public static partial class ClipboardHelper
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
data = GlobalLock(data);
|
||||
text = Marshal.PtrToStringUni(data);
|
||||
text = Marshal.PtrToStringUni(data) ?? string.Empty;
|
||||
GlobalUnlock(data);
|
||||
return true;
|
||||
}
|
||||
@@ -134,7 +136,7 @@ public static partial class ClipboardHelper
|
||||
if (data != IntPtr.Zero)
|
||||
{
|
||||
data = GlobalLock(data);
|
||||
text = Marshal.PtrToStringAnsi(data);
|
||||
text = Marshal.PtrToStringAnsi(data) ?? string.Empty;
|
||||
GlobalUnlock(data);
|
||||
return true;
|
||||
}
|
||||
@@ -183,8 +185,8 @@ public static partial class ClipboardHelper
|
||||
|
||||
private static bool SetSingleClipboardData(string text, uint format)
|
||||
{
|
||||
IntPtr hGlobal = IntPtr.Zero;
|
||||
IntPtr data = IntPtr.Zero;
|
||||
var hGlobal = IntPtr.Zero;
|
||||
var data = IntPtr.Zero;
|
||||
|
||||
try
|
||||
{
|
||||
@@ -216,7 +218,7 @@ public static partial class ClipboardHelper
|
||||
return false;
|
||||
}
|
||||
|
||||
IntPtr dataCopy = GlobalLock(hGlobal);
|
||||
var dataCopy = GlobalLock(hGlobal);
|
||||
if (dataCopy == IntPtr.Zero)
|
||||
{
|
||||
return false;
|
||||
@@ -254,7 +256,7 @@ public static partial class ClipboardHelper
|
||||
private static void ExecuteOnStaThread(Func<bool> action)
|
||||
{
|
||||
const int RetryCount = 5;
|
||||
int tries = 0;
|
||||
var tries = 0;
|
||||
|
||||
if (Thread.CurrentThread.GetApartmentState() == ApartmentState.STA)
|
||||
{
|
||||
@@ -266,7 +268,7 @@ public static partial class ClipboardHelper
|
||||
return;
|
||||
}
|
||||
|
||||
Exception exception = null;
|
||||
Exception? exception = null;
|
||||
var thread = new Thread(() =>
|
||||
{
|
||||
try
|
||||
@@ -292,3 +294,4 @@ public static partial class ClipboardHelper
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,10 +1,17 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class CommandContextItem : ICommandContextItem
|
||||
{
|
||||
public bool IsCritical { get; set; }
|
||||
|
||||
public ICommand Command { get; set; }
|
||||
public string Tooltip { get; set; } = "";
|
||||
|
||||
public string Tooltip { get; set; } = string.Empty;
|
||||
|
||||
public CommandContextItem(ICommand command)
|
||||
{
|
||||
Command = command;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class Details : BaseObservable, IDetails
|
||||
{
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class DetailsElement : IDetailsElement
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Key { get; set; } = string.Empty;
|
||||
|
||||
public IDetailsData? Data { get; set; }
|
||||
}
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class DetailsLink : IDetailsLink
|
||||
{
|
||||
public Uri Link { get; set; }
|
||||
public string Text { get; set; }
|
||||
public Uri Link { get; set; } = new(string.Empty);
|
||||
|
||||
public string Text { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class DetailsTags : IDetailsTags
|
||||
{
|
||||
public ITag[] Tags { get; set; }
|
||||
public ITag[] Tags { get; set; } = [];
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class DynamicListPage : ListPage, IDynamicListPage
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// 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.Runtime.InteropServices;
|
||||
using Windows.Win32;
|
||||
@@ -22,7 +23,7 @@ internal sealed class ExtensionInstanceManager<T> : IClassFactory
|
||||
|
||||
// Known constant ignored by win32metadata and cswin32 projections.
|
||||
// https://github.com/microsoft/win32metadata/blob/main/generation/WinSDK/RecompiledIdlHeaders/um/processthreadsapi.h
|
||||
private static HANDLE CURRENT_THREAD_PSEUDO_HANDLE = (HANDLE)(IntPtr)(-6);
|
||||
private static readonly HANDLE CURRENT_THREAD_PSEUDO_HANDLE = (HANDLE)(IntPtr)(-6);
|
||||
|
||||
private static readonly Guid IID_IUnknown = Guid.Parse("00000000-0000-0000-C000-000000000046");
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// 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.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class Filter : IFilter
|
||||
{
|
||||
|
||||
@@ -1,13 +1,22 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class Form: IForm
|
||||
{
|
||||
public string Data { get; set; }
|
||||
public string State { get; set; }
|
||||
public string Template { get; set; }
|
||||
public string Data { get; set; } = string.Empty;
|
||||
|
||||
public string State { get; set; } = string.Empty;
|
||||
|
||||
public string Template { get; set; } = string.Empty;
|
||||
|
||||
public virtual string DataJson() => Data;
|
||||
|
||||
public virtual string StateJson() => State;
|
||||
|
||||
public virtual string TemplateJson() => Template;
|
||||
|
||||
public virtual ICommandResult SubmitForm(string payload) => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,22 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class FormPage : Action, IFormPage
|
||||
{
|
||||
private bool _Loading = false;
|
||||
private bool _loading;
|
||||
|
||||
public bool Loading { get => _Loading; set { _Loading = value; OnPropertyChanged(nameof(Loading)); } }
|
||||
public bool Loading
|
||||
{
|
||||
get => _loading;
|
||||
set
|
||||
{
|
||||
_loading = value;
|
||||
OnPropertyChanged(nameof(Loading));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual IForm[] Forms() => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class GoToPageArgs : IGoToPageArgs
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class InvokableCommand : Action, IInvokableCommand
|
||||
{
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) Microsoft Corporation.
|
||||
// Licensed under the MIT License.
|
||||
// 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.Collections.ObjectModel;
|
||||
|
||||
@@ -11,7 +12,7 @@ public class ListHelpers
|
||||
// TODO! This has side effects! This calls UpdateQuery on fallback handlers and that's async
|
||||
public static int ScoreListItem(string query, IListItem listItem)
|
||||
{
|
||||
bool isFallback = false;
|
||||
var isFallback = false;
|
||||
if (listItem.FallbackHandler != null)
|
||||
{
|
||||
isFallback = true;
|
||||
|
||||
@@ -1,32 +1,96 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class ListItem : BaseObservable, IListItem
|
||||
{
|
||||
private string _title = "";
|
||||
private string _subtitle = "";
|
||||
private string _title = string.Empty;
|
||||
private string _subtitle = string.Empty;
|
||||
private ITag[] _tags = [];
|
||||
private IDetails? _details;
|
||||
private ICommand _command;
|
||||
private ICommand? _command;
|
||||
private IContextItem[] _moreCommands = [];
|
||||
private IFallbackHandler? _fallbackHandler;
|
||||
|
||||
public string Title
|
||||
{
|
||||
get => !string.IsNullOrEmpty(this._title) ? this._title : _command.Name;
|
||||
get
|
||||
{
|
||||
if (!string.IsNullOrEmpty(this._title))
|
||||
{
|
||||
return _title;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _command?.Name ?? string.Empty;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
_title = value; OnPropertyChanged(nameof(Title));
|
||||
_title = value;
|
||||
OnPropertyChanged(nameof(Title));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public string Subtitle { get => _subtitle; set { _subtitle = value; OnPropertyChanged(nameof(Subtitle)); } }
|
||||
public ITag[] Tags { get => _tags; set { _tags = value; OnPropertyChanged(nameof(Tags)); } }
|
||||
public IDetails? Details { get => _details; set { _details = value; OnPropertyChanged(nameof(Details)); } }
|
||||
public ICommand Command { get => _command; set { _command = value; OnPropertyChanged(nameof(Command)); } }
|
||||
public IContextItem[] MoreCommands { get => _moreCommands; set { _moreCommands = value; OnPropertyChanged(nameof(MoreCommands)); } }
|
||||
public string Subtitle
|
||||
{
|
||||
get => _subtitle;
|
||||
set
|
||||
{
|
||||
_subtitle = value;
|
||||
OnPropertyChanged(nameof(Subtitle));
|
||||
}
|
||||
}
|
||||
|
||||
public IFallbackHandler? FallbackHandler { get => _fallbackHandler ?? _command as IFallbackHandler; init { _fallbackHandler = value; } }
|
||||
public ITag[] Tags
|
||||
{
|
||||
get => _tags;
|
||||
set
|
||||
{
|
||||
_tags = value;
|
||||
OnPropertyChanged(nameof(Tags));
|
||||
}
|
||||
}
|
||||
|
||||
public IDetails? Details
|
||||
{
|
||||
get => _details;
|
||||
set
|
||||
{
|
||||
_details = value;
|
||||
OnPropertyChanged(nameof(Details));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand? Command
|
||||
{
|
||||
get => _command;
|
||||
set
|
||||
{
|
||||
_command = value;
|
||||
OnPropertyChanged(nameof(Command));
|
||||
}
|
||||
}
|
||||
|
||||
public IContextItem[] MoreCommands
|
||||
{
|
||||
get => _moreCommands;
|
||||
set
|
||||
{
|
||||
_moreCommands = value;
|
||||
OnPropertyChanged(nameof(MoreCommands));
|
||||
}
|
||||
}
|
||||
|
||||
public IFallbackHandler? FallbackHandler
|
||||
{
|
||||
get => _fallbackHandler ?? _command as IFallbackHandler;
|
||||
init => _fallbackHandler = value;
|
||||
}
|
||||
|
||||
public ListItem(ICommand command)
|
||||
{
|
||||
|
||||
@@ -2,19 +2,72 @@
|
||||
|
||||
public class ListPage : Action, IListPage
|
||||
{
|
||||
private string _PlaceholderText = "";
|
||||
private string _SearchText = "";
|
||||
private bool _ShowDetails = false;
|
||||
private bool _Loading = false;
|
||||
private IFilters _Filters = null;
|
||||
private IGridProperties _GridProperties = null;
|
||||
private string _placeholderText = string.Empty;
|
||||
private string _searchText = string.Empty;
|
||||
private bool _showDetails;
|
||||
private bool _loading;
|
||||
private IFilters? _filters;
|
||||
private IGridProperties? _gridProperties;
|
||||
|
||||
public string PlaceholderText { get => _PlaceholderText; set { _PlaceholderText = value; OnPropertyChanged(nameof(PlaceholderText)); } }
|
||||
public string SearchText { get => _SearchText; set { _SearchText = value; OnPropertyChanged(nameof(SearchText)); } }
|
||||
public bool ShowDetails { get => _ShowDetails; set { _ShowDetails = value; OnPropertyChanged(nameof(ShowDetails)); } }
|
||||
public bool Loading { get => _Loading; set { _Loading = value; OnPropertyChanged(nameof(Loading)); } }
|
||||
public IFilters Filters { get => _Filters; set { _Filters = value; OnPropertyChanged(nameof(Filters)); } }
|
||||
public IGridProperties GridProperties { get => _GridProperties; set { _GridProperties = value; OnPropertyChanged(nameof(GridProperties)); } }
|
||||
public string PlaceholderText
|
||||
{
|
||||
get => _placeholderText;
|
||||
set
|
||||
{
|
||||
_placeholderText = value;
|
||||
OnPropertyChanged(nameof(PlaceholderText));
|
||||
}
|
||||
}
|
||||
|
||||
public string SearchText
|
||||
{
|
||||
get => _searchText;
|
||||
set
|
||||
{
|
||||
_searchText = value;
|
||||
OnPropertyChanged(nameof(SearchText));
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowDetails
|
||||
{
|
||||
get => _showDetails;
|
||||
set
|
||||
{
|
||||
_showDetails = value;
|
||||
OnPropertyChanged(nameof(ShowDetails));
|
||||
}
|
||||
}
|
||||
|
||||
public bool Loading
|
||||
{
|
||||
get => _loading;
|
||||
set
|
||||
{
|
||||
_loading = value;
|
||||
OnPropertyChanged(nameof(Loading));
|
||||
}
|
||||
}
|
||||
|
||||
public IFilters? Filters
|
||||
{
|
||||
get => _filters;
|
||||
set
|
||||
{
|
||||
_filters = value;
|
||||
OnPropertyChanged(nameof(Filters));
|
||||
}
|
||||
}
|
||||
|
||||
public IGridProperties? GridProperties
|
||||
{
|
||||
get => _gridProperties;
|
||||
set
|
||||
{
|
||||
_gridProperties = value;
|
||||
OnPropertyChanged(nameof(GridProperties));
|
||||
}
|
||||
}
|
||||
|
||||
public virtual ISection[] GetItems() => throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class ListSection : ISection
|
||||
{
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
// 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.
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class MarkdownPage : Action, IMarkdownPage
|
||||
{
|
||||
|
||||
@@ -38,10 +38,7 @@ public class MatchResult
|
||||
|
||||
public int RawScore
|
||||
{
|
||||
get
|
||||
{
|
||||
return _rawScore;
|
||||
}
|
||||
get => _rawScore;
|
||||
|
||||
set
|
||||
{
|
||||
@@ -53,7 +50,7 @@ public class MatchResult
|
||||
/// <summary>
|
||||
/// Gets matched data to highlight.
|
||||
/// </summary>
|
||||
public List<int> MatchData { get; private set; }
|
||||
public List<int> MatchData { get; private set; } = new();
|
||||
|
||||
public SearchPrecisionScore SearchPrecision { get; set; }
|
||||
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Import Project="..\..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||
<PropertyGroup>
|
||||
<ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>None</ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<!-- Remove once new CsWinRT version is available and Uri.cs is removed -->
|
||||
<NoWarn>0436</NoWarn>
|
||||
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
//[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
||||
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.System.UnitTests")]
|
||||
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests")]
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public enum SearchPrecisionScore
|
||||
|
||||
@@ -4,10 +4,6 @@
|
||||
|
||||
using System.Globalization;
|
||||
|
||||
//[assembly: InternalsVisibleTo("Microsoft.Plugin.Program.UnitTests")]
|
||||
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.System.UnitTests")]
|
||||
//[assembly: InternalsVisibleTo("Microsoft.PowerToys.Run.Plugin.TimeDate.UnitTests")]
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class StringMatcher
|
||||
@@ -23,24 +19,23 @@ public class StringMatcher
|
||||
//_alphabet = alphabet;
|
||||
}
|
||||
|
||||
public static StringMatcher Instance { get; set; }
|
||||
private static StringMatcher? _instance;
|
||||
public static StringMatcher Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
_instance ??= new StringMatcher();
|
||||
|
||||
return _instance;
|
||||
}
|
||||
set => _instance = value;
|
||||
}
|
||||
|
||||
private static readonly char[] Separator = new[] { ' ' };
|
||||
|
||||
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
||||
public static int Score(string source, string target)
|
||||
{
|
||||
return FuzzySearch(target, source).Score;
|
||||
}
|
||||
|
||||
[Obsolete("This method is obsolete and should not be used. Please use the static function StringMatcher.FuzzySearch")]
|
||||
public static bool IsMatch(string source, string target)
|
||||
{
|
||||
return Score(source, target) > 0;
|
||||
}
|
||||
|
||||
public static MatchResult FuzzySearch(string query, string stringToCompare)
|
||||
{
|
||||
|
||||
return Instance.FuzzyMatch(query, stringToCompare);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,67 @@
|
||||
using Windows.UI;
|
||||
// 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.UI;
|
||||
|
||||
namespace Microsoft.CmdPal.Extensions.Helpers;
|
||||
|
||||
public class Tag : BaseObservable, ITag
|
||||
{
|
||||
protected Color _Color = new();
|
||||
protected IconDataType _Icon = null;
|
||||
protected string _Text = "";
|
||||
protected string _ToolTip = "";
|
||||
protected ICommand _Action;
|
||||
private Color _color;
|
||||
private IconDataType _icon = new(string.Empty);
|
||||
private string _text = string.Empty;
|
||||
private string _ToolTip = string.Empty;
|
||||
private ICommand? _command;
|
||||
|
||||
public Color Color { get => _Color; set { _Color = value; OnPropertyChanged(nameof(Color)); } }
|
||||
public IconDataType Icon { get => _Icon; set { _Icon = value; OnPropertyChanged(nameof(Icon)); } }
|
||||
public string Text { get => _Text; set { _Text = value; OnPropertyChanged(nameof(Text)); } }
|
||||
public string ToolTip { get => _ToolTip; set { _ToolTip = value; OnPropertyChanged(nameof(ToolTip)); } }
|
||||
public ICommand Command { get => _Action; set { _Action = value; OnPropertyChanged(nameof(Action)); } }
|
||||
public Color Color
|
||||
{
|
||||
get => _color;
|
||||
set
|
||||
{
|
||||
_color = value;
|
||||
OnPropertyChanged(nameof(Color));
|
||||
}
|
||||
}
|
||||
|
||||
public IconDataType Icon
|
||||
{
|
||||
get => _icon;
|
||||
set
|
||||
{
|
||||
_icon = value;
|
||||
OnPropertyChanged(nameof(Icon));
|
||||
}
|
||||
}
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => _text;
|
||||
set
|
||||
{
|
||||
_text = value;
|
||||
OnPropertyChanged(nameof(Text));
|
||||
}
|
||||
}
|
||||
|
||||
public string ToolTip
|
||||
{
|
||||
get => _ToolTip;
|
||||
set
|
||||
{
|
||||
_ToolTip = value;
|
||||
OnPropertyChanged(nameof(ToolTip));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand? Command
|
||||
{
|
||||
get => _command;
|
||||
set
|
||||
{
|
||||
_command = value;
|
||||
OnPropertyChanged(nameof(Action));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
using Microsoft.CmdPal.Extensions;
|
||||
using Microsoft.CmdPal.Extensions.Helpers;
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
|
||||
// To learn more about WinUI, the WinUI project structure,
|
||||
// and more about our project templates, see: http://aka.ms/winui-project-info.
|
||||
@@ -23,7 +24,11 @@ public class CalculatorAction : InvokableCommand
|
||||
{
|
||||
if (_success)
|
||||
{
|
||||
ClipboardHelper.SetText(_result);
|
||||
var dataPackage = new DataPackage();
|
||||
dataPackage.SetText(_result);
|
||||
Clipboard.SetContent(dataPackage);
|
||||
|
||||
// ClipboardHelper.SetText(_result);
|
||||
}
|
||||
|
||||
return ActionResult.KeepOpen();
|
||||
|
||||
@@ -13,7 +13,7 @@ namespace DeveloperCommandPalette;
|
||||
// cribbed heavily from
|
||||
//
|
||||
// https://github.com/microsoft/WindowsAppSDK-Samples/tree/main/Samples/AppLifecycle/Instancing/cs2/cs-winui-packaged/CsWinUiDesktopInstancing
|
||||
sealed class Program
|
||||
internal sealed class Program
|
||||
{
|
||||
private static App? app;
|
||||
|
||||
@@ -21,7 +21,7 @@ sealed class Program
|
||||
//
|
||||
// Main cannot be async. If it is, then the clipboard won't work, and neither will narrator.
|
||||
[STAThread]
|
||||
static int Main(string[] args)
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
WinRT.ComWrappersSupport.InitializeComWrappers();
|
||||
var isRedirect = DecideRedirection();
|
||||
|
||||
Reference in New Issue
Block a user