public EcasDefaultEventProvider()
        {
            EcasParameter[] epFileFilter = new EcasParameter[] {
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Comparison,
                                  EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Filter,
                                  EcasValueType.String, null)
            };
            EcasParameter[] epValueFilter = new EcasParameter[] {
                new EcasParameter(KPRes.Value + " - " + KPRes.Comparison,
                                  EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.Value + " - " + KPRes.Filter,
                                  EcasValueType.String, null)
            };

            m_events.Add(new EcasEventType(EcasEventIDs.AppInitPost,
                                           KPRes.ApplicationInitialized, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppLoadPost,
                                           KPRes.ApplicationStarted, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppExit,
                                           KPRes.ApplicationExit, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.OpenedDatabaseFile,
                                           KPRes.OpenedDatabaseFile, PwIcon.FolderOpen, epFileFilter,
                                           IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavingDatabaseFile,
                                           KPRes.SavingDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavedDatabaseFile,
                                           KPRes.SavedDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SynchronizingDatabaseFile,
                                           KPRes.SynchronizingDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SynchronizedDatabaseFile,
                                           KPRes.SynchronizedDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.ClosingDatabaseFilePre,
                                           KPRes.ClosingDatabaseFile + " (" + KPRes.SavingPre + ")",
                                           PwIcon.PaperQ, epFileFilter, IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.ClosingDatabaseFilePost,
                                           KPRes.ClosingDatabaseFile + " (" + KPRes.SavingPost + ")",
                                           PwIcon.PaperQ, epFileFilter, IsMatchIocDbEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.CopiedEntryInfo,
                                           KPRes.CopiedEntryData, PwIcon.ClipboardReady, epValueFilter,
                                           IsMatchTextEvent));
            // m_events.Add(new EcasEventType(EcasEventIDs.UpdatedUIState,
            //	KPRes.UpdatedUIState, PwIcon.PaperReady, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.TimePeriodic,
                                           KPRes.Time + " - " + KPRes.Periodic, PwIcon.Clock, new EcasParameter[] {
                new EcasParameter(KPRes.Interval + " [s]", EcasValueType.UInt64, null),
                new EcasParameter(KPRes.TimerRestartOnActivity, EcasValueType.Bool, null)
            },
                                           IsMatchTimePeriodicEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.CustomTbButtonClicked,
                                           KPRes.CustomTbButtonClicked, PwIcon.Star, new EcasParameter[] {
                new EcasParameter(KPRes.Id, EcasValueType.String, null)
            },
                                           IsMatchIdEvent));
        }
		public EcasConditionType(PwUuid uuidType, string strName, PwIcon pwIcon,
			EcasParameter[] vParams, EcasConditionEvaluate f)
		{
			if((uuidType == null) || PwUuid.Zero.Equals(uuidType))
				throw new ArgumentNullException("uuidType");
			if(strName == null) throw new ArgumentNullException("strName");
			// if(vParams == null) throw new ArgumentNullException("vParams");
			// if(f == null) throw new ArgumentNullException("f");

			m_type = uuidType;
			m_strName = strName;
			m_pwIcon = pwIcon;
			m_vParams = (vParams ?? EcasParameter.EmptyArray);
			m_fn = (f ?? EcasConditionEvaluateTrue);
		}
Exemple #3
0
        public EcasEventType(PwUuid uuidType, string strName, PwIcon pwIcon,
            EcasParameter[] vParams, EcasEventCompare f)
        {
            if((uuidType == null) || (uuidType.EqualsValue(PwUuid.Zero)))
                throw new ArgumentNullException("uuidType");
            if(strName == null) throw new ArgumentNullException("strName");
            // if(vParams == null) throw new ArgumentNullException("vParams");
            // if(f == null) throw new ArgumentNullException("f");

            m_type = uuidType;
            m_strName = strName;
            m_pwIcon = pwIcon;
            m_vParams = (vParams ?? EcasParameter.EmptyArray);
            m_fn = (f ?? EcasEventCompareTrue);
        }
        public EcasDefaultEventProvider()
        {
            EcasParameter[] epFileFilter = new EcasParameter[] {
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Comparison,
                    EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Filter,
                    EcasValueType.String, null) };
            EcasParameter[] epValueFilter = new EcasParameter[] {
                new EcasParameter(KPRes.Value + " - " + KPRes.Comparison,
                    EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.Value + " - " + KPRes.Filter,
                    EcasValueType.String, null) };

            m_events.Add(new EcasEventType(EcasEventIDs.AppInitPost,
                KPRes.ApplicationInitialized, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppLoadPost,
                KPRes.ApplicationStarted, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppExit,
                KPRes.ApplicationExit, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.OpenedDatabaseFile,
                KPRes.OpenedDatabaseFile, PwIcon.FolderOpen, epFileFilter,
                IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavingDatabaseFile,
                KPRes.SavingDatabaseFile, PwIcon.Disk, epFileFilter,
                IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavedDatabaseFile,
                KPRes.SavedDatabaseFile, PwIcon.Disk, epFileFilter,
                IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.ClosingDatabaseFilePre,
                KPRes.ClosingDatabaseFile + " (" + KPRes.SavingPre + ")",
                PwIcon.PaperQ, epFileFilter, IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.ClosingDatabaseFilePost,
                KPRes.ClosingDatabaseFile + " (" + KPRes.SavingPost + ")",
                PwIcon.PaperQ, epFileFilter, IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.CopiedEntryInfo,
                KPRes.CopiedEntryData, PwIcon.ClipboardReady, epValueFilter,
                IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.UpdatedUIState,
                KPRes.UpdatedUIState, PwIcon.PaperReady, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.CustomTbButtonClicked,
                KPRes.CustomTbButtonClicked, PwIcon.Star, new EcasParameter[] {
                    new EcasParameter(KPRes.Id, EcasValueType.String, null) },
                IsMatchCustomTbButton));
        }
Exemple #5
0
        public EcasDefaultEventProvider()
        {
            EcasParameter[] epFileFilter = new EcasParameter[] {
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Comparison,
                                  EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.FileOrUrl + " - " + KPRes.Filter,
                                  EcasValueType.String, null)
            };
            EcasParameter[] epValueFilter = new EcasParameter[] {
                new EcasParameter(KPRes.Value + " - " + KPRes.Comparison,
                                  EcasValueType.EnumStrings, EcasUtil.StdStringCompare),
                new EcasParameter(KPRes.Value + " - " + KPRes.Filter,
                                  EcasValueType.String, null)
            };

            m_events.Add(new EcasEventType(EcasEventIDs.AppInitPost,
                                           KPRes.ApplicationInitialized, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppLoadPost,
                                           KPRes.ApplicationStarted, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.AppExit,
                                           KPRes.ApplicationExit, PwIcon.ProgramIcons, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.OpenedDatabaseFile,
                                           KPRes.OpenedDatabaseFile, PwIcon.FolderOpen, epFileFilter,
                                           IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavingDatabaseFile,
                                           KPRes.SavingDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.SavedDatabaseFile,
                                           KPRes.SavedDatabaseFile, PwIcon.Disk, epFileFilter,
                                           IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.CopiedEntryInfo,
                                           KPRes.CopiedEntryData, PwIcon.ClipboardReady, epValueFilter,
                                           IsMatchTextEvent));
            m_events.Add(new EcasEventType(EcasEventIDs.UpdatedUIState,
                                           KPRes.UpdatedUIState, PwIcon.PaperReady, null, null));
            m_events.Add(new EcasEventType(EcasEventIDs.CustomTbButtonClicked,
                                           KPRes.CustomTbButtonClicked, PwIcon.Star, new EcasParameter[] {
                new EcasParameter(KPRes.Id, EcasValueType.String, null)
            },
                                           IsMatchCustomTbButton));
        }
Exemple #6
0
        public static string ParametersToString(IEcasObject ecasObj,
			EcasParameter[] vParamInfo)
        {
            if(ecasObj == null) throw new ArgumentNullException("ecasObj");
            if(ecasObj.Parameters == null) throw new ArgumentException();

            bool bParamInfoValid = true;
            if((vParamInfo == null) || (ecasObj.Parameters.Count > vParamInfo.Length))
            {
                Debug.Assert(false);
                bParamInfoValid = false;
            }

            StringBuilder sb = new StringBuilder();

            EcasCondition eCond = (ecasObj as EcasCondition);
            if(eCond != null)
            {
                if(eCond.Negate) sb.Append(KPRes.Not);
            }

            for(int i = 0; i < ecasObj.Parameters.Count; ++i)
            {
                string strParam = ecasObj.Parameters[i];
                string strAppend;

                if(bParamInfoValid)
                {
                    EcasValueType t = vParamInfo[i].Type;
                    if(t == EcasValueType.String)
                        strAppend = strParam;
                    else if(t == EcasValueType.Bool)
                        strAppend = (StrUtil.StringToBool(strParam) ? KPRes.Yes : KPRes.No);
                    else if(t == EcasValueType.EnumStrings)
                    {
                        uint uEnumID;
                        if(uint.TryParse(strParam, out uEnumID) == false) { Debug.Assert(false); }
                        EcasEnum ee = vParamInfo[i].EnumValues;
                        if(ee != null) strAppend = ee.GetItemString(uEnumID, string.Empty);
                        else { Debug.Assert(false); strAppend = strParam; }
                    }
                    else if(t == EcasValueType.Int64)
                        strAppend = FilterTypeI64(strParam);
                    else if(t == EcasValueType.UInt64)
                        strAppend = FilterTypeU64(strParam);
                    else { Debug.Assert(false); strAppend = strParam; }
                }
                else strAppend = strParam;

                if(string.IsNullOrEmpty(strAppend)) continue;
                string strAppTrimmed = strAppend.Trim();
                if(strAppTrimmed.Length == 0) continue;
                if(sb.Length > 0) sb.Append(", ");
                sb.Append(strAppTrimmed);
            }

            return sb.ToString();
        }
Exemple #7
0
        public static void ParametersToDataGridView(DataGridView dg,
                                                    IEcasParameterized p, IEcasObject objDefaults)
        {
            if (dg == null)
            {
                throw new ArgumentNullException("dg");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }
            if (p.Parameters == null)
            {
                throw new ArgumentException();
            }
            if (objDefaults == null)
            {
                throw new ArgumentNullException("objDefaults");
            }
            if (objDefaults.Parameters == null)
            {
                throw new ArgumentException();
            }

            dg.Rows.Clear();
            dg.Columns.Clear();

            Color clrBack      = dg.DefaultCellStyle.BackColor;
            Color clrValueBack = dg.DefaultCellStyle.BackColor;

            if (clrValueBack.GetBrightness() >= 0.5)
            {
                clrValueBack = UIUtil.DarkenColor(clrValueBack, 0.075);
            }
            else
            {
                clrValueBack = UIUtil.LightenColor(clrValueBack, 0.075);
            }

            dg.ColumnHeadersVisible = false;
            dg.RowHeadersVisible    = false;
            dg.GridColor            = clrBack;
            dg.BackgroundColor      = clrBack;
            dg.DefaultCellStyle.SelectionBackColor = clrBack;
            dg.DefaultCellStyle.SelectionForeColor = dg.DefaultCellStyle.ForeColor;
            dg.AllowDrop                = false;
            dg.AllowUserToAddRows       = false;
            dg.AllowUserToDeleteRows    = false;
            dg.AllowUserToOrderColumns  = false;
            dg.AllowUserToResizeColumns = false;
            dg.AllowUserToResizeRows    = false;
            // dg.EditMode: see below
            dg.Tag = p;

            int nWidth = (dg.ClientSize.Width - UIUtil.GetVScrollBarWidth());

            dg.Columns.Add("Name", KPRes.FieldName);
            dg.Columns.Add("Value", KPRes.FieldValue);
            dg.Columns[0].Width = (nWidth / 2);
            dg.Columns[1].Width = (nWidth / 2);

            bool bUseDefaults = true;

            if (objDefaults.Type == null)
            {
                Debug.Assert(false);
            }                                                                 // Optimistic
            else if (p.Type == null)
            {
                Debug.Assert(false);
            }                                                            // Optimistic
            else if (!objDefaults.Type.Equals(p.Type))
            {
                bUseDefaults = false;
            }

            for (int i = 0; i < p.Parameters.Length; ++i)
            {
                EcasParameter ep = p.Parameters[i];

                dg.Rows.Add();
                DataGridViewRow            row = dg.Rows[dg.Rows.Count - 1];
                DataGridViewCellCollection cc  = row.Cells;

                Debug.Assert(cc.Count == 2);
                cc[0].Value    = ep.Name;
                cc[0].ReadOnly = true;

                string strParam = (bUseDefaults ? EcasUtil.GetParamString(
                                       objDefaults.Parameters, i) : string.Empty);

                DataGridViewCell c = null;
                switch (ep.Type)
                {
                case EcasValueType.String:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = strParam;
                    break;

                case EcasValueType.Bool:
                    c = new DataGridViewCheckBoxCell(false);
                    (c as DataGridViewCheckBoxCell).Value =
                        StrUtil.StringToBool(strParam);
                    break;

                case EcasValueType.EnumStrings:
                    DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
                    cmb.Sorted       = false;
                    cmb.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
                    int iFound = -1;
                    for (int e = 0; e < ep.EnumValues.ItemCount; ++e)
                    {
                        EcasEnumItem eei = ep.EnumValues.Items[e];
                        cmb.Items.Add(eei.Name);
                        if (eei.ID.ToString() == strParam)
                        {
                            iFound = e;
                        }
                    }
                    if (iFound >= 0)
                    {
                        cmb.Value = ep.EnumValues.Items[iFound].Name;
                    }
                    else if (ep.EnumValues.ItemCount > 0)
                    {
                        cmb.Value = ep.EnumValues.Items[0].Name;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                    c = cmb;
                    break;

                case EcasValueType.Int64:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = FilterTypeI64(strParam);
                    break;

                case EcasValueType.UInt64:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = FilterTypeU64(strParam);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }

                if (c != null)
                {
                    cc[1] = c;
                }
                cc[1].ReadOnly                 = false;
                cc[1].Style.BackColor          = clrValueBack;
                cc[1].Style.SelectionBackColor = clrValueBack;
            }

            // Perform postponed setting of EditMode (cannot set it earlier
            // due to a Mono bug on FreeBSD);
            // https://sourceforge.net/p/keepass/discussion/329220/thread/cb8270e2/
            dg.EditMode = DataGridViewEditMode.EditOnEnter;
        }