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 EcasConditionForm : Form 36 { 37 private EcasCondition m_conditionInOut = null; 38 private EcasCondition m_condition = null; // Working copy 39 40 private bool m_bBlockTypeSelectionHandler = false; 41 InitEx(EcasCondition e)42 public void InitEx(EcasCondition e) 43 { 44 m_conditionInOut = e; 45 m_condition = e.CloneDeep(); 46 } 47 EcasConditionForm()48 public EcasConditionForm() 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.Condition; 59 this.Icon = AppIcons.Default; 60 61 Debug.Assert(!m_lblParamHint.AutoSize); // For RTL support 62 m_lblParamHint.Text = KPRes.ParamDescHelp; 63 64 foreach(EcasConditionProvider cp in Program.EcasPool.ConditionProviders) 65 { 66 foreach(EcasConditionType t in cp.Conditions) 67 m_cmbConditions.Items.Add(t.Name); 68 } 69 70 UpdateDataEx(m_condition, false, EcasTypeDxMode.Selection); 71 m_cbNegate.Checked = m_condition.Negate; 72 } 73 OnFormClosed(object sender, FormClosedEventArgs e)74 private void OnFormClosed(object sender, FormClosedEventArgs e) 75 { 76 GlobalWindowManager.RemoveWindow(this); 77 } 78 UpdateDataEx(EcasCondition c, bool bGuiToInternal, EcasTypeDxMode dxType)79 private bool UpdateDataEx(EcasCondition c, bool bGuiToInternal, 80 EcasTypeDxMode dxType) 81 { 82 m_bBlockTypeSelectionHandler = true; 83 bool bResult = EcasUtil.UpdateDialog(EcasObjectType.Condition, m_cmbConditions, 84 m_dgvParams, c, bGuiToInternal, dxType); 85 m_bBlockTypeSelectionHandler = false; 86 return bResult; 87 } 88 OnBtnOK(object sender, EventArgs e)89 private void OnBtnOK(object sender, EventArgs e) 90 { 91 if(!UpdateDataEx(m_conditionInOut, true, EcasTypeDxMode.Selection)) 92 { 93 this.DialogResult = DialogResult.None; 94 return; 95 } 96 97 m_conditionInOut.Negate = m_cbNegate.Checked; 98 } 99 OnBtnCancel(object sender, EventArgs e)100 private void OnBtnCancel(object sender, EventArgs e) 101 { 102 } 103 OnConditionsSelectedIndexChanged(object sender, EventArgs e)104 private void OnConditionsSelectedIndexChanged(object sender, EventArgs e) 105 { 106 if(m_bBlockTypeSelectionHandler) return; 107 108 UpdateDataEx(m_condition, true, EcasTypeDxMode.ParamsTag); 109 UpdateDataEx(m_condition, false, EcasTypeDxMode.None); 110 } 111 OnBtnHelp(object sender, EventArgs e)112 private void OnBtnHelp(object sender, EventArgs e) 113 { 114 AppHelp.ShowHelp(AppDefs.HelpTopics.Triggers, AppDefs.HelpTopics.TriggersConditions); 115 } 116 } 117 } 118