private void populate_fields() { // Fill combo-box with possible action types. cbActionType.DataSource = Action_Groups; //Used to be ActionSequence.Types (now we group them into forms) // Null the data grid, later we will bind actions to it (as list) dgActionSequence.DataSource = null; // if we have a sequence to edit, populate the fields with existing values if (sequence_to_edit != null) { txtActionSequenceName.Text = sequence_to_edit.name; // TODO : Hack // dgActionSequence.DataSource = sequence_to_edit.action_sequence.ToList(); txtActionSequenceComment.Text = sequence_to_edit.comment; } else { this.sequence_to_edit = new VI_Action_Sequence(); dgActionSequence.DataSource = new List <Action>(); } }
public frmActionSequence(VI_Profile profile, VI_Action_Sequence action_sequence) { InitializeComponent(); this.profile = profile; this.action_sequence = action_sequence; populate_sequence(); edit_mode = true; }
public frmActionSequence(VI_Profile profile) { InitializeComponent(); this.profile = profile; this.action_sequence = new VI_Action_Sequence("new sequence"); populate_sequence(); edit_mode = false; }
public frmActionSequence(VI_Action_Sequence action_sequence) { InitializeComponent(); this.action_sequence = action_sequence; populate_sequence(); edit_mode = true; }
public frmActionSequence() { InitializeComponent(); this.action_sequence = new VI_Action_Sequence("new sequence"); populate_sequence(); edit_mode = false; }
public frm_AddEdit_ActionSequence(VI_Action_Sequence action_sequence) { // Passing an action sequence edits the passed sequence. InitializeComponent(); this.sequence_to_edit = action_sequence; populate_fields(); }
public frm_AddEdit_ActionSequence( VI_Action_Sequence action_sequence ) { // Passing an action sequence edits the passed sequence. InitializeComponent(); this.sequence_to_edit = action_sequence; populate_fields(); }
// Edit Action Sequence private void editToolStripMenuItem1_Click(object sender, EventArgs e) { if (dgActionSequences.MultiSelect == true) { throw new NotImplementedException("Editing multiple sequences at once is unsupported."); } foreach (DataGridViewRow row in this.dgActionSequences.SelectedRows) { VI_Action_Sequence sequence_to_edit = row.DataBoundItem as VI_Action_Sequence; frm_AddEdit_ActionSequence newActionSequence = new frm_AddEdit_ActionSequence(sequence_to_edit); if (newActionSequence.ShowDialog() == DialogResult.OK) { ProfileEdited(); } } refresh_dgActionSequences(); refresh_dgTriggerEvents(); }
// Delete Action Sequence private void deleteToolStripMenuItem1_Click(object sender, EventArgs e) { if (dgActionSequences.MultiSelect == true) { throw new NotImplementedException("Multiple sequence deletions are unsupported."); } foreach (DataGridViewRow row in this.dgActionSequences.SelectedRows) { VI_Action_Sequence sequence_to_remove = row.DataBoundItem as VI_Action_Sequence; GAVPI.vi_profile.Profile_ActionSequences.Remove(sequence_to_remove); // Remove this event from existing triggers. foreach (VI_Trigger existing_trigger in GAVPI.vi_profile.Profile_Triggers) { existing_trigger.TriggerEvents.Remove(sequence_to_remove); } } refresh_dgActionSequences(); refresh_dgTriggerEvents(); ProfileEdited(); }
public void load_profile(string filename) { //Clean Current Profile_Triggers = new List<VI_Trigger>(); Profile_ActionSequences = new List<VI_Action_Sequence>(); //Constructor will catch. XmlDocument profile_xml = new XmlDocument(); profile_xml.Load(filename); //Check first element tag if (profile_xml.DocumentElement.Name != "gavpi") { throw new Exception("Malformed profile expected first tag gavpi got," + profile_xml.DocumentElement.Name); } XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes; foreach (XmlNode element in profile_xml_elements) { if (element.Name == "VI_Action_Sequence") { VI_Action_Sequence ack_frm_file; ack_frm_file = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value); ack_frm_file.type = element.Attributes.GetNamedItem("type").Value; ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value; foreach (XmlNode action in element.ChildNodes) { string action_type = action.Attributes.GetNamedItem("type").Value; string action_value = action.Attributes.GetNamedItem("value").Value; Type new_action_type = Type.GetType("GAVPI." + action_type ); object action_instance; if (action_type == "Speak") { action_instance = Activator.CreateInstance(new_action_type,this.synth, action_value); } else { action_instance = Activator.CreateInstance(new_action_type, action_value); } ack_frm_file.Add((Action)action_instance); } if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name)) { Profile_ActionSequences.Add(ack_frm_file); } } else if (element.Name == "VI_Trigger") { VI_Trigger trig_frm_file; string trigger_name = element.Attributes.GetNamedItem("name").Value; string trigger_type = element.Attributes.GetNamedItem("type").Value; string trigger_value = element.Attributes.GetNamedItem("value").Value; string trigger_comment= element.Attributes.GetNamedItem("comment").Value; Type new_trigger_type = Type.GetType("GAVPI." + trigger_type); object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value); trig_frm_file = (VI_Trigger)trigger_isntance; trig_frm_file.comment = trigger_comment; // Trigger Events foreach (XmlElement trigger_event in element.ChildNodes) { string event_type = trigger_event.Attributes.GetNamedItem("type").Value; string event_name = trigger_event.Attributes.GetNamedItem("name").Value; string event_value = trigger_event.Attributes.GetNamedItem("value").Value; if (event_type == "VI_Action_Sequence") { trig_frm_file.Add(Profile_ActionSequences.Find( ackseq => ackseq.name == event_name)); } else if (event_type == "VI_Phrase") { VI_Trigger newMetaTrigger; Type meta_trigger_type = Type.GetType("GAVPI." + event_type); object meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type,event_name, event_value); newMetaTrigger = (VI_Trigger)meta_trigger_isntance; trig_frm_file.Add(newMetaTrigger); } } // Malformed xml or double load, need to switch to dictionaries tbh if (!Profile_Triggers.Any(trig=>trig.name == trig_frm_file.name)) { Profile_Triggers.Add(trig_frm_file); } } } }
public void Add_Action_Sequence(VI_Action_Sequence action_sequence_toAdd) { Profile_ActionSequences.Add(action_sequence_toAdd); }
private void populate_fields() { // Fill combo-box with possible action types. cbActionType.DataSource = Action_Groups; //Used to be ActionSequence.Types (now we group them into forms) // Null the data grid, later we will bind actions to it (as list) dgActionSequence.DataSource = null; // if we have a sequence to edit, populate the fields with existing values if (sequence_to_edit != null) { txtActionSequenceName.Text = sequence_to_edit.name; // TODO : Hack // dgActionSequence.DataSource = sequence_to_edit.action_sequence.ToList(); txtActionSequenceComment.Text = sequence_to_edit.comment; } else { this.sequence_to_edit = new VI_Action_Sequence(); dgActionSequence.DataSource = new List<Action>(); } }
} // public bool NewProfile() public bool load_profile(string filename) { if (filename == null) { return(false); } // Reset any states... NewProfile(); XmlDocument profile_xml = new XmlDocument(); // Let's ensure that the user has actually selected a well-formed XML document for us to navigate as // opposed to - oh, I don't know: a picture of their cat? try { profile_xml.Load(filename); } catch (Exception) { return(false); } //Check first element tag if (profile_xml.DocumentElement.Name != "gavpi") { throw new Exception("Malformed profile expected first tag gavpi got," + profile_xml.DocumentElement.Name); } XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes; foreach (XmlNode element in profile_xml_elements) { if (element.Name == "AssociatedProcess") { AssociatedProcess = element.InnerText; } else if (element.Name == "VI_Action_Sequence") { VI_Action_Sequence ack_frm_file; ack_frm_file = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value); ack_frm_file.type = element.Attributes.GetNamedItem("type").Value; ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value; foreach (XmlNode action in element.ChildNodes) { string action_type = action.Attributes.GetNamedItem("type").Value; string action_value = action.Attributes.GetNamedItem("value").Value; Type new_action_type = Type.GetType("GAVPI." + action_type); object action_instance; if (action_type == "Speak") { action_instance = Activator.CreateInstance(new_action_type, this.synth, action_value); } else { action_instance = Activator.CreateInstance(new_action_type, action_value); } ack_frm_file.Add((Action)action_instance); } if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name)) { Profile_ActionSequences.Add(ack_frm_file); } } else if (element.Name == "VI_Trigger") { VI_Trigger trig_frm_file; string trigger_name = element.Attributes.GetNamedItem("name").Value; string trigger_type = element.Attributes.GetNamedItem("type").Value; string trigger_value = element.Attributes.GetNamedItem("value").Value; string trigger_comment = element.Attributes.GetNamedItem("comment").Value; Type new_trigger_type = Type.GetType("GAVPI." + trigger_type); object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value); trig_frm_file = (VI_Trigger)trigger_isntance; trig_frm_file.comment = trigger_comment; // Trigger Events foreach (XmlElement trigger_event in element.ChildNodes) { string event_type = trigger_event.Attributes.GetNamedItem("type").Value; string event_name = trigger_event.Attributes.GetNamedItem("name").Value; string event_value = trigger_event.Attributes.GetNamedItem("value").Value; if (event_type == "VI_Action_Sequence") { trig_frm_file.Add(Profile_ActionSequences.Find(ackseq => ackseq.name == event_name)); } else if (event_type == "VI_Phrase") { VI_Trigger newMetaTrigger; Type meta_trigger_type = Type.GetType("GAVPI." + event_type); object meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type, event_name, event_value); newMetaTrigger = (VI_Trigger)meta_trigger_isntance; trig_frm_file.Add(newMetaTrigger); } } // Malformed xml or double load, need to switch to dictionaries tbh if (!Profile_Triggers.Any(trig => trig.name == trig_frm_file.name)) { Profile_Triggers.Add(trig_frm_file); } } } // Load Database Components // DB will parse out the VI_DB tag, allong with its children. ProfileDB = new VI_DB(filename); // // We have successfully loaded the Profile, so retain the Profile's filename for future reference... // ProfileFilename = filename; return(true); } // public void load_profile()
} // public bool NewProfile() public bool load_profile() { string filename; // If there are any unsaved changes to an existing Profile, offer the opportunity to save them before opening // another Profile... if (UnsavedProfileChanges && !IsEmpty()) { DialogResult save_changes = MessageBox.Show("It appears you have made changes to your Profile.\n\n" + "Would you like to save those changes now?", "Unsaved Profile", MessageBoxButtons.YesNo); if (save_changes == DialogResult.Yes && !save_profile()) { return(false); } } // if() // // Present the user with a File Open Dialog through which they may choose a Profile to load. // using (OpenFileDialog profile_dialog = new OpenFileDialog()) { // Give the Dialog a title and then establish a filter to hide anything that isn't an XML file by default. profile_dialog.Title = "Select a Profile to open"; profile_dialog.Filter = "Profiles (*.XML)|*.XML|All Files (*.*)|*.*"; profile_dialog.RestoreDirectory = true; if (profile_dialog.ShowDialog() == DialogResult.Cancel) { return(false); } // Save the loaded Profile's filename for convenience sake. filename = profile_dialog.FileName; } // Reset any states... UnsavedProfileChanges = false; //Clean Current Profile_Triggers = new List <VI_Trigger>(); Profile_ActionSequences = new List <VI_Action_Sequence>(); //Constructor will catch. XmlDocument profile_xml = new XmlDocument(); // Let's ensure that the user has actually selected a well-formed XML document for us to navigate as // opposed to - oh, I don't know: a picture of their cat? try { profile_xml.Load(filename); } catch (XmlException exception) { MessageBox.Show("There appears to be a problem with the Profile you have chosen.\n\n" + "It may not been an actual Profile, or it may have become corrupted.", "I cannot load the Profile", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); return(false); } //Check first element tag if (profile_xml.DocumentElement.Name != "gavpi") { throw new Exception("Malformed profile expected first tag gavpi got," + profile_xml.DocumentElement.Name); } XmlNodeList profile_xml_elements = profile_xml.DocumentElement.ChildNodes; foreach (XmlNode element in profile_xml_elements) { if (element.Name == "VI_Action_Sequence") { VI_Action_Sequence ack_frm_file; ack_frm_file = new VI_Action_Sequence(element.Attributes.GetNamedItem("name").Value); ack_frm_file.type = element.Attributes.GetNamedItem("type").Value; ack_frm_file.comment = element.Attributes.GetNamedItem("comment").Value; foreach (XmlNode action in element.ChildNodes) { string action_type = action.Attributes.GetNamedItem("type").Value; string action_value = action.Attributes.GetNamedItem("value").Value; Type new_action_type = Type.GetType("GAVPI." + action_type); object action_instance; if (action_type == "Speak") { action_instance = Activator.CreateInstance(new_action_type, this.synth, action_value); } else { action_instance = Activator.CreateInstance(new_action_type, action_value); } ack_frm_file.Add((Action)action_instance); } if (!Profile_ActionSequences.Any(ack => ack.name == ack_frm_file.name)) { Profile_ActionSequences.Add(ack_frm_file); } } else if (element.Name == "VI_Trigger") { VI_Trigger trig_frm_file; string trigger_name = element.Attributes.GetNamedItem("name").Value; string trigger_type = element.Attributes.GetNamedItem("type").Value; string trigger_value = element.Attributes.GetNamedItem("value").Value; string trigger_comment = element.Attributes.GetNamedItem("comment").Value; Type new_trigger_type = Type.GetType("GAVPI." + trigger_type); object trigger_isntance = trigger_isntance = Activator.CreateInstance(new_trigger_type, trigger_name, trigger_value); trig_frm_file = (VI_Trigger)trigger_isntance; trig_frm_file.comment = trigger_comment; // Trigger Events foreach (XmlElement trigger_event in element.ChildNodes) { string event_type = trigger_event.Attributes.GetNamedItem("type").Value; string event_name = trigger_event.Attributes.GetNamedItem("name").Value; string event_value = trigger_event.Attributes.GetNamedItem("value").Value; if (event_type == "VI_Action_Sequence") { trig_frm_file.Add(Profile_ActionSequences.Find(ackseq => ackseq.name == event_name)); } else if (event_type == "VI_Phrase") { VI_Trigger newMetaTrigger; Type meta_trigger_type = Type.GetType("GAVPI." + event_type); object meta_trigger_isntance = Activator.CreateInstance(meta_trigger_type, event_name, event_value); newMetaTrigger = (VI_Trigger)meta_trigger_isntance; trig_frm_file.Add(newMetaTrigger); } } // Malformed xml or double load, need to switch to dictionaries tbh if (!Profile_Triggers.Any(trig => trig.name == trig_frm_file.name)) { Profile_Triggers.Add(trig_frm_file); } } } // // We have successfully loaded the Profile, so retain the Profile's filename for future reference... // ProfileFilename = filename; return(true); } // public void load_profile()