From 7b0444d3176d3ad5a98791f690c96d12bee9ebbc Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Wed, 19 Jun 2024 16:24:51 +0200 Subject: [PATCH] feature: Allow populating the repository URL from the clipboard Allow populating the repository URL from the clipboard if the clipboard contains a valid URL. --- src/App.axaml.cs | 12 ++++++++++++ src/ViewModels/Clone.cs | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index f1676fa3..619ab60c 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -317,6 +317,18 @@ namespace SourceGit }); } + public static async Task GetClipboardTextAsync() + { + if (Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) + { + if (desktop.MainWindow.Clipboard is { } clipboard) + { + return await clipboard.GetTextAsync(); + } + } + return default; + } + private ResourceDictionary _activeLocale = null; private ResourceDictionary _colorOverrides = null; private Models.INotificationReceiver _notificationReceiver = null; diff --git a/src/ViewModels/Clone.cs b/src/ViewModels/Clone.cs index 7db82081..89eff488 100644 --- a/src/ViewModels/Clone.cs +++ b/src/ViewModels/Clone.cs @@ -56,6 +56,22 @@ namespace SourceGit.ViewModels _page = launcher.ActivePage; View = new Views.Clone() { DataContext = this }; + App.GetClipboardTextAsync() + .ContinueWith(t => + { + if (t.IsFaulted) + { + t.Exception.Handle(static _ => true); + } + else if (t.IsCompleted) + { + var result = t.Result; + if (Models.Remote.IsValidURL(result)) + { + Remote = result; + } + } + }); } public static ValidationResult ValidateRemote(string remote, ValidationContext _)