using Microsoft.Win32; using PDF_Master.Helper; using PDF_Master.Model; using Prism.Commands; using Prism.Mvvm; using Prism.Regions; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace PDF_Master.ViewModels.HomePanel.ChatGPTAI { public class ChatGPTAITranslationContentViewModel : BindableBase, INavigationAware { HomeContentViewModel homeContentViewModel = null; private string fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(0); private string tolanguage = ChatGTPAIHelper.UpdateLanguagebType(1); private int fromlanguageIndex = 0; public int FromlanguageIndex { get { return fromlanguageIndex; } set { SetProperty(ref fromlanguageIndex, value); fromlanguage = ChatGTPAIHelper.UpdateLanguagebType(value); } } private int tolanguageIndex = 0; public int TolanguageIndex { get { return tolanguageIndex; } set { SetProperty(ref tolanguageIndex, value); tolanguage = ChatGTPAIHelper.UpdateLanguagebType(value + 1); } } public static List FromlanguageFamily { set; get; } = new List(); private void GetFromlanguageOrigin() { FromlanguageFamily.Clear(); FromlanguageFamily = ChatGTPAIHelper.SetFromlanguageOrigin(); } public List TolanguageFamily { set; get; } = new List(); private void GetTolanguageOrigin() { TolanguageFamily.Clear(); TolanguageFamily = ChatGTPAIHelper.SetTolanguageOrigin(); } public DelegateCommand SelectFilesCommand { get; set; } public ChatGPTAITranslationContentViewModel() { SelectFilesCommand = new DelegateCommand(selectFiles); init(); } private void init() { GetFromlanguageOrigin(); GetTolanguageOrigin(); } public async void selectFiles() { string word = Properties.Resources.wordex; string pdf= Properties.Resources.pdf; string allfiles = pdf+ word; OpenFileDialog dialog = new OpenFileDialog(); //dialog.Multiselect = true; dialog.Filter = string.Format($"Files({allfiles.Replace(";", ",")}|{allfiles})|" + $"Pdf({pdf})|{pdf}|" + $"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)) { if (homeContentViewModel != null) { homeContentViewModel.OpenFile(new string[] { newfile }); } } } } } public void OnNavigatedTo(NavigationContext navigationContext) { navigationContext.Parameters.TryGetValue(ParameterNames.HomeContentViewModel, out homeContentViewModel); } public bool IsNavigationTarget(NavigationContext navigationContext) { return true; } public void OnNavigatedFrom(NavigationContext navigationContext) { } } }