فهرست منبع

Merge branch 'master' into dev

chenrongqian 2 سال پیش
والد
کامیت
5dba8587a3

+ 99 - 0
PDF Office/DataConvert/FileFormatToIconConvert.cs

@@ -0,0 +1,99 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+using System.Windows.Media.Imaging;
+
+namespace PDF_Office.DataConvert
+{
+    public class DateTimeToStringConvert : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value == null)
+                return null;
+            else
+            {
+                if (value is DateTime)
+                {
+                    var datetime = (DateTime)value;
+                    return datetime.Year + "-" + datetime.Month +"-"+ datetime.Day + "  " + datetime.ToString("HH:mm:ss");
+                }
+                return null;
+
+            }
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+    public class FilePathToSizeConvert : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            if (value == null)
+                return null;
+            else
+            {
+                if (value is string)
+                {
+                   return GetFileSize((string)value);
+                }
+                return null;
+
+            }
+        }
+
+        public string GetFileSize(string path)
+        {
+            System.IO.FileInfo fileInfo = null;
+            try
+            {
+                fileInfo = new System.IO.FileInfo(path);
+            }
+            catch
+            {
+                return "0KB";
+            }
+            if (fileInfo != null && fileInfo.Exists)
+            {
+               
+                var size = Math.Round(fileInfo.Length / 1024.0, 0);
+                if (size > 1024)
+                {
+                   var sizeDouble = Math.Round(size / 1024.0,2);
+                    if(sizeDouble > 1024)
+                    {
+                        sizeDouble = Math.Round(sizeDouble / 1024.0,2);
+                        return sizeDouble + "G";
+                    }
+                    else
+                    return sizeDouble + "M";
+                }
+                else
+                {
+                    
+                    return (int)System.Math.Ceiling(size) + "KB";
+                }
+               
+            }
+            else
+            {
+                return "0KB";
+            }
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            throw new NotImplementedException();
+        }
+    }
+
+
+}

+ 15 - 15
PDF Office/Helper/SettingHelper.cs

@@ -92,23 +92,23 @@ namespace PDF_Office.Helper
 
         public static void RemoveAllRecentOpenFiles()
         {
-            //if (Settings.Default.RecentOpenFiles == null || Settings.Default.RecentOpenFiles.Count == 0)
-            //    return;
+            if (Settings.Default.RecentOpenFiles == null || Settings.Default.RecentOpenFiles.Count == 0)
+                return;
 
-            //string folderPath =System.IO.Path.Combine(App.CurrentPath, "CoverImage");
-            //DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
-            //if(directoryInfo.Exists)
-            //{
-            //    var files = directoryInfo.GetFiles();
-            //    foreach(var file in files)
-            //    {
-            //        if (file.Exists)
-            //            file.Delete();
-            //    }
-            //}
+            string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
+            DirectoryInfo directoryInfo = new DirectoryInfo(folderPath);
+            if (directoryInfo.Exists)
+            {
+                var files = directoryInfo.GetFiles();
+                foreach (var file in files)
+                {
+                    if (file.Exists)
+                        file.Delete();
+                }
+            }
 
-            //Settings.Default.RecentOpenFiles.Clear();
-            //Settings.Default.Save();
+            Settings.Default.RecentOpenFiles.Clear();
+            Settings.Default.Save();
         }
 
         public static OpenFileInfo GetFileInfo(string filePath)

+ 192 - 0
PDF Office/Helper/ToolMethod.cs

@@ -0,0 +1,192 @@
+using ComPDFKit.PDFDocument;
+using ComPDFKit.PDFPage;
+using PDF_Office.CustomControl;
+using PDFSettings.Settings;
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Media.Imaging;
+
+namespace PDF_Office.Helper
+{
+    public static class ToolMethod
+    {
+        /// <summary>
+        /// 返回跟DPi 无关的图片
+        /// </summary>
+        /// <param name="document"></param>
+        /// <param name="width"></param>
+        /// <param name="height"></param>
+        /// <param name="pageIndex"></param>
+        /// <returns></returns>
+        public static async Task<Bitmap> RenderPageBitmap(CPDFDocument document,int width,int height,int pageIndex,bool annot,bool form)
+        {
+            if (width <= 0.0 || height<= 0.0)
+            {
+                return null;
+            }
+
+            Bitmap bitmap = new Bitmap((int)width, (int)height, PixelFormat.Format32bppArgb);
+            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, (int)width, (int)height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
+            try
+            {
+                CPDFPage kMPDFPage = document.PageAtIndex(pageIndex);
+                await Task.Run(()=> kMPDFPage.RenderPageBitmap(0,0,width,height, uint.MaxValue, bitmapData.Scan0,annot?1:0,form));
+               // kMPDFPage.RenderPageBitmapWithMatrix((float)1, new System.Windows.Rect(), uint.MaxValue, bitmapData.Scan0, 1, form: true);
+            }
+            catch (Exception)
+            {
+                return null;
+            }
+
+            bitmap.UnlockBits(bitmapData);
+            return bitmap;
+        }
+
+        public static Bitmap RenderPageBitmapNoWait(CPDFDocument document, int width, int height, int pageIndex,bool annote,bool form,uint custombackground=0xFFFFFFFF)
+        {
+            if (width <= 0.0 || height <= 0.0)
+            {
+                return null;
+            }
+
+            Bitmap bitmap = new Bitmap((int)width, (int)height, PixelFormat.Format32bppArgb);
+            BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, (int)width, (int)height), ImageLockMode.ReadWrite, bitmap.PixelFormat);
+            try
+            {
+                CPDFPage kMPDFPage = document.PageAtIndex(pageIndex);
+                //1-显示注释 0-不显示注释  form-true 显示表单   form-false  不显示表单
+                if (custombackground != 0xFFFFFFFF)
+                {
+                    kMPDFPage.RenderPageBitmap(0, 0, width, height, custombackground, bitmapData.Scan0, annote ? 1 : 0, form);
+                }
+                else
+                {
+                    kMPDFPage.RenderPageBitmap(0, 0, width, height, uint.MaxValue, bitmapData.Scan0, annote ? 1 : 0, form);
+                }
+                //kMPDFPage.RenderPageBitmapWithMatrix((float)1, new System.Windows.Rect(), uint.MaxValue, bitmapData.Scan0, 1, form: true);
+            }
+            catch (Exception)
+            {
+                return null;
+            }
+
+            bitmap.UnlockBits(bitmapData);
+            return bitmap;
+        }
+
+
+        public static void SetFileThumbImg(string fileName)
+        {
+
+            bool isNewDocument = false;
+            //检查是否是新文档
+            OpenFileInfo isnew = SettingHelper.GetFileInfo(fileName);
+            if (isnew == null)
+                isNewDocument = true;
+
+            //检查是否是加密文档  要在open前检查
+            bool isLockedfile = false;
+            CPDFDocument tempdoc = CPDFDocument.InitWithFilePath(fileName);
+            if (tempdoc != null && (bool)(tempdoc.IsLocked))
+                isLockedfile = true;
+
+            OpenFileInfo fileInfo = SettingHelper.GetFileInfo(fileName);
+
+
+            if (fileInfo != null)
+            {
+                try
+                {
+                    if (string.IsNullOrWhiteSpace(fileInfo.ThumbImgPath) || isLockedfile)//未保存文档首页缩略图时,提取第一页当缩略图
+                    {
+                        if (isLockedfile)
+                        {
+                            fileInfo.ThumbImgPath = "pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png";
+                        }
+                        else
+                        {
+                            if (tempdoc.PageCount > 0)
+                            {
+                                var size = tempdoc.GetPageSize(0);
+                                System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(tempdoc, (int)size.Width, (int)size.Height, 0, true, true);
+                                string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
+                                //有可能因为其他原因存在同名文件,导致创建文件夹失败,需要先删除文件
+                                //保险措施(猜测)
+                                if (File.Exists(folderPath))
+                                    File.Delete(folderPath);
+                                DirectoryInfo folder = new DirectoryInfo(folderPath);
+                                if (!folder.Exists)
+                                    folder.Create();
+                                string imageName = Guid.NewGuid().ToString();
+                                string imagePath = System.IO.Path.Combine(folderPath, imageName);
+                                using (FileStream stream = new FileStream(imagePath, FileMode.Create))
+                                {
+                                    bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
+                                }
+                                fileInfo.ThumbImgPath = imagePath;
+                            }
+                        }
+
+
+                    }
+                    else//解锁文件覆盖了加密文件的情况 或者本地缩略图文件被删除
+                    {
+                        if (tempdoc.PageCount > 0 && (!File.Exists(fileInfo.ThumbImgPath) || (!tempdoc.IsEncrypted && fileInfo.ThumbImgPath.Equals("pack://application:,,,/Resources/Image/Home/FilesType/ic_propertybar_file_pdf_lock.png"))))
+                        {
+                            var size = tempdoc.GetPageSize(0);
+                            System.Drawing.Bitmap bitmap = ToolMethod.RenderPageBitmapNoWait(tempdoc, (int)size.Width, (int)size.Height, 0, true, true);
+                            string folderPath = System.IO.Path.Combine(App.CurrentPath, "CoverImage");
+                            if (File.Exists(folderPath))
+                                File.Delete(folderPath);
+                            DirectoryInfo folder = new DirectoryInfo(folderPath);
+                            if (!folder.Exists)
+                                folder.Create();
+                            string imageName = Guid.NewGuid().ToString();
+                            string imagePath = System.IO.Path.Combine(folderPath, imageName);
+                            using (FileStream stream = new FileStream(imagePath, FileMode.Create))
+                            {
+                                bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
+                            }
+                            fileInfo.ThumbImgPath = imagePath;
+                        }
+                    }
+                }
+                catch
+                {
+                    fileInfo.ThumbImgPath = null;
+                    MessageBoxEx.Show("LoadFile_GetThumbnailFailedWarning");
+                }
+            }
+
+        }
+
+
+        public static BitmapImage GetFileThumbImg(string path)
+        {
+            BitmapImage bitmap = new BitmapImage();
+            if (File.Exists(path))
+            {
+                bitmap.BeginInit();
+                bitmap.CacheOption = BitmapCacheOption.OnLoad;
+                using (Stream ms = new MemoryStream(File.ReadAllBytes(path)))
+                {
+                    bitmap.StreamSource = ms;
+                    bitmap.EndInit();
+                    bitmap.Freeze();
+                }
+            }
+            else if (path.Equals("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png"))
+                bitmap = new BitmapImage(new Uri("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png"));
+            else//最近文档 但是删除了缩略图的情况
+                bitmap = new BitmapImage(new Uri("pack://application:,,,/Resources/FilesType/ic_propertybar_file_png_Large.png"));
+            return bitmap;
+        }
+
+    }
+}

+ 3 - 0
PDF Office/PDF Office.csproj

@@ -82,6 +82,7 @@
     <Reference Include="System" />
     <Reference Include="System.Configuration" />
     <Reference Include="System.Data" />
+    <Reference Include="System.Drawing" />
     <Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
       <HintPath>packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
     </Reference>
@@ -117,9 +118,11 @@
     <Compile Include="CustomControl\ToastControl.xaml.cs">
       <DependentUpon>ToastControl.xaml</DependentUpon>
     </Compile>
+    <Compile Include="DataConvert\FileFormatToIconConvert.cs" />
     <Compile Include="EventAggregators\PageEditNotifyEvent.cs" />
     <Compile Include="EventAggregators\PageEditRefreshEvent.cs" />
     <Compile Include="Helper\SettingHelper.cs" />
+    <Compile Include="Helper\ToolMethod.cs" />
     <Compile Include="Model\DialogNames.cs" />
     <Compile Include="CustomControl\SystemControl\InterTabClient.cs" />
     <Compile Include="CustomControl\LoadingControl.xaml.cs">

+ 2 - 2
PDF Office/Styles/ListViewStyle.xaml

@@ -163,7 +163,7 @@
                             </MultiTrigger.Conditions>
                             <Setter TargetName="Bd" Property="Panel.Background" Value="#1A477EDE" />
                             <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#1A477EDE" />
-                            <Setter TargetName="SelectedIcon" Property="Grid.Visibility" Value="Visible" />
+                            <!--<Setter TargetName="SelectedIcon" Property="Grid.Visibility" Value="Visible" />-->
                         </MultiTrigger>
                         <MultiTrigger>
                             <MultiTrigger.Conditions>
@@ -172,7 +172,7 @@
                             </MultiTrigger.Conditions>
                             <Setter TargetName="Bd" Property="Panel.Background" Value="#1A477EDE" />
                             <Setter TargetName="Bd" Property="Border.BorderBrush" Value="#1A477EDE" />
-                            <Setter TargetName="SelectedIcon" Property="Grid.Visibility" Value="Visible" />
+                            <!--<Setter TargetName="SelectedIcon" Property="Grid.Visibility" Value="Visible" />-->
                         </MultiTrigger>
                         <Trigger Property="UIElement.IsEnabled" Value="False">
                             <Setter TargetName="Bd" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />

+ 3 - 0
PDF Office/ViewModels/HomeContentViewModel.cs

@@ -1,5 +1,6 @@
 using Microsoft.Win32;
 using PDF_Office.EventAggregators;
+using PDF_Office.Helper;
 using PDF_Office.Model;
 using Prism.Commands;
 using Prism.Events;
@@ -102,6 +103,7 @@ namespace PDF_Office.ViewModels
                     {
                         mainContentViewModel.OpenFile(openFileDialog.FileName);
                     }
+                    ToolMethod.SetFileThumbImg(openFileDialog.FileName);
                 }
                 else
                 {
@@ -116,6 +118,7 @@ namespace PDF_Office.ViewModels
                         {
                             App.mainWindowViewModel.AddTabItem(fileList[i]);
                         }
+                        ToolMethod.SetFileThumbImg(fileList[i]);
                     }
                 }
                 IsLoading = Visibility.Collapsed;

+ 2 - 1
PDF Office/ViewModels/MainContentViewModel.cs

@@ -137,7 +137,8 @@ namespace PDF_Office.ViewModels
             if (isnew == null)
             {
                 isNewDocument = true;
-                App.OpenedFileList.Add(filePath);
+                if(App.OpenedFileList.Contains(filePath) == false)
+                    App.OpenedFileList.Add(filePath);
                 SettingHelper.SortRecentOpenFiles(filePath);
             }
 

+ 3 - 0
PDF Office/ViewModels/MainWindowViewModel.cs

@@ -131,6 +131,9 @@ namespace PDF_Office.ViewModels
         public void SelectItem(string filepath)
         {
             var item = region.Regions[RegionNames.MainRegion].Views.Where(t => ((t as MainContent).DataContext as MainContentViewModel).FilePath == filepath).FirstOrDefault() as MainContent;
+            if (item == null)
+                return;
+
             region.Regions[RegionNames.MainRegion].Activate(item);
             var behavior = region.Regions[RegionNames.MainRegion].Behaviors[DragablzWindowBehavior.BehaviorKey] as DragablzWindowBehavior;
             if(behavior!=null)

+ 22 - 2
PDF Office/Views/HomePanel/RecentFiles/DocItemControl.xaml.cs

@@ -13,6 +13,9 @@ using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
 using System.IO;
+using PDFSettings.Settings;
+using PDF_Office.Helper;
+using ComPDFKit.PDFDocument;
 
 namespace PDF_Office.Views.HomePanel.RecentFiles
 {
@@ -28,9 +31,26 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
 
         private void Grid_Loaded(object sender, RoutedEventArgs e)
         {
-           
+            var grid = sender as Grid;
+            if (grid != null)
+            {
+                var data = grid.DataContext as OpenFileInfo;
+                if (data == null) return;
+                if (!string.IsNullOrEmpty(data.ThumbImgPath))
+                    CoverImage.Source = ToolMethod.GetFileThumbImg(data.ThumbImgPath);
+                else
+                {
+                    CPDFDocument tempdoc = CPDFDocument.InitWithFilePath(data.FilePath);
+                    if (tempdoc != null && (bool)(tempdoc.IsLocked))
+                    {
+                        CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png");
+                    }
+                    else
+                    CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources//FilesType/ic_propertybar_file_png_Large.png");
+                }
+                  
+            }
         }
 
-       
     }
 }

+ 15 - 17
PDF Office/Views/HomePanel/RecentFiles/DocItemListViewControl.xaml

@@ -4,7 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PDF_Office.Views.HomePanel"
-           
+             xmlns:convert="clr-namespace:PDF_Office.DataConvert"
              mc:Ignorable="d" 
              x:Name="usercontrol"
              d:DesignHeight="450" d:DesignWidth="800"
@@ -14,18 +14,17 @@
              >
     <!--xmlns:convert="clr-namespace:PDFReader_WPF.DataConvert"-->
     <UserControl.Resources>
-        <!--<ResourceDictionary>
+        <ResourceDictionary>
             <ResourceDictionary.MergedDictionaries>
-                <ResourceDictionary Source="../../Resources/Style/OtherControlStyle.xaml"/>
+                <!--<ResourceDictionary Source="../../Resources/Style/OtherControlStyle.xaml"/>-->
             </ResourceDictionary.MergedDictionaries>
-            <convert:FileFormatToIconConvert x:Key="FileFormatToIconConvert"/>
-            <convert:BoolToVisibleConvert x:Key="BoolToVisibleConvert"/>
+            <convert:BoolToVisible x:Key="BoolToVisibleConvert"/>
             <convert:DateTimeToStringConvert x:Key="DateTimeToStringConvert"/>
             <convert:FilePathToSizeConvert x:Key="FilePathToSizeConvert"/>
-        </ResourceDictionary>-->
+        </ResourceDictionary>
     </UserControl.Resources>
-    
-    <Grid HorizontalAlignment="Stretch">
+
+    <Grid HorizontalAlignment="Stretch"  Loaded="Grid_Loaded" DataContext="{Binding}" ToolTip="{Binding FilePath}">
         <Grid.Background>
             <SolidColorBrush Color="White" Opacity="0.01"/>
         </Grid.Background>
@@ -42,20 +41,18 @@
                     <ColumnDefinition />
                 </Grid.ColumnDefinitions>
                 <!--Source="{Binding FileName,Converter={StaticResource FileFormatToIconConvert}}"-->
-                <Image HorizontalAlignment="Left" Width="32" Height="32"/>
-                <StackPanel Grid.Column="1" Margin="8,0,0,0" VerticalAlignment="Center">
-                    <TextBlock x:Name="FileName" Grid.Column="0" VerticalAlignment="Center" Text="{Binding FileName}" FontSize="16" Foreground="Black" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis"/>
-                    <TextBlock x:Name="FilePath" Margin="0,4,0,0" Text="{Binding FilePath}" FontSize="12" Foreground="#FF666666" TextTrimming="WordEllipsis"/>
-                </StackPanel>
+                <Image x:Name="CoverImage" HorizontalAlignment="Left" Width="32" Height="32" RenderOptions.BitmapScalingMode="HighQuality" UseLayoutRounding="True"/>
+                <TextBlock x:Name="FileName"  Grid.Column="1" Margin="8,0,0,0"  VerticalAlignment="Center" Text="{Binding FileName}" FontSize="16" Foreground="Black" HorizontalAlignment="Stretch" TextTrimming="WordEllipsis"/>
             </Grid>
             
+            
             <Grid Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
-            <TextBlock x:Name="lastOpenTime" Grid.Column="1"
+            <TextBlock x:Name="lastOpenTime" Grid.Column="1" Text="{Binding LastOpenTime,Converter={StaticResource DateTimeToStringConvert}}"
                         Foreground="#FF666666" FontSize="14"
                        HorizontalAlignment="Center" VerticalAlignment="Center" TextTrimming="WordEllipsis"
                         />
             <!--Text="{Binding LastOpenTime,Converter={StaticResource DateTimeToStringConvert}}"-->
-            <TextBlock Grid.Column="2"
+            <TextBlock Grid.Column="2" Text="{Binding FilePath,Converter={StaticResource FilePathToSizeConvert}}"
                        Foreground="#FF666666" FontSize="14" 
                        HorizontalAlignment="Center" VerticalAlignment="Center" 
                       />
@@ -65,14 +62,15 @@
                     Orientation="Horizontal" HorizontalAlignment="Right" 
                    >
                 <!--Visibility="{Binding ElementName=usercontrol,Path=IsHoverState,Mode=OneWay,Converter={StaticResource BoolToVisibleConvert}}"-->
-         
-                <Grid x:Name="DeleteGrid" Height="40" Background="Transparent" HorizontalAlignment="Right">
+
+                <Grid x:Name="DeleteGrid" Height="40" Background="Transparent" HorizontalAlignment="Right" Visibility="{Binding ElementName=usercontrol,Path=IsHoverState,Mode=OneWay,Converter={StaticResource BoolToVisibleConvert}}">
                     <Button x:Name="DeleteButton" Height="40" Width="40" 
                         HorizontalAlignment="Right" VerticalContentAlignment="Center"
                         Click="DeleteButton_Click"
                        >
                         <!--Style="{StaticResource PageEditToolBtn}"-->
                         <Grid  RenderTransformOrigin="0.5 0.5">
+                            <TextBlock Text="X"/>
                             <!--<Path Fill="{StaticResource BOTA.Path.Fill}" Data="M8.69231 8L12.5 4.19231L11.8077 3.5L8 7.30769L4.19231 3.5L3.5 4.19231L7.30769 8L3.5 11.8077L4.19231 12.5L8 8.69231L11.8077 12.5L12.5 11.8077L8.69231 8Z"/>-->
                         </Grid>
                     </Button>

+ 28 - 2
PDF Office/Views/HomePanel/RecentFiles/DocItemListViewControl.xaml.cs

@@ -14,7 +14,10 @@ using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using ComPDFKit.PDFDocument;
 using ComPDFKitViewer.PdfViewer;
+using PDF_Office.Helper;
+using PDFSettings.Settings;
 
 namespace PDF_Office.Views.HomePanel.RecentFiles
 {
@@ -37,7 +40,7 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
 
         private void SetLangText()
         {
-            
+
         }
 
         #region UI
@@ -108,8 +111,31 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
 
         private void MenuMore_Loaded(object sender, RoutedEventArgs e)
         {
-      
+
 
         }
+
+        private void Grid_Loaded(object sender, RoutedEventArgs e)
+        {
+            var grid = sender as Grid;
+            if (grid != null)
+            {
+                var data = grid.DataContext as OpenFileInfo;
+                if (data == null) return;
+
+
+                if (File.Exists(data.ThumbImgPath))
+                {
+                    CoverImage.Source = ToolMethod.GetFileThumbImg(data.ThumbImgPath);
+                }
+                else if (data.ThumbImgPath.Equals("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png"))
+                    CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources/FilesType/ic_propertybar_file_pdf_lock.png");
+                else//最近文档 但是删除了缩略图的情况
+                    CoverImage.Source = ToolMethod.GetFileThumbImg("pack://application:,,,/Resources/FilesType/ic_propertybar_file_png_Large.png");
+            }
+
+        }
+
+     
     }
 }

+ 14 - 9
PDF Office/Views/HomePanel/RecentFiles/RecentFilesView.xaml

@@ -114,9 +114,9 @@
             </Style>
 
         </ResourceDictionary>
-      
+
     </UserControl.Resources>
-    
+
     <Grid>
         <Grid>
             <Grid.RowDefinitions>
@@ -125,7 +125,7 @@
                 <RowDefinition />
             </Grid.RowDefinitions>
             <Grid x:Name="GridRecentFilesTile" Margin="32,38,0,13">
-                <TextBlock x:Name="TxbRecentlyTile" Text="Recently" HorizontalAlignment="Left" FontWeight="Semibold" FontSize="24" Padding="0,6,0,0" Margin="0,0,0,0"/>
+                <TextBlock x:Name="TxbRecentlyTile" Text="Recent" HorizontalAlignment="Left" FontWeight="Semibold" FontSize="24" Padding="0,6,0,0" Margin="0,0,0,0"/>
 
                 <StackPanel x:Name="PnlRightBtns" Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,0,0" Orientation="Horizontal" HorizontalAlignment="Right">
 
@@ -145,7 +145,7 @@
                     </customControl:CustomIconToggleBtn>
 
 
-                    <Separator Style="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" Margin="1 0 1 0" Width="1" Height="16" BorderBrush="#1A000000" BorderThickness="1"/>
+                    <Separator  Margin="1 0 1 0" Width="1" Height="16" BorderBrush="#1A000000" BorderThickness="1"/>
 
                     <Button x:Name="BtnDelete" Margin="0" Padding="0,0,0,0" MaxHeight="40" Width="20" Height="20" Background="Transparent" BorderThickness="0" Click="btnDelete_Click"
                          >
@@ -161,6 +161,10 @@
             </Grid>
 
             <Grid  Grid.Row="2">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="799*"/>
+                    <ColumnDefinition Width="*"/>
+                </Grid.ColumnDefinitions>
                 <ListView x:Name="RecentFilesList" Margin="32,0,0,0"
                       VirtualizingPanel.IsVirtualizing="True" 
                       VirtualizingPanel.CacheLengthUnit="Page"
@@ -175,11 +179,11 @@
                       ItemContainerStyle="{StaticResource SubFilesListViewItemStyle}"
                       Style="{StaticResource FilesListViewStyle}"
                       ItemTemplate="{StaticResource listviewItem}"
-                     ItemsPanel="{StaticResource listPanel}"
+                     ItemsPanel="{StaticResource listPanel}" Grid.ColumnSpan="2"
                      >
                 </ListView>
-                
-                 <ListView x:Name="GridRecentFilesList" Margin="32,0,0,0" Visibility="Collapsed"
+
+                <ListView x:Name="GridRecentFilesList" Margin="32,0,0,0" Visibility="Collapsed"
                       VirtualizingPanel.IsVirtualizing="True" 
                       VirtualizingPanel.CacheLengthUnit="Page"
                       VirtualizingPanel.CacheLength="1"
@@ -193,7 +197,7 @@
                       ItemContainerStyle="{StaticResource HomeGridViewItemStyle}"
                       Style="{StaticResource FilesGridViewStyle}"
                       ItemTemplate="{StaticResource gridviewItem}"
-                     ItemsPanel="{StaticResource gridPanel}"
+                     ItemsPanel="{StaticResource gridPanel}" Grid.ColumnSpan="2"
                      >
                 </ListView>
 
@@ -212,7 +216,8 @@
                 </StackPanel>
 
             </StackPanel>
+
         </Grid>
     </Grid>
-    
+
 </UserControl>

+ 3 - 1
PDF Office/Views/HomePanel/RecentFiles/RecentFilesView.xaml.cs

@@ -9,6 +9,7 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.Diagnostics;
 using System.IO;
+using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -334,7 +335,7 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
 
         }
 
-        private void OpenFiles_Click(object sender, RoutedEventArgs e)
+        private async void OpenFiles_Click(object sender, RoutedEventArgs e)
         {
 
             var dlg = new OpenFileDialog();
@@ -343,6 +344,7 @@ namespace PDF_Office.Views.HomePanel.RecentFiles
 
             if (dlg.ShowDialog() == true)
             {
+                await Task.Delay(3);
                 MainWindow parentWindow = Window.GetWindow(this) as MainWindow;
                 parentWindow.LoadPdfViewer(dlg.FileNames);
             }

+ 8 - 2
PDF Office/Views/MainWindow.xaml.cs

@@ -20,6 +20,9 @@ using PDF_Office.CustomControl;
 using Prism.Ioc;
 using PDF_Office.Helper;
 using System.IO;
+using ComPDFKit.PDFDocument;
+using PDFSettings.Settings;
+using PDF_Office.Properties;
 
 namespace PDF_Office.Views
 {
@@ -77,6 +80,7 @@ namespace PDF_Office.Views
             aggregator?.GetEvent<DragablzWindowEvent>().Publish(new DragablzWindowEventArgs() { TabControl = TabablzControl, Type = DragablzWindowEventType.Closed });
         }
 
+        private bool isNewDocument = false;
         public void LoadPdfViewer(string[] filePaths)
         {
             var content = App.mainWindowViewModel.SelectedItem.DataContext as MainContentViewModel;
@@ -88,10 +92,9 @@ namespace PDF_Office.Views
                 }
                 else
                 {
-                   
-
                     content.OpenFile(filePaths[0]);
                 }
+                ToolMethod.SetFileThumbImg(filePaths[0]);
             }
             else
             {
@@ -106,9 +109,12 @@ namespace PDF_Office.Views
                     {
                         App.mainWindowViewModel.AddTabItem(fileList[i]);
                     }
+                    ToolMethod.SetFileThumbImg(fileList[i]);
                 }
             }
 
+            Settings.Default.Save();
         }
+
     }
 }