Skip to content

Commit 6a1362e

Browse files
committed
SOftlock now handles trigger toolbar buttons
1 parent 9d7c695 commit 6a1362e

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/SoftLock.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,23 @@ internal class SoftLock : IMessageFilter
3535

3636
private QuickUnlock _qu = null;
3737

38+
private static KeePassLib.PwUuid _uuidCustomTbButtonClicked = KeePassLib.PwUuid.Zero;
39+
40+
static SoftLock()
41+
{
42+
var x = typeof(Program).Assembly.GetType("KeePass.Ecas.EcasEventIDs");
43+
if (x == null) return;
44+
var u = x.GetField("CustomTbButtonClicked").GetValue(null) as KeePassLib.PwUuid;
45+
if (u != null) _uuidCustomTbButtonClicked = u;
46+
}
47+
3848
internal SoftLock(QuickUnlock qu)
3949
{
4050
Init(qu);
4151
}
4252

4353
private void Init(QuickUnlock qu)
44-
{
54+
{
4555
FillMessages();
4656
_qu = qu;
4757
Program.MainForm.Resize += OnMinimize; //To allow Softlock mode on minimizing
@@ -254,6 +264,30 @@ private void HandleMenu(bool bVisible)
254264
toolbar.Items["m_tbFind"].Enabled = bVisible;
255265
toolbar.Items["m_tbEntryViewsDropDown"].Enabled = bVisible;
256266
toolbar.Items["m_tbQuickFind"].Enabled = bVisible;
267+
268+
//Handle buttons for triggers
269+
foreach (var tItem in toolbar.Items)
270+
{
271+
if (_uuidCustomTbButtonClicked.Equals(KeePassLib.PwUuid.Zero)) break;
272+
ToolStripButton tsmi = tItem as ToolStripButton;
273+
if (tsmi == null) continue;
274+
if (!string.IsNullOrEmpty(tsmi.Name)) continue; //Trigger buttions don't have names
275+
if (string.IsNullOrEmpty((string)tsmi.Tag)) continue; //Trigger buttons have their trigger name as tag
276+
foreach (var t in Program.TriggerSystem.TriggerCollection)
277+
{
278+
foreach (var e in t.EventCollection)
279+
{
280+
if (!e.Type.Equals(_uuidCustomTbButtonClicked)) continue;
281+
//KeePass.Ecas.EcasEventType xxxx = new KeePass.Ecas.EcasEvent()
282+
//e.Type.Equals(KeePass.Ecas.EcasEvent.)
283+
if (e.Parameters.Count != 1) continue;
284+
if ((tsmi.Tag as string).Equals(e.Parameters[0], KeePassLib.Utility.StrUtil.CaseIgnoreCmp))
285+
{
286+
tsmi.Enabled = bVisible;
287+
}
288+
}
289+
}
290+
}
257291
}
258292
ApplyUICustomizations();
259293
}
@@ -360,7 +394,6 @@ public bool PreFilterMessage(ref Message m)
360394
bool bResetTimer = !m_SoftLocked && m_lMessagesForTimerRestart.Contains(m.Msg);
361395

362396
if (!bResetTimer) bResetTimer = CheckMouseMovement(m);
363-
364397
if (bResetTimer)
365398
{
366399
m_SLTimer.Enabled = false;

0 commit comments

Comments
 (0)