/// <summary> /// Handles unselecting a listviewitem /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListViewItem_Unselected(object sender, RoutedEventArgs e) { var lvi = sender as ListViewItem; var exp = GetParentElem <Expander>(lvi) as Expander; var cb = GetFirstChildElement <CheckBox>(exp) as CheckBox; var srvm = lvi.DataContext as RuleResultViewModel; // ElementContext can be null when app is closed. if (this.ElementContext != null) { ImageOverlayDriver.GetDefaultInstance().RemoveElement(this.ElementContext.Id, srvm.Element.UniqueId); } SelectedItems.Remove(srvm); var groupitem = GetParentElem <GroupItem>(exp) as GroupItem; var dc = cb.DataContext as CollectionViewGroup; var itms = dc.Items; var any = itms.Intersect(SelectedItems).Any(); if (any) { cb.IsChecked = null; groupitem.Tag = "some"; } else { cb.IsChecked = false; groupitem.Tag = "zero"; } UpdateSelectAll(); }
/// <summary> /// Handles list view item selection /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ListViewItem_Selected(object sender, RoutedEventArgs e) { if (ScreenshotAvailable) { var lvi = sender as ListViewItem; var exp = GetParentElem <Expander>(lvi) as Expander; var cb = GetFirstChildElement <CheckBox>(exp) as CheckBox; var itm = lvi.DataContext as RuleResultViewModel; if (!SelectedItems.Contains(itm)) { SelectedItems.Add(itm); UpdateSelectAll(); ImageOverlayDriver.GetDefaultInstance().AddElement(this.ElementContext.Id, itm.Element.UniqueId); } var groupitem = GetParentElem <GroupItem>(exp) as GroupItem; var dc = cb.DataContext as CollectionViewGroup; var itms = dc.Items; var any = itms.Except(SelectedItems).Any(); if (any) { cb.IsChecked = null; groupitem.Tag = "some"; // used to indicate how many children are selected } else { cb.IsChecked = true; groupitem.Tag = "all"; } } }
/// <summary> /// Sets element context and updates UI /// </summary> /// <param name="ec"></param> public void SetElement(ElementContext ec) { if (ec == null) { throw new ArgumentNullException(nameof(ec)); } try { // set handler here. it will make sure that highliter button is shown and working. ImageOverlayDriver.GetDefaultInstance().SetHighlighterButtonClickHandler(TBElem_Click); if (this.ElementContext == null || ec.Element != this.ElementContext.Element || this.DataContext != ec.DataContext) { this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.DataContext = ec.DataContext; this.chbxSelectAll.IsEnabled = ScreenshotAvailable; this.lvResults.ItemsSource = null; this.ElementContext = ec; this.tbGlimpse.Text = "Target: " + ec.Element.Glimpse; UpdateUI(); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); } #pragma warning restore CA1031 // Do not catch general exception types }
/// <summary> /// Select all items in list /// </summary> /// <param name="lst"></param> /// <param name="check"></param> /// <returns></returns> private bool SetItemsChecked(IReadOnlyCollection <Object> lst, bool check) { var ret = true; foreach (RuleResultViewModel itm in lst.AsParallel()) { if (check && !SelectedItems.Contains(itm)) { SelectedItems.Add(itm); ImageOverlayDriver.GetDefaultInstance().AddElement(this.ElementContext.Id, itm.Element.UniqueId); } else if (!check && SelectedItems.Contains(itm)) { SelectedItems.Remove(itm); ImageOverlayDriver.GetDefaultInstance().RemoveElement(this.ElementContext.Id, itm.Element.UniqueId); } var lvi = lvResults.ItemContainerGenerator.ContainerFromItem(itm) as ListViewItem; if (lvi != null) { lvi.IsSelected = check; } else { ret = false; } } UpdateSelectAll(); return(ret); }
/// <summary> /// Displays loading indicator and updates UI /// </summary> /// <param name="forceRefresh"></param> public void UpdateUI() { this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.AllExpanded = false; fabicnExpandAll.GlyphName = CommonUxComponents.Controls.FabricIcon.CaretSolidRight; this.SelectedItems.Clear(); this.chbxSelectAll.IsChecked = false; HollowHighlightDriver.GetDefaultInstance().Clear(); if (this.DataContext != null) { var list = this.DataContext.GetRuleResultsViewModelList(); SetRuleResults(list); if (list != null) { var ha = ImageOverlayDriver.GetDefaultInstance(); ha.SetImageElement(ElementContext.Id); if (HighlightVisibility) { ha.Show(); } } Dispatcher.Invoke(() => { CheckAllBoxes(lvResults, true); }, DispatcherPriority.Input); } }
/// <summary> /// Displays loading indicator and updates UI /// </summary> public void UpdateUI() { this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.nonFrameworkListControl.Reset(); this.frameworkListControl.Reset(); HollowHighlightDriver.GetDefaultInstance().Clear(); if (this.DataContext != null) { var list = this.DataContext.GetRuleResultsViewModelList(); SetRuleResults(list); if (list != null) { var ha = ImageOverlayDriver.GetDefaultInstance(); ha.SetImageElement(ElementContext.Id); if (HighlightVisibility) { ha.Show(); } } Dispatcher.Invoke(() => { nonFrameworkListControl.CheckAllBoxes(); frameworkListControl.CheckAllBoxes(); }, DispatcherPriority.Input); } }
/// Automated Checks mode is shown public void Show() { var ha = ImageOverlayDriver.GetDefaultInstance(); // set handler here. it will make sure that highliter button is shown and working. ha.SetHighlighterButtonClickHandler(TBElem_Click); if (this.HighlightVisibility) { ha.Show(); foreach (var svm in SelectedItems) { ha.AddElement(this.ElementContext.Id, svm.Element.UniqueId); } /// Only activate the main window if tests have already been run. This ensures we don't lose transient UI. /// We need to activate the window so that keyboard focus isn't lost when switching from Tab Stops to /// Automated Checks. if (this.ElementContext != null) { Application.Current.MainWindow.Activate(); } } }
/// <summary> /// Bring app back to selecting State /// </summary> public void HandleBackToSelectingState() { // if coming from startup, restore left nav bar if (this.CurrentPage == AppPage.Start) { this.bdLeftNav.IsEnabled = true; this.gdModes.Visibility = Visibility.Visible; this.btnPause.Visibility = Visibility.Visible; } // clear selected element highliter HollowHighlightDriver.GetInstance(HighlighterType.Selected).Clear(); ImageOverlayDriver.ClearDefaultInstance(); // this can be disabled if previous action was loading old data format. // bring it back to enabled state. this.btnHilighter.IsEnabled = true; // since we comes back to live mode, enable highlighter by default. SelectAction.GetDefaultInstance().ClearSelectedContext(); // turn highlighter on once you get back to selection mode. SetHighlightBtnState(true); var highlightDriver = HollowHighlightDriver.GetDefaultInstance(); highlightDriver.HighlighterMode = ConfigurationManager.GetDefaultInstance().AppConfig.HighlighterMode; highlightDriver.IsEnabled = true; highlightDriver.SetElement(null); /// make sure that all Mode UIs are clean since new selection will be done. CleanUpAllModeUIs(); #pragma warning disable CA1508 // Dead code warning doesn't apply here if (this.CurrentPage == AppPage.Start || (this.CurrentPage == AppPage.CCA) || (this.CurrentPage == AppPage.Test) || (this.CurrentPage == AppPage.Inspect && this.CurrentView != InspectView.Live) || (this.CurrentPage == AppPage.Events) || (this.CurrentPage == AppPage.Inspect && SelectAction.GetDefaultInstance().IsPaused)) { SelectAction.GetDefaultInstance().Scope = ConfigurationManager.GetDefaultInstance().AppConfig.IsUnderElementScope ? Axe.Windows.Actions.Enums.SelectionScope.Element : Axe.Windows.Actions.Enums.SelectionScope.App; cbSelectionScope.SelectedIndex = (SelectAction.GetDefaultInstance().Scope == Axe.Windows.Actions.Enums.SelectionScope.Element) ? 0 : 1; StartInspectMode(InspectView.Live); // clean up data when we get back to selection mode. this.CurrentPage = AppPage.Inspect; this.CurrentView = InspectView.Live; } #pragma warning restore CA1508 // Dead code warning doesn't apply here // garbage collection for any UI elements GC.Collect(); // enable element selector EnableElementSelector(); // if it was open when the switch back button is clicked. HideConfigurationMode(); UpdateMainWindowUI(); }
/// <summary> /// Clears listview /// </summary> public void ClearUI() { ImageOverlayDriver.ClearDefaultInstance(); this.ElementContext = null; this.lvResults.ItemsSource = null; this.tbGlimpse.Text = Properties.Resources.GlimpseTextTarget; this.gdFailures.Visibility = Visibility.Collapsed; this.SelectedItems.Clear(); }
/// <summary> /// Clears listview /// </summary> public void ClearUI() { ImageOverlayDriver.ClearDefaultInstance(); this.ElementContext = null; this.nonFrameworkListControl.Reset(); this.frameworkListControl.Reset(); this.tbGlimpse.Text = Properties.Resources.GlimpseTextTarget; this.gdFailures.Visibility = Visibility.Collapsed; }
/// <summary> /// Refresh /// </summary> public void Refresh() { // data will be asked to be captured again. so set the CurrentView right. MainWin.SetCurrentViewAndUpdateUI(TestView.CapturingData); ImageOverlayDriver.ClearDefaultInstance(); var ecId = SelectAction.GetDefaultInstance().GetSelectedElementContextId().Value; SetDataAction.ReleaseDataContext(ecId); #pragma warning disable CS4014 // NOTE: We aren't awaiting this async call, so if you // touch it, consider if you need to add the await this.SetElement(ecId); #pragma warning restore CS4014 }
/// <summary> /// Sets element context and updates UI /// </summary> public void SetElement(ElementContext ec) { if (ec == null) { throw new ArgumentNullException(nameof(ec)); } try { // set handler here. it will make sure that highliter button is shown and working. ImageOverlayDriver.GetDefaultInstance().SetHighlighterButtonClickHandler(TBElem_Click); if (this.ElementContext == null || ec.Element != this.ElementContext.Element || this.DataContext != ec.DataContext) { var controlContext = new AutomatedChecksCustomListControlContext(ec, NotifyElementSelected, SwitchToServerLogin); this.nonFrameworkListControl.SetControlContext(controlContext); this.frameworkListControl.SetControlContext(controlContext); this.nonFrameworkListControl.SetItemsSource(null); this.frameworkListControl.SetItemsSource(null); this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.DataContext = ec.DataContext; this.ElementContext = ec; this.tbGlimpse.Text = string.Format(CultureInfo.InvariantCulture, Properties.Resources.AutomatedChecksControl_TargetFormat, ec.Element.Glimpse); UpdateUI(); } } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); } #pragma warning restore CA1031 // Do not catch general exception types }
/// <summary> /// Sets element context and updates UI /// </summary> /// <param name="ec"></param> public void SetElement(ElementContext ec) { try { // set handler here. it will make sure that highliter button is shown and working. ImageOverlayDriver.GetDefaultInstance().SetHighlighterButtonClickHandler(TBElem_Click); if (this.ElementContext == null || ec.Element != this.ElementContext.Element || this.DataContext != ec.DataContext) { this.lblCongrats.Visibility = Visibility.Collapsed; this.lblNoFail.Visibility = Visibility.Collapsed; this.gdFailures.Visibility = Visibility.Collapsed; this.DataContext = ec.DataContext; this.chbxSelectAll.IsEnabled = ScreenshotAvailable; this.lvResults.ItemsSource = null; this.ElementContext = ec; this.tbGlimpse.Text = "Target: " + ec.Element.Glimpse; UpdateUI(); } } catch (Exception) { } }
/// <summary> /// Automated Checks mode is left /// </summary> public static void Hide() { ImageOverlayDriver.GetDefaultInstance().ClearElements(); }
/// <summary> /// Update Element Info UI(Properties/Patterns/Tests) /// </summary> /// <param name="ecId"></param> public async Task SetElement(Guid ecId) { this.ctrlProgressRing.Activate(); EnableMenuButtons(this.DataContextMode != DataContextMode.Load); bool selectionFailure = false; try { this.ctrlHierarchy.IsEnabled = false; ElementContext ec = null; await Task.Run(() => { CaptureAction.SetTestModeDataContext(ecId, this.DataContextMode, Configuration.TreeViewMode); ec = GetDataAction.GetElementContext(ecId); // send telemetry of scan results. var dc = GetDataAction.GetElementDataContext(ecId); dc.PublishScanResults(); }).ConfigureAwait(false); Application.Current.Dispatcher.Invoke(() => { if (ec != null && ec.DataContext != null) { this.ElementContext = ec; this.ctrlTabs.Clear(); if (!SelectAction.GetDefaultInstance().IsPaused) { this.ctrlHierarchy.CleanUpTreeView(); } this.ctrlHierarchy.SetElement(ec); this.ctrlTabs.SetElement(ec.Element, false, ec.Id); if (ec.DataContext.Screenshot == null && ec.DataContext.Mode != DataContextMode.Load) { Application.Current.MainWindow.WindowStyle = WindowStyle.ToolWindow; Application.Current.MainWindow.Visibility = Visibility.Hidden; HollowHighlightDriver.GetDefaultInstance().IsEnabled = false; this.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(() => { ScreenShotAction.CaptureScreenShot(ecId); Application.Current.MainWindow.Visibility = Visibility.Visible; Application.Current.MainWindow.WindowStyle = WindowStyle.SingleBorderWindow; })).Wait(); } var imageOverlay = ImageOverlayDriver.GetDefaultInstance(); imageOverlay.SetImageElement(ecId); //disable button on highlighter. imageOverlay.SetHighlighterButtonClickHandler(null); if (Configuration.IsHighlighterOn) { imageOverlay.Show(); } } // if it is enforced to select a specific element(like fastpass click case) if (ec.DataContext.FocusedElementUniqueId.HasValue) { this.ctrlHierarchy.SelectElement(ec.DataContext.FocusedElementUniqueId.Value); } if (!ec.DataContext.Elements.TryGetValue(ec.DataContext.FocusedElementUniqueId ?? 0, out A11yElement selectedElement)) { selectedElement = ec.DataContext.Elements[0]; } AutomationProperties.SetName(this, string.Format(CultureInfo.InvariantCulture, Properties.Resources.SetElementInspectTestDetail, selectedElement.Glimpse)); FireAsyncContentLoadedEvent(AsyncContentLoadedState.Completed); // Set focus on hierarchy tree Dispatcher.InvokeAsync(() => this.ctrlHierarchy.SetFocusOnHierarchyTree(), DispatcherPriority.Input).Wait(); ec.DataContext.FocusedElementUniqueId = null; }); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception e) { e.ReportException(); Application.Current.Dispatcher.Invoke(() => { Application.Current.MainWindow.Visibility = Visibility.Visible; EnableMenuButtons(false); this.ElementContext = null; selectionFailure = true; }); } #pragma warning restore CA1031 // Do not catch general exception types finally { Application.Current.Dispatcher.Invoke(() => { this.ctrlProgressRing.Deactivate(); this.ctrlHierarchy.IsEnabled = true; // if focus has gone to the window, we set focus to the hierarchy control. We do this because disabling the hierarchy control // will throw keyboard focus to mainwindow, where it is not very useful. if (Keyboard.FocusedElement is Window) { this.ctrlHierarchy.Focus(); } if (selectionFailure) { MainWin.HandleFailedSelectionReset(); } else { // Set the right view state : if (MainWin.CurrentView is TestView iv && iv == TestView.ElementHowToFix) { MainWin.SetCurrentViewAndUpdateUI(TestView.ElementHowToFix); }