diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 1f633ec..6c093ef 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -10,6 +10,8 @@ namespace FileConverter.ConversionJobs using CommunityToolkit.Mvvm.Input; using FileConverter.Diagnostics; + using System.Threading; + using FileConverter.Services; public class ConversionJob : INotifyPropertyChanged { @@ -445,6 +447,7 @@ namespace FileConverter.ConversionJobs this.State = ConversionState.Done; this.UserState = Properties.Resources.ConversionStateDone; Debug.Log("Conversion Done!"); + } protected void ConversionFailed(string exitingMessage) diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index 3e8daa1..96ad2c0 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -321,6 +321,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Copy files in clipboard after conversion. + /// + public static string CopyFilesInClipboardAfterConversion { + get { + return ResourceManager.GetString("CopyFilesInClipboardAfterConversion", resourceCulture); + } + } + /// /// Looks up a localized string similar to New folder. /// diff --git a/Application/FileConverter/Properties/Resources.resx b/Application/FileConverter/Properties/Resources.resx index 26f3cfb..91af1f8 100644 --- a/Application/FileConverter/Properties/Resources.resx +++ b/Application/FileConverter/Properties/Resources.resx @@ -592,4 +592,7 @@ use maj for uppercase version Can't load file converter user settings. Do you want to fall back to default settings ? + + Copy files in clipboard after conversion + \ No newline at end of file diff --git a/Application/FileConverter/Services/ConversionService.cs b/Application/FileConverter/Services/ConversionService.cs index dd49ba9..3445c54 100644 --- a/Application/FileConverter/Services/ConversionService.cs +++ b/Application/FileConverter/Services/ConversionService.cs @@ -70,6 +70,7 @@ namespace FileConverter.Services this.ConversionJobs[index].PrepareConversion(); } + System.Collections.Specialized.StringCollection files = new System.Collections.Specialized.StringCollection(); // Convert! Thread[] jobThreads = new Thread[this.numberOfConversionThread]; while (true) @@ -123,6 +124,11 @@ namespace FileConverter.Services } } + if (!files.Contains(conversionJob.OutputFilePath)) + { + files.Add(conversionJob.OutputFilePath); + } + break; } } @@ -130,6 +136,14 @@ namespace FileConverter.Services Thread.Sleep(50); } + // Copy the output files to the clipboard + if (this.settingsService.Settings.CopyFilesInClipboardAfterConversion && files.Count > 0) + { + Thread clipboardThread = Helpers.InstantiateThread("CopyFilesToClipboardThread", this.CopyFilesToClipboard); + clipboardThread.SetApartmentState(ApartmentState.STA); + clipboardThread.Start(files); + } + bool allConversionsSucceed = true; for (int index = 0; index < this.conversionJobs.Count; index++) { @@ -165,5 +179,24 @@ namespace FileConverter.Services Debug.LogError("Failure during conversion: {0}", exception.ToString()); } } + + private void CopyFilesToClipboard(object _filePaths) + { + try + { + System.Collections.Specialized.StringCollection FilePaths = _filePaths as System.Collections.Specialized.StringCollection; + System.Windows.Forms.Clipboard.SetFileDropList(FilePaths); + Debug.Log("Output files copied to the clipboard:"); + for (int index = 0; index < FilePaths.Count; index++) + { + Debug.Log(" {0}", FilePaths[index]); + } + } + catch (Exception exception) + { + Debug.Log("Can't copy files to the clipboard."); + Debug.Log("An exception has been thrown: {0}.", exception.ToString()); + } + } } } diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index 1b0af32..86076c9 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -21,7 +21,8 @@ namespace FileConverter private bool checkUpgradeAtStartup = true; private CultureInfo applicationLanguage; private int maximumNumberOfSimultaneousConversions; - + private bool copyFilesInClipboardAfterConversion = false; + public ConversionPreset GetPresetFromName(string presetName) { return this.conversionPresets.FirstOrDefault(match => match.FullName == presetName); @@ -206,6 +207,20 @@ namespace FileConverter } } + [XmlElement] + public bool CopyFilesInClipboardAfterConversion + { + get + { + return this.copyFilesInClipboardAfterConversion; + } + + set + { + this.copyFilesInClipboardAfterConversion = value; + this.OnPropertyChanged(); + } + } public void OnDeserializationComplete() { this.DurationBetweenEndOfConversionsAndApplicationExit = System.Math.Max(0, System.Math.Min(10, this.DurationBetweenEndOfConversionsAndApplicationExit)); diff --git a/Application/FileConverter/Views/SettingsWindow.xaml b/Application/FileConverter/Views/SettingsWindow.xaml index 58941e0..968cf62 100644 --- a/Application/FileConverter/Views/SettingsWindow.xaml +++ b/Application/FileConverter/Views/SettingsWindow.xaml @@ -370,6 +370,7 @@ +