Skip to content

Commit

Permalink
Restore the UI state directly during Prepare() phase of the screen. T…
Browse files Browse the repository at this point in the history
…his avoids duplicated focus setting (MP2-373)
  • Loading branch information
morpheusxx committed Aug 19, 2013
1 parent 0abad0d commit ebcd672
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions MediaPortal/Source/UI/SkinEngine/ScreenManagement/Screen.cs
Expand Up @@ -95,6 +95,7 @@ public class Screen : UIElement, INameScope, IAddChild<FrameworkElement>, IUnmod
public const string VIRTUAL_KEYBOARD_DIALOG = "DialogVirtualKeyboard";

public const string SHOW_EVENT = "Screen.Show";
public const string PREPARE_EVENT = "Screen.Prepare";
public const string CLOSE_EVENT = "Screen.Hide";

/// <summary>
Expand Down Expand Up @@ -455,6 +456,11 @@ public void Prepare()
// Switch to "Running" state which builds the final screen structure
ScreenState = State.Running;
int maxNumUpdate = 10;

// This violates against MP2 multi threading guidelines, but is required to execute this synchronously i.e. to restore state information
// directly when the screen is created.
TriggerScreenPreparingEvent_Sync();

while ((_root.IsMeasureInvalid || _root.IsArrangeInvalid) && maxNumUpdate-- > 0)
{
SetValues();
Expand Down Expand Up @@ -710,6 +716,15 @@ public void TriggerScreenClosingEvent()
_closeTime = FindCloseEventCompletionTime().AddMilliseconds(20); // 20 more milliseconds because of the delay until the event is fired in render loop
}

/// <summary>
/// Fires the <see cref="PREPARE_EVENT"/>. In contrast to <see cref="TriggerScreenShowingEvent"/> and <see cref="TriggerScreenClosingEvent"/> this method
/// directly fires the event instead of executing it later (<see cref="_pendingScreenEvent"/>).
/// </summary>
public void TriggerScreenPreparingEvent_Sync()
{
DoFireScreenEvent(new PendingScreenEvent(PREPARE_EVENT, RoutingStrategyEnum.VisualTree));
}

protected void DoFireScreenEvent(PendingScreenEvent pendingScreenEvent)
{
FireEvent(pendingScreenEvent.EventName, pendingScreenEvent.RoutingStategy);
Expand Down
Expand Up @@ -71,12 +71,12 @@ public void DetachFromObject()

private void OnUIEventOccured(string eventname)
{
if (eventname != Screen.SHOW_EVENT && eventname != Screen.CLOSE_EVENT)
if (eventname != Screen.PREPARE_EVENT && eventname != Screen.CLOSE_EVENT)
return;
UIElement targetElement = _targetObject;
if (targetElement == null)
return;
if (eventname == Screen.SHOW_EVENT)
if (eventname == Screen.PREPARE_EVENT)
{
// Mapping of context variable name -> UI state
IDictionary<string, IDictionary<string, object>> state =
Expand Down

0 comments on commit ebcd672

Please sign in to comment.