public IEnumerable <string> GetPathWithMeta(string path) { if (UniGitPathHelper.IsMetaPath(path)) { string assetPath = AssetPathFromMeta(path); yield return(path); //if the asset belonging to the meta file is a folder just return the meta if (IsDirectory(assetPath)) { yield break; } if (!string.IsNullOrEmpty(assetPath)) { yield return(assetPath); } } else { string metaPath = MetaPathFromAsset(path); //if the path is a directory then return only it's meta path if (IsDirectory(path)) { yield return(metaPath); yield break; } if (!string.IsNullOrEmpty(metaPath)) { yield return(path); yield return(metaPath); } } }
public static string AssetPathFromMeta(string metaPath) { if (UniGitPathHelper.IsMetaPath(metaPath)) { return(metaPath.Substring(0, metaPath.Length - 5)); } return(metaPath); }
public bool IsEmptyFolderMeta(string path) { if (UniGitPathHelper.IsMetaPath(path)) { return(IsEmptyFolder(path.Substring(0, path.Length - 5))); } return(false); }
internal void Add(GitStatusEntry entry, IComparer <StatusListEntry> sorter) { StatusListEntry statusEntry; if (UniGitPathHelper.IsMetaPath(entry.LocalPath)) { string mainAssetPath = GitManager.AssetPathFromMeta(entry.LocalPath); if (!gitSettings.ShowEmptyFolders && gitManager.IsEmptyFolder(mainAssetPath)) { return; } int index = entries.FindIndex(e => e.LocalPath == mainAssetPath); if (index >= 0) { StatusListEntry ent = entries[index]; ent.MetaChange |= MetaChangeEnum.Meta; ent.State |= entry.Status; entries[index] = ent; return; } statusEntry = new StatusListEntry(mainAssetPath, entry.Status, MetaChangeEnum.Meta, CalculateFlags(entry)); } else { int index = entries.FindIndex(e => e.LocalPath == entry.LocalPath); if (index >= 0) { StatusListEntry ent = entries[index]; ent.State |= entry.Status; entries[index] = ent; return; } statusEntry = new StatusListEntry(entry.LocalPath, entry.Status, MetaChangeEnum.Object, CalculateFlags(entry)); } if (sorter != null) { AddSorted(statusEntry, sorter); } else { entries.Add(statusEntry); } }
private void DrawTreeEntry(Tree tree, int depth) { foreach (var file in tree) { if (file.TargetType == TreeEntryTargetType.Tree) { EditorGUI.indentLevel = depth; EditorGUILayout.LabelField(Path.GetFileName(file.Path)); DrawTreeEntry(file.Target as Tree, depth + 1); } else if (!UniGitPathHelper.IsMetaPath(file.Path)) { EditorGUI.indentLevel = depth; EditorGUILayout.LabelField(file.Path); } } }
public bool CheckoutNotifyHandler(string path, CheckoutNotifyFlags notifyFlags) { if (gitSettings.CreateFoldersForDriftingMeta) { if (UniGitPathHelper.IsMetaPath(path)) { string assetPath = AssetPathFromMeta(path); string rootedAssetPath = Path.Combine(paths.RepoPath, assetPath); if (!Path.HasExtension(assetPath) && !File.Exists(rootedAssetPath) && !Directory.Exists(rootedAssetPath)) { Directory.CreateDirectory(rootedAssetPath); logger.LogFormat(LogType.Log, "Folder '{0}' created for drifting '{1}' file.", assetPath, path); } } } return(true); }
public void RemoveRange(string[] paths) { foreach (var path in paths) { if (UniGitPathHelper.IsMetaPath(path)) { var assetPath = GitManager.AssetPathFromMeta(path); for (int i = entries.Count - 1; i >= 0; i--) { var entry = entries[i]; if (entry.LocalPath == assetPath) { if (entry.MetaChange.HasFlag(MetaChangeEnum.Object)) { entry.MetaChange = entry.MetaChange.ClearFlags(MetaChangeEnum.Meta); entries[i] = entry; } else { entries.RemoveAt(i); } } } } else { for (int i = entries.Count - 1; i >= 0; i--) { var entry = entries[i]; if (entry.LocalPath == path) { if (entry.MetaChange.HasFlag(MetaChangeEnum.Meta)) { entry.MetaChange = entry.MetaChange.ClearFlags(MetaChangeEnum.Object); entries[i] = entry; } else { entries.RemoveAt(i); } } } } } }
public override void OnGUI(Rect rect) { EditorGUILayout.Space(); float msgHeight = commitMessageStyle.CalcHeight(GitGUI.GetTempContent(commit.Message), rect.width); scroll = EditorGUILayout.BeginScrollView(scroll); EditorGUILayout.LabelField(GitGUI.GetTempContent(commit.Message), commitMessageStyle, GUILayout.Height(msgHeight)); if (changes != null) { foreach (var change in changes) { //EditorGUILayout.BeginHorizontal(); //GUILayout.Label(change.Status.ToString(), "AssetLabel"); EditorGUILayout.BeginHorizontal("ProjectBrowserHeaderBgTop"); GUILayout.Label(new GUIContent(gitOverlay.GetDiffTypeIcon(change.Status, true)) { tooltip = change.Status.ToString() }, GUILayout.Width(16)); GUILayout.Space(8); string[] pathChunks = change.Path.Split(Path.DirectorySeparatorChar); for (int i = 0; i < pathChunks.Length; i++) { string chunk = pathChunks[i]; if (GUILayout.Button(GitGUI.GetTempContent(chunk), GitGUI.Styles.BreadcrumMid)) { string assetPath = string.Join("/", pathChunks, 0, i + 1); if (UniGitPathHelper.IsMetaPath(assetPath)) { assetPath = GitManager.AssetPathFromMeta(assetPath); } ShowContextMenuForElement(change.Path, assetPath); } } EditorGUILayout.EndHorizontal(); } } else { DrawTreeEntry(commitTree, 0); } EditorGUILayout.Space(); EditorGUILayout.EndScrollView(); }
internal void DoFileDiff(Rect rect, StatusListEntry info, bool enabled, bool selected, GitDiffWindow window) { RectOffset elementPadding = GetElementStyle().padding; float iconSize = GetElementStyle().fixedHeight - elementPadding.vertical; float toggleSize = styles.toggle.fixedHeight; Event current = Event.current; string projectPath = gitManager.ToProjectPath(info.LocalPath); string fileName = info.Name; GitGUI.StartEnable(enabled); Rect stageToggleRect = new Rect(rect.x + rect.width - toggleSize * 2, rect.y + (rect.height - toggleSize) * 0.5f, toggleSize, toggleSize); bool canUnstage = GitManager.CanUnstage(info.State); bool canStage = GitManager.CanStage(info.State); float maxPathSize = rect.width - stageToggleRect.width - toggleSize - 21; if (current.type == EventType.Repaint) { (selected ? styles.diffElementSelected : GetElementStyle()).Draw(rect, false, false, false, false); } if (canStage && canUnstage) { maxPathSize -= stageToggleRect.width - 4; Rect stageWarnningRect = new Rect(stageToggleRect.x - stageToggleRect.width - 4, stageToggleRect.y, stageToggleRect.width, stageToggleRect.height); EditorGUIUtility.AddCursorRect(stageWarnningRect, MouseCursor.Link); if (GUI.Button(stageWarnningRect, GitGUI.IconContent("console.warnicon", "", "Unstaged changed pending. Stage to update index."), GUIStyle.none)) { string[] localPaths = gitManager.GetPathWithMeta(info.LocalPath).ToArray(); if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage)) { gitManager.AsyncStage(localPaths).onComplete += (o) => { window.Repaint(); }; } else { GitCommands.Stage(gitManager.Repository, localPaths); gitManager.MarkDirtyAuto(localPaths); } window.Repaint(); } } if (current.type == EventType.Repaint) { Object asset = null; if (UniGitPathHelper.IsPathInAssetFolder(projectPath)) { asset = AssetDatabase.LoadAssetAtPath(UniGitPathHelper.IsMetaPath(projectPath) ? GitManager.AssetPathFromMeta(projectPath) : projectPath, typeof(Object)); } string extension = Path.GetExtension(projectPath); GUIContent tmpContent = GUIContent.none; if (string.IsNullOrEmpty(extension)) { tmpContent = GitGUI.GetTempContent(styles.folderIcon, "Folder"); } if (tmpContent.image == null) { if (asset != null) { tmpContent = GitGUI.GetTempContent(string.Empty, AssetDatabase.GetCachedIcon(projectPath), asset.GetType().Name); } else { tmpContent = GitGUI.GetTempContent(styles.defaultAssetIcon, "Unknown Type"); } } float x = rect.x + elementPadding.left; GUI.Box(new Rect(x, rect.y + elementPadding.top, iconSize, iconSize), tmpContent, styles.assetIcon); x += iconSize + 8; styles.diffElementName.Draw(new Rect(x, rect.y + elementPadding.top + 2, rect.width - elementPadding.right - iconSize - rect.height, EditorGUIUtility.singleLineHeight), GitGUI.GetTempContent(fileName), false, selected, selected, false); x = rect.x + elementPadding.left + iconSize + 8; foreach (var diffTypeIcon in gitOverlay.GetDiffTypeIcons(info.State, false)) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), diffTypeIcon, GUIStyle.none); x += 25; } if (info.MetaChange == (MetaChangeEnum.Object | MetaChangeEnum.Meta)) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.objectIconSmall.image, "main asset file changed"), GUIStyle.none); x += 25; } if (info.MetaChange.IsFlagSet(MetaChangeEnum.Meta)) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.metaIconSmall.image, ".meta file changed"), GUIStyle.none); x += 25; } if (info.Flags.IsFlagSet(StatusEntryFlags.IsLfs)) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.lfsObjectIconSmall.image, "Lfs Object"), GUIStyle.none); x += 25; } if (info.Flags.IsFlagSet(StatusEntryFlags.IsSubModule)) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempContent(gitOverlay.icons.submoduleTagIconSmall.image, "Sub Module"), GUIStyle.none); x += 25; } Vector2 pathSize = styles.diffElementPath.CalcSize(GitGUI.GetTempContent(projectPath)); pathSize.x = Mathf.Min(pathSize.x, maxPathSize - x); Rect pathRect = new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight, pathSize.x, EditorGUIUtility.singleLineHeight * 2); styles.diffElementPath.Draw(pathRect, GitGUI.GetTempContent(projectPath), false, selected, selected, false); x += pathRect.width + 4; if (!enabled) { GUI.Box(new Rect(x, rect.y + elementPadding.top + EditorGUIUtility.singleLineHeight + 4, 21, 21), GitGUI.GetTempSpinAnimatedTexture(), GUIStyle.none); //spinning animation needs constant repaint if (gitSettings.AnimationType.HasFlag(GitSettingsJson.AnimationTypeEnum.Loading)) { window.Repaint(); } } } if (canUnstage || canStage) { EditorGUI.BeginChangeCheck(); EditorGUIUtility.AddCursorRect(stageToggleRect, MouseCursor.Link); EditorGUI.Toggle(stageToggleRect, canUnstage, styles.toggle); if (EditorGUI.EndChangeCheck()) { bool updateFlag = false; if (GitManager.CanStage(info.State)) { string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray(); if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Stage)) { gitManager.AsyncStage(paths).onComplete += (o) => { window.Repaint(); }; } else { GitCommands.Stage(gitManager.Repository, paths); gitManager.MarkDirtyAuto(paths); } updateFlag = true; } else if (GitManager.CanUnstage(info.State)) { string[] paths = gitManager.GetPathWithMeta(info.LocalPath).ToArray(); if (gitManager.Threading.IsFlagSet(GitSettingsJson.ThreadingType.Unstage)) { gitManager.AsyncUnstage(paths).onComplete += (o) => { window.Repaint(); }; } else { GitCommands.Unstage(gitManager.Repository, paths); gitManager.MarkDirtyAuto(paths); } updateFlag = true; } if (updateFlag) { window.Repaint(); current.Use(); } } } GitGUI.EndEnable(); }