RightCardControl.xaml.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. using DraggAnimatedPanelExample;
  2. using GeekDesk.Constant;
  3. using GeekDesk.Control.Other;
  4. using GeekDesk.Util;
  5. using GeekDesk.ViewModel;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Diagnostics;
  10. using System.Drawing.Imaging;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading.Tasks;
  15. using System.Windows;
  16. using System.Windows.Controls;
  17. using System.Windows.Data;
  18. using System.Windows.Documents;
  19. using System.Windows.Input;
  20. using System.Windows.Media;
  21. using System.Windows.Media.Animation;
  22. using System.Windows.Media.Imaging;
  23. using System.Windows.Navigation;
  24. using System.Windows.Shapes;
  25. namespace GeekDesk.Control.UserControls.PannelCard
  26. {
  27. /// <summary>
  28. /// RightCardControl.xaml 的交互逻辑
  29. /// </summary>
  30. public partial class RightCardControl : UserControl
  31. {
  32. private AppData appData = MainWindow.appData;
  33. public RightCardControl()
  34. {
  35. InitializeComponent();
  36. }
  37. #region 图标拖动
  38. DelegateCommand<int[]> _swap;
  39. public DelegateCommand<int[]> SwapCommand
  40. {
  41. get
  42. {
  43. if (_swap == null)
  44. _swap = new DelegateCommand<int[]>(
  45. (indexes) =>
  46. {
  47. int fromS = indexes[0];
  48. int to = indexes[1];
  49. ObservableCollection<IconInfo> iconList = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
  50. var elementSource = iconList[to];
  51. var dragged = iconList[fromS];
  52. iconList.Remove(dragged);
  53. iconList.Insert(to, dragged);
  54. }
  55. );
  56. return _swap;
  57. }
  58. }
  59. #endregion 图标拖动
  60. /// <summary>
  61. /// 图标点击事件
  62. /// </summary>
  63. /// <param name="sender"></param>
  64. /// <param name="e"></param>
  65. private void IconClick(object sender, MouseButtonEventArgs e)
  66. {
  67. IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
  68. if (icon.AdminStartUp)
  69. {
  70. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  71. }
  72. else
  73. {
  74. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  75. }
  76. }
  77. /// <summary>
  78. /// 管理员方式启动
  79. /// </summary>
  80. /// <param name="sender"></param>
  81. /// <param name="e"></param>
  82. private void IconAdminStart(object sender, RoutedEventArgs e)
  83. {
  84. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  85. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  86. }
  87. /// <summary>
  88. /// 打开文件所在位置
  89. /// </summary>
  90. /// <param name="sender"></param>
  91. /// <param name="e"></param>
  92. private void ShowInExplore(object sender, RoutedEventArgs e)
  93. {
  94. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  95. StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
  96. }
  97. private void StartIconApp(IconInfo icon, IconStartType type)
  98. {
  99. try
  100. {
  101. if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
  102. {
  103. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
  104. return;
  105. }
  106. Process p = new Process();
  107. p.StartInfo.FileName = icon.Path;
  108. switch (type)
  109. {
  110. case IconStartType.ADMIN_STARTUP:
  111. p.StartInfo.Arguments = "1";//启动参数
  112. p.StartInfo.Verb = "runas";
  113. p.StartInfo.CreateNoWindow = false; //设置显示窗口
  114. p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
  115. p.StartInfo.ErrorDialog = false;
  116. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  117. {
  118. Window parentWin = Window.GetWindow(this);
  119. parentWin.Visibility = Visibility.Collapsed;
  120. }
  121. break;// c#好像不能case穿透
  122. case IconStartType.DEFAULT_STARTUP:
  123. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  124. {
  125. Window parentWin = Window.GetWindow(this);
  126. parentWin.Visibility = Visibility.Collapsed;
  127. }
  128. break;
  129. case IconStartType.SHOW_IN_EXPLORE:
  130. p.StartInfo.FileName = "Explorer.exe";
  131. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  132. break;
  133. }
  134. p.Start();
  135. icon.Count++;
  136. }
  137. catch (Exception)
  138. {
  139. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  140. }
  141. }
  142. private void Wrap_Drop(object sender, DragEventArgs e)
  143. {
  144. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  145. if (dropObject == null) return;
  146. foreach (object obj in dropObject)
  147. {
  148. string path = (string)obj;
  149. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg);
  150. string ext = System.IO.Path.GetExtension(path).ToLower();
  151. if (".lnk".Equals(ext))
  152. {
  153. string targetPath = FileUtil.GetTargetPathByLnk(path);
  154. if (targetPath!=null)
  155. {
  156. path = targetPath;
  157. }
  158. }
  159. IconInfo iconInfo = new IconInfo
  160. {
  161. Path = path,
  162. BitmapImage = ImageUtil.GetBitmapIconByPath(path)
  163. };
  164. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  165. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  166. if (StringUtil.IsEmpty(iconInfo.Name))
  167. {
  168. iconInfo.Name = path;
  169. }
  170. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  171. }
  172. }
  173. /// <summary>
  174. /// 从列表删除图标
  175. /// </summary>
  176. /// <param name="sender"></param>
  177. /// <param name="e"></param>
  178. private void RemoveIcon(object sender, RoutedEventArgs e)
  179. {
  180. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  181. }
  182. private void MenuItem_Click(object sender, RoutedEventArgs e)
  183. {
  184. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  185. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  186. psi.Arguments = "/e,/select," + icon.Path;
  187. System.Diagnostics.Process.Start(psi);
  188. }
  189. /// <summary>
  190. /// 弹出Icon属性修改面板
  191. /// </summary>
  192. /// <param name="sender"></param>
  193. /// <param name="e"></param>
  194. private void PropertyConfig(object sender, RoutedEventArgs e)
  195. {
  196. HandyControl.Controls.Dialog.Show(new IconInfoDialog((IconInfo)((MenuItem)sender).Tag));
  197. }
  198. private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
  199. {
  200. ImgStroyBoard(sender, (int)MainWindowEnum.IMAGE_HEIGHT_AM, (int)MainWindowEnum.IMAGE_WIDTH_AM, 1);
  201. }
  202. private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
  203. {
  204. ImgStroyBoard(sender, (int)MainWindowEnum.IMAGE_HEIGHT, (int)MainWindowEnum.IMAGE_WIDTH, 500);
  205. }
  206. private void ImgStroyBoard(object sender, int height, int width, int milliseconds)
  207. {
  208. StackPanel sp = sender as StackPanel;
  209. Image img = sp.Children[0] as Image;
  210. DoubleAnimation heightAnimation = new DoubleAnimation();
  211. DoubleAnimation widthAnimation = new DoubleAnimation();
  212. heightAnimation.From = img.Height;
  213. widthAnimation.From = img.Width;
  214. heightAnimation.To = height;
  215. widthAnimation.To = width;
  216. heightAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  217. widthAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  218. img.BeginAnimation(HeightProperty, heightAnimation);
  219. img.BeginAnimation(WidthProperty, widthAnimation);
  220. }
  221. }
  222. }