public void ReplaceAction(ActionBase target, ActionBase replacement) { foreach (var index in from action in _package.Actions where action == target select _package.Actions.IndexOf(action)) { _package.Actions.RemoveAt(index); _package.Actions.Insert(index, replacement); break; } }
/// <summary> /// Selects the action from TreeView. /// </summary> /// <param name="action">The action.</param> private void SelectActionFromTreeView(ActionBase action) { _isChangingAction = true; var actionType = action.GetType(); SetActionComboBox(actionType.Name.Substring(0, actionType.Name.IndexOf("Action", StringComparison.Ordinal))); PathAttribute.Text = action.Path; switch (actionType.Name) { case "ClickAction": var clickAction = action as ClickAction; if(clickAction != null) { TextAttribute.Text = clickAction.Text; } break; case "EnterKeyAction": var enterKeyAction = action as EnterKeyAction; if(enterKeyAction != null) { TextAttribute.Text = enterKeyAction.Text; } break; case "NavigateToAction": break; case "SelectItemAction": var selectItemAction = action as SelectItemAction; if (selectItemAction != null) { ConditionAttribute.SelectedItem = null; foreach ( var comboBoxItem in ConditionAttribute.Items.Cast<ComboBoxItem>() .Where( comboBoxItem => comboBoxItem.Tag.Equals(selectItemAction.Condition.ToString()))) { ConditionAttribute.SelectedItem = comboBoxItem; break; } ValueAttribute.Text = selectItemAction.Value; TextAttribute.Text = selectItemAction.Text; } break; case "SetTextAction": var setTextAction = action as SetTextAction; if(setTextAction != null) { TextAttribute.Text = setTextAction.Value; } break; case "TestAction": var testAction = action as TestAction; if (testAction != null) { ConditionAttribute.SelectedItem = null; foreach ( var comboBoxItem in ConditionAttribute.Items.Cast<ComboBoxItem>() .Where(comboBoxItem => comboBoxItem.Tag.Equals(testAction.Condition.ToString()))) { ConditionAttribute.SelectedItem = comboBoxItem; break; } ValueAttribute.Text = testAction.ExpectedValue; TextAttribute.Text = testAction.ExpectedText; } break; case "WaitAction": var waitAction = action as WaitAction; if(waitAction != null) { ValueAttribute.Text = waitAction.Seconds.ToString(); } break; } _isChangingAction = false; }
/// <summary> /// Refreshes the TreeView. /// </summary> /// <param name="selectedAction">The selected action.</param> private void RefreshTreeView(ActionBase selectedAction = null) { PackageActions.Items.Refresh(); if (selectedAction != null) { foreach (var container in from object item in PackageActions.Items where item == selectedAction select PackageActions.ItemContainerGenerator.ContainerFromItem(item) as TreeViewItem) { if (container != null) { container.IsSelected = true; } break; } } else { if (PackageActions.Items.Count > 0) { var container = PackageActions.ItemContainerGenerator.ContainerFromIndex(0) as TreeViewItem; if (container != null) { container.IsSelected = true; } } } }