-
Notifications
You must be signed in to change notification settings - Fork 296
/
NugetPreferences.cs
151 lines (129 loc) · 5.99 KB
/
NugetPreferences.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
namespace NugetForUnity
{
using UnityEditor;
using UnityEngine;
/// <summary>
/// Handles the displaying, editing, and saving of the preferences for NuGet For Unity.
/// </summary>
public static class NugetPreferences
{
/// <summary>
/// The current version of NuGet for Unity.
/// </summary>
public const string NuGetForUnityVersion = "1.2.2";
/// <summary>
/// The current position of the scroll bar in the GUI.
/// </summary>
private static Vector2 scrollPosition;
/// <summary>
/// Draws the preferences GUI inside the Unity preferences window in the Editor.
/// </summary>
[PreferenceItem("NuGet For Unity")]
public static void PreferencesGUI()
{
EditorGUILayout.LabelField(string.Format("Version: {0}", NuGetForUnityVersion));
if (NugetHelper.NugetConfigFile == null)
{
NugetHelper.LoadNugetConfigFile();
}
NugetHelper.NugetConfigFile.InstallFromCache = EditorGUILayout.Toggle("Install From the Cache", NugetHelper.NugetConfigFile.InstallFromCache);
NugetHelper.NugetConfigFile.ReadOnlyPackageFiles = EditorGUILayout.Toggle("Read-Only Package Files", NugetHelper.NugetConfigFile.ReadOnlyPackageFiles);
NugetHelper.NugetConfigFile.Verbose = EditorGUILayout.Toggle("Use Verbose Logging", NugetHelper.NugetConfigFile.Verbose);
EditorGUILayout.LabelField("Package Sources:");
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);
NugetPackageSource sourceToMoveUp = null;
NugetPackageSource sourceToMoveDown = null;
NugetPackageSource sourceToRemove = null;
foreach (var source in NugetHelper.NugetConfigFile.PackageSources)
{
EditorGUILayout.BeginVertical();
{
EditorGUILayout.BeginHorizontal();
{
EditorGUILayout.BeginVertical(GUILayout.Width(20));
{
GUILayout.Space(10);
source.IsEnabled = EditorGUILayout.Toggle(source.IsEnabled, GUILayout.Width(20));
}
EditorGUILayout.EndVertical();
EditorGUILayout.BeginVertical();
{
source.Name = EditorGUILayout.TextField(source.Name);
source.SavedPath = EditorGUILayout.TextField(source.SavedPath);
}
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
GUILayout.Space(29);
EditorGUIUtility.labelWidth = 75;
EditorGUILayout.BeginVertical();
source.HasPassword = EditorGUILayout.Toggle("Credentials", source.HasPassword);
if (source.HasPassword)
{
source.UserName = EditorGUILayout.TextField("User Name", source.UserName);
source.SavedPassword = EditorGUILayout.PasswordField("Password", source.SavedPassword);
}
else
{
source.UserName = null;
}
EditorGUIUtility.labelWidth = 0;
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.BeginHorizontal();
{
if (GUILayout.Button(string.Format("Move Up")))
{
sourceToMoveUp = source;
}
if (GUILayout.Button(string.Format("Move Down")))
{
sourceToMoveDown = source;
}
if (GUILayout.Button(string.Format("Remove")))
{
sourceToRemove = source;
}
}
EditorGUILayout.EndHorizontal();
}
EditorGUILayout.EndVertical();
}
if (sourceToMoveUp != null)
{
int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveUp);
if (index > 0)
{
NugetHelper.NugetConfigFile.PackageSources[index] = NugetHelper.NugetConfigFile.PackageSources[index - 1];
NugetHelper.NugetConfigFile.PackageSources[index - 1] = sourceToMoveUp;
}
}
if (sourceToMoveDown != null)
{
int index = NugetHelper.NugetConfigFile.PackageSources.IndexOf(sourceToMoveDown);
if (index < NugetHelper.NugetConfigFile.PackageSources.Count - 1)
{
NugetHelper.NugetConfigFile.PackageSources[index] = NugetHelper.NugetConfigFile.PackageSources[index + 1];
NugetHelper.NugetConfigFile.PackageSources[index + 1] = sourceToMoveDown;
}
}
if (sourceToRemove != null)
{
NugetHelper.NugetConfigFile.PackageSources.Remove(sourceToRemove);
}
if (GUILayout.Button(string.Format("Add New Source")))
{
NugetHelper.NugetConfigFile.PackageSources.Add(new NugetPackageSource("New Source", "source_path"));
}
EditorGUILayout.EndScrollView();
if (GUILayout.Button(string.Format("Save")))
{
NugetHelper.NugetConfigFile.Save(NugetHelper.NugetConfigFilePath);
NugetHelper.LoadNugetConfigFile();
}
}
}
}