mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-07 19:57:07 +02:00
[AdvancedPaste] Custom Actions (#34395)
* [AdvancedPaste] Custom Actions * Renamed pipe name to make spellcheck happy * Improved settings page for Custom Actions * UI improvements, disabled standard paste actions when no clipboard text, update clipboard text and gpo state every second * Bug fixes, single query/prompt box, Ctrl+num shortcuts for custom actions, error box * Spellcheck issue * Bug fixes and used Advanced Paste Window as wait indicator for keyboard shortcuts * Improvements to PromptBox, incluing show error message as tooltip * Refactoring * Fixed issue where ESC sometimes didn't close paste window * Update src/settings-ui/Settings.UI/Strings/en-us/Resources.resw Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com> --------- Co-authored-by: Stefan Markovic <57057282+stefansjfw@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
// See the LICENSE file in the project root for more information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
@@ -10,7 +11,6 @@ using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.ViewModels;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using Windows.Security.Credentials;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
{
|
||||
@@ -69,14 +69,85 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
|
||||
private void AdvancedPaste_EnableAIDialogOpenAIApiKey_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (AdvancedPaste_EnableAIDialogOpenAIApiKey.Text.Length > 0)
|
||||
EnableAIDialog.IsPrimaryButtonEnabled = AdvancedPaste_EnableAIDialogOpenAIApiKey.Text.Length > 0;
|
||||
}
|
||||
|
||||
public async void DeleteCustomActionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var customAction = GetBoundCustomAction(sender);
|
||||
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
||||
|
||||
ContentDialog dialog = new()
|
||||
{
|
||||
EnableAIDialog.IsPrimaryButtonEnabled = true;
|
||||
XamlRoot = RootPage.XamlRoot,
|
||||
Title = customAction.Name,
|
||||
PrimaryButtonText = resourceLoader.GetString("Yes"),
|
||||
CloseButtonText = resourceLoader.GetString("No"),
|
||||
DefaultButton = ContentDialogButton.Primary,
|
||||
Content = new TextBlock() { Text = resourceLoader.GetString("Delete_Dialog_Description") },
|
||||
};
|
||||
|
||||
dialog.PrimaryButtonClick += (_, _) => ViewModel.DeleteCustomAction(customAction);
|
||||
|
||||
await dialog.ShowAsync();
|
||||
}
|
||||
|
||||
private async void AddCustomActionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
||||
|
||||
CustomActionDialog.Title = resourceLoader.GetString("AddCustomAction");
|
||||
CustomActionDialog.DataContext = ViewModel.GetNewCustomAction(resourceLoader.GetString("AdvancedPasteUI_NewCustomActionPrefix"));
|
||||
CustomActionDialog.PrimaryButtonText = resourceLoader.GetString("CustomActionSave");
|
||||
await CustomActionDialog.ShowAsync();
|
||||
}
|
||||
|
||||
private async void EditCustomActionButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var resourceLoader = ResourceLoaderInstance.ResourceLoader;
|
||||
|
||||
CustomActionDialog.Title = resourceLoader.GetString("EditCustomAction");
|
||||
CustomActionDialog.DataContext = GetBoundCustomAction(sender).Clone();
|
||||
CustomActionDialog.PrimaryButtonText = resourceLoader.GetString("CustomActionUpdate");
|
||||
await CustomActionDialog.ShowAsync();
|
||||
}
|
||||
|
||||
private void ReorderButtonDown_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var index = ViewModel.CustomActions.IndexOf(GetBoundCustomAction(sender));
|
||||
ViewModel.CustomActions.Move(index, index + 1);
|
||||
}
|
||||
|
||||
private void ReorderButtonUp_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
var index = ViewModel.CustomActions.IndexOf(GetBoundCustomAction(sender));
|
||||
ViewModel.CustomActions.Move(index, index - 1);
|
||||
}
|
||||
|
||||
private void CustomActionDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args)
|
||||
{
|
||||
if (args.Result != ContentDialogResult.Primary)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var dialogCustomAction = GetBoundCustomAction(sender);
|
||||
var existingCustomAction = ViewModel.CustomActions.FirstOrDefault(candidate => candidate.Id == dialogCustomAction.Id);
|
||||
|
||||
if (existingCustomAction == null)
|
||||
{
|
||||
ViewModel.AddCustomAction(dialogCustomAction);
|
||||
|
||||
var element = (ContentPresenter)CustomActions.ContainerFromIndex(CustomActions.Items.Count - 1);
|
||||
element.StartBringIntoView(new BringIntoViewOptions { VerticalOffset = -60, AnimationDesired = true });
|
||||
element.Focus(FocusState.Programmatic);
|
||||
}
|
||||
else
|
||||
{
|
||||
EnableAIDialog.IsPrimaryButtonEnabled = false;
|
||||
existingCustomAction.Update(dialogCustomAction);
|
||||
}
|
||||
}
|
||||
|
||||
private static AdvancedPasteCustomAction GetBoundCustomAction(object sender) => (AdvancedPasteCustomAction)((FrameworkElement)sender).DataContext;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user