/// 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; }
/// @copybrief SCFF::Common::ClientApplication::OnProfileSaving /// @param[in] sender 使用しない /// @param[in] e e.Cancelでキャンセル可能 private void OnProfileSaving(object sender, ProfileSavingEventArgs e) { // [保存]で既に一回以上ファイルに保存されている場合はパスの指定は必要ない if (e.Action == SaveActions.Save && e.Path != null && e.Path != string.Empty) return; // ダイアログでパスを指定 var dialog = new SaveFileDialog(); dialog.Title = "SCFF.GUI"; dialog.Filter = "SCFF Profile|*" + Constants.ProfileExtension; dialog.InitialDirectory = e.InitialDirectory; dialog.FileName = e.FileName; var result = dialog.ShowDialog(); if (result.HasValue && (bool)result) { e.Path = dialog.FileName; } else { // e.Cancelをfalseからtrueに e.Cancel = true; } }