private void OnGUI() { Rect labelRect = EditorGUILayout.GetControlRect(); labelRect.y += labelRect.height / 2f; Rect updateAllRect = labelRect; updateAllRect.width = 70; updateAllRect.height = 15; updateAllRect.x = labelRect.width - 70; Rect cancelAllRect = labelRect; cancelAllRect.width = 70; cancelAllRect.height = 15; cancelAllRect.x = labelRect.width - (70 * 2); GUI.Label(labelRect, "Repositories", EditorStyles.miniLabel); List <bool> localChangesFlags = new List <bool>(_repoPanels.Count); foreach (var panel in _repoPanels) { localChangesFlags.Add(panel.HasLocalChanges()); } if (GUI.Button(updateAllRect, new GUIContent("Update All", "Update all. You will be asked before overwriting local changes."), EditorStyles.toolbarButton)) { bool localChangesDetected = false; for (int i = 0; i < _repoPanels.Count; i++) { if (localChangesFlags[i]) { localChangesDetected = true; break; } } if (localChangesDetected) { int choice = EditorUtility.DisplayDialogComplex("Local Changes Detected", "One or more repositories have local changes. Proceed with caution.", "Update and wipe all changes", "Cancel", "Update only clean submodules"); switch (choice) { case 0: { //Update and wipe all. for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].UpdateRepository(); } break; } case 1: { //Do nothing on cancel. break; } case 2: { //Update only clean for (int i = 0; i < _repoPanels.Count; i++) { if (!localChangesFlags[i]) { _repoPanels[i].UpdateRepository(); } } break; } } } else { for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].UpdateRepository(); } } } GUIUtility.DrawLine(); for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].OnDrawGUI(i); } GUIUtility.DrawLine(); //This is a dumb but kidna fancy way of adding new dependencies. if (_tester.Testing) { GUI.enabled = false; } if (EditorGUILayout.BeginFadeGroup(_showAddDependencyMenu.faded)) { _potentialNewDependency.Url = EditorGUILayout.TextField("Url", _potentialNewDependency.Url); if (_potentialNewDependency.Branch == null) { _potentialNewDependency.Branch = "main"; } _potentialNewDependency.Branch = EditorGUILayout.TextField("Branch", _potentialNewDependency.Branch); EditorGUILayout.Space(); _potentialNewDependency.Name = EditorGUILayout.TextField("Name", _potentialNewDependency.Name); _potentialNewDependency.SubFolder = EditorGUILayout.TextField("Subfolder", _potentialNewDependency.SubFolder); EditorGUILayout.Space(); } else { addDependencyFailureMessage = string.Empty; } EditorGUILayout.EndFadeGroup(); Rect addButtonRect = EditorGUILayout.GetControlRect(); Rect cancelButtonRect = new Rect(addButtonRect); if (_showAddDependencyMenu.target) { addButtonRect = new Rect(addButtonRect.x, addButtonRect.y, addButtonRect.width * 0.6666f, addButtonRect.height); cancelButtonRect = new Rect(addButtonRect.x + addButtonRect.width, cancelButtonRect.y, cancelButtonRect.width * 0.33333f, cancelButtonRect.height); } if (!_tester.Testing) { if (GUI.Button(addButtonRect, _showAddDependencyMenu.target ? "Confirm" : "Add Repository", EditorStyles.miniButton)) { addDependencyFailureMessage = string.Empty; _addTime = EditorApplication.timeSinceStartup; if (!_showAddDependencyMenu.target) { _showAddDependencyMenu.target = true; } else { //simple validation of fields bool validationSuccess = true; if (String.IsNullOrEmpty(_potentialNewDependency.Branch)) { addDependencyFailureMessage = "A valid branch must be specified"; validationSuccess = false; } foreach (Dependency dep in _dependencies.Dependencies) { if (dep.Name.Trim().ToLower() == _potentialNewDependency.Name.Trim().ToLower()) { addDependencyFailureMessage = $"Name already exists: {dep.Name}"; validationSuccess = false; } else if (String.Equals(dep.Url.Trim(), _potentialNewDependency.Url.Trim(), StringComparison.CurrentCultureIgnoreCase) && String.Equals(dep.SubFolder.Trim(), _potentialNewDependency.SubFolder.Trim(), StringComparison.CurrentCultureIgnoreCase) && String.Equals(dep.Branch.Trim(), _potentialNewDependency.Branch.Trim(), StringComparison.CurrentCultureIgnoreCase)) { addDependencyFailureMessage = $"Repository already exists with the current url, branch and subfolder.\nExisting: {dep.Name}"; validationSuccess = false; } } if (String.IsNullOrEmpty(_potentialNewDependency.Name)) { addDependencyFailureMessage = "Name can not be empty."; validationSuccess = false; } if (validationSuccess) { //actually connect to repository _tester.Test(_potentialNewDependency.Url, _potentialNewDependency.Branch, _potentialNewDependency.SubFolder, (success, message) => { if (success) { _dependencies.Dependencies.Add(_potentialNewDependency); UpdateDependencies(_dependencies.Dependencies); //Update the newly added repo foreach (GUIRepositoryPanel panel in _repoPanels) { if (panel.DependencyInfo.Name == _potentialNewDependency.Name) { //force this as we want to copy panel.UpdateRepository(); } } CloseAddMenu(); } else { addDependencyFailureMessage = message; } }); } } } } else { GUI.Label(addButtonRect, "Testing connection" + GUIUtility.GetLoadingDots(), EditorStyles.boldLabel); } GUI.enabled = true; if (_showAddDependencyMenu.target) { if (GUI.Button(cancelButtonRect, "Cancel", EditorStyles.miniButton)) { CloseAddMenu(); } } if (Event.current.type == EventType.Layout) { // Give the failure message a slight delay so we can see that the message is new even if its the same. double timeSinceButtonPress = EditorApplication.timeSinceStartup - _addTime; showWarningMessage = (!string.IsNullOrEmpty(addDependencyFailureMessage) && timeSinceButtonPress > _minimumAddTimeBeforeFeedback); } if (showWarningMessage) { EditorGUILayout.HelpBox(addDependencyFailureMessage, MessageType.Warning); } }
private void OnGUI() { bool reImport = EditorGUILayout.Toggle("Full Re-Import", EditorPrefs.GetBool(FULL_RE_IMPORT_KEY, true)); EditorPrefs.SetBool(FULL_RE_IMPORT_KEY, reImport); Rect labelRect = EditorGUILayout.GetControlRect(); labelRect.y += labelRect.height / 2f; Rect updateAllRect = labelRect; updateAllRect.width = 70; updateAllRect.height = 15; updateAllRect.x = labelRect.width - 70; Rect openCacheRect = labelRect; openCacheRect.width = 70; openCacheRect.height = 15; openCacheRect.x = labelRect.width - (70 * 2); Rect cancelAllRect = labelRect; cancelAllRect.width = 70; cancelAllRect.height = 15; cancelAllRect.x = labelRect.width - (70 * 2); GUI.Label(labelRect, "Repositories" /*(" + Repository.TotalInitialized + ")"*/, EditorStyles.miniLabel); if (GUI.Button(updateAllRect, new GUIContent("Update All", "Update all repositories. You will be asked before overwriting local changes."), EditorStyles.toolbarButton)) { bool localChangesDetected = false; for (int i = 0; i < _repoPanels.Count; i++) { if (_repoPanels[i].HasLocalChanges()) { localChangesDetected = true; break; } } if (localChangesDetected) { int choice = EditorUtility.DisplayDialogComplex("Local Changes Detected", "One or more repositories have local changes. Proceed with caution.", "Update and wipe all changes", "Cancel", "Update only clean repositories"); switch (choice) { case 0: { //Update and wipe all. for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].UpdateRepository(); } break; } case 1: { //Do nothing on cancel. break; } case 2: { //Update only clean for (int i = 0; i < _repoPanels.Count; i++) { if (!_repoPanels[i].HasLocalChanges()) { _repoPanels[i].UpdateRepository(); } } break; } } } else { for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].UpdateRepository(); } } } if (GUI.Button(cancelAllRect, new GUIContent("Open Cache", "Open the cache folder root. All repositories for all projects are stored here."), EditorStyles.toolbarButton)) { Process.Start(new ProcessStartInfo() { FileName = RepoPanel.CacheRoot, UseShellExecute = true, Verb = "open" }); } if (_reposBusy.Count > 0) { //TODO: Cancel not fully implemented due to complexities in libgit2sharp. Hiding for now. /*if (GUI.Button(cancelAllRect, "Cancel All", EditorStyles.miniButton)) * { * for (int i = 0; i < _repoPanels.Count; i++) * { * _repoPanels[i].CancelUpdateRepository(); * } * }*/ } GUIUtility.DrawLine(); for (int i = 0; i < _repoPanels.Count; i++) { _repoPanels[i].OnDrawGUI(i); } GUIUtility.DrawLine(); //This is a dumb but kidna fancy way of adding new dependencies. if (_tester.Testing) { GUI.enabled = false; } if (EditorGUILayout.BeginFadeGroup(_showAddDependencyMenu.faded)) { _potentialNewDependency.Url = EditorGUILayout.TextField("Url", _potentialNewDependency.Url); //TODO: For now tags are not exposed. When we do expose them we may have to have both branch and tag as git expects a branch in lots of places //Unless we can get branch from tag but not sure its worth the effort _potentialNewDependency.Branch = EditorGUILayout.TextField("Branch", _potentialNewDependency.Branch); //_potentialNewDependency.Tag = null; EditorGUILayout.Space(); _potentialNewDependency.Name = EditorGUILayout.TextField("Name", _potentialNewDependency.Name); _potentialNewDependency.SubFolder = EditorGUILayout.TextField("Subfolder", _potentialNewDependency.SubFolder); /*GUILayout.BeginHorizontal(); * selectedFilterIndex = EditorGUILayout.Popup(selectedFilterIndex, new string[] { "Branch", "Tag" }, GUILayout.Width(146)); * * if (selectedFilterIndex == 0) * { * if (_potentialNewDependency.Branch == null) _potentialNewDependency.Branch = "master"; * _potentialNewDependency.Branch = GUILayout.TextField(_potentialNewDependency.Branch); * _potentialNewDependency.Tag = null; * } * else * { * if (_potentialNewDependency.Tag == null) _potentialNewDependency.Tag = ""; * _potentialNewDependency.Tag = GUILayout.TextField(_potentialNewDependency.Tag); * _potentialNewDependency.Branch = null; * } * GUILayout.EndHorizontal();*/ } else { addDependencyFailureMessage = string.Empty; } EditorGUILayout.EndFadeGroup(); Rect addButtonRect = EditorGUILayout.GetControlRect(); Rect cancelButtonRect = new Rect(addButtonRect); if (_showAddDependencyMenu.target) { addButtonRect = new Rect(addButtonRect.x, addButtonRect.y, addButtonRect.width * 0.6666f, addButtonRect.height); cancelButtonRect = new Rect(addButtonRect.x + addButtonRect.width, cancelButtonRect.y, cancelButtonRect.width * 0.33333f, cancelButtonRect.height); } if (!_tester.Testing) { if (GUI.Button(addButtonRect, _showAddDependencyMenu.target ? "Add" : "Add Repository", EditorStyles.miniButton)) { addDependencyFailureMessage = string.Empty; _addTime = EditorApplication.timeSinceStartup; if (!_showAddDependencyMenu.target) { _showAddDependencyMenu.target = true; } else { //simple validation of fields bool validationSuccess = true; if (String.IsNullOrEmpty(_potentialNewDependency.Branch) /* && String.IsNullOrEmpty(_potentialNewDependency.Tag)*/) { addDependencyFailureMessage = "Either a valid branch or tag must be specified"; validationSuccess = false; } foreach (Dependency dep in _dependencies.Dependencies) { if (dep.Name.Trim().ToLower() == _potentialNewDependency.Name.Trim().ToLower()) { addDependencyFailureMessage = "Name already exists."; validationSuccess = false; } else if (dep.Url.Trim().ToLower() == _potentialNewDependency.Url.Trim().ToLower()) { addDependencyFailureMessage = "Repository already exists with the current url.\nExisting: " + dep.Name; validationSuccess = false; } } if (String.IsNullOrEmpty(_potentialNewDependency.Name)) { addDependencyFailureMessage = "Name can not be empty."; validationSuccess = false; } if (validationSuccess) { //actually connect to repository _tester.Test(_potentialNewDependency.Url, _potentialNewDependency.Branch, _potentialNewDependency.SubFolder, GetPlatformAuthentication(), (success, message) => { if (success) { _dependencies.Dependencies.Add(_potentialNewDependency); UpdateDependencies(_dependencies.Dependencies); //Update the newly added repo foreach (RepoPanel panel in _repoPanels) { if (panel.DependencyInfo.Url == _potentialNewDependency.Url && panel.DependencyInfo.Branch == _potentialNewDependency.Branch && panel.DependencyInfo.Name == _potentialNewDependency.Name) { //force this as we want to copy panel.UpdateRepository(); } } CloseAddMenu(); } else { addDependencyFailureMessage = message; } }); } } } } else { GUI.Label(addButtonRect, "Testing connection" + GUIUtility.GetLoadingDots() + "\n" + _potentialNewDependency.Url, EditorStyles.boldLabel); } GUI.enabled = true; if (_showAddDependencyMenu.target) { if (GUI.Button(cancelButtonRect, "Cancel", EditorStyles.miniButton)) { CloseAddMenu(); } } if (Event.current.type == EventType.Layout) { // Give the failure message a slight delay so we can see that the message is new even if its the same. double timeSinceButtonPress = EditorApplication.timeSinceStartup - _addTime; showWarningMessage = (!string.IsNullOrEmpty(addDependencyFailureMessage) && timeSinceButtonPress > _minimumAddTimeBeforeFeedback); } if (showWarningMessage) { EditorGUILayout.HelpBox(addDependencyFailureMessage, MessageType.Warning); } }