Exemple #1
0
        private void RenderUnstageButtons()
        {
            bool noneSelected = (stagedFileViewer.GetSelectedPaths().Count == 0);
            bool noFiles      = (stagedFiles.Count == 0);

            EditorGUILayout.BeginHorizontal();

            //UNSTAGE SELECTED
            EditorGUI.BeginDisabledGroup(noneSelected);

            if (GUILayout.Button("Unstage Selected", GUILayout.ExpandWidth(false)))
            {
                GitCore.UnstagePaths(stagedFileViewer.GetSelectedPaths(), null);
                Scan();
            }

            EditorGUI.EndDisabledGroup();

            //UNSTAGE ALL
            EditorGUI.BeginDisabledGroup(noFiles);

            if (GUILayout.Button("Unstage All", GUILayout.ExpandWidth(false)))
            {
                GitCore.UnstagePaths(GitFile.GetPaths(stagedFiles), null);
                Scan();
            }

            EditorGUI.EndDisabledGroup();

            EditorGUILayout.EndHorizontal();
        }
        public override List <string> GetSelectedPaths()
        {
            if (selectedFiles == null)
            {
                return(new List <string>());
            }

            return(GitFile.GetPaths(selectedFiles));
        }
Exemple #3
0
        /// <summary>
        /// Converts status string into two file lists - staged and unstaged
        /// TODO: Make this function generic, instead of only working for this specific use
        /// </summary>
        private void BuildStageLists(string status)
        {
            stagedFiles   = new List <GitFile>();
            unstagedFiles = new List <GitFile>();

            if (status == null)
            {
                return;
            }

            //Remove any pesky quotes
            status = status.Replace("\"", "");

            //Read status code, more info here:
            //https://www.git-scm.com/docs/git-status/1.8.5
            foreach (string s in status.Split('\n'))
            {
                //Skip any non important lines
                if (s.Length < 3)
                {
                    continue;
                }

                string filestatus = s.Substring(0, 2);
                string filepathA  = s.Substring(3, s.Length - 3);
                string filepathB  = filepathA;

                //Detect separate paths
                if (filepathA.Contains("->"))
                {
                    string[] split = filepathA.Split(new string[] { " -> " }, System.StringSplitOptions.None);
                    filepathA = split[0];
                    filepathB = split[1];
                }

                FileStatus stagedStatus   = GitFile.StatusCodeToFileStatus(filestatus[0]);
                FileStatus unstagedStatus = GitFile.StatusCodeToFileStatus(filestatus[1]);

                //Stage
                if (stagedStatus != FileStatus.unmodified &&
                    stagedStatus != FileStatus.ignored &&
                    stagedStatus != FileStatus.untracked)
                {
                    stagedFiles.Add(new GitFile(filepathA, stagedStatus));
                }

                //Unstage
                if (unstagedStatus != FileStatus.unmodified &&
                    unstagedStatus != FileStatus.ignored)
                {
                    unstagedFiles.Add(new GitFile(filepathB, unstagedStatus));
                }
            }
        }
        public override void Render(List <GitFile> files)
        {
            if (files == null)
            {
                return;
            }

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, false, GUIStyle.none, GUI.skin.verticalScrollbar);

            float statusSize = 20;

            //Render list of files
            selectedFiles = SelectableListGUI.RenderList <GitFile>(files, selectedFiles, (file, selected) =>
            {
                //Render
                EditorGUILayout.BeginHorizontal();

                GUIStyle style = new GUIStyle("Label");

                if (selected)
                {
                    style.normal.textColor = Color.blue;
                }

                //Status Icon
                if (fileStatusIcons.ContainsKey(file.status))
                {
                    GUILayout.Label(fileStatusIcons[file.status], GUILayout.Width(statusSize), GUILayout.Height(statusSize));
                }
                else
                {
                    GUILayout.Label(file.status.ToString(), GUILayout.Width(statusSize), GUILayout.Height(statusSize));
                }

                //Button
                bool pressed = GUILayout.Button(file.path, style, GUILayout.Height(statusSize));

                EditorGUILayout.EndHorizontal();
                return(pressed);
            },
                                                                   (selectedFiles, mouse) =>
            {
                //Context click
                if (mouse == 1)
                {
                    ContextOption <string> .ShowContextMenu(GitFile.GetPaths(selectedFiles), contextOptions);
                }
            });

            EditorGUILayout.EndScrollView();
        }