RightCardControl.xaml.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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.Imaging;
  22. using System.Windows.Navigation;
  23. using System.Windows.Shapes;
  24. namespace GeekDesk.Control.UserControls.PannelCard
  25. {
  26. /// <summary>
  27. /// RightCardControl.xaml 的交互逻辑
  28. /// </summary>
  29. public partial class RightCardControl : UserControl
  30. {
  31. private AppData appData = MainWindow.appData;
  32. public RightCardControl()
  33. {
  34. InitializeComponent();
  35. }
  36. #region 图标拖动
  37. DelegateCommand<int[]> _swap;
  38. public DelegateCommand<int[]> SwapCommand
  39. {
  40. get
  41. {
  42. if (_swap == null)
  43. _swap = new DelegateCommand<int[]>(
  44. (indexes) =>
  45. {
  46. int fromS = indexes[0];
  47. int to = indexes[1];
  48. ObservableCollection<IconInfo> iconList = appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList;
  49. var elementSource = iconList[to];
  50. var dragged = iconList[fromS];
  51. iconList.Remove(dragged);
  52. iconList.Insert(to, dragged);
  53. }
  54. );
  55. return _swap;
  56. }
  57. }
  58. #endregion 图标拖动
  59. /// <summary>
  60. /// 图标点击事件
  61. /// </summary>
  62. /// <param name="sender"></param>
  63. /// <param name="e"></param>
  64. private void IconClick(object sender, MouseButtonEventArgs e)
  65. {
  66. IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
  67. if (icon.AdminStartUp)
  68. {
  69. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  70. }
  71. else
  72. {
  73. StartIconApp(icon, IconStartType.DEFAULT_STARTUP);
  74. }
  75. }
  76. /// <summary>
  77. /// 管理员方式启动
  78. /// </summary>
  79. /// <param name="sender"></param>
  80. /// <param name="e"></param>
  81. private void IconAdminStart(object sender, RoutedEventArgs e)
  82. {
  83. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  84. StartIconApp(icon, IconStartType.ADMIN_STARTUP);
  85. }
  86. /// <summary>
  87. /// 打开文件所在位置
  88. /// </summary>
  89. /// <param name="sender"></param>
  90. /// <param name="e"></param>
  91. private void ShowInExplore(object sender, RoutedEventArgs e)
  92. {
  93. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  94. StartIconApp(icon, IconStartType.SHOW_IN_EXPLORE);
  95. }
  96. private void StartIconApp(IconInfo icon, IconStartType type)
  97. {
  98. try
  99. {
  100. if (!File.Exists(icon.Path) && !Directory.Exists(icon.Path))
  101. {
  102. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(文件路径不存在或已删除)!");
  103. return;
  104. }
  105. Process p = new Process();
  106. p.StartInfo.FileName = icon.Path;
  107. switch (type)
  108. {
  109. case IconStartType.ADMIN_STARTUP:
  110. p.StartInfo.Arguments = "1";//启动参数
  111. p.StartInfo.Verb = "runas";
  112. p.StartInfo.CreateNoWindow = false; //设置显示窗口
  113. p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动进程
  114. p.StartInfo.ErrorDialog = false;
  115. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  116. {
  117. Window parentWin = Window.GetWindow(this);
  118. parentWin.Visibility = Visibility.Collapsed;
  119. }
  120. break;// c#好像不能case穿透
  121. case IconStartType.DEFAULT_STARTUP:
  122. if (appData.AppConfig.AppHideType == AppHideType.START_EXE)
  123. {
  124. Window parentWin = Window.GetWindow(this);
  125. parentWin.Visibility = Visibility.Collapsed;
  126. }
  127. break;
  128. case IconStartType.SHOW_IN_EXPLORE:
  129. p.StartInfo.FileName = "Explorer.exe";
  130. p.StartInfo.Arguments = "/e,/select," + icon.Path;
  131. break;
  132. }
  133. p.Start();
  134. icon.Count++;
  135. }
  136. catch (Exception)
  137. {
  138. HandyControl.Controls.Growl.WarningGlobal("程序启动失败(不支持的启动方式)!");
  139. }
  140. }
  141. /// <summary>
  142. /// data选中事件 设置不可选中
  143. /// </summary>
  144. /// <param name="sender"></param>
  145. /// <param name="e"></param>
  146. private void IconSelectionChanged(object sender, SelectionChangedEventArgs e)
  147. {
  148. if (icons.SelectedIndex != -1) icons.SelectedIndex = -1;
  149. }
  150. private void Wrap_Drop(object sender, DragEventArgs e)
  151. {
  152. Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
  153. if (dropObject == null) return;
  154. foreach (object obj in dropObject)
  155. {
  156. string path = (string)obj;
  157. //string base64 = ImageUtil.FileImageToBase64(path, ImageFormat.Jpeg);
  158. IconInfo iconInfo = new IconInfo
  159. {
  160. Path = path,
  161. BitmapImage = ImageUtil.GetBitmapIconByPath(path)
  162. };
  163. iconInfo.DefaultImage = iconInfo.ImageByteArr;
  164. iconInfo.Name = System.IO.Path.GetFileNameWithoutExtension(path);
  165. MainWindow.appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Add(iconInfo);
  166. }
  167. }
  168. /// <summary>
  169. /// 从列表删除图标
  170. /// </summary>
  171. /// <param name="sender"></param>
  172. /// <param name="e"></param>
  173. private void RemoveIcon(object sender, RoutedEventArgs e)
  174. {
  175. appData.MenuList[appData.AppConfig.SelectedMenuIndex].IconList.Remove((IconInfo)((MenuItem)sender).Tag);
  176. }
  177. private void MenuItem_Click(object sender, RoutedEventArgs e)
  178. {
  179. IconInfo icon = (IconInfo)((MenuItem)sender).Tag;
  180. System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("Explorer.exe");
  181. psi.Arguments = "/e,/select," + icon.Path;
  182. System.Diagnostics.Process.Start(psi);
  183. }
  184. /// <summary>
  185. /// 弹出Icon属性修改面板
  186. /// </summary>
  187. /// <param name="sender"></param>
  188. /// <param name="e"></param>
  189. private void PropertyConfig(object sender, RoutedEventArgs e)
  190. {
  191. HandyControl.Controls.Dialog.Show(new IconInfoDialog((IconInfo)((MenuItem)sender).Tag));
  192. }
  193. }
  194. }