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 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; }
public MainWindow() { InitializeComponent(); //AllocConsole(); libs.Add(new LibraryItem() { Library = new MathLibary(), IsStoreLibrary = false, Image = LoadSource("/images/Math.png") }); libs.Add(new LibraryItem() { Library = new CanvasCollection(), IsStoreLibrary = false, Image = LoadSource("/images/PAINT.png") }); libs.Add(new LibraryItem() { Library = new SpeechLibrary(), IsStoreLibrary = false, Image = LoadSource("/images/Microphone.png") }); libs.Add(new LibraryItem() { Library = new CollectionLibary(), IsStoreLibrary = false, Image = LoadSource("/images/list.png") }); libs.Add(new LibraryItem() { Library = new DataStructureLibrary(), IsStoreLibrary = false, Image = LoadSource("/images/collection.png") }); libs.Add(new LibraryItem() { Library = new ThreadCollection(), IsStoreLibrary = false, Image = LoadSource("/images/th.png") }); Editor.IsEnabled = false; Editor.IsLibraryEnabled = true; Editor.Register((Color)ColorConverter.ConvertFromString("#95f0c7"), typeof(StringExpression), typeof(IndexOfStringExpression), typeof(LastIndexOfStringExpression), typeof(SubStringExpression), typeof(StringLengthExpression), typeof(ParseLongExpression), typeof(ParseIntExpression), typeof(ParseFloatExpression), typeof(ParseDoubleExpression)); Editor.Register((Color)ColorConverter.ConvertFromString("#4C97FF"), typeof(PrintLnStatement), typeof(PrintStatement), typeof(ReadLineExpression), typeof(ReadExpression), typeof(ClearStatement)); Editor.Register <IfStatement, TrueExpression, FalseExpression>((Color)ColorConverter.ConvertFromString("#078aab")); Editor.Register((Color)ColorConverter.ConvertFromString("#06cccc"), typeof(NewArrayExpression), typeof(ArrayValueExpression), typeof(NewArray2Expression), typeof(Array2ValueExpression), typeof(ArrayLengthExpression)); foreach (var l in libs) { Color c = (Color)ColorConverter.ConvertFromString(l.Library.DefaultColor); foreach (var g in l.Library) { foreach (var s in g) { Editor.Register(c, s.Step.GetType()); } } } Editor.SetToolBar(CreateToolbar()); Editor.ScacleRatio = ScaleRatio; Editor.TypeColorChanged += EditTypeColorChanged; Editor.ChangeImportLibrary += Editor_ChangeImportLibrary; if ("true".Equals(IniFile.ReadValue("Editor", "IsHighLight"), StringComparison.OrdinalIgnoreCase)) { ButtonHighligh.IsChecked = true; } string speed = IniFile.ReadValue("Editor", "HighLightSpeed"); if (!string.IsNullOrEmpty(speed)) { try { SliderSpeeder.Value = 100 - double.Parse(speed); } catch { } } toast = new Toast(); Unloaded += MainWindow_Unloaded; Loaded += MainWindow_Loaded; LoadColors(); string firstTime = IniFile.ReadValue("Editor", "FirstUsage"); if (string.IsNullOrEmpty(firstTime)) { IniFile.WriteValue("Editor", "FirstUsage", "false"); new Thread(() => { Dispatcher.InvokeAsync(() => { MessageBoxResult ret = MessageBox.Show(this, Properties.Resources.RequestVideo, Properties.Resources.Welcome, MessageBoxButton.YesNo, MessageBoxImage.Information); if (ret == MessageBoxResult.Yes) { OnHelp(null, null); } }); }).Start(); } else if (!string.IsNullOrEmpty(File) && System.IO.File.Exists(File)) { new Thread(() => { Thread.Sleep(500); Dispatcher.Invoke(() => { Editor.Script = null; Editor.IsEnabled = false; try { Script script = Serialization.Load(File) as Script; SetupScriptToolbar(script); Editor.Script = script; this.Title = Properties.Resources.VisualCodeEditor + " - " + File; ShowMessage(toast.ShowSuccess, string.Format(Properties.Resources.SuccessLodFile, File)); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); ShowMessage(toast.ShowWarning, string.Format(Properties.Resources.ExceptionLoadFile, File)); return; } Editor.IsEnabled = true; ButtonStart.IsEnabled = true; ButtonOpen.IsEnabled = true; ButtonSave.IsEnabled = true; ButtonSaveAs.IsEnabled = true; ButtonPrint.IsEnabled = true; //d.PurchaseAddOn("9NG2QVSXT34H"); }); }).Start(); } }