/GitUI/FormSettings.cs
C# | 2343 lines | 2041 code | 277 blank | 25 comment | 203 complexity | 843cdb74fc5cb02984f60e537aa04782 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
Large files files are truncated, but you can click here to view the full file
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Windows.Forms;
- using GitCommands;
- using GitCommands.Config;
- using GitUI.Editor;
- using GitUI.Script;
- using Gravatar;
- using Microsoft.Win32;
- using ResourceManager.Translation;
-
- namespace GitUI
- {
- public sealed partial class FormSettings : GitExtensionsForm
- {
- #region Translation
- private readonly TranslationString _homeIsSetToString = new TranslationString("HOME is set to:");
- private readonly TranslationString __diffToolSuggestCaption = new TranslationString("Suggest difftool cmd");
- private readonly TranslationString __mergeToolSuggestCaption = new TranslationString("Suggest mergetool cmd");
-
- private readonly TranslationString _loadingSettingsFailed =
- new TranslationString("Could not load settings.");
-
- private readonly TranslationString _cantFindGitMessage =
- new TranslationString("The command to run git is not configured correct." + Environment.NewLine +
- "You need to set the correct path to be able to use GitExtensions." + Environment.NewLine +
- Environment.NewLine + "Do you want to set the correct command now?");
-
- private readonly TranslationString _cantFindGitMessageCaption =
- new TranslationString("Incorrect path");
-
- private static readonly TranslationString _cantReadRegistry =
- new TranslationString("GitExtensions has insufficient permissions to check the registry.");
-
- private static readonly TranslationString _cantReadRegistryAddEntryManually =
- new TranslationString("GitExtensions has insufficient permissions to modify the registry." +
- Environment.NewLine + "Please add this key to the registry manually." +
- Environment.NewLine + "Path: {0}\\{1}" + Environment.NewLine +
- "Value: {2} = {3}");
-
- private readonly TranslationString _cantRegisterShellExtension =
- new TranslationString("Could not register the shell extension because '{0}' could not be found.");
-
- private readonly TranslationString _noDiffToolConfigured =
- new TranslationString("There is no difftool configured. Do you want to configure kdiff3 as your difftool?" +
- Environment.NewLine + "Select no if you want to configure a different difftool yourself.");
-
- private readonly TranslationString _noDiffToolConfiguredCaption =
- new TranslationString("Difftool");
-
- private readonly TranslationString _kdiff3NotFoundAuto =
- new TranslationString("Path to kdiff3 could not be found automatically." + Environment.NewLine +
- "Please make sure KDiff3 is installed or set path manually.");
-
- private readonly TranslationString _noMergeToolConfigured =
- new TranslationString("There is no mergetool configured. Do you want to configure kdiff3 as your mergetool?" +
- Environment.NewLine + "Select no if you want to configure a different mergetool yourself.");
-
- private readonly TranslationString _noMergeToolConfiguredCaption =
- new TranslationString("Mergetool");
-
- private readonly TranslationString _solveGitCommandFailed =
- new TranslationString("The command to run git could not be determined automatically." + Environment.NewLine +
- "Please make sure git (msysgit or cygwin) is installed or set the correct command manually.");
-
- private readonly TranslationString _solveGitCommandFailedCaption =
- new TranslationString("Locate git");
-
- private readonly TranslationString _gitCanBeRun =
- new TranslationString("Git can be run using: {0}");
-
- private readonly TranslationString _gitCanBeRunCaption =
- new TranslationString("Locate git");
-
- private readonly TranslationString _linuxToolsShNotFound =
- new TranslationString("The path to linux tools (sh) could not be found automatically." + Environment.NewLine +
- "Please make sure there are linux tools installed (through msysgit or cygwin) or set the correct path manually.");
-
- private readonly TranslationString _linuxToolsShNotFoundCaption =
- new TranslationString("Locate linux tools");
-
- private readonly TranslationString _shCanBeRun =
- new TranslationString("Command sh can be run using: {0}sh");
-
- private readonly TranslationString _shCanBeRunCaption =
- new TranslationString("Locate linux tools");
-
- private static readonly TranslationString _selectFile =
- new TranslationString("Select file");
-
- private readonly TranslationString _puttyFoundAuto =
- new TranslationString("All paths needed for PuTTY could be automatically found and are set.");
-
- private readonly TranslationString _puttyFoundAutoCaption =
- new TranslationString("PuTTY");
-
- private readonly TranslationString _noDictFilesFound =
- new TranslationString("No dictionary files found in: {0}");
-
- private readonly TranslationString _noLanguageConfigured =
- new TranslationString("There is no language configured for Git Extensions.");
-
- private readonly TranslationString _languageConfigured =
- new TranslationString("The configured language is {0}.");
-
- private readonly TranslationString _plinkputtyGenpageantNotFound =
- new TranslationString("PuTTY is configured as SSH client but cannot find plink.exe, puttygen.exe or pageant.exe.");
-
- private readonly TranslationString _puttyConfigured =
- new TranslationString("SSH client PuTTY is configured properly.");
-
- private readonly TranslationString _opensshUsed =
- new TranslationString("Default SSH client, OpenSSH, will be used. (commandline window will appear on pull, push and clone operations)");
-
- private readonly TranslationString _unknownSshClient =
- new TranslationString("Unknown SSH client configured: {0}.");
-
- private readonly TranslationString _linuxToolsSshNotFound =
- new TranslationString("Linux tools (sh) not found. To solve this problem you can set the correct path in settings.");
-
- private readonly TranslationString _linuxToolsSshFound =
- new TranslationString("Linux tools (sh) found on your computer.");
-
- private readonly TranslationString _gitNotFound =
- new TranslationString("Git not found. To solve this problem you can set the correct path in settings.");
-
- private readonly TranslationString _wrongGitVersion =
- new TranslationString("Git found but version {0} is not supported. Upgrage to version {1} or later");
-
- private readonly TranslationString _gitVersionFound =
- new TranslationString("Git {0} is found on your computer.");
-
- private readonly TranslationString _adviceDiffToolConfiguration =
- new TranslationString("You should configure a diff tool to show file diff in external program (kdiff3 for example).");
-
- private readonly TranslationString _kdiffAsDiffConfiguredButNotFound =
- new TranslationString("KDiff3 is configured as difftool, but the path to kdiff.exe is not configured.");
-
- private readonly TranslationString _kdiffAsDiffConfigured =
- new TranslationString("KDiff3 is configured as difftool.");
-
- private readonly TranslationString _toolSuggestPath =
- new TranslationString("Please enter the path to {0} and press suggest.");
-
- private readonly TranslationString _diffToolXConfigured =
- new TranslationString("There is a difftool configured: {0}");
-
- private readonly TranslationString _configureMergeTool =
- new TranslationString("You need to configure merge tool in order to solve mergeconflicts (kdiff3 for example).");
-
- private readonly TranslationString _kdiffAsMergeConfiguredButNotFound =
- new TranslationString("KDiff3 is configured as mergetool, but the path to kdiff.exe is not configured.");
-
- private readonly TranslationString _kdiffAsMergeConfigured =
- new TranslationString("KDiff3 is configured as mergetool.");
-
- private readonly TranslationString _mergeToolXConfiguredNeedsCmd =
- new TranslationString("{0} is configured as mergetool, this is a custom mergetool and needs a custom cmd to be configured.");
-
- private readonly TranslationString _customMergeToolXConfigured =
- new TranslationString("There is a custom mergetool configured: {0}");
-
- private readonly TranslationString _mergeToolXConfigured =
- new TranslationString("There is a custom mergetool configured.");
-
- private readonly TranslationString _noEmailSet =
- new TranslationString("You need to configure a username and an email address.");
-
- private readonly TranslationString _emailSet =
- new TranslationString("A username and an email address are configured.");
-
- private readonly TranslationString _shellExtNoInstalled =
- new TranslationString("Shell extensions are not installed. Run the installer to install the shell extensions.");
-
- private readonly TranslationString _shellExtNeedsToBeRegistered =
- new TranslationString("{0} needs to be registered in order to use the shell extensions.");
-
- private readonly TranslationString _shellExtRegistered =
- new TranslationString("Shell extensions registered properly.");
-
- private readonly TranslationString _registryKeyGitExtensionsMissing =
- new TranslationString("Registry entry missing [Software\\GitExtensions\\GitExtensions\\InstallDir].");
-
- private readonly TranslationString _registryKeyGitExtensionsFaulty =
- new TranslationString("Invalid installation directory stored in [Software\\GitExtensions\\GitExtensions\\InstallDir].");
-
- private readonly TranslationString _registryKeyGitExtensionsCorrect =
- new TranslationString("GitExtensions is properly registered.");
- #endregion
-
- private Font diffFont;
- private const string GitExtensionsShellExName = "GitExtensionsShellEx32.dll";
- private string IconName = "bug";
-
- public FormSettings()
- {
- InitializeComponent();
- Translate();
-
- noImageService.Items.AddRange(GravatarService.DynamicServices.Cast<object>().ToArray());
-
- FillEncodings(Global_FilesEncoding);
- FillEncodings(Global_AppEncoding);
- FillEncodings(Local_FilesEncoding);
- FillEncodings(Local_AppEncoding);
-
- string npp = MergeToolsHelper.FindFileInFolders("notepad++.exe", "Notepad++");
- if (string.IsNullOrEmpty(npp))
- npp = "notepad++";
- else
- npp = "\"" + npp + "\"";
-
- GlobalEditor.Items.AddRange(new Object[] { "\"" + Settings.GetGitExtensionsFullPath() + "\" fileeditor", "vi", "notepad", npp + " -multiInst -nosession" });
-
- SetCurrentDiffFont(Settings.DiffFont);
- }
-
- protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
- {
- base.OnClosing(e);
- SavePosition("settings");
- }
-
- public static bool AutoSolveAllSettings()
- {
- if (!Settings.RunningOnWindows())
- return SolveGitCommand();
-
- return SolveGitCommand() &&
- SolveLinuxToolsDir() &&
- SolveMergeToolForKDiff() &&
- SolveDiffToolForKDiff() &&
- SolveGitExtensionsDir() &&
- SolveEditor();
- }
-
- private static string GetGlobalEditor()
- {
- string editor = Environment.GetEnvironmentVariable("GIT_EDITOR");
- if (!string.IsNullOrEmpty(editor))
- return editor;
- editor = Settings.Module.GetGlobalPathSetting("core.editor");
- if (!string.IsNullOrEmpty(editor))
- return editor;
- editor = Environment.GetEnvironmentVariable("VISUAL");
- if (!string.IsNullOrEmpty(editor))
- return editor;
- return Environment.GetEnvironmentVariable("EDITOR");
- }
-
- private static bool SolveEditor()
- {
- string editor = GetGlobalEditor();
- if (string.IsNullOrEmpty(editor))
- {
- Settings.Module.SetGlobalPathSetting("core.editor", "\"" + Settings.GetGitExtensionsFullPath() + "\" fileeditor");
- }
-
- return true;
- }
-
- private static void SetCheckboxFromString(CheckBox checkBox, string str)
- {
- str = str.Trim().ToLower();
-
- switch (str)
- {
- case "true":
- {
- checkBox.CheckState = CheckState.Checked;
- return;
- }
- case "false":
- {
- checkBox.CheckState = CheckState.Unchecked;
- return;
- }
- default:
- checkBox.CheckState = CheckState.Indeterminate;
- return;
- }
- }
-
- private static string GetGlobalDiffToolFromConfig()
- {
- if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
- return GitCommandHelpers.GetGlobalConfig().GetValue("diff.guitool");
- return GitCommandHelpers.GetGlobalConfig().GetValue("diff.tool");
- }
-
- private static void SetGlobalDiffToolToConfig(ConfigFile configFile, string diffTool)
- {
- if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
- {
- configFile.SetValue("diff.guitool", diffTool);
- return;
- }
- configFile.SetValue("diff.tool", diffTool);
- }
-
- private void EncodingToCombo(Encoding encoding, ComboBox combo)
- {
- if (encoding == null)
- combo.Text = "";
- else
- combo.Text = encoding.EncodingName;
- }
-
- private Encoding ComboToEncoding(ComboBox combo)
- {
- return combo.SelectedItem as Encoding;
- }
-
- private void FillEncodings(ComboBox combo)
- {
- combo.Items.AddRange(Settings.availableEncodings.Values.ToArray());
- combo.DisplayMember = "EncodingName";
- }
-
- private bool loadingSettings;
-
- public void LoadSettings()
- {
- loadingSettings = true;
- try
- {
- GitCommandHelpers.SetEnvironmentVariable();
- homeIsSetToLabel.Text = string.Concat(_homeIsSetToString.Text, " ", GitCommandHelpers.GetHomeDir());
-
- scriptEvent.DataSource = Enum.GetValues(typeof(ScriptEvent));
- EncodingToCombo(Settings.GetFilesEncoding(false), Global_FilesEncoding);
- EncodingToCombo(Settings.GetAppEncoding(false, false), Global_AppEncoding);
- EncodingToCombo(Settings.GetFilesEncoding(true), Local_FilesEncoding);
- EncodingToCombo(Settings.GetAppEncoding(true, false), Local_AppEncoding);
-
- chkStartWithRecentWorkingDir.Checked = Settings.StartWithRecentWorkingDir;
- chkPlaySpecialStartupSound.Checked = Settings.PlaySpecialStartupSound;
- chkUsePatienceDiffAlgorithm.Checked = Settings.UsePatienceDiffAlgorithm;
- chkShowCurrentBranchInVisualStudio.Checked = Settings.ShowCurrentBranchInVisualStudio;
- RevisionGridQuickSearchTimeout.Value = Settings.RevisionGridQuickSearchTimeout;
- chkFollowRenamesInFileHistory.Checked = Settings.FollowRenamesInFileHistory;
- _NO_TRANSLATE_DaysToCacheImages.Value = Settings.AuthorImageCacheDays;
- _NO_TRANSLATE_authorImageSize.Value = Settings.AuthorImageSize;
- ShowAuthorGravatar.Checked = Settings.ShowAuthorGravatar;
- noImageService.Text = Settings.GravatarFallbackService;
- chkShowErrorsWhenStagingFiles.Checked = Settings.ShowErrorsWhenStagingFiles;
- chkStashUntrackedFiles.Checked = Settings.IncludeUntrackedFilesInAutoStash;
-
- Language.Items.Clear();
- Language.Items.Add("English");
- Language.Items.AddRange(Translator.GetAllTranslations());
- Language.Text = Settings.Translation;
-
- MulticolorBranches.Checked = Settings.MulticolorBranches;
- MulticolorBranches_CheckedChanged(null, null);
- DrawNonRelativesGray.Checked = Settings.RevisionGraphDrawNonRelativesGray;
- DrawNonRelativesTextGray.Checked = Settings.RevisionGraphDrawNonRelativesTextGray;
- chkShowCurrentChangesInRevisionGraph.Checked = Settings.RevisionGraphShowWorkingDirChanges;
- chkShowStashCountInBrowseWindow.Checked = Settings.ShowStashCount;
- BranchBorders.Checked = Settings.BranchBorders;
- StripedBanchChange.Checked = Settings.StripedBranchChange;
- chkShowGitStatusInToolbar.Checked = Settings.ShowGitStatusInBrowseToolbar;
-
- _NO_TRANSLATE_truncatePathMethod.Text = Settings.TruncatePathMethod;
- _NO_TRANSLATE_ColorGraphLabel.BackColor = Settings.GraphColor;
- _NO_TRANSLATE_ColorGraphLabel.Text = Settings.GraphColor.Name;
- _NO_TRANSLATE_ColorGraphLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorGraphLabel.BackColor);
- _NO_TRANSLATE_ColorTagLabel.BackColor = Settings.TagColor;
- _NO_TRANSLATE_ColorTagLabel.Text = Settings.TagColor.Name;
- _NO_TRANSLATE_ColorTagLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorTagLabel.BackColor);
- _NO_TRANSLATE_ColorBranchLabel.BackColor = Settings.BranchColor;
- _NO_TRANSLATE_ColorBranchLabel.Text = Settings.BranchColor.Name;
- _NO_TRANSLATE_ColorBranchLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorBranchLabel.BackColor);
- _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor = Settings.RemoteBranchColor;
- _NO_TRANSLATE_ColorRemoteBranchLabel.Text = Settings.RemoteBranchColor.Name;
- _NO_TRANSLATE_ColorRemoteBranchLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemoteBranchLabel.BackColor);
- _NO_TRANSLATE_ColorOtherLabel.BackColor = Settings.OtherTagColor;
- _NO_TRANSLATE_ColorOtherLabel.Text = Settings.OtherTagColor.Name;
- _NO_TRANSLATE_ColorOtherLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorOtherLabel.BackColor);
-
-
- _NO_TRANSLATE_ColorAddedLineLabel.BackColor = Settings.DiffAddedColor;
- _NO_TRANSLATE_ColorAddedLineLabel.Text = Settings.DiffAddedColor.Name;
- _NO_TRANSLATE_ColorAddedLineLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineLabel.BackColor);
- _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor = Settings.DiffAddedExtraColor;
- _NO_TRANSLATE_ColorAddedLineDiffLabel.Text = Settings.DiffAddedExtraColor.Name;
- _NO_TRANSLATE_ColorAddedLineDiffLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor);
-
- _NO_TRANSLATE_ColorRemovedLine.BackColor = Settings.DiffRemovedColor;
- _NO_TRANSLATE_ColorRemovedLine.Text = Settings.DiffRemovedColor.Name;
- _NO_TRANSLATE_ColorRemovedLine.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLine.BackColor);
- _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor = Settings.DiffRemovedExtraColor;
- _NO_TRANSLATE_ColorRemovedLineDiffLabel.Text = Settings.DiffRemovedExtraColor.Name;
- _NO_TRANSLATE_ColorRemovedLineDiffLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor);
- _NO_TRANSLATE_ColorSectionLabel.BackColor = Settings.DiffSectionColor;
- _NO_TRANSLATE_ColorSectionLabel.Text = Settings.DiffSectionColor.Name;
- _NO_TRANSLATE_ColorSectionLabel.ForeColor =
- ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorSectionLabel.BackColor);
-
- SmtpServer.Text = Settings.Smtp;
-
- _NO_TRANSLATE_MaxCommits.Value = Settings.MaxRevisionGraphCommits;
-
- GitPath.Text = Settings.GitCommand;
- GitBinPath.Text = Settings.GitBinDir;
-
- ConfigFile localConfig = Settings.Module.GetLocalConfig();
- ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
-
- UserName.Text = localConfig.GetValue("user.name");
- UserEmail.Text = localConfig.GetValue("user.email");
- Editor.Text = localConfig.GetPathValue("core.editor");
- LocalMergeTool.Text = localConfig.GetValue("merge.tool");
-
- Dictionary.Text = Settings.Dictionary;
-
- GlobalUserName.Text = globalConfig.GetValue("user.name");
- GlobalUserEmail.Text = globalConfig.GetValue("user.email");
- GlobalEditor.Text = globalConfig.GetPathValue("core.editor");
- GlobalMergeTool.Text = globalConfig.GetValue("merge.tool");
- CommitTemplatePath.Text = globalConfig.GetValue("commit.template");
-
- SetCheckboxFromString(KeepMergeBackup, localConfig.GetValue("mergetool.keepBackup"));
-
- string autocrlf = localConfig.GetValue("core.autocrlf").ToLower();
- localAutoCrlfFalse.Checked = autocrlf == "false";
- localAutoCrlfInput.Checked = autocrlf == "input";
- localAutoCrlfTrue.Checked = autocrlf == "true";
-
- if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
- MergetoolPath.Text = globalConfig.GetPathValue(string.Format("mergetool.{0}.path", GlobalMergeTool.Text));
- if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
- MergeToolCmd.Text = globalConfig.GetPathValue(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text));
-
- string iconColor = Settings.IconColor.ToLower();
- DefaultIcon.Checked = iconColor == "default";
- BlueIcon.Checked = iconColor == "blue";
- GreenIcon.Checked = iconColor == "green";
- PurpleIcon.Checked = iconColor == "purple";
- RedIcon.Checked = iconColor == "red";
- YellowIcon.Checked = iconColor == "yellow";
- RandomIcon.Checked = iconColor == "random";
-
- IconStyle.Text = Settings.IconStyle;
-
- ShowIconPreview();
-
- GlobalDiffTool.Text = GetGlobalDiffToolFromConfig();
-
- if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
- DifftoolPath.Text = globalConfig.GetPathValue(string.Format("difftool.{0}.path", GlobalDiffTool.Text));
- if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
- DifftoolCmd.Text = globalConfig.GetPathValue(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text));
-
- SetCheckboxFromString(GlobalKeepMergeBackup, globalConfig.GetValue("mergetool.keepBackup"));
-
- string globalAutocrlf = string.Empty;
- if (globalConfig.HasValue("core.autocrlf"))
- {
- globalAutocrlf = globalConfig.GetValue("core.autocrlf").ToLower();
- }
- else if (!string.IsNullOrEmpty(Settings.GitBinDir))
- {
- try
- {
- //the following lines only work for msysgit (i think). MSysgit has a config file
- //in the etc directory which is checked after the local and global config. In
- //practice this is only used to core.autocrlf. If there are more cases, we might
- //need to consider a better solution.
- var configFile =
- new ConfigFile(Path.GetDirectoryName(Settings.GitBinDir).Replace("bin", "etc\\gitconfig"), false);
- globalAutocrlf = configFile.GetValue("core.autocrlf").ToLower();
- }
- catch
- {
- }
- }
-
- globalAutoCrlfFalse.Checked = globalAutocrlf == "false";
- globalAutoCrlfInput.Checked = globalAutocrlf == "input";
- globalAutoCrlfTrue.Checked = globalAutocrlf == "true";
-
- PlinkPath.Text = Settings.Plink;
- PuttygenPath.Text = Settings.Puttygen;
- PageantPath.Text = Settings.Pageant;
- AutostartPageant.Checked = Settings.AutoStartPageant;
-
- chkCloseProcessDialog.Checked = Settings.CloseProcessDialog;
- chkShowGitCommandLine.Checked = Settings.ShowGitCommandLine;
-
- chkUseFastChecks.Checked = Settings.UseFastChecks;
- chkShowRelativeDate.Checked = Settings.RelativeDate;
-
- chkCascadedContextMenu.Checked = Settings.ShellCascadeContextMenu;
-
- for (int i = 0; i < Settings.ShellVisibleMenuItems.Length; i++)
- {
- chlMenuEntries.SetItemChecked(i, Settings.ShellVisibleMenuItems[i] == '1');
- }
-
- if (string.IsNullOrEmpty(GitCommandHelpers.GetSsh()))
- OpenSSH.Checked = true;
- else if (GitCommandHelpers.Plink())
- Putty.Checked = true;
- else
- {
- OtherSsh.Text = GitCommandHelpers.GetSsh();
- Other.Checked = true;
- }
-
- EnableSshOptions();
- LoadScripts();
- }
- catch (Exception ex)
- {
- MessageBox.Show(this, _loadingSettingsFailed.Text + Environment.NewLine + ex);
-
- // Bail out before the user saves the incompletely loaded settings
- // and has their day ruined.
- DialogResult = DialogResult.Abort;
- }
- loadingSettings = false;
- }
-
- private void Ok_Click(object sender, EventArgs e)
- {
- Close();
- }
-
- private bool Save()
- {
- SaveScripts();
-
- if (Settings.RunningOnWindows())
- FormFixHome.CheckHomePath();
-
- GitCommandHelpers.SetEnvironmentVariable(true);
-
- Settings.StartWithRecentWorkingDir = chkStartWithRecentWorkingDir.Checked;
- Settings.PlaySpecialStartupSound = chkPlaySpecialStartupSound.Checked;
- Settings.UsePatienceDiffAlgorithm = chkUsePatienceDiffAlgorithm.Checked;
- Settings.TruncatePathMethod = _NO_TRANSLATE_truncatePathMethod.Text;
- Settings.ShowCurrentBranchInVisualStudio = chkShowCurrentBranchInVisualStudio.Checked;
- Settings.ShowErrorsWhenStagingFiles = chkShowErrorsWhenStagingFiles.Checked;
- Settings.IncludeUntrackedFilesInAutoStash = chkStashUntrackedFiles.Checked;
- Settings.FollowRenamesInFileHistory = chkFollowRenamesInFileHistory.Checked;
-
- if ((int)_NO_TRANSLATE_authorImageSize.Value != Settings.AuthorImageSize)
- {
- Settings.AuthorImageSize = (int)_NO_TRANSLATE_authorImageSize.Value;
- GravatarService.ClearImageCache();
- }
-
- Settings.Translation = Language.Text;
- Strings.Reinit();
-
- Settings.ShowGitStatusInBrowseToolbar = chkShowGitStatusInToolbar.Checked;
-
- Settings.AuthorImageCacheDays = (int)_NO_TRANSLATE_DaysToCacheImages.Value;
-
- Settings.Smtp = SmtpServer.Text;
-
- Settings.GitCommand = GitPath.Text;
- Settings.GitBinDir = GitBinPath.Text;
-
- Settings.ShowAuthorGravatar = ShowAuthorGravatar.Checked;
- Settings.GravatarFallbackService = noImageService.Text;
-
- Settings.CloseProcessDialog = chkCloseProcessDialog.Checked;
- Settings.ShowGitCommandLine = chkShowGitCommandLine.Checked;
-
- Settings.UseFastChecks = chkUseFastChecks.Checked;
- Settings.RelativeDate = chkShowRelativeDate.Checked;
-
- Settings.Dictionary = Dictionary.Text;
-
- Settings.MaxRevisionGraphCommits = (int)_NO_TRANSLATE_MaxCommits.Value;
-
- Settings.Plink = PlinkPath.Text;
- Settings.Puttygen = PuttygenPath.Text;
- Settings.Pageant = PageantPath.Text;
- Settings.AutoStartPageant = AutostartPageant.Checked;
- Settings.SetFilesEncoding(false, ComboToEncoding(Global_FilesEncoding));
- Settings.SetAppEncoding(false, ComboToEncoding(Global_AppEncoding));
- Settings.SetFilesEncoding(true, ComboToEncoding(Local_FilesEncoding));
- Settings.SetAppEncoding(true, ComboToEncoding(Local_AppEncoding));
- Settings.RevisionGridQuickSearchTimeout = (int)RevisionGridQuickSearchTimeout.Value;
- Settings.MulticolorBranches = MulticolorBranches.Checked;
- Settings.RevisionGraphDrawNonRelativesGray = DrawNonRelativesGray.Checked;
- Settings.RevisionGraphDrawNonRelativesTextGray = DrawNonRelativesTextGray.Checked;
- Settings.RevisionGraphShowWorkingDirChanges = chkShowCurrentChangesInRevisionGraph.Checked;
- Settings.ShowStashCount = chkShowStashCountInBrowseWindow.Checked;
- Settings.BranchBorders = BranchBorders.Checked;
- Settings.StripedBranchChange = StripedBanchChange.Checked;
- Settings.GraphColor = _NO_TRANSLATE_ColorGraphLabel.BackColor;
- Settings.TagColor = _NO_TRANSLATE_ColorTagLabel.BackColor;
- Settings.BranchColor = _NO_TRANSLATE_ColorBranchLabel.BackColor;
- Settings.RemoteBranchColor = _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor;
- Settings.OtherTagColor = _NO_TRANSLATE_ColorOtherLabel.BackColor;
-
- Settings.DiffAddedColor = _NO_TRANSLATE_ColorAddedLineLabel.BackColor;
- Settings.DiffRemovedColor = _NO_TRANSLATE_ColorRemovedLine.BackColor;
- Settings.DiffAddedExtraColor = _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor;
- Settings.DiffRemovedExtraColor = _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor;
- Settings.DiffFont = diffFont;
- Settings.DiffSectionColor = _NO_TRANSLATE_ColorSectionLabel.BackColor;
-
- Settings.IconColor = GetSelectedApplicationIconColor();
- Settings.IconStyle = IconStyle.Text;
-
- // Shell Extension settings
- Settings.ShellCascadeContextMenu = chkCascadedContextMenu.Checked;
-
- String l_ShellVisibleMenuItems = "";
-
- for (int i = 0; i < chlMenuEntries.Items.Count; i++)
- {
- if (chlMenuEntries.GetItemChecked(i))
- {
- l_ShellVisibleMenuItems += "1";
- }
- else
- {
- l_ShellVisibleMenuItems += "0";
- }
- }
-
- Settings.ShellVisibleMenuItems = l_ShellVisibleMenuItems;
-
- EnableSettings();
-
- if (!CanFindGitCmd())
- {
- if (MessageBox.Show(this, _cantFindGitMessage.Text, _cantFindGitMessageCaption.Text,
- MessageBoxButtons.YesNo) == DialogResult.Yes)
- return false;
- }
- else
- {
- handleCanFindGitCommand();
- }
-
- if (OpenSSH.Checked)
- GitCommandHelpers.UnsetSsh();
-
- if (Putty.Checked)
- GitCommandHelpers.SetSsh(PlinkPath.Text);
-
- if (Other.Checked)
- GitCommandHelpers.SetSsh(OtherSsh.Text);
-
- Settings.SaveSettings();
-
- return true;
- }
-
- private string GetSelectedApplicationIconColor()
- {
- if (BlueIcon.Checked)
- return "blue";
- if (LightblueIcon.Checked)
- return "lightblue";
- if (GreenIcon.Checked)
- return "green";
- if (PurpleIcon.Checked)
- return "purple";
- if (RedIcon.Checked)
- return "red";
- if (YellowIcon.Checked)
- return "yellow";
- if (RandomIcon.Checked)
- return "random";
- return "default";
- }
-
- private void handleCanFindGitCommand()
- {
- ConfigFile localConfig = Settings.Module.GetLocalConfig();
- ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
-
- if (string.IsNullOrEmpty(UserName.Text) || !UserName.Text.Equals(localConfig.GetValue("user.name")))
- localConfig.SetValue("user.name", UserName.Text);
- if (string.IsNullOrEmpty(UserEmail.Text) || !UserEmail.Text.Equals(localConfig.GetValue("user.email")))
- localConfig.SetValue("user.email", UserEmail.Text);
- localConfig.SetPathValue("core.editor", Editor.Text);
- localConfig.SetValue("merge.tool", LocalMergeTool.Text);
-
-
- if (KeepMergeBackup.CheckState == CheckState.Checked)
- localConfig.SetValue("mergetool.keepBackup", "true");
- else if (KeepMergeBackup.CheckState == CheckState.Unchecked)
- localConfig.SetValue("mergetool.keepBackup", "false");
-
- if (localAutoCrlfFalse.Checked) localConfig.SetValue("core.autocrlf", "false");
- if (localAutoCrlfInput.Checked) localConfig.SetValue("core.autocrlf", "input");
- if (localAutoCrlfTrue.Checked) localConfig.SetValue("core.autocrlf", "true");
-
- if (string.IsNullOrEmpty(GlobalUserName.Text) ||
- !GlobalUserName.Text.Equals(globalConfig.GetValue("user.name")))
- globalConfig.SetValue("user.name", GlobalUserName.Text);
- if (string.IsNullOrEmpty(GlobalUserEmail.Text) ||
- !GlobalUserEmail.Text.Equals(globalConfig.GetValue("user.email")))
- globalConfig.SetValue("user.email", GlobalUserEmail.Text);
- if (string.IsNullOrEmpty(CommitTemplatePath.Text) ||
- !CommitTemplatePath.Text.Equals(globalConfig.GetValue("commit.template")))
- globalConfig.SetValue("commit.template", CommitTemplatePath.Text);
- globalConfig.SetPathValue("core.editor", GlobalEditor.Text);
-
- SetGlobalDiffToolToConfig(globalConfig, GlobalDiffTool.Text);
-
- if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
- globalConfig.SetPathValue(string.Format("difftool.{0}.path", GlobalDiffTool.Text), DifftoolPath.Text);
- if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
- globalConfig.SetPathValue(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text), DifftoolCmd.Text);
-
- globalConfig.SetValue("merge.tool", GlobalMergeTool.Text);
-
- if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
- globalConfig.SetPathValue(string.Format("mergetool.{0}.path", GlobalMergeTool.Text), MergetoolPath.Text);
- if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
- globalConfig.SetPathValue(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text), MergeToolCmd.Text);
-
- if (GlobalKeepMergeBackup.CheckState == CheckState.Checked)
- globalConfig.SetValue("mergetool.keepBackup", "true");
- else if (GlobalKeepMergeBackup.CheckState == CheckState.Unchecked)
- globalConfig.SetValue("mergetool.keepBackup", "false");
-
- if (globalAutoCrlfFalse.Checked) globalConfig.SetValue("core.autocrlf", "false");
- if (globalAutoCrlfInput.Checked) globalConfig.SetValue("core.autocrlf", "input");
- if (globalAutoCrlfTrue.Checked) globalConfig.SetValue("core.autocrlf", "true");
-
- Action<Encoding, bool, string> setEncoding = delegate(Encoding e, bool local, string name)
- {
- string value = e == null ? "" : e.HeaderName;
- if (local)
- localConfig.SetValue(name, value);
- else
- globalConfig.SetValue(name, value);
- };
- setEncoding(Settings.GetLogOutputEncoding(false), false, "i18n.logoutputencoding");
- setEncoding(Settings.GetLogOutputEncoding(true), true, "i18n.logoutputencoding");
- setEncoding(Settings.GetCommitEncoding(false), false, "i18n.commitEncoding");
- setEncoding(Settings.GetCommitEncoding(true), true, "i18n.commitEncoding");
- setEncoding(Settings.GetFilesEncoding(false), false, "i18n.filesEncoding");
- setEncoding(Settings.GetFilesEncoding(true), true, "i18n.filesEncoding");
-
-
- globalConfig.Save();
-
- //Only save local settings when we are inside a valid working dir
- if (Settings.Module.ValidWorkingDir())
- localConfig.Save();
- }
-
- private static string GetRegistryValue(RegistryKey root, string subkey, string key)
- {
- string value = null;
- try
- {
- RegistryKey registryKey = root.OpenSubKey(subkey, false);
- if (registryKey != null)
- {
- using (registryKey)
- {
- value = registryKey.GetValue(key) as string;
- }
- }
- }
- catch (UnauthorizedAccessException)
- {
- MessageBox.Show(_cantReadRegistry.Text);
- }
- return value ?? string.Empty;
- }
-
- private static void SetRegistryValue(RegistryKey root, string subkey, string key, string value)
- {
- try
- {
- value = value.Replace("\\", "\\\\");
- string reg = "Windows Registry Editor Version 5.00" + Environment.NewLine + Environment.NewLine + "[" + root +
- "\\" + subkey + "]" + Environment.NewLine + "\"" + key + "\"=\"" + value + "\"";
-
- TextWriter tw = new StreamWriter(Path.GetTempPath() + "GitExtensions.reg", false);
- tw.Write(reg);
- tw.Close();
- Settings.Module.RunCmd("regedit", "\"" + Path.GetTempPath() + "GitExtensions.reg" + "\"");
- }
- catch (UnauthorizedAccessException)
- {
- MessageBox.Show(String.Format(_cantReadRegistryAddEntryManually.Text, root, subkey, key, value));
- }
- }
-
- public bool CheckSettings()
- {
- bool bValid = true;
- try
- {
- // once a check fails, we want bValid to stay false
- bValid = CheckGitCmdValid();
- bValid = CheckGlobalUserSettingsValid() && bValid;
- bValid = CheckMergeTool() && bValid;
- bValid = CheckDiffToolConfiguration() && bValid;
- bValid = CheckTranslationConfigSettings() && bValid;
-
- if (Settings.RunningOnWindows())
- {
- bValid = CheckGitExtensionsInstall() && bValid;
- bValid = CheckGitExtensionRegistrySettings() && bValid;
- bValid = CheckGitExe() && bValid;
- bValid = CheckSSHSettings() && bValid;
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(this, ex.Message);
- }
-
- CheckAtStartup.Checked = getCheckAtStartupChecked(bValid);
- return bValid;
- }
-
- private static bool CanFindGitCmd()
- {
- return !string.IsNullOrEmpty(Settings.Module.RunGitCmd(""));
- }
-
- private void GitExtensionsInstall_Click(object sender, EventArgs e)
- {
- SolveGitExtensionsDir();
-
- CheckSettings();
- }
-
- public static bool SolveGitExtensionsDir()
- {
- string fileName = Settings.GetGitExtensionsDirectory();
-
- if (Directory.Exists(fileName))
- {
- Settings.SetInstallDir(fileName);
- return true;
- }
-
- return false;
- }
-
- private void ShellExtensionsRegistered_Click(object sender, EventArgs e)
- {
- string path = Path.Combine(Settings.GetInstallDir(), GitExtensionsShellExName);
- if (!File.Exists(path))
- {
- path = Assembly.GetAssembly(GetType()).Location;
- path = Path.GetDirectoryName(path);
- path = Path.Combine(path, GitExtensionsShellExName);
- }
- if (File.Exists(path))
- {
- Settings.Module.RunCmd("regsvr32", string.Format("\"{0}\"", path));
- }
- else
- {
- MessageBox.Show(this, string.Format(_cantRegisterShellExtension.Text, GitExtensionsShellExName));
- }
-
- CheckSettings();
- }
-
- private void UserNameSet_Click(object sender, EventArgs e)
- {
- tabControl1.SelectTab(tpGlobalSettings);
- }
-
- private static string GetMergeTool()
- {
- return Settings.Module.GetGlobalSetting("merge.tool");
- }
-
- private static bool IsMergeTool(string toolName)
- {
- return GetMergeTool().Equals(toolName,
- StringComparison.CurrentCultureIgnoreCase);
- }
-
- public static bool SolveMergeToolForKDiff()
- {
- string mergeTool = GetMergeTool();
- if (string.IsNullOrEmpty(mergeTool))
- {
- mergeTool = "kdiff3";
- Settings.Module.SetGlobalSetting("merge.tool", mergeTool);
- }
-
- if (mergeTool.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
- return SolveMergeToolPathForKDiff();
-
- return true;
- }
-
- public static bool SolveDiffToolForKDiff()
- {
- string diffTool = GetGlobalDiffToolFromConfig();
- if (string.IsNullOrEmpty(diffTool))
- {
- diffTool = "kdiff3";
- ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
- SetGlobalDiffToolToConfig(globalConfig, diffTool);
- globalConfig.Save();
- }
-
- if (diffTool.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
- return SolveDiffToolPathForKDiff();
-
- return true;
- }
-
- public static bool SolveDiffToolPathForKDiff()
- {
- string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("difftool.kdiff3.path"));
- if (string.IsNullOrEmpty(kdiff3path))
- return false;
-
- Settings.Module.SetGlobalPathSetting("difftool.kdiff3.path", kdiff3path);
- return true;
- }
-
- public static bool SolveMergeToolPathForKDiff()
- {
- string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("mergetool.kdiff3.path"));
- if (string.IsNullOrEmpty(kdiff3path))
- return false;
-
- Settings.Module.SetGlobalPathSetting("mergetool.kdiff3.path", kdiff3path);
- return true;
- }
-
- private void ResolveDiffToolPath()
- {
- string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("difftool.kdiff3.path"));
- if (string.IsNullOrEmpty(kdiff3path))
- return;
-
- kdiff3path = MergeToolsHelper.FindFileInFolders("kdiff3.exe", MergetoolPath.Text);
- if (string.IsNullOrEmpty(kdiff3path))
- return;
-
- DifftoolPath.Text = kdiff3path;
- }
-
- private void DiffToolCmdSuggest_Click(object sender, EventArgs e)
- {
- if (!Settings.RunningOnWindows())
- return;
-
- string exeName;
- string exeFile = MergeToolsHelper.FindDiffToolExeFile(GlobalDiffTool.Text, out exeName);
- if (String.IsNullOrEmpty(exeFile))
- {
- DifftoolPath.SelectAll();
- DifftoolPath.SelectedText = "";
- DifftoolCmd.SelectAll();
- DifftoolCmd.SelectedText = "";
- if (sender != null)
- MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
- __diffToolSuggestCaption.Text);
- return;
- }
- DifftoolPath.SelectAll(); // allow Undo action
- DifftoolPath.SelectedText = exeFile;
- DifftoolCmd.SelectAll();
- DifftoolCmd.SelectedText = MergeToolsHelper.DiffToolCmdSuggest(GlobalDiffTool.Text, exeFile);
- }
-
- private void MergeToolCmdSuggest_Click(object sender, EventArgs e)
- {
- if (!Settings.RunningOnWindows())
- return;
-
- string exeName;
- string exeFile = MergeToolsHelper.FindMergeToolExeFile(GlobalMergeTool.Text, out exeName);
- if (String.IsNullOrEmpty(exeFile))
- {
- MergetoolPath.SelectAll();
- MergetoolPath.SelectedText = "";
- MergeToolCmd.SelectAll();
- MergeToolCmd.SelectedText = "";
- if (sender != null)
- MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
- __mergeToolSuggestCaption.Text);
- return;
- }
- MergetoolPath.SelectAll(); // allow Undo action
- MergetoolPath.SelectedText = exeFile;
- MergeToolCmd.SelectAll();
- MergeToolCmd.SelectedText = MergeToolsHelper.MergeToolcmdSuggest(GlobalMergeTool.Text, exeFile);
- }
-
- private void AutoConfigMergeToolCmd(bool silent)
- {
- string exeName;
- string exeFile = MergeToolsHelper.FindMergeToolExeFile(GlobalMergeTool.Text, out exeName);
- if (String.IsNullOrEmpty(exeFile))
- {
- MergetoolPath.Text = "";
- MergeToolCmd.Text = "";
- if (!silent)
- MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
- __mergeToolSuggestCaption.Text);
- return;
- }
- MergetoolPath.Text = exeFile;
- MergeToolCmd.Text = MergeToolsHelper.AutoConfigMergeToolCmd(GlobalMergeTool.Text, exeFile);
- }
-
- private void DiffToolFix_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(GetGlobalDiffToolFromConfig()))
- {
- if (MessageBox.Show(this, _noDiffToolConfigured.Text, _noDiffToolConfiguredCaption.Text,
- MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- SolveDiffToolForKDiff();
- GlobalDiffTool.Text = "kdiff3";
- }
- else
- {
- tabControl1.SelectTab(tpGlobalSettings);
- return;
- }
- }
-
- if (GetGlobalDiffToolFromConfig().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
- {
- SolveDiffToolPathForKDiff();
- }
-
- if (GetGlobalDiffToolFromConfig().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase) &&
- string.IsNullOrEmpty(Settings.Module.GetGlobalSetting("difftool.kdiff3.path")))
- {
- MessageBox.Show(this, _kdiff3NotFoundAuto.Text);
- tabControl1.SelectTab(tpGlobalSettings);
- return;
- }
-
- Rescan_Click(null, null);
- }
-
- private void MergeToolFix_Click(object sender, EventArgs e)
- {
- if (string.IsNullOrEmpty(GetMergeTool()))
- {
- if (
- MessageBox.Show(this, _noMergeToolConfigured.Text…
Large files files are truncated, but you can click here to view the full file