コード例 #1
0
        private void lvCommands_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
            {
                CommandItem ci = e.AddedItems[0] as CommandItem;

                mActionItems.Clear();
                foreach (sp.VoiceAction act in ci.ObjRef.Actions)
                {
                    mActionItems.Add(new ActionItem(act));
                }
            } //if
        }     //func
コード例 #2
0
        }                //func

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            switch ((sender as Button).Name)
            {
            //............................................................
            case "btnCancel": this.Close(); break;

            //............................................................
            case "btnAddCmd":
                var newCmd = new sp.VoiceCommand("New Command");
                mProfile.Commands.Add(newCmd);
                mCommandItems.Add(new CommandItem()
                {
                    ObjRef = newCmd
                });

                var va = new sp.VoiceAction()
                {
                    Type = "kb", Data = "LCTRL x"
                };
                newCmd.Actions.Add(va);
                break;

            //............................................................
            case "btnRemoveCmd":
                if (lvCommands.SelectedItem != null)
                {
                    CommandItem ci = (CommandItem)lvCommands.SelectedItem;
                    mProfile.Commands.Remove(ci.ObjRef); //Remove From Profile
                    mCommandItems.Remove(ci);            //Remove from bound list
                }                                        //if
                break;

            //............................................................
            case "btnAddAct":
                if (lvCommands.SelectedItem != null)
                {
                    var vaa = new sp.VoiceAction()
                    {
                        Type = "kb", Data = "LCTRL x"
                    };
                    (lvCommands.SelectedItem as CommandItem).ObjRef.Actions.Add(vaa);
                    mActionItems.Add(new ActionItem(vaa));
                }                                //if
                break;

            //............................................................
            case "btnRemoveAct":
                if (lvActions.SelectedItem != null)
                {
                    CommandItem ci = (CommandItem)lvCommands.SelectedItem;
                    ActionItem  ai = (ActionItem)lvActions.SelectedItem;
                    ci.ObjRef.Actions.Remove(ai.ObjRef); //Remove From Command
                    mActionItems.Remove(ai);             //Remove from bound list
                }                                        //if
                break;

            //............................................................
            case "btnSave":
                string pName = tbProfileName.Text.Trim();
                if (String.IsNullOrEmpty(pName))
                {
                    MessageBox.Show("Must have a profile name", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }                                //if

                //Convert delimited string into an string array for the profile.
                string[] ary;
                foreach (var cmd in mCommandItems)
                {
                    cmd.ObjRef.Grammar.Clear();
                    ary = cmd.Grammar.ToLower().Split(',');
                    foreach (string str in ary)
                    {
                        cmd.ObjRef.Grammar.Add(str.Trim());
                    }
                }                                //for

                //Save everything else
                mProfile.Name = pName;
                mProfile.Save();
                mHasSaved = true;

                //If changing the profile name, then the profile will save to a new file
                //Because of that, we need to delete the old profile. TODO
                if (mProfileName != null && !mProfileName.Equals(pName))
                {
                }                                //if

                this.Close();
                break;
            }                    //switch
        }