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

Commit 1ee80cb

Browse files
Moving BaseWindow to it's own file for clarity's sake
1 parent 3fdec18 commit 1ee80cb

File tree

3 files changed

+148
-142
lines changed

3 files changed

+148
-142
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/GitHub.Unity.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@
8484
<Compile Include="Logging\UnityLogAdapter.cs" />
8585
<Compile Include="EntryPoint.cs" />
8686
<Compile Include="Misc\Installer.cs" />
87+
<Compile Include="UI\BaseWindow.cs" />
8788
<Compile Include="UI\PublishWindow.cs" />
8889
<Compile Include="UI\ProjectWindowInterface.cs" />
8990
<Compile Include="Misc\Styles.cs" />
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
using System;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace GitHub.Unity
6+
{
7+
abstract class BaseWindow : EditorWindow, IView
8+
{
9+
[NonSerialized] private bool finishCalled = false;
10+
[NonSerialized] private bool initialized = false;
11+
12+
[NonSerialized] private IApplicationManager cachedManager;
13+
[NonSerialized] private IRepository cachedRepository;
14+
[NonSerialized] private bool initializeWasCalled;
15+
[NonSerialized] private bool inLayout;
16+
17+
public event Action<bool> OnClose;
18+
19+
public virtual void Initialize(IApplicationManager applicationManager)
20+
{
21+
Logger.Trace("Initialize ApplicationManager:{0} Initialized:{1}", applicationManager, initialized);
22+
}
23+
24+
public void InitializeWindow(IApplicationManager applicationManager)
25+
{
26+
if (inLayout)
27+
{
28+
initializeWasCalled = true;
29+
cachedManager = applicationManager;
30+
return;
31+
}
32+
33+
Manager = applicationManager;
34+
cachedRepository = Environment.Repository;
35+
initialized = true;
36+
Initialize(applicationManager);
37+
OnRepositoryChanged(null);
38+
Redraw();
39+
}
40+
41+
public virtual void Redraw()
42+
{
43+
Repaint();
44+
}
45+
46+
public virtual void Refresh()
47+
{
48+
Logger.Debug("Refresh");
49+
}
50+
51+
public virtual void Finish(bool result)
52+
{
53+
finishCalled = true;
54+
RaiseOnClose(result);
55+
}
56+
57+
protected void RaiseOnClose(bool result)
58+
{
59+
OnClose.SafeInvoke(result);
60+
}
61+
62+
public virtual void Awake()
63+
{
64+
Logger.Trace("Awake Initialized:{0}", initialized);
65+
if (!initialized)
66+
InitializeWindow(EntryPoint.ApplicationManager);
67+
}
68+
69+
public virtual void OnEnable()
70+
{
71+
Logger.Trace("OnEnable Initialized:{0}", initialized);
72+
if (!initialized)
73+
InitializeWindow(EntryPoint.ApplicationManager);
74+
}
75+
76+
public virtual void OnDisable() {}
77+
78+
public virtual void Update() {}
79+
80+
public virtual void OnDataUpdate()
81+
{}
82+
83+
public virtual void OnRepositoryChanged(IRepository oldRepository)
84+
{}
85+
86+
// OnGUI calls this everytime, so override it to render as you would OnGUI
87+
public virtual void OnUI() {}
88+
89+
// This is Unity's magic method
90+
private void OnGUI()
91+
{
92+
if (Event.current.type == EventType.layout)
93+
{
94+
if (cachedRepository != Environment.Repository)
95+
{
96+
OnRepositoryChanged(cachedRepository);
97+
cachedRepository = Environment.Repository;
98+
}
99+
inLayout = true;
100+
OnDataUpdate();
101+
}
102+
103+
OnUI();
104+
105+
if (Event.current.type == EventType.repaint)
106+
{
107+
inLayout = false;
108+
if (initializeWasCalled)
109+
{
110+
initializeWasCalled = false;
111+
InitializeWindow(cachedManager);
112+
}
113+
}
114+
}
115+
116+
public virtual void OnDestroy()
117+
{
118+
if (!finishCalled)
119+
{
120+
RaiseOnClose(false);
121+
}
122+
}
123+
124+
public virtual void OnSelectionChange()
125+
{}
126+
127+
public virtual Rect Position { get { return position; } }
128+
public IApplicationManager Manager { get; private set; }
129+
public IRepository Repository { get { return inLayout ? cachedRepository : Environment.Repository; } }
130+
public bool HasRepository { get { return Environment.RepositoryPath != null; } }
131+
132+
protected ITaskManager TaskManager { get { return Manager.TaskManager; } }
133+
protected IGitClient GitClient { get { return Manager.GitClient; } }
134+
protected IEnvironment Environment { get { return Manager.Environment; } }
135+
protected IPlatform Platform { get { return Manager.Platform; } }
136+
private ILogging logger;
137+
protected ILogging Logger
138+
{
139+
get
140+
{
141+
if (logger == null)
142+
logger = Logging.GetLogger(GetType());
143+
return logger;
144+
}
145+
}
146+
}
147+
}

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Subview.cs

Lines changed: 0 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -1,150 +1,8 @@
11
using System;
2-
using UnityEditor;
32
using UnityEngine;
43

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

0 commit comments

Comments
 (0)