mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-09 15:08:43 +00:00
Offer code blocks of an answer in the export menu
This commit is contained in:
4 files changed
+71
-24
No files matched your search
@@ -140,6 +140,20 @@ public static class FileExportFormatExtensions
|
||||
/// <returns>True for the formats a spreadsheet opens.</returns>
|
||||
public static bool IsTabular(this FileExportFormat format) => format is FileExportFormat.CSV or FileExportFormat.TSV;
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a file of the format is plain text, which AI Studio writes as it is.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// That holds for a web page and a LaTeX document as well, even though an entire answer needs
|
||||
/// Pandoc to become one: the answer is Markdown, whereas a page the model wrote is a finished
|
||||
/// file already. A Word or an OpenDocument file is an archive, and only Pandoc produces one. The
|
||||
/// list is spelled out on purpose, so a format added later counts as plain text only once
|
||||
/// somebody says so.
|
||||
/// </remarks>
|
||||
/// <param name="format">The format.</param>
|
||||
/// <returns>True, when a text written as it is makes a valid file of the format.</returns>
|
||||
public static bool IsPlainText(this FileExportFormat format) => format is FileExportFormat.LATEX or FileExportFormat.MARKDOWN or FileExportFormat.HTML or FileExportFormat.CSV or FileExportFormat.TSV;
|
||||
|
||||
/// <summary>
|
||||
/// Returns the file name the save dialog starts with.
|
||||
/// </summary>
|
||||
|
||||
@@ -178,20 +178,26 @@ public static class PlainFileExport
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given text to a plain text file and lets the user save it.
|
||||
/// Writes the given text to a plain text file as it is and lets the user save it.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Nothing is converted here, which is what sets this apart from PandocExport.ToDocument. A web
|
||||
/// page or a LaTeX document the model wrote is a finished file already and comes through here;
|
||||
/// an entire answer in one of these formats is Markdown and goes to Pandoc instead.
|
||||
/// </remarks>
|
||||
/// <param name="rustService">The Rust service, used for the save dialog.</param>
|
||||
/// <param name="dialogTitle">The title of the save dialog. The caller knows what the user is
|
||||
/// looking at, a chat message or the result of an assistant, so the caller names it.</param>
|
||||
/// <param name="format">The format to write. Must be a format which does not use Pandoc.</param>
|
||||
/// <param name="fileContent">What to write. The caller decides whether that is the entire
|
||||
/// message or one table out of it.</param>
|
||||
/// <param name="format">The format to write. Must be a plain text format, see
|
||||
/// FileExportFormatExtensions.IsPlainText.</param>
|
||||
/// <param name="fileContent">The finished file. The caller decides whether that is the entire
|
||||
/// message or one file out of it.</param>
|
||||
/// <param name="fileName">What the file is about, used to suggest a name in the save dialog.
|
||||
/// Null falls back to a generic name.</param>
|
||||
/// <returns>True, when the file was written.</returns>
|
||||
public static async Task<bool> ToFile(RustService rustService, string dialogTitle, FileExportFormat format, string fileContent, string? fileName = null)
|
||||
{
|
||||
if (format.UsesPandoc() || format.ToFileTypeFilter() is not { } fileTypeFilter)
|
||||
if (!format.IsPlainText() || format.ToFileTypeFilter() is not { } fileTypeFilter)
|
||||
throw new ArgumentOutOfRangeException(nameof(format), format, "AI Studio cannot write this format itself.");
|
||||
|
||||
var response = await rustService.SaveFile(dialogTitle, [fileTypeFilter], format.ToSuggestedFileName(fileName));
|
||||
|
||||
Reference in new issue
Block a user