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

Refatoring to remove unused code #249

Merged
merged 4 commits into from
Sep 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Octokit;
using Rackspace.Threading;
using UnityEditor;
using UnityEngine;

Expand Down
314 changes: 0 additions & 314 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/SettingsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,52 +11,16 @@ namespace GitHub.Unity
[Serializable]
class SettingsView : Subview
{
private const string EditorSettingsMissingTitle = "Missing editor settings";
private const string EditorSettingsMissingMessage =
"No valid editor settings found when looking in expected path '{0}'. Please save the project.";
private const string BadVCSSettingsTitle = "Update settings";
private const string BadVCSSettingsMessage =
"To use Git, you will need to set project Version Control Mode to either 'Visible Meta Files' or 'Hidden Meta Files'.";
private const string SelectEditorSettingsButton = "View settings";
private const string NoActiveRepositoryTitle = "No repository found";
private const string NoActiveRepositoryMessage = "Your current project is not currently in an active Git repository:";
private const string TextSerialisationMessage =
"For optimal Git use, it is recommended that you configure Unity to serialize assets using text serialization. Note that this may cause editor slowdowns for projects with very large datasets.";
private const string BinarySerialisationMessage = "This project is currently configured for binary serialization.";
private const string MixedSerialisationMessage = "This project is currently configured for mixed serialization.";
private const string IgnoreSerialisationIssuesSetting = "IgnoreSerializationIssues";
private const string IgnoreSerialisationSettingsButton = "Ignore forever";
private const string RefreshIssuesButton = "Refresh";
private const string GitIgnoreExceptionWarning = "Exception when searching .gitignore files: {0}";
private const string GitIgnoreIssueWarning = "{0}: {2}\n\nIn line \"{1}\"";
private const string GitIgnoreIssueNoLineWarning = "{0}: {1}";
private const string GitInitBrowseTitle = "Pick desired repository root";
private const string GitInitButton = "Set up Git";
private const string InvalidInitDirectoryTitle = "Invalid repository root";
private const string InvalidInitDirectoryMessage =
"Your selected folder '{0}' is not a valid repository root for your current project.";
private const string InvalidInitDirectoryOK = "OK";
private const string GitInstallTitle = "Git installation";
private const string GitInstallMissingMessage =
"GitHub was unable to locate a valid Git install. Please specify install location or install git.";
private const string GitInstallBrowseTitle = "Select git binary";
private const string GitInstallPickInvalidTitle = "Invalid Git install";
private const string GitInstallPickInvalidMessage = "The selected file is not a valid Git install. {0}";
private const string GitInstallPickInvalidOK = "OK";
private const string GitInstallFindButton = "Find install";
private const string GitInstallURL = "http://desktop.github.com";
private const string GitIgnoreRulesTitle = "gitignore rules";
private const string GitIgnoreRulesEffect = "Effect";
private const string GitIgnoreRulesFile = "File";
private const string GitIgnoreRulesLine = "Line";
private const string GitIgnoreRulesDescription = "Description";
private const string NewGitIgnoreRuleButton = "New";
private const string DeleteGitIgnoreRuleButton = "Delete";
private const string GitConfigTitle = "Git Configuration";
private const string GitConfigNameLabel = "Name";
private const string GitConfigEmailLabel = "Email";
private const string GitConfigUserSave = "Save User";
private const string GitConfigUserSaved = "Saved";
private const string GitRepositoryTitle = "Repository Configuration";
private const string GitRepositoryRemoteLabel = "Remote";
private const string GitRepositorySave = "Save Repository";
Expand Down Expand Up @@ -240,14 +204,6 @@ private void MaybeUpdateData()
}
}

private void ResetToDefaults()
{
gitName = Repository != null ? Repository.User.Name : String.Empty;
gitEmail = Repository != null ? Repository.User.Email : String.Empty;
repositoryRemoteName = DefaultRepositoryRemoteName;
repositoryRemoteUrl = string.Empty;
}

private void Repository_OnActiveRemoteChanged(string remote)
{
remoteHasChanged = true;
Expand Down Expand Up @@ -385,237 +341,6 @@ private bool ValidateGitInstall(string path)
return true;
}

private bool OnIssuesGUI()
{
IList<ProjectConfigurationIssue> projectConfigurationIssues;
if (Utility.Issues != null)
{
projectConfigurationIssues = Utility.Issues;
}
else
{
projectConfigurationIssues = new ProjectConfigurationIssue[0];
}

var settingsIssues = projectConfigurationIssues.Select(i => i as ProjectSettingsIssue).FirstOrDefault(i => i != null);

if (settingsIssues != null)
{
if (settingsIssues.WasCaught(ProjectSettingsEvaluation.EditorSettingsMissing))
{
Styles.BeginInitialStateArea(EditorSettingsMissingTitle,
String.Format(EditorSettingsMissingMessage, EvaluateProjectConfigurationTask.EditorSettingsPath));
Styles.EndInitialStateArea();

return false;
}
else if (settingsIssues.WasCaught(ProjectSettingsEvaluation.BadVCSSettings))
{
Styles.BeginInitialStateArea(BadVCSSettingsTitle, BadVCSSettingsMessage);
{
GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

// Button to select editor settings - for remedying the bad setting
if (Styles.InitialStateActionButton(SelectEditorSettingsButton))
{
Selection.activeObject = EvaluateProjectConfigurationTask.LoadEditorSettings();
}
}
Styles.EndInitialStateArea();

return false;
}
}

if (!Utility.GitFound)
{
Styles.BeginInitialStateArea(GitInstallTitle, GitInstallMissingMessage);
{
OnInstallPathGUI();
}
Styles.EndInitialStateArea();

return false;
}
else if (!Utility.ActiveRepository)
{
Styles.BeginInitialStateArea(NoActiveRepositoryTitle, NoActiveRepositoryMessage);
{
// Init directory path field
Styles.PathField(ref initDirectory, () => EditorUtility.OpenFolderPanel(GitInitBrowseTitle, initDirectory, ""),
ValidateInitDirectory);

GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

// Git init, which starts the config flow
if (Styles.InitialStateActionButton(GitInitButton))
{
if (ValidateInitDirectory(initDirectory))
{
Init();
}
else
{
ResetInitDirectory();
}
}
}
Styles.EndInitialStateArea();

return false;
}

if (settingsIssues != null && !Manager.LocalSettings.Get(IgnoreSerialisationIssuesSetting, "0").Equals("1"))
{
var binary = settingsIssues.WasCaught(ProjectSettingsEvaluation.BinarySerialization);
var mixed = settingsIssues.WasCaught(ProjectSettingsEvaluation.MixedSerialization);

if (binary || mixed)
{
GUILayout.Label(TextSerialisationMessage, Styles.LongMessageStyle);
Styles.Warning(binary ? BinarySerialisationMessage : MixedSerialisationMessage);

GUILayout.BeginHorizontal();
{
if (GUILayout.Button(IgnoreSerialisationSettingsButton))
{
Manager.LocalSettings.Set(IgnoreSerialisationIssuesSetting, "1");
}

GUILayout.FlexibleSpace();

if (GUILayout.Button(RefreshIssuesButton))
{
// TODO: Fix this
}

if (GUILayout.Button(SelectEditorSettingsButton))
{
Selection.activeObject = EvaluateProjectConfigurationTask.LoadEditorSettings();
}
}
GUILayout.EndHorizontal();
}
}

var gitIgnoreException = projectConfigurationIssues.Select(i => i as GitIgnoreException).FirstOrDefault(i => i != null);
if (gitIgnoreException != null)
{
Styles.Warning(String.Format(GitIgnoreExceptionWarning, gitIgnoreException.Exception));
}

foreach (var issue in projectConfigurationIssues.Select(i => i as GitIgnoreIssue).Where(i => i != null))
{
if (string.IsNullOrEmpty(issue.Line))
{
Styles.Warning(String.Format(GitIgnoreIssueNoLineWarning, issue.File, issue.Description));
}
else
{
Styles.Warning(String.Format(GitIgnoreIssueWarning, issue.File, issue.Line, issue.Description));
}
}

return true;
}

private void OnGitIgnoreRulesGUI()
{
var gitignoreRulesWith = Position.width - Styles.GitIgnoreRulesTotalHorizontalMargin - Styles.GitIgnoreRulesSelectorWidth - 16f;
var effectWidth = gitignoreRulesWith * Styles.GitIgnoreRulesEffectRatio;
var fileWidth = gitignoreRulesWith * Styles.GitIgnoreRulesFileRatio;
var lineWidth = gitignoreRulesWith * Styles.GitIgnoreRulesLineRatio;

GUILayout.Label(GitIgnoreRulesTitle, EditorStyles.boldLabel);
GUILayout.BeginVertical(GUI.skin.box);
GUILayout.BeginHorizontal(EditorStyles.toolbar);
{
GUILayout.Space(Styles.GitIgnoreRulesSelectorWidth);
TableCell(GitIgnoreRulesEffect, effectWidth);
TableCell(GitIgnoreRulesFile, fileWidth);
TableCell(GitIgnoreRulesLine, lineWidth);
}
GUILayout.EndHorizontal();

var count = GitIgnoreRule.Count;
for (var index = 0; index < count; ++index)
{
GitIgnoreRule rule;
if (GitIgnoreRule.TryLoad(index, out rule))
{
GUILayout.BeginHorizontal();
{
GUILayout.Space(Styles.GitIgnoreRulesSelectorWidth);

if (gitIgnoreRulesSelection == index && Event.current.type == EventType.Repaint)
{
var selectorRect = GUILayoutUtility.GetLastRect();
selectorRect.Set(selectorRect.x, selectorRect.y + 2f, selectorRect.width - 2f, EditorGUIUtility.singleLineHeight);
EditorStyles.foldout.Draw(selectorRect, false, false, false, false);
}

TableCell(rule.Effect.ToString(), effectWidth);
// TODO: Tint if the regex is null
TableCell(rule.FileString, fileWidth);
TableCell(rule.LineString, lineWidth);
}
GUILayout.EndHorizontal();

if (Event.current.type == EventType.MouseDown && GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition))
{
newGitIgnoreRulesSelection = index;
Event.current.Use();
}
}
}

GUILayout.BeginHorizontal();
{
GUILayout.FlexibleSpace();
if (GUILayout.Button(NewGitIgnoreRuleButton, EditorStyles.miniButton))
{
GitIgnoreRule.New();
GUIUtility.hotControl = GUIUtility.keyboardControl = -1;
}
}
GUILayout.EndHorizontal();

GUILayout.Space(EditorGUIUtility.standardVerticalSpacing);

// Selected gitignore rule edit

GitIgnoreRule selectedRule;
if (GitIgnoreRule.TryLoad(gitIgnoreRulesSelection, out selectedRule))
{
GUILayout.BeginVertical(GUI.skin.box);
{
GUILayout.BeginHorizontal();
{
GUILayout.FlexibleSpace();
if (GUILayout.Button(DeleteGitIgnoreRuleButton, EditorStyles.miniButton))
{
GitIgnoreRule.Delete(gitIgnoreRulesSelection);
newGitIgnoreRulesSelection = gitIgnoreRulesSelection - 1;
}
}
GUILayout.EndHorizontal();
EditorGUI.BeginChangeCheck();
var newEffect = (GitIgnoreRuleEffect)EditorGUILayout.EnumPopup(GitIgnoreRulesEffect, selectedRule.Effect);
var newFile = EditorGUILayout.TextField(GitIgnoreRulesFile, selectedRule.FileString);
var newLine = EditorGUILayout.TextField(GitIgnoreRulesLine, selectedRule.LineString);
GUILayout.Label(GitIgnoreRulesDescription);
var newDescription = EditorGUILayout.TextArea(selectedRule.TriggerText, Styles.CommitDescriptionFieldStyle);
if (EditorGUI.EndChangeCheck())
{
GitIgnoreRule.Save(gitIgnoreRulesSelection, newEffect, newFile, newLine, newDescription);
// TODO: Fix this
}
}
GUILayout.EndVertical();
}
GUILayout.EndVertical();
}

private void OnGitLfsLocksGUI()
{
EditorGUI.BeginDisabledGroup(isBusy || Repository == null);
Expand Down Expand Up @@ -792,44 +517,5 @@ private void OnLoggingSettingsGui()
}
EditorGUI.EndDisabledGroup();
}

private void ResetInitDirectory()
{
initDirectory = Utility.UnityProjectPath;
GUIUtility.keyboardControl = GUIUtility.hotControl = 0;
}

private void ForceUnlockFile(object obj)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should make sure we track this in an issue for fixing, we'll need to do this as part of the initial file locking support.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Who are you?

{
var fileName = obj;

EditorUtility.DisplayDialog("Force unlock file?",
"Are you sure you want to force unlock " + fileName + "? "
+ "This will notify the owner of the lock.",
"Unlock",
"Cancel");
}

private void Init()
{
//Logger.Debug("TODO: Init '{0}'", initDirectory);
}

private static void TableCell(string label, float width)
{
GUILayout.Label(label, EditorStyles.miniLabel, GUILayout.Width(width), GUILayout.MaxWidth(width));
}

private static bool ValidateInitDirectory(string path)
{
if (Utility.UnityProjectPath.IndexOf(path) != 0)
{
EditorUtility.DisplayDialog(InvalidInitDirectoryTitle, String.Format(InvalidInitDirectoryMessage, path),
InvalidInitDirectoryOK);
return false;
}

return true;
}
}
}
19 changes: 0 additions & 19 deletions src/UnityExtension/Assets/Editor/GitHub.Unity/UI/Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ class Window : BaseWindow
private const float DefaultNotificationTimeout = 4f;
private const string Title = "GitHub";
private const string LaunchMenu = "Window/GitHub";
private const string RefreshButton = "Refresh";
private const string UnknownSubTabError = "Unsupported view mode: {0}";
private const string BadNotificationDelayError = "A delay of {0} is shorter than the default delay and thus would get pre-empted.";
private const string HistoryTitle = "History";
private const string ChangesTitle = "Changes";
private const string BranchesTitle = "Branches";
private const string SettingsTitle = "Settings";
private const string AuthenticationTitle = "Auth";
private const string DefaultRepoUrl = "No remote configured";
private const string Window_RepoUrlTooltip = "Url of the {0} remote";
private const string Window_RepoNoUrlTooltip = "Add a remote in the Settings tab";
Expand Down Expand Up @@ -350,22 +347,6 @@ private void SignOut(object obj)
apiClient.Logout(host);
}

private bool ValidateSettings()
{
var settingsIssues = Utility.Issues.Select(i => i as ProjectSettingsIssue).FirstOrDefault(i => i != null);

// Initial state
if (!Utility.ActiveRepository || !Utility.GitFound ||
(settingsIssues != null &&
(settingsIssues.WasCaught(ProjectSettingsEvaluation.EditorSettingsMissing) ||
settingsIssues.WasCaught(ProjectSettingsEvaluation.BadVCSSettings))))
{
return false;
}

return true;
}

public new void ShowNotification(GUIContent content)
{
ShowNotification(content, DefaultNotificationTimeout);
Expand Down