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
Show all changes
26 commits
Select commit Hold shift + click to select a range
e4c8162
Stub of "Get Link" feature
shana Jan 7, 2016
069dc80
Basic implementation for opening selection in browser
Jan 7, 2016
d4d7762
Refactored browser url creation and added copy to clipboard menu item
Jan 8, 2016
ed5711b
Merge master into feature/link-to-vs
shana Jan 11, 2016
3df7b6c
Merge pull request #184 from austin94/feature/link-to-vs
shana Jan 11, 2016
60b2a70
Merge branch 'shana/new-menu-system' into feature/link-to-vs
shana Jan 11, 2016
068c43a
Give IActiveDocument a better name
shana Jan 12, 2016
72828e2
Give a better name to the open link command
shana Jan 12, 2016
b36c02c
Move open/copy link to MEF menus and cleanup
shana Jan 12, 2016
d8b2d16
Add tests for url generation
shana Jan 12, 2016
172aba3
Attempt at fixing tests
shana Jan 12, 2016
2c61005
Merge master into feature/link-to-vs
shana Feb 8, 2016
a4f8516
Merge feature/status-bar-notifications into feature/link-to-vs
shana Feb 8, 2016
f297056
Show statusbar message when a link is copied
shana Feb 8, 2016
68aef19
Minor formatting change
haacked Feb 9, 2016
499cba8
Style cleanup
shana Feb 9, 2016
2e2b5e0
Move useful functionality into SimpleRepositoryModel
shana Feb 9, 2016
3228dc2
Fix tests
shana Feb 9, 2016
2b49df3
Move commands to submenu
shana Feb 9, 2016
2a8582a
Make the export public
shana Feb 10, 2016
a8d2427
Merge master into feature/link-to-vs
shana Feb 10, 2016
006eb83
Don't need this anymore
shana Feb 19, 2016
a9c0614
Add theming
shana Feb 19, 2016
b5c7b35
Fix context menu icon colors and sizes
shana Feb 19, 2016
e5f269f
Don't need a viewbox here
shana Feb 19, 2016
808e859
Fix rendering of icons
shana Feb 22, 2016
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
5 changes: 5 additions & 0 deletions src/GitHub.App/SampleData/SampleViewModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ public void SetIcon(bool isPrivate, bool isFork)
{
}

public UriString GenerateUrl(string path = null, int startLine = -1, int endLine = -1)
{
return null;
}

public string Name { get; set; }
public UriString CloneUrl { get; set; }
public string LocalPath { get; set; }
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Exports/GitHub.Exports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<Compile Include="Helpers\NotificationAwareObject.cs" />
<Compile Include="Services\Connection.cs" />
<Compile Include="Services\GitService.cs" />
<Compile Include="Services\IActiveDocumentSnapshot.cs" />
<Compile Include="Services\IGitService.cs" />
<Compile Include="Services\IMenuHandler.cs" />
<Compile Include="Services\IMenuProvider.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Exports/Models/ISimpleRepositoryModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public interface ISimpleRepositoryModel : INotifyPropertyChanged
/// Updates the url information based on the local path
/// </summary>
void Refresh();
UriString GenerateUrl(string path = null, int startLine = -1, int endLine = -1);
}
}
66 changes: 65 additions & 1 deletion src/GitHub.Exports/Models/SimpleRepositoryModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using GitHub.Primitives;
using GitHub.UI;
using GitHub.VisualStudio.Helpers;
Expand All @@ -10,7 +11,7 @@
namespace GitHub.Models
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public class SimpleRepositoryModel : NotificationAwareObject, ISimpleRepositoryModel, INotifyPropertySource, IEquatable<SimpleRepositoryModel>
public class SimpleRepositoryModel : NotificationAwareObject, ISimpleRepositoryModel, IEquatable<SimpleRepositoryModel>
{
public SimpleRepositoryModel(string name, UriString cloneUrl, string localPath = null)
{
Expand Down Expand Up @@ -53,13 +54,76 @@ public void Refresh()
CloneUrl = uri;
}

/// <summary>
/// Generates a http(s) url to the repository in the remote server, optionally
/// pointing to a specific file and specific line range in it.
/// </summary>
/// <param name="path">The file to generate an url to. Optional.</param>
/// <param name="startLine">A specific line, or (if specifying the <paramref name="endLine"/> as well) the start of a range</param>
/// <param name="endLine">The end of a line range on the specified file.</param>
/// <returns>An UriString with the generated url, or null if the repository has no remote server configured or if it can't be found locally</returns>
public UriString GenerateUrl(string path = null, int startLine = -1, int endLine = -1)
{
if (CloneUrl == null)
return null;

var sha = HeadSha;
// this also incidentally checks whether the repo has a valid LocalPath
if (String.IsNullOrEmpty(sha))
return CloneUrl.ToRepositoryUrl().AbsoluteUri;

if (path != null && Path.IsPathRooted(path))
{
// if the path root doesn't match the repository local path, then ignore it
if (!path.StartsWith(LocalPath, StringComparison.OrdinalIgnoreCase))
{
Debug.Assert(false, String.Format(CultureInfo.CurrentCulture, "GenerateUrl: path {0} doesn't match repository {1}", path, LocalPath));
path = null;
}
else
path = path.Substring(LocalPath.Length + 1);
}

return new UriString(GenerateUrl(CloneUrl.ToRepositoryUrl().AbsoluteUri, sha, path, startLine, endLine));
}

const string CommitFormat = "{0}/commit/{1}";
const string BlobFormat = "{0}/blob/{1}/{2}";
const string StartLineFormat = "{0}#L{1}";
const string EndLineFormat = "{0}-L{1}";
static string GenerateUrl(string basePath, string sha, string path, int startLine = -1, int endLine = -1)
{
if (sha == null)
return basePath;

if (String.IsNullOrEmpty(path))
return String.Format(CultureInfo.InvariantCulture, CommitFormat, basePath, sha);

var ret = String.Format(CultureInfo.InvariantCulture, BlobFormat, basePath, sha, path.Replace(@"\", "/"));
if (startLine < 0)
return ret;
ret = String.Format(CultureInfo.InvariantCulture, StartLineFormat, ret, startLine);
if (endLine < 0)
return ret;
return String.Format(CultureInfo.InvariantCulture, EndLineFormat, ret, endLine);
}

public string Name { get; }
UriString cloneUrl;
public UriString CloneUrl { get { return cloneUrl; } set { cloneUrl = value; this.RaisePropertyChange(); } }
public string LocalPath { get; }
Octicon icon;
public Octicon Icon { get { return icon; } set { icon = value; this.RaisePropertyChange(); } }

public string HeadSha
{
get
{
var repo = GitService.GitServiceHelper.GetRepo(LocalPath);
return repo?.Commits.FirstOrDefault()?.Sha ?? String.Empty;
}
}

/// <summary>
/// Note: We don't consider CloneUrl a part of the hash code because it can change during the lifetime
/// of a repository. Equals takes care of any hash collisions because of this
Expand Down
9 changes: 9 additions & 0 deletions src/GitHub.Exports/Services/IActiveDocumentSnapshot.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace GitHub.VisualStudio
{
public interface IActiveDocumentSnapshot
{
string Name { get; }
int StartLine { get; }
int EndLine { get; }
}
}
31 changes: 31 additions & 0 deletions src/GitHub.VisualStudio/Base/MenuBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using System.Globalization;
using GitHub.Extensions;
using GitHub.Models;
using GitHub.Services;

namespace GitHub.VisualStudio
{
Expand All @@ -7,6 +11,8 @@ public abstract class MenuBase
readonly IServiceProvider serviceProvider;
protected IServiceProvider ServiceProvider { get { return serviceProvider; } }

protected ISimpleRepositoryModel ActiveRepo { get; private set; }

protected MenuBase()
{
}
Expand All @@ -15,5 +21,30 @@ protected MenuBase(IServiceProvider serviceProvider)
{
this.serviceProvider = serviceProvider;
}

void RefreshRepo()
{
ActiveRepo = ServiceProvider.GetExportedValue<ITeamExplorerServiceHolder>().ActiveRepo;

if (ActiveRepo == null)
{
var vsservices = ServiceProvider.GetExportedValue<IVSServices>();
string path = vsservices?.GetActiveRepoPath() ?? String.Empty;
try
{
ActiveRepo = !String.IsNullOrEmpty(path) ? new SimpleRepositoryModel(path) : null;
}
catch (Exception ex)
{
VsOutputLogger.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}: Error loading the repository from '{1}'. {2}", GetType(), path, ex));
}
}
}

protected bool IsGitHubRepo()
{
RefreshRepo();
return ActiveRepo?.CloneUrl?.RepositoryName != null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,9 @@ void OnThemeChanged()
{
try
{
var color = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
var brightness = color.GetBrightness();
var dark = brightness > 0.5f;

Icon = SharedResources.GetDrawingForIcon(octicon, dark ? Colors.DarkThemeNavigationItem : Colors.LightThemeNavigationItem, dark ? "dark" : "light");
var theme = Colors.DetectTheme();
var dark = theme == "Dark";
Icon = SharedResources.GetDrawingForIcon(octicon, dark ? Colors.DarkThemeNavigationItem : Colors.LightThemeNavigationItem, theme);
}
catch (ArgumentNullException)
{
Expand Down
24 changes: 24 additions & 0 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,12 @@
<Compile Include="Base\TeamExplorerServiceHolder.cs" />
<Compile Include="Converters\CountToVisibilityConverter.cs" />
<Compile Include="Helpers\SharedDictionaryManager.cs" />
<Compile Include="Helpers\ActiveDocumentSnapshot.cs" />
<Compile Include="Menus\OpenLink.cs" />
<Compile Include="Menus\LinkMenuBase.cs" />
<Compile Include="Menus\ShowGitHubPane.cs" />
<Compile Include="Menus\AddConnection.cs" />
<Compile Include="Menus\CopyLink.cs" />
<Compile Include="Base\MenuBase.cs" />
<Compile Include="Menus\MenuProvider.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down Expand Up @@ -340,6 +344,14 @@
<Resource Include="Resources\default_user_avatar.png" />
</ItemGroup>
<ItemGroup>
<Page Include="Resources\icons\clippy.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\icons\link_external.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Resources\icons\refresh.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
Expand All @@ -360,6 +372,18 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Styles\ThemeBlue.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Styles\ThemeLight.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="Styles\ThemeDark.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="SharedDictionary.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
Expand Down
8 changes: 8 additions & 0 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.imagemanifest
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<ID Name="arrow_right" Value="3" />
<ID Name="refresh" Value="4" />
<ID Name="pullrequest" Value="5" />
<ID Name="link_external" Value="6"/>
<ID Name="clippy" Value="7"/>
</Symbols>

<Images>
Expand All @@ -26,5 +28,11 @@
<Image Guid="$(guidImages)" ID="$(pullrequest)">
<Source Uri="$(Resources)/git_pull_request.xaml" />
</Image>
<Image Guid="$(guidImages)" ID="$(link_external)">
<Source Uri="$(Resources)/link_external.xaml" />
</Image>
<Image Guid="$(guidImages)" ID="$(clippy)">
<Source Uri="$(Resources)/clippy.xaml" />
</Image>
</Images>
</ImageManifest>
Loading