Skip to content

Commit cca53dc

Browse files
committed
Work on option to disable clipboard integration
1 parent bb1304b commit cca53dc

File tree

5 files changed

+67
-11
lines changed

5 files changed

+67
-11
lines changed

SmartImage 3/App/Integration.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using System.Reflection;
99
using System.Runtime.InteropServices;
1010
using System.Runtime.Versioning;
11+
using System.Text;
1112
using Novus.OS;
1213
using Novus;
1314
using Novus.Win32;
@@ -226,8 +227,10 @@ public static void KeepOnTop(bool add)
226227

227228
public static bool ReadClipboardImage(out byte[] i)
228229
{
229-
const uint png = (uint) ClipboardFormat.PNG;
230-
230+
const uint png = (uint) ClipboardFormat.PNG;
231+
// var sb = new StringBuilder(2048);
232+
// var l=Native.GetClipboardFormatName(png, sb, sb.Length);
233+
// Debug.WriteLine($"{sb} {l}");
231234
if (Clipboard.IsFormatAvailable(png)) {
232235
i = Clipboard.GetData(png) as byte[];
233236
return true;

SmartImage 3/Mode/Shell/ShellMode.Dialog.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,25 @@ void ReloadDialog()
265265
Config.Silent = !b;
266266
ReloadDialog();
267267
};
268-
268+
269269
cbSilent.Checked = Config.Silent;
270270

271+
CheckBox cbCb = new(R1.S_Clipboard)
272+
{
273+
X = Pos.Right(cbOpenRaw) + 1,
274+
Y = Pos.Y(cbOpenRaw),
275+
// Width = WIDTH,
276+
Height = 1,
277+
AutoSize = true,
278+
ColorScheme = UI.Cs_Btn3,
279+
Checked = UseClipboard
280+
};
281+
282+
cbCb.Toggled += b =>
283+
{
284+
UseClipboard = !b;
285+
};
286+
271287
/*============================================================================*\
272288
Eh username/password
273289
\*============================================================================*/
@@ -363,7 +379,7 @@ void OnAction(ListView lv, Action<SearchEngineOptions> f)
363379
dlCfg.Add(tvConfig, lvSearchEngines, lvPriorityEngines,
364380
cbContextMenu, cbOnTop, lbConfig, lbSearchEngines, lbPriorityEngines,
365381
lbHelp, cbAutoSearch, lbEhUsername, tfEhUsername, lbEhPassword, tfEhPassword,
366-
cbOpenRaw, cbSilent, btnClear, btnClear2);
382+
cbOpenRaw, cbSilent, btnClear, btnClear2, cbCb);
367383

368384
dlCfg.AddButton(btnRefresh);
369385
dlCfg.AddButton(btnOk);

SmartImage 3/Mode/Shell/ShellMode.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,13 +248,38 @@ static ShellMode() { }
248248

249249
private CancellationTokenSource m_token;
250250

251+
private bool m_useclipboard;
252+
253+
public bool UseClipboard
254+
{
255+
get { return m_useclipboard; }
256+
set
257+
{
258+
m_useclipboard = value;
259+
260+
if (m_useclipboard) {
261+
m_cbCallbackTok = Application.MainLoop.AddTimeout(TimeoutTimeSpan, ClipboardCallback);
262+
263+
}
264+
else {
265+
m_cbCallbackTok = Application.MainLoop.RemoveTimeout(m_cbCallbackTok);
266+
m_clipboard.Clear();
267+
}
268+
269+
}
270+
}
271+
272+
private readonly ConcurrentQueue<ustring> m_queue;
273+
251274
#region Static
252275

253276
private static readonly TimeSpan TimeoutTimeSpan = TimeSpan.FromSeconds(1.5);
254277

255278
[SupportedOSPlatform(Compat.OS)]
256279
private static readonly SoundPlayer Player = new(R2.hint);
257280

281+
private static readonly ILogger Logger = LogUtil.Factory.CreateLogger(nameof(ShellMode));
282+
258283
#endregion
259284

260285
#region
@@ -275,8 +300,6 @@ static ShellMode() { }
275300

276301
internal ManualResetEvent IsReady { get; set; }
277302

278-
private readonly ConcurrentQueue<ustring> m_queue;
279-
280303
#endregion
281304

282305
#endregion
@@ -308,7 +331,8 @@ public ShellMode(string[] args)
308331
* Check if clipboard contains valid query input
309332
*/
310333

311-
m_cbCallbackTok = Application.MainLoop.AddTimeout(TimeoutTimeSpan, ClipboardCallback);
334+
// m_cbCallbackTok = Application.MainLoop.AddTimeout(TimeoutTimeSpan, ClipboardCallback);
335+
UseClipboard = true;
312336

313337
m_clipboard = new List<ustring>();
314338

@@ -568,8 +592,6 @@ internal void SetInputText(ustring s)
568592

569593
}
570594

571-
private static readonly ILogger Logger = LogUtil.Factory.CreateLogger(nameof(ShellMode));
572-
573595
private async Task<bool> SetQuery(ustring text)
574596
{
575597
// Btn_Run.Enabled = false;
@@ -685,7 +707,8 @@ private async Task<bool> SetQuery(ustring text)
685707

686708
private bool ClipboardCallback(MainLoop c)
687709
{
688-
710+
Debug.WriteLine($"executing timeout {nameof(ClipboardCallback)} {c} {UseClipboard} {c.EventsPending(false)}");
711+
689712
try {
690713
/*
691714
* Don't set input if:
@@ -735,7 +758,9 @@ private bool ClipboardCallback(MainLoop c)
735758

736759
finally { }
737760

738-
return true;
761+
Debug.WriteLine($"{UseClipboard}");
762+
// return true;
763+
return UseClipboard;
739764
}
740765

741766
public void Dispose()

SmartImage.Lib 3/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

SmartImage.Lib 3/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,7 @@
151151
<data name="S_Silent" xml:space="preserve">
152152
<value>Silent</value>
153153
</data>
154+
<data name="S_Clipboard" xml:space="preserve">
155+
<value>Clipboard detection</value>
156+
</data>
154157
</root>

0 commit comments

Comments
 (0)