@@ -6,13 +6,28 @@ namespace GitHub.Unity
6
6
{
7
7
abstract class BaseWindow : EditorWindow , IView
8
8
{
9
- private bool finishCalled = false ;
9
+ [ NonSerialized ] private bool finishCalled = false ;
10
+ [ NonSerialized ] private bool initialized = false ;
11
+
12
+ [ NonSerialized ] private IApplicationManager cachedManager ;
13
+ [ NonSerialized ] private bool initializeWasCalled ;
14
+ [ NonSerialized ] private bool inLayout ;
10
15
11
16
public event Action < bool > OnClose ;
12
17
13
18
public virtual void Initialize ( IApplicationManager applicationManager )
14
19
{
20
+ Debug . Log ( "Initialize " + applicationManager + " " + initialized ) ;
21
+
22
+ if ( inLayout )
23
+ {
24
+ initializeWasCalled = true ;
25
+ cachedManager = applicationManager ;
26
+ return ;
27
+ }
28
+
15
29
Manager = applicationManager ;
30
+ initialized = true ;
16
31
}
17
32
18
33
public virtual void Redraw ( )
@@ -23,6 +38,7 @@ public virtual void Redraw()
23
38
public virtual void Refresh ( )
24
39
{
25
40
}
41
+
26
42
public virtual void Finish ( bool result )
27
43
{
28
44
finishCalled = true ;
@@ -36,36 +52,67 @@ protected void RaiseOnClose(bool result)
36
52
37
53
public virtual void Awake ( )
38
54
{
55
+ Debug . Log ( "Awake " + initialized ) ;
56
+ if ( ! initialized )
57
+ Initialize ( EntryPoint . ApplicationManager ) ;
39
58
}
40
59
41
60
public virtual void OnEnable ( )
42
61
{
62
+ Debug . Log ( "OnEnable " + initialized ) ;
63
+ if ( ! initialized )
64
+ Initialize ( EntryPoint . ApplicationManager ) ;
43
65
}
44
66
45
- public virtual void OnDisable ( )
67
+ public virtual void OnDisable ( ) { }
68
+
69
+ public virtual void Update ( ) { }
70
+
71
+ // OnGUI calls this everytime, so override it to render as you would OnGUI
72
+ public virtual void OnUI ( ) { }
73
+
74
+ // This is Unity's magic method
75
+ private void OnGUI ( )
46
76
{
77
+ if ( Event . current . type == EventType . layout )
78
+ {
79
+ inLayout = true ;
80
+ }
81
+
82
+ Debug . LogFormat ( "OnGUI initialize?{0} inLayout?{1} initializeWasCalled?{2}" , initialized , inLayout , initializeWasCalled ) ;
83
+
84
+ OnUI ( ) ;
85
+
86
+ if ( Event . current . type == EventType . repaint )
87
+ {
88
+ inLayout = false ;
89
+ if ( initializeWasCalled )
90
+ {
91
+ initializeWasCalled = false ;
92
+ Initialize ( cachedManager ) ;
93
+ }
94
+ }
47
95
}
48
96
49
- public virtual void Update ( ) { }
50
- public virtual void OnGUI ( ) { }
51
97
public virtual void OnDestroy ( )
52
98
{
53
99
if ( ! finishCalled )
54
100
{
55
101
RaiseOnClose ( false ) ;
56
102
}
57
-
58
103
}
104
+
59
105
public virtual void OnSelectionChange ( )
60
106
{ }
61
107
62
108
public virtual Rect Position { get { return position ; } }
109
+
63
110
public IApplicationManager Manager { get ; private set ; }
64
- public IRepository Repository { get { return Manager != null ? Manager . Environment . Repository : null ; } }
65
- public ITaskManager TaskManager { get { return Manager != null ? Manager . TaskManager : null ; } }
66
- protected IGitClient GitClient { get { return Manager != null ? Manager . GitClient : null ; } }
67
- protected IEnvironment Environment { get { return Manager != null ? Manager . Environment : null ; } }
68
- protected IPlatform Platform { get { return Manager != null ? Manager . Platform : null ; } }
111
+ public IRepository Repository { get { return Environment . Repository ; } }
112
+ public ITaskManager TaskManager { get { return Manager . TaskManager ; } }
113
+ protected IGitClient GitClient { get { return Manager . GitClient ; } }
114
+ protected IEnvironment Environment { get { return Manager . Environment ; } }
115
+ protected IPlatform Platform { get { return Manager . Platform ; } }
69
116
70
117
71
118
private ILogging logger ;
@@ -86,24 +133,17 @@ abstract class Subview : IView
86
133
87
134
private const string NullParentError = "Subview parent is null" ;
88
135
protected IView Parent { get ; private set ; }
89
- public IApplicationManager Manager { get ; private set ; }
90
- public IRepository Repository { get { return Manager != null ? Manager . Environment . Repository : null ; } }
91
- public ITaskManager TaskManager { get { return Manager != null ? Manager . TaskManager : null ; } }
92
- protected IGitClient GitClient { get { return Manager != null ? Manager . GitClient : null ; } }
93
- protected IEnvironment Environment { get { return Manager != null ? Manager . Environment : null ; } }
94
- protected IPlatform Platform { get { return Manager != null ? Manager . Platform : null ; } }
95
-
96
- public virtual void Initialize ( IApplicationManager applicationManager )
97
- {
98
- Logger . Trace ( "Initialize(IApplicationManager: {0})" , applicationManager != null ) ;
99
- Manager = applicationManager ;
100
- }
136
+ public IApplicationManager Manager { get { return Parent . Manager ; } }
137
+ public IRepository Repository { get { return Manager . Environment . Repository ; } }
138
+ public ITaskManager TaskManager { get { return Manager . TaskManager ; } }
139
+ protected IGitClient GitClient { get { return Manager . GitClient ; } }
140
+ protected IEnvironment Environment { get { return Manager . Environment ; } }
141
+ protected IPlatform Platform { get { return Manager . Platform ; } }
101
142
102
143
public virtual void InitializeView ( IView parent )
103
144
{
104
145
Debug . Assert ( parent != null , NullParentError ) ;
105
146
Parent = parent ;
106
- ( ( IView ) this ) . Initialize ( parent . Manager ) ;
107
147
}
108
148
109
149
public virtual void OnShow ( )
0 commit comments