1 /*
2   KeePass Password Safe - The Open-Source Password Manager
3   Copyright (C) 2003-2021 Dominik Reichl <dominik.reichl@t-online.de>
4 
5   This program is free software; you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation; either version 2 of the License, or
8   (at your option) any later version.
9 
10   This program is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14 
15   You should have received a copy of the GNU General Public License
16   along with this program; if not, write to the Free Software
17   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19 
20 using System;
21 using System.Collections.Generic;
22 using System.ComponentModel;
23 using System.Diagnostics;
24 using System.Drawing;
25 using System.Text;
26 using System.Windows.Forms;
27 
28 using KeePass.App;
29 using KeePass.Ecas;
30 using KeePass.Resources;
31 using KeePass.UI;
32 
33 namespace KeePass.Forms
34 {
35 	public partial class EcasEventForm : Form
36 	{
37 		private EcasEvent m_eventInOut = null;
38 		private EcasEvent m_event = null; // Working copy
39 
40 		private bool m_bBlockTypeSelectionHandler = false;
41 
InitEx(EcasEvent e)42 		public void InitEx(EcasEvent e)
43 		{
44 			m_eventInOut = e;
45 			m_event = e.CloneDeep();
46 		}
47 
EcasEventForm()48 		public EcasEventForm()
49 		{
50 			InitializeComponent();
51 			GlobalWindowManager.InitializeForm(this);
52 		}
53 
OnFormLoad(object sender, EventArgs e)54 		private void OnFormLoad(object sender, EventArgs e)
55 		{
56 			GlobalWindowManager.AddWindow(this);
57 
58 			this.Text = KPRes.Event;
59 			this.Icon = AppIcons.Default;
60 
61 			Debug.Assert(!m_lblParamHint.AutoSize); // For RTL support
62 			m_lblParamHint.Text = KPRes.ParamDescHelp;
63 
64 			foreach(EcasEventProvider ep in Program.EcasPool.EventProviders)
65 			{
66 				foreach(EcasEventType t in ep.Events)
67 					m_cmbEvents.Items.Add(t.Name);
68 			}
69 
70 			UpdateDataEx(m_event, false, EcasTypeDxMode.Selection);
71 		}
72 
OnFormClosed(object sender, FormClosedEventArgs e)73 		private void OnFormClosed(object sender, FormClosedEventArgs e)
74 		{
75 			GlobalWindowManager.RemoveWindow(this);
76 		}
77 
UpdateDataEx(EcasEvent e, bool bGuiToInternal, EcasTypeDxMode dxType)78 		private bool UpdateDataEx(EcasEvent e, bool bGuiToInternal,
79 			EcasTypeDxMode dxType)
80 		{
81 			m_bBlockTypeSelectionHandler = true;
82 			bool bResult = EcasUtil.UpdateDialog(EcasObjectType.Event, m_cmbEvents,
83 				m_dgvParams, e, bGuiToInternal, dxType);
84 			m_bBlockTypeSelectionHandler = false;
85 			return bResult;
86 		}
87 
OnBtnOK(object sender, EventArgs e)88 		private void OnBtnOK(object sender, EventArgs e)
89 		{
90 			if(!UpdateDataEx(m_eventInOut, true, EcasTypeDxMode.Selection))
91 				this.DialogResult = DialogResult.None;
92 			else m_eventInOut.RunAtTicks = -1;
93 		}
94 
OnBtnCancel(object sender, EventArgs e)95 		private void OnBtnCancel(object sender, EventArgs e)
96 		{
97 		}
98 
OnEventsSelectedIndexChanged(object sender, EventArgs e)99 		private void OnEventsSelectedIndexChanged(object sender, EventArgs e)
100 		{
101 			if(m_bBlockTypeSelectionHandler) return;
102 
103 			UpdateDataEx(m_event, true, EcasTypeDxMode.ParamsTag);
104 			UpdateDataEx(m_event, false, EcasTypeDxMode.None);
105 		}
106 
OnBtnHelp(object sender, EventArgs e)107 		private void OnBtnHelp(object sender, EventArgs e)
108 		{
109 			AppHelp.ShowHelp(AppDefs.HelpTopics.Triggers, AppDefs.HelpTopics.TriggersEvents);
110 		}
111 	}
112 }
113