mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-23 17:09:17 +01:00
Fix some problems.
This commit is contained in:
parent
ca69aae500
commit
4b3253b9e7
2 changed files with 18 additions and 13 deletions
|
|
@ -35,16 +35,17 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService
|
||||||
/// <summary> Gets a value indicating whether a valid external drag and drop is currently active and hovering over any FFXIV-related viewport. </summary>
|
/// <summary> Gets a value indicating whether a valid external drag and drop is currently active and hovering over any FFXIV-related viewport. </summary>
|
||||||
public bool IsDragging { get; private set; }
|
public bool IsDragging { get; private set; }
|
||||||
|
|
||||||
/// <summary> Gets a value indicating whether there are any files or directories currently being dragged. </summary>
|
/// <summary> Gets a value indicating whether there are any files or directories currently being dragged, or stored from the last drop. </summary>
|
||||||
public bool HasPaths { get; private set; }
|
public bool HasPaths
|
||||||
|
=> this.Files.Count + this.Directories.Count > 0;
|
||||||
|
|
||||||
/// <summary> Gets the list of file paths currently being dragged from an external application over any FFXIV-related viewport. </summary>
|
/// <summary> Gets the list of file paths currently being dragged from an external application over any FFXIV-related viewport, or stored from the last drop. </summary>
|
||||||
public IReadOnlyList<string> Files { get; private set; } = Array.Empty<string>();
|
public IReadOnlyList<string> Files { get; private set; } = Array.Empty<string>();
|
||||||
|
|
||||||
/// <summary> Gets a set of all extensions available in the paths currently being dragged from an external application over any FFXIV-related viewport. </summary>
|
/// <summary> Gets a set of all extensions available in the paths currently being dragged from an external application over any FFXIV-related viewport or stored from the last drop. </summary>
|
||||||
public IReadOnlySet<string> Extensions { get; private set; } = new HashSet<string>();
|
public IReadOnlySet<string> Extensions { get; private set; } = new HashSet<string>();
|
||||||
|
|
||||||
/// <summary> Gets the list of directory paths currently being dragged from an external application over any FFXIV-related viewport. </summary>
|
/// <summary> Gets the list of directory paths currently being dragged from an external application over any FFXIV-related viewport or stored from the last drop. </summary>
|
||||||
public IReadOnlyList<string> Directories { get; private set; } = Array.Empty<string>();
|
public IReadOnlyList<string> Directories { get; private set; } = Array.Empty<string>();
|
||||||
|
|
||||||
/// <summary> Enable external drag and drop. </summary>
|
/// <summary> Enable external drag and drop. </summary>
|
||||||
|
|
@ -96,7 +97,7 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService
|
||||||
/// <inheritdoc cref="IDragDropManager.CreateImGuiSource(string, Func{IDragDropManager, bool}, Func{IDragDropManager, bool})"/>
|
/// <inheritdoc cref="IDragDropManager.CreateImGuiSource(string, Func{IDragDropManager, bool}, Func{IDragDropManager, bool})"/>
|
||||||
public void CreateImGuiSource(string label, Func<IDragDropManager, bool> validityCheck, Func<IDragDropManager, bool> tooltipBuilder)
|
public void CreateImGuiSource(string label, Func<IDragDropManager, bool> validityCheck, Func<IDragDropManager, bool> tooltipBuilder)
|
||||||
{
|
{
|
||||||
if (!this.HasPaths && !this.IsDropping())
|
if (!this.IsDragging && !this.IsDropping())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -120,7 +121,7 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService
|
||||||
{
|
{
|
||||||
files = Array.Empty<string>();
|
files = Array.Empty<string>();
|
||||||
directories = Array.Empty<string>();
|
directories = Array.Empty<string>();
|
||||||
if (!this.IsDragging || !ImGui.BeginDragDropTarget())
|
if (!this.HasPaths || !ImGui.BeginDragDropTarget())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
using System.Runtime.InteropServices.ComTypes;
|
using System.Runtime.InteropServices.ComTypes;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
|
|
@ -15,6 +16,7 @@ namespace Dalamud.Interface.DragDrop;
|
||||||
internal partial class DragDropManager : DragDropManager.IDropTarget
|
internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
{
|
{
|
||||||
private int lastUpdateFrame = -1;
|
private int lastUpdateFrame = -1;
|
||||||
|
private DragDropInterop.ModifierKeys lastKeyState = DragDropInterop.ModifierKeys.MK_NONE;
|
||||||
|
|
||||||
/// <summary> Create the drag and drop formats we accept. </summary>
|
/// <summary> Create the drag and drop formats we accept. </summary>
|
||||||
private static FORMATETC FormatEtc =
|
private static FORMATETC FormatEtc =
|
||||||
|
|
@ -37,7 +39,7 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
public void DragEnter(IDataObject pDataObj, uint grfKeyState, POINTL pt, ref uint pdwEffect)
|
public void DragEnter(IDataObject pDataObj, uint grfKeyState, POINTL pt, ref uint pdwEffect)
|
||||||
{
|
{
|
||||||
this.IsDragging = true;
|
this.IsDragging = true;
|
||||||
UpdateIo((DragDropInterop.ModifierKeys)grfKeyState, true);
|
this.lastKeyState = UpdateIo((DragDropInterop.ModifierKeys)grfKeyState, true);
|
||||||
|
|
||||||
if (pDataObj.QueryGetData(ref FormatEtc) != 0)
|
if (pDataObj.QueryGetData(ref FormatEtc) != 0)
|
||||||
{
|
{
|
||||||
|
|
@ -47,9 +49,9 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
{
|
{
|
||||||
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
||||||
(this.Files, this.Directories) = this.GetPaths(pDataObj);
|
(this.Files, this.Directories) = this.GetPaths(pDataObj);
|
||||||
this.HasPaths = this.Files.Count + this.Directories.Count > 0;
|
|
||||||
this.Extensions = this.Files.Select(Path.GetExtension).Where(p => !p.IsNullOrEmpty()).Distinct().ToHashSet();
|
this.Extensions = this.Files.Select(Path.GetExtension).Where(p => !p.IsNullOrEmpty()).Distinct().ToHashSet();
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.Debug("[DragDrop] Entering external Drag and Drop with {KeyState} at {PtX}, {PtY} and with {N} files.", (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y, this.Files.Count + this.Directories.Count);
|
Log.Debug("[DragDrop] Entering external Drag and Drop with {KeyState} at {PtX}, {PtY} and with {N} files.", (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y, this.Files.Count + this.Directories.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +66,7 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
if (frame != this.lastUpdateFrame)
|
if (frame != this.lastUpdateFrame)
|
||||||
{
|
{
|
||||||
this.lastUpdateFrame = frame;
|
this.lastUpdateFrame = frame;
|
||||||
UpdateIo((DragDropInterop.ModifierKeys)grfKeyState, false);
|
this.lastKeyState = UpdateIo((DragDropInterop.ModifierKeys)grfKeyState, false);
|
||||||
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
||||||
Log.Verbose("[DragDrop] External Drag and Drop with {KeyState} at {PtX}, {PtY}.", (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y);
|
Log.Verbose("[DragDrop] External Drag and Drop with {KeyState} at {PtX}, {PtY}.", (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y);
|
||||||
}
|
}
|
||||||
|
|
@ -87,10 +89,10 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
/// <param name="pdwEffect"> Effects that can be used with this drag and drop process. </param>
|
/// <param name="pdwEffect"> Effects that can be used with this drag and drop process. </param>
|
||||||
public void Drop(IDataObject pDataObj, uint grfKeyState, POINTL pt, ref uint pdwEffect)
|
public void Drop(IDataObject pDataObj, uint grfKeyState, POINTL pt, ref uint pdwEffect)
|
||||||
{
|
{
|
||||||
MouseDrop((DragDropInterop.ModifierKeys)grfKeyState);
|
MouseDrop(this.lastKeyState);
|
||||||
this.lastDropFrame = ImGui.GetFrameCount();
|
this.lastDropFrame = ImGui.GetFrameCount();
|
||||||
this.IsDragging = false;
|
this.IsDragging = false;
|
||||||
if (this.Files.Count > 0 || this.Directories.Count > 0)
|
if (this.HasPaths)
|
||||||
{
|
{
|
||||||
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
pdwEffect &= (uint)DragDropInterop.DropEffects.Copy;
|
||||||
}
|
}
|
||||||
|
|
@ -102,7 +104,7 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
Log.Debug("[DragDrop] Dropping {N} files with {KeyState} at {PtX}, {PtY}.", this.Files.Count + this.Directories.Count, (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y);
|
Log.Debug("[DragDrop] Dropping {N} files with {KeyState} at {PtX}, {PtY}.", this.Files.Count + this.Directories.Count, (DragDropInterop.ModifierKeys)grfKeyState, pt.x, pt.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UpdateIo(DragDropInterop.ModifierKeys keys, bool entering)
|
private static DragDropInterop.ModifierKeys UpdateIo(DragDropInterop.ModifierKeys keys, bool entering)
|
||||||
{
|
{
|
||||||
var io = ImGui.GetIO();
|
var io = ImGui.GetIO();
|
||||||
void UpdateMouse(int mouseIdx)
|
void UpdateMouse(int mouseIdx)
|
||||||
|
|
@ -163,6 +165,8 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
io.KeyShift = false;
|
io.KeyShift = false;
|
||||||
io.AddKeyEvent(ImGuiKey.LeftShift, false);
|
io.AddKeyEvent(ImGuiKey.LeftShift, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MouseDrop(DragDropInterop.ModifierKeys keys)
|
private static void MouseDrop(DragDropInterop.ModifierKeys keys)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue