Browse Source

增加排序功能

liufei 3 years ago
parent
commit
c46f66b54d

+ 4 - 2
Constant/SortType.cs

@@ -3,7 +3,9 @@
     public enum SortType
     {
         CUSTOM = 1, //自定义排序
-        NAME = 2, //按名称排序
-        COUNT = 3 //按使用次数排序
+        COUNT_UP = 2, //按使用次数升序
+        COUNT_LOW = 3, //按使用次数降序
+        NAME_UP = 4, //按名称升序
+        NAME_LOW = 5, //按名称降序
     }
 }

+ 1 - 1
Control/UserControls/Config/MotionControl.xaml.cs

@@ -1,6 +1,6 @@
 using GeekDesk.Constant;
 using GeekDesk.Control.Windows;
-using GeekDesk.Thread;
+using GeekDesk.MyThread;
 using GeekDesk.Util;
 using GeekDesk.ViewModel;
 using HandyControl.Data;

+ 41 - 1
Control/UserControls/Config/OtherControl.xaml

@@ -13,6 +13,7 @@
 
     <UserControl.Resources>
         <cvt:UpdateTypeConvert x:Key="UpdateTypeConvert"/>
+        <cvt:SortTypeConvert x:Key="SortTypeConvert"/>
     </UserControl.Resources>
     <Grid MouseDown="DragMove" Background="Transparent">
         <hc:SimplePanel Margin="20" >
@@ -40,6 +41,45 @@
                         </CheckBox.Background>
                     </CheckBox>
                 </hc:UniformSpacingPanel>
+                <TextBlock Text="排序方式"  Margin="0,25,0,0"/>
+
+                <hc:UniformSpacingPanel Spacing="10" Margin="20,8,0,0">
+                    <RadioButton x:Name="CustomSort" Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}" 
+                                 Style="{StaticResource RadioButtonIcon}" Content="自定义"
+                                 Tag="1"
+                                 hc:IconElement.Geometry="{StaticResource CustomSort}"
+                                 PreviewMouseLeftButtonDown="SortType_PreviewMouseLeftButtonDown"
+                                 IsChecked="{Binding IconSortType, Mode=OneWay, Converter={StaticResource SortTypeConvert}, ConverterParameter=1}"/>
+
+                    <RadioButton x:Name="CountUpSort" Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}"
+                                 hc:IconElement.Geometry="{StaticResource UpSort}"
+                                 Style="{StaticResource RadioButtonIcon}" Content="使用次数" 
+                                 Tag="2"
+                                 PreviewMouseLeftButtonDown="SortType_PreviewMouseLeftButtonDown"
+                                 IsChecked="{Binding IconSortType, Mode=OneWay, Converter={StaticResource SortTypeConvert}, ConverterParameter=2}"/>
+
+                    <RadioButton x:Name="CountLowSort" Margin="10,0,0,0" Visibility="Collapsed" Background="{DynamicResource SecondaryRegionBrush}"
+                                 hc:IconElement.Geometry="{StaticResource LowSort}"
+                                 Style="{StaticResource RadioButtonIcon}" Content="使用次数" 
+                                 Tag="3"
+                                 PreviewMouseLeftButtonDown="SortType_PreviewMouseLeftButtonDown"
+                                 IsChecked="{Binding IconSortType, Mode=OneWay, Converter={StaticResource SortTypeConvert}, ConverterParameter=3}"/>
+
+                    <RadioButton x:Name="NameUpSort" Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}"
+                                 hc:IconElement.Geometry="{StaticResource UpSort}"
+                                 Style="{StaticResource RadioButtonIcon}" Content="名称" 
+                                 Tag="4"
+                                 PreviewMouseLeftButtonDown="SortType_PreviewMouseLeftButtonDown"
+                                 IsChecked="{Binding IconSortType, Mode=OneWay, Converter={StaticResource SortTypeConvert}, ConverterParameter=4}"/>
+
+                    <RadioButton x:Name="NameLowSort" Margin="10,0,0,0" Visibility="Collapsed" Background="{DynamicResource SecondaryRegionBrush}"
+                                 hc:IconElement.Geometry="{StaticResource LowSort}"
+                                 Style="{StaticResource RadioButtonIcon}" Content="名称" 
+                                 Tag="5"
+                                 PreviewMouseLeftButtonDown="SortType_PreviewMouseLeftButtonDown"
+                                 IsChecked="{Binding IconSortType, Mode=OneWay, Converter={StaticResource SortTypeConvert}, ConverterParameter=5}"/>
+
+                </hc:UniformSpacingPanel>
                 <TextBlock Text="更新源"  Margin="0,25,0,0"/>
                 <hc:UniformSpacingPanel Spacing="10" Margin="20,8,0,0">
                     <RadioButton Margin="10,0,0,0" Background="{DynamicResource SecondaryRegionBrush}" 
@@ -56,6 +96,6 @@
             </StackPanel>
         </hc:SimplePanel>
     </Grid>
-   
+
 
 </UserControl>

+ 72 - 0
Control/UserControls/Config/OtherControl.xaml.cs

@@ -26,6 +26,13 @@ namespace GeekDesk.Control.UserControls.Config
         public OtherControl()
         {
             InitializeComponent();
+            this.Loaded += OtherControl_Loaded;
+
+        }
+
+        private void OtherControl_Loaded(object sender, RoutedEventArgs e)
+        {
+            Sort_Check();
         }
 
         private void SelfStartUpBox_Click(object sender, RoutedEventArgs e)
@@ -46,5 +53,70 @@ namespace GeekDesk.Control.UserControls.Config
                 Window.GetWindow(this).DragMove();
             }
         }
+
+        private void SortType_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
+        {
+            RadioButton rb = sender as RadioButton;
+            SortType type = (SortType)int.Parse(rb.Tag.ToString());
+
+            SortType resType = type;
+            switch (type)
+            {
+                case SortType.CUSTOM:
+                    break;
+                case SortType.COUNT_UP:
+                    if (rb.IsChecked == true)
+                    {
+                        CountLowSort.IsChecked = true;
+                        CountUpSort.Visibility = Visibility.Collapsed;
+                        CountLowSort.Visibility = Visibility.Visible;
+                        resType = SortType.COUNT_LOW;
+                    }
+                    break;
+                case SortType.COUNT_LOW:
+                    if (rb.IsChecked == true)
+                    {
+                        CountUpSort.IsChecked = true;
+                        CountLowSort.Visibility = Visibility.Collapsed;
+                        CountUpSort.Visibility = Visibility.Visible;
+                        resType = SortType.COUNT_UP;
+                    }
+                    break;
+                case SortType.NAME_UP:
+                    if (rb.IsChecked == true)
+                    {
+                        NameLowSort.IsChecked = true;
+                        NameUpSort.Visibility = Visibility.Collapsed;
+                        NameLowSort.Visibility = Visibility.Visible;
+                        resType = SortType.NAME_LOW;
+                    }
+                    break;
+                case SortType.NAME_LOW:
+                    if (rb.IsChecked == true)
+                    {
+                        NameUpSort.IsChecked = true;
+                        NameLowSort.Visibility = Visibility.Collapsed;
+                        NameUpSort.Visibility = Visibility.Visible;
+                        resType = SortType.NAME_UP;
+                    }
+                    break;
+            }
+            MainWindow.appData.AppConfig.IconSortType = resType;
+            CommonCode.SortIconList();
+        }
+
+        private void Sort_Check()
+        {
+            if (NameLowSort.IsChecked == true)
+            {
+                NameUpSort.Visibility = Visibility.Collapsed;
+                NameLowSort.Visibility = Visibility.Visible;
+            }
+            if (CountLowSort.IsChecked == true)
+            {
+                CountUpSort.Visibility = Visibility.Collapsed;
+                CountLowSort.Visibility = Visibility.Visible;
+            }
+        }
     }
 }

+ 25 - 0
Converts/SearchResWidth.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Data;
+
+namespace GeekDesk.Converts
+{
+    class SearchResWidth : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            double menuLeftWidth = double.Parse(value.ToString());
+            return MainWindow.mainWindow.Width - menuLeftWidth;
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return null;
+        }
+    }
+}

+ 29 - 0
Converts/SortTypeConvert.cs

@@ -0,0 +1,29 @@
+using GeekDesk.Constant;
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Data;
+
+namespace GeekDesk.Converts
+{
+    public class SortTypeConvert : IValueConverter
+    {
+        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            return (SortType)value == (SortType)int.Parse(parameter.ToString());
+        }
+
+        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+        {
+            bool isChecked = (bool)value;
+            if (!isChecked)
+            {
+                return null;
+            }
+            return (SortType)int.Parse(parameter.ToString());
+        }
+    }
+}

+ 9 - 3
GeekDesk.csproj

@@ -72,6 +72,9 @@
     <Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
       <HintPath>packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
     </Reference>
+    <Reference Include="NPinyin.Core, Version=3.0.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>packages\NPinyin.Core.3.0.0\lib\net45\NPinyin.Core.dll</HintPath>
+    </Reference>
     <Reference Include="Quartz, Version=3.3.3.0, Culture=neutral, PublicKeyToken=f6b8c98a402cc8a4, processorArchitecture=MSIL">
       <HintPath>packages\Quartz.3.3.3\lib\net472\Quartz.dll</HintPath>
     </Reference>
@@ -189,6 +192,8 @@
     </Compile>
     <Compile Include="Converts\DoubleToGridLength.cs" />
     <Compile Include="Converts\MenuInfoConvert.cs" />
+    <Compile Include="Converts\SearchResWidth.cs" />
+    <Compile Include="Converts\SortTypeConvert.cs" />
     <Compile Include="Converts\TodoTaskExecConvert.cs" />
     <Compile Include="Converts\IntToCornerRadius.cs" />
     <Compile Include="Converts\OpcityConvert.cs" />
@@ -198,9 +203,9 @@
     <Compile Include="Converts\HideTypeConvert.cs" />
     <Compile Include="Interface\IWindowCommon.cs" />
     <Compile Include="Task\ToDoTask.cs" />
-    <Compile Include="Thread\MouseHookThread.cs" />
-    <Compile Include="Thread\DispatcherBuild.cs" />
-    <Compile Include="Thread\UpdateThread.cs" />
+    <Compile Include="MyThread\MouseHookThread.cs" />
+    <Compile Include="MyThread\DispatcherBuild.cs" />
+    <Compile Include="MyThread\UpdateThread.cs" />
     <Compile Include="Util\AeroGlassHelper.cs" />
     <Compile Include="Util\GlobalHotKey.cs" />
     <Compile Include="Util\CommonCode.cs" />
@@ -223,6 +228,7 @@
     <Compile Include="Util\SvgToGeometry.cs" />
     <Compile Include="ViewModel\AppConfig.cs" />
     <Compile Include="ViewModel\AppData.cs" />
+    <Compile Include="ViewModel\Temp\SearchIconList.cs" />
     <Compile Include="ViewModel\ToDoInfo.cs" />
     <Compile Include="ViewModel\IconfontInfo.cs" />
     <Compile Include="ViewModel\IconInfo.cs" />

File diff suppressed because it is too large
+ 1 - 0
Resource/Dictionary/Geometry.xaml


+ 35 - 2
Util/CommonCode.cs

@@ -1,6 +1,8 @@
 using GeekDesk.Constant;
 using GeekDesk.ViewModel;
 using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.IO;
 using System.Runtime.InteropServices;
 using System.Runtime.Serialization.Formatters.Binary;
@@ -186,8 +188,39 @@ namespace GeekDesk.Util
 
 
 
-
-
+        /// <summary>
+        /// 排序图标
+        /// </summary>
+        public static void SortIconList()
+        {
+            if (MainWindow.appData.AppConfig.IconSortType != SortType.CUSTOM)
+            {
+                ObservableCollection<MenuInfo> menuList = MainWindow.appData.MenuList;
+                //List<IconInfo> list = new List<IconInfo>(menuList[MainWindow.appData.AppConfig.SelectedMenuIndex].IconList);
+                List<IconInfo> list;
+                foreach (MenuInfo menuInfo in menuList)
+                {
+                    list = new List<IconInfo>(menuInfo.IconList);
+                    switch (MainWindow.appData.AppConfig.IconSortType)
+                    {
+                        case SortType.COUNT_UP:
+                            list.Sort((x, y) => x.Count.CompareTo(y.Count));
+                            break;
+                        case SortType.COUNT_LOW:
+                            list.Sort((x, y) => y.Count.CompareTo(x.Count));
+                            break;
+                        case SortType.NAME_UP:
+                            list.Sort((x, y) => x.Name.CompareTo(y.Name));
+                            break;
+                        case SortType.NAME_LOW:
+                            list.Sort((x, y) => y.Name.CompareTo(x.Name));
+                            break;
+                    }
+                    menuInfo.IconList = new ObservableCollection<IconInfo>(list);
+                }
+                MainWindow.appData.AppConfig.SelectedMenuIcons = MainWindow.appData.MenuList[MainWindow.appData.AppConfig.SelectedMenuIndex].IconList;
+            }
+        }
 
     }
 }

+ 31 - 0
ViewModel/Temp/SearchIconList.cs

@@ -0,0 +1,31 @@
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+
+namespace GeekDesk.ViewModel.Temp
+{
+    public class SearchIconList
+    {
+
+        private static ObservableCollection<IconInfo> iconList = new ObservableCollection<IconInfo>();
+
+        public static ObservableCollection<IconInfo> IconList
+        {
+            get
+            {
+                return iconList;
+            }
+            set
+            {
+                iconList = value;
+                OnPropertyChanged("IconList");
+            }
+        }
+
+
+        public static event PropertyChangedEventHandler PropertyChanged;
+        private static void OnPropertyChanged(string propertyName)
+        {
+            PropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
+        }
+    }
+}

+ 1 - 0
packages.config

@@ -6,6 +6,7 @@
   <package id="Microsoft.Extensions.Logging.Abstractions" version="2.1.1" targetFramework="net472" />
   <package id="MouseKeyHook" version="5.6.0" targetFramework="net472" />
   <package id="Newtonsoft.Json" version="13.0.1" targetFramework="net472" />
+  <package id="NPinyin.Core" version="3.0.0" targetFramework="net472" />
   <package id="Quartz" version="3.3.3" targetFramework="net472" />
   <package id="System.Buffers" version="4.5.1" targetFramework="net472" />
   <package id="System.Diagnostics.DiagnosticSource" version="4.7.1" targetFramework="net472" />

Some files were not shown because too many files changed in this diff