예제 #1
0
        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();
            }
        }