-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Added support for pushing Git commits (#12633)
- Loading branch information
1 parent
fd002b5
commit 7b463ec
Showing
20 changed files
with
727 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class GitPushAction : ObservableObject, IAction | ||
{ | ||
private readonly IContentPageContext _context; | ||
|
||
public string Label { get; } = "Push".GetLocalizedResource(); | ||
|
||
public string Description { get; } = "GitPushDescription".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new("\uE74A"); | ||
|
||
public bool IsExecutable => | ||
_context.CanExecuteGitAction; | ||
|
||
public GitPushAction() | ||
{ | ||
_context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
_context.PropertyChanged += Context_PropertyChanged; | ||
} | ||
|
||
public Task ExecuteAsync() | ||
{ | ||
return GitHelpers.PushToOrigin( | ||
_context.ShellPage?.InstanceViewModel.GitRepositoryPath, | ||
_context.ShellPage?.InstanceViewModel.GitBranchName); | ||
} | ||
|
||
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction)) | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Files.App.Commands; | ||
using Files.App.Contexts; | ||
|
||
namespace Files.App.Actions | ||
{ | ||
internal class GitSyncAction : ObservableObject, IAction | ||
{ | ||
private readonly IContentPageContext _context; | ||
|
||
public string Label { get; } = "GitSync".GetLocalizedResource(); | ||
|
||
public string Description { get; } = "GitSyncDescription".GetLocalizedResource(); | ||
|
||
public RichGlyph Glyph { get; } = new("\uEDAB"); | ||
|
||
public bool IsExecutable => | ||
_context.CanExecuteGitAction; | ||
|
||
public GitSyncAction() | ||
{ | ||
_context = Ioc.Default.GetRequiredService<IContentPageContext>(); | ||
|
||
_context.PropertyChanged += Context_PropertyChanged; | ||
} | ||
|
||
public Task ExecuteAsync() | ||
{ | ||
var instance = _context.ShellPage?.InstanceViewModel; | ||
|
||
return GitHelpers.PullOrigin(instance?.GitRepositoryPath) | ||
.ContinueWith(t => GitHelpers.PushToOrigin( | ||
instance?.GitRepositoryPath, | ||
instance?.GitBranchName)); | ||
} | ||
|
||
private void Context_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName is nameof(IContentPageContext.CanExecuteGitAction)) | ||
OnPropertyChanged(nameof(IsExecutable)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -183,5 +183,7 @@ public enum CommandCodes | |
// Git | ||
GitFetch, | ||
GitPull, | ||
GitPush, | ||
GitSync, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<!-- Copyright (c) 2023 Files Community. Licensed under the MIT License. See the LICENSE. --> | ||
<ContentDialog | ||
x:Class="Files.App.Dialogs.GitHubLoginDialog" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:converters="using:CommunityToolkit.WinUI.UI.Converters" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:helpers="using:Files.App.Helpers" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
Title="{helpers:ResourceString Name=ConnectGitHub}" | ||
CloseButtonCommand="{x:Bind ViewModel.CloseButtonCommand}" | ||
CloseButtonStyle="{StaticResource AccentButtonStyle}" | ||
CloseButtonText="{helpers:ResourceString Name=Close}" | ||
CornerRadius="{StaticResource OverlayCornerRadius}" | ||
PrimaryButtonClick="ContentDialog_PrimaryButtonClick" | ||
PrimaryButtonText="{helpers:ResourceString Name=OK}" | ||
RequestedTheme="{x:Bind helpers:ThemeHelper.RootTheme}" | ||
Style="{StaticResource DefaultContentDialogStyle}" | ||
mc:Ignorable="d"> | ||
|
||
<ContentDialog.PrimaryButtonStyle> | ||
<Style BasedOn="{StaticResource DefaultButtonStyle}" TargetType="Button"> | ||
<Setter Property="ContentTemplate"> | ||
<Setter.Value> | ||
<DataTemplate> | ||
<StackPanel | ||
HorizontalAlignment="Center" | ||
Orientation="Horizontal" | ||
Spacing="8"> | ||
<FontIcon FontSize="14" Glyph="" /> | ||
<TextBlock Text="{helpers:ResourceString Name=CopyCode}" /> | ||
</StackPanel> | ||
</DataTemplate> | ||
</Setter.Value> | ||
</Setter> | ||
</Style> | ||
</ContentDialog.PrimaryButtonStyle> | ||
|
||
<ContentDialog.Resources> | ||
<ResourceDictionary> | ||
<converters:BoolNegationConverter x:Key="BoolNegationConverter" /> | ||
</ResourceDictionary> | ||
</ContentDialog.Resources> | ||
|
||
<Grid RowSpacing="20"> | ||
<Grid.RowDefinitions> | ||
<RowDefinition Height="Auto" /> | ||
<RowDefinition /> | ||
</Grid.RowDefinitions> | ||
|
||
<StackPanel Width="360" Height="40"> | ||
<!-- Subtitle --> | ||
<TextBlock | ||
x:Name="Subtitle" | ||
Grid.Row="0" | ||
HorizontalAlignment="Left" | ||
VerticalAlignment="Center" | ||
Text="{x:Bind ViewModel.Subtitle, Mode=OneWay}" | ||
TextWrapping="WrapWholeWords" /> | ||
</StackPanel> | ||
|
||
<StackPanel | ||
x:Name="UserCodeContainer" | ||
Grid.Row="1" | ||
HorizontalAlignment="Stretch" | ||
VerticalAlignment="Stretch" | ||
x:Load="{x:Bind ViewModel.LoginConfirmed, Converter={StaticResource BoolNegationConverter}, Mode=OneWay}"> | ||
<HyperlinkButton | ||
x:Name="LoginUrl" | ||
Content="{x:Bind ViewModel.LoginUrl}" | ||
NavigateUri="{x:Bind ViewModel.NavigateUri}" /> | ||
<TextBlock | ||
Margin="12,8" | ||
CharacterSpacing="150" | ||
FontFamily="Cascadia Mono,Consolas,Segoe UI Variable" | ||
FontSize="32" | ||
FontWeight="Normal" | ||
Text="{x:Bind ViewModel.UserCode}" /> | ||
</StackPanel> | ||
<Border | ||
x:Name="LoginSuccessBadge" | ||
Grid.Row="1" | ||
Width="70" | ||
Height="70" | ||
Margin="8" | ||
x:Load="{x:Bind ViewModel.LoginConfirmed, Mode=OneWay}" | ||
Background="#6ccb5f" | ||
CornerRadius="35"> | ||
<SymbolIcon | ||
Width="52" | ||
Height="52" | ||
Symbol="Accept" /> | ||
</Border> | ||
</Grid> | ||
</ContentDialog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright (c) 2023 Files Community | ||
// Licensed under the MIT License. See the LICENSE. | ||
|
||
using Microsoft.UI.Xaml.Controls; | ||
using Windows.ApplicationModel.DataTransfer; | ||
|
||
namespace Files.App.Dialogs | ||
{ | ||
public sealed partial class GitHubLoginDialog : ContentDialog, IDialog<GitHubLoginDialogViewModel> | ||
{ | ||
public GitHubLoginDialogViewModel ViewModel | ||
{ | ||
get => (GitHubLoginDialogViewModel)DataContext; | ||
set | ||
{ | ||
if (ViewModel is not null) | ||
ViewModel.PropertyChanged -= ViewModel_PropertyChanged; | ||
|
||
DataContext = value; | ||
if (value is not null) | ||
value.PropertyChanged += ViewModel_PropertyChanged; | ||
} | ||
} | ||
|
||
public GitHubLoginDialog() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
public new async Task<DialogResult> ShowAsync() => (DialogResult)await base.ShowAsync(); | ||
|
||
private void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) | ||
{ | ||
args.Cancel = true; | ||
|
||
var data = new DataPackage(); | ||
data.SetText(ViewModel.UserCode); | ||
|
||
Clipboard.SetContent(data); | ||
Clipboard.Flush(); | ||
} | ||
|
||
private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs e) | ||
{ | ||
if (e.PropertyName == nameof(GitHubLoginDialogViewModel.LoginConfirmed) && ViewModel.LoginConfirmed) | ||
PrimaryButtonText = null; | ||
} | ||
} | ||
} |
Oops, something went wrong.