ChatGPTAITranslationContent.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using ComPDFKitViewer;
  2. using PDF_Master.Helper;
  3. using System.Data;
  4. using System.Windows;
  5. using System;
  6. using System.Windows.Controls;
  7. using System.Windows.Interop;
  8. using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
  9. using PDF_Master.ViewModels.HomePanel.ChatGPTAI;
  10. using Microsoft.Office.Core;
  11. using PDF_Master.ViewModels;
  12. using Microsoft.Office.Interop.Word;
  13. using System.IO;
  14. using Point = System.Windows.Point;
  15. using Window = System.Windows.Window;
  16. namespace PDF_Master.Views.HomePanel.ChatGPTAI
  17. {
  18. /// <summary>
  19. /// Interaction logic for ChatGPTAITranslationContent
  20. /// </summary>
  21. public partial class ChatGPTAITranslationContent : UserControl
  22. {
  23. private ChatGPTAITranslationContentViewModel viewModel;
  24. private IDropTargetHelper dropHelper;
  25. public ChatGPTAITranslationContent()
  26. {
  27. InitializeComponent();
  28. viewModel = this.DataContext as ChatGPTAITranslationContentViewModel;
  29. }
  30. private async void Grid_Drop(object sender, DragEventArgs e)
  31. {
  32. try
  33. {
  34. Point iconPoint = e.GetPosition(this);
  35. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  36. }
  37. catch (Exception ex)
  38. {
  39. }
  40. string dropFile = "Drop";
  41. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  42. {
  43. //BtnBlank.IsEnabled = true;
  44. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  45. for (int i = 0; i < count; i++)
  46. {
  47. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString();
  48. if (dropFile.ToLower().EndsWith("pdf")|| dropFile.ToLower().EndsWith(".doc") || dropFile.ToLower().EndsWith(".docx")|| dropFile.ToLower().EndsWith(".docm")|| dropFile.ToLower().EndsWith(".dot")|| dropFile.ToLower().EndsWith(".dotx") || dropFile.ToLower().EndsWith(".dotm"))
  49. {
  50. string newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
  51. if (!string.IsNullOrEmpty(newfile))
  52. {
  53. if (File.Exists(newfile))
  54. {
  55. if (viewModel.homeContentViewModel != null)
  56. {
  57. viewModel.homeContentViewModel.OpenFile(new string[] { newfile });
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }
  64. }
  65. private void MainPage_DragEnter(object sender, DragEventArgs e)
  66. {
  67. //BtnBlank.IsEnabled = false;
  68. //页面编辑和缩略图
  69. if ((e.OriginalSource as Image) != null)
  70. return;
  71. try
  72. {
  73. if (dropHelper == null)
  74. {
  75. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  76. }
  77. Point iconPoint = e.GetPosition(this);
  78. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  79. }
  80. catch (Exception ex)
  81. {
  82. }
  83. }
  84. private void MainPage_DragOver(object sender, DragEventArgs e)
  85. {
  86. if ((e.OriginalSource as Image) != null)
  87. return;
  88. try
  89. {
  90. Point iconPoint = e.GetPosition(this);
  91. dropHelper?.DragOver(ref iconPoint, e.Effects);
  92. }
  93. catch (Exception ex)
  94. {
  95. }
  96. }
  97. private void MainPage_DragLeave(object sender, DragEventArgs e)
  98. {
  99. // BtnBlank.IsEnabled = true;
  100. if ((e.OriginalSource as Image) != null)
  101. return;
  102. try
  103. {
  104. dropHelper?.DragLeave();
  105. }
  106. catch (Exception ex)
  107. {
  108. }
  109. }
  110. }
  111. }