/// <summary> /// Save the script contained in <see cref="scriptPanelViewModel"/>. /// The first time it will show a dialog to save the script and the next times it will overwrite the data. /// </summary> /// <param name="scriptPanelViewModel">The <see cref="IScriptPanelViewModel"/> that contains the script.</param> private void SaveScript(IScriptPanelViewModel scriptPanelViewModel) { var contentScript = scriptPanelViewModel.AvalonEditor.Text; string header; // Check if the content of the Panel is dirty or not to not include the * in the name of the file saved if (scriptPanelViewModel.Caption.EndsWith("*")) { header = scriptPanelViewModel.Caption.Remove(scriptPanelViewModel.Caption.Length - 1); } else { header = scriptPanelViewModel.Caption; } string filePath; if (this.PathScriptingFiles.TryGetValue(header, out filePath) && File.Exists(filePath)) { File.WriteAllText(filePath, contentScript); scriptPanelViewModel.IsDirty = false; return; } // Open the dialog to save the file var extension = scriptPanelViewModel.FileExtension; var filterIndex = this.FindFilterIndex(extension); filePath = this.fileDialogService.GetSaveFileDialog(header, extension, DialogFilters, this.initialDialogPath, filterIndex); var fileName = Path.GetFileName(filePath); if (string.IsNullOrEmpty(filePath) || string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException(String.Format("An error occured with the path or the name of the file, the script has not been saved. " + "Please verify that the path '{0}' amd the name '{1}' are not empty.", filePath, fileName)); } File.WriteAllText(filePath, contentScript); // Update the dictionnary which contains the paths of the open tabs if (this.PathScriptingFiles.ContainsKey(header)) { this.PathScriptingFiles.Remove(header); } scriptPanelViewModel.Caption = fileName; this.PathScriptingFiles.Add(fileName, filePath); scriptPanelViewModel.IsDirty = false; }
/// <summary> /// Initializes a new instance of the <see cref="InputTerminal"/> class. /// </summary> /// <param name="panelViewModel">The <see cref="IScriptPanelViewModel"/> that contains this terminal.</param> public InputTerminal(IScriptPanelViewModel panelViewModel) { this.panelViewModel = panelViewModel; this.PreviousCommands = new List <string>(); this.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto; this.VerticalScrollBarVisibility = ScrollBarVisibility.Auto; this.IsUndoEnabled = false; this.AcceptsReturn = false; this.AcceptsTab = false; this.BorderThickness = new Thickness(0); this.LastPromptIndex = -1; this.AppendText("Results are shown in the output window"); this.InsertNewPrompt(); this.TextChanged += (s, e) => this.ScrollToEnd(); }
/// <summary> /// Initializes a new instance of the <see cref="ScriptPanelEvent"/> class. /// </summary> /// <param name="scriptPanelViewModel">The script panel view model.</param> /// <param name="status">The status.</param> public ScriptPanelEvent(IScriptPanelViewModel scriptPanelViewModel, ScriptPanelStatus status) { this.ScriptPanelViewModel = scriptPanelViewModel; this.Status = status; }