Beispiel #1
0
        void update_gui()
        {
            var key_names = key_manager.get_key_names();

            if (key_names.Count == 0)
            {
                ExistingKeys_text.Visibility = Visibility.Collapsed;
                ExistingKeys_lb.Visibility   = Visibility.Collapsed;
            }
            else
            {
                // key_names.Count > 0. Populate list box with key_names
                key_names.Sort();

                ExistingKeys_lb.Items.Clear();
                foreach (var key_name in key_names)
                {
                    ExistingKeys_lb.Items.Add(key_name);
                }

                ExistingKeys_text.Visibility = Visibility.Visible;
                ExistingKeys_lb.Visibility   = Visibility.Visible;
            }

            NewKeyName_tb.Text = "";
        }
Beispiel #2
0
        /// <summary>
        /// Update Keys_cb, to reflect update to key_manager,
        /// while preserving user selection.
        /// </summary>
        void update_Keys_cb()
        {
            // Record current selections
            int    old_index = Keys_cb.SelectedIndex;
            string old_name  = "";

            if (old_index >= 0)
            {
                old_name = Keys_cb.Items[old_index].ToString();
            }

            // Generate a list of names from
            var names = key_manager.get_key_names();

            names.Sort();

            // Attach names to Keys_cb.Items
            Keys_cb.Items.Clear();
            Keys_cb.Items.Add("New Key");
            foreach (var name in names)
            {
                Keys_cb.Items.Add(name);
            }

            // Set SelectedIndex to the previous selection.
            if (old_index <= 0)
            {
                Keys_cb.SelectedIndex = 0;
            }
            else
            {
                int index = names.IndexOf(old_name);
                if (index >= 0)
                {
                    Keys_cb.SelectedIndex = index + 1;
                }
                else
                {
                    Keys_cb.SelectedIndex = -1;
                }
            }
        }