终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

267 lines
9.7 KiB

  1. using BeDesignerSCADA.Helper;
  2. using Microsoft.Win32;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace BeDesignerSCADA.Controls
  18. {
  19. /// <summary>
  20. /// CodeCanvasPanel.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class CodeCanvasPanel : UserControl
  23. {
  24. public CodeCanvasPanel()
  25. {
  26. InitializeComponent();
  27. }
  28. #region 变量
  29. string _currentFile;
  30. public string File
  31. {
  32. get
  33. {
  34. if (string.IsNullOrEmpty(_currentFile))
  35. _currentFile = IniFile.ReadValue("Editor", "LastOpen");
  36. return _currentFile;
  37. }
  38. set
  39. {
  40. _currentFile = value;
  41. IniFile.WriteValue("Editor", "LastOpen", value);
  42. }
  43. }
  44. string _lastFolder = null;
  45. public string LastFolder
  46. {
  47. get
  48. {
  49. if (string.IsNullOrEmpty(_lastFolder))
  50. {
  51. _lastFolder = IniFile.ReadValue("Editor", "LastFolder");
  52. }
  53. if (string.IsNullOrEmpty(_lastFolder))
  54. {
  55. _lastFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisualCodeEditor");
  56. }
  57. return _lastFolder;
  58. }
  59. set
  60. {
  61. _lastFolder = value;
  62. IniFile.WriteValue("Editor", "LastFolder", value);
  63. }
  64. }
  65. #endregion
  66. #region 操作按钮
  67. private void OnNew(object sender, RoutedEventArgs e)
  68. {
  69. e.Handled = true;
  70. File = null;
  71. //Title = "Visual Code Editor";
  72. //using (var stream = GetType().Assembly.GetManifestResourceStream("ScratchNet.scripts.main.vsc"))
  73. //{
  74. // //Script script = Serialization.Load(stream) as Script;
  75. // //SetupScriptToolbar(script);
  76. // //Editor.Script = script;
  77. // stream.Close();
  78. //}
  79. //Editor.IsEnabled = true;
  80. ButtonOpen.IsEnabled = true;
  81. ButtonSave.IsEnabled = true;
  82. ButtonStart.IsEnabled = true;
  83. ButtonSaveAs.IsEnabled = true;
  84. ButtonPrint.IsEnabled = true;
  85. //Editor.IsModified = true;
  86. }
  87. private void OnOpen(object sender, RoutedEventArgs e)
  88. {
  89. e.Handled = true;
  90. OpenFileDialog dlg = new OpenFileDialog();
  91. dlg.DefaultExt = ".vsc";
  92. dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
  93. dlg.Multiselect = false;
  94. dlg.InitialDirectory = LastFolder;
  95. Nullable<bool> result = dlg.ShowDialog();
  96. if (result == true)
  97. {
  98. //Editor.Script = null;
  99. //Editor.IsEnabled = false;
  100. //File = dlg.FileName;
  101. //LastFolder = new FileInfo(dlg.FileName).DirectoryName;
  102. //try
  103. //{
  104. // Script script = Serialization.Load(File) as Script;
  105. // SetupScriptToolbar(script);
  106. // Editor.Script = script;
  107. // if (script == null)
  108. // return;
  109. // this.Title = Properties.Resources.VisualCodeEditor + " - " + File;
  110. // Editor.IsModified = false;
  111. // ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
  112. //}
  113. //catch (Exception ex)
  114. //{
  115. // MessageBox.Show(string.Format(Properties.Resources.ExceptionLoadFile, File));
  116. // return;
  117. //}
  118. //Editor.IsEnabled = true;
  119. ButtonOpen.IsEnabled = true;
  120. ButtonSave.IsEnabled = true;
  121. ButtonStart.IsEnabled = true;
  122. ButtonSaveAs.IsEnabled = true;
  123. ButtonPrint.IsEnabled = true;
  124. ButtonStart.IsEnabled = true;
  125. }
  126. }
  127. private void OnSave(object sender, RoutedEventArgs e)
  128. {
  129. //if (string.IsNullOrEmpty(File))
  130. //{
  131. // SaveFileDialog dlg = new SaveFileDialog();
  132. // dlg.DefaultExt = ".vsc";
  133. // dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
  134. // //dlg.Multiselect = false;
  135. // if (!string.IsNullOrEmpty(LastFolder))
  136. // dlg.InitialDirectory = LastFolder;
  137. // Nullable<bool> result = dlg.ShowDialog();
  138. // if (result != true)
  139. // {
  140. // return;
  141. // }
  142. // File = dlg.FileName;
  143. // Title = Properties.Resources.VisualCodeEditor + " - " + File;
  144. // LastFolder = new FileInfo(dlg.FileName).DirectoryName;
  145. //}
  146. //Serialization.Save((Script)Editor.Script, File);
  147. //ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
  148. //Editor.IsModified = false;
  149. //ButtonOpen.IsEnabled = true;
  150. //ButtonSave.IsEnabled = true;
  151. //ButtonStart.IsEnabled = true;
  152. //ButtonSaveAs.IsEnabled = true;
  153. //ButtonPrint.IsEnabled = true;
  154. }
  155. private void OnSaveAs(object sender, RoutedEventArgs e)
  156. {
  157. //e.Handled = true;
  158. //SaveFileDialog dlg = new SaveFileDialog();
  159. //dlg.DefaultExt = ".vsc";
  160. //dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
  161. ////dlg.Multiselect = false;
  162. //dlg.InitialDirectory = LastFolder;
  163. //Nullable<bool> result = dlg.ShowDialog();
  164. //if (result != true)
  165. //{
  166. // return;
  167. //}
  168. //File = dlg.FileName;
  169. //LastFolder = new FileInfo(dlg.FileName).DirectoryName;
  170. //Serialization.Save((Script)Editor.Script, File);
  171. //Title = Properties.Resources.VisualCodeEditor + " - " + File;
  172. //ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
  173. //Editor.IsModified = false;
  174. //ButtonOpen.IsEnabled = true;
  175. //ButtonSave.IsEnabled = true;
  176. //ButtonStart.IsEnabled = true;
  177. //ButtonSaveAs.IsEnabled = true;
  178. //ButtonPrint.IsEnabled = true;
  179. }
  180. private void OnPrint(object sender, RoutedEventArgs e)
  181. {
  182. //e.Handled = true;
  183. //Editor.Print();
  184. }
  185. private void OnCopy(object sender, RoutedEventArgs e)
  186. {
  187. //Editor.Copy();
  188. }
  189. private void OnPaste(object sender, RoutedEventArgs e)
  190. {
  191. //Editor.Paste(new Point());
  192. }
  193. private void OnStartRun(object sender, RoutedEventArgs e)
  194. {
  195. //Editor.ClearHighlight();
  196. //stackTrace.Clear();
  197. ////check main function
  198. //bool hasMain = false;
  199. //foreach (var f in Editor.Script.Functions)
  200. //{
  201. // if (f.Name.Equals("main", StringComparison.OrdinalIgnoreCase))
  202. // {
  203. // hasMain = true;
  204. // break;
  205. // }
  206. //}
  207. //if (!hasMain)
  208. //{
  209. // MessageBox.Show(Properties.Resources.MainNotFound, Properties.Resources.NoMain, MessageBoxButton.OK, MessageBoxImage.Warning);
  210. // return;
  211. //}
  212. //ButtonClearError.IsEnabled = false;
  213. //IsHighlightStep = ButtonHighligh.IsChecked.Value;
  214. //stackTrace.Clear();
  215. //engine = new ExecutionEnvironment();
  216. //engine.EnterNode += Engine_EnterNode;
  217. //engine.LeaveNode += Engine_LeaveNode;
  218. //ButtonStart.IsEnabled = false;
  219. //ButtonStop.IsEnabled = true;
  220. ////Editor.IsEnabled = false;
  221. //engine.ExecutionCompleted += Engine_ExecutionCompleted;
  222. //engine.ExecutionAborted += Engine_ExecutionAborted;
  223. //engine.ExecuteAsync(Editor.Script);
  224. //Console.WriteLine("Start run");
  225. return;
  226. }
  227. private void OnStopRun(object sender, RoutedEventArgs e)
  228. {
  229. //if (engine != null)
  230. //{
  231. // engine.EnterNode -= Engine_EnterNode;
  232. // engine.LeaveNode -= Engine_LeaveNode;
  233. // //Editor.IsEnabled = false;
  234. // engine.ExecutionCompleted -= Engine_ExecutionCompleted;
  235. // engine.ExecutionAborted -= Engine_ExecutionAborted;
  236. // engine.Stop();
  237. // PrintLnStatement.Stop();
  238. // engine = null;
  239. // ButtonStart.IsEnabled = true;
  240. // ButtonStop.IsEnabled = false;
  241. //}
  242. }
  243. private void OnClearError(object sender, RoutedEventArgs e)
  244. {
  245. //ButtonClearError.IsEnabled = false;
  246. //Editor.ClearHighlight();
  247. }
  248. private void OnHighlightClicked(object sender, RoutedEventArgs e)
  249. {
  250. // IsHighlightStep = ButtonHighligh.IsChecked.Value;
  251. }
  252. private void OnSpeedValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
  253. {
  254. }
  255. #endregion
  256. }
  257. }