8000 Show current PR on status bar and allow navigation to PR details MVP by jcansdale · Pull Request #1102 · github/VisualStudio · GitHub
[go: up one dir, main page]

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

Show current PR on status bar and allow navigation to PR details MVP #1102

Merged
merged 18 commits into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Wire up property change events
  • Loading branch information
jcansdale committed Sep 12, 2017
commit 8b6cfa2ddf3ec6721c3e2e76f31045dee94d1413
43 changes: 38 additions & 5 deletions src/GitHub.InlineReviews/Services/PullRequestStatusManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,53 @@
using System.ComponentModel.Composition;
using GitHub.InlineReviews.Views;
using GitHub.InlineReviews.ViewModels;
using GitHub.Services;
using System.ComponentModel;

namespace GitHub.InlineReviews.Services
{

[Export(typeof(IPullRequestStatusManager))]
public class PullRequestStatusManager : IPullRequestStatusManager
{
const string SccStatusBarName = "SccStatusBar";
const string GitHubStatusName = "GitHubStatusView";

readonly Window mainWindow;
readonly IPullRequestSessionManager pullRequestSessionManager;
readonly PullRequestStatusViewModel pullRequestStatusViewModel;

[ImportingConstructor]
public PullRequestStatusManager(IPullRequestSessionManager pullRequestSessionManager) : this(new PullRequestStatusViewModel())
{
this.pullRequestSessionManager = pullRequestSessionManager;

RefreshCurrentSession();
pullRequestSessionManager.PropertyChanged += PullRequestSessionManager_PropertyChanged;
}

void PullRequestSessionManager_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(PullRequestSessionManager.CurrentSession))
{
RefreshCurrentSession();
}
}

void RefreshCurrentSession()
{
var currentSession = pullRequestSessionManager.CurrentSession;
var pullRequest = currentSession?.PullRequest;

if (pullRequest != null)
{
pullRequestStatusViewModel.Number = pullRequest.Number;
pullRequestStatusViewModel.Title = pullRequest.Title;
}
}

public PullRequestStatusManager()
public PullRequestStatusManager(PullRequestStatusViewModel pullRequestStatusViewModel)
{
this.pullRequestStatusViewModel = pullRequestStatusViewModel;
mainWindow = Application.Current.MainWindow;
}

Expand All @@ -31,8 +64,7 @@ public void ShowStatus()
var githubStatusBar = FindPullRequestStatusView(statusBar);
if (githubStatusBar == null)
{
var viewModel = new PullRequestStatusViewModel { Number = 666, Title = "A beast of a PR" };
var view = new PullRequestStatusView { Name = GitHubStatusName, DataContext = viewModel };
var view = new PullRequestStatusView { Name = GitHubStatusName, DataContext = pullRequestStatusViewModel };
statusBar.Items.Insert(0, view);
}
}
Expand Down Expand Up @@ -110,7 +142,8 @@ class PullRequestStatusManagerInstaller
[STAThread]
void Install()
{
var provider = new PullRequestStatusManager();
var viewModel = new PullRequestStatusViewModel { Number = 666, Title = "A beast of a PR" };
var provider = new PullRequestStatusManager(viewModel);
provider.HideStatus();
provider.ShowStatus();
}
Expand Down
36 changes: 33 additions & 3 deletions src/GitHub.InlineReviews/ViewModels/PullRequestStatusViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
using System;
using System.ComponentModel;

namespace GitHub.InlineReviews.ViewModels
{
class PullRequestStatusViewModel
public class PullRequestStatusViewModel : INotifyPropertyChanged
{
public int Number { get; set; }
public string Title { get; set; }
int number;
string title;

public int Number
{
get { return number; }
set
{
if (number != value)
{
number = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Number)));
}
}
}


public string Title
{
get { return title; }
set
{
if (title != value)
{
title = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Title)));
}
}
}

public event PropertyChangedEventHandler PropertyChanged;
}
}
0