forked from MrJoy/UnityGit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GitShell.cs
executable file
·132 lines (117 loc) · 3.69 KB
/
GitShell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//-----------------------------------------------------------------
// GitShell v0.1
// Copyright 2012 MrJoy, Inc.
// All rights reserved
//
//-----------------------------------------------------------------
// Unity editor extension for Git integration.
//-----------------------------------------------------------------
using System;
using UnityEditor;
using UnityEngine;
public class GitShell : EditorWindow {
public const string VERSION = "0.0.2";
public const string COPYRIGHT = "(C)Copyright 2012 MrJoy, Inc.";
protected GUIContent refreshButton = new GUIContent();
public void OnEnable() {
refreshButton.image = AssetDatabase.LoadAssetAtPath("Assets/Editor/UnityGit/Resources/Refresh.png", typeof(Texture2D)) as Texture2D;
foreach(GitPanel panel in panels)
if(panel != null)
panel.OnEnable();
}
public void OnDisable() {
foreach(GitPanel panel in panels)
if(panel != null)
panel.OnDisable();
}
private bool forceRefresh = false;
public void OnFocus() {
forceRefresh = true;
GitPanel panel = panels[panelIndex];
if(panel != null)
panel.OnFocus();
}
public void OnLostFocus() {
GitPanel panel = panels[panelIndex];
if(panel != null)
panel.OnLostFocus();
}
public void OnDestroy() { }
[System.NonSerialized]
protected int panelIndex = 0;
[System.NonSerialized]
protected GUIContent[] panelLabels = new GUIContent[] {
new GUIContent("Commit"),
new GUIContent("Branch/Merge"),
new GUIContent("Remotes"),
new GUIContent("History"),
new GUIContent("Refs"),
null,
new GUIContent("TEST Diff"),
new GUIContent("About")
};
[System.NonSerialized]
protected GitPanel[] panels = null;
public GitShell() {
// Need to do this here to enable "this" reference.
panels = new GitPanel[] {
new GitStatusPanel(this),
null,
null,
null,
new GitRefsPanel(this),
null,
new GitDiffTestPanel(this),
new GitAboutPanel(this)
};
}
public void OnGUI() {
GitPanel panel = panels[panelIndex];
EditorGUILayoutToolbar.Begin();
if(GUILayout.Button(refreshButton, EditorStyles.toolbarButton, GUIHelper.NoExpandWidth))
forceRefresh = true;
if(forceRefresh && panel != null) {
forceRefresh = false;
panel.OnRefresh();
}
EditorGUILayoutToolbar.Space();
bool hasShownToolbar = false;
for(int i = 0; i < panelLabels.Length; i++) {
if(panelLabels[i] == null) {
if(!hasShownToolbar) {
hasShownToolbar = true;
EditorGUILayoutToolbar.Space();
if(panel != null && !panel.IsDisabledForError) {
panel.OnToolbarGUI();
}
EditorGUILayoutToolbar.FlexibleSpace();
}
} else {
if(GUILayout.Toggle((panelIndex == i), panelLabels[i], EditorStyles.toolbarButton, GUIHelper.NoExpandWidth))
panelIndex = i;
}
}
EditorGUILayoutToolbar.End();
GUILayout.BeginVertical(GitStyles.Indented);
panel = panels[panelIndex];
if(panel != null) {
if(!panel.IsDisabledForError)
panel.OnGUI();
else {
Color c = GUI.color;
GUI.color = GitStyles.ErrorColor;
GUILayout.Label("Whoops! Encountered an error in git. Please see the About tab to ensure git is set up properly!", GitStyles.WhiteBoldLabel);
GUI.color = c;
}
} else {
GUILayout.Label("Not implemented yet.");
}
GUILayout.EndVertical();
}
[MenuItem("Window/Git Shell #%g")]
public static void Init() {
GitShell window = (GitShell)EditorWindow.GetWindow(typeof(GitShell));
window.title = "Git";
window.Show();
}
}