private void OptionsControl_EntryIconUpdated(object sender, IconUpdatedEventArgs e)
 {
     if (this.EntryIconUpdated != null)
     {
         this.EntryIconUpdated(sender, e);
     }
 }
Exemple #2
0
        /// <summary>
        /// Event handler triggered when the set icon button is clicked.
        /// </summary>
        /// <param name="sender">The object which triggered the event.</param>
        /// <param name="e">The event arguments.</param>
        private void setIcon_Click(object sender, System.EventArgs e)
        {
            string       application = this.application.Text;
            PwCustomIcon customIcon  = this.passwordEntryManager.SetIconFromExecutable(application);

            if (this.EntryIconUpdated != null)
            {
                IconUpdatedEventArgs eventArgs = new IconUpdatedEventArgs(customIcon);
                this.EntryIconUpdated(this, eventArgs);
            }
        }
        private void RunAsTab_EntryIconUpdated(object sender, IconUpdatedEventArgs e)
        {
            const string CUSTOM_ICON_UUID_FORM_FIELD = "m_pwCustomIconID";
            const string ENTRY_ICON_BUTTON_NAME      = "m_btnIcon";

            PwEntryForm entryForm = ((PwEntryForm)((Control)sender).FindForm());

            // Icon for the password entry has been updated by the run as tab so update the UI.
            try
            {
                // The password entry manager will set the UUID on the entry but when the user saves it will overwrite it.
                // We need to set the UUID value in the password form but it is a private class member.
                // HACK: Do some cheeky reflection to set the value of the private property.
                // WARNING: Likely to break!!!
                FieldInfo customIconUuidField = typeof(PwEntryForm).GetField(
                    CUSTOM_ICON_UUID_FORM_FIELD,
                    BindingFlags.NonPublic | BindingFlags.Instance);
                customIconUuidField.SetValue(entryForm, e.NewIcon.Uuid);

                // Now that we've updated the value, we need to update the image on the button.
                Button iconSelectonButton = UIUtils.GetControlByName <Button>(entryForm, ENTRY_ICON_BUTTON_NAME);
                UIUtil.SetButtonImage(
                    iconSelectonButton,
                    ImageUtils.ScaleImage(e.NewIcon.GetImage(), 16, 16),
                    true);

                // Finally, update the password entry list.
                host.MainWindow.RefreshEntriesList();
                host.MainWindow.UpdateUI(false, null, false, null, true, null, true);

                MessageBox.Show(entryForm, "Password Entry icon updated.", "Icon Updated");
            }
            catch (Exception ex)
            {
                MessageBox.Show(
                    entryForm,
                    string.Concat("The icon was updated for the password entry but there was an error while updating this form. Saving the entry will overwrite the new icon.\n\nAdditional Details:\n", ex.Message),
                    "Warning",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Warning);
            }
        }