From 45ec5ea1c768f7426b83da6281f1975cb81ced16 Mon Sep 17 00:00:00 2001 From: hsayed21 Date: Mon, 4 Dec 2023 20:46:11 +0200 Subject: [PATCH 1/3] Copy File After Converting --- .../ConversionJobs/ConversionJob.cs | 26 +++++++++++++++++++ .../Properties/Resources.Designer.cs | 11 +++++++- .../FileConverter/Properties/Resources.resx | 3 +++ Application/FileConverter/Settings.cs | 17 +++++++++++- .../FileConverter/Views/SettingsWindow.xaml | 4 +++ 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 9c51027..4cd92cc 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -8,6 +8,9 @@ namespace FileConverter.ConversionJobs using System.Windows.Input; using FileConverter.Diagnostics; + using GalaSoft.MvvmLight.Ioc; + using System.Threading; + using FileConverter.Services; using GalaSoft.MvvmLight.Command; @@ -445,6 +448,15 @@ namespace FileConverter.ConversionJobs this.State = ConversionState.Done; this.UserState = Properties.Resources.ConversionStateDone; Debug.Log("Conversion Done!"); + + ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + // Copy the output file to the clipboard using Task + if (settingsService.Settings.CheckCopyFileAfterConverting) + { + Thread clipboardThread = new Thread(CopyFileToClipboard); + clipboardThread.SetApartmentState(ApartmentState.STA); + clipboardThread.Start(); + } } protected void ConversionFailed(string exitingMessage) @@ -526,5 +538,19 @@ namespace FileConverter.ConversionJobs return false; } + + private void CopyFileToClipboard() + { + try + { + System.Windows.Forms.Clipboard.SetFileDropList(new System.Collections.Specialized.StringCollection { OutputFilePath }); + Debug.Log("Output file copied to the clipboard: '{0}'", OutputFilePath); + } + catch (Exception exception) + { + Debug.Log("Can't copy file '{0}' to the clipboard.", OutputFilePath); + Debug.Log("An exception has been thrown: {0}.", exception.ToString()); + } + } } } diff --git a/Application/FileConverter/Properties/Resources.Designer.cs b/Application/FileConverter/Properties/Resources.Designer.cs index 66b3980..aae88f9 100644 --- a/Application/FileConverter/Properties/Resources.Designer.cs +++ b/Application/FileConverter/Properties/Resources.Designer.cs @@ -19,7 +19,7 @@ namespace FileConverter.Properties { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] public class Resources { @@ -321,6 +321,15 @@ namespace FileConverter.Properties { } } + /// + /// Looks up a localized string similar to Copy File After Converting. + /// + public static string CopyFileAfterConverting { + get { + return ResourceManager.GetString("CopyFileAfterConverting", 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 a06c49b..935da49 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 File After Converting + \ No newline at end of file diff --git a/Application/FileConverter/Settings.cs b/Application/FileConverter/Settings.cs index 33f1d10..87dc071 100644 --- a/Application/FileConverter/Settings.cs +++ b/Application/FileConverter/Settings.cs @@ -22,7 +22,8 @@ namespace FileConverter private bool checkUpgradeAtStartup = true; private CultureInfo applicationLanguage; private int maximumNumberOfSimultaneousConversions; - + private bool checkCopyFileAfterConverting = false; + public ConversionPreset GetPresetFromName(string presetName) { return this.conversionPresets.FirstOrDefault(match => match.FullName == presetName); @@ -207,6 +208,20 @@ namespace FileConverter } } + [XmlElement] + public bool CheckCopyFileAfterConverting + { + get + { + return this.checkCopyFileAfterConverting; + } + + set + { + this.checkCopyFileAfterConverting = value; + this.RaisePropertyChanged(); + } + } 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 475745d..2a4dc92 100644 --- a/Application/FileConverter/Views/SettingsWindow.xaml +++ b/Application/FileConverter/Views/SettingsWindow.xaml @@ -371,6 +371,7 @@ +