Esempio n. 1
0
        public void ShowElementSelector(object sender, EventArgs e)
        {
            //create element selector form
            frmElementSelector newElementSelector = new frmElementSelector();

            //get copy of user element and append system elements, then load to combobox
            var elementList = _currentEditor.ScriptElements.Select(f => f.ElementName).ToList();

            newElementSelector.lstElements.Items.AddRange(elementList.ToArray());

            //if user pressed "OK"
            if (newElementSelector.ShowDialog() == DialogResult.OK)
            {
                //ensure that a element was actually selected
                if (newElementSelector.lstElements.SelectedItem == null)
                {
                    //return out as nothing was selected
                    MessageBox.Show("There were no elements selected!");
                    return;
                }

                //grab the referenced input assigned to the 'insert element' button instance
                CommandItemControl inputBox = (CommandItemControl)sender;

                if (inputBox.Tag is DataGridView)
                {
                    DataGridView targetDGV = (DataGridView)inputBox.Tag;

                    targetDGV.DataSource = _currentEditor.ScriptElements
                                           .Where(x => x.ElementName == newElementSelector.lstElements.SelectedItem.ToString().Replace("<", "").Replace(">", ""))
                                           .FirstOrDefault().ElementValue;
                }
            }
        }
Esempio n. 2
0
        public static void ShowElementSelector(object sender, EventArgs e)
        {
            //create element selector form
            frmElementSelector newElementSelector = new frmElementSelector();

            //get copy of user element and append system elements, then load to combobox
            var elementList = CurrentEditor.ScriptElements.Select(f => "(" + f.ElementType.Description() + ") " + f.ElementName).ToList();

            newElementSelector.lstElements.Items.AddRange(elementList.ToArray());

            //if user pressed "OK"
            if (newElementSelector.ShowDialog() == DialogResult.OK)
            {
                //ensure that a element was actually selected
                if (newElementSelector.lstElements.SelectedItem == null)
                {
                    //return out as nothing was selected
                    MessageBox.Show("There were no elements selected!");
                    return;
                }

                //grab the referenced input assigned to the 'insert element' button instance
                CommandItemControl inputBox = (CommandItemControl)sender;
                //currently element insertion is only available for simply textboxes

                Regex regex = new Regex(@"\([\w\s]+\)\s");
                if (inputBox.Tag is TextBox)
                {
                    TextBox targetTextbox = (TextBox)inputBox.Tag;
                    //concat element name with brackets <vElement> as engine searches for the same
                    targetTextbox.Text = targetTextbox.Text + "<" + regex.Replace(newElementSelector.lstElements.SelectedItem.ToString(), "") + ">";
                }
                else if (inputBox.Tag is ComboBox)
                {
                    ComboBox targetCombobox = (ComboBox)inputBox.Tag;
                    //concat element name with brackets <vElement> as engine searches for the same
                    targetCombobox.Text = targetCombobox.Text + "<" + regex.Replace(newElementSelector.lstElements.SelectedItem.ToString(), "") + ">";
                }
                else if (inputBox.Tag is DataGridView)
                {
                    DataGridView targetDGV = (DataGridView)inputBox.Tag;

                    if (targetDGV.SelectedCells.Count == 0)
                    {
                        MessageBox.Show("Please make sure you have selected an action and selected a cell before attempting" +
                                        " to insert an element!", "No Cell Found", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (targetDGV.SelectedCells[0].ColumnIndex == 0)
                    {
                        MessageBox.Show("Invalid Cell Selected!", "Invalid Cell Selected", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    targetDGV.SelectedCells[0].Value = targetDGV.SelectedCells[0].Value + "<" + newElementSelector.lstElements.SelectedItem.ToString() + ">";
                }
            }
        }