Quellcode durchsuchen

翻译文件-添加拖拽,主页取消拖拽效果

liyijie vor 1 Jahr
Ursprung
Commit
6cac0d4ce4

+ 1 - 0
PDF Office/ViewModels/Dialog/ChatGPTAIDialogs/DocumentaryTranslationDialogViewModel.cs

@@ -100,6 +100,7 @@ namespace PDF_Master.ViewModels.Dialog.ChatGPTAIDialogs
                     }
                 }
             }
+            RequestClose.Invoke(new DialogResult(ButtonResult.Cancel));
         }
 
         public string Title => "";

+ 4 - 0
PDF Office/ViewModels/HomeContentViewModel.cs

@@ -66,6 +66,8 @@ namespace PDF_Master.ViewModels
 
         #endregion
 
+        public string currentViewName="";
+
         private string fileName = "Home";
         public string FileName
         {
@@ -135,6 +137,7 @@ namespace PDF_Master.ViewModels
         /// <param name="view"></param>
         public void ShowToolContent(string view)
         {
+            currentViewName = view;
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.HomeContentViewModel, this);
             if (view.Contains("ChatGPT"))
@@ -433,6 +436,7 @@ namespace PDF_Master.ViewModels
             }
             NavigationParameters param = new NavigationParameters();
             param.Add(ParameterNames.HomeContentViewModel, this);
+            currentViewName = "Guid";
             toolregion.RequestNavigate(ToolRegionName, "Guid", param);
         }
 

+ 13 - 10
PDF Office/ViewModels/HomePanel/ChatGPTAI/ChatGPTAITranslationContentViewModel.cs

@@ -14,11 +14,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
     public class ChatGPTAITranslationContentViewModel : BindableBase, INavigationAware
     {
 
-        HomeContentViewModel homeContentViewModel = null;
+        public HomeContentViewModel homeContentViewModel = null;
 
-        private string fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(0);
+        public string fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(0);
 
-        private string tolanguage = ChatGTPAIHelper.UpdateLanguagebType(1);
+        public string tolanguage = ChatGTPAIHelper.UpdateLanguagebType(1);
 
         private int fromlanguageIndex = 0;
         public int FromlanguageIndex
@@ -68,10 +68,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
             GetTolanguageOrigin();
         }
 
-        public async void selectFiles() {
+        public async void selectFiles()
+        {
             string word = Properties.Resources.wordex;
-            string pdf= Properties.Resources.pdf;
-            string allfiles = pdf+ word;
+            string pdf = Properties.Resources.pdf;
+            string allfiles = pdf + word;
             OpenFileDialog dialog = new OpenFileDialog();
             //dialog.Multiselect = true;
             dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" +
@@ -79,9 +80,11 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
            $"Microsoft Office Word({word})|{word}");
             if ((bool)dialog.ShowDialog())
             {
-               string newfile= await ChatGTPAIHelper.fileTranslate( dialog.FileName , fromlanguage, tolanguage);
-                if (!string.IsNullOrEmpty(newfile)) {
-                    if (File.Exists(newfile)) {
+                string newfile = await ChatGTPAIHelper.fileTranslate(dialog.FileName, fromlanguage, tolanguage);
+                if (!string.IsNullOrEmpty(newfile))
+                {
+                    if (File.Exists(newfile))
+                    {
                         if (homeContentViewModel != null)
                         {
                             homeContentViewModel.OpenFile(new string[] { newfile });
@@ -89,7 +92,7 @@ namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI
                     }
                 }
             }
-                
+
         }
 
         public void OnNavigatedTo(NavigationContext navigationContext)

+ 4 - 4
PDF Office/ViewModels/ViewContentViewModel.cs

@@ -1367,15 +1367,15 @@ namespace PDF_Master.ViewModels
         /// </summary>
         public void OpenFile(string[] newfile)
         {
-            if (App.OpenedFileList.Contains(newfile[1]))
+            if (App.OpenedFileList.Contains(newfile[0]))
             {
-                App.mainWindowViewModel.SelectItem(newfile[1]);
+                App.mainWindowViewModel.SelectItem(newfile[0]);
             }
             else
             {
-                App.mainWindowViewModel.AddTabItem(newfile[1]);
+                App.mainWindowViewModel.AddTabItem(newfile[0]);
             }
-            ToolMethod.SetFileThumbImg(newfile[1]);
+            ToolMethod.SetFileThumbImg(newfile[0]);
 
         }
 

+ 21 - 16
PDF Office/Views/HomeContent.xaml.cs

@@ -1,6 +1,6 @@
 using PDF_Master.CustomControl;
 using PDF_Master.Helper;
-using PDF_Master.ViewModels;
+using PDF_Master.ViewModels;
 using System;
 using System.Collections.Generic;
 using System.Collections.ObjectModel;
@@ -25,7 +25,7 @@ namespace PDF_Master.Views
         public string Content { get; set; }
 
         public string Uri { get; set; }
-        public PromotionBanner(string ImagePath,string Content,string uri)
+        public PromotionBanner(string ImagePath, string Content, string uri)
         {
             this.ImagePath = ImagePath;
             this.Content = Content;
@@ -37,17 +37,18 @@ namespace PDF_Master.Views
     /// HomeContent.xaml 的交互逻辑
     /// </summary>
     public partial class HomeContent : UserControl
-    {
+    {
+        private HomeContentViewModel viewModel;
 
-        private bool IsContextMenuOpen = false;
-       
+        private bool IsContextMenuOpen = false;
+
         public HomeContent()
         {
             InitializeComponent();
-            BtnGuid.IsChecked = true;
-           
-        }
-      
+            BtnGuid.IsChecked = true;
+            viewModel = this.DataContext as HomeContentViewModel;
+        }
+
         private void ToggleBtnSelect_Click(object sender, RoutedEventArgs e)
         {
             BtnGuid.IsChecked = false;
@@ -55,17 +56,17 @@ namespace PDF_Master.Views
             BtnCloud.IsChecked = false;
 
             var btn = sender as CustomIconToggleBtn;
-            if(btn != null )
+            if (btn != null)
             {
                 btn.IsChecked = true;
-            }
-            
+            }
+
         }
 
         private void BtnCreatPDF_Initialized(object sender, EventArgs e)
         {
             var btn = sender as Button;
-            if(btn!=null)
+            if (btn != null)
             {
                 btn.ContextMenu = null;
             }
@@ -92,7 +93,7 @@ namespace PDF_Master.Views
 
         private void UserControl_DragEnter(object sender, DragEventArgs e)
         {
-            DragDropHelper.DragEnter(this,e);
+            DragDropHelper.DragEnter(this, e);
         }
 
         private void UserControl_DragOver(object sender, DragEventArgs e)
@@ -112,9 +113,13 @@ namespace PDF_Master.Views
                 DragDropHelper.Drop(this, e);
 
                 string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
-                if(file.Length>0)
+                if (file.Length > 0)
                 {
-                    (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
+                    //判断是否为Home页面
+                    if (viewModel.currentViewName == "Guid")
+                    {
+                        (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
+                    }
                 }
             }
             catch { }

+ 6 - 0
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml

@@ -28,6 +28,11 @@ Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, P
                         </VisualBrush.Visual>
                     </VisualBrush>
                 </Border.BorderBrush>
+                <Grid AllowDrop="True"
+                  Drop="Grid_Drop"
+                  DragEnter="MainPage_DragEnter"
+                  DragOver="MainPage_DragOver"
+                  DragLeave="MainPage_DragLeave"> 
                 <StackPanel>
                     <StackPanel Margin="0,72,0,0">
                         <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
@@ -75,6 +80,7 @@ Height="{Binding RelativeSource={RelativeSource AncestorType={x:Type Border}}, P
                         TextWrapping="Wrap"
                         />
                 </StackPanel>
+                </Grid>
             </Border>
         </StackPanel>
     </Grid>

+ 113 - 1
PDF Office/Views/HomePanel/ChatGPTAI/ChatGPTAITranslationContent.xaml.cs

@@ -1,4 +1,18 @@
-using System.Windows.Controls;
+using ComPDFKitViewer;
+using PDF_Master.Helper;
+using System.Data;
+using System.Windows;
+using System;
+using System.Windows.Controls;
+using System.Windows.Interop;
+using PDF_Master.ViewModels.Dialog.HomePageToolsDialogs.HomePageBatchProcessing;
+using PDF_Master.ViewModels.HomePanel.ChatGPTAI;
+using Microsoft.Office.Core;
+using PDF_Master.ViewModels;
+using Microsoft.Office.Interop.Word;
+using System.IO;
+using Point = System.Windows.Point;
+using Window = System.Windows.Window;
 
 namespace PDF_Master.Views.HomePanel.ChatGPTAI
 {
@@ -7,9 +21,107 @@ namespace PDF_Master.Views.HomePanel.ChatGPTAI
     /// </summary>
     public partial class ChatGPTAITranslationContent : UserControl
     {
+        private ChatGPTAITranslationContentViewModel viewModel;
+        private IDropTargetHelper dropHelper;
         public ChatGPTAITranslationContent()
         {
             InitializeComponent();
+            viewModel = this.DataContext as ChatGPTAITranslationContentViewModel;
         }
+
+        private async void Grid_Drop(object sender, DragEventArgs e)
+        {
+
+            try
+            {
+               Point iconPoint = e.GetPosition(this);
+                dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+            string dropFile = "Drop";
+            if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
+            {
+                //BtnBlank.IsEnabled = true;
+                int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
+                for (int i = 0; i < count; i++)
+                {
+                    dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); 
+                    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")) 
+                    {
+                        string newfile = await ChatGTPAIHelper.fileTranslate(dropFile, viewModel.fromlanguage, viewModel.tolanguage);
+                        if (!string.IsNullOrEmpty(newfile))
+                        {
+                            if (File.Exists(newfile))
+                            {
+                                if (viewModel.homeContentViewModel != null)
+                                { 
+                                    viewModel.homeContentViewModel.OpenFile(new string[] { newfile }); 
+                                
+                                }
+                            }
+                        }
+                                    
+                    }
+                }
+            }
+        }
+        private void MainPage_DragEnter(object sender, DragEventArgs e)
+        {
+            //BtnBlank.IsEnabled = false;
+            //页面编辑和缩略图
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                if (dropHelper == null)
+                {
+                    dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
+                }
+                Point iconPoint = e.GetPosition(this);
+                dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
+        private void MainPage_DragOver(object sender, DragEventArgs e)
+        {
+
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                Point iconPoint = e.GetPosition(this);
+                dropHelper?.DragOver(ref iconPoint, e.Effects);
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
+        private void MainPage_DragLeave(object sender, DragEventArgs e)
+        {
+           // BtnBlank.IsEnabled = true;
+            if ((e.OriginalSource as Image) != null)
+                return;
+            try
+            {
+                dropHelper?.DragLeave();
+            }
+            catch (Exception ex)
+            {
+
+            }
+
+        }
+
     }
 }