123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using Microsoft.Win32;
- using PDF_Master.Model.CloudDrive;
- using PDF_Master.ViewModels.HomePanel.CloudDrive;
- using PDF_Master.ViewModels.HomePanel.CloudDrive.CloudDriveType;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace PDF_Master.Views.HomePanel.CloudDrive
- {
- /// <summary>
- /// CloudFilesContent.xaml 的交互逻辑
- /// </summary>
- public partial class CloudFilesContent : UserControl
- {
-
- private CloudFilesContentViewModel ViewModel => DataContext as CloudFilesContentViewModel;
- private ContextMenu FlyoutMenu;
- private ContextMenu UserFlyoutMenu;
- private List<CloudBoxItem> CloudeDrives = new List<CloudBoxItem>();
- public CloudFilesContent()
- {
- InitializeComponent();
- InitCloudDrive();
- this.Loaded -= usercontrol_Loaded;
- this.Loaded += usercontrol_Loaded;
- }
- private void InitCloudDrive()
- {
- CloudeDrives = Cloud.InitCloudBoxs();
- combCloudDrive.ItemsSource = CloudeDrives;
- combCloudDrive.SelectedIndex = 0;
- FlyoutMenu = Resources["FlyoutMenu"] as ContextMenu;
- UserFlyoutMenu = Resources["UserFlyoutMenu"] as ContextMenu;
-
- }
- private void usercontrol_Loaded(object sender, RoutedEventArgs e)
- {
- if(ViewModel != null)
- {
- if (Listusers.ItemsSource == null)
- Listusers.ItemsSource = Cloud.CloudLists;
- }
- }
- private UserBaseItem CurrentUser;
- private void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
- if(cloudFileUser != null)
- {
- CurrentUser = cloudFileUser;
- switch(cloudFileUser.cloudType)
- {
- case CloudType.GoogleDrive:
- {
- FileOperation fileOperation = new FileOperation(cloudFileUser, null);
- ViewModel?.OpenFolderCommand?.Execute(fileOperation);
- }
- break;
- case CloudType.DropBox:
- {
- FileOperation fileOperation = new FileOperation(cloudFileUser, null);
- ViewModel?.OpenFolderCommand?.Execute(fileOperation);
- }
- break;
- }
- }
- }
- private void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
- {
- var menuItem = sender as MenuItem;
- if (menuItem == null)
- return;
- var file = menuItem.DataContext as FilesBaseItem;
- if (file != null)
- {
- var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
- if (cloudFileUser != null)
- {
- FileOperation fileOperation = new FileOperation(cloudFileUser, file);
- ViewModel?.OpenFileCommand?.Execute(fileOperation);
- }
- }
- }
- private void RemoveUserMenuItem_Click(object sender, RoutedEventArgs e)
- {
- var menuItem = sender as MenuItem;
- if (menuItem == null)
- return;
- var user = menuItem.DataContext as UserBaseItem;
- if (user != null)
- {
- ViewModel?.RemoveUserCommand?.Execute(user);
- }
- }
- private void SelectListFolder_Click(object sender, MouseButtonEventArgs e)
- {
- var folderItem = (sender as FrameworkElement).DataContext as FolderBaseItem;
- if (folderItem != null)
- {
- ViewModel?.SelectedFolderCommand?.Execute(folderItem);
- }
- }
- private void ListViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- var frame = sender as FrameworkElement;
- if (frame != null && frame.DataContext as FilesBaseItem != null)
- {
- var file = frame.DataContext as FilesBaseItem;
- if ((file == null || file.IsFolder == false) && FlyoutMenu != null)
- {
- FlyoutMenu.DataContext = file;
- FlyoutMenu.IsOpen = true;
- }
- }
- }
- /// <summary>
- /// 打开文件夹,显示文件列表内容
- /// </summary>
- private void ListViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
- {
- var frame = sender as FrameworkElement;
- if (frame != null && frame.DataContext as FilesBaseItem != null)
- {
- var file = frame.DataContext as FilesBaseItem;
- if (file != null && file.IsFolder == true)
- {
- var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
- if (cloudFileUser != null)
- {
- FileOperation fileOperation = new FileOperation(cloudFileUser, file);
- ViewModel?.OpenFolderCommand?.Execute(fileOperation);
- }
- }
- }
- }
- private void userItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
- {
- var frame = sender as FrameworkElement;
- if (frame != null && frame.DataContext as UserBaseItem != null)
- {
- var user = frame.DataContext as UserBaseItem;
- if (user != null && UserFlyoutMenu != null)
- {
- UserFlyoutMenu.DataContext = user;
- UserFlyoutMenu.IsOpen = true;
- }
- }
- }
- private void UpLoadFileBtn_Click(object sender, RoutedEventArgs e)
- {
- var folder = ListFolder.Items[ListFolder.Items.Count - 1] as FolderBaseItem;
- if (folder != null && folder.Operation != null)
- {
- FileOperation fileOperation = new FileOperation(CurrentUser, folder.Operation.DoFile);
- ViewModel?.UpLoadFileCommand?.Execute(fileOperation);
- }
- }
- }
- }
|