private void PasteRows()
        {
            CreateUndoSnapshot();

            if (_rowsSelectedForCopy != null)
            {
                if (SelectedTabScriptActions.SelectedItems.Count == 0)
                {
                    MessageBox.Show("In order to paste, you must first select a command to paste under.",
                                    "Select Command To Paste Under");
                    return;
                }

                int destinationIndex = SelectedTabScriptActions.SelectedItems[0].Index + 1;

                foreach (ListViewItem item in _rowsSelectedForCopy)
                {
                    dynamic duplicatedCommand = CommonMethods.Clone(item.Tag);
                    duplicatedCommand.GenerateID();
                    SelectedTabScriptActions.Items.Insert(destinationIndex, CreateScriptCommandListViewItem(duplicatedCommand));
                    destinationIndex += 1;
                }

                SelectedTabScriptActions.Invalidate();
                Notify(_rowsSelectedForCopy.Count + " item(s) pasted!", Color.White);
            }
        }
        private void DeleteSelectedCode()
        {
            SelectAllScopedCode();

            foreach (ListViewItem item in SelectedTabScriptActions.SelectedItems)
            {
                SelectedTabScriptActions.Items.Remove(item);
            }

            SelectedTabScriptActions.Invalidate();
        }
        private void RedoChange()
        {
            if (((ScriptActionTag)SelectedTabScriptActions.Tag).RedoList.Count > 0)
            {
                CreateUndoSnapshot();
                SelectedTabScriptActions.Items.Clear();

                foreach (ListViewItem rowItem in ((ScriptActionTag)SelectedTabScriptActions.Tag).RedoList.Last())
                {
                    SelectedTabScriptActions.Items.Add(rowItem);
                }

                ((ScriptActionTag)SelectedTabScriptActions.Tag).RedoList
                .RemoveAt(((ScriptActionTag)SelectedTabScriptActions.Tag).RedoList.Count - 1);

                SelectedTabScriptActions.Invalidate();
            }
        }
        private void AddRemoveBreakpoint()
        {
            //warn if nothing was selected
            if (SelectedTabScriptActions.SelectedItems.Count == 0)
            {
                Notify("No code was selected!", Color.Yellow);
            }
            else
            {
                CreateUndoSnapshot();
            }

            //get each item and set appropriately
            foreach (ListViewItem item in SelectedTabScriptActions.SelectedItems)
            {
                var selectedCommand = (ScriptCommand)item.Tag;
                selectedCommand.PauseBeforeExecution = !selectedCommand.PauseBeforeExecution;
            }

            //recolor
            SelectedTabScriptActions.Invalidate();
        }
        private void SetSelectedCodeToCommented(bool setCommented)
        {
            SelectAllScopedCode();

            //warn if nothing was selected
            if (SelectedTabScriptActions.SelectedItems.Count == 0)
            {
                Notify("No code was selected!", Color.Yellow);
            }
            else
            {
                CreateUndoSnapshot();
            }

            //get each item and set appropriately
            foreach (ListViewItem item in SelectedTabScriptActions.SelectedItems)
            {
                var selectedCommand = (ScriptCommand)item.Tag;
                selectedCommand.IsCommented = setCommented;
            }

            //recolor
            SelectedTabScriptActions.Invalidate();
        }
 private void ClearSelectedListViewItems()
 {
     SelectedTabScriptActions.SelectedItems.Clear();
     SelectedTabScriptActions.Invalidate();
 }
        private void lstScriptActions_DragDrop(object sender, DragEventArgs e)
        {
            //returns the location of the mouse pointer in the ListView control
            Point cp = SelectedTabScriptActions.PointToClient(new Point(e.X, e.Y));

            //obtain the item that is located at the specified location of the mouse pointer
            ListViewItem dragToItem = SelectedTabScriptActions.GetItemAt(cp.X, cp.Y);

            if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false))
            {
                TreeNode commandNode = ((TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"));

                if (commandNode.Nodes.Count != 0)
                {
                    return;
                }

                var commandName      = commandNode.Text;
                var commandGroupName = commandNode.Parent.Text;

                var newCommandName = _automationCommands.Where(x => x.ShortName == commandName && x.DisplayGroup == commandGroupName)
                                     .Select(x => x.Command).FirstOrDefault().GetType();

                dynamic newCommandInstance = TypeMethods.CreateTypeInstance(AContainer, newCommandName.Name);

                CreateUndoSnapshot();
                if (dragToItem != null)
                {
                    AddCommandToListView(newCommandInstance, dragToItem.Index);
                }
                else
                {
                    AddCommandToListView(newCommandInstance, SelectedTabScriptActions.Items.Count);
                }
            }
            else
            {
                //return if the items are not selected in the ListView control
                if (SelectedTabScriptActions.SelectedItems.Count == 0)
                {
                    return;
                }

                CreateUndoSnapshot();

                if (dragToItem == null)
                {
                    return;
                }

                List <ScriptCommand> commandsToMove = new List <ScriptCommand>();

                for (int i = 0; i <= SelectedTabScriptActions.SelectedItems.Count - 1; i++)
                {
                    var command = (ScriptCommand)SelectedTabScriptActions.SelectedItems[i].Tag;
                    commandsToMove.Add(command);
                }

                //obtain the index of the item at the mouse pointer
                int dragIndex = dragToItem.Index;

                ListViewItem[] sel = new ListViewItem[SelectedTabScriptActions.SelectedItems.Count];
                for (int i = 0; i <= SelectedTabScriptActions.SelectedItems.Count - 1; i++)
                {
                    sel[i] = SelectedTabScriptActions.SelectedItems[i];
                }
                for (int i = 0; i < sel.GetLength(0); i++)
                {
                    //obtain the ListViewItem to be dragged to the target location
                    ListViewItem dragItem  = sel[i];
                    int          itemIndex = dragIndex;
                    if (itemIndex == dragItem.Index)
                    {
                        return;
                    }
                    if (dragItem.Index < itemIndex)
                    {
                        itemIndex++;
                    }
                    else
                    {
                        itemIndex = dragIndex + i;
                    }

                    //insert the item at the mouse pointer
                    ListViewItem insertItem = (ListViewItem)dragItem.Clone();
                    SelectedTabScriptActions.Items.Insert(itemIndex, insertItem);

                    //removes the item from the initial location while the item is moved to the new location
                    SelectedTabScriptActions.Items.Remove(dragItem);
                    SelectedTabScriptActions.Invalidate();
                }
            }
        }
        public void AddCommandToListView(ScriptCommand selectedCommand, int index = -1)
        {
            if (!uiScriptTabControl.SelectedTab.Controls[0].Visible)
            {
                uiScriptTabControl.SelectedTab.Controls[0].Show();
            }

            ListViewItem command;

            //valid command verification for drag/dropped commands
            if (selectedCommand != null)
            {
                command = CreateScriptCommandListViewItem(selectedCommand);
            }
            else
            {
                return;
            }

            int insertionIndex;

            if (index == -1)
            {
                //insert to end by default
                insertionIndex = SelectedTabScriptActions.Items.Count;

                //verify setting to insert inline is selected and if an item is currently selected
                if ((_appSettings.ClientSettings.InsertCommandsInline) && (SelectedTabScriptActions.SelectedItems.Count > 0))
                {
                    //insert inline
                    insertionIndex = SelectedTabScriptActions.SelectedItems[0].Index + 1;
                }
            }
            else
            {
                insertionIndex = index;
            }

            //insert command
            SelectedTabScriptActions.Items.Insert(insertionIndex, command);
            ClearSelectedListViewItems();
            command.Selected = true;

            //special types also get a following command and comment
            if ((selectedCommand.CommandName == "LoopCollectionCommand") || (selectedCommand.CommandName == "LoopContinuouslyCommand") ||
                (selectedCommand.CommandName == "LoopNumberOfTimesCommand") || (selectedCommand.CommandName == "BeginLoopCommand") ||
                (selectedCommand.CommandName == "BeginMultiLoopCommand"))
            {
                dynamic addCodeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                addCodeCommentCommand.v_Comment = "Items in this section will run within the loop";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(addCodeCommentCommand));

                dynamic endLoopCommand = TypeMethods.CreateTypeInstance(AContainer, "EndLoopCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(endLoopCommand));
            }
            else if ((selectedCommand.CommandName == "BeginIfCommand") || (selectedCommand.CommandName == "BeginMultiIfCommand"))
            {
                dynamic addCodeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                addCodeCommentCommand.v_Comment = "Items in this section will run if the statement is true";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(addCodeCommentCommand));

                dynamic endIfCommand = TypeMethods.CreateTypeInstance(AContainer, "EndIfCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(endIfCommand));
            }
            else if (selectedCommand.CommandName == "BeginTryCommand")
            {
                dynamic addCodeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                addCodeCommentCommand.v_Comment = "Items in this section will be handled if error occurs";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(addCodeCommentCommand));

                dynamic catchCommand = TypeMethods.CreateTypeInstance(AContainer, "CatchCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(catchCommand));

                dynamic codeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                codeCommentCommand.v_Comment = "This section executes if error occurs above";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 3, CreateScriptCommandListViewItem(codeCommentCommand));

                dynamic endTryCommand = TypeMethods.CreateTypeInstance(AContainer, "EndTryCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 4, CreateScriptCommandListViewItem(endTryCommand));
            }
            else if (selectedCommand.CommandName == "BeginRetryCommand")
            {
                dynamic addCodeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                addCodeCommentCommand.v_Comment = "Items in this section will be retried as long as the condition is not met or an error is thrown";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(addCodeCommentCommand));

                dynamic endRetryCommand = TypeMethods.CreateTypeInstance(AContainer, "EndRetryCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(endRetryCommand));
            }
            else if (selectedCommand.CommandName == "BeginSwitchCommand")
            {
                dynamic caseCommand = TypeMethods.CreateTypeInstance(AContainer, "CaseCommand");
                caseCommand.v_CaseValue = "Default";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 1, CreateScriptCommandListViewItem(caseCommand));

                dynamic addCodeCommentCommand = TypeMethods.CreateTypeInstance(AContainer, "AddCodeCommentCommand");
                addCodeCommentCommand.v_Comment = "Items in this section will run if no case statements match";
                SelectedTabScriptActions.Items.Insert(insertionIndex + 2, CreateScriptCommandListViewItem(addCodeCommentCommand));

                dynamic endSwitchCommand = TypeMethods.CreateTypeInstance(AContainer, "EndSwitchCommand");
                SelectedTabScriptActions.Items.Insert(insertionIndex + 3, CreateScriptCommandListViewItem(endSwitchCommand));
            }

            CreateUndoSnapshot();
            SelectedTabScriptActions.Invalidate();
            AutoSizeLineNumberColumn();
        }
 private void lstScriptActions_MouseMove(object sender, MouseEventArgs e)
 {
     SelectedTabScriptActions.Invalidate();
 }
 private void lstScriptActions_ItemDrag(object sender, ItemDragEventArgs e)
 {
     SelectedTabScriptActions.DoDragDrop(SelectedTabScriptActions.SelectedItems, DragDropEffects.Move);
 }