/// <summary> /// スクリプトファイル名を変更する。 /// </summary> /// <param name="parameters">パラメータ。</param> private void RenameScriptFileName(KeyValueMap parameters) { ScriptDefinition definition = parameters["Definition"]; using (var dialog = new SaveFileDialog()) { dialog.InitialDirectory = Project.ScriptFolderFullPath; dialog.FileName = definition.FileName; dialog.Filter = ApplicationConstants.ScriptFileFilterString; dialog.OverwritePrompt = false; dialog.Title = "ファイル名の変更"; if (dialog.ShowDialog(MainForm) != DialogResult.OK) return; var validator = new ScriptDefinitionValidator(Message, Project, definition); ProvidedMessage result; string newPath = null; result = validator.ValidateFileFullPath(dialog.FileName, ref newPath); if (result != null) { InvokeMessage(result); return; } if (definition.FileName.ToLower() == newPath.ToLower()) return; result = validator.ValidateFileName(newPath); if (result != null) { InvokeMessage(result); return; } try { File.Move(Project.GetScriptFullPath(definition.FileName), Project.GetScriptFullPath(newPath)); } catch (Exception ex) { ProvideMessage("Default.Exception.Error", "スクリプトファイルのリネーム", ex.Message); return; } definition.FileName = newPath; RefreshSelectedNodeProperty(); if (!SaveProject()) return; RefreshObjectDefinition(); } }
/// <summary> /// スクリプト定義を作成する。 /// </summary> /// <param name="parameters">パラメータ。</param> private void CreateScriptDefinition(KeyValueMap parameters) { ScriptDefinition definition = parameters["Definition"]; using (var dialog = new SaveFileDialog()) { dialog.InitialDirectory = Project.ScriptFolderFullPath; dialog.Filter = ApplicationConstants.ScriptFileFilterString; dialog.OverwritePrompt = false; if (dialog.ShowDialog(MainForm) != DialogResult.OK) return; var validator = new ScriptDefinitionValidator(Message, Project, definition); ProvidedMessage result; string newPath = null; result = validator.ValidateFileFullPath(dialog.FileName, ref newPath); if (result != null) { InvokeMessage(result); return; } result = validator.ValidateFileName(newPath); if (result != null) { InvokeMessage(result); return; } var newDefinition = new ScriptDefinition() { FileName = newPath, DisplayName = ApplicationConstants.DefaultScriptName, Guid = Project.NewScriptGuid() }; if (definition == null) { Project.ScriptDefinitions.Add(newDefinition); RefreshScriptNode(newDefinition); } else { definition.Children.Add(newDefinition); RefreshScriptNode(definition); } if (!SaveProject()) return; if (!File.Exists(Project.GetScriptFullPath(newDefinition.FileName))) { try { using (var fs = File.Create(Project.GetScriptFullPath(newDefinition.FileName))) { } } catch (Exception ex) { ProvideMessage("Default.Exception.Error", "スクリプトファイルの作成", ex.Message); return; } } RefreshObjectDefinition(); RegisterScriptEditor(newDefinition); } }