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

Fix: Fixed crash when switching away from Git folder #12656

Merged
merged 2 commits into from
Jun 20, 2023
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
27 changes: 27 additions & 0 deletions src/Files.App/Converters/Converters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,31 @@ protected override string ConvertBack(bool value, object? parameter, string? lan
return string.Empty;
}
}

internal sealed class NullToVisibilityCollapsedConverter : ValueConverter<object?, Visibility>
{
/// <summary>
/// Converts a source value to the target type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override Visibility Convert(object? value, object? parameter, string? language)
{
return value is null ? Visibility.Collapsed : Visibility.Visible;
}

/// <summary>
/// Converts a target value back to the source type.
/// </summary>
/// <param name="value"></param>
/// <param name="parameter"></param>
/// <param name="language"></param>
/// <returns></returns>
protected override object? ConvertBack(Visibility value, object? parameter, string? language)
{
return new NotSupportedException();
}
}
}
147 changes: 76 additions & 71 deletions src/Files.App/UserControls/StatusBarControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

<UserControl.Resources>
<converters:NullToTrueConverter x:Key="NullToFalseConverter" Inverse="True" />
<converters:NullToVisibilityCollapsedConverter x:Key="NullToVisibilityCollapsedConverter" />

<Style x:Key="Local.RadioButtonStyle" TargetType="RadioButton">
<Setter Property="Foreground" Value="{ThemeResource TextFillColorSecondaryBrush}" />
Expand Down Expand Up @@ -100,10 +101,11 @@
</Style>
</UserControl.Resources>

<Grid Padding="8,0" ColumnSpacing="8">
<Grid Padding="8,0" ColumnSpacing="4">
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel
Grid.Column="0"
Expand Down Expand Up @@ -201,83 +203,86 @@
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.PullInfo, Mode=OneWay}" />
</StackPanel>
</Button>
</StackPanel>

<Button
x:Name="GitBranch"
Height="24"
Padding="8,0,8,0"
Background="Transparent"
BorderBrush="Transparent"
ToolTipService.ToolTip="{helpers:ResourceString Name=ManageBranches}">

<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="8">
<usercontrols:OpacityIcon Style="{StaticResource ColorIconGitBranches}" />

<!-- Branch Name -->
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay}" />
</StackPanel>
</Button.Content>
<!-- Use visibility because it causes a crash to use a TwoWay x:Bind on an element that is inside an element with x:Load (#12589, #12599) -->
<Button
x:Name="GitBranch"
Grid.Column="2"
yaira2 marked this conversation as resolved.
Show resolved Hide resolved
Height="24"
Padding="8,0,8,0"
Background="Transparent"
BorderBrush="Transparent"
ToolTipService.ToolTip="{helpers:ResourceString Name=ManageBranches}"
Visibility="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay, Converter={StaticResource NullToVisibilityCollapsedConverter}}">

<Button.Flyout>
<Flyout x:Name="BranchesFlyout" Opening="BranchesFlyout_Opening">
<Grid
Width="300"
Height="340"
Margin="-16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button.Content>
<StackPanel Orientation="Horizontal" Spacing="8">
<usercontrols:OpacityIcon Style="{StaticResource ColorIconGitBranches}" />

<!-- Header -->
<Grid
Grid.Row="0"
Padding="4,8,8,8"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="0,0,0,1">
<!-- Branch Name -->
<TextBlock Text="{x:Bind DirectoryPropertiesViewModel.GitBranchDisplayName, Mode=OneWay}" />
</StackPanel>
</Button.Content>

<!-- Locals and Remotes -->
<StackPanel
Grid.Row="1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal">
<RadioButton
Content="{helpers:ResourceString Name=Locals}"
IsChecked="{x:Bind DirectoryPropertiesViewModel.ShowLocals, Mode=TwoWay}"
Style="{StaticResource Local.RadioButtonStyle}" />
<RadioButton Content="{helpers:ResourceString Name=Remotes}" Style="{StaticResource Local.RadioButtonStyle}" />
</StackPanel>
<Button.Flyout>
<Flyout x:Name="BranchesFlyout" Opening="BranchesFlyout_Opening">
<Grid
Width="300"
Height="340"
Margin="-16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>

<!-- New Branch Button -->
<Button
x:Name="NewBranchButton"
Height="24"
Padding="8,0"
HorizontalAlignment="Right"
Command="{x:Bind DirectoryPropertiesViewModel.NewBranchCommand, Mode=OneWay}"
Content="{helpers:ResourceString Name=CreateBranch}"
FontSize="12"
ToolTipService.ToolTip="{helpers:ResourceString Name=CreateBranch}" />
</Grid>
<!-- Header -->
<Grid
Grid.Row="0"
Padding="4,8,8,8"
Background="{ThemeResource AcrylicBackgroundFillColorDefaultBrush}"
BorderBrush="{ThemeResource CardStrokeColorDefaultBrush}"
BorderThickness="0,0,0,1">

<!-- Branches List -->
<ListView
x:Name="BranchesList"
<!-- Locals and Remotes -->
<StackPanel
Grid.Row="1"
Padding="4"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
IsItemClickEnabled="True"
ItemClick="BranchesList_ItemClick"
ItemsSource="{x:Bind DirectoryPropertiesViewModel.BranchesNames, Mode=OneWay}"
SelectedIndex="{x:Bind DirectoryPropertiesViewModel.SelectedBranchIndex, Mode=TwoWay}"
SelectionMode="Single" />
HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal">
<RadioButton
Content="{helpers:ResourceString Name=Locals}"
IsChecked="{x:Bind DirectoryPropertiesViewModel.ShowLocals, Mode=TwoWay}"
Style="{StaticResource Local.RadioButtonStyle}" />
<RadioButton Content="{helpers:ResourceString Name=Remotes}" Style="{StaticResource Local.RadioButtonStyle}" />
</StackPanel>

<!-- New Branch Button -->
<Button
x:Name="NewBranchButton"
Height="24"
Padding="8,0"
HorizontalAlignment="Right"
Command="{x:Bind DirectoryPropertiesViewModel.NewBranchCommand, Mode=OneWay}"
Content="{helpers:ResourceString Name=CreateBranch}"
FontSize="12"
ToolTipService.ToolTip="{helpers:ResourceString Name=CreateBranch}" />
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</StackPanel>

<!-- Branches List -->
<ListView
x:Name="BranchesList"
Grid.Row="1"
Padding="4"
Background="{ThemeResource CardBackgroundFillColorDefaultBrush}"
IsItemClickEnabled="True"
ItemClick="BranchesList_ItemClick"
ItemsSource="{x:Bind DirectoryPropertiesViewModel.BranchesNames, Mode=OneWay}"
SelectedIndex="{x:Bind DirectoryPropertiesViewModel.SelectedBranchIndex, Mode=TwoWay}"
SelectionMode="Single" />
</Grid>
</Flyout>
</Button.Flyout>
</Button>
</Grid>
</UserControl>