Skip to content

Commit d500f26

Browse files
committed
Clipboard multi-file integration
1 parent b21f570 commit d500f26

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

SmartImage 3/App/Integration.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,31 @@ public static bool ReadClipboardImage(out byte[] i)
260260
}
261261
}
262262

263-
public static bool ReadClipboard(out string str)
263+
public static bool ReadClipboard(out string[] str)
264264
{
265265
Clipboard.Open();
266-
266+
str = Array.Empty<string>();
267267
/*
268268
* 1 File
269269
*/
270270

271+
if (Clipboard.IsFormatAvailable((uint) ClipboardFormat.CF_HDROP)) {
272+
// var d = Clipboard.GetData((uint) ClipboardFormat.CF_HDROP);
273+
var files = Clipboard.GetDragQueryList();
274+
str = files;
275+
goto cl;
276+
}
277+
271278
var data = Clipboard.GetData((uint) ClipboardFormat.FileNameW);
272279

273280
if (data is IntPtr { } p && p == IntPtr.Zero) {
274281
str = null;
275282
}
276283
else {
277-
str = (string) data;
284+
str = new string[] { (string) data };
278285
}
279286

280-
if (!string.IsNullOrWhiteSpace(str)) goto cl;
287+
if (str is { } && str.Any()) goto cl;
281288

282289
/*
283290
* 3 Text
@@ -290,16 +297,16 @@ public static bool ReadClipboard(out string str)
290297
str = null;
291298
}
292299
else {
293-
str = (string) o;
300+
str = new string[] { (string) o };
294301
}
295302

296303
if (o is nint n && n != nint.Zero) {
297304
// str = (string) o;
298305

299-
str = Marshal.PtrToStringUni(n);
306+
str = new[] { Marshal.PtrToStringUni(n) };
300307
}
301308

302-
if (!string.IsNullOrWhiteSpace(str)) goto cl;
309+
if (str is { } && str.Any()) goto cl;
303310
}
304311

305312
/*
@@ -314,15 +321,17 @@ public static bool ReadClipboard(out string str)
314321
File.WriteAllBytes(s, ms);
315322
}
316323

317-
str = s;
324+
str = new[] { s };
318325
Debug.WriteLine($"read png from clipboard {s}");
319326
}
320327

321328
cl:
322329
Clipboard.Close();
323330
Debug.WriteLine($"Clipboard data: {str}");
331+
str = str.Where(SearchQuery.IsValidSourceType).ToArray();
324332

325-
var b = SearchQuery.IsValidSourceType(str);
333+
// var b = SearchQuery.IsValidSourceType(str);
334+
var b = str.Any();
326335
return b;
327336
}
328337

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static ShellMode() { }
275275
#endregion
276276

277277
#region Fields/properties
278-
278+
279279
private object m_cbCallbackTok;
280280

281281
private Func<bool>? m_runIdleTok;
@@ -961,9 +961,17 @@ private bool ClipboardCallback(MainLoop c)
961961

962962
var s = Tf_Input.Text.ToString().CleanString();
963963

964-
var rc = Integration.ReadClipboard(out var str);
964+
var rc = Integration.ReadClipboard(out var strs);
965+
string str = strs[0];
966+
967+
if (QueueMode) {
968+
foreach (string str1 in strs[1..]) {
969+
Queue.Enqueue(str1);
970+
}
971+
}
965972

966-
var b = !m_clipboard.Contains(str);
973+
// var b = !m_clipboard.Contains(str);
974+
var b = strs.Any(s => !m_clipboard.Contains(s));
967975

968976
if ( /*!SearchQuery.IsValidSourceType(s)
969977
&&*/ rc && b

0 commit comments

Comments
 (0)