From 31cffae691be9a15b7a2a1902f9ed36dc09f065d Mon Sep 17 00:00:00 2001 From: Adreia Gaita Date: Mon, 3 Jul 2017 16:11:21 -0400 Subject: [PATCH 1/3] Cherry picking refactoring to Window subsystem --- .../Application/ApplicationManagerBase.cs | 10 +- .../Editor/GitHub.Unity/ApplicationManager.cs | 3 +- .../Assets/Editor/GitHub.Unity/EntryPoint.cs | 3 +- .../GitHub.Unity/UI/AuthenticationWindow.cs | 2 +- .../Editor/GitHub.Unity/UI/HistoryView.cs | 11 +- .../Assets/Editor/GitHub.Unity/UI/IView.cs | 1 - .../Assets/Editor/GitHub.Unity/UI/Subview.cs | 86 ++++++++++---- .../Assets/Editor/GitHub.Unity/UI/Window.cs | 110 +++++++++--------- 8 files changed, 128 insertions(+), 98 deletions(-) diff --git a/src/GitHub.Api/Application/ApplicationManagerBase.cs b/src/GitHub.Api/Application/ApplicationManagerBase.cs index 34c2fa9bc..c8a9c8302 100644 --- a/src/GitHub.Api/Application/ApplicationManagerBase.cs +++ b/src/GitHub.Api/Application/ApplicationManagerBase.cs @@ -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; } } } } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs index f8e636ad2..aa096fb93 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/ApplicationManager.cs @@ -23,6 +23,7 @@ public ApplicationManager(IMainThreadSynchronizationContext synchronizationConte protected override void SetupMetrics() { + new ActionTask(CancellationToken, () => SetupMetrics(Environment.UnityVersion, ApplicationCache.Instance.FirstRun)) { Affinity = TaskAffinity.UI } @@ -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); } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs index e64141314..323308227 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/EntryPoint.cs @@ -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() { @@ -69,6 +67,7 @@ private static bool ServerCertificateValidationCallback(object sender, X509Certi return true; } + private static ApplicationManager appManager; public static IApplicationManager ApplicationManager { get diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs index fbfbb6fc8..57e908de3 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs @@ -27,7 +27,7 @@ public static IView Open(Action onClose = null) return authWindow; } - public override void OnGUI() + public override void OnUI() { if (authView == null) { diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 5c711e580..7452d7e3a 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -59,19 +59,14 @@ class HistoryView : Subview [SerializeField] private List history = new List(); [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; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs index fdca7162e..d525f5b91 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs @@ -5,7 +5,6 @@ namespace GitHub.Unity { interface IView { - void Initialize(IApplicationManager applicationManager); void Refresh(); void Redraw(); Rect Position { get; } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs index 2494756ef..fb2f4104a 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs @@ -6,13 +6,28 @@ namespace GitHub.Unity { abstract class BaseWindow : EditorWindow, IView { - private bool finishCalled = false; + [NonSerialized] private bool finishCalled = false; + [NonSerialized] private bool initialized = false; + + [NonSerialized] private IApplicationManager cachedManager; + [NonSerialized] private bool initializeWasCalled; + [NonSerialized] private bool inLayout; public event Action OnClose; public virtual void Initialize(IApplicationManager applicationManager) { + Debug.Log("Initialize " + applicationManager + " " + initialized); + + if (inLayout) + { + initializeWasCalled = true; + cachedManager = applicationManager; + return; + } + Manager = applicationManager; + initialized = true; } public virtual void Redraw() @@ -23,6 +38,7 @@ public virtual void Redraw() public virtual void Refresh() { } + public virtual void Finish(bool result) { finishCalled = true; @@ -36,36 +52,67 @@ protected void RaiseOnClose(bool result) public virtual void Awake() { + Debug.Log("Awake " + initialized); + if (!initialized) + Initialize(EntryPoint.ApplicationManager); } public virtual void OnEnable() { + Debug.Log("OnEnable " + initialized); + if (!initialized) + Initialize(EntryPoint.ApplicationManager); } - public virtual void OnDisable() + public virtual void OnDisable() {} + + public virtual void Update() {} + + // OnGUI calls this everytime, so override it to render as you would OnGUI + public virtual void OnUI() {} + + // This is Unity's magic method + private void OnGUI() { + if (Event.current.type == EventType.layout) + { + inLayout = true; + } + + Debug.LogFormat("OnGUI initialize?{0} inLayout?{1} initializeWasCalled?{2}", initialized, inLayout, initializeWasCalled); + + OnUI(); + + if (Event.current.type == EventType.repaint) + { + inLayout = false; + if (initializeWasCalled) + { + initializeWasCalled = false; + Initialize(cachedManager); + } + } } - public virtual void Update() {} - public virtual void OnGUI() {} public virtual void OnDestroy() { if (!finishCalled) { RaiseOnClose(false); } - } + public virtual void OnSelectionChange() {} public virtual Rect Position { get { return position; } } + public IApplicationManager Manager { get; private set; } - public IRepository Repository { get { return Manager != null ? Manager.Environment.Repository : null; } } - public ITaskManager TaskManager { get { return Manager != null ? Manager.TaskManager : null; } } - protected IGitClient GitClient { get { return Manager != null ? Manager.GitClient : null; } } - protected IEnvironment Environment { get { return Manager != null ? Manager.Environment : null; } } - protected IPlatform Platform { get { return Manager != null ? Manager.Platform : null; } } + public IRepository Repository { get { return Environment.Repository; } } + public ITaskManager TaskManager { get { return Manager.TaskManager; } } + protected IGitClient GitClient { get { return Manager.GitClient; } } + protected IEnvironment Environment { get { return Manager.Environment; } } + protected IPlatform Platform { get { return Manager.Platform; } } private ILogging logger; @@ -86,24 +133,17 @@ abstract class Subview : IView private const string NullParentError = "Subview parent is null"; protected IView Parent { get; private set; } - public IApplicationManager Manager { get; private set; } - public IRepository Repository { get { return Manager != null ? Manager.Environment.Repository : null; } } - public ITaskManager TaskManager { get { return Manager != null ? Manager.TaskManager : null; } } - protected IGitClient GitClient { get { return Manager != null ? Manager.GitClient : null; } } - protected IEnvironment Environment { get { return Manager != null ? Manager.Environment : null; } } - protected IPlatform Platform { get { return Manager != null ? Manager.Platform : null; } } - - public virtual void Initialize(IApplicationManager applicationManager) - { - Logger.Trace("Initialize(IApplicationManager: {0})", applicationManager != null); - Manager = applicationManager; - } + public IApplicationManager Manager { get { return Parent.Manager; } } + public IRepository Repository { get { return Manager.Environment.Repository; } } + public ITaskManager TaskManager { get { return Manager.TaskManager; } } + protected IGitClient GitClient { get { return Manager.GitClient; } } + protected IEnvironment Environment { get { return Manager.Environment; } } + protected IPlatform Platform { get { return Manager.Platform; } } public virtual void InitializeView(IView parent) { Debug.Assert(parent != null, NullParentError); Parent = parent; - ((IView)this).Initialize(parent.Manager); } public virtual void OnShow() diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index da7723368..14a7519ce 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -57,9 +57,20 @@ public static void ShowWindow(IApplicationManager applicationManager) window.Show(); } - public static IView GetView() + public static Window GetWindow() { - return Resources.FindObjectsOfTypeAll(typeof(Window)).FirstOrDefault() as IView; + return Resources.FindObjectsOfTypeAll(typeof(Window)).FirstOrDefault() as Window; + } + + public override void Initialize(IApplicationManager applicationManager) + { + base.Initialize(applicationManager); + + HistoryTab.InitializeView(this); + ChangesTab.InitializeView(this); + BranchesTab.InitializeView(this); + SettingsTab.InitializeView(this); + ActiveTab.InitializeView(this); } public override void OnEnable() @@ -72,37 +83,15 @@ public override void OnEnable() // Set window title titleContent = new GUIContent(Title, Styles.SmallLogo); - - historyTab.InitializeView(this); - changesTab.InitializeView(this); - branchesTab.InitializeView(this); - settingsTab.InitializeView(this); } public override void Refresh() { + base.Refresh(); if (ActiveTab != null) ActiveTab.Refresh(); } - 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(); - Refresh(); - } - public override void OnDisable() { base.OnDisable(); @@ -111,10 +100,9 @@ public override void OnDisable() ActiveTab.OnHide(); } - - public override void OnGUI() + public override void OnUI() { - base.OnGUI(); + base.OnUI(); if (Repository != null) { @@ -130,6 +118,44 @@ public override void OnGUI() } } + public override void Update() + { + base.Update(); + + // Notification auto-clear timer override + if (notificationClearTime > 0f && EditorApplication.timeSinceStartup > notificationClearTime) + { + notificationClearTime = -1f; + RemoveNotification(); + Redraw(); + } + } + + 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(); + Refresh(); + } + private void DoHeaderGUI() { GUILayout.BeginHorizontal(Styles.HeaderBoxStyle); @@ -253,17 +279,6 @@ private bool ValidateSettings() return true; } - public override void Update() - { - // Notification auto-clear timer override - if (notificationClearTime > 0f && EditorApplication.timeSinceStartup > notificationClearTime) - { - notificationClearTime = -1f; - RemoveNotification(); - Redraw(); - } - } - public new void ShowNotification(GUIContent content) { ShowNotification(content, DefaultNotificationTimeout); @@ -282,12 +297,6 @@ private static SubTab TabButton(SubTab tab, string title, SubTab activeTab) return GUILayout.Toggle(activeTab == tab, title, EditorStyles.toolbarButton) ? tab : activeTab; } - public override void OnSelectionChange() - { - if (ActiveTab != null) - ActiveTab.OnSelectionChange(); - } - public HistoryView HistoryTab { get { return historyTab; } @@ -339,16 +348,5 @@ private enum SubTab Branches, Settings } - - public override void Initialize(IApplicationManager applicationManager) - { - base.Initialize(applicationManager); - - HistoryTab.InitializeView(this); - ChangesTab.InitializeView(this); - BranchesTab.InitializeView(this); - SettingsTab.InitializeView(this); - ActiveTab.InitializeView(this); - } } } From 7852b1d9bdcc6ee38be5815c48687d076a7fc00d Mon Sep 17 00:00:00 2001 From: Stanley Goldman Date: Mon, 3 Jul 2017 16:39:28 -0400 Subject: [PATCH 2/3] Tweaking log messages --- .../Assets/Editor/GitHub.Unity/UI/Subview.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs index fb2f4104a..3c77cf0d9 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs @@ -17,7 +17,7 @@ abstract class BaseWindow : EditorWindow, IView public virtual void Initialize(IApplicationManager applicationManager) { - Debug.Log("Initialize " + applicationManager + " " + initialized); + Logger.Trace("Initialize ApplicationManager:{0} Initialized:{1}", applicationManager, initialized); if (inLayout) { @@ -52,14 +52,14 @@ protected void RaiseOnClose(bool result) public virtual void Awake() { - Debug.Log("Awake " + initialized); + Logger.Trace("Awake Initialized:{0}", initialized); if (!initialized) Initialize(EntryPoint.ApplicationManager); } public virtual void OnEnable() { - Debug.Log("OnEnable " + initialized); + Logger.Trace("OnEnable Initialized:{0}", initialized); if (!initialized) Initialize(EntryPoint.ApplicationManager); } @@ -79,8 +79,6 @@ private void OnGUI() inLayout = true; } - Debug.LogFormat("OnGUI initialize?{0} inLayout?{1} initializeWasCalled?{2}", initialized, inLayout, initializeWasCalled); - OnUI(); if (Event.current.type == EventType.repaint) From e280096ddbe5a6ca846c6d3553566d88050efbe1 Mon Sep 17 00:00:00 2001 From: Andreia Gaita Date: Wed, 5 Jul 2017 15:10:31 +0200 Subject: [PATCH 3/3] Make the view methods more consistent, and make sure all windows call 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. --- .../GitHub.Unity/UI/AuthenticationView.cs | 8 ++-- .../GitHub.Unity/UI/AuthenticationWindow.cs | 46 +++++++++---------- .../Editor/GitHub.Unity/UI/BranchesView.cs | 8 ++-- .../Editor/GitHub.Unity/UI/ChangesView.cs | 8 ++-- .../Editor/GitHub.Unity/UI/HistoryView.cs | 8 ++-- .../Assets/Editor/GitHub.Unity/UI/IView.cs | 2 + .../Editor/GitHub.Unity/UI/SettingsView.cs | 8 ++-- .../Assets/Editor/GitHub.Unity/UI/Subview.cs | 15 ++---- .../Assets/Editor/GitHub.Unity/UI/Window.cs | 43 ++++++++--------- 9 files changed, 66 insertions(+), 80 deletions(-) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs index bbd8282f7..bded38e4e 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs @@ -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() diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs index 57e908de3..18fe1b32c 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationWindow.cs @@ -27,45 +27,45 @@ public static IView Open(Action 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) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs index 4ce7c2a5f..385badde2 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/BranchesView.cs @@ -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; @@ -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; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs index 9830b7059..e9e847c51 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/ChangesView.cs @@ -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; @@ -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; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs index 7452d7e3a..57d801d60 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs @@ -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; @@ -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; diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs index d525f5b91..f04d0e909 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/IView.cs @@ -5,6 +5,8 @@ namespace GitHub.Unity { interface IView { + void OnEnable(); + void OnDisable(); void Refresh(); void Redraw(); Rect Position { get; } diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs index 6637ebcdd..93320e21b 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs @@ -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; @@ -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 locks) diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs index 3c77cf0d9..0657443a7 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs @@ -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 { @@ -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() diff --git a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs index 14a7519ce..f8c0c9eea 100644 --- a/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs +++ b/src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs @@ -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() @@ -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(); }