Exemplo n.º 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            ScriptInfoProxy script = _scripts.AddNew();

            script.HotkeyCommandIdentifier = Math.Max(ScriptManager.MinimumUserScriptID, _scripts.Max(s => s.HotkeyCommandIdentifier)) + 1;
            script.Name = "<New Script>";

            BindScripts(_scripts, script);
        }
Exemplo n.º 2
0
        private void btnMoveUp_Click(object sender, EventArgs e)
        {
            if (SelectedScript is null)
            {
                return;
            }

            ScriptInfoProxy script = SelectedScript;

            int index = _scripts.IndexOf(script);

            _scripts.Remove(script);
            _scripts.Insert(Math.Max(index - 1, 0), script);

            BindScripts(_scripts, script);
        }
Exemplo n.º 3
0
        private void lvScripts_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvScripts.SelectedItems.Count < 1 || !(lvScripts.SelectedItems[0].Tag is ScriptInfoProxy script))
            {
                propertyGrid1.SelectedObject = null;
                return;
            }

            SelectedScript = script;
            script.SetImages(EmbeddedIcons);

            propertyGrid1.SelectedObject = script;

            int index = _scripts.IndexOf(script);

            btnMoveUp.Enabled   = index > 0;
            btnMoveDown.Enabled = index < _scripts.Count - 1;
        }
Exemplo n.º 4
0
        private void BindScripts(IList <ScriptInfoProxy> scripts, ScriptInfoProxy selectedScript)
        {
            try
            {
                lvScripts.BeginUpdate();
                lvScripts.SelectedIndexChanged -= lvScripts_SelectedIndexChanged;
                lvScripts.ItemChecked          -= lvScripts_ItemChecked;
                lvScripts.Items.Clear();

                if (scripts.Count < 1)
                {
                    btnAdd.Focus();
                    return;
                }

                foreach (ScriptInfoProxy script in scripts)
                {
                    var color = !script.Enabled ? SystemColors.GrayText : SystemColors.WindowText;

                    ListViewItem lvitem = new ListViewItem(script.Name)
                    {
                        ToolTipText = $"{script.Command} {script.Arguments}",
                        Tag         = script,
                        ForeColor   = color,
                        ImageKey    = script.Icon,
                        Checked     = script.Enabled
                    };
                    lvScripts.Items.Add(lvitem);

                    lvitem.SubItems.Add(script.OnEvent.ToString());
                    lvitem.SubItems.Add(string.Concat(script.Command, " ", script.Arguments));
                }

                lvScripts.SelectedIndexChanged += lvScripts_SelectedIndexChanged;
                lvScripts.ItemChecked          += lvScripts_ItemChecked;
                lvScripts.SelectedIndices.Clear();

                SelectedScript = selectedScript;

                if (selectedScript is object)
                {
                    ListViewItem lvi = lvScripts.Items.Cast <ListViewItem>().FirstOrDefault(x => x.Tag == selectedScript);
                    if (lvi != null)
                    {
                        lvi.Selected          = true;
                        lvScripts.FocusedItem = lvi;
                    }
                }

                if (lvScripts.FocusedItem is null)
                {
                    lvScripts.Items[0].Selected = true;
                    lvScripts.FocusedItem       = lvScripts.Items[0];
                }

                lvScripts.Select();
            }
            finally
            {
                lvScripts.EndUpdate();
            }
        }