Skip to content

Commit 387fa93

Browse files
authored
Use Avalonia 11 generated view codes (#1479)
Avalonia 11 automatically generates some view codes. - Properties for controls with `x:Name` or `Name`. - `InitializeComponent()` method to initialize such properties. - DevTools for debug builds. This change uses such generated codes in views and reduces manual efforts. The names of the controls are changed to start with underscore, so that the generated property names align with the naming style in this project.
2 parents df96311 + 2e16a72 commit 387fa93

22 files changed

+44
-176
lines changed

src/shared/Atlassian.Bitbucket/UI/Views/CredentialsView.axaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
Margin="0,10,0,0"/>
3030
</StackPanel>
3131

32-
<TabControl x:Name="authModesTabControl"
32+
<TabControl x:Name="_authModesTabControl"
3333
VerticalContentAlignment="Center"
3434
AutoScrollToSelectedItem="True"
3535
Width="288"
@@ -48,7 +48,7 @@
4848
<TextBlock Text="Browser" FontSize="12" />
4949
</TabItem.Header>
5050
<StackPanel Margin="0,15">
51-
<Button x:Name="oauthLoginButton" IsDefault="True"
51+
<Button x:Name="_oauthLoginButton" IsDefault="True"
5252
HorizontalAlignment="Center" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
5353
Command="{Binding OAuthCommand}"
5454
Classes="accent" Height="40" Padding="15,5"
@@ -61,11 +61,11 @@
6161
<TextBlock Text="Password/Token" FontSize="12" />
6262
</TabItem.Header>
6363
<StackPanel Margin="0,15">
64-
<TextBox x:Name="userNameTextBox" Margin="0,0,0,10"
64+
<TextBox x:Name="_userNameTextBox" Margin="0,0,0,10"
6565
HorizontalAlignment="Stretch"
6666
Watermark="Email or username"
6767
Text="{Binding UserName}" />
68-
<TextBox x:Name="passwordTextBox" Margin="0,0,0,10"
68+
<TextBox x:Name="_passwordTextBox" Margin="0,0,0,10"
6969
HorizontalAlignment="Stretch"
7070
Watermark="Password or token" PasswordChar=""
7171
Text="{Binding Password}" />

src/shared/Atlassian.Bitbucket/UI/Views/CredentialsView.axaml.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,11 @@ namespace Atlassian.Bitbucket.UI.Views
88
{
99
public partial class CredentialsView : UserControl, IFocusable
1010
{
11-
private TabControl _tabControl;
12-
private Button _oauthLoginButton;
13-
private TextBox _userNameTextBox;
14-
private TextBox _passwordTextBox;
15-
1611
public CredentialsView()
1712
{
1813
InitializeComponent();
1914
}
2015

21-
private void InitializeComponent()
22-
{
23-
AvaloniaXamlLoader.Load(this);
24-
25-
_tabControl = this.FindControl<TabControl>("authModesTabControl");
26-
_oauthLoginButton = this.FindControl<Button>("oauthLoginButton");
27-
_userNameTextBox = this.FindControl<TextBox>("userNameTextBox");
28-
_passwordTextBox = this.FindControl<TextBox>("passwordTextBox");
29-
}
30-
3116
public void SetFocus()
3217
{
3318
if (!(DataContext is CredentialsViewModel vm))
@@ -37,12 +22,12 @@ public void SetFocus()
3722

3823
if (vm.ShowOAuth)
3924
{
40-
_tabControl.SelectedIndex = 0;
25+
_authModesTabControl.SelectedIndex = 0;
4126
_oauthLoginButton.Focus();
4227
}
4328
else if (vm.ShowBasic)
4429
{
45-
_tabControl.SelectedIndex = 1;
30+
_authModesTabControl.SelectedIndex = 1;
4631
if (string.IsNullOrWhiteSpace(vm.UserName))
4732
{
4833
// Workaround: https://github.com/git-ecosystem/git-credential-manager/issues/1293

src/shared/Core/UI/Controls/AboutWindow.axaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,6 @@ public partial class AboutWindow : Window
1414
public AboutWindow()
1515
{
1616
InitializeComponent();
17-
#if DEBUG
18-
this.AttachDevTools();
19-
#endif
20-
}
21-
22-
private void InitializeComponent()
23-
{
24-
AvaloniaXamlLoader.Load(this);
2517
}
2618

2719
private void ProjectButton_Click(object sender, RoutedEventArgs e)

src/shared/Core/UI/Controls/DialogWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
Content="Show Custom Chrome" Margin="5,0"/>
6565
</StackPanel>
6666

67-
<ContentControl x:Name="contentHolder" Margin="30,25,30,30"/>
67+
<ContentControl x:Name="_contentHolder" Margin="30,25,30,30"/>
6868
</DockPanel>
6969
</Border>
7070

src/shared/Core/UI/Controls/DialogWindow.axaml.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ namespace GitCredentialManager.UI.Controls
1212
public partial class DialogWindow : Window
1313
{
1414
private readonly Control _view;
15-
private ContentControl _contentHolder;
1615

1716
public DialogWindow() : this(null)
1817
{
@@ -22,20 +21,10 @@ public DialogWindow() : this(null)
2221
public DialogWindow(Control view)
2322
{
2423
InitializeComponent();
25-
#if DEBUG
26-
this.AttachDevTools();
27-
#endif
2824
_view = view;
2925
_contentHolder.Content = _view;
3026
}
3127

32-
private void InitializeComponent()
33-
{
34-
AvaloniaXamlLoader.Load(this);
35-
36-
_contentHolder = this.FindControl<ContentControl>("contentHolder");
37-
}
38-
3928
protected override void OnDataContextChanged(EventArgs e)
4029
{
4130
if (DataContext is WindowViewModel vm)

src/shared/Core/UI/Controls/ProgressWindow.axaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public ProgressWindow()
1414
InitializeComponent();
1515
}
1616

17-
private void InitializeComponent()
18-
{
19-
AvaloniaXamlLoader.Load(this);
20-
}
21-
2217
public static IntPtr ShowAndGetHandle(CancellationToken ct)
2318
{
2419
var tsc = new TaskCompletionSource<IntPtr>();

src/shared/Core/UI/Views/CredentialsView.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
</StackPanel>
3434

3535
<StackPanel Margin="20,0">
36-
<TextBox x:Name="userNameTextBox"
36+
<TextBox x:Name="_userNameTextBox"
3737
Watermark="Username" Margin="0,0,0,10"
3838
Text="{Binding UserName}"/>
39-
<TextBox x:Name="passwordTextBox"
39+
<TextBox x:Name="_passwordTextBox"
4040
Watermark="Password" Margin="0,0,0,20"
4141
PasswordChar=""
4242
Text="{Binding Password}"/>

src/shared/Core/UI/Views/CredentialsView.axaml.cs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,11 @@ namespace GitCredentialManager.UI.Views
77
{
88
public partial class CredentialsView : UserControl, IFocusable
99
{
10-
private TextBox _userNameTextBox;
11-
private TextBox _passwordTextBox;
12-
1310
public CredentialsView()
1411
{
1512
InitializeComponent();
1613
}
1714

18-
private void InitializeComponent()
19-
{
20-
AvaloniaXamlLoader.Load(this);
21-
22-
_userNameTextBox = this.FindControl<TextBox>("userNameTextBox");
23-
_passwordTextBox = this.FindControl<TextBox>("passwordTextBox");
24-
}
25-
2615
public void SetFocus()
2716
{
2817
if (!(DataContext is CredentialsViewModel vm))

src/shared/Core/UI/Views/DefaultAccountView.axaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ public DefaultAccountView()
99
{
1010
InitializeComponent();
1111
}
12-
13-
private void InitializeComponent()
14-
{
15-
AvaloniaXamlLoader.Load(this);
16-
}
1712
}
1813
}

src/shared/Core/UI/Views/DeviceCodeView.axaml.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,5 @@ public DeviceCodeView()
99
{
1010
InitializeComponent();
1111
}
12-
13-
private void InitializeComponent()
14-
{
15-
AvaloniaXamlLoader.Load(this);
16-
}
1712
}
1813
}

0 commit comments

Comments
 (0)