Example #1
0
        /// <summary>
        /// This function will highlight a Window element (the element can be located in DynamoView or another Window or can be a MenuItem
        /// <param name="bVisible">Indicates if the highlight should be applied or removed</param>
        internal void HighlightWindowElement(bool bVisible)
        {
            //Check if the HighlightRectArea was provided in the json file and the HostUIElement was found in the DynamoView VisualTree
            if (HostPopupInfo.HighlightRectArea == null || HostPopupInfo.HostUIElement == null)
            {
                return;
            }
            //Check if the WindowElementNameString was provided in the json and is not empty
            if (string.IsNullOrEmpty(HostPopupInfo.HighlightRectArea.WindowElementNameString))
            {
                return;
            }

            //If is MenuItem type means that the Popup.TargetPlacement will be calculated dinamically
            if (HostPopupInfo.HighlightRectArea.UIElementTypeString.Equals(typeof(MenuItem).Name))
            {
                //We try to find the WindowElementNameString (in this case the MenuItem) in the DynamoView VisualTree
                var foundUIElement = Guide.FindChild(HostPopupInfo.HostUIElement, HostPopupInfo.HighlightRectArea.WindowElementNameString);

                if (foundUIElement != null)
                {
                    var subMenuItem = foundUIElement as MenuItem;

                    //If the HighlightRectArea.WindowElementNameString described is a MenuItem (Dynamo menu) then we need to add the Rectangle dynamically to the Template
                    HighlightMenuItem(subMenuItem, bVisible);
                }
            }
            //The HighlightRectArea.UIElementTypeString was provided but the type is DynamoView then we will search the element in the DynamoView VisualTree
            else if (HostPopupInfo.HighlightRectArea.UIElementTypeString.Equals(typeof(DynamoView).Name))
            {
                string highlightColor = HostPopupInfo.HighlightRectArea.HighlightColor;

                //Find the in the DynamoView VisualTree the specified Element (WindowElementNameString)
                var hostUIElement = Guide.FindChild(MainWindow, HostPopupInfo.HighlightRectArea.WindowElementNameString);

                if (hostUIElement == null)
                {
                    return;
                }

                //If the Element was found we need to calculate the X,Y coordinates based in the UIElement Ancestor
                Point relativePoint = hostUIElement.TransformToAncestor(MainWindow)
                                      .Transform(new Point(0, 0));

                var holeWidth  = hostUIElement.DesiredSize.Width + HostPopupInfo.HighlightRectArea.WidthBoxDelta;
                var holeHeight = hostUIElement.DesiredSize.Height + HostPopupInfo.HighlightRectArea.HeightBoxDelta;

                //Activate the Highlight rectangle from the GuideBackground
                StepGuideBackground.HighlightBackgroundArea.SetHighlighRectSize(relativePoint.Y, relativePoint.X, holeWidth, holeHeight);

                if (string.IsNullOrEmpty(highlightColor))
                {
                    StepGuideBackground.GuideHighlightRectangle.Stroke = Brushes.Transparent;
                }
                else
                {
                    //This section will put the desired color in the Highlight rectangle (read from the json file)
                    var converter = new BrushConverter();
                    var brush     = (Brush)converter.ConvertFromString(highlightColor);
                    StepGuideBackground.GuideHighlightRectangle.Stroke = brush;
                }
            }
            //If the UIElementTypeString is not a MenuItem and also not a DynamoView we need to find the Window in the OwnedWindows and search the element inside it
            else
            {
                string highlightColor = HostPopupInfo.HighlightRectArea.HighlightColor;
                Window ownedWindow    = Guide.FindWindowOwned(HostPopupInfo.HighlightRectArea.WindowName, MainWindow as Window);
                if (ownedWindow == null)
                {
                    return;
                }
                UIElement foundElement = Guide.FindChild(ownedWindow, HostPopupInfo.HighlightRectArea.WindowElementNameString);
                switch (HostPopupInfo.HighlightRectArea.UIElementTypeString.ToUpper())
                {
                //We need to highlight a Button (if the Button template doesn't have a grid then the template needs to be updated)
                case "BUTTON":
                    var buttonElement = foundElement as Button;
                    if (buttonElement == null)
                    {
                        return;
                    }

                    //We will be searching for the Grid name provided in the json file and then add the Highlight Rectangle
                    var bordersGrid = buttonElement.Template.FindName(HostPopupInfo.HighlightRectArea.UIElementGridContainer, buttonElement) as Grid;
                    if (bordersGrid == null)
                    {
                        return;
                    }

                    if (bVisible)
                    {
                        var buttonRectangle = CreateRectangle(bordersGrid, HostPopupInfo.HighlightRectArea.HighlightColor);
                        //The Rectangle will be added dynamically in a specific step and then when passing to next step we will remove it
                        bordersGrid.Children.Add(buttonRectangle);
                    }
                    else
                    {
                        //When we need to undo the highlight we find the Rectangle and remove it
                        var buttonRectangle = bordersGrid.Children.OfType <Rectangle>().Where(rect => rect.Name.Equals("HighlightRectangle")).FirstOrDefault();
                        if (buttonRectangle != null)
                        {
                            bordersGrid.Children.Remove(buttonRectangle);
                        }
                    }
                    break;
                }
            }
        }
Example #2
0
        /// <summary>
        /// This method will execute an UIAutomation action over a specific UIElement
        /// </summary>
        /// <param name="uiAutomationData">UIAutomation info read from a json file</param>
        /// <param name="enableUIAutomation">Enable/Disable the automation action for a specific UIElement</param>
        private void ExecuteUIAutomationStep(StepUIAutomation uiAutomationData, bool enableUIAutomation, Guide.GuideFlow currentFlow)
        {
            //This section will search the UIElement dynamically in the Dynamo VisualTree in which an automation action will be executed
            UIElement automationUIElement = Guide.FindChild(MainWindow, uiAutomationData.Name);

            if (automationUIElement != null)
            {
                uiAutomationData.UIElementAutomation = automationUIElement;
            }

            switch (uiAutomationData.ControlType)
            {
            case StepUIAutomation.UIControlType.MENUITEM:
                if (uiAutomationData.UIElementAutomation == null)
                {
                    return;
                }
                MenuItem menuEntry = uiAutomationData.UIElementAutomation as MenuItem;
                if (menuEntry == null)
                {
                    return;
                }
                switch (uiAutomationData.Action)
                {
                case StepUIAutomation.UIAction.OPEN:
                    menuEntry.IsSubmenuOpen    = enableUIAutomation;
                    menuEntry.StaysOpenOnClick = enableUIAutomation;
                    break;
                }
                break;

            //In this case the UI Automation will be done using a Function located in the static class GuidesValidationMethods
            case StepUIAutomation.UIControlType.FUNCTION:
                MethodInfo builderMethod   = typeof(GuidesValidationMethods).GetMethod(uiAutomationData.Name, BindingFlags.Static | BindingFlags.NonPublic);
                object[]   parametersArray = new object[] { this, uiAutomationData, enableUIAutomation, currentFlow };
                builderMethod.Invoke(null, parametersArray);
                //If UpdatePlacementTarget = true then means that a new Window was opened after executing the funtion then we need to update the Popup.PlacementTarget
                if (uiAutomationData.UpdatePlacementTarget)
                {
                    UpdatePlacementTarget();
                }
                break;

            //In this case the UI Automation will be done over a WPF Button
            case StepUIAutomation.UIControlType.BUTTON:
                if (string.IsNullOrEmpty(uiAutomationData.WindowName))
                {
                    return;
                }

                //This means that the Button is in a PopupWindow (instead of the DynamoView) so we need to find the button and then apply the automation
                if (uiAutomationData.WindowName.Equals(WindowNamePopup))
                {
                    //Finds the Button inside the PopupWindow
                    var buttonFound = Guide.FindChild((stepUIPopup as PopupWindow).mainPopupGrid, uiAutomationData.Name) as Button;
                    if (buttonFound == null)
                    {
                        return;
                    }

                    switch (uiAutomationData.Action)
                    {
                    case StepUIAutomation.UIAction.DISABLE:
                        if (enableUIAutomation)
                        {
                            buttonFound.IsEnabled = false;
                        }
                        else
                        {
                            buttonFound.IsEnabled = true;
                        }
                        break;
                    }
                }
                break;
            }
        }
        /// <summary>
        /// This method will be used to open the PackageManagerSearchView and search for a specific Package
        /// </summary>
        /// <param name="stepInfo">Step information</param>
        /// <param name="uiAutomationData">Specific UI Automation step that is being executed</param>
        /// <param name="enableFunction">it says if the functionality should be enabled or disabled</param>
        /// <param name="currentFlow">The current flow of the Guide can be FORWARD or BACKWARD</param>
        internal static void ExecutePackageSearch(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            CurrentExecutingStep = stepInfo;
            //We try to find the PackageManagerSearchView window
            Window ownedWindow = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window);

            if (enableFunction)
            {
                //We need to check if the PackageManager search is already open if that is the case we don't need to open it again
                if (ownedWindow != null)
                {
                    return;
                }
                stepInfo.DynamoViewModelStep.ShowPackageManagerSearch(null);

                PackageManagerSearchView packageManager = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;
                if (packageManagerViewModel == null)
                {
                    return;
                }

                searchPackagesLoaded = false;
                //Due that we need to search the Autodesk Sample package after the initial search is completed
                //we need to subscribe to the PropertyChanged event so we will know when the SearchState property is equal to Results (meaning that got results)
                searchPackagesPropertyChanged            = (sender, e) => { PackageManagerViewModel_PropertyChanged(sender, e, uiAutomationData); };
                packageManagerViewModel.PropertyChanged += searchPackagesPropertyChanged.Invoke;
            }
            else
            {
                PackageManagerSearchView packageManager = Guide.FindWindowOwned(stepInfo.HostPopupInfo.WindowName, stepInfo.MainWindow as Window) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;
                if (packageManagerViewModel == null)
                {
                    return;
                }

                //Depending of the SetUp done in the Guides Json we will make the Clean Up or not, for example there are several Steps that use the PackageManagerSearchView then we won't close it

                //The Guide is moving to FORWARD and the ExecuteCleanUpForward = false, then we don't need to close the PackageManagerSearchView
                if (uiAutomationData.ExecuteCleanUpForward && currentFlow == GuideFlow.FORWARD)
                {
                    ClosePackageManager(packageManager);
                }

                //The Guide is moving to FORWARD and the ExecuteCleanUpForward = false, then we don't need to close the PackageManagerSearchView
                if (uiAutomationData.ExecuteCleanUpBackward && currentFlow == GuideFlow.BACKWARD)
                {
                    ClosePackageManager(packageManager);
                }

                //The currentFlow = GuideFlow.CURRENT when exiting the Guide
                if (currentFlow == GuideFlow.CURRENT)
                {
                    ClosePackageManager(packageManager);
                }
            }
        }
        /// <summary>
        /// This method will be opening the SideBar Package Details (or closing it when enableFunction = false)
        /// </summary>
        /// <param name="stepInfo">Information about the Step</param>
        /// <param name="uiAutomationData">Information about UI Automation that is being executed</param>
        /// <param name="enableFunction">Variable used to know if we are executing the automation or undoing changes</param>
        /// <param name="currentFlow">Current Guide Flow</param>
        internal static void ExecuteViewDetailsSideBar(Step stepInfo, StepUIAutomation uiAutomationData, bool enableFunction, GuideFlow currentFlow)
        {
            const string packageDetailsName      = "Package Details";
            const string closeButtonName         = "CloseButton";
            const string packageSearchWindowName = "PackageSearch";

            CurrentExecutingStep = stepInfo;
            var stepMainWindow       = stepInfo.MainWindow as Window;
            var packageDetailsWindow = Guide.FindChild(stepMainWindow, stepInfo.HostPopupInfo.HostUIElementString) as UserControl;

            if (enableFunction)
            {
                //This section will open the Package Details Sidebar
                PackageManagerSearchView packageManager = Guide.FindWindowOwned(packageSearchWindowName, stepMainWindow) as PackageManagerSearchView;
                if (packageManager == null)
                {
                    return;
                }
                PackageManagerSearchViewModel packageManagerViewModel = packageManager.DataContext as PackageManagerSearchViewModel;

                //If the results in the PackageManagerSearch are null then we cannot open the Package Detail tab
                if (packageManagerViewModel == null || packageManagerViewModel.SearchResults.Count == 0)
                {
                    return;
                }

                //We take the first result from the PackageManagerSearch
                PackageManagerSearchElementViewModel packageManagerSearchElementViewModel = packageManagerViewModel.SearchResults[0];
                if (packageManagerSearchElementViewModel == null)
                {
                    return;
                }

                if (packageDetailsWindow == null)
                {
                    packageManagerViewModel.ViewPackageDetailsCommand.Execute(packageManagerSearchElementViewModel.Model);
                }

                //The PackageDetails sidebar is using events when is being shown then we need to execute those events before setting the Popup.PlacementTarget.
                //otherwise the sidebar will not be present (and we don't have host for the Popup) and the Popup will be located out of the Dynamo window
                CurrentExecutingStep.MainWindow.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));
            }
            else
            {
                //This section will close the Package Details Sidebar (just in case is still opened),
                //due that the sidebar (UserControl) is inserted inside a TabItem the only way to close is by using the method dynamoView.CloseExtensionTab
                var dynamoView = (stepMainWindow as DynamoView);
                if (packageDetailsWindow == null)
                {
                    return;
                }
                //In order to close the Package Details tab we need first to get the Tab, then get the Close button and finally call the event to close it
                TabItem tabitem = dynamoView.ExtensionTabItems.OfType <TabItem>().SingleOrDefault(n => n.Header.ToString() == packageDetailsName);
                if (tabitem == null)
                {
                    return;
                }
                //Get the Close button from the PackageDetailsView
                Button closeButton = Guide.FindChild(tabitem, closeButtonName) as Button;
                if (closeButton == null)
                {
                    return;
                }
                dynamoView.CloseExtensionTab(closeButton, null);
            }
        }
Example #5
0
 /// <summary>
 /// GuidesManager Constructor
 /// </summary>
 /// <param name="root">root item of the main Dynamo Window </param>
 /// <param name="dynViewModel"></param>
 public GuidesManager(UIElement root, DynamoViewModel dynViewModel)
 {
     mainRootElement        = root;
     dynamoViewModel        = dynViewModel;
     guideBackgroundElement = Guide.FindChild(root, guideBackgroundName) as GuideBackground;
 }