Example #1
0
        /// <summary>
        /// Initializes the plugin.
        /// </summary>
        /// <param name="host">Reference to the <see cref="IPluginHost"/> object.</param>
        /// <returns>True if the plugin is initialized properly, false otherwise.</returns>
        public override bool Initialize(IPluginHost host)
        {
            _host = host;

            // Add handler to detect when a new window has been opened.
            GlobalWindowManager.WindowAdded += GlobalWindowManager_WindowAdded;

            string configFilePath = GetConfigFilePath();

            if (!File.Exists(configFilePath))
            {
                // Create sample dates.
                CustomDateOptions = new List <CustomDateOption>
                {
                    new CustomDateOption {
                        Days = 31
                    },
                    new CustomDateOption {
                        Days = 45
                    },
                    new CustomDateOption {
                        Days = 180
                    }
                };
            }
            else
            {
                // Read config file.
                using (FileStream fileStream = new FileStream(configFilePath, FileMode.OpenOrCreate))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof(List <CustomDateOption>), new XmlRootAttribute("CustomDateOptions"));
                    CustomDateOptions = serializer.Deserialize(fileStream) as List <CustomDateOption>;
                }
            }

            // Sort custom options
            CustomDateOptions.Sort((x, y) => string.Compare(x.ToString(), y.ToString()));

            return(true);
        }
Example #2
0
        private void GlobalWindowManager_WindowAdded(object sender, GwmWindowEventArgs e)
        {
            // Get the password entry form
            PwEntryForm entryForm = e.Form as PwEntryForm;

            if (entryForm != null && CustomDateOptions.Count > 0)
            {
                ToolStripSeparator separator = new ToolStripSeparator();
                entryForm.DefaultTimesContextMenu.Items.Add(new ToolStripSeparator());

                // Add custom date options menu items.
                CustomDateOptions.ForEach(o =>
                {
                    ToolStripMenuItem customOptionMenuItem = new ToolStripMenuItem(o.ToString())
                    {
                        Tag = o
                    };
                    customOptionMenuItem.Click += CustomOptionMenuItem_Click;
                    entryForm.DefaultTimesContextMenu.Items.Add(customOptionMenuItem);
                });
            }
        }