private void CodeBoxSaveCommand_Executed(object sender, ExecutedRoutedEventArgs e) { CodeBoxSaveButton.Focus(); _m.CanExecuteCommand = false; Global.MainViewModel.WorkInProgress = true; try { _m.SaveCodeBox(); } finally { _m.CanExecuteCommand = true; Global.MainViewModel.WorkInProgress = false; CommandManager.InvalidateRequerySuggested(); CodeBoxInputTextBox.Focus(); } }
private async void CodeBoxRunCommand_Executed(object sender, ExecutedRoutedEventArgs e) { CodeBoxRunButton.Focus(); _m.CanExecuteCommand = false; try { // Save CodeBox first _m.SaveCodeBox(); // Run Engine if (Engine.TryEnterLock()) { try { Project project = _m.CurrentProject; Script sc = project.LoadScriptRuntime(_m.CodeFile, new LoadScriptRuntimeOptions { IgnoreMain = true }); MainViewModel mainModel = Global.MainViewModel; mainModel.BuildTreeItems.Clear(); mainModel.SwitchNormalBuildInterface = false; mainModel.WorkInProgress = true; EngineState s = new EngineState(sc.Project, Global.Logger, mainModel, EngineMode.RunMainAndOne, sc); s.SetOptions(Global.Setting); s.SetCompat(sc.Project.Compat); Engine.WorkingEngine = new Engine(s); // Set StatusBar Text using (CancellationTokenSource ct = new CancellationTokenSource()) { Task printStatus = MainViewModel.PrintBuildElapsedStatus("Running CodeBox...", s, ct.Token); await Engine.WorkingEngine.Run($"CodeBox - {project.ProjectName}"); // Cancel and Wait until PrintBuildElapsedStatus stops ct.Cancel(); await printStatus; } // Turn off progress ring mainModel.WorkInProgress = false; // Build ended, Switch to Normal View mainModel.SwitchNormalBuildInterface = true; mainModel.BuildTreeItems.Clear(); // Report elapsed build time string haltReason = s.RunResultReport(); if (haltReason != null) { mainModel.StatusBarText = $"CodeBox took {s.Elapsed:h\\:mm\\:ss}, stopped by {haltReason}"; } else { mainModel.StatusBarText = $"CodeBox took {s.Elapsed:h\\:mm\\:ss}"; } s.MainViewModel.DisplayScript(mainModel.CurMainTree.Script); if (Global.Setting.General.ShowLogAfterBuild && LogWindow.Count == 0) { // Open BuildLogWindow Application.Current?.Dispatcher?.Invoke(() => { if (!(Application.Current.MainWindow is MainWindow w)) { return; } w.LogDialog = new LogWindow(1); w.LogDialog.Show(); }); } } finally { Engine.WorkingEngine = null; Engine.ExitLock(); } } } finally { _m.CanExecuteCommand = true; CommandManager.InvalidateRequerySuggested(); CodeBoxInputTextBox.Focus(); } }