Example #1
0
        public PopupPickList(IChildPicker picker, string childHeading, bool okOnDeactivate)
        {
            InitializeComponent();

            Size = SizeAll;

            cbItems.Text = childHeading;

            _modFonts = new ModFontHolder(pickListMulti);
            _nodeTip = new NodeTip(this);

            _picker = picker;
            _chosenAtStart = new List<DocNode>(picker.Chosen);
            _okOnDeactivate = okOnDeactivate;

            bool filter = tbbFilter.Checked = _picker.Filtered;
            var choices = picker.GetChoices(filter).ToArray();
            if (choices.Length != choices.Select(c => c.Id.GlobalIndex).Distinct().Count())
                throw new ArgumentException("Choices must be unique"); // Not L10N

            if (filter)
            {
                // If filtered choices do not contain a choice that
                // has already been chose, then use the unfiltered list.
                foreach (var choice in _chosenAtStart)
                {
                    if (!ContainsChoice(choices, choice))
                    {
                        choices = picker.GetChoices(false).ToArray();
                        tbbFilter.Checked = false;
                        break;
                    }
                }
            }
            SetChoices(choices, _chosenAtStart);

            if (pickListMulti.Items.Count > 0)
                pickListMulti.SelectedIndex = 0;

            // Avoid setting the property, because it will actually
            // change what is picked.
            _autoManageChildren = _picker.AutoManageChildren;
            UpdateAutoManageUI();

            // Hide the synchronize checkbox, or set its label correctly
            string synchLabelText = _picker.SynchSiblingsLabel;
            if (string.IsNullOrEmpty(synchLabelText))
            {
                cbSynchronize.Visible = false;

                // Resize to hide space for the checkbox
                var anchorList = pickListMulti.Anchor;
                pickListMulti.Anchor = anchorList & ~AnchorStyles.Bottom;
                Height = pickListMulti.Bottom + 8;
                pickListMulti.Anchor = anchorList;
            }
            else
            {
                cbSynchronize.Text = synchLabelText;
                cbSynchronize.Checked = _picker.IsSynchSiblings;
            }
        }