Ejemplo n.º 1
0
        public void ShowDiff(Commit commit)
        {
            if (ListBox.SelectedItems.Count < 2)
            {
                diffService.ShowDiffAsync(commit.RealCommitSha).RunInBackground();
            }
            else
            {
                CommitViewModel topCommit    = ListBox.SelectedItems[0] as CommitViewModel;
                int             bottomIndex  = ListBox.SelectedItems.Count - 1;
                CommitViewModel bottomCommit = ListBox.SelectedItems[bottomIndex] as CommitViewModel;

                if (topCommit != null && bottomCommit != null)
                {
                    // Selection was made with ctrl-click. Lets take top and bottom commits as range
                    // even if there are more commits in the middle
                    CommitSha id1 = topCommit.Commit.RealCommitSha;
                    CommitSha id2 = bottomCommit.Commit.HasFirstParent
                                                ? bottomCommit.Commit.FirstParent.RealCommitSha
                                                : bottomCommit.Commit.RealCommitSha;

                    diffService.ShowDiffRangeAsync(id1, id2).RunInBackground();
                }
                else if (topCommit != null)
                {
                    // Selection was probably done with shift-click. Fore some reason SelectedItems
                    // only contains first selected item, other items are null, but there are one null
                    // item for each selected item plus one extra.
                    // Find the range by iterating first parents of the top commit (selected items count)
                    Commit current = topCommit.Commit;
                    for (int i = 0; i < bottomIndex; i++)
                    {
                        if (!current.HasFirstParent)
                        {
                            break;
                        }
                        current = current.FirstParent;
                    }

                    CommitSha id1 = topCommit.Commit.RealCommitSha;
                    CommitSha id2 = current.RealCommitSha;
                    diffService.ShowDiffRangeAsync(id1, id2).RunInBackground();;
                }
            }
        }
Ejemplo n.º 2
0
        public void MouseEnterBranch(BranchViewModel branch, Point viewPoint)
        {
            branch.SetHighlighted();
            CommitViewModel commitViewModel = TryGetCommitAt(viewPoint);

            if (commitViewModel != null)
            {
                int index = Commits.IndexOf(commitViewModel);
                for (int i = index; i > -1; i--)
                {
                    if (Commits[i].Commit.Branch.Name == branch.Branch.Name)
                    {
                        branch.MouseOnCommit(Commits[i].Commit);
                        break;
                    }
                }
            }

            if (branch.Branch.IsLocalPart)
            {
                // Local part branch, then do not dim common commits in main branch part
                foreach (CommitViewModel commit in Commits)
                {
                    if (commit.Commit.Branch.Id != branch.Branch.Id &&
                        !(commit.Commit.IsCommon &&
                          commit.Commit.Branch.IsMainPart &&
                          commit.Commit.Branch.LocalSubBranch == branch.Branch))
                    {
                        commit.SetDim();
                    }
                }
            }
            else
            {
                // Normal branches and main branches
                foreach (CommitViewModel commit in Commits)
                {
                    if (commit.Commit.Branch.Id != branch.Branch.Id)
                    {
                        commit.SetDim();
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Clicked(Point position)
        {
            CommitViewModel commitViewModel = TryGetCommitAt(position);

            if (commitViewModel == null)
            {
                return;
            }

            double clickX     = position.X - 9;
            double clickY     = position.Y - 5;
            int    xDotCenter = commitViewModel.X;
            int    yDotCenter = commitViewModel.Y;

            double absx = Math.Abs(xDotCenter - clickX);
            double absy = Math.Abs(yDotCenter - clickY);

            if ((absx < 10) && (absy < 10))
            {
                Clicked(commitViewModel);
            }
        }
Ejemplo n.º 4
0
        private void MouseEntering(object sender, MouseEventArgs e)
        {
            ListBoxItem item = sender as ListBoxItem;

            if (item != null)
            {
                Point viewPoint = e.GetPosition(ItemsListBox);

                BranchViewModel branch = item.Content as BranchViewModel;
                if (branch != null)
                {
                    viewModel.MouseEnterBranch(branch, viewPoint);
                }

                CommitViewModel commit = item.Content as CommitViewModel;
                if (commit != null)
                {
                    if (viewPoint.X < viewModel.GraphWidth)
                    {
                        branch = viewModel.Branches.FirstOrDefault(b => b.Branch == commit.Commit.Branch);
                        if (branch != null)
                        {
                            viewModel.MouseEnterBranch(branch, viewPoint);
                        }
                    }

                    if (viewPoint.X > viewModel.GraphWidth)
                    {
                        branch = viewModel.Branches.FirstOrDefault(b => b.Branch == commit.Commit.Branch);
                        if (branch != null)
                        {
                            viewModel.MouseLeaveBranch(branch);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
 private void SetCommitsDetails(CommitViewModel commit)
 {
     CommitDetailsViewModel.CommitViewModel = commit;
 }