/// <summary>Function to retrieve the default content name, and data.</summary> /// <param name="generatedName">A default name generated by the application.</param> /// <returns>The default content name along with the content data serialized as a byte array. If either the name or data are <b>null</b>, then the user cancelled..</returns> /// <remarks> /// <para> /// Plug in authors may override this method so a custom UI can be presented when creating new content, or return a default set of data and a default name, or whatever they wish. /// </para> /// <para> /// If an empty string (or whitespace) is returned for the name, then the <paramref name="generatedName"/> will be used. /// </para> /// </remarks> protected override Task <(string name, byte[] data)> OnGetDefaultContentAsync(string generatedName) { var sprite = new GorgonSprite { Anchor = new DX.Vector2(0.5f, 0.5f), Size = new DX.Size2F(1, 1) }; byte[] data; using (var stream = new MemoryStream()) { _defaultCodec.Save(sprite, stream); data = stream.ToArray(); } using (var formName = new FormName { Text = Resources.GORSPR_CAPTION_SPRITE_NAME, ObjectName = generatedName ?? string.Empty, ObjectType = ContentType }) { if (formName.ShowDialog(GorgonApplication.MainForm) == DialogResult.OK) { return(Task.FromResult((formName.ObjectName, data))); } } return(Task.FromResult <(string, byte[])>((null, null))); }
private void SaveFile(string type) { switch (type) { case "HDD": SaveFileDialog sf = new SaveFileDialog(); sf.Title = "Save file to " + type; sf.Filter = "XML|*.xml|JSON|*.json|TXT|*.txt|All files(*.*)|*.*"; sf.FileName = GlobalFileInfo.FileName; if (sf.ShowDialog() == DialogResult.Cancel) { return; } string fileName = System.IO.Path.GetFileNameWithoutExtension(sf.FileName); System.IO.File.WriteAllText(sf.FileName, rtb_MainEditor.Text); SetGlobalFileName(System.IO.Path.GetFileNameWithoutExtension(sf.FileName), System.IO.Path.GetExtension(sf.FileName)); _InfoLabel.Print(fileName + " saved. Storage: " + type); break; case "Database": using (var fileNameForm = new FormName(GlobalFileInfo.FileName, GlobalFileInfo.FileType)) { var result = fileNameForm.ShowDialog(); if (result == DialogResult.OK) { string content = rtb_MainEditor.Text; //Save file in task Task.Run(() => DatabaseHelper.SaveFileToDatabase(content, fileNameForm.FileName, fileNameForm.FileType, _InfoLabel)); SetGlobalFileName(fileNameForm.FileName, fileNameForm.FileType); } } break; default: break; } }