Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Add edit with VS Code button #504

Merged
merged 50 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 45 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8227a33
💄 Add edit with VS Code button
Lamparter Aug 29, 2024
f946fc2
✨ Add open in VSCode functionality
Lamparter Aug 29, 2024
3134e85
🎨 Use uniform URI variable schematics
Lamparter Aug 29, 2024
1bf138c
🔊 Add error for failure to open GitHub Desktop to logs
Lamparter Aug 29, 2024
3372a8d
🎨 Format comment
Lamparter Aug 29, 2024
54d6708
🔊 Add correct logs for open VS event
Lamparter Aug 29, 2024
79d9955
💄 Make editor buttons more compact
Lamparter Aug 29, 2024
bef63b2
🐛 Fix crash when repo opened in non-existent app
Lamparter Aug 29, 2024
b3dab36
🔊 Add descriptive log to archive download errorevent
Lamparter Aug 29, 2024
c9d92af
💄 Add regular button fill to VS (Code) buttons
Lamparter Aug 29, 2024
5faaeca
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Aug 29, 2024
5ac1aaf
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Aug 29, 2024
b4b36b4
💄 Use transparent button style
Lamparter Aug 29, 2024
eac8597
✨ Add open in Codespaces button
Lamparter Aug 29, 2024
73e63b7
🎨 Improve formatting of method definitions
Lamparter Aug 29, 2024
1bfcefc
🎨 Improve formatting of method definitions
Lamparter Aug 29, 2024
309abb7
✨ Handle other Git clients
Lamparter Aug 30, 2024
268bce2
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Sep 1, 2024
de74fe0
✨ Add download page redirects for errors opening VS
Lamparter Sep 1, 2024
d80c516
💄 Add edit with VS Code button
Lamparter Aug 29, 2024
2c9903f
✨ Add open in VSCode functionality
Lamparter Aug 29, 2024
79f9280
🎨 Use uniform URI variable schematics
Lamparter Aug 29, 2024
bfd57c7
🔊 Add error for failure to open GitHub Desktop to logs
Lamparter Aug 29, 2024
2ffaf44
🎨 Format comment
Lamparter Aug 29, 2024
97a6dfa
🔊 Add correct logs for open VS event
Lamparter Aug 29, 2024
875d0e9
💄 Make editor buttons more compact
Lamparter Aug 29, 2024
35db575
🐛 Fix crash when repo opened in non-existent app
Lamparter Aug 29, 2024
23bb482
🔊 Add descriptive log to archive download errorevent
Lamparter Aug 29, 2024
0b6bbe0
💄 Add regular button fill to VS (Code) buttons
Lamparter Aug 29, 2024
64bc79c
💄 Use transparent button style
Lamparter Aug 29, 2024
aae1b6a
✨ Add open in Codespaces button
Lamparter Aug 29, 2024
3193878
🎨 Improve formatting of method definitions
Lamparter Aug 29, 2024
0150790
🎨 Improve formatting of method definitions
Lamparter Aug 29, 2024
b2d3e39
✨ Handle other Git clients
Lamparter Aug 30, 2024
b28a629
✨ Add download page redirects for errors opening VS
Lamparter Sep 1, 2024
20a8d8e
🔀 Merge `origin/lamparter/vscode` into local
Lamparter Sep 7, 2024
8590ce0
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Sep 15, 2024
5ae7529
✨ Add Code button
Lamparter Sep 15, 2024
6ec5029
🔀 Merge branch `lamparter/refactor` into lamparter/vscode
Lamparter Sep 15, 2024
b9ee9b8
♿ Update copy command button with better name
Lamparter Sep 15, 2024
527ad3f
🔀 Merge branch `lamparter/refactor` into lamparter/vscode
Lamparter Sep 18, 2024
e48123d
🚚 Rename git CLI button for better UI simplicity
Lamparter Sep 19, 2024
983eb57
🎨 Fix bad formatting in `ActivityBlock.xaml.cs`
Lamparter Sep 19, 2024
d79a5ee
🐛 Fix error with `ActivityBlock.xaml.cs`
Lamparter Sep 19, 2024
e20efba
✨ Add `SplitButton` for opening repo
Lamparter Sep 19, 2024
80cd9c8
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Dec 25, 2024
dea7258
Merge branch 'lamparter/refactor' into lamparter/vscode
Lamparter Dec 25, 2024
94397d6
Update clone string
Lamparter Dec 25, 2024
b44b613
Remove icon from code button
Lamparter Dec 25, 2024
4452645
Link `OpenWithButton` to click event
Lamparter Dec 25, 2024
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
15 changes: 13 additions & 2 deletions src/FluentHub.App/UserControls/FileNavigationBlock.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,26 @@
<DropDownButton.Content>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<TextBlock Text="Clone" />
<FontIcon
Margin="0,0,4,0"
FontSize="16"
Glyph="&#xE943;" />

<TextBlock
Grid.Column="2"
Margin="4,0,0,0"
Text="Code" />

<AnimatedIcon
x:Name="ChevronIcon"
Grid.Column="1"
Grid.Column="4"
Width="12"
Height="12"
Margin="8,0,0,0"
Expand Down
29 changes: 16 additions & 13 deletions src/FluentHub.App/UserControls/GitCloneFlyout.xaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<UserControl
<UserControl
x:Class="FluentHub.App.UserControls.GitCloneFlyout"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -39,7 +39,7 @@
IsSelected="True"
Tag="Https" />
<NavigationViewItem Content="SSH" Tag="Ssh" />
<NavigationViewItem Content="GitHub CLI" Tag="GitHubCli" />
<NavigationViewItem Content="CLI" Tag="GitHubCli" />
</NavigationView.MenuItems>

<NavigationView.PaneFooter>
Expand All @@ -51,7 +51,7 @@
ToolTipService.ToolTip="Copy git clone command">
<StackPanel Orientation="Horizontal" Spacing="6">
<FontIcon FontSize="16" Glyph="&#xE756;" />
<TextBlock Text="Git" />
<TextBlock Text="Copy" />
</StackPanel>
</Button>
</NavigationView.PaneFooter>
Expand Down Expand Up @@ -113,25 +113,28 @@

<Button
HorizontalAlignment="Stretch"
Click="GitHubDeskButton_Click"
Click="OpenGitHubDesktopButton_Click"
IsEnabled="True">
<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon
FontFamily="{StaticResource Octicons}"
FontSize="14"
Glyph="&#xE970;" />
<TextBlock Text="Open with GitHub Desktop" />
<TextBlock Text="Open in your local Git client" />
</StackPanel>
</Button>

<Button
HorizontalAlignment="Stretch"
Click="OpenVSButton_Click"
IsEnabled="True">
<StackPanel Orientation="Horizontal" Spacing="8">
<TextBlock Text="Open with Visual Studio" />
</StackPanel>
</Button>
<SplitButton x:Name="OpenWithButton" HorizontalAlignment="Stretch">
<TextBlock Text="Open with..." />
<SplitButton.Flyout>
<MenuFlyout Placement="BottomEdgeAlignedRight">
<MenuFlyoutItem Click="OpenVSCodeButton_Click" Text="Visual Studio Code" />
<MenuFlyoutItem Click="OpenVSButton_Click" Text="Visual Studio" />
<MenuFlyoutSeparator />
<MenuFlyoutItem Click="OpenCodespaceButton_Click" Text="GitHub Codespaces" />
</MenuFlyout>
</SplitButton.Flyout>
</SplitButton>

<Button
HorizontalAlignment="Stretch"
Expand Down
125 changes: 106 additions & 19 deletions src/FluentHub.App/UserControls/GitCloneFlyout.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,62 +80,149 @@ private void CopyButton_Click(object sender, RoutedEventArgs e)
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dp);
}

private void CopyGitCommand_Click(object sender, RoutedEventArgs e)
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
{
var dp = new Windows.ApplicationModel.DataTransfer.DataPackage();
dp.SetText("git clone" + " " + CloneUriTextBox.Text);
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dp);
}
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved

private async void OpenGitHubDesktopButton_Click(object sender, RoutedEventArgs e)
{
string encodedUrl = Uri.EscapeDataString(_repoGitUrl);
string openGitHubDesktopUrl = "x-github-client://openRepo/" + encodedUrl;

var uri = new Uri(openGitHubDesktopUrl);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

if (success)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened GitHub Desktop with the repository");
}
else
{
Log.Error("Error opening GitHub Desktop; opening GitKraken instead");
// Try GitKraken
string openGitKrakenUrl = $"gitkraken://repolink/-?url=https%3A%2F%2Fgithub.com%2F{ViewModel.Repository.Owner.Login}%2F{ViewModel.Repository.Name}.git";
var gitKrakenUri = new Uri(openGitKrakenUrl);
var secondSuccess = await Windows.System.Launcher.LaunchUriAsync(gitKrakenUri);
if (secondSuccess)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened GitKraken with the repository");
}
else
{
Log.Error("Error opening GitKraken; opening GitHub Desktop download page instead.");
// Open GitHub Desktop download page
var downloadUri = new Uri("https://desktop.github.com/");
var thirdSuccess = await Windows.System.Launcher.LaunchUriAsync(downloadUri);
if (thirdSuccess)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened GitHub Desktop download page");
}
else
{
Log.Error("Error opening GitHub Desktop download page; cancelling operation");
}
}
}
}

private async void OpenVSButton_Click(object sender, RoutedEventArgs e)
{
string encodedURL = Uri.EscapeDataString(_repoGitUrl);
string openVS_URL = "git-client://clone?repo=" + encodedURL;
string encodedUrl = Uri.EscapeDataString(_repoGitUrl);
string openStudioUrl = "git-client://clone?repo=" + encodedUrl;

var uri = new Uri(openVS_URL);
var uri = new Uri(openStudioUrl);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

if (success)
{
Console.WriteLine("Add to LOG it successed");
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened the repository in Visual Studio");
}
else
{
Console.WriteLine("Add to LOG it failed");
Log.Error(openStudioUrl, "Something went wrong. Visual Studio is not installed or there was another unspecified error; opening appropriate download page instead");
// Open visual studio download page
var downloadUri = new Uri("https://visualstudio.microsoft.com/");
var downloadSuccess = await Windows.System.Launcher.LaunchUriAsync(downloadUri);
if (downloadSuccess)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened Visual Studio download page");
}
else
{
Log.Error("Unknown error opening VS download page.");
}
}
}

private async void DownloadZipButton_Click(object sender, RoutedEventArgs e)
private async void OpenVSCodeButton_Click(object sender, RoutedEventArgs e)
{
string downloadZip = _repoUrl + $"/archive/refs/heads/{ViewModel.BranchName}.zip"; //Just made it with the main branch
string encodedUrl = Uri.EscapeDataString(_repoGitUrl);
string openCodeUrl = "vscode://vscode.git/clone?url=" + encodedUrl; // There should be an API to detect Code Insiders and open that instead of the stable version

var uri = new Uri(downloadZip);
var uri = new Uri(openCodeUrl);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

if (success)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Downloaded the repository into a .zip file");
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened the repository in Visual Studio Code");
}
else
{
Log.Error(downloadZip, "Something went wrong. The URL was not found or it doesn't work");
Log.Error(openCodeUrl, "Something went wrong. Code is not installed or there was another unspecified error; opening the download page instead.");
// Open vscode download page
var downloadUri = new Uri("https://code.visualstudio.com/");
var downloadSuccess = await Windows.System.Launcher.LaunchUriAsync(downloadUri);
if (downloadSuccess)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened Visual Studio Code download page");
}
else
{
Log.Error("Unknown error opening VSCode download page.");
}
}
}

private async void GitHubDeskButton_Click(object sender, RoutedEventArgs e)
private async void OpenCodespaceButton_Click(object sender, RoutedEventArgs e)
{
string gitHubDeskUrl = "x-github-client://openRepo " + _repoUrl;
string openCodespaceUrl = $"https://github.com/codespaces/new?hide_repo_select=true&repo={ViewModel.Repository.Owner.Login}/{ViewModel.Repository.Name}";

var uri = new Uri(gitHubDeskUrl);
var uri = new Uri(openCodespaceUrl);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

if (!success)
if (success)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Opened the repository in Codespaces in the user's local browser.");
}
else
{
Log.Warning($"Cannot open GitHub Desktop with uri \"" + gitHubDeskUrl + "\"");
Log.Error(openCodespaceUrl, "Something went wrong opening GitHub Codespaces in the user's browser.");
}
}

private void CopyGitCommand_Click(object sender, RoutedEventArgs e)
private async void DownloadZipButton_Click(object sender, RoutedEventArgs e)
{
var dp = new Windows.ApplicationModel.DataTransfer.DataPackage();
dp.SetText("git clone" + " " + CloneUriTextBox.Text);
Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dp);
string downloadZipUrl = _repoUrl + $"/archive/refs/heads/{ViewModel.BranchName}.zip"; // Just made it with the main branch

var uri = new Uri(downloadZipUrl);

var success = await Windows.System.Launcher.LaunchUriAsync(uri);

if (success)
{
Log.Write(Serilog.Events.LogEventLevel.Information, "Downloaded the repository into a .zip file");
}
else
{
Log.Error(downloadZipUrl, "Something went wrong downloading the repository in archive form. The URL was not found or it doesn't work");
0x5bfa marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Loading