Exemplo n.º 1
0
        protected override void OnInit()
        {
            KeyDic.Add(new ShortCut(KeyCode.U, "Change Stage", ChangeStage));
            KeyDic.Add(new ShortCut(KeyCode.R, "Refresh", item => Refresh(TreeView.GetSelectionIndex())));
            KeyDic.Add(new ShortCut(KeyCode.Z, "Undo", ChangeUndo));
            KeyDic.Add(new ShortCut(KeyCode.Return, "Show Diff", item => {
                if (item.depth != 1)
                {
                    return;
                }
                var param = new DiffParam();
                param.SetFile(item.displayName, item.Status == GitStatusType.Stage);
                GUI.OpenSub(ModuleType.Diff, param);
            }));
            KeyDic.Add(new ShortCut(KeyCode.T, "Target", item =>
            {
                if (item.depth != 1)
                {
                    return;
                }

                // スクリプト
                if (item.displayName.EndsWith(".cs"))
                {
                    InternalEditorUtility.OpenFileAtLineExternal(item.displayName, 0);

                    return;
                }

                var asset         = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(item.displayName);
                Selection.objects = new[] { asset };
            }));
        }
Exemplo n.º 2
0
        private List <TreeViewItem> GetDiffList(DiffParam param)
        {
            var line     = 0;
            var filePath = param.Str;

            return(GetDiff("\'" + param.Str + "\'", "\'" + param.PrevFileName + "\'", param.IsStaged)
                   .Select((l, i) =>
            {
                if (l.StartsWith("@@"))
                {
                    var index = l.IndexOf("+");
                    var s = l.Substring(index + 1);
                    index = s.IndexOf(",");
                    if (int.TryParse(s.Substring(0, index), out line))
                    {
                        line--;
                    }
                }
                else if (!l.StartsWith("-"))
                {
                    line++;
                }
                return new GitTreeViewItem()
                {
                    id = i,
                    displayName = l,
                    depth = 0,
                    FilePath = filePath,
                    FileLine = line,
                };
            })
                   .Cast <TreeViewItem>()
                   .ToList());
        }
Exemplo n.º 3
0
        protected override void OnInit()
        {
            KeyDic.Add(new ShortCut(KeyCode.Return, "Show Diff", item =>
            {
                var param = new DiffParam();
                param.SetHash(item.displayName);
                GUI.OpenSub(ModuleType.Diff, param);
            }));
            KeyDic.Add(new ShortCut(KeyCode.R, "Reload", item => OnEnter(CurrentBranch())));
            KeyDic.Add(new ShortCut(KeyCode.P, "Push", item =>
            {
                var branch = CurrentBranch();
                if (EditorUtility.DisplayDialog("Warning", $"Try to Push \"{branch}\" ?", "Yes", "No"))
                {
                    Push(branch);
                    OnEnter(branch);
                }
            }));
            KeyDic.Add(new ShortCut(KeyCode.F, "Pull", item =>
            {
                var cb = CurrentBranch();
                if (cb.StartsWith("origin/"))
                {
                    return;
                }

                var output = GetStatus();
                // 差分があった場合
                if (output.Count() - GetUntrack(output).Count() > 0)
                {
                    if (!EditorUtility.DisplayDialog(
                            "Warning",
                            "There is a diff, want to pull rebase?",
                            "Yes",
                            "No"))
                    {
                        return;
                    }

                    var o2 = Stash();
                    EditorUtility.DisplayDialog("Info", o2, "Ok");
                }

                var o3 = PullRebase(cb);
                EditorUtility.DisplayDialog("Info", o3, "Ok");
                OnEnter(cb);
            }));
        }
Exemplo n.º 4
0
        private List <TreeViewItem> GetLogList(DiffParam param)
        {
            var mode     = 0;
            var filePath = "";
            var line     = 0;

            return(GetShow(param.Str)
                   .Select((l, i) =>
            {
                if (mode == 0)
                {
                    if (!l.Contains("files changed,") && !l.Contains("file changed,"))
                    {
                        var index = l.IndexOf("|");
                        filePath = l.Substring(0, index).Trim();
                    }
                    else
                    {
                        mode++;
                    }
                }
                else if (mode == 1)
                {
                    filePath = "";
                    mode++;
                }
                else if (mode == 2)
                {
                    if (l.StartsWith("+++ b/"))
                    {
                        var index = l.IndexOf("+++ b/") + 7;
                        filePath = l.Substring(index);
                        line = 0;
                    }
                    else if (l.StartsWith("@@"))
                    {
                        var index = l.IndexOf("+");
                        var s = l.Substring(index + 1);
                        index = s.IndexOf(",");
                        if (int.TryParse(s.Substring(0, index), out line))
                        {
                            line--;
                        }
                    }
                    else if (!l.StartsWith("-"))
                    {
                        line++;
                    }
                }

                return new GitTreeViewItem()
                {
                    id = i,
                    displayName = l,
                    depth = 0,
                    FilePath = filePath,
                    FileLine = line,
                };
            })
                   .Cast <TreeViewItem>()
                   .ToList());
        }