using Microsoft.Win32; using System; using System.Windows; using System.Windows.Controls; namespace SourceGit.UI { /// /// Preference window. /// public partial class Preference : UserControl { /// /// Constructor. /// public Preference() { InitializeComponent(); int mergeType = App.Preference.MergeTool; var merger = Git.MergeTool.Supported[mergeType]; txtMergePath.IsReadOnly = !merger.IsConfigured; txtMergeParam.Text = merger.Parameter; } /// /// Show preference. /// public static void Show() { PopupManager.Show(new Preference()); } /// /// Close this dialog /// private void Close(object sender, RoutedEventArgs e) { PopupManager.Close(); } /// /// Select git executable file path. /// /// /// private void SelectGitPath(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Git Executable|git.exe"; dialog.FileName = "git.exe"; dialog.Title = "Select Git Executable File"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); dialog.CheckFileExists = true; if (dialog.ShowDialog() == true) { txtGitPath.Text = dialog.FileName; App.Preference.GitExecutable = dialog.FileName; } } /// /// Set default clone path. /// /// /// private void SelectDefaultClonePath(object sender, RoutedEventArgs e) { var dialog = new System.Windows.Forms.FolderBrowserDialog(); dialog.Description = "Select Folder To Clone Repository Into As Default"; dialog.RootFolder = Environment.SpecialFolder.MyComputer; dialog.ShowNewFolderButton = true; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { txtGitCloneDir.Text = dialog.SelectedPath; App.Preference.GitDefaultCloneDir = dialog.SelectedPath; } } /// /// Choose external merge tool. /// /// /// private void ChangeMergeTool(object sender, SelectionChangedEventArgs e) { if (IsLoaded) { var t = Git.MergeTool.Supported[App.Preference.MergeTool]; App.Preference.MergeExecutable = t.Finder(); txtMergePath.Text = App.Preference.MergeExecutable; txtMergeParam.Text = t.Parameter; txtMergePath.IsReadOnly = !t.IsConfigured; } } /// /// Set merge tool executable file path. /// /// /// private void SelectMergeToolPath(object sender, RoutedEventArgs e) { int mergeType = App.Preference.MergeTool; if (mergeType == 0) return; var merger = Git.MergeTool.Supported[mergeType]; var dialog = new OpenFileDialog(); dialog.Filter = $"{merger.Name} Executable|{merger.ExecutableName}"; dialog.Title = $"Select {merger.Name} Install Path"; dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles); dialog.CheckFileExists = true; if (dialog.ShowDialog() == true) { txtMergePath.Text = dialog.FileName; App.Preference.MergeExecutable = dialog.FileName; } } } }