RightCardControl.xaml.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  122. if (appData.AppConfig.MarginHide)
  123. {
  124. if (!MainWindow.hide.IsMargin())
  125. {
  126. MainWindow.mainWindow.Visibility = Visibility.Collapsed;
  127. }
  128. }
  129. else
  130. {
  131. MainWindow.mainWindow.Visibility = Visibility.Collapsed;
  132. }
  133. }
  134. break;// c#好像不能case穿透
  135. case IconStartType.DEFAULT_STARTUP:
  136. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  137. {
  138. //如果开启了贴边隐藏 则窗体不贴边才隐藏窗口
  139. if (appData.AppConfig.MarginHide)
  140. {
  141. if (!MainWindow.hide.IsMargin())
  142. {
  143. MainWindow.mainWindow.Visibility = Visibility.Collapsed;
  144. }
  145. } else
  146. {
  147. MainWindow.mainWindow.Visibility = Visibility.Collapsed;
  148. }
  149. }
  150. break;
  151. case IconStartType.SHOW_IN_EXPLORE:
  152. p.StartInfo.FileName = "Explorer.exe";
  153. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  154. break;
  155. }
  156. }
  157. p.Start();
  158. icon.Count++;
  159. }
  160. catch (Exception)
  161. {
  162. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  163. }
  164. }
  165. private void Wrap_Drop(object sender, DragEventArgs e)
  166. {
  167. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  168. if (dropObject == null) return;
  169. foreach (object obj in dropObject)
  170. {
  171. string path = (string)obj;
  172. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Png);
  173. string ext = System.IO.Path.GetExtension(path).ToLower();
  174. if (".lnk".Equals(ext))
  175. {
  176. string targetPath = FileUtil.GetTargetPathByLnk(path);
  177. if (targetPath!=null)
  178. {
  179. path = targetPath;
  180. }
  181. }
  182. BitmapImage bi = ImageUtil.GetBitmapIconByPath(path);
  183. IconInfo iconInfo = new IconInfo
  184. {
  185. Path = path,
  186. BitmapImage = bi
  187. };
  188. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  189. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  190. if (StringUtil.IsEmpty(iconInfo.Name))
  191. {
  192. iconInfo.Name = path;
  193. }
  194. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  195. CommonCode.SaveAppData(MainWindow.appData);
  196. }
  197. }
  198. /// <summary>
  199. /// 从列表删除图标
  200. /// </summary>
  201. /// <param name="sender"></param>
  202. /// <param name="e"></param>
  203. private void RemoveIcon(object sender, RoutedEventArgs e)
  204. {
  205. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  206. }
  207. private void SystemContextMenu(object sender, RoutedEventArgs e)
  208. {
  209. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  210. DirectoryInfo[] folders = new DirectoryInfo[1];
  211. folders[0] = new DirectoryInfo(icon.Path);
  212. ShellContextMenu scm = new ShellContextMenu();
  213. System.Drawing.Point p = System.Windows.Forms.Cursor.Position;
  214. p.X -= 80;
  215. p.Y -= 80;
  216. scm.ShowContextMenu(folders, p);
  217. }
  218. /// <summary>
  219. /// 弹出Icon属性修改面板
  220. /// </summary>
  221. /// <param name="sender"></param>
  222. /// <param name="e"></param>
  223. private void PropertyConfig(object sender, RoutedEventArgs e)
  224. {
  225. IconInfo info = (IconInfo)((MenuItem)sender).Tag;
  226. switch (info.IconType)
  227. {
  228. case IconType.URL:
  229. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog(info);
  230. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog);
  231. break;
  232. default:
  233. IconInfoDialog dialog = new IconInfoDialog(info);
  234. dialog.dialog = HandyControl.Controls.Dialog.Show(dialog);
  235. break;
  236. }
  237. }
  238. private void StackPanel_MouseEnter(object sender, MouseEventArgs e)
  239. {
  240. ImgStoryBoard(sender, (int)CommonEnum.IMAGE_HEIGHT_AM, (int)CommonEnum.IMAGE_WIDTH_AM, 1);
  241. }
  242. private void StackPanel_MouseLeave(object sender, MouseEventArgs e)
  243. {
  244. ImgStoryBoard(sender, (int)CommonEnum.IMAGE_HEIGHT, (int)CommonEnum.IMAGE_WIDTH, 220);
  245. }
  246. private void ImgStoryBoard(object sender, int height, int width, int milliseconds)
  247. {
  248. if (appData.AppConfig.PMModel) return;
  249. StackPanel sp = sender as StackPanel;
  250. Image img = sp.Children[0] as Image;
  251. DoubleAnimation heightAnimation = new DoubleAnimation();
  252. DoubleAnimation widthAnimation = new DoubleAnimation();
  253. heightAnimation.From = img.Height;
  254. widthAnimation.From = img.Width;
  255. heightAnimation.To = height;
  256. widthAnimation.To = width;
  257. heightAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  258. widthAnimation.Duration = new Duration(TimeSpan.FromMilliseconds(milliseconds));
  259. Timeline.SetDesiredFrameRate(heightAnimation, 60);
  260. Timeline.SetDesiredFrameRate(widthAnimation, 60);
  261. img.BeginAnimation(HeightProperty, null);
  262. img.BeginAnimation(WidthProperty, null);
  263. img.BeginAnimation(HeightProperty, heightAnimation);
  264. img.BeginAnimation(WidthProperty, widthAnimation);
  265. }
  266. private void AddUrlIcon(object sender, RoutedEventArgs e)
  267. {
  268. IconInfoUrlDialog urlDialog = new IconInfoUrlDialog();
  269. urlDialog.dialog = HandyControl.Controls.Dialog.Show(urlDialog);
  270. }
  271. }
  272. }