mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-10-18 09:57:59 +00:00
Added a name question when copying a chat
This commit is contained in:
3 files changed
+45
-8
No files matched your search
@@ -12973,20 +12973,32 @@ UI_TEXT_CONTENT["AISTUDIO::TOOLS::VALIDATION::PROVIDERVALIDATION::T818893091"] =
|
|||||||
-- Are you sure you want to delete the chat '{0}' in the workspace '{1}'?
|
-- Are you sure you want to delete the chat '{0}' in the workspace '{1}'?
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1016188706"] = "Are you sure you want to delete the chat '{0}' in the workspace '{1}'?"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1016188706"] = "Are you sure you want to delete the chat '{0}' in the workspace '{1}'?"
|
||||||
|
|
||||||
|
-- Copy Chat
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1192756314"] = "Copy Chat"
|
||||||
|
|
||||||
-- Unnamed workspace
|
-- Unnamed workspace
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1307384014"] = "Unnamed workspace"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1307384014"] = "Unnamed workspace"
|
||||||
|
|
||||||
|
-- Copy
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T1703884388"] = "Copy"
|
||||||
|
|
||||||
-- Delete Chat
|
-- Delete Chat
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T2244038752"] = "Delete Chat"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T2244038752"] = "Delete Chat"
|
||||||
|
|
||||||
|
-- Please enter a chat name.
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T2301651387"] = "Please enter a chat name."
|
||||||
|
|
||||||
-- Are you sure you want to delete the temporary chat '{0}'?
|
-- Are you sure you want to delete the temporary chat '{0}'?
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3043761007"] = "Are you sure you want to delete the temporary chat '{0}'?"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3043761007"] = "Are you sure you want to delete the temporary chat '{0}'?"
|
||||||
|
|
||||||
-- Unnamed chat
|
-- Unnamed chat
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3310482275"] = "Unnamed chat"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3310482275"] = "Unnamed chat"
|
||||||
|
|
||||||
|
-- Please enter a name for the copy of your chat '{0}':
|
||||||
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3323676840"] = "Please enter a name for the copy of your chat '{0}':"
|
||||||
|
|
||||||
-- Copy of {0}
|
-- Copy of {0}
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3365678931"] = "Copy of {0}"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3365678931"] = "Copy of {0}"
|
||||||
|
|
||||||
-- Empty chat
|
-- Chat Name
|
||||||
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T4019509364"] = "Empty chat"
|
UI_TEXT_CONTENT["AISTUDIO::TOOLS::WORKSPACEBEHAVIOUR::T3891063690"] = "Chat Name"
|
||||||
@@ -819,7 +819,9 @@ public partial class Workspaces : MSGComponentBase
|
|||||||
}
|
}
|
||||||
|
|
||||||
var sourceChat = isCopyOfOpenChat ? openChat! : chat;
|
var sourceChat = isCopyOfOpenChat ? openChat! : chat;
|
||||||
var copy = await WorkspaceBehaviour.CopyChatAsync(sourceChat);
|
var copy = await WorkspaceBehaviour.CopyChatAsync(this.DialogService, sourceChat);
|
||||||
|
if (copy is null)
|
||||||
|
return;
|
||||||
|
|
||||||
await this.LoadTreeItemsAsync(startPrefetch: false);
|
await this.LoadTreeItemsAsync(startPrefetch: false);
|
||||||
this.CurrentChatThread = copy;
|
this.CurrentChatThread = copy;
|
||||||
|
|||||||
@@ -789,23 +789,46 @@ public static class WorkspaceBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Copies a chat into a new chat of the same workspace, including its managed transcript files.
|
/// Copies a chat into a new chat of the same workspace, including its managed transcript files,
|
||||||
|
/// after asking the user for the name of the copy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="dialogService">Used to ask for the name.</param>
|
||||||
/// <param name="sourceChat">The chat to copy. Its own files and state stay untouched.</param>
|
/// <param name="sourceChat">The chat to copy. Its own files and state stay untouched.</param>
|
||||||
/// <returns>The persisted copy.</returns>
|
/// <returns>The persisted copy. Null when the user canceled the question, in which case nothing was copied.</returns>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
|
/// This is the one place that asks for the name of a copy, so every way of copying a chat
|
||||||
|
/// suggests the same name and words the question the same way.<br/><br/>
|
||||||
|
///
|
||||||
/// The copy is written before it is returned, so the caller may open it right away. Runtime-only
|
/// The copy is written before it is returned, so the caller may open it right away. Runtime-only
|
||||||
/// state of the source is not part of the copy: it is rebuilt when the copy gets loaded.
|
/// state of the source is not part of the copy: it is rebuilt when the copy gets loaded. When
|
||||||
|
/// the copy cannot be written, nothing of it stays behind and the error reaches the caller.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public static async Task<ChatThread> CopyChatAsync(ChatThread sourceChat)
|
public static async Task<ChatThread?> CopyChatAsync(IDialogService dialogService, ChatThread sourceChat)
|
||||||
{
|
{
|
||||||
|
var sourceName = string.IsNullOrWhiteSpace(sourceChat.Name) ? TB("Unnamed chat") : sourceChat.Name;
|
||||||
|
var dialogParameters = new DialogParameters<SingleInputDialog>
|
||||||
|
{
|
||||||
|
{ x => x.Message, string.Format(TB("Please enter a name for the copy of your chat '{0}':"), sourceName) },
|
||||||
|
{ x => x.InputHeaderText, TB("Chat Name") },
|
||||||
|
{ x => x.UserInput, string.Format(TB("Copy of {0}"), sourceName) },
|
||||||
|
{ x => x.ConfirmText, TB("Copy") },
|
||||||
|
{ x => x.ConfirmColor, Color.Info },
|
||||||
|
{ x => x.AllowEmptyInput, false },
|
||||||
|
{ x => x.EmptyInputErrorMessage, TB("Please enter a chat name.") },
|
||||||
|
};
|
||||||
|
|
||||||
|
var dialogReference = await dialogService.ShowAsync<SingleInputDialog>(TB("Copy Chat"), dialogParameters, Dialogs.DialogOptions.FULLSCREEN);
|
||||||
|
var dialogResult = await dialogReference.Result;
|
||||||
|
if (dialogResult is null || dialogResult.Canceled)
|
||||||
|
return null;
|
||||||
|
|
||||||
var serializedChat = JsonSerializer.Serialize(sourceChat, JSON_OPTIONS);
|
var serializedChat = JsonSerializer.Serialize(sourceChat, JSON_OPTIONS);
|
||||||
var copiedChat = JsonSerializer.Deserialize<ChatThread>(serializedChat, JSON_OPTIONS)
|
var copiedChat = JsonSerializer.Deserialize<ChatThread>(serializedChat, JSON_OPTIONS)
|
||||||
?? throw new InvalidOperationException("The chat could not be copied.");
|
?? throw new InvalidOperationException("The chat could not be copied.");
|
||||||
copiedChat = copiedChat with
|
copiedChat = copiedChat with
|
||||||
{
|
{
|
||||||
ChatId = Guid.NewGuid(),
|
ChatId = Guid.NewGuid(),
|
||||||
Name = string.Format(TB("Copy of {0}"), string.IsNullOrWhiteSpace(sourceChat.Name) ? TB("Empty chat") : sourceChat.Name),
|
Name = (dialogResult.Data as string)!,
|
||||||
};
|
};
|
||||||
|
|
||||||
var targetDirectory = GetChatDirectory(copiedChat.WorkspaceId, copiedChat.ChatId);
|
var targetDirectory = GetChatDirectory(copiedChat.WorkspaceId, copiedChat.ChatId);
|
||||||
|
|||||||
Reference in new issue
Block a user