private void CustomIcons(string guid, Rect rect)
        {
            if (statusTree == null)
            {
                return;
            }
            string path   = AssetDatabase.GUIDToAssetPath(guid);
            var    status = statusTree.GetStatus(path);

            if (status != null)
            {
                Object assetObject = AssetDatabase.LoadMainAssetAtPath(path);
                if (assetObject != null && ProjectWindowUtil.IsFolder(assetObject.GetInstanceID()))
                {
                    //exclude the Assets folder
                    if (status.Depth == 0)
                    {
                        return;
                    }
                    //todo cache expandedProjectWindowItems into a HashSet for faster Contains
                    if (!status.ForceStatus && InternalEditorUtility.expandedProjectWindowItems.Contains(assetObject.GetInstanceID()))
                    {
                        return;
                    }
                }
                DrawFileIcon(rect, GitOverlay.GetDiffTypeIcon(status.State, rect.height <= 16));
            }
        }
 public GitDiffWindowCommitRenderer(GitSettingsJson gitSettings, GitManager gitManager, GitOverlay gitOverlay, GitInitializer initializer)
 {
     this.gitSettings = gitSettings;
     this.gitManager  = gitManager;
     this.gitOverlay  = gitOverlay;
     this.initializer = initializer;
 }
 private void Construct(GitManager gitManager, GitOverlay gitOverlay, ILogger logger, GitAnimation gitAnimation)
 {
     this.gitManager   = gitManager;
     this.gitOverlay   = gitOverlay;
     this.logger       = logger;
     this.gitAnimation = gitAnimation;
 }
Exemple #4
0
 public GitDiffElementContextFactory(GitManager gitManager, GitConflictsHandler conflictsHandler, GitOverlay gitOverlay,
                                     GitExternalManager externalManager, GitCallbacks gitCallbacks)
 {
     this.gitManager       = gitManager;
     this.conflictsHandler = conflictsHandler;
     this.gitOverlay       = gitOverlay;
     this.externalManager  = externalManager;
     this.gitCallbacks     = gitCallbacks;
 }
 public GitSubModulesPopup(UniGitData data, GitOverlay gitOverlay, GitManager gitManager)
 {
     this.data       = data;
     this.gitOverlay = gitOverlay;
     this.gitManager = gitManager;
     moduleStyle     = new GUIStyle("ProjectBrowserHeaderBgTop")
     {
         wordWrap = true, fixedHeight = 0, alignment = TextAnchor.MiddleLeft
     };
 }
 public GitDiffWindowToolbarRenderer(GitManager gitManager, GitDiffElementContextFactory contextFactory,
                                     UniGitData data, InjectionHelper injectionHelper, GitSettingsJson gitSettings, GitOverlay gitOverlay, IGitPrefs prefs)
 {
     this.gitManager      = gitManager;
     this.contextFactory  = contextFactory;
     this.data            = data;
     this.injectionHelper = injectionHelper;
     this.gitSettings     = gitSettings;
     this.gitOverlay      = gitOverlay;
     this.prefs           = prefs;
     searchField          = new SearchField();
 }
        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 (assetPath.EndsWith(".meta"))
                            {
                                assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath);
                            }
                            ShowContextMenuForElement(change.Path, assetPath);
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                DrawTreeEntry(commitTree, 0);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
Exemple #8
0
        public GitCommitDetailsWindow(GitManager gitManager, GitExternalManager externalManager, Commit commit, GitOverlay gitOverlay)
        {
            this.gitManager      = gitManager;
            this.commit          = commit;
            this.externalManager = externalManager;
            this.gitOverlay      = gitOverlay;
            commitTree           = commit.Tree;
            Commit parentCommit = commit.Parents.FirstOrDefault();

            if (parentCommit != null)
            {
                changes = gitManager.Repository.Diff.Compare <TreeChanges>(parentCommit.Tree, commitTree);
            }

            commitMessageStyle = new GUIStyle("TL SelectionButton")
            {
                alignment = TextAnchor.UpperLeft, padding = new RectOffset(4, 4, 4, 4), wordWrap = true, normal = { textColor = Color.black }
            };
        }
Exemple #9
0
 private void Construct(GitExternalManager externalManager,
                        GitAsyncManager asyncManager,
                        GitOverlay gitOverlay,
                        InjectionHelper injectionHelper,
                        GitDiffWindowToolbarRenderer toolbarRenderer,
                        GitDiffElementContextFactory elementContextFactory,
                        GitDiffWindowCommitRenderer gitDiffWindowCommitRenderer,
                        GitDiffWindowDiffElementRenderer diffElementRenderer,
                        GitLfsHelper lfsHelper)
 {
     this.lfsHelper                   = lfsHelper;
     this.externalManager             = externalManager;
     this.asyncManager                = asyncManager;
     this.gitOverlay                  = gitOverlay;
     this.injectionHelper             = injectionHelper;
     this.toolbarRenderer             = toolbarRenderer;
     this.elementContextFactory       = elementContextFactory;
     this.gitDiffWindowCommitRenderer = gitDiffWindowCommitRenderer;
     this.diffElementRenderer         = diffElementRenderer;
     sorter = new GitDiffWindowSorter(this, gitManager);
 }
Exemple #10
0
        internal static void Initlize()
        {
            repoPathCached = Application.dataPath.Replace("/Assets", "").Replace("/", "\\");
            gitPathCached  = Application.dataPath.Replace("Assets", ".git");

            if (!IsValidRepo)
            {
                return;
            }

            LoadGitSettings();

            GitResourceManager.Initilize();
            GitCredentialsManager.Load();
            GitOverlay.Initlize();
            GitLfsManager.Load();
            GitHookManager.Load();
            GitExternalManager.Load();

            needsFetch                 = !EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isCompiling && !EditorApplication.isUpdating;
            repositoryDirty            = true;
            GitCallbacks.EditorUpdate += OnEditorUpdate;
        }
Exemple #11
0
 public GitStashWindow(GitManager gitManager, GitOverlay gitOverlay, GitCallbacks gitCallbacks)
 {
     this.gitManager   = gitManager;
     this.gitOverlay   = gitOverlay;
     this.gitCallbacks = gitCallbacks;
 }
        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('\\');
                    for (int i = 0; i < pathChunks.Length; i++)
                    {
                        string chunk = pathChunks[i];
                        if (GUILayout.Button(GitGUI.GetTempContent(chunk), "GUIEditor.BreadcrumbMid"))
                        {
                            string assetPath = string.Join("/", pathChunks, 0, i + 1);
                            if (assetPath.EndsWith(".meta"))
                            {
                                assetPath = AssetDatabase.GetAssetPathFromTextMetaFilePath(assetPath);
                            }
                            var asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));
                            if (asset != null)
                            {
                                Selection.activeObject = asset;
                            }
                        }
                    }
                    //GUILayout.Label(new GUIContent(" (" + change.Status + ") " + change.Path));
                    EditorGUILayout.EndHorizontal();
                    Rect r = GUILayoutUtility.GetLastRect();
                    if (Event.current.type == EventType.ContextClick && r.Contains(Event.current.mousePosition))
                    {
                        string      path = change.Path;
                        GenericMenu menu = new GenericMenu();
                        if (commit.Parents.Count() == 1)
                        {
                            menu.AddItem(new GUIContent("Difference with previous commit"), false, () =>
                            {
                                Commit parent = commit.Parents.Single();
                                GitManager.ShowDiff(path, parent, commit);
                            });
                        }
                        else
                        {
                            menu.AddDisabledItem(new GUIContent(new GUIContent("Difference with previous commit")));
                        }
                        menu.AddItem(new GUIContent("Difference with HEAD"), false, () =>
                        {
                            GitManager.ShowDiff(path, commit, GitManager.Repository.Head.Tip);
                        });
                        menu.ShowAsContext();
                    }
                    //EditorGUILayout.EndHorizontal();
                }
            }
            else
            {
                DrawTreeEntry(commitTree, 0);
            }
            EditorGUILayout.Space();
            EditorGUILayout.EndScrollView();
        }
Exemple #13
0
        static UniGitLoader()
        {
            Profiler.BeginSample("UniGit Initialization");
            try
            {
                injectionHelper = new InjectionHelper();
                GitWindows.Init();
                var recompileChecker = ScriptableObject.CreateInstance <AssemblyReloadScriptableChecker>();
                recompileChecker.OnBeforeReloadAction = OnBeforeAssemblyReload;

                string repoPath     = Application.dataPath.Replace(UniGitPath.UnityDeirectorySeparatorChar + "Assets", "").Replace(UniGitPath.UnityDeirectorySeparatorChar, Path.DirectorySeparatorChar);
                string settingsPath = UniGitPath.Combine(repoPath, ".git", "UniGit", "Settings.json");

                injectionHelper.Bind <string>().FromInstance(repoPath).WithId("repoPath");
                injectionHelper.Bind <string>().FromInstance(settingsPath).WithId("settingsPath");

                injectionHelper.Bind <GitCallbacks>().FromMethod(() =>
                {
                    var c = new GitCallbacks();
                    EditorApplication.update += c.IssueEditorUpdate;
                    c.RefreshAssetDatabase   += AssetDatabase.Refresh;
                    c.SaveAssetDatabase      += AssetDatabase.SaveAssets;
                    EditorApplication.projectWindowItemOnGUI += c.IssueProjectWindowItemOnGUI;
                    //asset postprocessing
                    GitAssetPostprocessors.OnWillSaveAssetsEvent            += c.IssueOnWillSaveAssets;
                    GitAssetPostprocessors.OnPostprocessImportedAssetsEvent += c.IssueOnPostprocessImportedAssets;
                    GitAssetPostprocessors.OnPostprocessDeletedAssetsEvent  += c.IssueOnPostprocessDeletedAssets;
                    GitAssetPostprocessors.OnPostprocessMovedAssetsEvent    += c.IssueOnPostprocessMovedAssets;
                    return(c);
                });
                injectionHelper.Bind <IGitPrefs>().To <UnityEditorGitPrefs>();
                injectionHelper.Bind <GitManager>();
                injectionHelper.Bind <GitSettingsJson>();
                injectionHelper.Bind <GitSettingsManager>();
                injectionHelper.Bind <GitAsyncManager>();

                GitManager = injectionHelper.GetInstance <GitManager>();
                GitManager.Callbacks.RepositoryCreate += OnRepositoryCreate;

                GitUnityMenu.Init(GitManager);
                GitResourceManager.Initilize();
                GitOverlay.Initlize();

                //credentials
                injectionHelper.Bind <ICredentialsAdapter>().To <WincredCredentialsAdapter>();
                injectionHelper.Bind <GitCredentialsManager>();
                //externals
                injectionHelper.Bind <IExternalAdapter>().To <GitExtensionsAdapter>();
                injectionHelper.Bind <IExternalAdapter>().To <TortoiseGitAdapter>();
                injectionHelper.Bind <GitExternalManager>();
                injectionHelper.Bind <GitLfsManager>();
                //hooks
                injectionHelper.Bind <GitPushHookBase>().To <GitLfsPrePushHook>();
                injectionHelper.Bind <GitHookManager>();
                //helpers
                injectionHelper.Bind <GitLfsHelper>();
                injectionHelper.Bind <FileLinesReader>();
                //project window overlays
                injectionHelper.Bind <GitProjectOverlay>();

                if (!Repository.IsValid(repoPath))
                {
                    EditorApplication.delayCall += OnDelayedInit;
                }
                else
                {
                    Rebuild(injectionHelper);
                    EditorApplication.delayCall += OnDelayedInit;
                }
            }
            finally
            {
                Profiler.EndSample();
            }
        }
Exemple #14
0
        public GitProjectOverlay(GitManager gitManager,
                                 GitCallbacks gitCallbacks,
                                 GitSettingsJson gitSettings,
                                 GitAsyncManager asyncManager,
                                 GitReflectionHelper reflectionHelper,
                                 GitOverlay gitOverlay,
                                 IGitPrefs prefs,
                                 UniGitData data,
                                 ILogger logger,
                                 InjectionHelper injectionHelper,
                                 [UniGitInjectOptional] bool cullNonAssetPaths = true)
        {
            if (iconStyle == null)
            {
                iconStyle = new GUIStyle
                {
                    imagePosition = ImagePosition.ImageOnly,
                    alignment     = TextAnchor.LowerLeft,
                    padding       = new RectOffset(2, 2, 2, 2)
                };
                lineStyle = new GUIStyle(EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IN Title"))
                {
                    padding       = new RectOffset(),
                    margin        = new RectOffset(),
                    contentOffset = Vector2.zero,
                    fixedHeight   = 0,
                    fixedWidth    = 0,
                    border        = { left = 0, right = 0 }
                };
            }

            this.logger            = logger;
            this.data              = data;
            this.gitManager        = gitManager;
            this.gitSettings       = gitSettings;
            this.asyncManager      = asyncManager;
            this.gitCallbacks      = gitCallbacks;
            this.reflectionHelper  = reflectionHelper;
            this.gitOverlay        = gitOverlay;
            this.prefs             = prefs;
            this.cullNonAssetPaths = cullNonAssetPaths;
            this.injectionHelper   = injectionHelper;

            gitManager.AddWatcher(this);

            gitCallbacks.EditorUpdate           += OnEditorUpdate;
            gitCallbacks.ProjectWindowItemOnGUI += CustomIcons;
            gitCallbacks.UpdateRepository       += OnUpdateRepository;

            //project browsers only get created before delay call but not before constructor
            gitCallbacks.DelayCall += () =>
            {
                projectWindows = new List <EditorWindow>(Resources.FindObjectsOfTypeAll(reflectionHelper.ProjectWindowType).Cast <EditorWindow>());
            };

            //shortcut to getting instance id without loading asset
            var method = typeof(AssetDatabase).GetMethod("GetMainAssetOrInProgressProxyInstanceID", BindingFlags.NonPublic | BindingFlags.Static);

            if (method != null)
            {
                GetMainAssetOrInProgressProxyInstanceID = (Func <string, int>)Delegate.CreateDelegate(typeof(Func <string, int>), method);
            }
        }
 private void Construct(GitManager gitManager, GitOverlay gitOverlay)
 {
     this.gitManager = gitManager;
     this.gitOverlay = gitOverlay;
 }