Ejemplo n.º 1
0
        /// <summary>
        /// Occures when any of the form button is clicked
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void frmButtonClick(object sender, RoutedEventArgs e)
        {
            //Check which button is pressed.
            switch (((Button)sender).Name)
            {
            default:
            case nameof(btnAddNewKey):      //If its Add Key button.
                //Verify input
                if (string.IsNullOrEmpty(txtAddKey.Text) || string.IsNullOrEmpty(txtAddKeyValue.Text))
                {
                    return;
                }
                //If INPUT KEY's LENGTH is greater than 1, throw error because the input key must be a character.
                if (txtAddKey.Text.Length > 1)
                {
                    Logger.Notify("Please write a single character to add in the font set. ", MessageKind.Error);
                    return;
                }
                //Check if the font already contains the key code
                if (xFont.Contains(txtAddKey.Text[0]))
                {
                    return;    //return
                }
                //Add a new key in the font set with custom parameters.
                this.xFont.Keys.Add(new XKey(0, txtAddKey.Text[0], txtAddKeyValue.Text));
                this.RefreshList();
                break;

            case nameof(btnRemoveSelectedKey):
                xFont.Keys.Remove(listView.SelectedItem as XKey);
                RefreshList();
                break;

            case nameof(btnAutoFill):
                //Replace all the keys of items.
                var afText = txtAutofill.Text.Split(' ');

                for (int i = 0; i < afText.Length; i++)
                {
                    this.xFont.Keys[i].TargetValue = afText[i].ToString();
                }
                this.RefreshList();
                break;

            case nameof(btnSave):
                Save();
                break;

            case nameof(btnSaveAs):
                SaveAs();
                break;
            }
        }