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

Commit

Permalink
Merge pull request #87 from github-for-unity/fixes/refactor-view
Browse files Browse the repository at this point in the history
Refactoring BaseWindow and Subview to better handle initialization
  • Loading branch information
shana authored Jul 5, 2017
2 parents 9c57623 + e280096 commit e659480
Show file tree
Hide file tree
Showing 12 changed files with 167 additions and 153 deletions.
10 changes: 4 additions & 6 deletions src/GitHub.Api/Application/ApplicationManagerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,13 @@ public void Dispose()
public CancellationToken CancellationToken { get { return TaskManager.Token; } }
public ITaskManager TaskManager { get; protected set; }
public IGitClient GitClient { get; protected set; }


protected TaskScheduler UIScheduler { get; private set; }
protected SynchronizationContext SynchronizationContext { get; private set; }
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }

public ISettings LocalSettings { get; protected set; }
public ISettings SystemSettings { get; protected set; }
public ISettings UserSettings { get; protected set; }
public IUsageTracker UsageTracker { get; protected set; }

protected TaskScheduler UIScheduler { get; private set; }
protected SynchronizationContext SynchronizationContext { get; private set; }
protected IRepositoryManager RepositoryManager { get { return repositoryManager; } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public ApplicationManager(IMainThreadSynchronizationContext synchronizationConte

protected override void SetupMetrics()
{

new ActionTask(CancellationToken,
() => SetupMetrics(Environment.UnityVersion, ApplicationCache.Instance.FirstRun))
{ Affinity = TaskAffinity.UI }
Expand All @@ -33,7 +34,7 @@ protected override void InitializeUI()
{
Logger.Trace("Restarted {0}", Environment.Repository);
ProjectWindowInterface.Initialize(Environment.Repository);
var view = Window.GetView();
var view = Window.GetWindow();
if (view != null)
view.Initialize(this);
}
Expand Down
3 changes: 1 addition & 2 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ namespace GitHub.Unity
[InitializeOnLoad]
class EntryPoint : ScriptableObject
{
private static ApplicationManager appManager;

// this may run on the loader thread if it's an appdomain restart
static EntryPoint()
{
Expand Down Expand Up @@ -69,6 +67,7 @@ private static bool ServerCertificateValidationCallback(object sender, X509Certi
return true;
}

private static ApplicationManager appManager;
public static IApplicationManager ApplicationManager
{
get
Expand Down
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 OnGUI()
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
19 changes: 7 additions & 12 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,14 @@ class HistoryView : Subview
[SerializeField] private List<GitLogEntry> history = new List<GitLogEntry>();
[SerializeField] private bool isBusy;

public override void Initialize(IApplicationManager applicationManager)
public override void InitializeView(IView parent)
{
base.Initialize(applicationManager);
base.InitializeView(parent);

if (Manager != null)
{
UpdateLog();
}
}

public override void InitializeView(IView parent)
{
Logger.Trace("InitializeView(IView)");
base.InitializeView(parent);

lastWidth = Position.width;
selectionIndex = newSelectionIndex = -1;
Expand All @@ -86,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 @@ -97,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
3 changes: 2 additions & 1 deletion src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace GitHub.Unity
{
interface IView
{
void Initialize(IApplicationManager applicationManager);
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
Loading

0 comments on commit e659480

Please sign in to comment.