From 7d48b16900cec468e45bd4fd1c840887d384b333 Mon Sep 17 00:00:00 2001 From: liufei Date: Fri, 25 Mar 2022 16:23:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=90=9C=E7=B4=A2=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PannelCard/RightCardControl.xaml | 251 ++++++++++++------ .../PannelCard/RightCardControl.xaml.cs | 53 +++- MainWindow.xaml | 38 ++- MainWindow.xaml.cs | 113 ++++++-- 4 files changed, 335 insertions(+), 120 deletions(-) diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml b/Control/UserControls/PannelCard/RightCardControl.xaml index 9adaa0e..7912bd1 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml +++ b/Control/UserControls/PannelCard/RightCardControl.xaml @@ -3,7 +3,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" - xmlns:local="clr-namespace:GeekDesk.Control.UserControls.PannelCard" + xmlns:temp="clr-namespace:GeekDesk.ViewModel.Temp" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:cvt="clr-namespace:GeekDesk.Converts" xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" @@ -12,6 +12,14 @@ > + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - + + + + + - - + + - - - - - - - - - - - + + + + + + + + + + + - - - - + + + - - - - - - - - - + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Control/UserControls/PannelCard/RightCardControl.xaml.cs b/Control/UserControls/PannelCard/RightCardControl.xaml.cs index 2a33414..a8d26f7 100644 --- a/Control/UserControls/PannelCard/RightCardControl.xaml.cs +++ b/Control/UserControls/PannelCard/RightCardControl.xaml.cs @@ -26,6 +26,9 @@ namespace GeekDesk.Control.UserControls.PannelCard { private AppData appData = MainWindow.appData; + private volatile static bool DROP_ICON = false; + private Thread dropCheckThread = null; + public RightCardControl() { InitializeComponent(); @@ -42,6 +45,34 @@ namespace GeekDesk.Control.UserControls.PannelCard _swap = new DelegateCommand( (indexes) => { + DROP_ICON = true; + if (appData.AppConfig.IconSortType != SortType.CUSTOM + && (dropCheckThread == null || !dropCheckThread.IsAlive)) + { + dropCheckThread = new Thread(() => + { + do + { + DROP_ICON = false; + Thread.Sleep(1000); + } while (DROP_ICON); + + MainWindow.appData.AppConfig.IconSortType = SortType.CUSTOM; + App.Current.Dispatcher.Invoke(() => + { + if (MainWindow.mainWindow.Visibility == Visibility.Collapsed + || MainWindow.mainWindow.Opacity != 1) + { + Growl.WarningGlobal("已将图标排序规则重置为自定义!"); + } + else + { + Growl.Warning("已将图标排序规则重置为自定义!", "MainWindowGrowl"); + } + }); + }); + dropCheckThread.Start(); + } int fromS = indexes[0]; int to = indexes[1]; ObservableCollection iconList = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList; @@ -165,9 +196,9 @@ namespace GeekDesk.Control.UserControls.PannelCard case IconStartType.ADMIN_STARTUP: //p.StartInfo.Arguments = "1";//启动参数 p.StartInfo.Verb = "runas"; - p.StartInfo.CreateNoWindow = false; //设置显示窗口 - p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程 - p.StartInfo.ErrorDialog = false; + //p.StartInfo.CreateNoWindow = false; //设置显示窗口 + p.StartInfo.UseShellExecute = true;//不使用操作系统外壳程序启动进程 + //p.StartInfo.ErrorDialog = false; if (appData.AppConfig.AppHideType == AppHideType.START_EXE) { //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 @@ -330,8 +361,9 @@ namespace GeekDesk.Control.UserControls.PannelCard string path = (string)obj; IconInfo iconInfo = CommonCode.GetIconInfoByPath(path); MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo); - CommonCode.SaveAppData(MainWindow.appData); } + CommonCode.SortIconList(); + CommonCode.SaveAppData(MainWindow.appData); } /// @@ -539,5 +571,18 @@ namespace GeekDesk.Control.UserControls.PannelCard SystemItemWindow.Show(); } + public void VisibilitySearchCard(Visibility vb) + { + VerticalCard.Visibility = vb; + if (vb == Visibility.Visible) + { + WrapCard.Visibility = Visibility.Collapsed; + } + else + { + WrapCard.Visibility = Visibility.Visible; + } + } + } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 475bee7..fc73cf5 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -3,11 +3,9 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:local="clr-namespace:GeekDesk" xmlns:uc="clr-namespace:GeekDesk.Control.UserControls.PannelCard" mc:Ignorable="d" xmlns:cvt="clr-namespace:GeekDesk.Converts" - xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window" xmlns:hc="https://handyorg.github.io/handycontrol" xmlns:viewmodel="clr-namespace:GeekDesk.ViewModel" d:DataContext="{d:DesignInstance Type=viewmodel:AppData}" Title="GeekDesk" @@ -18,33 +16,42 @@ Background="Transparent" ShowInTaskbar="False" Opacity="0" - Deactivated="Window_Deactivated" + Deactivated="App_LostFocus" SizeChanged="Window_SizeChanged" KeyDown="OnKeyDown" Focusable="True" + MouseDown="MainWindow_MouseDown" > + + + + + + + - + @@ -62,6 +69,7 @@ + @@ -69,9 +77,11 @@ - + + + @@ -123,7 +133,21 @@ - + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 37b5bf7..2e2592e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -1,28 +1,22 @@ -using DraggAnimatedPanelExample; -using GeekDesk.Constant; -using GeekDesk.Control; +using GeekDesk.Constant; using GeekDesk.Control.UserControls.Config; using GeekDesk.Control.Windows; using GeekDesk.Interface; using GeekDesk.Task; -using GeekDesk.Thread; +using GeekDesk.MyThread; using GeekDesk.Util; using GeekDesk.ViewModel; -using Gma.System.MouseKeyHook; -using HandyControl.Data; using System; -using System.Collections.ObjectModel; using System.Diagnostics; -using System.Drawing; -using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Input; -using System.Windows.Interop; -using System.Windows.Media; using System.Windows.Media.Animation; using static GeekDesk.Util.ShowWindowFollowMouse; +using System.Collections.ObjectModel; +using NPinyin; +using GeekDesk.ViewModel.Temp; namespace GeekDesk { @@ -48,6 +42,7 @@ namespace GeekDesk this.SizeChanged += MainWindow_Resize; ToDoTask.BackLogCheck(); + ////实例化隐藏 Hide类,进行时间timer设置 MarginHide.ReadyHide(this); if (appData.AppConfig.MarginHide) @@ -56,6 +51,61 @@ namespace GeekDesk } } + /// + /// 显示搜索框 + /// + /// + /// + private void SearchItem(object sender, CanExecuteRoutedEventArgs e) + { + RightCard.VisibilitySearchCard(Visibility.Visible); + SearchBox.Visibility = Visibility.Visible; + SearchBox.Focus(); + } + /// + /// 搜索开始 + /// + /// + /// + private void SearchBox_TextChanged(object sender, TextChangedEventArgs e) + { + string inputText = SearchBox.Text.ToLower(); + if (!string.IsNullOrEmpty(inputText)) + { + SearchIconList.IconList.Clear(); + ObservableCollection menuList = appData.MenuList; + foreach (MenuInfo menu in menuList) + { + ObservableCollection iconList = menu.IconList; + foreach (IconInfo icon in iconList) + { + string pyName = Pinyin.GetInitials(icon.Name).ToLower(); + if (icon.Name.Contains(inputText) || pyName.Contains(inputText)) + { + SearchIconList.IconList.Add(icon); + } + } + } + } + else + { + SearchIconList.IconList.Clear(); + } + } + /// + /// 隐藏搜索框 + /// + /// + /// + private void SearchBox_LostFocus(object sender, RoutedEventArgs e) + { + SearchIconList.IconList.Clear(); + RightCard.VisibilitySearchCard(Visibility.Collapsed); + SearchBox.Visibility = Visibility.Collapsed; + SearchBox.Text = ""; + } + + /// /// 加载缓存数据 /// @@ -302,13 +352,15 @@ namespace GeekDesk // return; //} //修改贴边隐藏状态为未隐藏 + mainWindow.Activate(); + MarginHide.IS_HIDE = false; if (appData.AppConfig.FollowMouse) { ShowWindowFollowMouse.Show(mainWindow, MousePosition.CENTER, 0, 0, false); } FadeStoryBoard(1, (int)CommonEnum.WINDOW_ANIMATION_TIME, Visibility.Visible); - Keyboard.Focus(mainWindow); + mainWindow.Focus(); } public static void HideApp() @@ -342,6 +394,7 @@ namespace GeekDesk else { mainWindow.Opacity = 0; + CommonCode.SortIconList(); } }; Timeline.SetDesiredFrameRate(opacityAnimation, 60); @@ -352,6 +405,10 @@ namespace GeekDesk //防止关闭动画后 窗体仍是0透明度 mainWindow.Opacity = 1; mainWindow.Visibility = visibility; + if (visibility == Visibility.Collapsed) + { + CommonCode.SortIconList(); + } } } @@ -440,26 +497,19 @@ namespace GeekDesk SettingButton.ContextMenu = null; } - private void App_LostFocus(object sender, RoutedEventArgs e) + private void App_LostFocus(object sender, EventArgs e) { - if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS) + if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS + && this.Opacity == 1) { //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口 - if (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE) + if (!appData.AppConfig.MarginHide || (appData.AppConfig.MarginHide && !MarginHide.IS_HIDE)) { - this.Visibility = Visibility.Collapsed; + HideApp(); } } } - private void Window_Deactivated(object sender, EventArgs e) - { - if (appData.AppConfig.AppHideType == AppHideType.LOST_FOCUS) - { - this.Visibility = Visibility.Collapsed; - } - } - private void Window_SizeChanged(object sender, SizeChangedEventArgs e) { if (this.DataContext != null) @@ -523,9 +573,16 @@ namespace GeekDesk HideApp(); } } + + /// + /// 为了让修改菜单的textBox失去焦点 + /// + /// + /// + private void MainWindow_MouseDown(object sender, MouseButtonEventArgs e) + { + EmptyTextBox.Focus(); + } + } - - - - }