mirror of
https://github.com/Tichau/FileConverter.git
synced 2026-11-19 17:12:22 +01:00
Merge pull request #348 from hsayed21/integration
Copy Files To Clipboard After Converting
This commit is contained in:
6 files changed
+68
-1
No files matched your search
@@ -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)
|
||||
|
||||
@@ -321,6 +321,15 @@ namespace FileConverter.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Copy files in clipboard after conversion.
|
||||
/// </summary>
|
||||
public static string CopyFilesInClipboardAfterConversion {
|
||||
get {
|
||||
return ResourceManager.GetString("CopyFilesInClipboardAfterConversion", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to New folder.
|
||||
/// </summary>
|
||||
|
||||
@@ -592,4 +592,7 @@ use maj for uppercase version</value>
|
||||
<data name="ErrorCantLoadSettings" xml:space="preserve">
|
||||
<value>Can't load file converter user settings. Do you want to fall back to default settings ?</value>
|
||||
</data>
|
||||
<data name="CopyFilesInClipboardAfterConversion" xml:space="preserve">
|
||||
<value>Copy files in clipboard after conversion</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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));
|
||||
|
||||
@@ -370,6 +370,7 @@
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="{x:Static project:Resources.Language}" HorizontalAlignment="Right" Margin="0,0,5,0"/>
|
||||
@@ -397,6 +398,9 @@
|
||||
|
||||
<Label Grid.Row="4" Grid.Column="0" Content="{x:Static project:Resources.AutomaticallyCheckForUpdates}" HorizontalAlignment="Right" Margin="0,0,5,0"/>
|
||||
<CheckBox Grid.Row="4" Grid.Column="1" IsChecked="{Binding Settings.CheckUpgradeAtStartup, Mode=TwoWay}" Margin="0,5,0,5" />
|
||||
|
||||
<Label Grid.Row="5" Grid.Column="0" Content="{x:Static project:Resources.CopyFilesInClipboardAfterConversion}" HorizontalAlignment="Right" Margin="0,0,5,0"/>
|
||||
<CheckBox Grid.Row="5" Grid.Column="1" x:Name="CopyFilesInClipboardAfterConversionCheckBox" IsChecked="{Binding Settings.CopyFilesInClipboardAfterConversion, Mode=TwoWay}" Margin="0,5,0,5" />
|
||||
</Grid>
|
||||
</TabItem>
|
||||
|
||||
|
||||
Reference in new issue
Block a user