Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 75f0026

Browse files
authored
Merge branch 'master' into patch-1
2 parents 458f3bd + dae248e commit 75f0026

12 files changed

+303
-93
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2.5.2.{build}'
1+
version: '2.5.3.{build}'
22
skip_tags: true
33
install:
44
- ps: |

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,21 @@ public class PullRequestService : IPullRequestService
4141

4242
readonly IGitClient gitClient;
4343
readonly IGitService gitService;
44+
readonly IVSGitExt gitExt;
4445
readonly IOperatingSystem os;
4546
readonly IUsageTracker usageTracker;
4647

4748
[ImportingConstructor]
48-
public PullRequestService(IGitClient gitClient, IGitService gitService, IOperatingSystem os, IUsageTracker usageTracker)
49+
public PullRequestService(
50+
IGitClient gitClient,
51+
IGitService gitService,
52+
IVSGitExt gitExt,
53+
IOperatingSystem os,
54+
IUsageTracker usageTracker)
4955
{
5056
this.gitClient = gitClient;
5157
this.gitService = gitService;
58+
this.gitExt = gitExt;
5259
this.os = os;
5360
this.usageTracker = usageTracker;
5461
}
@@ -652,6 +659,8 @@ async Task<IPullRequestModel> PushAndCreatePR(IModelService modelService,
652659
await Task.Delay(TimeSpan.FromSeconds(5));
653660

654661
var ret = await modelService.CreatePullRequest(sourceRepository, targetRepository, sourceBranch, targetBranch, title, body);
662+
await MarkBranchAsPullRequest(repo, sourceBranch.Name, ret);
663+
gitExt.RefreshActiveRepositories();
655664
await usageTracker.IncrementCounter(x => x.NumberOfUpstreamPullRequests);
656665
return ret;
657666
}

src/GitHub.App/Services/TeamExplorerContext.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Linq;
33
using System.ComponentModel;
44
using System.ComponentModel.Composition;
5+
using System.Reactive.Linq;
56
using GitHub.Models;
67
using GitHub.Logging;
78
using GitHub.Primitives;
@@ -29,25 +30,26 @@ public class TeamExplorerContext : ITeamExplorerContext
2930

3031
readonly DTE dte;
3132
readonly IVSGitExt gitExt;
33+
readonly IPullRequestService pullRequestService;
3234

3335
string solutionPath;
3436
string repositoryPath;
3537
UriString cloneUrl;
3638
string branchName;
3739
string headSha;
3840
string trackedSha;
41+
Tuple<string, int> pullRequest;
3942

4043
ILocalRepositoryModel repositoryModel;
4144

4245
[ImportingConstructor]
43-
public TeamExplorerContext(IGitHubServiceProvider serviceProvider, IVSGitExt gitExt)
44-
: this(gitExt, serviceProvider)
45-
{
46-
}
47-
48-
public TeamExplorerContext(IVSGitExt gitExt, IGitHubServiceProvider serviceProvider)
46+
public TeamExplorerContext(
47+
IGitHubServiceProvider serviceProvider,
48+
IVSGitExt gitExt,
49+
IPullRequestService pullRequestService)
4950
{
5051
this.gitExt = gitExt;
52+
this.pullRequestService = pullRequestService;
5153

5254
// This is a standard service which should always be available.
5355
dte = serviceProvider.GetService<DTE>();
@@ -56,7 +58,7 @@ public TeamExplorerContext(IVSGitExt gitExt, IGitHubServiceProvider serviceProvi
5658
gitExt.ActiveRepositoriesChanged += Refresh;
5759
}
5860

59-
void Refresh()
61+
async void Refresh()
6062
{
6163
try
6264
{
@@ -76,6 +78,7 @@ void Refresh()
7678
var newBranchName = repo?.CurrentBranch?.Name;
7779
var newHeadSha = repo?.CurrentBranch?.Sha;
7880
var newTrackedSha = repo?.CurrentBranch?.TrackedSha;
81+
var newPullRequest = await pullRequestService.GetPullRequestForCurrentBranch(repo);
7982

8083
if (newRepositoryPath != repositoryPath)
8184
{
@@ -102,13 +105,19 @@ void Refresh()
102105
log.Debug("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
103106
StatusChanged?.Invoke(this, EventArgs.Empty);
104107
}
108+
else if (newPullRequest != pullRequest)
109+
{
110+
log.Debug("Fire StatusChanged event when PullRequest changes for ActiveRepository");
111+
StatusChanged?.Invoke(this, EventArgs.Empty);
112+
}
105113

106114
repositoryPath = newRepositoryPath;
107115
cloneUrl = newCloneUrl;
108116
branchName = newBranchName;
109117
headSha = newHeadSha;
110118
solutionPath = newSolutionPath;
111119
trackedSha = newTrackedSha;
120+
pullRequest = newPullRequest;
112121
}
113122
}
114123
catch (Exception e)
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Controls.Primitives;
6+
using System.Windows.Media;
7+
8+
namespace GitHub.UI.Controls
9+
{
10+
/// <summary>
11+
/// A vertical stack panel which implements its own logical scrolling, allowing controls to be
12+
/// fixed horizontally in the scroll area.
13+
/// </summary>
14+
/// <remarks>
15+
/// This panel is needed by the PullRequestDetailsView because of #1698: there is no default
16+
/// panel in WPF which allows the horizontal scrollbar to always be present at the bottom while
17+
/// also making the PR description etc be fixed horizontally (non-scrollable) in the viewport.
18+
/// </remarks>
19+
public class ScrollingVerticalStackPanel : Panel, IScrollInfo
20+
{
21+
const int lineSize = 16;
22+
const int mouseWheelSize = 48;
23+
24+
/// <summary>
25+
/// Attached property which when set to True on a child control, will cause it to be fixed
26+
/// horizontally within the scrollable viewport.
27+
/// </summary>
28+
public static readonly DependencyProperty IsFixedProperty =
29+
DependencyProperty.RegisterAttached(
30+
"IsFixed",
31+
typeof(bool),
32+
typeof(ScrollingVerticalStackPanel),
33+
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure));
34+
35+
public bool CanHorizontallyScroll
36+
{
37+
get { return true; }
38+
set { }
39+
}
40+
41+
public bool CanVerticallyScroll
42+
{
43+
get { return true; }
44+
set { }
45+
}
46+
47+
public double ExtentHeight { get; private set; }
48+
public double ExtentWidth { get; private set; }
49+
public double HorizontalOffset { get; private set; }
50+
public double VerticalOffset { get; private set; }
51+
public double ViewportHeight { get; private set; }
52+
public double ViewportWidth { get; private set; }
53+
public ScrollViewer ScrollOwner { get; set; }
54+
55+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Can only be applied to controls")]
56+
public static bool GetIsFixed(FrameworkElement control)
57+
{
58+
return (bool)control.GetValue(IsFixedProperty);
59+
}
60+
61+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters", Justification = "Can only be applied to controls")]
62+
public static void SetIsFixed(FrameworkElement control, bool value)
63+
{
64+
control.SetValue(IsFixedProperty, value);
65+
}
66+
67+
public void LineDown() => SetVerticalOffset(VerticalOffset + lineSize);
68+
public void LineLeft() => SetHorizontalOffset(HorizontalOffset - lineSize);
69+
public void LineRight() => SetHorizontalOffset(HorizontalOffset + lineSize);
70+
public void LineUp() => SetVerticalOffset(VerticalOffset - lineSize);
71+
public void MouseWheelDown() => SetVerticalOffset(VerticalOffset + mouseWheelSize);
72+
public void MouseWheelLeft() => SetHorizontalOffset(HorizontalOffset - mouseWheelSize);
73+
public void MouseWheelRight() => SetHorizontalOffset(HorizontalOffset + mouseWheelSize);
74+
public void MouseWheelUp() => SetVerticalOffset(VerticalOffset - mouseWheelSize);
75+
public void PageDown() => SetVerticalOffset(VerticalOffset + ViewportHeight);
76+
public void PageLeft() => SetHorizontalOffset(HorizontalOffset - ViewportWidth);
77+
public void PageRight() => SetHorizontalOffset(HorizontalOffset + ViewportWidth);
78+
public void PageUp() => SetVerticalOffset(VerticalOffset - ViewportHeight);
79+
80+
public Rect MakeVisible(Visual visual, Rect rectangle)
81+
{
82+
var transform = visual.TransformToVisual(this);
83+
var rect = transform.TransformBounds(rectangle);
84+
var offsetX = HorizontalOffset;
85+
var offsetY = VerticalOffset;
86+
87+
if (rect.Bottom > ViewportHeight)
88+
{
89+
var delta = rect.Bottom - ViewportHeight;
90+
offsetY += delta;
91+
rect.Y -= delta;
92+
}
93+
94+
if (rect.Y < 0)
95+
{
96+
offsetY += rect.Y;
97+
}
98+
99+
// We technially should be trying to also show the right-hand side of the rect here
100+
// using the same technique that we just used to show the bottom of the rect above,
101+
// but in the case of the PR details view, the left hand side of the item is much
102+
// more important than the right hand side and it actually feels better to not do
103+
// this. If this control is used elsewhere and this behavior is required, we could
104+
// put in a switch to enable it.
105+
106+
if (rect.X < 0)
107+
{
108+
offsetX += rect.X;
109+
}
110+
111+
SetHorizontalOffset(offsetX);
112+
SetVerticalOffset(offsetY);
113+
114+
return rect;
115+
}
116+
117+
public void SetHorizontalOffset(double offset)
118+
{
119+
var value = Math.Max(0, Math.Min(offset, ExtentWidth - ViewportWidth));
120+
121+
if (value != HorizontalOffset)
122+
{
123+
HorizontalOffset = value;
124+
InvalidateArrange();
125+
}
126+
}
127+
128+
public void SetVerticalOffset(double offset)
129+
{
130+
var value = Math.Max(0, Math.Min(offset, ExtentHeight - ViewportHeight));
131+
132+
if (value != VerticalOffset)
133+
{
134+
VerticalOffset = value;
135+
InvalidateArrange();
136+
}
137+
}
138+
139+
protected override void ParentLayoutInvalidated(UIElement child)
140+
{
141+
base.ParentLayoutInvalidated(child);
142+
}
143+
144+
protected override Size MeasureOverride(Size availableSize)
145+
{
146+
var maxWidth = 0.0;
147+
var height = 0.0;
148+
149+
foreach (FrameworkElement child in Children)
150+
{
151+
var isFixed = GetIsFixed(child);
152+
var childConstraint = new Size(
153+
isFixed ? availableSize.Width : double.PositiveInfinity,
154+
double.PositiveInfinity);
155+
child.Measure(childConstraint);
156+
157+
if (height - VerticalOffset < availableSize.Height)
158+
{
159+
maxWidth = Math.Max(maxWidth, child.DesiredSize.Width);
160+
}
161+
162+
height += child.DesiredSize.Height;
163+
}
164+
165+
UpdateScrollInfo(new Size(maxWidth, height), availableSize);
166+
167+
return new Size(
168+
Math.Min(maxWidth, availableSize.Width),
169+
Math.Min(height, availableSize.Height));
170+
}
171+
172+
protected override Size ArrangeOverride(Size finalSize)
173+
{
174+
var y = -VerticalOffset;
175+
var thisRect = new Rect(finalSize);
176+
var visibleMaxWidth = 0.0;
177+
178+
foreach (FrameworkElement child in Children)
179+
{
180+
var isFixed = GetIsFixed(child);
181+
var x = isFixed ? 0 : -HorizontalOffset;
182+
var childRect = new Rect(x, y, child.DesiredSize.Width, child.DesiredSize.Height);
183+
child.Arrange(childRect);
184+
y += child.DesiredSize.Height;
185+
186+
if (childRect.IntersectsWith(thisRect) && childRect.Right > visibleMaxWidth)
187+
{
188+
visibleMaxWidth = childRect.Right;
189+
}
190+
}
191+
192+
UpdateScrollInfo(new Size(visibleMaxWidth, ExtentHeight), new Size(finalSize.Width, finalSize.Height));
193+
return finalSize;
194+
}
195+
196+
void UpdateScrollInfo(Size extent, Size viewport)
197+
{
198+
ExtentWidth = extent.Width;
199+
ExtentHeight = extent.Height;
200+
ScrollOwner?.InvalidateScrollInfo();
201+
ViewportWidth = viewport.Width;
202+
ViewportHeight = viewport.Height;
203+
ScrollOwner?.InvalidateScrollInfo();
204+
}
205+
}
206+
}

src/GitHub.UI/GitHub.UI.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
<DesignTime>True</DesignTime>
8686
<DependentUpon>OcticonPaths.resx</DependentUpon>
8787
</Compile>
88+
<Compile Include="Controls\ScrollingVerticalStackPanel.cs" />
8889
<Compile Include="Controls\SectionControl.cs" />
8990
<Compile Include="Controls\Spinner.xaml.cs">
9091
<DependentUpon>Spinner.xaml</DependentUpon>

0 commit comments

Comments
 (0)