CloudFilesContent.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using Microsoft.Win32;
  2. using PDF_Office.Model.CloudDrive;
  3. using PDF_Office.ViewModels.HomePanel.CloudDrive;
  4. using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Windows;
  12. using System.Windows.Controls;
  13. using System.Windows.Data;
  14. using System.Windows.Documents;
  15. using System.Windows.Input;
  16. using System.Windows.Media;
  17. using System.Windows.Media.Imaging;
  18. using System.Windows.Navigation;
  19. using System.Windows.Shapes;
  20. namespace PDF_Office.Views.HomePanel.CloudDrive
  21. {
  22. /// <summary>
  23. /// CloudFilesContent.xaml 的交互逻辑
  24. /// </summary>
  25. public partial class CloudFilesContent : UserControl
  26. {
  27. private CloudFilesContentViewModel ViewModel => DataContext as CloudFilesContentViewModel;
  28. private ContextMenu FlyoutMenu;
  29. private ContextMenu UserFlyoutMenu;
  30. private List<CloudBoxItem> CloudeDrives = new List<CloudBoxItem>();
  31. public CloudFilesContent()
  32. {
  33. InitializeComponent();
  34. InitCloudDrive();
  35. this.Loaded -= usercontrol_Loaded;
  36. this.Loaded += usercontrol_Loaded;
  37. }
  38. private void InitCloudDrive()
  39. {
  40. CloudeDrives = Cloud.InitCloudBoxs();
  41. combCloudDrive.ItemsSource = CloudeDrives;
  42. combCloudDrive.SelectedIndex = 0;
  43. FlyoutMenu = Resources["FlyoutMenu"] as ContextMenu;
  44. UserFlyoutMenu = Resources["UserFlyoutMenu"] as ContextMenu;
  45. }
  46. private void usercontrol_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. if(ViewModel != null)
  49. {
  50. if (Listusers.ItemsSource == null)
  51. Listusers.ItemsSource = Cloud.CloudLists;
  52. }
  53. }
  54. private UserBaseItem CurrentUser;
  55. private void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
  56. {
  57. var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
  58. if(cloudFileUser != null)
  59. {
  60. CurrentUser = cloudFileUser;
  61. switch(cloudFileUser.cloudType)
  62. {
  63. case CloudType.GoogleDrive:
  64. {
  65. FileOperation fileOperation = new FileOperation(cloudFileUser, null);
  66. ViewModel?.OpenFolderCommand?.Execute(fileOperation);
  67. }
  68. break;
  69. case CloudType.DropBox:
  70. {
  71. FileOperation fileOperation = new FileOperation(cloudFileUser, null);
  72. ViewModel?.OpenFolderCommand?.Execute(fileOperation);
  73. }
  74. break;
  75. }
  76. }
  77. }
  78. private void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
  79. {
  80. var menuItem = sender as MenuItem;
  81. if (menuItem == null)
  82. return;
  83. var file = menuItem.DataContext as FilesBaseItem;
  84. if (file != null)
  85. {
  86. var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
  87. if (cloudFileUser != null)
  88. {
  89. FileOperation fileOperation = new FileOperation(cloudFileUser, file);
  90. ViewModel?.OpenFileCommand?.Execute(fileOperation);
  91. }
  92. }
  93. }
  94. private void RemoveUserMenuItem_Click(object sender, RoutedEventArgs e)
  95. {
  96. var menuItem = sender as MenuItem;
  97. if (menuItem == null)
  98. return;
  99. var user = menuItem.DataContext as UserBaseItem;
  100. if (user != null)
  101. {
  102. ViewModel?.RemoveUserCommand?.Execute(user);
  103. }
  104. }
  105. private void SelectListFolder_Click(object sender, MouseButtonEventArgs e)
  106. {
  107. var folderItem = (sender as FrameworkElement).DataContext as FolderBaseItem;
  108. if (folderItem != null)
  109. {
  110. ViewModel?.SelectedFolderCommand?.Execute(folderItem);
  111. }
  112. }
  113. private void ListViewItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  114. {
  115. var frame = sender as FrameworkElement;
  116. if (frame != null && frame.DataContext as FilesBaseItem != null)
  117. {
  118. var file = frame.DataContext as FilesBaseItem;
  119. if ((file == null || file.IsFolder == false) && FlyoutMenu != null)
  120. {
  121. FlyoutMenu.DataContext = file;
  122. FlyoutMenu.IsOpen = true;
  123. }
  124. }
  125. }
  126. /// <summary>
  127. /// 打开文件夹,显示文件列表内容
  128. /// </summary>
  129. private void ListViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
  130. {
  131. var frame = sender as FrameworkElement;
  132. if (frame != null && frame.DataContext as FilesBaseItem != null)
  133. {
  134. var file = frame.DataContext as FilesBaseItem;
  135. if (file != null && file.IsFolder == true)
  136. {
  137. var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
  138. if (cloudFileUser != null)
  139. {
  140. FileOperation fileOperation = new FileOperation(cloudFileUser, file);
  141. ViewModel?.OpenFolderCommand?.Execute(fileOperation);
  142. }
  143. }
  144. }
  145. }
  146. private void userItem_PreviewMouseRightButtonDown(object sender, MouseButtonEventArgs e)
  147. {
  148. var frame = sender as FrameworkElement;
  149. if (frame != null && frame.DataContext as UserBaseItem != null)
  150. {
  151. var user = frame.DataContext as UserBaseItem;
  152. if (user != null && UserFlyoutMenu != null)
  153. {
  154. UserFlyoutMenu.DataContext = user;
  155. UserFlyoutMenu.IsOpen = true;
  156. }
  157. }
  158. }
  159. private void UpLoadFileBtn_Click(object sender, RoutedEventArgs e)
  160. {
  161. var folder = ListFolder.Items[ListFolder.Items.Count - 1] as FolderBaseItem;
  162. if (folder != null && folder.Operation != null)
  163. {
  164. FileOperation fileOperation = new FileOperation(CurrentUser, folder.Operation.DoFile);
  165. ViewModel?.UpLoadFileCommand?.Execute(fileOperation);
  166. }
  167. }
  168. }
  169. }