mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-24 20:57:19 -08:00
Enable to configure global core.autocrlf
in Preference panel
This commit is contained in:
parent
da81d0c6c8
commit
fd4cb12b4a
2 changed files with 374 additions and 308 deletions
|
@ -8,7 +8,7 @@
|
||||||
xmlns:app="clr-namespace:SourceGit"
|
xmlns:app="clr-namespace:SourceGit"
|
||||||
xmlns:git="clr-namespace:SourceGit.Git"
|
xmlns:git="clr-namespace:SourceGit.Git"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Height="472" Width="500">
|
Height="500" Width="500">
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="36"/>
|
<RowDefinition Height="36"/>
|
||||||
|
@ -21,6 +21,7 @@
|
||||||
<RowDefinition Height="36"/>
|
<RowDefinition Height="36"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
|
<RowDefinition Height="28"/>
|
||||||
<RowDefinition Height="18"/>
|
<RowDefinition Height="18"/>
|
||||||
<RowDefinition Height="36"/>
|
<RowDefinition Height="36"/>
|
||||||
<RowDefinition Height="28"/>
|
<RowDefinition Height="28"/>
|
||||||
|
@ -81,16 +82,32 @@
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<!-- Global User -->
|
<!-- Global User -->
|
||||||
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL USER" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
<Label Grid.Row="7" Grid.ColumnSpan="2" Content="GLOBAL SETTING" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
||||||
<Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="8" Grid.Column="0" Content="Name :" HorizontalAlignment="Right"/>
|
||||||
<TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
|
<TextBox Grid.Row="8" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user name" Text="{Binding ElementName=me, Path=GlobalUser, Mode=TwoWay}"/>
|
||||||
<Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="9" Grid.Column="0" Content="Email :" HorizontalAlignment="Right"/>
|
||||||
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
|
<TextBox Grid.Row="9" Grid.Column="1" Height="24" helpers:TextBoxHelper.Placeholder="Global git user email" Text="{Binding ElementName=me, Path=GlobalUserEmail, Mode=TwoWay}"/>
|
||||||
|
<Label Grid.Row="10" Grid.Column="0" Content="Auto CRLF :" HorizontalAlignment="Right"/>
|
||||||
|
<ComboBox Grid.Row="10" Grid.Column="1"
|
||||||
|
x:Name="cmbAutoCRLF"
|
||||||
|
Height="24"
|
||||||
|
HorizontalAlignment="Stretch"
|
||||||
|
VerticalContentAlignment="Center"
|
||||||
|
SelectionChanged="AutoCRLFSelectionChanged">
|
||||||
|
<ComboBox.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<StackPanel Orientation="Horizontal" Height="20">
|
||||||
|
<Label Content="{Binding Value}" Padding="0" VerticalContentAlignment="Center"/>
|
||||||
|
<Label Content="{Binding Desc}" Foreground="{StaticResource Brush.FG2}" FontSize="10" Margin="8,0,0,0" Padding="0"/>
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</ComboBox.ItemTemplate>
|
||||||
|
</ComboBox>
|
||||||
|
|
||||||
<!-- 合并工具配置 -->
|
<!-- 合并工具配置 -->
|
||||||
<Label Grid.Row="11" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
<Label Grid.Row="12" Grid.ColumnSpan="2" Content="MERGE TOOL" FontSize="16" FontWeight="DemiBold" Opacity=".85"/>
|
||||||
<Label Grid.Row="12" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="13" Grid.Column="0" Content="Choose Merger :" HorizontalAlignment="Right"/>
|
||||||
<ComboBox Grid.Row="12" Grid.Column="1"
|
<ComboBox Grid.Row="13" Grid.Column="1"
|
||||||
Height="24"
|
Height="24"
|
||||||
Padding="2,0,0,0"
|
Padding="2,0,0,0"
|
||||||
HorizontalContentAlignment="Left"
|
HorizontalContentAlignment="Left"
|
||||||
|
@ -99,8 +116,8 @@
|
||||||
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
|
ItemsSource="{Binding Source={x:Static git:MergeTool.Supported}}"
|
||||||
DisplayMemberPath="Name"
|
DisplayMemberPath="Name"
|
||||||
SelectionChanged="ChangeMergeTool"/>
|
SelectionChanged="ChangeMergeTool"/>
|
||||||
<Label Grid.Row="13" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="14" Grid.Column="0" Content="Install Path :" HorizontalAlignment="Right"/>
|
||||||
<Grid Grid.Row="13" Grid.Column="1">
|
<Grid Grid.Row="14" Grid.Column="1">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="*"/>
|
<ColumnDefinition Width="*"/>
|
||||||
<ColumnDefinition Width="28"/>
|
<ColumnDefinition Width="28"/>
|
||||||
|
@ -115,13 +132,13 @@
|
||||||
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
|
<Path Width="14" Style="{StaticResource Style.Icon}" Data="{StaticResource Icon.Folder}"/>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Label Grid.Row="14" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
|
<Label Grid.Row="15" Grid.Column="0" Content="Command :" HorizontalAlignment="Right"/>
|
||||||
<TextBlock Grid.Row="14" Grid.Column="1"
|
<TextBlock Grid.Row="15" Grid.Column="1"
|
||||||
x:Name="txtMergeParam"
|
x:Name="txtMergeParam"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Foreground="{StaticResource Brush.FG2}"/>
|
Foreground="{StaticResource Brush.FG2}"/>
|
||||||
|
|
||||||
<Button Grid.Row="16" Grid.Column="1"
|
<Button Grid.Row="17" Grid.Column="1"
|
||||||
Content="CLOSE"
|
Content="CLOSE"
|
||||||
Click="Close"
|
Click="Close"
|
||||||
Width="80"
|
Width="80"
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
@ -28,12 +29,35 @@ namespace SourceGit.UI {
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Git core.autocrlf setting.
|
||||||
|
/// </summary>
|
||||||
|
public string AutoCRLF {
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Options for core.autocrlf
|
||||||
|
/// </summary>
|
||||||
|
public class AutoCRLFOption {
|
||||||
|
public string Value { get; set; }
|
||||||
|
public string Desc { get; set; }
|
||||||
|
|
||||||
|
public AutoCRLFOption(string v, string d) {
|
||||||
|
Value = v;
|
||||||
|
Desc = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructor.
|
/// Constructor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Preference() {
|
public Preference() {
|
||||||
GlobalUser = GetConfig("user.name");
|
GlobalUser = GetConfig("user.name");
|
||||||
GlobalUserEmail = GetConfig("user.email");
|
GlobalUserEmail = GetConfig("user.email");
|
||||||
|
AutoCRLF = GetConfig("core.autocrlf");
|
||||||
|
if (string.IsNullOrEmpty(AutoCRLF)) AutoCRLF = "false";
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -41,6 +65,14 @@ namespace SourceGit.UI {
|
||||||
var merger = Git.MergeTool.Supported[mergeType];
|
var merger = Git.MergeTool.Supported[mergeType];
|
||||||
txtMergePath.IsReadOnly = !merger.IsConfigured;
|
txtMergePath.IsReadOnly = !merger.IsConfigured;
|
||||||
txtMergeParam.Text = merger.Parameter;
|
txtMergeParam.Text = merger.Parameter;
|
||||||
|
|
||||||
|
var crlfOptions = new List<AutoCRLFOption>() {
|
||||||
|
new AutoCRLFOption("true", "Commit as LF, checkout as CRLF"),
|
||||||
|
new AutoCRLFOption("input", "Only convert for commit"),
|
||||||
|
new AutoCRLFOption("false", "Do NOT convert"),
|
||||||
|
};
|
||||||
|
cmbAutoCRLF.ItemsSource = crlfOptions;
|
||||||
|
cmbAutoCRLF.SelectedItem = crlfOptions.Find(o => o.Value == AutoCRLF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -60,6 +92,9 @@ namespace SourceGit.UI {
|
||||||
var oldEmail = GetConfig("user.email");
|
var oldEmail = GetConfig("user.email");
|
||||||
if (oldEmail != GlobalUserEmail) SetConfig("user.email", GlobalUserEmail);
|
if (oldEmail != GlobalUserEmail) SetConfig("user.email", GlobalUserEmail);
|
||||||
|
|
||||||
|
var oldAutoCRLF = GetConfig("core.autocrlf");
|
||||||
|
if (oldAutoCRLF != AutoCRLF) SetConfig("core.autocrlf", AutoCRLF);
|
||||||
|
|
||||||
PopupManager.Close();
|
PopupManager.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +173,20 @@ namespace SourceGit.UI {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set core.autocrlf
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="sender"></param>
|
||||||
|
/// <param name="e"></param>
|
||||||
|
private void AutoCRLFSelectionChanged(object sender, SelectionChangedEventArgs e) {
|
||||||
|
if (e.AddedItems.Count != 1) return;
|
||||||
|
|
||||||
|
var mode = e.AddedItems[0] as AutoCRLFOption;
|
||||||
|
if (mode == null) return;
|
||||||
|
|
||||||
|
AutoCRLF = mode.Value;
|
||||||
|
}
|
||||||
|
|
||||||
#region CONFIG
|
#region CONFIG
|
||||||
private string GetConfig(string key) {
|
private string GetConfig(string key) {
|
||||||
if (!App.IsGitConfigured) return "";
|
if (!App.IsGitConfigured) return "";
|
||||||
|
|
Loading…
Reference in a new issue