Browse Source

云文档 - 文件列表点击文件夹,更新该文件夹下的文件列表

chenrongqian 2 years ago
parent
commit
4997ac965f

+ 39 - 11
PDF Office/Model/CloudDrive/CloudFiles.cs

@@ -33,7 +33,7 @@ namespace PDF_Office.Model.CloudDrive
         }
     }
 
-    #region 公有云盘
+    #region 云盘基类
 
     /// <summary>
     /// 用户信息
@@ -47,6 +47,13 @@ namespace PDF_Office.Model.CloudDrive
         public string UserAccount { get; set; }
     }
 
+    public class FolderBaseItem
+    {
+        public FileOperation Operation { get; set; }
+        public int Level { get; set; }
+        public string FolderName { get; set; }
+    }
+
     /// <summary>
     /// 用户云盘
     /// </summary>
@@ -56,15 +63,6 @@ namespace PDF_Office.Model.CloudDrive
         public CloudType cloudType { get; set; }
     }
 
-    #endregion
-
-    #region GooglrDrive
-    //文件夹
-    public class GoogleDriveFolder
-    {
-        public string fileId { get; set; }
-        public int Level { get; set; }
-    }
     public class FilesBaseItem
     {
         public string Id { get; set; }
@@ -76,6 +74,17 @@ namespace PDF_Office.Model.CloudDrive
         public DateTime? CreatedTime { get; set; }
     }
 
+    #endregion
+
+    #region GooglrDrive
+    //文件夹
+    public class GoogleDriveFolder: FolderBaseItem
+    {
+     
+        
+    }
+
+
     /// <summary>
     /// 谷歌云盘的文件
     /// </summary>
@@ -87,7 +96,7 @@ namespace PDF_Office.Model.CloudDrive
     #endregion
 
 
-    #region GooglrDrive
+    #region DropbBox
 
     /// <summary>
     /// 谷歌云盘的文件
@@ -96,6 +105,25 @@ namespace PDF_Office.Model.CloudDrive
     {
 
     }
+    public class DropbBoxFolder : FolderBaseItem
+    {
+
+
+    }
+
+    /// <summary>
+    /// 指定某云盘某用户,对文件的操作
+    /// </summary>
+    public class FileOperation
+    {
+        public UserBaseItem User { get; set; }
+        public FilesBaseItem DoFile { get; set; }
+        public FileOperation(UserBaseItem user, FilesBaseItem doFile)
+        {
+            User = user;
+            DoFile = doFile;
+        }
+    }
 
     #endregion
 

+ 1 - 1
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveContentViewModel.cs

@@ -16,7 +16,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         public DelegateCommand<CloudBoxItem> CheckDriveCommand { get; set; }
         public DelegateCommand<CloudBoxItem> CheckDriveLoginUserCommand { get; set; }
 
-        private CloudDriveManager Manager =>CloudDriveManager.GetInstance();
+        private CloudDriveManager Manager =>CloudDriveManager.CloudManager;
         public event EventHandler<bool> IshowContentHandler;
       
         public CloudDriveContentViewModel()

+ 95 - 11
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveManager.cs

@@ -1,4 +1,6 @@
-using PDF_Office.Model.CloudDrive;
+using PDF_Office.Helper;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.Properties;
 using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
 using System;
 using System.Collections.Generic;
@@ -18,21 +20,13 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         #region 云盘类型
         public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
         public DropbBoxManager DropbBox => DropbBoxManager.DropbBox;
-
+       
         #endregion
 
         public CloudType cloudType;
-       // public ObservableCollection<>
 
         private static CloudDriveManager instance;
-
-        public static CloudDriveManager GetInstance()
-        {
-            if (instance == null)
-                instance = new CloudDriveManager();
-
-            return instance;
-        }
+        public static CloudDriveManager CloudManager => instance ?? (instance = new CloudDriveManager());
         private CloudDriveManager()
         {
         }
@@ -55,6 +49,96 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
             return false;
         }
 
+        public async Task<ObservableCollection<FilesBaseItem>> OpenFolder(FileOperation fileOperation)
+        {
+            ObservableCollection<FilesBaseItem> FilesList = null;
+            switch (fileOperation.User.cloudType)
+            {
+                case CloudType.GoogleDrive:
+                    {
+                        var list = await GoogleDrive.GetFolder(fileOperation);
+                        FilesList = new ObservableCollection<FilesBaseItem>();
+                        foreach (var item in list)
+                        {
+                            FilesList.Add(item);
+                        }
+                    }
+
+                    break;
+                case CloudType.DropBox:
+                    {
+                        var list = await DropbBox.GetFolder(fileOperation);
+                        FilesList = new ObservableCollection<FilesBaseItem>();
+                        foreach (var item in list)
+                        {
+                            FilesList.Add(item);
+                        }
+                    }
+                    break;
+            }
+
+            return FilesList;
+        }
+
+        public async Task<bool> OpenFile(FileOperation fileOperation)
+        {
+            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
+            string tempPath = "";
+            switch (fileOperation.User.cloudType)
+            {
+                case CloudType.GoogleDrive:
+                    tempPath = await GoogleDrive.DownloadGoogleFile(fileOperation, docPath);
+                    break;
+                case CloudType.DropBox:
+                    tempPath = await DropbBox.DownloadFile(fileOperation, docPath);
+                    break;
+            }
+
+            if(string.IsNullOrEmpty(tempPath) == false)
+            {
+                string[] filePaths = { tempPath };
+                await Task.Delay(3);
+                LoadPdfViewer(filePaths);
+            }
+
+            return false;
+        }
+
+        public void LoadPdfViewer(string[] filePaths)
+        {
+            var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
+            if (filePaths.Count() == 1)
+            {
+                if (App.OpenedFileList.Contains(filePaths[0]))
+                {
+                    App.mainWindowViewModel.SelectItem(filePaths[0]);
+                }
+                else
+                {
+                    content.OpenFile(filePaths[0]);
+                }
+                ToolMethod.SetFileThumbImg(filePaths[0]);
+            }
+            else
+            {
+                var fileList = filePaths.ToList().Where(x => !App.OpenedFileList.Exists(y => y == x)).ToList();
+                if (fileList.Count <= 0)
+                    return;
+
+                content.OpenFile(filePaths[0]);
+                for (int i = 1; i < fileList.Count(); i++)
+                {
+                    if (!App.OpenedFileList.Contains(fileList[i]))
+                    {
+                        App.mainWindowViewModel.AddTabItem(fileList[i]);
+                    }
+                    ToolMethod.SetFileThumbImg(fileList[i]);
+                }
+            }
+
+            Settings.Default.Save();
+        }
+
         public bool LoadedUsers()
         {
             bool isUsers = false;

+ 28 - 12
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/DropbBoxManager.cs

@@ -30,17 +30,8 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         {
             bool result = false;
             DropbBoxUserItem dropbBoxUserItem = new DropbBoxUserItem();
+            dropbBoxUserItem.cloudType = CloudType.DropBox;
             result = await dropbBoxUserItem.LoginUser();
-            if(result)
-            {
-                dropbBoxUserItem.cloudType = CloudType.DropBox;
-                   UserInfo user = new UserInfo();
-                user.Name = "DropBox测试" + (Cloud.CloudLists.Count + 1).ToString();
-                dropbBoxUserItem.userInfo = user;
-
-                Cloud.CloudLists.Add(dropbBoxUserItem);
-
-            }
             return result;
         }
 
@@ -71,15 +62,40 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
         }
 
-        public void GetFolders()
+        public async Task<List<DropbBoxFiles>> GetFolder(FileOperation fileOperation)
         {
-
+            var user = fileOperation.User as DropbBoxUserItem;
+            if (user != null)
+            {
+                if (fileOperation.DoFile == null)
+                {
+                    return await user.RefreshList();
+                }
+                else
+                {
+                    return await user.RefreshList((fileOperation.DoFile as DropbBoxFiles).Id);
+                }
+              
+            }
+            return null;
         }
 
         public void UpLoad()
         {
 
         }
+
+        public async Task<string> DownloadFile(FileOperation fileOperation, string savePath)
+        {
+            string result = "";
+            var user = fileOperation.User as DropbBoxUserItem;
+            if (user != null)
+            {
+                result = await user.Download((fileOperation.DoFile as DropbBoxFiles).Name, savePath);
+               
+            }
+            return result;
+        }
         #endregion
 
 

+ 21 - 2
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/DropbBoxUserItem.cs

@@ -26,7 +26,15 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
             if (client == null)
                 return false;
             else
+            {
+                UserInfo user = new UserInfo();
+                user.UserAccount = "DropBox测试" + (Cloud.CloudLists.Count + 1).ToString();
+                userInfo = user;
+
+                Cloud.CloudLists.Add(this);
                 return true;
+            }
+                
         }
 
         public async Task<List<DropbBoxFiles>> RefreshList(string path = "")
@@ -40,9 +48,20 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                 {
                     DropbBoxFiles dropbBoxFiles = new DropbBoxFiles();
                     dropbBoxFiles.Name = file.Name;
-                    dropbBoxFiles.Id = file.ParentSharedFolderId;
                     dropbBoxFiles.IsFolder = file.IsFolder;
-                    dropbBoxFiles.MimeType = ".pdf";
+                    if (file.IsFolder)
+                    {
+                        if(file.AsFolder != null)
+                        dropbBoxFiles.Id = file.AsFolder.Id;
+                        dropbBoxFiles.MimeType = ".pdf";
+                    }
+                    else
+                    {
+                        if(file.AsFile != null)
+                        dropbBoxFiles.Id = file.AsFile.Id;
+                        dropbBoxFiles.MimeType = ".pdf";
+                    }
+                   
                     FileList.Add(dropbBoxFiles);
                 }
             }

+ 29 - 0
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/GoogleDriveManager.cs

@@ -98,5 +98,34 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
         }
 
         #endregion
+
+        #region  文件
+
+        public async Task<string> DownloadGoogleFile(FileOperation fileOperation, string savePath)
+        {
+            string result = "";
+            var user = fileOperation.User as GoogleDriveUserItem;
+            if(user != null)
+            {
+                result = await user.DownloadGoogleFile(fileOperation.DoFile as GoogleDriveFiles, savePath);
+            }
+            return result;
+        }
+        
+        public async Task<List<GoogleDriveFiles>> GetFolder(FileOperation fileOperation)
+        {
+            var user = fileOperation.User as GoogleDriveUserItem;
+            if (user != null)
+            {
+                if (fileOperation.DoFile == null)
+                {
+                    return await user.GetDriveFiles(user.Service);
+                }
+                else
+                    return await user.GetDriveFiles(user.Service, (fileOperation.DoFile as GoogleDriveFiles).Id);
+            }
+            return null;
+        }
+        #endregion
     }
 }

+ 11 - 11
PDF Office/ViewModels/HomePanel/CloudDrive/CloudDriveType/GoogleDriveUserItem.cs

@@ -7,6 +7,7 @@ using Google.Apis.Util.Store;
 using PDF_Office.Model.CloudDrive;
 using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.IO;
 using System.Linq;
 using System.Text;
@@ -24,7 +25,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
        
         public  DriveService Service { get; set; }//Google提供服务
         private List<GoogleDriveFiles> FilesList = new List<GoogleDriveFiles>();//文件
-        private List<GoogleDriveFolder> FolderList = new List<GoogleDriveFolder>();//文件
+      //  private List<GoogleDriveFolder> FolderList = new List<GoogleDriveFolder>();//文件
         public UserCredential CurrentCredential { get; set; }//当前用户访问令牌
 
         public GoogleDriveUserItem()
@@ -124,7 +125,7 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
 
             //get file list.
             // String pageToken = null;
-            List<GoogleDriveFiles> FileList = new List<GoogleDriveFiles>();
+            List<GoogleDriveFiles> filelist = new List<GoogleDriveFiles>();
 
             IList<Google.Apis.Drive.v3.Data.File> files = result.Files;
 
@@ -151,12 +152,11 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                         {
                             if (file.Parents != null)
                             {
-
                                 level = file.Parents.Count;
-                                var folderItem = new GoogleDriveFolder();
-                                folderItem.Level = level;
-                                folderItem.fileId = file.Id;
-                                FolderList.Add(folderItem);
+                                //var folderItem = new GoogleDriveFolder();
+                                //folderItem.Level = level;
+                                //folderItem.fileId = file.Id;
+                                //FolderList.Add(folderItem);
                             }
                         }
                         else
@@ -165,15 +165,15 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType
                         }
 
                         File.Level = level;
-                        FileList.Add(File);
+                        filelist.Add(File);
                     }
 
                 }
 
             }
-            if(parentFilesId == null)
-            this.FilesList = FileList;
-            return FileList;
+            this.FilesList.Clear();
+            this.FilesList = filelist;
+            return filelist;
         }
 
         private void SearchParentFiles()

+ 93 - 49
PDF Office/ViewModels/HomePanel/CloudDrive/CloudFilesContentViewModel.cs

@@ -1,4 +1,6 @@
-using PDF_Office.Model.CloudDrive;
+using PDF_Office.Helper;
+using PDF_Office.Model.CloudDrive;
+using PDF_Office.Properties;
 using PDF_Office.ViewModels.HomePanel.CloudDrive.CloudDriveType;
 using Prism.Commands;
 using Prism.Mvvm;
@@ -11,26 +13,41 @@ using System.Threading.Tasks;
 
 namespace PDF_Office.ViewModels.HomePanel.CloudDrive
 {
-    public class FolderItem
-    {
-        public int FolderTreeId { get; set; }
-        public string FolderName { get; set; }
-        public int FolderType { get; set; }
-    }
+
     //各云盘事件
     public class CloudFilesContentViewModel : BindableBase
     {
-     
-        public ObservableCollection<FolderItem> FolderItems { get; set; }
+        #region 云盘变量
+        public CloudDriveManager CloudManager => CloudDriveManager.CloudManager;
+        private ObservableCollection<FolderBaseItem> _folderItems = new ObservableCollection<FolderBaseItem>();
+        public ObservableCollection<FolderBaseItem> FolderItems
+        {
+            get { return _folderItems; }
+            set { SetProperty (ref _folderItems, value); }
+        }
+        private ObservableCollection<FilesBaseItem> _filesList = new ObservableCollection<FilesBaseItem>();
+        public ObservableCollection<FilesBaseItem> FilesList
+        {
+            get { return _filesList; }
+            set { SetProperty(ref _filesList, value); }
+        }
+      
+        private CloudType _currentCloudType = CloudType.GoogleDrive;
+        public CloudType CurrentCloudType
+        {
+            get { return _currentCloudType; }
+            set { SetProperty(ref _currentCloudType, value); }
+        }
+        #endregion
 
-        public GoogleDriveManager GoogleDrive => GoogleDriveManager.GoogleDrive;
-        public DropbBoxManager DropbBox => DropbBoxManager.DropbBox;
-        public DelegateCommand OpenCloudDriveCommand { get; set; }
+        #region  事件
+        public DelegateCommand<FileOperation> OpenFileCommand { get; set; }
+        public DelegateCommand<FileOperation> OpenFolderCommand { get; set; }
         public DelegateCommand CheckDriveUsersCommand { get; set; }
+        public DelegateCommand<CloudBoxItem> LoginCommand { get; set; }
 
-        public DelegateCommand<CloudBoxItem> CheckDriveCommand { get; set; }
-
-        public DelegateCommand<FolderItem> SelectedFolderCommand { get; set; }
+        public DelegateCommand<FolderBaseItem> SelectedFolderCommand { get; set; }
+        #endregion
 
         public CloudFilesContentViewModel()
         {
@@ -40,19 +57,24 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
 
         private void InitCommand()
         {
-            OpenCloudDriveCommand = new DelegateCommand(OpenCloudDrive_Click);
-            OpenCloudDriveCommand = new DelegateCommand(CheckDriveUsers);
-
-            CheckDriveCommand = new DelegateCommand<CloudBoxItem>(LoginUser);
-            SelectedFolderCommand = new DelegateCommand<FolderItem>(SelectedFolder_Command);
+          //  OpenFileCommand = new DelegateCommand(OpenCloudDrive_Click);
+            OpenFileCommand = new DelegateCommand<FileOperation>(OpenFile);
+            OpenFolderCommand = new DelegateCommand<FileOperation>(OpenFolder);
+            LoginCommand = new DelegateCommand<CloudBoxItem>(LoginUser);
+            SelectedFolderCommand = new DelegateCommand<FolderBaseItem>(SelectedFolder_Command);
         }
 
-        private void SelectedFolder_Command(FolderItem obj)
+        private void SelectedFolder_Command(FolderBaseItem obj)
         {
            if(obj != null)
             {
+                var objIndex = FolderItems.IndexOf(obj);
                 var count = FolderItems.Count;
-                if (obj.FolderTreeId == 0)
+
+                if (objIndex == count - 1)
+                    return;
+
+                if (obj.Level == -1)
                 {
                     
                     for(int i = 1; i < count; i++)
@@ -62,7 +84,6 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
                 }
                 else
                 {
-                    var objIndex = FolderItems.IndexOf(obj);
                     if(objIndex != -1)
                     {
                         for(int i = count - 1; i > objIndex; i--)
@@ -71,31 +92,19 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
                         }
                     }
                 }
+
+                SelectedFolder(obj.Operation);
             }
         }
 
         private void InitVariable()
         {
-            FolderItems = new ObservableCollection<FolderItem>();
-            FolderItems.Add(new FolderItem() { FolderName = "云文档", FolderTreeId = 0 });
-            FolderItems.Add(new FolderItem() { FolderName = "文件夹1", FolderTreeId = 1 });
-            FolderItems.Add(new FolderItem() { FolderName = "文件夹2", FolderTreeId = 2 });
-            FolderItems.Add(new FolderItem() { FolderName = "文件夹3", FolderTreeId = 3 });
-            FolderItems.Add(new FolderItem() { FolderName = "文件夹4", FolderTreeId = 4 });
-            FolderItems.Add(new FolderItem() { FolderName = "文件夹5", FolderTreeId = 5 });
+           
         }
 
         public async void CheckDrive(CloudBoxItem cloudDriveItem)
         {
-            switch (cloudDriveItem.CloudDiskType)
-            {
-                case CloudType.GoogleDrive:
-                     await GoogleDrive.LoginUserCount();
-                    break;
-                case CloudType.DropBox:
-                     await DropbBox.LoginUser();
-                    break;
-            }
+            await CloudManager.LoginUser(cloudDriveItem.CloudDiskType);
         }
 
         #region 云盘公用接口
@@ -121,15 +130,9 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         /// </summary>
         public async void LoginUser(CloudBoxItem cloudDriveItem)
         {
-            switch (cloudDriveItem.CloudDiskType)
-            {
-                case CloudType.GoogleDrive:
-                    await GoogleDrive.LoginUserCount();
-                    break;
-                case CloudType.DropBox:
-                    await DropbBox.LoginUser();
-                    break;
-            }
+            if (cloudDriveItem != null)
+                await CloudManager.LoginUser(cloudDriveItem.CloudDiskType);
+            
         }
 
         /// <summary>
@@ -173,11 +176,52 @@ namespace PDF_Office.ViewModels.HomePanel.CloudDrive
         /// <summary>
         /// 下载并打开文件
         /// </summary>
-        public void OpenFile()
+        public async void OpenFile(FileOperation fileOperation)
         {
+            await CloudManager.OpenFile(fileOperation);
+        }
+
+        public async void OpenFolder(FileOperation fileOperation)
+        {
+            FilesList = await CloudManager.OpenFolder(fileOperation);
+            AddFolder(fileOperation);
+        }
 
+        /// <summary>
+        /// 在文件列表点击文件夹,而更新文件列表
+        /// </summary>
+        /// <param name="fileOperation"></param>
+        public async void SelectedFolder(FileOperation fileOperation)
+        {
+            FilesList = await CloudManager.OpenFolder(fileOperation);
         }
 
+        private void AddFolder(FileOperation folder)
+        {
+          
+            if (folder != null)
+            {
+               if(folder.DoFile != null)
+                {
+                    FolderBaseItem folderItem = new FolderBaseItem();
+                    folderItem.FolderName = folder.DoFile.Name;
+                    folderItem.Level = folder.DoFile.Level;
+                    folderItem.Operation = folder;
+                    FolderItems.Add(folderItem);
+                }
+                else
+                {
+                    FolderItems.Clear();
+                    FolderBaseItem folderItem = new FolderBaseItem();
+                    folderItem.FolderName = "云文档";
+                    folderItem.Level = -1;
+                    folderItem.Operation = folder;
+                    FolderItems.Add(folderItem);
+                }
+            }
+        }
+
+
         /// <summary>
         /// 上传文件
         /// </summary>

+ 15 - 6
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml

@@ -4,6 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:DataConvert ="clr-namespace:PDF_Office.DataConvert"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:prism ="http://prismlibrary.com/"
              prism:ViewModelLocator.AutoWireViewModel="True"
              xmlns:local="clr-namespace:PDF_Office.Views.HomePanel.CloudDrive"
@@ -12,8 +13,7 @@
     <UserControl.Resources>
         <DataConvert:BoolToVisible x:Key="BoolToVisible"/>
         <DataConvert:InvertBoolToVisibleConvert x:Key="InvertBoolToVisibleConvert"/>
-        <ContextMenu x:Key="FlyoutMenu" FontSize="14"
-                         >
+        <ContextMenu x:Key="FlyoutMenu" FontSize="14">
             <ContextMenu.ItemContainerStyle>
                 <Style TargetType="MenuItem">
                     <Setter Property="Padding" Value="0,7,0,7"/>
@@ -34,7 +34,10 @@
         </ContextMenu>
 
         <Style x:Key="itemstyle" TargetType="{x:Type ListViewItem}">
-            <Setter Property="ContextMenu" Value="{StaticResource FlyoutMenu}"></Setter>
+            <EventSetter Event="PreviewMouseRightButtonDown"
+                             Handler="ListViewItem_PreviewMouseRightButtonDown"/>
+            <EventSetter Event="PreviewMouseDoubleClick"
+                             Handler="ListViewItem_PreviewMouseDoubleClick"/>
         </Style>
     </UserControl.Resources>
     <Grid>
@@ -71,7 +74,7 @@
                 </ListBox.ItemContainerStyle>
             </ListBox>
             <StackPanel Grid.Column="1" Orientation="Horizontal">
-                <ComboBox x:Name="combCloudDrive" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right" SelectionChanged="combCloudDrive_SelectionChanged">
+                <ComboBox x:Name="combCloudDrive" Grid.Column="1" Width="115" Height="32" Background="Wheat" HorizontalAlignment="Right">
                     <ComboBox.ItemTemplate>
                         <DataTemplate>
                             <Border Background="#DBDBDB">
@@ -79,8 +82,12 @@
                             </Border>
                         </DataTemplate>
                     </ComboBox.ItemTemplate>
+                    <i:Interaction.Triggers>
+                        <i:EventTrigger EventName="SelectionChanged">
+                            <i:InvokeCommandAction Command="{Binding LoginCommand}"  CommandParameter="{Binding ElementName=combCloudDrive,Path=SelectedItem}"/>
+                        </i:EventTrigger>
+                    </i:Interaction.Triggers>
                 </ComboBox>
-                <Button Content="Test" Click="Button_Click"/>
             </StackPanel>
            
         </Grid>
@@ -102,7 +109,9 @@
                 </ListView.ItemTemplate>
             </ListView>
 
-            <ListView x:Name="ListvmFiles" Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource itemstyle}">
+            <ListView x:Name="ListvmFiles" Grid.Column="1" ScrollViewer.VerticalScrollBarVisibility="Auto" 
+                      ItemsSource="{Binding FilesList}"
+                      ItemContainerStyle="{StaticResource itemstyle}">
                 <ListView.ItemTemplate>
                     <DataTemplate>
                         <Grid>

+ 57 - 80
PDF Office/Views/HomePanel/CloudDrive/CloudFilesContent.xaml.cs

@@ -27,7 +27,7 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
     {
      
         private CloudFilesContentViewModel ViewModel => DataContext as CloudFilesContentViewModel;
-
+        private ContextMenu FlyoutMenu;
         private List<CloudBoxItem> CloudeDrives = new List<CloudBoxItem>();
         private List<string> pathFolder = new List<string>();
 
@@ -36,6 +36,7 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
         {
             InitializeComponent();
             InitCloudDrive();
+            this.Loaded -= usercontrol_Loaded;
             this.Loaded += usercontrol_Loaded;
         }
 
@@ -44,6 +45,7 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
             CloudeDrives = Cloud.InitCloudBoxs();
             combCloudDrive.ItemsSource = CloudeDrives;
             combCloudDrive.SelectedIndex = 0;
+            FlyoutMenu = Resources["FlyoutMenu"] as ContextMenu;
         }
 
         private void usercontrol_Loaded(object sender, RoutedEventArgs e)
@@ -54,34 +56,12 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
                 if (Listusers.ItemsSource == null)
                     Listusers.ItemsSource = Cloud.CloudLists;
             }
-            InitListFolder();
-        }
-
-        private void InitListFolder()
-        {
-         
-
-        }
-
-        private void combCloudDrive_SelectionChanged(object sender, SelectionChangedEventArgs e)
-        {
-            var cloudDriveItem = combCloudDrive.SelectedItem as CloudBoxItem;
-            if (cloudDriveItem != null)
-            {
-                ViewModel.CheckDriveCommand.Execute(cloudDriveItem);
-            }
         }
 
 
-        private void Button_Click(object sender, RoutedEventArgs e)
-        {
-
-         
-        }
-
         private UserBaseItem CurrentUser;
 
-        private async void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        private void Listusers_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
             if(cloudFileUser != null)
@@ -91,30 +71,16 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
                 switch(cloudFileUser.cloudType)
                 {
                     case CloudType.GoogleDrive:
-                        if ((CurrentUser as GoogleDriveUserItem) != null)
                         {
-                            var item = CurrentUser as GoogleDriveUserItem;
-                            var files = await item.GetDriveFiles(item.Service);
-                            ObservableCollection<GoogleDriveFiles> filesList = new ObservableCollection<GoogleDriveFiles>();
-                            foreach (var file in files)
-                            {
-                                    filesList.Add(file);
-                            }
-                            ListvmFiles.ItemsSource = filesList;
+                            FileOperation fileOperation = new FileOperation(cloudFileUser, null);
+                            ViewModel?.OpenFolderCommand?.Execute(fileOperation);
                         }
                         break;
 
                     case CloudType.DropBox:
-                        if ((CurrentUser as DropbBoxUserItem) != null)
                         {
-                            var item = CurrentUser as DropbBoxUserItem;
-                            var files = await item.RefreshList();
-                            ObservableCollection<DropbBoxFiles> filesList = new ObservableCollection<DropbBoxFiles>();
-                            foreach (var file in files)
-                            {
-                                    filesList.Add(file);
-                            }
-                            ListvmFiles.ItemsSource = filesList;
+                            FileOperation fileOperation = new FileOperation(cloudFileUser, null);
+                            ViewModel?.OpenFolderCommand?.Execute(fileOperation);
                         }
                         break;
 
@@ -123,59 +89,70 @@ namespace PDF_Office.Views.HomePanel.CloudDrive
             }
         }
 
-        private async void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
+        private void OpenDocMenuItem_Click(object sender, RoutedEventArgs e)
         {
             var menuItem = sender as MenuItem;
             if (menuItem == null)
                 return;
 
-            string docPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
-
-            switch (CurrentUser.cloudType)
+            var file = menuItem.DataContext as FilesBaseItem;
+            if (file != null)
             {
-                case CloudType.GoogleDrive:
-               
-                    var item = menuItem.DataContext as GoogleDriveFiles;
-                    if (menuItem == null || item == null)
-                        return;
-
-                    var googleItem = CurrentUser as GoogleDriveUserItem;
-                    var filename = await googleItem.DownloadGoogleFile(item, docPath);
-                    if (filename != null)
-                    {
-                        string[] filePaths = { filename };
-                        await Task.Delay(3);
-                        MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
-                        parentWindow.LoadPdfViewer(filePaths);
-                    }
-                    break;
-
-                case CloudType.DropBox:
-
-                    var file = menuItem.DataContext as DropbBoxFiles;
-                    var dropBoxItem = CurrentUser as DropbBoxUserItem;
-
-                    var dropBoxFileName = await dropBoxItem.Download(file.Name, docPath);
-                    if (dropBoxFileName != null)
-                    {
-                        string[] filePaths = { dropBoxFileName };
-                        await Task.Delay(3);
-                        MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
-                        parentWindow.LoadPdfViewer(filePaths);
-                    }
-                    break;
+                var cloudFileUser = Listusers.SelectedItem as UserBaseItem;
+                if (cloudFileUser != null)
+                {
+                    FileOperation fileOperation = new FileOperation(cloudFileUser, file);
+                    ViewModel?.OpenFileCommand?.Execute(fileOperation);
+                }
 
             }
 
 
+        }
 
+        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 SelectListFolder_Click(object sender, MouseButtonEventArgs e)
+        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.IsOpen = true;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 打开文件夹,显示文件列表内容
+        /// </summary>
+        private void ListViewItem_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
         {
-            var folderItem = (sender as FrameworkElement).DataContext as FolderItem;
-            ViewModel?.SelectedFolderCommand?.Execute(folderItem);
+            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);
+                    }
+                      
+                }
+            }
         }
     }
 }