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

Commit 2b9206e

Browse files
Merge branch 'master' into fixes/popup-window-refactor
# Conflicts: # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/AuthenticationView.cs # src/UnityExtension/Assets/Editor/GitHub.Unity/UI/HistoryView.cs
2 parents fdc35ba + ccfeef3 commit 2b9206e

File tree

6 files changed

+308
-248
lines changed

6 files changed

+308
-248
lines changed

src/GitHub.Api/OutputProcessors/ProcessManager.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,32 @@ public void RunCommandLineWindow(NPath workingDirectory)
7171
if (environment.IsWindows)
7272
{
7373
startInfo.FileName = "cmd";
74+
gitEnvironment.Configure(startInfo, workingDirectory);
7475
}
7576
else if (environment.IsMac)
7677
{
7778
// we need to create a temp bash script to set up the environment properly, because
7879
// osx terminal app doesn't inherit the PATH env var and there's no way to pass it in
7980

8081
var envVarFile = NPath.GetTempFilename();
81-
environment.FileSystem.WriteAllLines(envVarFile, new string[] { "cd $GHU_WORKINGDIR", "PATH=$GHU_FULLPATH:$PATH /bin/bash" });
82-
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8382
startInfo.FileName = "open";
8483
startInfo.Arguments = $"-a Terminal {envVarFile}";
84+
gitEnvironment.Configure(startInfo, workingDirectory);
85+
86+
var envVars = startInfo.EnvironmentVariables;
87+
var scriptContents = new[] {
88+
$"cd {envVars["GHU_WORKINGDIR"]}",
89+
$"PATH={envVars["GHU_FULLPATH"]}:$PATH /bin/bash"
90+
};
91+
environment.FileSystem.WriteAllLines(envVarFile, scriptContents);
92+
Mono.Unix.Native.Syscall.chmod(envVarFile, (Mono.Unix.Native.FilePermissions)493); // -rwxr-xr-x mode (0755)
8593
}
8694
else
8795
{
8896
startInfo.FileName = "sh";
97+
gitEnvironment.Configure(startInfo, workingDirectory);
8998
}
9099

91-
gitEnvironment.Configure(startInfo, workingDirectory);
92100
Process.Start(startInfo);
93101
}
94102

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

Lines changed: 65 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AuthenticationView : Subview
2525
[SerializeField] private string two2fa = "";
2626

2727
[NonSerialized] private bool need2fa;
28-
[NonSerialized] private bool busy;
28+
[NonSerialized] private bool isBusy;
2929
[NonSerialized] private string errorMessage;
3030
[NonSerialized] private bool enterPressed;
3131
[NonSerialized] private string password = "";
@@ -61,7 +61,7 @@ private AuthenticationService AuthenticationService
6161
public override void InitializeView(IView parent)
6262
{
6363
base.InitializeView(parent);
64-
need2fa = busy = false;
64+
need2fa = isBusy = false;
6565
Title = WindowTitle;
6666
Size = viewSize;
6767
}
@@ -136,81 +136,83 @@ private void HandleEnterPressed()
136136

137137
private void OnGUILogin()
138138
{
139-
GUILayout.Space(3);
140-
GUILayout.BeginHorizontal();
139+
EditorGUI.BeginDisabledGroup(isBusy);
141140
{
142-
if (busy) GUI.enabled = false;
143-
username = EditorGUILayout.TextField(UsernameLabel ,username, Styles.TextFieldStyle);
144-
GUI.enabled = true;
145-
}
146-
GUILayout.EndHorizontal();
147-
GUILayout.Space(Styles.BaseSpacing);
148-
GUILayout.BeginHorizontal();
149-
{
150-
if (busy) GUI.enabled = false;
151-
password = EditorGUILayout.PasswordField(PasswordLabel, password, Styles.TextFieldStyle);
152-
GUI.enabled = true;
153-
}
154-
GUILayout.EndHorizontal();
141+
GUILayout.Space(3);
142+
GUILayout.BeginHorizontal();
143+
{
144+
username = EditorGUILayout.TextField(UsernameLabel ,username, Styles.TextFieldStyle);
145+
}
146+
GUILayout.EndHorizontal();
155147

156-
ShowErrorMessage();
148+
GUILayout.Space(Styles.BaseSpacing);
149+
GUILayout.BeginHorizontal();
150+
{
151+
password = EditorGUILayout.PasswordField(PasswordLabel, password, Styles.TextFieldStyle);
152+
}
153+
GUILayout.EndHorizontal();
157154

158-
GUILayout.Space(Styles.BaseSpacing + 3);
155+
ShowErrorMessage();
159156

160-
if (busy) GUI.enabled = false;
161-
GUILayout.BeginHorizontal();
162-
GUILayout.FlexibleSpace();
163-
if (GUILayout.Button(LoginButton) || (GUI.enabled && enterPressed))
164-
{
165-
GUI.FocusControl(null);
166-
busy = true;
167-
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
157+
GUILayout.Space(Styles.BaseSpacing + 3);
158+
GUILayout.BeginHorizontal();
159+
{
160+
GUILayout.FlexibleSpace();
161+
if (GUILayout.Button(LoginButton) || (!isBusy && enterPressed))
162+
{
163+
GUI.FocusControl(null);
164+
isBusy = true;
165+
AuthenticationService.Login(username, password, DoRequire2fa, DoResult);
166+
}
167+
}
168+
GUILayout.EndHorizontal();
168169
}
169-
GUILayout.EndHorizontal();
170-
GUI.enabled = true;
170+
EditorGUI.EndDisabledGroup();
171171
}
172172

173173
private void OnGUI2FA()
174174
{
175175
GUILayout.BeginVertical();
176-
GUILayout.Label(TwofaTitle, EditorStyles.boldLabel);
177-
GUILayout.Label(TwofaDescription, EditorStyles.wordWrappedLabel);
178-
179-
GUILayout.Space(Styles.BaseSpacing);
180-
181-
GUILayout.BeginHorizontal();
182176
{
183-
if (busy) GUI.enabled = false;
184-
two2fa = EditorGUILayout.TextField(TwofaLabel, two2fa, Styles.TextFieldStyle);
185-
GUI.enabled = true;
186-
}
187-
GUILayout.EndHorizontal();
188-
GUILayout.Space(Styles.BaseSpacing);
177+
GUILayout.Label(TwofaTitle, EditorStyles.boldLabel);
178+
GUILayout.Label(TwofaDescription, EditorStyles.wordWrappedLabel);
189179

190-
ShowErrorMessage();
180+
EditorGUI.BeginDisabledGroup(isBusy);
181+
{
182+
GUILayout.Space(Styles.BaseSpacing);
183+
GUILayout.BeginHorizontal();
184+
{
185+
two2fa = EditorGUILayout.TextField(TwofaLabel, two2fa, Styles.TextFieldStyle);
186+
}
187+
GUILayout.EndHorizontal();
191188

192-
GUILayout.Space(Styles.BaseSpacing);
189+
GUILayout.Space(Styles.BaseSpacing);
190+
ShowErrorMessage();
193191

194-
if (busy) GUI.enabled = false;
195-
GUILayout.BeginHorizontal();
196-
GUILayout.FlexibleSpace();
197-
if (GUILayout.Button(BackButton))
198-
{
199-
GUI.FocusControl(null);
200-
need2fa = false;
201-
Redraw();
202-
}
192+
GUILayout.Space(Styles.BaseSpacing);
193+
GUILayout.BeginHorizontal();
194+
{
195+
GUILayout.FlexibleSpace();
196+
if (GUILayout.Button(BackButton))
197+
{
198+
GUI.FocusControl(null);
199+
need2fa = false;
200+
Redraw();
201+
}
202+
203+
if (GUILayout.Button(TwofaButton) || (!isBusy && enterPressed))
204+
{
205+
GUI.FocusControl(null);
206+
isBusy = true;
207+
AuthenticationService.LoginWith2fa(two2fa);
208+
}
209+
}
210+
GUILayout.EndHorizontal();
203211

204-
if (GUILayout.Button(TwofaButton) || (GUI.enabled && enterPressed))
205-
{
206-
GUI.FocusControl(null);
207-
busy = true;
208-
AuthenticationService.LoginWith2fa(two2fa);
212+
GUILayout.Space(Styles.BaseSpacing);
213+
}
214+
EditorGUI.EndDisabledGroup();
209215
}
210-
GUILayout.EndHorizontal();
211-
212-
GUI.enabled = true;
213-
GUILayout.Space(Styles.BaseSpacing);
214216
GUILayout.EndVertical();
215217
}
216218

@@ -220,7 +222,7 @@ private void DoRequire2fa(string msg)
220222

221223
need2fa = true;
222224
errorMessage = msg;
223-
busy = false;
225+
isBusy = false;
224226
Redraw();
225227
}
226228

@@ -229,7 +231,7 @@ private void DoResult(bool success, string msg)
229231
Logger.Trace("DoResult - Success:{0} Message:\"{1}\"", success, msg);
230232

231233
errorMessage = msg;
232-
busy = false;
234+
isBusy = false;
233235

234236
if (success == true)
235237
{

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

Lines changed: 72 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ class BranchesView : Subview
1515
private const string ConfirmSwitchMessage = "Switch branch to {0}?";
1616
private const string ConfirmSwitchOK = "Switch";
1717
private const string ConfirmSwitchCancel = "Cancel";
18+
private const string ConfirmCheckoutBranchTitle = "Confirm branch checkout";
19+
private const string ConfirmCheckoutBranchMessage = "Checkout branch {0} from {1}?";
20+
private const string ConfirmCheckoutBranchOK = "Checkout";
21+
private const string ConfirmCheckoutBranchCancel = "Cancel";
22+
private const string WarningCheckoutBranchExistsTitle = "Branch already exists";
23+
private const string WarningCheckoutBranchExistsMessage = "Branch {0} already exists";
24+
private const string WarningCheckoutBranchExistsOK = "Ok";
1825
private const string NewBranchCancelButton = "x";
1926
private const string NewBranchConfirmButton = "Create";
2027
private const string FavoritesSetting = "Favorites";
@@ -23,6 +30,10 @@ class BranchesView : Subview
2330
private const string LocalTitle = "Local branches";
2431
private const string RemoteTitle = "Remote branches";
2532
private const string CreateBranchButton = "New Branch";
33+
private const string DeleteBranchMessageFormatString = "Are you sure you want to delete the branch: {0}?";
34+
private const string DeleteBranchTitle = "Delete Branch?";
35+
private const string DeleteBranchButton = "Delete";
36+
private const string CancelButtonLabel = "Cancel";
2637

2738
private bool showLocalBranches = true;
2839
private bool showRemoteBranches = true;
@@ -147,7 +158,7 @@ public void OnEmbeddedGUI()
147158

148159
GUILayout.BeginHorizontal();
149160
{
150-
OnCreateGUI();
161+
OnButtonBarGUI();
151162
}
152163
GUILayout.EndHorizontal();
153164

@@ -308,6 +319,9 @@ private void OnRemoteBranchesUpdate(IEnumerable<GitBranch> list)
308319

309320
private void BuildTree(IEnumerable<GitBranch> local, IEnumerable<GitBranch> remote)
310321
{
322+
//Clear the selected node
323+
selectedNode = null;
324+
311325
// Sort
312326
var localBranches = new List<GitBranch>(local);
313327
var remoteBranches = new List<GitBranch>(remote);
@@ -451,28 +465,28 @@ private void SetFavourite(BranchTreeNode branch, bool favourite)
451465
}
452466
}
453467

454-
private void OnCreateGUI()
468+
private void OnButtonBarGUI()
455469
{
456-
// Create button
457470
if (mode == BranchesMode.Default)
458471
{
472+
// Delete button
459473
// If the current branch is selected, then do not enable the Delete button
460-
var disableDelete = activeBranchNode == selectedNode;
474+
var disableDelete = selectedNode == null || selectedNode.Type == NodeType.Folder || activeBranchNode == selectedNode;
461475
EditorGUI.BeginDisabledGroup(disableDelete);
462476
{
463-
if (GUILayout.Button("Delete", EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
477+
if (GUILayout.Button(DeleteBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
464478
{
465479
var selectedBranchName = selectedNode.Name;
466-
var dialogTitle = "Delete Branch: " + selectedBranchName;
467-
var dialogMessage = "Are you sure you want to delete the branch: " + selectedBranchName + "?";
468-
if (EditorUtility.DisplayDialog("Delete Branch?", dialogMessage, "Delete", "Cancel"))
480+
var dialogMessage = string.Format(DeleteBranchMessageFormatString, selectedBranchName);
481+
if (EditorUtility.DisplayDialog(DeleteBranchTitle, dialogMessage, DeleteBranchButton, CancelButtonLabel))
469482
{
470483
GitClient.DeleteBranch(selectedBranchName, true).Start();
471484
}
472485
}
473486
}
474487
EditorGUI.EndDisabledGroup();
475488

489+
// Create button
476490
GUILayout.FlexibleSpace();
477491
if (GUILayout.Button(CreateBranchButton, EditorStyles.miniButton, GUILayout.ExpandWidth(false)))
478492
{
@@ -649,37 +663,62 @@ private void OnTreeNodeGUI(BranchTreeNode node)
649663

650664
if (Event.current.clickCount > 1 && mode == BranchesMode.Default)
651665
{
652-
if (node.Type == NodeType.LocalBranch &&
653-
EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK,
654-
ConfirmSwitchCancel))
666+
if (node.Type == NodeType.LocalBranch)
655667
{
656-
GitClient.SwitchBranch(node.Name)
657-
.FinallyInUI((success, e) =>
658-
{
659-
if (success)
660-
Refresh();
661-
else
668+
if (EditorUtility.DisplayDialog(ConfirmSwitchTitle, String.Format(ConfirmSwitchMessage, node.Name), ConfirmSwitchOK, ConfirmSwitchCancel))
669+
{
670+
GitClient.SwitchBranch(node.Name)
671+
.FinallyInUI((success, e) =>
662672
{
663-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
664-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
665-
Localization.Ok);
666-
}
667-
}).Start();
673+
if (success)
674+
{
675+
Refresh();
676+
}
677+
else
678+
{
679+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
680+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
681+
Localization.Ok);
682+
}
683+
}).Start();
684+
}
668685
}
669686
else if (node.Type == NodeType.RemoteBranch)
670687
{
671-
GitClient.CreateBranch(selectedNode.Name.Substring(selectedNode.Name.IndexOf('/') + 1), selectedNode.Name)
672-
.FinallyInUI((success, e) =>
688+
var indexOfFirstSlash = selectedNode.Name.IndexOf('/');
689+
var originName = selectedNode.Name.Substring(0, indexOfFirstSlash);
690+
var branchName = selectedNode.Name.Substring(indexOfFirstSlash + 1);
691+
692+
if (Repository.LocalBranches.Any(localBranch => localBranch.Name == branchName))
693+
{
694+
EditorUtility.DisplayDialog(WarningCheckoutBranchExistsTitle,
695+
String.Format(WarningCheckoutBranchExistsMessage, branchName),
696+
WarningCheckoutBranchExistsOK);
697+
}
698+
else
699+
{
700+
var confirmCheckout = EditorUtility.DisplayDialog(ConfirmCheckoutBranchTitle,
701+
String.Format(ConfirmCheckoutBranchMessage, node.Name, originName),
702+
ConfirmCheckoutBranchOK, ConfirmCheckoutBranchCancel);
703+
704+
if (confirmCheckout)
673705
{
674-
if (success)
675-
Refresh();
676-
else
677-
{
678-
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
679-
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
680-
Localization.Ok);
681-
}
682-
}).Start();
706+
GitClient.CreateBranch(branchName, selectedNode.Name)
707+
.FinallyInUI((success, e) =>
708+
{
709+
if (success)
710+
{
711+
Refresh();
712+
}
713+
else
714+
{
715+
EditorUtility.DisplayDialog(Localization.SwitchBranchTitle,
716+
String.Format(Localization.SwitchBranchFailedDescription, node.Name),
717+
Localization.Ok);
718+
}
719+
}).Start();
720+
}
721+
}
683722
}
684723
}
685724
}

0 commit comments

Comments
 (0)