Copy All Selected Files

This commit is contained in:
hsayed21 committed 2023-12-08 14:53:21 +02:00
1 parent 45ec5ea1c7
commit ae11eb1999
6 files changed
+42 -30

No files matched your search

@@ -449,14 +449,6 @@ namespace FileConverter.ConversionJobs
this.UserState = Properties.Resources.ConversionStateDone;
Debug.Log("Conversion Done!");
ISettingsService settingsService = SimpleIoc.Default.GetInstance<ISettingsService>();
// 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)
@@ -538,19 +530,5 @@ 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());
}
}
}
}
+3 -3
View File
@@ -322,11 +322,11 @@ namespace FileConverter.Properties {
}
/// <summary>
/// Looks up a localized string similar to Copy File After Converting.
/// Looks up a localized string similar to Copy Files After Converting.
/// </summary>
public static string CopyFileAfterConverting {
public static string CopyFilesAfterConverting {
get {
return ResourceManager.GetString("CopyFileAfterConverting", resourceCulture);
return ResourceManager.GetString("CopyFilesAfterConverting", resourceCulture);
}
}
@@ -592,7 +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="CopyFileAfterConverting" xml:space="preserve">
<value>Copy File After Converting</value>
<data name="CopyFilesAfterConverting" xml:space="preserve">
<value>Copy Files After Converting</value>
</data>
</root>
@@ -65,6 +65,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)
@@ -118,6 +119,11 @@ namespace FileConverter.Services
}
}
if (!files.Contains(conversionJob.OutputFilePath))
{
files.Add(conversionJob.OutputFilePath);
}
break;
}
}
@@ -125,6 +131,15 @@ namespace FileConverter.Services
Thread.Sleep(50);
}
ISettingsService settingsService = SimpleIoc.Default.GetInstance<ISettingsService>();
// Copy the output files to the clipboard
if (settingsService.Settings.CheckCopyFilesAfterConverting && 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++)
{
@@ -160,5 +175,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());
}
}
}
}
+1 -1
View File
@@ -209,7 +209,7 @@ namespace FileConverter
}
[XmlElement]
public bool CheckCopyFileAfterConverting
public bool CheckCopyFilesAfterConverting
{
get
{
@@ -400,8 +400,8 @@
<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.CopyFileAfterConverting}" HorizontalAlignment="Right" Margin="0,0,5,0"/>
<CheckBox Grid.Row="5" Grid.Column="1" x:Name="CopyFileAfterConvertingCheckBox" IsChecked="{Binding Settings.CheckCopyFileAfterConverting, Mode=TwoWay}" Margin="0,5,0,5" />
<Label Grid.Row="5" Grid.Column="0" Content="{x:Static project:Resources.CopyFilesAfterConverting}" HorizontalAlignment="Right" Margin="0,0,5,0"/>
<CheckBox Grid.Row="5" Grid.Column="1" x:Name="CopyFilesAfterConvertingCheckBox" IsChecked="{Binding Settings.CheckCopyFilesAfterConverting, Mode=TwoWay}" Margin="0,5,0,5" />
</Grid>
</TabItem>