/// コンストラクタ public ProfileSavingEventArgs(SaveActions action, string path, string fileName, string initialDirectory) { // 初期値=キャンセルしない this.Cancel = false; this.Action = action; this.Path = path; this.FileName = fileName; this.InitialDirectory = initialDirectory; }
/// Profileの保存 public bool SaveProfile(SaveActions action) { // Event: ProfileSaving var path = this.RuntimeOptions.ProfilePath; { var fileName = this.HasSaved ? this.RuntimeOptions.ProfileName : "Untitled"; var initialDirectory = this.HasSaved ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath) : Utilities.ApplicationDirectory; var args = new ProfileSavingEventArgs(action, path, fileName, initialDirectory); var handler = this.OnProfileSaving; if (handler != null) handler(this, args); if (args.Cancel) { return false; } else { path = args.Path; } } // データの書き込み var success = this.SaveProfileInternal(path); if (!success) { // Event: ErrorOccured { var message = "Couldn't save the profile"; if (path != null && path != string.Empty) { message = string.Format("Couldn't save the profile to {0}.", path); } var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) handler(this, args); } return false; } // Event: SavedProfile { var handler = this.OnProfileSaved; if (handler != null) handler(this, EventArgs.Empty); } return true; }
/// Profileの保存 public bool SaveProfile(SaveActions action) { // Event: ProfileSaving var path = this.RuntimeOptions.ProfilePath; { var fileName = this.HasSaved ? this.RuntimeOptions.ProfileName : "Untitled"; var initialDirectory = this.HasSaved ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath) : Utilities.ApplicationDirectory; var args = new ProfileSavingEventArgs(action, path, fileName, initialDirectory); var handler = this.OnProfileSaving; if (handler != null) { handler(this, args); } if (args.Cancel) { return(false); } else { path = args.Path; } } // データの書き込み var success = this.SaveProfileInternal(path); if (!success) { // Event: ErrorOccured { var message = "Couldn't save the profile"; if (path != null && path != string.Empty) { message = string.Format("Couldn't save the profile to {0}.", path); } var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) { handler(this, args); } } return(false); } // Event: SavedProfile { var handler = this.OnProfileSaved; if (handler != null) { handler(this, EventArgs.Empty); } } return(true); }
/// コンストラクタ public ProfileSavingEventArgs(SaveActions action, string path, string fileName, string initialDirectory) { // 初期値=キャンセルしない this.Cancel = false; this.Action = action; this.Path = path; this.FileName = fileName; this.InitialDirectory = initialDirectory; }