|
- using BeDesignerSCADA.Helper;
- using Microsoft.Win32;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
-
- namespace BeDesignerSCADA.Controls
- {
- /// <summary>
- /// CodeCanvasPanel.xaml 的交互逻辑
- /// </summary>
- public partial class CodeCanvasPanel : UserControl
- {
- public CodeCanvasPanel()
- {
- InitializeComponent();
- }
-
- #region 变量
- string _currentFile;
- public string File
- {
- get
- {
- if (string.IsNullOrEmpty(_currentFile))
- _currentFile = IniFile.ReadValue("Editor", "LastOpen");
- return _currentFile;
- }
- set
- {
- _currentFile = value;
- IniFile.WriteValue("Editor", "LastOpen", value);
- }
- }
- string _lastFolder = null;
- public string LastFolder
- {
- get
- {
- if (string.IsNullOrEmpty(_lastFolder))
- {
- _lastFolder = IniFile.ReadValue("Editor", "LastFolder");
- }
- if (string.IsNullOrEmpty(_lastFolder))
- {
- _lastFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "VisualCodeEditor");
-
- }
- return _lastFolder;
- }
- set
- {
- _lastFolder = value;
- IniFile.WriteValue("Editor", "LastFolder", value);
- }
- }
- #endregion
-
- #region 操作按钮
- private void OnNew(object sender, RoutedEventArgs e)
- {
- e.Handled = true;
- File = null;
- //Title = "Visual Code Editor";
- //using (var stream = GetType().Assembly.GetManifestResourceStream("ScratchNet.scripts.main.vsc"))
- //{
- // //Script script = Serialization.Load(stream) as Script;
- // //SetupScriptToolbar(script);
- // //Editor.Script = script;
- // stream.Close();
- //}
- //Editor.IsEnabled = true;
- ButtonOpen.IsEnabled = true;
- ButtonSave.IsEnabled = true;
- ButtonStart.IsEnabled = true;
- ButtonSaveAs.IsEnabled = true;
- ButtonPrint.IsEnabled = true;
- //Editor.IsModified = true;
- }
- private void OnOpen(object sender, RoutedEventArgs e)
- {
- e.Handled = true;
- OpenFileDialog dlg = new OpenFileDialog();
- dlg.DefaultExt = ".vsc";
- dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
- dlg.Multiselect = false;
- dlg.InitialDirectory = LastFolder;
- Nullable<bool> result = dlg.ShowDialog();
- if (result == true)
- {
- //Editor.Script = null;
- //Editor.IsEnabled = false;
- //File = dlg.FileName;
- //LastFolder = new FileInfo(dlg.FileName).DirectoryName;
- //try
- //{
- // Script script = Serialization.Load(File) as Script;
- // SetupScriptToolbar(script);
- // Editor.Script = script;
- // if (script == null)
- // return;
- // this.Title = Properties.Resources.VisualCodeEditor + " - " + File;
- // Editor.IsModified = false;
- // ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
- //}
- //catch (Exception ex)
- //{
- // MessageBox.Show(string.Format(Properties.Resources.ExceptionLoadFile, File));
- // return;
- //}
- //Editor.IsEnabled = true;
- ButtonOpen.IsEnabled = true;
- ButtonSave.IsEnabled = true;
- ButtonStart.IsEnabled = true;
- ButtonSaveAs.IsEnabled = true;
- ButtonPrint.IsEnabled = true;
- ButtonStart.IsEnabled = true;
- }
- }
- private void OnSave(object sender, RoutedEventArgs e)
- {
- //if (string.IsNullOrEmpty(File))
- //{
- // SaveFileDialog dlg = new SaveFileDialog();
- // dlg.DefaultExt = ".vsc";
- // dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
- // //dlg.Multiselect = false;
- // if (!string.IsNullOrEmpty(LastFolder))
- // dlg.InitialDirectory = LastFolder;
-
- // Nullable<bool> result = dlg.ShowDialog();
- // if (result != true)
- // {
- // return;
- // }
- // File = dlg.FileName;
- // Title = Properties.Resources.VisualCodeEditor + " - " + File;
- // LastFolder = new FileInfo(dlg.FileName).DirectoryName;
- //}
- //Serialization.Save((Script)Editor.Script, File);
- //ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
- //Editor.IsModified = false;
- //ButtonOpen.IsEnabled = true;
- //ButtonSave.IsEnabled = true;
- //ButtonStart.IsEnabled = true;
- //ButtonSaveAs.IsEnabled = true;
- //ButtonPrint.IsEnabled = true;
- }
- private void OnSaveAs(object sender, RoutedEventArgs e)
- {
- //e.Handled = true;
- //SaveFileDialog dlg = new SaveFileDialog();
- //dlg.DefaultExt = ".vsc";
- //dlg.Filter = "Visual Script Files (*.vsc)|*.vsc|All Files (*.*)|*.*";
- ////dlg.Multiselect = false;
- //dlg.InitialDirectory = LastFolder;
-
- //Nullable<bool> result = dlg.ShowDialog();
- //if (result != true)
- //{
- // return;
- //}
- //File = dlg.FileName;
- //LastFolder = new FileInfo(dlg.FileName).DirectoryName;
- //Serialization.Save((Script)Editor.Script, File);
- //Title = Properties.Resources.VisualCodeEditor + " - " + File;
- //ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File));
- //Editor.IsModified = false;
- //ButtonOpen.IsEnabled = true;
- //ButtonSave.IsEnabled = true;
- //ButtonStart.IsEnabled = true;
- //ButtonSaveAs.IsEnabled = true;
- //ButtonPrint.IsEnabled = true;
- }
- private void OnPrint(object sender, RoutedEventArgs e)
- {
- //e.Handled = true;
- //Editor.Print();
- }
- private void OnCopy(object sender, RoutedEventArgs e)
- {
- //Editor.Copy();
- }
- private void OnPaste(object sender, RoutedEventArgs e)
- {
- //Editor.Paste(new Point());
- }
- private void OnStartRun(object sender, RoutedEventArgs e)
- {
- //Editor.ClearHighlight();
- //stackTrace.Clear();
- ////check main function
- //bool hasMain = false;
- //foreach (var f in Editor.Script.Functions)
- //{
- // if (f.Name.Equals("main", StringComparison.OrdinalIgnoreCase))
- // {
- // hasMain = true;
- // break;
- // }
- //}
- //if (!hasMain)
- //{
- // MessageBox.Show(Properties.Resources.MainNotFound, Properties.Resources.NoMain, MessageBoxButton.OK, MessageBoxImage.Warning);
- // return;
- //}
- //ButtonClearError.IsEnabled = false;
- //IsHighlightStep = ButtonHighligh.IsChecked.Value;
- //stackTrace.Clear();
- //engine = new ExecutionEnvironment();
- //engine.EnterNode += Engine_EnterNode;
- //engine.LeaveNode += Engine_LeaveNode;
- //ButtonStart.IsEnabled = false;
- //ButtonStop.IsEnabled = true;
- ////Editor.IsEnabled = false;
- //engine.ExecutionCompleted += Engine_ExecutionCompleted;
- //engine.ExecutionAborted += Engine_ExecutionAborted;
- //engine.ExecuteAsync(Editor.Script);
- //Console.WriteLine("Start run");
- return;
- }
- private void OnStopRun(object sender, RoutedEventArgs e)
- {
-
- //if (engine != null)
- //{
- // engine.EnterNode -= Engine_EnterNode;
- // engine.LeaveNode -= Engine_LeaveNode;
- // //Editor.IsEnabled = false;
- // engine.ExecutionCompleted -= Engine_ExecutionCompleted;
- // engine.ExecutionAborted -= Engine_ExecutionAborted;
- // engine.Stop();
- // PrintLnStatement.Stop();
- // engine = null;
- // ButtonStart.IsEnabled = true;
- // ButtonStop.IsEnabled = false;
- //}
-
- }
- private void OnClearError(object sender, RoutedEventArgs e)
- {
- //ButtonClearError.IsEnabled = false;
- //Editor.ClearHighlight();
- }
- private void OnHighlightClicked(object sender, RoutedEventArgs e)
- {
- // IsHighlightStep = ButtonHighligh.IsChecked.Value;
- }
- private void OnSpeedValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
- {
-
- }
- #endregion
- }
- }
|