Skip to content

Commit

Permalink
Merge pull request #51 from zebraxxl/feature/set-focus
Browse files Browse the repository at this point in the history
CruciatusElement.SetFocus support
  • Loading branch information
skyline-gleb committed Oct 16, 2015
2 parents c1eb4f0 + 1e800d8 commit 0707a1e
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Winium.Cruciatus/Elements/CruciatusElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,41 @@ public override int GetHashCode()
return this.Instance.GetHashCode();
}

/// <summary>
/// Устанавливает фокус на элементе.
/// Если элемент - окно и оно было свёрнуто, то разворачивает его.
/// </summary>
public void SetFocus()
{
if (!this.Instance.Current.IsEnabled)
{
Logger.Error("Element '{0}' not enabled. Set focus failed.", this.ToString());
CruciatusFactory.Screenshoter.AutomaticScreenshotCaptureIfNeeded();
throw new ElementNotEnabledException("NOT SET FOCUS");
}

if (this.Instance.Current.ControlType.Equals(ControlType.Window))
{
object windowPatternObject;
if (this.Instance.TryGetCurrentPattern(WindowPattern.Pattern, out windowPatternObject))
{
((WindowPattern)windowPatternObject).SetWindowVisualState(WindowVisualState.Normal);
return;
}
}

try
{
this.Instance.SetFocus();
}
catch (InvalidOperationException exception)
{
Logger.Error("Set focus on element '{0}' failed.", this.ToString());
Logger.Debug(exception);
throw new CruciatusException("NOT SET FOCUS");
}
}

/// <summary>
/// Установка текста.
/// </summary>
Expand Down

0 comments on commit 0707a1e

Please sign in to comment.