123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- using Microsoft.Win32;
- using PDF_Office.EventAggregators;
- using PDF_Office.Helper;
- using PDF_Office.Model;
- using Prism.Commands;
- using Prism.Events;
- using Prism.Mvvm;
- using Prism.Regions;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- namespace PDF_Office.ViewModels
- {
- public class HomeContentViewModel : BindableBase, INavigationAware
- {
- private string fileName = "Home";
- public string FileName
- {
- get { return fileName; }
- set { SetProperty(ref fileName, value); }
- }
- private string regionName;
- public string ToolRegionName
- {
- get { return regionName; }
- set { SetProperty(ref regionName, value); }
- }
- private Visibility isLoading = Visibility.Collapsed;
- public Visibility IsLoading
- {
- get { return isLoading; }
- set
- {
- SetProperty(ref isLoading, value);
- }
- }
- private MainContentViewModel mainContentViewModel;
- public DelegateCommand OpenFileCommand { get; set; }
- public DelegateCommand<string> ShowToolCommand { get; set; }
- public DelegateCommand CreateBlackPDFCommand { get; set; }
- public DelegateCommand CreateFromOtherFile { get; set; }
- public IRegionManager toolregion;
- public IEventAggregator eventer;
- public HomeContentViewModel(IRegionManager regionManager, IEventAggregator eventAggregator)
- {
- toolregion = regionManager;
- eventer = eventAggregator;
- ToolRegionName = RegionNames.ToolRegionName;
- OpenFileCommand = new DelegateCommand(OpenFile);
- ShowToolCommand = new DelegateCommand<string>(ShowToolContent);
- CreateBlackPDFCommand = new DelegateCommand(CreatBlankPDF);
- CreateFromOtherFile = new DelegateCommand(createFromOtherFile);
- System.Windows.Application.Current.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
- {
- toolregion.RequestNavigate(ToolRegionName, "Guid");
- }));
- }
- /// <summary>
- /// 显示右侧不同的工具栏页面
- /// </summary>
- /// <param name="view"></param>
- public void ShowToolContent(string view)
- {
- toolregion.RequestNavigate(ToolRegionName, view);
- }
- /// <summary>
- /// 从其他格式文件创建PDF
- /// </summary>
- private void createFromOtherFile()
- {
- }
- /// <summary>
- /// 打开文件
- /// </summary>
- public async void OpenFile()
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = Properties.Resources.OpenDialogFilter;
- openFileDialog.Multiselect = true;
- if ((bool)openFileDialog.ShowDialog())
- {
- IsLoading = Visibility.Visible;
- await Task.Delay(3);
- if (openFileDialog.FileNames.Count() == 1)
- {
- if (App.OpenedFileList.Contains(openFileDialog.FileName))
- {
- App.mainWindowViewModel.SelectItem(openFileDialog.FileName);
- }
- else
- {
- mainContentViewModel.OpenFile(openFileDialog.FileName);
- }
- ToolMethod.SetFileThumbImg(openFileDialog.FileName);
- }
- else
- {
- var fileList = openFileDialog.FileNames.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
- if (fileList.Count <= 0)
- return;
- mainContentViewModel.OpenFile(fileList[0]);
- for (int i = 1; i < fileList.Count(); i++)
- {
- if (!App.OpenedFileList.Contains(fileList[i]))
- {
- App.mainWindowViewModel.AddTabItem(fileList[i]);
- }
- ToolMethod.SetFileThumbImg(fileList[i]);
- }
- }
- IsLoading = Visibility.Collapsed;
- }
- }
- /// <summary>
- /// 打开其他格式文件
- /// </summary>
- public void OpenFromOtherFile()
- {
- }
- public void CreatBlankPDF()
- {
- mainContentViewModel.CreateFile();
- }
- #region Navigate
- public void OnNavigatedTo(NavigationContext navigationContext)
- {
- var mainVM = navigationContext.Parameters[ParameterNames.MainViewModel] as MainContentViewModel;
- if (mainVM != null)
- {
- mainContentViewModel = mainVM;
- }
- }
- public bool IsNavigationTarget(NavigationContext navigationContext)
- {
- return true;
- }
- public void OnNavigatedFrom(NavigationContext navigationContext)
- {
- }
- #endregion
- }
- }
|