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 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
| using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.Text; namespace Svn { public class SVNSettingWindow : EditorWindow { const string _MenuPath = "Svn"; const string _tip = ""; string[] _career = {"Artist", "Tester", "Programmer", "Designer"}; GUIContent[] _tabContents = new GUIContent[]{ new GUIContent("Artist"), new GUIContent("Tester"), new GUIContent("Programmer"), new GUIContent("Designer"), }; [MenuItem(_MenuPath + "Update", priority = 0, validate = false)] public static void UpdateSVN() { SvnClientHelper.OpenUpdateWindow(SvnCmdHelper.GetSvnWorkDir()); } [MenuItem(_MenuPath + "Revert", priority = 0, validate = false)] public static void RevertSVN() { SvnClientHelper.OpenRevertWindow(SvnCmdHelper.GetSvnWorkDir()); } [MenuItem(_MenuPath + "CommitAll", priority = 0, validate = false)] public static void CommitAllSVN() { SvnClientHelper.OpenCommitWindow(SvnCmdHelper.GetSvnWorkDir()); } [MenuItem(_MenuPath + "CommitAllWithFilter", priority = 0, validate = true)] public static bool CommitAllWithFilterValidate() { if(string.IsNullOrEmpty(SvnCmdHelper.GetSvnVerison())) return false; if(string.IsNullOrEmpty(SvnCmdHelper.GetSvnWorkDir())) return false; return true; } [MenuItem(_MenuPath + "CommitAllWithFilter", priority = 0, validate = false)] public static void CommitAllWithFilter() { if(SvnFilterData.Load(out var data)) { SvnCmdHelper.SetChangelistForFilterData(data); SvnClientHelper.OpenCommitWindow(SvnCmdHelper.GetSvnWorkDir()); } else Open(); } [MenuItem(_MenuPath + "Settings", false, 1000)] public static void Open() { SVNSettingWindow window = GetWindow<SVNSettingWindow>("Setting"); window._svnVersion = SvnCmdHelper.GetSvnVersion(); window._workDir = SvnCmdHelper.GetSvnWorkDir(); if(!string.IsNullOrEmpty(window._workDir)) window._workDir = window._workDir.Replace("\\","/"); window.minSize = new Vector2(520, 520); window.InitConfigData(); window.Show(); }
[SerializeField] private string _svnVersion = null; [SerializeField] private string _workDir = null;
[SerializeField] private int careerSelectedIdx = -1; [SerializeField] private string ignorePatternModify = ""; [SerializeField] private List<string> ignoreFilesModify = new List<string>(); [SerializeField] private List<string> ignoreFoldersModify = new List<string>(); [SerializeField] private string ignorePatternAdd = ""; [SerializeField] private List<string> ignoreFilesAdd = new List<string>(); [SerializeField] private List<string> ignoreFoldersAdd = new List<string>(); [SerializeField] private string ignorePatternDelete = ""; [SerializeField] private List<string> ignoreFilesDelete = new List<string>(); [SerializeField] private List<string> ignoreFoldersDelete = new List<string>();
[SerializeField] private Vector2 scrollPos = Vector2.zero; private GUIContent content = new GUIContent(); private StringBuilder stringBuilder = new StringBuilder(); private GUIContent GetGUIContent(string text, Texture image, string tooltip) { content.text = text; content.image = image; content.tooltip = tooltip; return content; } private void InitConfigData() { if(SvnFilterData.Load(out var data)) { careerSelectedIdx = data.careerIndex; AddWorkDir(_workDir, data.ignoreFilesModify, ref ignoreFilesModify); AddWorkDir(_workDir, data.ignoreFoldersModify, ref ignoreFoldersModify); PatternCombine(data.ignorePatternModify, ref ignorePatternModify); AddWorkDir(_workDir, data.ignoreFilesAdd, ref ignoreFilesAdd); AddWorkDir(_workDir, data.ignoreFoldersAdd, ref ignoreFoldersAdd); PatternCombine(data.ignorePatternAdd, ref ignorePatternAdd); AddWorkDir(_workDir, data.ignoreFilesDelete, ref ignoreFilesDelete); AddWorkDir(_workDir, data.ignoreFoldersDelete, ref ignoreFoldersDelete); PatternCombine(data.ignorePatternDelete, ref ignorePatternDelete); } } void PatternSplit(string pattern, ref List<string> patternList) { patternList.Clear(); var slpits = pattern.Split(' "); foreach(var v in splits) { if(string.IsNullOrEmpty(v)) patternList.Add(v); } } var PatternCombine(List<string> patternList, ref string pattern) { StringBuilder stringBuilder = new StringBuilder(); const string space = " "; foreach(var v in patternList) { stringBuilder.Append(v); stringBuilder.Append(space); } pattern = stringBuilder.ToString(); } void RemoveWorkDir(string workDir, List<string> org, ref List<string> dst) { dst.Clear(); workDir = string.Format("{0}/", workDir); workDir = workDir.Replace("\\","/"); for(int i = 0;i<org.Count; ++i) { dst.Add(org[i].Replace("\\", "/").Replace(workDir, "")); } } void AddWorkDir(string workDir, List<string> org, ref List<string> dst) { dst.Clear(); for(int i = 0;i<org.Count; ++i) { if(org[i].StartsWith(workDir)) dst.Add(org[i]); else dst.Add(string.Format("{0}/{1}", workDir, org[i])); } } private void OnGUI() { bool show = false; EditorGUILayout.LabelField("Base Info"); if(_svnVersion == null) { EditorGUILayout.HelpBox("never find svn!", MessageType.Error, true); } else if(_workDir == null) { EditorGUI.indentLevel += 1; GUI.enabled = false; EditorGUILayout.TextField("svn version:", _svnVersion); GUI.enabled = true; EditorGUI.indentLevel -= 1; EditorGUILayout.HelpBox("current project not in svn control", MessageType.Warning, true); } else { GUI.enabled = false; EditorGUI.indentLevel += 1; EditorGUILayout.TextField("svn version:", _svnVersion); EditorGUILayout.TextField("workDir:", _workDir); EditorGUI.indentLevel -= 1; GUILayout.Space(10); GUI.enabled = true; show = true; } GUI.enabled = show; DrawBody(); GUI.enabled = true; } void DrawBody() { EditorGUILayout.HelpBox(_tip, MessageType.Info, true); EditorGUI.BeginChangeCheck(); careerSelectedIdx = GUILayout.Toolbar(careerSelectedIdx, _tabContents); if(EditorGUI.EndChangeCheck()) { PresetConfig(careerSelectedIdx); EditorGUIUtility.editingTextField = false; }
GUI.enbaled = careerSelectedIdx != -1; GUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Ignore Setting"); if(GUILayout.Button(GetGUIContent("save", nul, "save"), GUILayout.Width(50))) { SaveConfig(careerSelectedIdx); } GUILayout.EndHorizontal();
scrollPos = GUILayout.BeginScrollView(scrollPos, EditorStyles.helpBox); Panel("Modify Ignore", ref ignorePatternModify, ref ignoreFilesModify, ref ignoreFoldersModify); Panel("Add Ignore", ref ignorePatternAdd, ref ignoreFilesAdd, ref ignoreFoldersAdd); Panel("Delete Ignore", ref ignorePatternDelete, ref ignoreFilesDelete, ref ignoreFoldersDelete); GUILayout.EndScrollView(); GUILayout.Space(10); } private void Panel(string name, ref string ignPat, ref List<string> ignFiles, ref List<string> ignFolders) { GUILayout.Space(10); EditorGUILayout.LabelField(name); EditorGUI.indentLevel += 1; ignPat = EditorGUILayout.TextField(GetGUIContent("Ignore Pattern:", null, ""), ignPat);
EditorGUILayout.LabelField("Ignore Files"); EditorGUI.indentLevel += 1; int removeIdx = -1; for(int i = 0;i<ignFiles.Count; ++i) { EditorGUILayout.BeginHorizontal(); GUI.enabled = false; EditorGUILayout.TextTield(GetGUIContent("Ignore Files:", null, ""), ignFiles[i]); GUI.enabled = true; if(GUILayout.Button("-", GUILayout.Width(20))) removeIdx = i; EditorGUILayout.EndHorizontal(); } if(removeIdx != -1) { ignFiles.RemoveAt(removeIdx); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(24)); if(GUILayout.Button(GetGUIContent("Add File", null, ""))) { string file = EditorUtility.OpenFilePanel("Select File", _workDir, null); if(file.Contens(_workDir) &&!ignFiles.Contents(file)) ignFiles.Add(file); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel -= 1;
EditorGUILayout.LabelField("Ignore Folders"); EditorGUI.indentLevel += 1; removeIdx = -1; for(int i = 0;i<ignFolders.Count; ++i) { EditorGUILayout.BeginHorizontal(); GUI.enabled = false; EditorGUILayout.TextTield(GetGUIContent("Ignore Folders:", null, ""), ignFolders[i]); GUI.enabled = true; if(GUILayout.Button("-", GUILayout.Width(20))) removeIdx = i; EditorGUILayout.EndHorizontal(); } if(removeIdx != -1) { ignFolders.RemoveAt(removeIdx); } EditorGUILayout.BeginHorizontal(); GUILayout.Label("", GUILayout.Width(24)); if(GUILayout.Button(GetGUIContent("Add Folder", null, ""))) { string file = EditorUtility.OpenFolderPanel("Select Folder", _workDir, null); if(file.Contens(_workDir) &&!ignFolders.Contents(file)) ignFolders.Add(file); } EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel -= 1; }
private void PresetConfig(int careerIndex) { string career = _careers[careerIndex]; stringBuilder.Clear(); stringBuilder.Append(defaultPattern); switch(career) { case "Artist": break; case "Tester": case "Programmer": case "Designer": { stringBuilder.Append(".mat .anim .png .jpg"); } } ignorePatternModify = stringBuilder.ToString(); ignoreFilesModify.Clear(); ignoreFoldersModify.Clear(); ignorePatternAdd = stringBuilder.ToString(); ignoreFilesAdd.Clear(); ignoreFoldersAdd.Clear(); ignorePatternDelete = stringBuilder.ToString(); ignoreFilesDelete.Clear(); ignoreFoldersDelete.Clear(); }
private void SaveConfig(int careerIndex) { SvnFilterData data = new SvnFilterData(); data.careerIndex = careerIndex; RemoveWorkDir(_workDir, ignoreFilesModify, ref data.ignoreFilesModify); RemoveWorkDir(_workDir, ignoreFoldersModify, ref data.ignoreFoldersModify); PatternSplit(ignorePatternModify, ref data.ignorePatternModify); RemoveWorkDir(_workDir, ignoreFilesAdd, ref data.ignoreFilesAdd); RemoveWorkDir(_workDir, ignoreFoldersAdd, ref data.ignoreFoldersAdd); PatternSplit(ignorePatternAdd, ref data.ignorePatternAdd); RemoveWorkDir(_workDir, ignoreFilesDelete, ref data.ignoreFilesDelete); RemoveWorkDir(_workDir, ignoreFoldersDelete, ref data.ignoreFoldersDelete); PatternSplit(ignorePatternDelete, ref data.ignorePatternDelete); } } }
|