private bool SetCurrentVaultAlias()
        {
            if (null == uxComboBoxVaultAlias.SelectedItem)
            {
                return(false);
            }
            // Ignore selection of the same vault alias, only when list view is not empty
            if ((CurrentVaultAlias?.Alias == uxComboBoxVaultAlias.SelectedItem.ToString()) && (uxListViewSecrets.Items.Count > 0))
            {
                return(false);
            }
            if (uxComboBoxVaultAlias.SelectedItem is string)
            {
                switch (uxComboBoxVaultAlias.SelectedItem.ToString())
                {
                case AddNewVaultText:
                    uxButtonHelp.PerformClick();
                    uxComboBoxVaultAlias.SelectedItem = CurrentVaultAlias;
                    return(false);

                case PickVaultText:
                    var smd = new SubscriptionsManagerDialog();
                    if (smd.ShowDialog() != DialogResult.OK)
                    {
                        uxComboBoxVaultAlias.SelectedItem = CurrentVaultAlias;
                        return(false);
                    }
                    _tempVaultAliases[smd.CurrentVaultAlias.Alias] = smd.CurrentVaultAlias;
                    uxComboBoxVaultAlias.Items.Insert(uxComboBoxVaultAlias.Items.Count - 1, smd.CurrentVaultAlias);
                    uxComboBoxVaultAlias.SelectedItem = smd.CurrentVaultAlias;

                    // Set user alias and domain hint manually as they are not set from the assignment
                    ((VaultAlias)uxComboBoxVaultAlias.SelectedItem).UserAlias  = smd.CurrentVaultAlias.UserAlias;
                    ((VaultAlias)uxComboBoxVaultAlias.SelectedItem).DomainHint = smd.CurrentVaultAlias.DomainHint;
                    break;
                }
            }
            CurrentVaultAlias = (VaultAlias)uxComboBoxVaultAlias.SelectedItem;
            bool itemSelected = (null != CurrentVaultAlias);

            uxComboBoxVaultAlias.SelectedText = CurrentVaultAlias.Alias;
            // In some cases, the combobox will be blank. Setting the text on a blank combobox will null the selected item. So, always ensure the selecteditem is set when setting the selected text.
            uxComboBoxVaultAlias.SelectedItem = CurrentVaultAlias;
            uxComboBoxVaultAlias.ToolTipText  = itemSelected ? "Vault names: " + string.Join(", ", CurrentVaultAlias.VaultNames) : "";
            uxMenuItemRefresh.Enabled         = itemSelected;
            return(itemSelected);
        }
Ejemplo n.º 2
0
        private bool SetCurrentVaultAlias()
        {
            if (null == uxComboBoxVaultAlias.SelectedItem)
            {
                return(false);
            }
            // Ignore selection of the same vault alias, only when list view is not empty
            if ((CurrentVaultAlias?.Alias == uxComboBoxVaultAlias.SelectedItem.ToString()) && (uxListViewSecrets.Items.Count > 0))
            {
                return(false);
            }
            if (uxComboBoxVaultAlias.SelectedItem is string)
            {
                switch (uxComboBoxVaultAlias.SelectedItem.ToString())
                {
                case AddNewVaultText:
                    uxButtonHelp.PerformClick();
                    uxComboBoxVaultAlias.SelectedItem = CurrentVaultAlias;
                    return(false);

                case PickVaultText:
                    var smd = new SubscriptionsManagerDialog();
                    if (smd.ShowDialog() != DialogResult.OK)
                    {
                        uxComboBoxVaultAlias.SelectedItem = CurrentVaultAlias;
                        return(false);
                    }
                    _tempVaultAliases[smd.CurrentVaultAlias.Alias] = smd.CurrentVaultAlias;
                    uxComboBoxVaultAlias.Items.Insert(uxComboBoxVaultAlias.Items.Count - 1, smd.CurrentVaultAlias);
                    uxComboBoxVaultAlias.SelectedItem = smd.CurrentVaultAlias;
                    break;
                }
            }
            CurrentVaultAlias = (VaultAlias)uxComboBoxVaultAlias.SelectedItem;
            bool itemSelected = (null != CurrentVaultAlias);

            uxComboBoxVaultAlias.ToolTipText = itemSelected ? "Vault names: " + string.Join(", ", CurrentVaultAlias.VaultNames) : "";
            uxMenuItemRefresh.Enabled        = itemSelected;
            return(itemSelected);
        }