Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
Make the view methods more consistent, and make sure all windows call…
Browse files Browse the repository at this point in the history
… into them

Use OnEnable/OnDisable instead of OnShow/OnHide, it's more consistent with Unity's
naming and our own window class.

AuthenticationView was missing some calls from the window, fixicate.
  • Loading branch information
shana committed Jul 5, 2017
1 parent dc885e3 commit e280096
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ public override void InitializeView(IView parent)
need2fa = busy = false;
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
}

public override void OnGUI()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,45 @@ public static IView Open(Action<bool> onClose = null)
return authWindow;
}

public override void OnUI()
public override void Initialize(IApplicationManager applicationManager)
{
base.Initialize(applicationManager);
if (authView == null)
{
CreateViews();
}
authView.OnGUI();
}

public override void Refresh()
{
authView.Refresh();
authView = new AuthenticationView();
authView.InitializeView(this);
}

public override void OnEnable()
{
base.OnEnable();

// Set window title
titleContent = new GUIContent(Title, Styles.SmallLogo);
authView.OnEnable();
}

Utility.UnregisterReadyCallback(CreateViews);
Utility.RegisterReadyCallback(CreateViews);

Utility.UnregisterReadyCallback(ShowActiveView);
Utility.RegisterReadyCallback(ShowActiveView);
public override void OnDisable()
{
base.OnDisable();
authView.OnDisable();
}

private void CreateViews()
public override void OnUI()
{
if (authView == null)
authView = new AuthenticationView();
base.OnUI();
authView.OnGUI();
}

Initialize(EntryPoint.ApplicationManager);
authView.InitializeView(this);
public override void Refresh()
{
base.Refresh();
authView.Refresh();
}

private void ShowActiveView()
public override void OnSelectionChange()
{
authView.OnShow();
Refresh();
base.OnSelectionChange();
authView.OnSelectionChange();
}

public override void Finish(bool result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ public override void InitializeView(IView parent)
targetMode = mode;
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository != null)
{
Repository.OnLocalBranchListChanged += RunRefreshEmbeddedOnMainThread;
Expand All @@ -55,9 +55,9 @@ public override void OnShow()
}
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository != null)
{
Repository.OnLocalBranchListChanged -= RunRefreshEmbeddedOnMainThread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public override void InitializeView(IView parent)
tree.InitializeView(this);
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository == null)
return;

Expand All @@ -44,9 +44,9 @@ public override void OnShow()
Repository.Refresh();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository == null)
return;
Repository.OnRepositoryChanged -= RunStatusUpdateOnMainThread;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public override void InitializeView(IView parent)
}
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository != null)
{
Repository.OnCommitChanged += UpdateLogOnMainThread;
Expand All @@ -92,9 +92,9 @@ public override void OnShow()
UpdateLog();
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
if (Repository != null)
{
Repository.OnCommitChanged -= UpdateLogOnMainThread;
Expand Down
2 changes: 2 additions & 0 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace GitHub.Unity
{
interface IView
{
void OnEnable();
void OnDisable();
void Refresh();
void Redraw();
Rect Position { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ private void Repository_OnActiveRemoteChanged(string remote)
repositoryRemoteUrl = currentRemote.Value.Url;
}

public override void OnShow()
public override void OnEnable()
{
base.OnShow();
base.OnEnable();
if (Repository == null)
return;

Expand All @@ -140,9 +140,9 @@ public override void OnShow()
gitEmail = Repository.User.Email;
}

public override void OnHide()
public override void OnDisable()
{
base.OnHide();
base.OnDisable();
}

private void RunLocksUpdateOnMainThread(IEnumerable<GitLock> locks)
Expand Down
15 changes: 3 additions & 12 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ public virtual void OnSelectionChange()
protected IEnvironment Environment { get { return Manager.Environment; } }
protected IPlatform Platform { get { return Manager.Platform; } }


private ILogging logger;
protected ILogging Logger
{
Expand Down Expand Up @@ -144,21 +143,13 @@ public virtual void InitializeView(IView parent)
Parent = parent;
}

public virtual void OnShow()
{
}

public virtual void OnHide()
{
}

public virtual void OnUpdate()
public virtual void OnEnable()
{}

public virtual void OnGUI()
public virtual void OnDisable()
{}

public virtual void OnDestroy()
public virtual void OnGUI()
{}

public virtual void OnSelectionChange()
Expand Down
43 changes: 18 additions & 25 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,30 @@ public override void OnEnable()

// Set window title
titleContent = new GUIContent(Title, Styles.SmallLogo);
}

public override void Refresh()
{
base.Refresh();
if (ActiveTab != null)
ActiveTab.Refresh();
ActiveTab.OnEnable();
}

public override void OnDisable()
{
base.OnDisable();
if (ActiveTab != null)
ActiveTab.OnDisable();
}

public override void OnSelectionChange()
{
base.OnSelectionChange();
if (ActiveTab != null)
ActiveTab.OnHide();
ActiveTab.OnSelectionChange();
}

public override void Refresh()
{
base.Refresh();
if (ActiveTab != null)
ActiveTab.Refresh();
}

public override void OnUI()
Expand Down Expand Up @@ -131,28 +140,12 @@ public override void Update()
}
}

public override void OnSelectionChange()
{
base.OnSelectionChange();
if (ActiveTab != null)
ActiveTab.OnSelectionChange();
}

private void ShowActiveView()
{
if (Repository == null)
return;

if (ActiveTab != null)
ActiveTab.OnShow();
Refresh();
}

private void SwitchView(Subview from, Subview to)
{
GUI.FocusControl(null);
from.OnHide();
to.OnShow();
if (from != null)
from.OnDisable();
to.OnEnable();
Refresh();
}

Expand Down

0 comments on commit e280096

Please sign in to comment.