RightCardControl.xaml.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. Process p = new Process();
  102. p.StartInfo.FileName = icon.Path;
  103. if (icon.IconType == IconType.OTHER)
  104. {
  105. if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
  106. {
  107. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
  108. return;
  109. }
  110. p.StartInfo.WorkingDirectory = icon.Path.Substring(0, icon.Path.LastIndexOf("\\"));
  111. switch (type)
  112. {
  113. case IconStartType.ADMIN_STARTUP:
  114. p.StartInfo.Arguments = "1";//启动参数
  115. p.StartInfo.Verb = "runas";
  116. p.StartInfo.CreateNoWindow = false; //设置显示窗口
  117. p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
  118. p.StartInfo.ErrorDialog = false;
  119. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  120. {
  121. Window parentWin = Window.GetWindow(this);
  122. parentWin.Visibility = Visibility.Collapsed;
  123. }
  124. break;// c#好像不能case穿透
  125. case IconStartType.DEFAULT_STARTUP:
  126. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  127. {
  128. Window parentWin = Window.GetWindow(this);
  129. parentWin.Visibility = Visibility.Collapsed;
  130. }
  131. break;
  132. case IconStartType.SHOW_IN_EXPLORE:
  133. p.StartInfo.FileName = "Explorer.exe";
  134. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  135. break;
  136. }
  137. }
  138. p.Start();
  139. icon.Count++;
  140. }
  141. catch (Exception)
  142. {
  143. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  144. }
  145. }
  146. private void Wrap_Drop(object sender, DragEventArgs e)
  147. {
  148. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  149. if (dropObject == null) return;
  150. foreach (object obj in dropObject)
  151. {
  152. string path = (string)obj;
  153. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Png);
  154. string ext = System.IO.Path.GetExtension(path).ToLower();
  155. if (".lnk".Equals(ext))
  156. {
  157. string targetPath = FileUtil.GetTargetPathByLnk(path);
  158. if (targetPath!=null)
  159. {
  160. path = targetPath;
  161. }
  162. }
  163. BitmapImage bi = ImageUtil.GetBitmapIconByPath(path);
  164. IconInfo iconInfo = new IconInfo
  165. {
  166. Path = path,
  167. BitmapImage = bi
  168. };
  169. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  170. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  171. if (StringUtil.IsEmpty(iconInfo.Name))
  172. {
  173. iconInfo.Name = path;
  174. }
  175. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  176. CommonCode.SaveAppData(MainWindow.appData);
  177. }
  178. }
  179. /// <summary>
  180. /// 从列表删除图标
  181. /// </summary>
  182. /// <param name="sender"></param>
  183. /// <param name="e"></param>
  184. private void RemoveIcon(object sender, RoutedEventArgs e)
  185. {
  186. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  187. }
  188. private void SystemContextMenu(object sender, RoutedEventArgs e)
  189. {
  190. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  191. DirectoryInfo[] folders = new DirectoryInfo[1];
  192. folders[0] = new DirectoryInfo(icon.Path);
  193. ShellContextMenu scm = new ShellContextMenu();
  194. System.Drawing.Point p = System.Windows.Forms.Cursor.Position;
  195. p.X -= 80;
  196. p.Y -= 80;
  197. scm.ShowContextMenu(folders, p);
  198. }
  199. /// <summary>
  200. /// 弹出Icon属性修改面板
  201. /// </summary>
  202. /// <param name="sender"></param>
  203. /// <param name="e"></param>
  204. private void PropertyConfig(object sender, RoutedEventArgs e)
  205. {
  206. IconInfo info = (IconInfo)((MenuItem)sender).Tag;
  207. switch (info.IconType)
  208. {
  209. case IconType.URL:
  210. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog(info);
  211. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog);
  212. break;
  213. default:
  214. IconInfoDialog dialog = new IconInfoDialog(info);
  215. dialog.dialog = HandyControl.Controls.Dialog.Show(dialog);
  216. break;
  217. }
  218. }
  219. private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
  220. {
  221. ImgStroyBoard(sender, (int)CommonEnum.IMAGE_HEIGHT_AM, (int)CommonEnum.IMAGE_WIDTH_AM, 1);
  222. }
  223. private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
  224. {
  225. ImgStroyBoard(sender, (int)CommonEnum.IMAGE_HEIGHT, (int)CommonEnum.IMAGE_WIDTH, 500);
  226. }
  227. private void ImgStroyBoard(object sender, int height, int width, int milliseconds)
  228. {
  229. if (appData.AppConfig.PMModel) return;
  230. StackPanel sp = sender as StackPanel;
  231. Image img = sp.Children[0] as Image;
  232. DoubleAnimation heightAnimation = new DoubleAnimation();
  233. DoubleAnimation widthAnimation = new DoubleAnimation();
  234. heightAnimation.From = img.Height;
  235. widthAnimation.From = img.Width;
  236. heightAnimation.To = height;
  237. widthAnimation.To = width;
  238. heightAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  239. widthAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  240. Timeline.SetDesiredFrameRate(heightAnimation, 60);
  241. Timeline.SetDesiredFrameRate(widthAnimation, 60);
  242. img.BeginAnimation(HeightProperty, heightAnimation);
  243. img.BeginAnimation(WidthProperty, widthAnimation);
  244. }
  245. private void AddUrlIcon(object sender, RoutedEventArgs e)
  246. {
  247. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog();
  248. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog);
  249. }
  250. }
  251. }