mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-14 17:57:06 -05:00
DroppedNestFiles.Select keeps the dropped paths with the .nest extension in any case, as the WinForms main window does, ignoring everything else. It returns full paths in the order dropped, each once however its path is written, compared as NestTabs compares open files. Any says whether the drop holds a nest file, so a window accepts it only then. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
41 lines
1.4 KiB
C#
41 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using OpenNest.IO;
|
|
|
|
namespace OpenNest.Desktop;
|
|
|
|
/// <summary>
|
|
/// Which files dropped on the main window open as nests, as in the WinForms app: only paths
|
|
/// with the .nest extension (in any case); everything else is ignored.
|
|
/// </summary>
|
|
public static class DroppedNestFiles
|
|
{
|
|
/// <summary>Whether the drop holds a nest file, so the window accepts it.</summary>
|
|
public static bool Any(IEnumerable<string> paths) => Select(paths).Count > 0;
|
|
|
|
/// <summary>
|
|
/// The dropped nest files to open, in the order dropped, each once (a file dropped twice,
|
|
/// however its path is written, opens one tab).
|
|
/// </summary>
|
|
public static IReadOnlyList<string> Select(IEnumerable<string> paths)
|
|
{
|
|
var nests = new List<string>();
|
|
if (paths == null)
|
|
return nests;
|
|
var seen = new HashSet<string>(NestTabs.PathComparer);
|
|
foreach (var path in paths)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(path) || !IsNestFile(path))
|
|
continue;
|
|
var fullPath = System.IO.Path.GetFullPath(path);
|
|
if (seen.Add(fullPath))
|
|
nests.Add(fullPath);
|
|
}
|
|
return nests;
|
|
}
|
|
|
|
private static bool IsNestFile(string path) => string.Equals(
|
|
System.IO.Path.GetExtension(path), NestFormat.FileExtension,
|
|
StringComparison.OrdinalIgnoreCase);
|
|
}
|