Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@

namespace GitHub.InlineReviews.Peek
{
class InlineCommentPeekResultPresentation : IPeekResultPresentation
class InlineCommentPeekResultPresentation : IPeekResultPresentation, IDesiredHeightProvider
{
const double PeekBorders = 28.0;
readonly InlineCommentPeekViewModel viewModel;
InlineCommentPeekView view;
double desiredHeight;

public bool IsDirty => false;
public bool IsReadOnly => true;
Expand All @@ -24,9 +27,23 @@ public double ZoomLevel
set { }
}

public double DesiredHeight
{
get { return desiredHeight; }
private set
{
if (desiredHeight != value && DesiredHeightChanged != null)
{
desiredHeight = value;
DesiredHeightChanged(this, EventArgs.Empty);
}
}
}

public event EventHandler IsDirtyChanged;
public event EventHandler IsReadOnlyChanged;
public event EventHandler<RecreateContentEventArgs> RecreateContent;
public event EventHandler<EventArgs> DesiredHeightChanged;

public bool CanSave(out string defaultPath)
{
Expand All @@ -45,8 +62,15 @@ public void Close()

public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState)
{
var view = new InlineCommentPeekView();
view = new InlineCommentPeekView();
view.DataContext = viewModel;

// Report the desired size back to the peek view. Unfortunately the peek view
// helpfully assigns this desired size to the control that also contains the tab at
// the top of the peek view, so we need to put in a fudge factor. Using a const
// value for the moment, as there's no easy way to get the size of the control.
view.DesiredHeight.Subscribe(x => DesiredHeight = x + PeekBorders);

return view;
}

Expand Down
15 changes: 13 additions & 2 deletions src/GitHub.InlineReviews/Services/InlineCommentPeekService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ public ITrackingPoint Show(ITextView textView, AddInlineCommentTag tag)

var line = textView.TextSnapshot.GetLineFromLineNumber(tag.LineNumber);
var trackingPoint = textView.TextSnapshot.CreateTrackingPoint(line.Start.Position, PointTrackingMode.Positive);
var options = new PeekSessionCreationOptions(
textView,
InlineCommentPeekRelationship.Instance.Name,
trackingPoint,
defaultHeight: 0);

ExpandCollapsedRegions(textView, line.Extent);

var session = peekBroker.TriggerPeekSession(textView, trackingPoint, InlineCommentPeekRelationship.Instance.Name);
var session = peekBroker.TriggerPeekSession(options);
var item = session.PeekableItems.OfType<InlineCommentPeekableItem>().FirstOrDefault();

if (item != null)
Expand Down Expand Up @@ -133,8 +138,14 @@ public ITrackingPoint Show(ITextView textView, ShowInlineCommentTag tag)

var line = snapshot.GetLineFromLineNumber(tag.LineNumber);
var trackingPoint = snapshot.CreateTrackingPoint(line.Start.Position, PointTrackingMode.Positive);
var options = new PeekSessionCreationOptions(
textView,
InlineCommentPeekRelationship.Instance.Name,
trackingPoint,
defaultHeight: 0);

ExpandCollapsedRegions(textView, line.Extent);
peekBroker.TriggerPeekSession(textView, trackingPoint, InlineCommentPeekRelationship.Instance.Name);
peekBroker.TriggerPeekSession(options);
return trackingPoint;
}

Expand Down
1 change: 1 addition & 0 deletions src/GitHub.InlineReviews/ViewModels/CommentViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
Expand Down
5 changes: 3 additions & 2 deletions src/GitHub.InlineReviews/Views/InlineCommentPeekView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@
</StackPanel>
</Border>

<ScrollViewer VerticalScrollBarVisibility="Auto"
<ScrollViewer Name="threadScroller"
VerticalScrollBarVisibility="Auto"
Background="#FFF5F5F5">
<Grid>
<local:CommentThreadView DataContext="{Binding Thread}"/>
<local:CommentThreadView x:Name="threadView" DataContext="{Binding Thread}"/>
</Grid>
</ScrollViewer>
</DockPanel>
Expand Down
29 changes: 17 additions & 12 deletions src/GitHub.InlineReviews/Views/InlineCommentPeekView.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Reactive.Subjects;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using GitHub.VisualStudio.UI.Helpers;

namespace GitHub.InlineReviews.Views
{
public partial class InlineCommentPeekView : UserControl
{
readonly Subject<double> desiredHeight;

public InlineCommentPeekView()
{
InitializeComponent();

desiredHeight = new Subject<double>();
threadView.LayoutUpdated += ThreadViewLayoutUpdated;
threadScroller.PreviewMouseWheel += ScrollViewerUtilities.FixMouseWheelScroll;
}

public IObservable<double> DesiredHeight => desiredHeight;

void ThreadViewLayoutUpdated(object sender, EventArgs e)
{
var otherControlsHeight = ActualHeight - threadScroller.ActualHeight;
var threadViewHeight = threadView.DesiredSize.Height + threadView.Margin.Top + threadView.Margin.Bottom;
desiredHeight.OnNext(threadViewHeight + otherControlsHeight);
}
}
}
1 change: 1 addition & 0 deletions src/GitHub.UI/GitHub.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<Compile Include="Helpers\ScrollViewerUtilities.cs" />
<Compile Include="Helpers\SharedDictionaryManager.cs" />
<Compile Include="Helpers\TreeViewExtensions.cs" />
<Compile Include="Helpers\VisualTreeExtensions.cs" />
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
31 changes: 22 additions & 9 deletions src/GitHub.UI/Helpers/ScrollViewerUtilities.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Windows;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using GitHub.UI.Helpers;

namespace GitHub.VisualStudio.UI.Helpers
{
Expand All @@ -15,8 +18,9 @@ public static class ScrollViewerUtilities
/// <param name="e">The event arguments.</param>
/// <remarks>
/// WPF's ScrollViewer is broken in that it doesn't pass scroll events to the parent
/// control when it can't scroll any more. Add this method as an event handler to a
/// control which has a ScrollViewer in its template to fix this.
/// control when it can't scroll any more. Add this method as a PreviewMouseWheel event
/// handler to a ScrollViewer or a control which has a ScrollViewer in its template to
/// fix this.
/// </remarks>
public static void FixMouseWheelScroll(object sender, MouseWheelEventArgs e)
{
Expand All @@ -26,15 +30,24 @@ public static void FixMouseWheelScroll(object sender, MouseWheelEventArgs e)
{
var control = sender as FrameworkElement;
var parent = control.Parent as UIElement;
var scrollViewer = control.GetSelfAndVisualDescendents()
.OfType<ScrollViewer>()
.FirstOrDefault();

if (parent != null)
if (scrollViewer != null && parent != null)
{
e.Handled = true;
parent.RaiseEvent(new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
var offset = scrollViewer.ContentVerticalOffset;

if ((offset == scrollViewer.ScrollableHeight && e.Delta < 0) ||
(offset == 0 && e.Delta > 0))
{
RoutedEvent = UIElement.MouseWheelEvent,
Source = control,
});
e.Handled = true;
parent.RaiseEvent(new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta)
{
RoutedEvent = UIElement.MouseWheelEvent,
Source = control,
});
}
}
}
}
Expand Down
57 changes: 57 additions & 0 deletions src/GitHub.UI/Helpers/VisualTreeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using System.Windows.Media;
using GitHub.Extensions;

namespace GitHub.UI.Helpers
{
public static class VisualTreeExtensions
{
public static IEnumerable<Visual> GetSelfAndVisualAncestors(this Visual visual)
{
Guard.ArgumentNotNull(visual, nameof(visual));

return Enumerable.Repeat(visual, 1).Concat(GetVisualAncestors(visual));
}

public static IEnumerable<Visual> GetVisualAncestors(this Visual visual)
{
Guard.ArgumentNotNull(visual, nameof(visual));

while (true)
{
visual = VisualTreeHelper.GetParent(visual) as Visual;

if (visual != null)
yield return visual;
else
break;
}
}

public static IEnumerable<Visual> GetSelfAndVisualDescendents(this Visual visual)
{
Guard.ArgumentNotNull(visual, nameof(visual));

return Enumerable.Repeat(visual, 1).Concat(GetVisualDescendents(visual));
}

public static IEnumerable<Visual> GetVisualDescendents(this Visual visual)
{
Guard.ArgumentNotNull(visual, nameof(visual));

var count = VisualTreeHelper.GetChildrenCount(visual);

for (var i = 0; i < count; ++i)
{
var child = (Visual)VisualTreeHelper.GetChild(visual, i);
yield return child;

foreach (var descendent in child.GetVisualDescendents())
{
yield return descendent;
}
}
}
}
}
1 change: 0 additions & 1 deletion src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="AssemblyResolverPackage.cs" />
<Compile Include="Helpers\VisualTreeExtensions.cs" />
<Compile Include="IServiceProviderPackage.cs" />
<Compile Include="Menus\BlameLink.cs" />
<Compile Include="Menus\MenuBase.cs" />
Expand Down
32 changes: 0 additions & 32 deletions src/GitHub.VisualStudio/Helpers/VisualTreeExtensions.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@
using System.Windows.Media;
using GitHub.Exports;
using GitHub.Extensions;
using GitHub.InlineReviews.Commands;
using GitHub.Models;
using GitHub.Services;
using GitHub.UI;
using GitHub.UI.Helpers;
using GitHub.ViewModels;
using GitHub.VisualStudio.Helpers;
using GitHub.VisualStudio.UI.Helpers;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Editor;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using ReactiveUI;
using Task = System.Threading.Tasks.Task;
using GitHub.InlineReviews.Commands;
using GitHub.UI.Helpers;

namespace GitHub.VisualStudio.UI.Views
{
Expand Down