Skip to content

Commit

Permalink
CurrentFiles are no longer generated on each mouse move
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex4SSB committed Feb 1, 2025
1 parent 78d3184 commit 4931699
Showing 1 changed file with 50 additions and 25 deletions.
75 changes: 50 additions & 25 deletions ADB Explorer/Services/AppInfra/CopyPasteService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,45 +150,70 @@ public string[] Files
public string[] DragFiles
{
get => dragFiles;
set => Set(ref dragFiles, value);
set
{
// The Set method only compares instances
if (dragFiles.SequenceEqual(value))
return;

Set(ref dragFiles, value);
_currentFiles = null;
}
}

private FileDescriptor[] descriptors = [];
public FileDescriptor[] Descriptors
{
get => descriptors;
set => Set(ref descriptors, value);
set
{
// The Set method only compares instances
if (descriptors.SequenceEqual(value))
return;

Set(ref descriptors, value);
_currentFiles = null;
}
}

private IEnumerable<FileClass> _currentFiles = [];
public IEnumerable<FileClass> CurrentFiles
{
get
{
if (IsWindows && !IsVirtual)
if (_currentFiles is null)
_currentFiles = GetCurrentFiles();

return _currentFiles;
}
}

private IEnumerable<FileClass> GetCurrentFiles()
{
if (IsWindows && !IsVirtual)
{
foreach (var file in DragFiles)
{
foreach (var file in DragFiles)
{
yield return new(ShellItem.Open(file));
}
yield return new(ShellItem.Open(file));
}
else
}
else
{
for (int i = 0; i < Descriptors.Length; i++)
{
for (int i = 0; i < Descriptors.Length; i++)
{
TrashIndexer indexer = null;
if (DragFiles.Length == Descriptors.Length && CurrentParent is AdbExplorerConst.RECYCLE_PATH)
indexer = new() { RecycleName = DragFiles[i] };
TrashIndexer indexer = null;
if (DragFiles.Length == Descriptors.Length && CurrentParent is AdbExplorerConst.RECYCLE_PATH)
indexer = new() { RecycleName = DragFiles[i] };

var desc = Descriptors[i];
desc.SourcePath = FileHelper.ConcatPaths(CurrentParent, desc.Name);
yield return new(desc)
{
PathType = IsWindows
? FilePathType.Windows
: FilePathType.Android,
TrashIndex = indexer,
};
}
var desc = Descriptors[i];
desc.SourcePath = FileHelper.ConcatPaths(CurrentParent, desc.Name);
yield return new(desc)
{
PathType = IsWindows
? FilePathType.Windows
: FilePathType.Android,
TrashIndex = indexer,
};
}
}
}
Expand Down Expand Up @@ -281,7 +306,7 @@ public DragDropEffects GetAllowedDragEffects(IDataObject dataObject, FrameworkEl
}
else
DragPasteSource &= ~DataSource.None;

PreviewDataObject(dataObject);
if (DragFiles.Length < 1)
return DragDropEffects.None;
Expand Down Expand Up @@ -504,7 +529,7 @@ void ReadObject()
// Skip non top level items
if (e.DestItem.Parent.ParsingName != Data.RuntimeSettings.TempDragPath)
return;

if (lastTopItem is not null && lastTopItem.ParsingName != e.DestItem.ParsingName)
{
// A new top level item means the previous one is done
Expand Down

0 comments on commit 4931699

Please sign in to comment.