Enhanced drag-and-drop functionality in AttachDocuments

This commit is contained in:
Thorsten Sommer 2025-12-17 19:46:26 +01:00
parent 12b5f060eb
commit db11f5c99e
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
3 changed files with 50 additions and 6 deletions

View File

@ -1501,6 +1501,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T1637046680"] = "Click t
-- Drag and drop files into the marked area or click here to attach documents:
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T230755331"] = "Drag and drop files into the marked area or click here to attach documents:"
-- Click here to attach files
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T2393263310"] = "Click here to attach files"
-- Document Preview
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T285154968"] = "Document Preview"
@ -1510,9 +1513,6 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T2928927510"] = "Videos
-- Images are not supported yet
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T298062956"] = "Images are not supported yet"
-- Click to attach files
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T3521845090"] = "Click to attach files"
-- Clear file list
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T3759696136"] = "Clear file list"
@ -1525,6 +1525,9 @@ UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T4167762413"] = "Executa
-- Select a file to attach
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T595772870"] = "Select a file to attach"
-- Drop files here to attach them
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::ATTACHDOCUMENTS::T602877785"] = "Drop files here to attach them"
-- Changelog
UI_TEXT_CONTENT["AISTUDIO::COMPONENTS::CHANGELOG::T3017574265"] = "Changelog"

View File

@ -3,7 +3,27 @@
@if (this.UseSmallForm)
{
<div @onmouseenter="@this.OnMouseEnter" @onmouseleave="@this.OnMouseLeave">
@if (this.DocumentPaths.Any())
@if (this.isDraggingOver)
{
<MudBadge
Content="@this.DocumentPaths.Count"
Color="Color.Primary"
Overlap="true"
Class="cursor-pointer"
OnClick="@this.OpenAttachmentsDialog">
<MudLink OnClick="@this.AddFilesManually" Style="text-decoration: none;">
<MudTextField T="string"
Text="@DROP_FILES_HERE_TEXT"
Adornment="Adornment.Start"
AdornmentIcon="@Icons.Material.Filled.AttachFile"
Typo="Typo.body2"
Variant="Variant.Outlined"
ReadOnly="true"
/>
</MudLink>
</MudBadge>
}
else if (this.DocumentPaths.Any())
{
<MudTooltip Text="@T("Click the paperclip to attach files, or click the number to see your attached files")" Placement="@TOOLBAR_TOOLTIP_PLACEMENT">
<MudBadge

View File

@ -1,4 +1,5 @@
using AIStudio.Dialogs;
using AIStudio.Tools.PluginSystem;
using AIStudio.Tools.Rust;
using AIStudio.Tools.Services;
@ -10,6 +11,8 @@ using DialogOptions = Dialogs.DialogOptions;
public partial class AttachDocuments : MSGComponentBase
{
private static string TB(string fallbackEN) => I18N.I.T(fallbackEN, typeof(AttachDocuments).Namespace, nameof(AttachDocuments));
[Parameter]
public string Name { get; set; } = string.Empty;
@ -41,6 +44,11 @@ public partial class AttachDocuments : MSGComponentBase
private IDialogService DialogService { get; init; } = null!;
private const Placement TOOLBAR_TOOLTIP_PLACEMENT = Placement.Top;
private static readonly string DROP_FILES_HERE_TEXT = TB("Drop files here to attach them");
private bool isComponentHovered;
private bool isDraggingOver;
#region Overrides of MSGComponentBase
@ -61,10 +69,23 @@ public partial class AttachDocuments : MSGComponentBase
return;
}
this.isDraggingOver = true;
this.SetDragClass();
this.StateHasChanged();
break;
case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_CANCELED }:
this.isDraggingOver = false;
this.StateHasChanged();
break;
case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.WINDOW_NOT_FOCUSED }:
this.isDraggingOver = false;
this.isComponentHovered = false;
this.ClearDragClass();
this.StateHasChanged();
break;
case Event.TAURI_EVENT_RECEIVED when data is TauriEvent { EventType: TauriEventType.FILE_DROP_DROPPED, Payload: var paths }:
if(!this.isComponentHovered && !this.CatchAllDocuments)
{
@ -82,6 +103,8 @@ public partial class AttachDocuments : MSGComponentBase
await this.DocumentPathsChanged.InvokeAsync(this.DocumentPaths);
await this.OnChange(this.DocumentPaths);
this.isDraggingOver = false;
this.ClearDragClass();
this.StateHasChanged();
break;
}
@ -93,8 +116,6 @@ public partial class AttachDocuments : MSGComponentBase
private string dragClass = DEFAULT_DRAG_CLASS;
private bool isComponentHovered;
private async Task AddFilesManually()
{
var selectedFile = await this.RustService.SelectFile(T("Select a file to attach"));