Пример #1
0
        private void Makros_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Delete)
            {
                ActivatorTime.CancelTimers(SelectedNode);
                ActivatorShortcut.RemoveEvents(SelectedNode);

                if (SelectedNode.GetType() == typeof(ActivatorShortcut))
                {
                    SelectedNode.Remove();
                }
                else if (SelectedNode.GetType() == typeof(ActivatorTime))
                {
                    SelectedNode.Remove();
                }
                else if (SelectedNode.Name == "command" || SelectedNode.Name == "activator" || SelectedNode.Name == "condition")
                {
                    SelectedNode.Remove();
                }
                else if (SelectedNode.Name == "makro" || SelectedNode.Name == "folder")
                {
                    DialogResult result = MessageBox.Show("Wollen Sie \"" + SelectedNode.Text + "\" und somit auch alle Unterpunkte wirklich löschen?", "Löschen", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        Nodes.Remove(SelectedNode);
                    }
                }
            }
            else if (e.KeyCode == Keys.Add)
            {
                if (SelectedNode.GetType() == typeof(CommandWait))
                {
                    CommandWait cw = (CommandWait)SelectedNode;
                    if (cw.Duration + 50 <= 3600000)
                    {
                        cw.Duration += 50;
                    }
                    else
                    {
                        cw.Duration = 3600000;
                    }
                }
            }
            else if (e.KeyCode == Keys.Subtract)
            {
                if (SelectedNode.GetType() == typeof(CommandWait))
                {
                    CommandWait cw = (CommandWait)SelectedNode;
                    if (cw.Duration - 50 >= 20)
                    {
                        cw.Duration -= 50;
                    }
                    else
                    {
                        cw.Duration = 20;
                    }
                }
            }
            else if (e.KeyCode == Keys.NumPad0)
            {
                if (SelectedNode.GetType() == typeof(CommandWait))
                {
                    CommandWait cw = (CommandWait)SelectedNode;
                    cw.Duration = 40;
                }
            }
            else if (e.KeyCode == Keys.NumPad1)
            {
                if (SelectedNode.GetType() == typeof(CommandWait))
                {
                    CommandWait cw = (CommandWait)SelectedNode;
                    cw.Duration = 100;
                }
            }
            else if (e.KeyCode == Keys.NumPad2)
            {
                if (SelectedNode.GetType() == typeof(CommandWait))
                {
                    CommandWait cw = (CommandWait)SelectedNode;
                    cw.Duration = 200;
                }
            }
            else if (e.KeyCode == Keys.Up && m_controlPressed)
            {
                if (SelectedNode.Name == "command" || SelectedNode.Name == "condition" ||
                    SelectedNode.Name == "activator" || SelectedNode.Name == "makro" || SelectedNode.Name == "folder")
                {
                    int tnIndex = SelectedNode.Index;
                    if (tnIndex - 1 >= 0)
                    {
                        TreeNode parentNode = SelectedNode.Parent;
                        TreeNode tn         = SelectedNode;
                        parentNode.Nodes.Remove(tn);
                        parentNode.Nodes.Insert(tnIndex - 1, tn);
                        SelectedNode = tn;
                    }
                }
            }
            else if (e.KeyCode == Keys.Down && m_controlPressed)
            {
                if (SelectedNode.Name == "command" || SelectedNode.Name == "condition" ||
                    SelectedNode.Name == "activator" || SelectedNode.Name == "makro" || SelectedNode.Name == "folder")
                {
                    int      tnIndex    = SelectedNode.Index;
                    TreeNode parentNode = SelectedNode.Parent;
                    if (tnIndex + 1 <= parentNode.Nodes.Count)
                    {
                        TreeNode tn = SelectedNode;
                        parentNode.Nodes.Remove(tn);
                        parentNode.Nodes.Insert(tnIndex + 1, tn);
                        SelectedNode = tn;
                    }
                }
            }
            if (e.KeyCode == Keys.ControlKey)
            {
                m_controlPressed = true;
            }
        }