Browse Source

PDF工具 - 调整快捷工具布局

chenrongqian 2 years ago
parent
commit
bb4f23008e

+ 5 - 6
PDF Office/Model/PDFTool/ToolItem.cs

@@ -1,4 +1,5 @@
-using Prism.Mvvm;
+using PDF_Office.Views.HomePanel.PDFTools;
+using Prism.Mvvm;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -10,12 +11,10 @@ namespace PDF_Office.Model.PDFTool
     public class ToolItem : BindableBase
     {
         public int Id { get; set; }
+        public PDFToolType Tag { get; set; }
         public string Image { get; set; }
-        public string NameInfo { get; set; }
-        public string Name { get; set; }
-        public ToolItem()
-        {
+        public string TitleInfo { get; set; }
+        public string Title { get; set; }
 
-        }
     }
 }

+ 1 - 0
PDF Office/PDF Office.csproj

@@ -193,6 +193,7 @@
     <Compile Include="Views\HomePanel\HomeToolsContent.xaml.cs">
       <DependentUpon>HomeToolsContent.xaml</DependentUpon>
     </Compile>
+    <Compile Include="Views\HomePanel\PDFTools\PDFTools.cs" />
     <Compile Include="Views\HomePanel\PDFTools\PDFToolsContent.xaml.cs">
       <DependentUpon>PDFToolsContent.xaml</DependentUpon>
     </Compile>

+ 3 - 3
PDF Office/Views/HomePanel/PDFTools/PDFToolItem.xaml

@@ -29,14 +29,14 @@
                     </Grid.RowDefinitions>
                     <Image VerticalAlignment="Top" Source="{Binding Image}" HorizontalAlignment="Center" Width="28" Height="28" Margin="5,10,5,5" />
 
-                    <TextBlock  Name="TxbTitle" Grid.Column="1" Text="{Binding Name}" 
+                    <TextBlock  Name="TxbTitle" Grid.Column="1" Text="{Binding Title}" 
                                     FontSize="14" FontWeight="SemiBold" Foreground="Black"
                                     VerticalAlignment="Top" Margin="0,15,0,0"></TextBlock>
 
 
                     <StackPanel Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1"  Margin="6,0,6,0">
                         <Grid>
-                            <TextBlock Name="ToolInfoBlock" Text="{Binding NameInfo}"
+                            <TextBlock Name="ToolInfoBlock" Text="{Binding TitleInfo}"
                                        Foreground="#666666" LineHeight="16"  FontSize="12"  TextWrapping="Wrap" VerticalAlignment="Center" Margin="0,8,0,0"></TextBlock>
                         </Grid>
 
@@ -53,7 +53,7 @@
                 </Grid.ColumnDefinitions>
                 <Grid x:Name="GridToolMaskConcise" Grid.ColumnSpan="2" Background="#477EDE" Visibility="Collapsed"/>
                 <Image VerticalAlignment="Top" Source="{Binding Image}" HorizontalAlignment="Center" Width="28" Height="28" Margin="5,10,5,5" />
-                <TextBlock  Name="TxbTitleConcise" Grid.Column="1" Text="{Binding Name}" FontSize="14" FontWeight="SemiBold" VerticalAlignment="Top" Margin="0,15,0,0"></TextBlock>
+                <TextBlock  Name="TxbTitleConcise" Grid.Column="1" Text="{Binding Title}" FontSize="14" FontWeight="SemiBold" VerticalAlignment="Top" Margin="0,15,0,0"></TextBlock>
             </Grid>
         </Border>
         

+ 13 - 12
PDF Office/Views/HomePanel/PDFTools/PDFToolsContent.xaml.cs

@@ -21,7 +21,7 @@ using System.Windows.Shapes;
 
 namespace PDF_Office.Views.HomePanel.PDFTools
 {
-
+   
     /// <summary>
     /// ToolbarPage.xaml 的交互逻辑
     /// </summary>
@@ -79,7 +79,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
             {
                 ToolItem aToolModule = new ToolItem();
                 aToolModule.Id = i + 1;
-                aToolModule.Name = all[i];
+                aToolModule.Title = all[i];
                 aToolModule.Image = path;
                 allTools.Add(aToolModule);
             }
@@ -157,7 +157,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
         {
             var source = sourceListItem.Content as ToolItem;
             if (moreTools == null && moreTools.Count != 0) return;
-            List<ToolItem> toolModule = moreTools.FindAll(item => item.Name == source.Name);
+            List<ToolItem> toolModule = moreTools.FindAll(item => item.Title == source.Title);
             if (toolModule.Count > 0)
             {
                 // 判断文件夹是否存在,不存在则创建
@@ -166,7 +166,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
                 {
                     folder.Create();
                 }
-                fileName = System.IO.Path.Combine(folder.FullName, $"{source.Name}.png");
+                fileName = System.IO.Path.Combine(folder.FullName, $"{source.Title}.png");
 
                 SaveToPng(sourceListItem, fileName);
             }
@@ -191,7 +191,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
                 return;
             }
             var targetAToolModule = targetListItem.Content as ToolItem;
-            ToolItem target = quickTools.Find(c => c.Name == targetAToolModule.Name);
+            ToolItem target = quickTools.Find(c => c.Title == targetAToolModule.Title);
 
             //查找元数据
             var sourceAToolModule = e.Data.GetData(typeof(ToolItem)) as ToolItem;
@@ -221,17 +221,17 @@ namespace PDF_Office.Views.HomePanel.PDFTools
         private void ModuleExchange(ToolItem sourceAToolModule, ToolItem targetAToolModule)
         {
             if (moreTools == null) return;
-            ToolItem source = moreTools.Find(c => c.Name == sourceAToolModule.Name);
+            ToolItem source = moreTools.Find(c => c.Title == sourceAToolModule.Title);
 
-            int targetIndex = quickTools.FindIndex(item => item.Name == targetAToolModule.Name);
+            int targetIndex = quickTools.FindIndex(item => item.Title == targetAToolModule.Title);
             if (targetIndex < 0) return;
             if (!isMoreCuts)
             {
                 ListMoreCuts.AllowDrop = false;
                 sourceImage.Visibility = Visibility.Hidden;
-                source = quickTools.Find(c => c.Name == sourceAToolModule.Name);
+                source = quickTools.Find(c => c.Title == sourceAToolModule.Title);
                 if (source == null) return;
-                int sourceIndex = quickTools.FindIndex(item => item.Name == sourceAToolModule.Name);
+                int sourceIndex = quickTools.FindIndex(item => item.Title == sourceAToolModule.Title);
                 if (sourceIndex < 0) return;
                 var temp = quickTools[sourceIndex];
                 quickTools[sourceIndex] = quickTools[targetIndex];
@@ -390,7 +390,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
             {
                 var sourceAToolModule = e.Data.GetData(typeof(ToolItem)) as ToolItem;
                 if (sourceAToolModule == null) return;
-                int sourceIndex = quickTools.FindIndex(item => item.Name == sourceAToolModule.Name);
+                int sourceIndex = quickTools.FindIndex(item => item.Title == sourceAToolModule.Title);
                 //根据index找listbox对应的item
                 sourceListItem = (ListItemQuickTool)(ListShortCuts.ItemContainerGenerator.ContainerFromIndex(sourceIndex) as FrameworkElement);
                 if (sourceListItem == null)
@@ -404,7 +404,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
             {
                 var sourceAToolModule = e.Data.GetData(typeof(ToolItem)) as ToolItem;
                 if (sourceAToolModule == null) return;
-                int sourceIndex = moreTools.FindIndex(item => item.Name == sourceAToolModule.Name);
+                int sourceIndex = moreTools.FindIndex(item => item.Title == sourceAToolModule.Title);
                 //根据index找listbox对应的item
                 sourceListItem = (ListItemQuickTool)(ListMoreCuts.ItemContainerGenerator.ContainerFromIndex(sourceIndex) as FrameworkElement);
                 if (sourceListItem == null)
@@ -431,7 +431,7 @@ namespace PDF_Office.Views.HomePanel.PDFTools
             }
             var targetAToolModule = targetListItem.Content as ToolItem;
             if (targetAToolModule == null) return;
-            target = quickTools.Find(c => c.Name == targetAToolModule.Name);
+            target = quickTools.Find(c => c.Title == targetAToolModule.Title);
         }
 
         /// <summary>
@@ -632,4 +632,5 @@ namespace PDF_Office.Views.HomePanel.PDFTools
 
 
     }
+
 }

+ 11 - 2
PDF Office/Views/HomePanel/PDFTools/QuickToolsContent.xaml

@@ -8,6 +8,8 @@
     xmlns:customControl="clr-namespace:PDF_Office.CustomControl"
     xmlns:converter="clr-namespace:PDF_Office.DataConvert"
     xmlns:pDFTools="clr-namespace:PDF_Office.Views.HomePanel.PDFTools"
+    xmlns:prism="http://prismlibrary.com/"
+    prism:ViewModelLocator.AutoWireViewModel="True"
     d:DesignHeight="450"
     d:DesignWidth="800"
     mc:Ignorable="d">
@@ -36,6 +38,13 @@
                        Orientation="Horizontal" />
             </ItemsPanelTemplate>
 
+            <Style x:Key="QuickToolsListBoxItemStyle" BasedOn="{StaticResource MoreListBoxItemStyle}"
+               TargetType="{x:Type customControl:ListItemQuickTool}">
+                <!--<EventSetter Event="PreviewMouseLeftButtonUp"
+                             Handler="{Binding QuickToolsCommand}"/>-->
+
+            </Style>
+
         </ResourceDictionary>
         
     </UserControl.Resources>
@@ -78,7 +87,7 @@
                 x:Name="BtnMore"
                 Width="28"
                 Height="28"
-                Margin="12,0,0,0"
+                Margin="12,0,0,0" Command="{Binding OpenFileCommand}"
                  Background="#FFFFFF" BorderThickness="0" Content="..."
                 Click="BtnMore_Click"
                >
@@ -100,7 +109,7 @@
                         ItemTemplate="{StaticResource DataTemplate}"
                         ItemsPanel="{StaticResource ListItemsPanelTemplate}"
                         ScrollViewer.HorizontalScrollBarVisibility="Disabled"
-                        SelectionMode="Single" />
+                        SelectionMode="Single"  />
 
         </Grid>
 

+ 4 - 18
PDF Office/Views/HomePanel/PDFTools/QuickToolsContent.xaml.cs

@@ -16,26 +16,12 @@ namespace PDF_Office.Views.HomePanel.PDFTools
     /// </summary>
     public partial class QuickToolsContent : UserControl
     {
-
-        private List<ToolItem> allToolbars = null;
+        PDFTools PDFtools;
         public QuickToolsContent()
         {
-            InitializeComponent(); 
-             allToolbars = new List<ToolItem>();
-            string path = @"pack://application:,,,/Resources/PromotionIcon/Windows.png";
-            List<string> all = new List<string>() { "PDF转Word", "PDF转Excel", "PDF转PPT", "转档PDF", "OCR", "拆分",
-            "提取","合并","压缩","图片转PDF","安全", "水印", "页眉页脚","贝茨Bates码","批量处理","打印", "背景","插入","文件对比"};
-            for (int i = 0; i < 8; i++)
-            {
-                ToolItem aToolModule = new ToolItem();
-                aToolModule.Id = i + 1;
-                aToolModule.Name = all[i];
-                aToolModule.Image = path;
-                aToolModule.NameInfo = "Batch convert, compress, secure, watermark PDFs.";
-                allToolbars.Add(aToolModule);
-            }
-
-            ListBoxToolBars.ItemsSource = allToolbars;
+            InitializeComponent();
+            PDFtools = new PDFTools();
+            ListBoxToolBars.ItemsSource = PDFtools.QuickTools;
         }