mirror of
https://github.com/goatcorp/Dalamud.git
synced 2026-01-02 13:53:40 +01:00
Merge pull request #1314 from Ottermandias/dragdrop
This commit is contained in:
commit
34d5a5e837
2 changed files with 17 additions and 10 deletions
|
|
@ -19,15 +19,21 @@ namespace Dalamud.Interface.DragDrop;
|
||||||
[ResolveVia<IDragDropManager>]
|
[ResolveVia<IDragDropManager>]
|
||||||
internal partial class DragDropManager : IDisposable, IDragDropManager, IServiceType
|
internal partial class DragDropManager : IDisposable, IDragDropManager, IServiceType
|
||||||
{
|
{
|
||||||
[ServiceManager.ServiceDependency]
|
private nint windowHandlePtr = nint.Zero;
|
||||||
private readonly InterfaceManager.InterfaceManagerWithScene interfaceManager = Service<InterfaceManager.InterfaceManagerWithScene>.Get();
|
|
||||||
|
|
||||||
private int lastDropFrame = -2;
|
private int lastDropFrame = -2;
|
||||||
private int lastTooltipFrame = -1;
|
private int lastTooltipFrame = -1;
|
||||||
|
|
||||||
[ServiceManager.ServiceConstructor]
|
[ServiceManager.ServiceConstructor]
|
||||||
private DragDropManager()
|
private DragDropManager()
|
||||||
=> this.Enable();
|
{
|
||||||
|
Service<InterfaceManager.InterfaceManagerWithScene>.GetAsync()
|
||||||
|
.ContinueWith(t =>
|
||||||
|
{
|
||||||
|
this.windowHandlePtr = t.Result.Manager.WindowHandlePtr;
|
||||||
|
this.Enable();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary> Gets a value indicating whether external drag and drop is available at all. </summary>
|
/// <summary> Gets a value indicating whether external drag and drop is available at all. </summary>
|
||||||
public bool ServiceAvailable { get; private set; }
|
public bool ServiceAvailable { get; private set; }
|
||||||
|
|
@ -51,21 +57,21 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService
|
||||||
/// <summary> Enable external drag and drop. </summary>
|
/// <summary> Enable external drag and drop. </summary>
|
||||||
public void Enable()
|
public void Enable()
|
||||||
{
|
{
|
||||||
if (this.ServiceAvailable)
|
if (this.ServiceAvailable || this.windowHandlePtr == nint.Zero)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var ret = DragDropInterop.RegisterDragDrop(this.interfaceManager.Manager.WindowHandlePtr, this);
|
var ret = DragDropInterop.RegisterDragDrop(this.windowHandlePtr, this);
|
||||||
Log.Information($"[DragDrop] Registered window 0x{this.interfaceManager.Manager.WindowHandlePtr:X} for external drag and drop operations. ({ret})");
|
Log.Information($"[DragDrop] Registered window 0x{this.windowHandlePtr:X} for external drag and drop operations. ({ret})");
|
||||||
Marshal.ThrowExceptionForHR(ret);
|
Marshal.ThrowExceptionForHR(ret);
|
||||||
this.ServiceAvailable = true;
|
this.ServiceAvailable = true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error($"Could not create windows drag and drop utility for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}:\n{ex}");
|
Log.Error($"Could not create windows drag and drop utility for window 0x{this.windowHandlePtr:X}:\n{ex}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,13 +85,13 @@ internal partial class DragDropManager : IDisposable, IDragDropManager, IService
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var ret = DragDropInterop.RevokeDragDrop(this.interfaceManager.Manager.WindowHandlePtr);
|
var ret = DragDropInterop.RevokeDragDrop(this.windowHandlePtr);
|
||||||
Log.Information($"[DragDrop] Disabled external drag and drop operations for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}. ({ret})");
|
Log.Information($"[DragDrop] Disabled external drag and drop operations for window 0x{this.windowHandlePtr:X}. ({ret})");
|
||||||
Marshal.ThrowExceptionForHR(ret);
|
Marshal.ThrowExceptionForHR(ret);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error($"Could not disable windows drag and drop utility for window 0x{this.interfaceManager.Manager.WindowHandlePtr:X}:\n{ex}");
|
Log.Error($"Could not disable windows drag and drop utility for window 0x{this.windowHandlePtr:X}:\n{ex}");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ServiceAvailable = false;
|
this.ServiceAvailable = false;
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ internal partial class DragDropManager : DragDropManager.IDropTarget
|
||||||
this.Files = Array.Empty<string>();
|
this.Files = Array.Empty<string>();
|
||||||
this.Directories = Array.Empty<string>();
|
this.Directories = Array.Empty<string>();
|
||||||
this.Extensions = new HashSet<string>();
|
this.Extensions = new HashSet<string>();
|
||||||
|
MouseDrop(this.lastKeyState);
|
||||||
Log.Debug("[DragDrop] Leaving external Drag and Drop.");
|
Log.Debug("[DragDrop] Leaving external Drag and Drop.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue