Exemplo n.º 1
0
        private void AddToOrderedSignDir(SortedList <string, List <RecentRepoInfo> > orderedRepos, RecentRepoInfo repoInfo, bool shortenPath)
        {
            List <RecentRepoInfo> list = null;
            bool existsShortName;

            //if there is no short name for a repo, then try to find unique caption extendig short directory path
            if (shortenPath && repoInfo.DirInfo != null)
            {
                string s = repoInfo.DirName.Substring(repoInfo.DirInfo.FullName.Length);
                s = s.Trim(Path.DirectorySeparatorChar);
                //candidate for short name
                repoInfo.Caption = repoInfo.ShortName;
                if (!s.IsNullOrEmpty())
                {
                    repoInfo.Caption += " (" + s + ")";
                }
                repoInfo.DirInfo = repoInfo.DirInfo.Parent;
            }
            else
            {
                repoInfo.Caption = repoInfo.Repo.Path;
            }

            existsShortName = orderedRepos.TryGetValue(repoInfo.Caption, out list);
            if (!existsShortName)
            {
                list = new List <RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }

            List <RecentRepoInfo> tmpList = new List <RecentRepoInfo>();

            if (existsShortName)
            {
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    RecentRepoInfo r = list[i];
                    if (!r.FullPath)
                    {
                        tmpList.Add(r);
                        list.RemoveAt(i);
                    }
                }
            }

            if (repoInfo.FullPath || !existsShortName)
            {
                list.Add(repoInfo);
            }
            else
            {
                tmpList.Add(repoInfo);
            }

            //find unique caption for repos with no title
            foreach (RecentRepoInfo r in tmpList)
            {
                AddToOrderedSignDir(orderedRepos, r, shortenPath);
            }
        }
        private bool GetSelectedRepo(object sender, out RecentRepoInfo repo)
        {
            if (sender is ContextMenuStrip)
                sender = (sender as ContextMenuStrip).SourceControl;
            else if (sender is ToolStripItem)
                return GetSelectedRepo((sender as ToolStripItem).Owner, out repo);
            else
                sender = null;

            ListBox lb;
            if (sender == MostRecentLB)
                lb = MostRecentLB;
            else if (sender == LessRecentLB)
                lb = LessRecentLB;
            else
                lb = null;

            if (lb != null)
                repo = (RecentRepoInfo)lb.SelectedItem;
            else
                repo = null;

            return repo != null;
        }
Exemplo n.º 3
0
        private void AddToOrderedMiddleDots(SortedList <string, List <RecentRepoInfo> > orderedRepos, RecentRepoInfo repoInfo)
        {
            DirectoryInfo dirInfo;

            try
            {
                dirInfo = new DirectoryInfo(repoInfo.Repo.Path);
            }
            catch (Exception)
            {
                dirInfo = null;
            }

            if (dirInfo != null)
            {
                string root       = null;
                string company    = null;
                string repository = null;
                string workingDir = null;


                workingDir = dirInfo.Name;
                dirInfo    = dirInfo.Parent;
                if (dirInfo != null)
                {
                    repository = dirInfo.Name;
                    dirInfo    = dirInfo.Parent;
                }
                bool addDots = false;

                if (dirInfo != null)
                {
                    while (dirInfo.Parent != null && dirInfo.Parent.Parent != null)
                    {
                        dirInfo = dirInfo.Parent;
                        addDots = true;
                    }
                    company = dirInfo.Name;
                    if (dirInfo.Parent != null)
                    {
                        root = dirInfo.Parent.Name;
                    }
                }


                Func <int, bool> shortenPath = delegate(int skipCount)
                {
                    bool   result = false;
                    string c      = null;
                    string r      = null;
                    if (company != null)
                    {
                        if (company.Length > skipCount)
                        {
                            c      = company.Substring(0, company.Length - skipCount);
                            result = true;
                        }
                    }

                    if (repository != null)
                    {
                        if (repository.Length > skipCount)
                        {
                            r      = repository.Substring(skipCount, repository.Length - skipCount);
                            result = true;
                        }
                    }

                    repoInfo.Caption = MakePath(root, c);
                    if (addDots)
                    {
                        repoInfo.Caption = MakePath(repoInfo.Caption, "...");
                    }

                    repoInfo.Caption = MakePath(repoInfo.Caption, r);
                    repoInfo.Caption = MakePath(repoInfo.Caption, workingDir);

                    return(result && addDots);
                };



                //if fixed width is not set then short as in pull request vccp's example
                //full "E:\CompanyName\Projects\git\ProductName\Sources\RepositoryName\WorkingDirName"
                //short "E:\CompanyName\...\RepositoryName\WorkingDirName"
                if (this.RecentReposComboMinWidth == 0)
                {
                    shortenPath(0);
                }
                //else skip symbols beginning from the middle to both sides,
                //so we'll see "E:\Compa......toryName\WorkingDirName" and "E:\...\WorkingDirName" at the end.
                else
                {
                    SizeF captionSize;
                    bool  canShorten;
                    int   skipCount = 0;
                    do
                    {
                        canShorten = shortenPath(skipCount);
                        skipCount++;
                        captionSize = graphics.MeasureString(repoInfo.Caption, measureFont);
                    }while (captionSize.Width > RecentReposComboMinWidth && canShorten);
                }
            }

            List <RecentRepoInfo> list = null;

            if (!orderedRepos.TryGetValue(repoInfo.Caption, out list))
            {
                list = new List <RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }
            list.Add(repoInfo);
        }
Exemplo n.º 4
0
        public void SplitRecentRepos(ICollection <Repository> recentRepositories, List <RecentRepoInfo> mostRecentRepoList, List <RecentRepoInfo> lessRecentRepoList)
        {
            SortedList <string, List <RecentRepoInfo> > orderedRepos = new SortedList <string, List <RecentRepoInfo> >();
            List <RecentRepoInfo> mostRecentRepos = new List <RecentRepoInfo>();
            List <RecentRepoInfo> lessRecentRepos = new List <RecentRepoInfo>();

            bool middleDot = ShorteningStrategy_MiddleDots.Equals(ShorteningStrategy);
            bool signDir   = ShorteningStrategy_MostSignDir.Equals(ShorteningStrategy);

            int n = Math.Min(MaxRecentRepositories, recentRepositories.Count);

            //the maxRecentRepositories repositories will be added at begining
            //rest will be added in alphabetical order
            foreach (Repository repository in recentRepositories)
            {
                bool mostRecent = mostRecentRepos.Count < n && repository.Anchor == Repository.RepositoryAnchor.None ||
                                  repository.Anchor == Repository.RepositoryAnchor.MostRecent;
                RecentRepoInfo ri = new RecentRepoInfo(repository, mostRecent);
                if (ri.MostRecent)
                {
                    mostRecentRepos.Add(ri);
                }
                else
                {
                    lessRecentRepos.Add(ri);
                }
                if (middleDot)
                {
                    AddToOrderedMiddleDots(orderedRepos, ri);
                }
                else
                {
                    AddToOrderedSignDir(orderedRepos, ri, signDir);
                }
            }
            int r = mostRecentRepos.Count - 1;

            //remove not anchored repos if there is more than maxRecentRepositories repos
            while (mostRecentRepos.Count > n && r >= 0)
            {
                var repo = mostRecentRepos[r];
                if (repo.Repo.Anchor == Repository.RepositoryAnchor.MostRecent)
                {
                    r--;
                }
                else
                {
                    repo.MostRecent = false;
                    mostRecentRepos.RemoveAt(r);
                }
            }


            Action <bool, List <RecentRepoInfo> > addSortedRepos = delegate(bool mostRecent, List <RecentRepoInfo> addToList)
            {
                foreach (string caption in orderedRepos.Keys)
                {
                    List <RecentRepoInfo> list = orderedRepos[caption];
                    foreach (RecentRepoInfo repo in list)
                    {
                        if (repo.MostRecent == mostRecent)
                        {
                            addToList.Add(repo);
                        }
                    }
                }
            };

            Action <List <RecentRepoInfo>, List <RecentRepoInfo> > addNotSortedRepos = delegate(List <RecentRepoInfo> list, List <RecentRepoInfo> addToList)
            {
                foreach (RecentRepoInfo repo in list)
                {
                    addToList.Add(repo);
                }
            };

            if (SortMostRecentRepos)
            {
                addSortedRepos(true, mostRecentRepoList);
            }
            else
            {
                addNotSortedRepos(mostRecentRepos, mostRecentRepoList);
            }

            if (SortLessRecentRepos)
            {
                addSortedRepos(false, lessRecentRepoList);
            }
            else
            {
                addNotSortedRepos(lessRecentRepos, lessRecentRepoList);
            }
        }
Exemplo n.º 5
0
        private void AddToOrderedMiddleDots(SortedList <string, List <RecentRepoInfo> > orderedRepos, RecentRepoInfo repoInfo)
        {
            DirectoryInfo dirInfo;

            try
            {
                dirInfo = new DirectoryInfo(repoInfo.Repo.Path);
            }
            catch (Exception)
            {
                dirInfo = null;
            }

            if (dirInfo == null)
            {
                repoInfo.Caption = repoInfo.Repo.Path;
                if (repoInfo.Caption.IsNullOrEmpty())
                {
                    repoInfo.Caption = repoInfo.Repo.Title ?? string.Empty;
                }
            }
            else
            {
                string root       = null;
                string company    = null;
                string repository = null;
                var    workingDir = dirInfo.Name;

                dirInfo = dirInfo.Parent;
                if (dirInfo != null)
                {
                    repository = dirInfo.Name;
                    dirInfo    = dirInfo.Parent;
                }

                bool addDots = false;

                if (dirInfo != null)
                {
                    while (dirInfo.Parent?.Parent != null)
                    {
                        dirInfo = dirInfo.Parent;
                        addDots = true;
                    }

                    company = dirInfo.Name;
                    if (dirInfo.Parent != null)
                    {
                        root = dirInfo.Parent.Name;
                    }
                }

                void ShortenPathWithCompany(int skipCount)
                {
                    string c = null;
                    string r = null;

                    if (company?.Length > skipCount)
                    {
                        c = company.Substring(0, company.Length - skipCount);
                    }

                    if (repository?.Length > skipCount)
                    {
                        r = repository.Substring(skipCount, repository.Length - skipCount);
                    }

                    repoInfo.Caption = MakePath(root, c);

                    if (addDots)
                    {
                        repoInfo.Caption = MakePath(repoInfo.Caption, "..");
                    }

                    repoInfo.Caption = MakePath(repoInfo.Caption, r);
                    repoInfo.Caption = MakePath(repoInfo.Caption, workingDir);
                }

                bool ShortenPath(int skipCount)
                {
                    string path    = repoInfo.Repo.Path;
                    string fistDir = (root ?? company) ?? repository;
                    string lastDir = workingDir;

                    if (fistDir != null && path.Length - lastDir.Length - fistDir.Length - skipCount > 0)
                    {
                        int middle     = ((path.Length - lastDir.Length) / 2) + ((path.Length - lastDir.Length) % 2);
                        int leftEnd    = middle - (skipCount / 2);
                        int rightStart = middle + (skipCount / 2) + (skipCount % 2);

                        if (leftEnd == rightStart)
                        {
                            repoInfo.Caption = path;
                        }
                        else
                        {
                            repoInfo.Caption = path.Substring(0, leftEnd) + ".." + path.Substring(rightStart, path.Length - rightStart);
                        }

                        return(true);
                    }

                    return(false);
                }

                // if fixed width is not set then short as in pull request vccp's example
                // full "E:\CompanyName\Projects\git\ProductName\Sources\RepositoryName\WorkingDirName"
                // short "E:\CompanyName\...\RepositoryName\WorkingDirName"
                if (RecentReposComboMinWidth == 0)
                {
                    ShortenPathWithCompany(0);
                }

                // else skip symbols beginning from the middle to both sides,
                // so we'll see "E:\Compa...toryName\WorkingDirName" and "E:\...\WorkingDirName" at the end.
                else
                {
                    SizeF captionSize;
                    bool  canShorten;
                    int   skipCount = 0;
                    do
                    {
                        canShorten = ShortenPath(skipCount);
                        skipCount++;
                        captionSize = Graphics.MeasureString(repoInfo.Caption, MeasureFont);
                    }while (captionSize.Width > RecentReposComboMinWidth - 10 && canShorten);
                }
            }

            if (!orderedRepos.TryGetValue(repoInfo.Caption, out var list))
            {
                list = new List <RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }

            list.Add(repoInfo);
        }
Exemplo n.º 6
0
        public void SplitRecentRepos(IReadOnlyList <Repository> recentRepositories, List <RecentRepoInfo> mostRecentRepoList, List <RecentRepoInfo> lessRecentRepoList)
        {
            var orderedRepos    = new SortedList <string, List <RecentRepoInfo> >();
            var mostRecentRepos = new List <RecentRepoInfo>();
            var lessRecentRepos = new List <RecentRepoInfo>();

            bool middleDot = ShorteningStrategy == ShorteningStrategy_MiddleDots;
            bool signDir   = ShorteningStrategy == ShorteningStrategy_MostSignDir;

            int n = Math.Min(MaxRecentRepositories, recentRepositories.Count);

            // the maxRecentRepositories repositories will be added at beginning
            // rest will be added in alphabetical order
            foreach (Repository repository in recentRepositories)
            {
                bool mostRecent = (mostRecentRepos.Count < n && repository.Anchor == Repository.RepositoryAnchor.None) ||
                                  repository.Anchor == Repository.RepositoryAnchor.MostRecent;
                RecentRepoInfo ri = new RecentRepoInfo(repository, mostRecent);
                if (ri.MostRecent)
                {
                    mostRecentRepos.Add(ri);
                }
                else
                {
                    lessRecentRepos.Add(ri);
                }

                if (middleDot)
                {
                    AddToOrderedMiddleDots(orderedRepos, ri);
                }
                else
                {
                    AddToOrderedSignDir(orderedRepos, ri, signDir);
                }
            }

            int r = mostRecentRepos.Count - 1;

            // remove not anchored repos if there is more than maxRecentRepositories repos
            while (mostRecentRepos.Count > n && r >= 0)
            {
                var repo = mostRecentRepos[r];
                if (repo.Repo.Anchor == Repository.RepositoryAnchor.MostRecent)
                {
                    r--;
                }
                else
                {
                    repo.MostRecent = false;
                    mostRecentRepos.RemoveAt(r);
                }
            }

            void AddSortedRepos(bool mostRecent, List <RecentRepoInfo> addToList)
            {
                addToList.AddRange(
                    from caption in orderedRepos.Keys
                    from repo in orderedRepos[caption]
                    where repo.MostRecent == mostRecent
                    select repo);
            }

            void AddNotSortedRepos(List <RecentRepoInfo> list, List <RecentRepoInfo> addToList)
            {
                addToList.AddRange(list);
            }

            if (SortMostRecentRepos)
            {
                AddSortedRepos(true, mostRecentRepoList);
            }
            else
            {
                AddNotSortedRepos(mostRecentRepos, mostRecentRepoList);
            }

            if (SortLessRecentRepos)
            {
                AddSortedRepos(false, lessRecentRepoList);
            }
            else
            {
                AddNotSortedRepos(lessRecentRepos, lessRecentRepoList);
            }
        }
Exemplo n.º 7
0
        private void AddToOrderedSignDir(SortedList<string, List<RecentRepoInfo>> orderedRepos, RecentRepoInfo repoInfo, bool shortenPath)
        {
            List<RecentRepoInfo> list = null;
            bool existsShortName;
            //if there is no short name for a repo, then try to find unique caption extendig short directory path
            if (shortenPath)
            {
                if (repoInfo.DirInfo != null)
                {
                    string s = repoInfo.DirName.Substring(repoInfo.DirInfo.FullName.Length);
                    s = s.Trim(Path.DirectorySeparatorChar);
                    //candidate for short name
                    repoInfo.Caption = repoInfo.ShortName;
                    if (!s.IsNullOrEmpty())
                        repoInfo.Caption += " (" + s + ")";
                    repoInfo.DirInfo = repoInfo.DirInfo.Parent;
                }
            }
            else
                repoInfo.Caption = repoInfo.Repo.Path;

            existsShortName = orderedRepos.TryGetValue(repoInfo.Caption, out list);
            if (!existsShortName)
            {
                list = new List<RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }

            List<RecentRepoInfo> tmpList = new List<RecentRepoInfo>();
            if (existsShortName)
                for (int i = list.Count - 1; i >= 0; i--)
                {
                    RecentRepoInfo r = list[i];
                    if (!r.FullPath)
                    {
                        tmpList.Add(r);
                        list.RemoveAt(i);
                    }
                }

            if (repoInfo.FullPath || !existsShortName)
                list.Add(repoInfo);
            else
                tmpList.Add(repoInfo);

            //find unique caption for repos with no title
            foreach (RecentRepoInfo r in tmpList)
                AddToOrderedSignDir(orderedRepos, r, shortenPath);
        }
Exemplo n.º 8
0
        private void AddToOrderedMiddleDots(SortedList<string, List<RecentRepoInfo>> orderedRepos, RecentRepoInfo repoInfo)
        {
            DirectoryInfo dirInfo;

            try
            {
                dirInfo = new DirectoryInfo(repoInfo.Repo.Path);
            }
            catch (Exception)
            {
                dirInfo = null;
            }

            if (dirInfo != null)
            {

                string root = null;
                string company = null;
                string repository = null;
                string workingDir = null;

                workingDir = dirInfo.Name;
                dirInfo = dirInfo.Parent;
                if (dirInfo != null)
                {
                    repository = dirInfo.Name;
                    dirInfo = dirInfo.Parent;
                }
                bool addDots = false;

                if (dirInfo != null)
                {
                    while (dirInfo.Parent != null && dirInfo.Parent.Parent != null)
                    {
                        dirInfo = dirInfo.Parent;
                        addDots = true;
                    }
                    company = dirInfo.Name;
                    if (dirInfo.Parent != null)
                        root = dirInfo.Parent.Name;
                }

                Func<int, bool> shortenPath = delegate(int skipCount)
                {
                    bool result = false;
                    string c = null;
                    string r = null;
                    if (company != null)
                    {
                        if (company.Length > skipCount)
                        {
                            c = company.Substring(0, company.Length - skipCount);
                            result = true;
                        }
                    }

                    if (repository != null)
                    {
                        if (repository.Length > skipCount)
                        {
                            r = repository.Substring(skipCount, repository.Length - skipCount);
                            result = true;
                        }
                    }

                    repoInfo.Caption = MakePath(root, c);
                    if (addDots)
                        repoInfo.Caption = MakePath(repoInfo.Caption, "...");

                    repoInfo.Caption = MakePath(repoInfo.Caption, r);
                    repoInfo.Caption = MakePath(repoInfo.Caption, workingDir);

                    return result && addDots;
                };

                //if fixed width is not set then short as in pull request vccp's example
                //full "E:\CompanyName\Projects\git\ProductName\Sources\RepositoryName\WorkingDirName"
                //short "E:\CompanyName\...\RepositoryName\WorkingDirName"
                if (this.RecentReposComboMinWidth == 0)
                {
                    shortenPath(0);
                }
                //else skip symbols beginning from the middle to both sides,
                //so we'll see "E:\Compa......toryName\WorkingDirName" and "E:\...\WorkingDirName" at the end.
                else
                {
                    SizeF captionSize;
                    bool canShorten;
                    int skipCount = 0;
                    do
                    {
                        canShorten = shortenPath(skipCount);
                        skipCount++;
                        captionSize = graphics.MeasureString(repoInfo.Caption, measureFont);
                    }
                    while (captionSize.Width > RecentReposComboMinWidth && canShorten);
                }
            }

            List<RecentRepoInfo> list = null;

            if (!orderedRepos.TryGetValue(repoInfo.Caption, out list))
            {
                list = new List<RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }
            list.Add(repoInfo);
        }
Exemplo n.º 9
0
        public void SplitRecentRepos(ICollection<Repository> recentRepositories, List<RecentRepoInfo> mostRecentRepoList, List<RecentRepoInfo> lessRecentRepoList)
        {
            SortedList<string, List<RecentRepoInfo>> orderedRepos = new SortedList<string, List<RecentRepoInfo>>();
            List<RecentRepoInfo> mostRecentRepos = new List<RecentRepoInfo>();
            List<RecentRepoInfo> lessRecentRepos = new List<RecentRepoInfo>();

            bool middleDot = ShorteningStrategy_MiddleDots.Equals(ShorteningStrategy);
            bool signDir = ShorteningStrategy_MostSignDir.Equals(ShorteningStrategy);

            int n = Math.Min(MaxRecentRepositories, recentRepositories.Count);
            //the maxRecentRepositories repositories will be added at begining
            //rest will be added in alphabetical order
            foreach (Repository repository in recentRepositories)
            {
                bool mostRecent = mostRecentRepos.Count < n && repository.Anchor == Repository.RepositoryAnchor.None ||
                    repository.Anchor == Repository.RepositoryAnchor.MostRecent;
                RecentRepoInfo ri = new RecentRepoInfo(repository, mostRecent);
                if (ri.MostRecent)
                    mostRecentRepos.Add(ri);
                else
                    lessRecentRepos.Add(ri);
                if (middleDot)
                    AddToOrderedMiddleDots(orderedRepos, ri);
                else
                    AddToOrderedSignDir(orderedRepos, ri, signDir);
            }
            int r = mostRecentRepos.Count - 1;
            //remove not anchored repos if there is more than maxRecentRepositories repos
            while (mostRecentRepos.Count > n && r >= 0 )
            {
                var repo = mostRecentRepos[r];
                if (repo.Repo.Anchor == Repository.RepositoryAnchor.MostRecent)
                    r--;
                else
                {
                    repo.MostRecent = false;
                    mostRecentRepos.RemoveAt(r);
                }
            }

            Action<bool, List<RecentRepoInfo>> addSortedRepos = delegate(bool mostRecent, List<RecentRepoInfo> addToList)
            {
                foreach (string caption in orderedRepos.Keys)
                {
                    List<RecentRepoInfo> list = orderedRepos[caption];
                    foreach (RecentRepoInfo repo in list)
                        if (repo.MostRecent == mostRecent)
                            addToList.Add(repo);
                }
            };

            Action<List<RecentRepoInfo>, List<RecentRepoInfo>> addNotSortedRepos = delegate(List<RecentRepoInfo> list, List<RecentRepoInfo> addToList)
            {
                foreach (RecentRepoInfo repo in list)
                    addToList.Add(repo);
            };

            if (SortMostRecentRepos)
                addSortedRepos(true, mostRecentRepoList);
            else
                addNotSortedRepos(mostRecentRepos, mostRecentRepoList);

            if (SortLessRecentRepos)
                addSortedRepos(false, lessRecentRepoList);
            else
                addNotSortedRepos(lessRecentRepos, lessRecentRepoList);
        }
Exemplo n.º 10
0
        private void AddToOrderedMiddleDots(SortedList<string, List<RecentRepoInfo>> orderedRepos, RecentRepoInfo repoInfo)
        {
            DirectoryInfo dirInfo;

            try
            {
                dirInfo = new DirectoryInfo(repoInfo.Repo.Path);
            }
            catch (Exception)
            {
                dirInfo = null;
            }

            if (dirInfo == null)
            {
                repoInfo.Caption = repoInfo.Repo.Path;
                if (repoInfo.Caption.IsNullOrEmpty())
                {
                    repoInfo.Caption = repoInfo.Repo.Title ?? string.Empty;
                }
            }
            else
            {

                string root = null;
                string company = null;
                string repository = null;
                string workingDir = null;


                workingDir = dirInfo.Name;
                dirInfo = dirInfo.Parent;
                if (dirInfo != null)
                {
                    repository = dirInfo.Name;
                    dirInfo = dirInfo.Parent;
                }
                bool addDots = false;

                if (dirInfo != null)
                {
                    while (dirInfo.Parent != null && dirInfo.Parent.Parent != null)
                    {
                        dirInfo = dirInfo.Parent;
                        addDots = true;
                    }
                    company = dirInfo.Name;
                    if (dirInfo.Parent != null)
                        root = dirInfo.Parent.Name;
                }

                Func<int, bool> shortenPathWithCompany = delegate(int skipCount)
                {
                    bool result = false;
                    string c = null;
                    string r = null;
                    if (company != null)
                    {
                        if (company.Length > skipCount)
                        {
                            c = company.Substring(0, company.Length - skipCount);
                            result = true;
                        }
                    }

                    if (repository != null)
                    {
                        if (repository.Length > skipCount)
                        {
                            r = repository.Substring(skipCount, repository.Length - skipCount);
                            result = true;
                        }
                    }

                    repoInfo.Caption = MakePath(root, c);
                    if (addDots)
                        repoInfo.Caption = MakePath(repoInfo.Caption, "..");

                    repoInfo.Caption = MakePath(repoInfo.Caption, r);
                    repoInfo.Caption = MakePath(repoInfo.Caption, workingDir);

                    return result && addDots;
                };


                Func<int, bool> shortenPath = delegate(int skipCount)
                {
                    string path = repoInfo.Repo.Path;
                    string fistDir = (root ?? company) ?? repository;
                    string lastDir = workingDir;
                    if (fistDir != null && path.Length - lastDir.Length - fistDir.Length - skipCount > 0)
                    {

                        int middle = (path.Length - lastDir.Length) / 2 + (path.Length - lastDir.Length) % 2;
                        int leftEnd = middle - skipCount / 2;
                        int rightStart = middle + skipCount / 2 + skipCount % 2;

                        if (leftEnd == rightStart)
                            repoInfo.Caption = path;
                        else
                            repoInfo.Caption = path.Substring(0, leftEnd) + ".." + path.Substring(rightStart, path.Length - rightStart);
                        return true;
                    }

                    return false;
                };

                //if fixed width is not set then short as in pull request vccp's example
                //full "E:\CompanyName\Projects\git\ProductName\Sources\RepositoryName\WorkingDirName"
                //short "E:\CompanyName\...\RepositoryName\WorkingDirName"
                if (this.RecentReposComboMinWidth == 0)
                {
                    shortenPathWithCompany(0);
                }
                //else skip symbols beginning from the middle to both sides, 
                //so we'll see "E:\Compa...toryName\WorkingDirName" and "E:\...\WorkingDirName" at the end.
                else
                {
                    SizeF captionSize;
                    bool canShorten;
                    int skipCount = 0;
                    do
                    {
                        canShorten = shortenPath(skipCount);
                        skipCount++;
                        captionSize = Graphics.MeasureString(repoInfo.Caption, MeasureFont);
                    }
                    while (captionSize.Width > RecentReposComboMinWidth - 10 && canShorten);
                }
            }

            List<RecentRepoInfo> list = null;

            if (!orderedRepos.TryGetValue(repoInfo.Caption, out list))
            {
                list = new List<RecentRepoInfo>();
                orderedRepos.Add(repoInfo.Caption, list);
            }
            list.Add(repoInfo);
        }