PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/GitUI/FormSettings.cs

https://github.com/eisnerd/gitextensions
C# | 2343 lines | 2041 code | 277 blank | 25 comment | 203 complexity | 843cdb74fc5cb02984f60e537aa04782 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using GitCommands;
  11. using GitCommands.Config;
  12. using GitUI.Editor;
  13. using GitUI.Script;
  14. using Gravatar;
  15. using Microsoft.Win32;
  16. using ResourceManager.Translation;
  17. namespace GitUI
  18. {
  19. public sealed partial class FormSettings : GitExtensionsForm
  20. {
  21. #region Translation
  22. private readonly TranslationString _homeIsSetToString = new TranslationString("HOME is set to:");
  23. private readonly TranslationString __diffToolSuggestCaption = new TranslationString("Suggest difftool cmd");
  24. private readonly TranslationString __mergeToolSuggestCaption = new TranslationString("Suggest mergetool cmd");
  25. private readonly TranslationString _loadingSettingsFailed =
  26. new TranslationString("Could not load settings.");
  27. private readonly TranslationString _cantFindGitMessage =
  28. new TranslationString("The command to run git is not configured correct." + Environment.NewLine +
  29. "You need to set the correct path to be able to use GitExtensions." + Environment.NewLine +
  30. Environment.NewLine + "Do you want to set the correct command now?");
  31. private readonly TranslationString _cantFindGitMessageCaption =
  32. new TranslationString("Incorrect path");
  33. private static readonly TranslationString _cantReadRegistry =
  34. new TranslationString("GitExtensions has insufficient permissions to check the registry.");
  35. private static readonly TranslationString _cantReadRegistryAddEntryManually =
  36. new TranslationString("GitExtensions has insufficient permissions to modify the registry." +
  37. Environment.NewLine + "Please add this key to the registry manually." +
  38. Environment.NewLine + "Path: {0}\\{1}" + Environment.NewLine +
  39. "Value: {2} = {3}");
  40. private readonly TranslationString _cantRegisterShellExtension =
  41. new TranslationString("Could not register the shell extension because '{0}' could not be found.");
  42. private readonly TranslationString _noDiffToolConfigured =
  43. new TranslationString("There is no difftool configured. Do you want to configure kdiff3 as your difftool?" +
  44. Environment.NewLine + "Select no if you want to configure a different difftool yourself.");
  45. private readonly TranslationString _noDiffToolConfiguredCaption =
  46. new TranslationString("Difftool");
  47. private readonly TranslationString _kdiff3NotFoundAuto =
  48. new TranslationString("Path to kdiff3 could not be found automatically." + Environment.NewLine +
  49. "Please make sure KDiff3 is installed or set path manually.");
  50. private readonly TranslationString _noMergeToolConfigured =
  51. new TranslationString("There is no mergetool configured. Do you want to configure kdiff3 as your mergetool?" +
  52. Environment.NewLine + "Select no if you want to configure a different mergetool yourself.");
  53. private readonly TranslationString _noMergeToolConfiguredCaption =
  54. new TranslationString("Mergetool");
  55. private readonly TranslationString _solveGitCommandFailed =
  56. new TranslationString("The command to run git could not be determined automatically." + Environment.NewLine +
  57. "Please make sure git (msysgit or cygwin) is installed or set the correct command manually.");
  58. private readonly TranslationString _solveGitCommandFailedCaption =
  59. new TranslationString("Locate git");
  60. private readonly TranslationString _gitCanBeRun =
  61. new TranslationString("Git can be run using: {0}");
  62. private readonly TranslationString _gitCanBeRunCaption =
  63. new TranslationString("Locate git");
  64. private readonly TranslationString _linuxToolsShNotFound =
  65. new TranslationString("The path to linux tools (sh) could not be found automatically." + Environment.NewLine +
  66. "Please make sure there are linux tools installed (through msysgit or cygwin) or set the correct path manually.");
  67. private readonly TranslationString _linuxToolsShNotFoundCaption =
  68. new TranslationString("Locate linux tools");
  69. private readonly TranslationString _shCanBeRun =
  70. new TranslationString("Command sh can be run using: {0}sh");
  71. private readonly TranslationString _shCanBeRunCaption =
  72. new TranslationString("Locate linux tools");
  73. private static readonly TranslationString _selectFile =
  74. new TranslationString("Select file");
  75. private readonly TranslationString _puttyFoundAuto =
  76. new TranslationString("All paths needed for PuTTY could be automatically found and are set.");
  77. private readonly TranslationString _puttyFoundAutoCaption =
  78. new TranslationString("PuTTY");
  79. private readonly TranslationString _noDictFilesFound =
  80. new TranslationString("No dictionary files found in: {0}");
  81. private readonly TranslationString _noLanguageConfigured =
  82. new TranslationString("There is no language configured for Git Extensions.");
  83. private readonly TranslationString _languageConfigured =
  84. new TranslationString("The configured language is {0}.");
  85. private readonly TranslationString _plinkputtyGenpageantNotFound =
  86. new TranslationString("PuTTY is configured as SSH client but cannot find plink.exe, puttygen.exe or pageant.exe.");
  87. private readonly TranslationString _puttyConfigured =
  88. new TranslationString("SSH client PuTTY is configured properly.");
  89. private readonly TranslationString _opensshUsed =
  90. new TranslationString("Default SSH client, OpenSSH, will be used. (commandline window will appear on pull, push and clone operations)");
  91. private readonly TranslationString _unknownSshClient =
  92. new TranslationString("Unknown SSH client configured: {0}.");
  93. private readonly TranslationString _linuxToolsSshNotFound =
  94. new TranslationString("Linux tools (sh) not found. To solve this problem you can set the correct path in settings.");
  95. private readonly TranslationString _linuxToolsSshFound =
  96. new TranslationString("Linux tools (sh) found on your computer.");
  97. private readonly TranslationString _gitNotFound =
  98. new TranslationString("Git not found. To solve this problem you can set the correct path in settings.");
  99. private readonly TranslationString _wrongGitVersion =
  100. new TranslationString("Git found but version {0} is not supported. Upgrage to version {1} or later");
  101. private readonly TranslationString _gitVersionFound =
  102. new TranslationString("Git {0} is found on your computer.");
  103. private readonly TranslationString _adviceDiffToolConfiguration =
  104. new TranslationString("You should configure a diff tool to show file diff in external program (kdiff3 for example).");
  105. private readonly TranslationString _kdiffAsDiffConfiguredButNotFound =
  106. new TranslationString("KDiff3 is configured as difftool, but the path to kdiff.exe is not configured.");
  107. private readonly TranslationString _kdiffAsDiffConfigured =
  108. new TranslationString("KDiff3 is configured as difftool.");
  109. private readonly TranslationString _toolSuggestPath =
  110. new TranslationString("Please enter the path to {0} and press suggest.");
  111. private readonly TranslationString _diffToolXConfigured =
  112. new TranslationString("There is a difftool configured: {0}");
  113. private readonly TranslationString _configureMergeTool =
  114. new TranslationString("You need to configure merge tool in order to solve mergeconflicts (kdiff3 for example).");
  115. private readonly TranslationString _kdiffAsMergeConfiguredButNotFound =
  116. new TranslationString("KDiff3 is configured as mergetool, but the path to kdiff.exe is not configured.");
  117. private readonly TranslationString _kdiffAsMergeConfigured =
  118. new TranslationString("KDiff3 is configured as mergetool.");
  119. private readonly TranslationString _mergeToolXConfiguredNeedsCmd =
  120. new TranslationString("{0} is configured as mergetool, this is a custom mergetool and needs a custom cmd to be configured.");
  121. private readonly TranslationString _customMergeToolXConfigured =
  122. new TranslationString("There is a custom mergetool configured: {0}");
  123. private readonly TranslationString _mergeToolXConfigured =
  124. new TranslationString("There is a custom mergetool configured.");
  125. private readonly TranslationString _noEmailSet =
  126. new TranslationString("You need to configure a username and an email address.");
  127. private readonly TranslationString _emailSet =
  128. new TranslationString("A username and an email address are configured.");
  129. private readonly TranslationString _shellExtNoInstalled =
  130. new TranslationString("Shell extensions are not installed. Run the installer to install the shell extensions.");
  131. private readonly TranslationString _shellExtNeedsToBeRegistered =
  132. new TranslationString("{0} needs to be registered in order to use the shell extensions.");
  133. private readonly TranslationString _shellExtRegistered =
  134. new TranslationString("Shell extensions registered properly.");
  135. private readonly TranslationString _registryKeyGitExtensionsMissing =
  136. new TranslationString("Registry entry missing [Software\\GitExtensions\\GitExtensions\\InstallDir].");
  137. private readonly TranslationString _registryKeyGitExtensionsFaulty =
  138. new TranslationString("Invalid installation directory stored in [Software\\GitExtensions\\GitExtensions\\InstallDir].");
  139. private readonly TranslationString _registryKeyGitExtensionsCorrect =
  140. new TranslationString("GitExtensions is properly registered.");
  141. #endregion
  142. private Font diffFont;
  143. private const string GitExtensionsShellExName = "GitExtensionsShellEx32.dll";
  144. private string IconName = "bug";
  145. public FormSettings()
  146. {
  147. InitializeComponent();
  148. Translate();
  149. noImageService.Items.AddRange(GravatarService.DynamicServices.Cast<object>().ToArray());
  150. FillEncodings(Global_FilesEncoding);
  151. FillEncodings(Global_AppEncoding);
  152. FillEncodings(Local_FilesEncoding);
  153. FillEncodings(Local_AppEncoding);
  154. string npp = MergeToolsHelper.FindFileInFolders("notepad++.exe", "Notepad++");
  155. if (string.IsNullOrEmpty(npp))
  156. npp = "notepad++";
  157. else
  158. npp = "\"" + npp + "\"";
  159. GlobalEditor.Items.AddRange(new Object[] { "\"" + Settings.GetGitExtensionsFullPath() + "\" fileeditor", "vi", "notepad", npp + " -multiInst -nosession" });
  160. SetCurrentDiffFont(Settings.DiffFont);
  161. }
  162. protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
  163. {
  164. base.OnClosing(e);
  165. SavePosition("settings");
  166. }
  167. public static bool AutoSolveAllSettings()
  168. {
  169. if (!Settings.RunningOnWindows())
  170. return SolveGitCommand();
  171. return SolveGitCommand() &&
  172. SolveLinuxToolsDir() &&
  173. SolveMergeToolForKDiff() &&
  174. SolveDiffToolForKDiff() &&
  175. SolveGitExtensionsDir() &&
  176. SolveEditor();
  177. }
  178. private static string GetGlobalEditor()
  179. {
  180. string editor = Environment.GetEnvironmentVariable("GIT_EDITOR");
  181. if (!string.IsNullOrEmpty(editor))
  182. return editor;
  183. editor = Settings.Module.GetGlobalPathSetting("core.editor");
  184. if (!string.IsNullOrEmpty(editor))
  185. return editor;
  186. editor = Environment.GetEnvironmentVariable("VISUAL");
  187. if (!string.IsNullOrEmpty(editor))
  188. return editor;
  189. return Environment.GetEnvironmentVariable("EDITOR");
  190. }
  191. private static bool SolveEditor()
  192. {
  193. string editor = GetGlobalEditor();
  194. if (string.IsNullOrEmpty(editor))
  195. {
  196. Settings.Module.SetGlobalPathSetting("core.editor", "\"" + Settings.GetGitExtensionsFullPath() + "\" fileeditor");
  197. }
  198. return true;
  199. }
  200. private static void SetCheckboxFromString(CheckBox checkBox, string str)
  201. {
  202. str = str.Trim().ToLower();
  203. switch (str)
  204. {
  205. case "true":
  206. {
  207. checkBox.CheckState = CheckState.Checked;
  208. return;
  209. }
  210. case "false":
  211. {
  212. checkBox.CheckState = CheckState.Unchecked;
  213. return;
  214. }
  215. default:
  216. checkBox.CheckState = CheckState.Indeterminate;
  217. return;
  218. }
  219. }
  220. private static string GetGlobalDiffToolFromConfig()
  221. {
  222. if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
  223. return GitCommandHelpers.GetGlobalConfig().GetValue("diff.guitool");
  224. return GitCommandHelpers.GetGlobalConfig().GetValue("diff.tool");
  225. }
  226. private static void SetGlobalDiffToolToConfig(ConfigFile configFile, string diffTool)
  227. {
  228. if (GitCommandHelpers.VersionInUse.GuiDiffToolExist)
  229. {
  230. configFile.SetValue("diff.guitool", diffTool);
  231. return;
  232. }
  233. configFile.SetValue("diff.tool", diffTool);
  234. }
  235. private void EncodingToCombo(Encoding encoding, ComboBox combo)
  236. {
  237. if (encoding == null)
  238. combo.Text = "";
  239. else
  240. combo.Text = encoding.EncodingName;
  241. }
  242. private Encoding ComboToEncoding(ComboBox combo)
  243. {
  244. return combo.SelectedItem as Encoding;
  245. }
  246. private void FillEncodings(ComboBox combo)
  247. {
  248. combo.Items.AddRange(Settings.availableEncodings.Values.ToArray());
  249. combo.DisplayMember = "EncodingName";
  250. }
  251. private bool loadingSettings;
  252. public void LoadSettings()
  253. {
  254. loadingSettings = true;
  255. try
  256. {
  257. GitCommandHelpers.SetEnvironmentVariable();
  258. homeIsSetToLabel.Text = string.Concat(_homeIsSetToString.Text, " ", GitCommandHelpers.GetHomeDir());
  259. scriptEvent.DataSource = Enum.GetValues(typeof(ScriptEvent));
  260. EncodingToCombo(Settings.GetFilesEncoding(false), Global_FilesEncoding);
  261. EncodingToCombo(Settings.GetAppEncoding(false, false), Global_AppEncoding);
  262. EncodingToCombo(Settings.GetFilesEncoding(true), Local_FilesEncoding);
  263. EncodingToCombo(Settings.GetAppEncoding(true, false), Local_AppEncoding);
  264. chkStartWithRecentWorkingDir.Checked = Settings.StartWithRecentWorkingDir;
  265. chkPlaySpecialStartupSound.Checked = Settings.PlaySpecialStartupSound;
  266. chkUsePatienceDiffAlgorithm.Checked = Settings.UsePatienceDiffAlgorithm;
  267. chkShowCurrentBranchInVisualStudio.Checked = Settings.ShowCurrentBranchInVisualStudio;
  268. RevisionGridQuickSearchTimeout.Value = Settings.RevisionGridQuickSearchTimeout;
  269. chkFollowRenamesInFileHistory.Checked = Settings.FollowRenamesInFileHistory;
  270. _NO_TRANSLATE_DaysToCacheImages.Value = Settings.AuthorImageCacheDays;
  271. _NO_TRANSLATE_authorImageSize.Value = Settings.AuthorImageSize;
  272. ShowAuthorGravatar.Checked = Settings.ShowAuthorGravatar;
  273. noImageService.Text = Settings.GravatarFallbackService;
  274. chkShowErrorsWhenStagingFiles.Checked = Settings.ShowErrorsWhenStagingFiles;
  275. chkStashUntrackedFiles.Checked = Settings.IncludeUntrackedFilesInAutoStash;
  276. Language.Items.Clear();
  277. Language.Items.Add("English");
  278. Language.Items.AddRange(Translator.GetAllTranslations());
  279. Language.Text = Settings.Translation;
  280. MulticolorBranches.Checked = Settings.MulticolorBranches;
  281. MulticolorBranches_CheckedChanged(null, null);
  282. DrawNonRelativesGray.Checked = Settings.RevisionGraphDrawNonRelativesGray;
  283. DrawNonRelativesTextGray.Checked = Settings.RevisionGraphDrawNonRelativesTextGray;
  284. chkShowCurrentChangesInRevisionGraph.Checked = Settings.RevisionGraphShowWorkingDirChanges;
  285. chkShowStashCountInBrowseWindow.Checked = Settings.ShowStashCount;
  286. BranchBorders.Checked = Settings.BranchBorders;
  287. StripedBanchChange.Checked = Settings.StripedBranchChange;
  288. chkShowGitStatusInToolbar.Checked = Settings.ShowGitStatusInBrowseToolbar;
  289. _NO_TRANSLATE_truncatePathMethod.Text = Settings.TruncatePathMethod;
  290. _NO_TRANSLATE_ColorGraphLabel.BackColor = Settings.GraphColor;
  291. _NO_TRANSLATE_ColorGraphLabel.Text = Settings.GraphColor.Name;
  292. _NO_TRANSLATE_ColorGraphLabel.ForeColor =
  293. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorGraphLabel.BackColor);
  294. _NO_TRANSLATE_ColorTagLabel.BackColor = Settings.TagColor;
  295. _NO_TRANSLATE_ColorTagLabel.Text = Settings.TagColor.Name;
  296. _NO_TRANSLATE_ColorTagLabel.ForeColor =
  297. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorTagLabel.BackColor);
  298. _NO_TRANSLATE_ColorBranchLabel.BackColor = Settings.BranchColor;
  299. _NO_TRANSLATE_ColorBranchLabel.Text = Settings.BranchColor.Name;
  300. _NO_TRANSLATE_ColorBranchLabel.ForeColor =
  301. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorBranchLabel.BackColor);
  302. _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor = Settings.RemoteBranchColor;
  303. _NO_TRANSLATE_ColorRemoteBranchLabel.Text = Settings.RemoteBranchColor.Name;
  304. _NO_TRANSLATE_ColorRemoteBranchLabel.ForeColor =
  305. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemoteBranchLabel.BackColor);
  306. _NO_TRANSLATE_ColorOtherLabel.BackColor = Settings.OtherTagColor;
  307. _NO_TRANSLATE_ColorOtherLabel.Text = Settings.OtherTagColor.Name;
  308. _NO_TRANSLATE_ColorOtherLabel.ForeColor =
  309. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorOtherLabel.BackColor);
  310. _NO_TRANSLATE_ColorAddedLineLabel.BackColor = Settings.DiffAddedColor;
  311. _NO_TRANSLATE_ColorAddedLineLabel.Text = Settings.DiffAddedColor.Name;
  312. _NO_TRANSLATE_ColorAddedLineLabel.ForeColor =
  313. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineLabel.BackColor);
  314. _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor = Settings.DiffAddedExtraColor;
  315. _NO_TRANSLATE_ColorAddedLineDiffLabel.Text = Settings.DiffAddedExtraColor.Name;
  316. _NO_TRANSLATE_ColorAddedLineDiffLabel.ForeColor =
  317. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor);
  318. _NO_TRANSLATE_ColorRemovedLine.BackColor = Settings.DiffRemovedColor;
  319. _NO_TRANSLATE_ColorRemovedLine.Text = Settings.DiffRemovedColor.Name;
  320. _NO_TRANSLATE_ColorRemovedLine.ForeColor =
  321. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLine.BackColor);
  322. _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor = Settings.DiffRemovedExtraColor;
  323. _NO_TRANSLATE_ColorRemovedLineDiffLabel.Text = Settings.DiffRemovedExtraColor.Name;
  324. _NO_TRANSLATE_ColorRemovedLineDiffLabel.ForeColor =
  325. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor);
  326. _NO_TRANSLATE_ColorSectionLabel.BackColor = Settings.DiffSectionColor;
  327. _NO_TRANSLATE_ColorSectionLabel.Text = Settings.DiffSectionColor.Name;
  328. _NO_TRANSLATE_ColorSectionLabel.ForeColor =
  329. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorSectionLabel.BackColor);
  330. SmtpServer.Text = Settings.Smtp;
  331. _NO_TRANSLATE_MaxCommits.Value = Settings.MaxRevisionGraphCommits;
  332. GitPath.Text = Settings.GitCommand;
  333. GitBinPath.Text = Settings.GitBinDir;
  334. ConfigFile localConfig = Settings.Module.GetLocalConfig();
  335. ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
  336. UserName.Text = localConfig.GetValue("user.name");
  337. UserEmail.Text = localConfig.GetValue("user.email");
  338. Editor.Text = localConfig.GetPathValue("core.editor");
  339. LocalMergeTool.Text = localConfig.GetValue("merge.tool");
  340. Dictionary.Text = Settings.Dictionary;
  341. GlobalUserName.Text = globalConfig.GetValue("user.name");
  342. GlobalUserEmail.Text = globalConfig.GetValue("user.email");
  343. GlobalEditor.Text = globalConfig.GetPathValue("core.editor");
  344. GlobalMergeTool.Text = globalConfig.GetValue("merge.tool");
  345. CommitTemplatePath.Text = globalConfig.GetValue("commit.template");
  346. SetCheckboxFromString(KeepMergeBackup, localConfig.GetValue("mergetool.keepBackup"));
  347. string autocrlf = localConfig.GetValue("core.autocrlf").ToLower();
  348. localAutoCrlfFalse.Checked = autocrlf == "false";
  349. localAutoCrlfInput.Checked = autocrlf == "input";
  350. localAutoCrlfTrue.Checked = autocrlf == "true";
  351. if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
  352. MergetoolPath.Text = globalConfig.GetPathValue(string.Format("mergetool.{0}.path", GlobalMergeTool.Text));
  353. if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
  354. MergeToolCmd.Text = globalConfig.GetPathValue(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text));
  355. string iconColor = Settings.IconColor.ToLower();
  356. DefaultIcon.Checked = iconColor == "default";
  357. BlueIcon.Checked = iconColor == "blue";
  358. GreenIcon.Checked = iconColor == "green";
  359. PurpleIcon.Checked = iconColor == "purple";
  360. RedIcon.Checked = iconColor == "red";
  361. YellowIcon.Checked = iconColor == "yellow";
  362. RandomIcon.Checked = iconColor == "random";
  363. IconStyle.Text = Settings.IconStyle;
  364. ShowIconPreview();
  365. GlobalDiffTool.Text = GetGlobalDiffToolFromConfig();
  366. if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
  367. DifftoolPath.Text = globalConfig.GetPathValue(string.Format("difftool.{0}.path", GlobalDiffTool.Text));
  368. if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
  369. DifftoolCmd.Text = globalConfig.GetPathValue(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text));
  370. SetCheckboxFromString(GlobalKeepMergeBackup, globalConfig.GetValue("mergetool.keepBackup"));
  371. string globalAutocrlf = string.Empty;
  372. if (globalConfig.HasValue("core.autocrlf"))
  373. {
  374. globalAutocrlf = globalConfig.GetValue("core.autocrlf").ToLower();
  375. }
  376. else if (!string.IsNullOrEmpty(Settings.GitBinDir))
  377. {
  378. try
  379. {
  380. //the following lines only work for msysgit (i think). MSysgit has a config file
  381. //in the etc directory which is checked after the local and global config. In
  382. //practice this is only used to core.autocrlf. If there are more cases, we might
  383. //need to consider a better solution.
  384. var configFile =
  385. new ConfigFile(Path.GetDirectoryName(Settings.GitBinDir).Replace("bin", "etc\\gitconfig"), false);
  386. globalAutocrlf = configFile.GetValue("core.autocrlf").ToLower();
  387. }
  388. catch
  389. {
  390. }
  391. }
  392. globalAutoCrlfFalse.Checked = globalAutocrlf == "false";
  393. globalAutoCrlfInput.Checked = globalAutocrlf == "input";
  394. globalAutoCrlfTrue.Checked = globalAutocrlf == "true";
  395. PlinkPath.Text = Settings.Plink;
  396. PuttygenPath.Text = Settings.Puttygen;
  397. PageantPath.Text = Settings.Pageant;
  398. AutostartPageant.Checked = Settings.AutoStartPageant;
  399. chkCloseProcessDialog.Checked = Settings.CloseProcessDialog;
  400. chkShowGitCommandLine.Checked = Settings.ShowGitCommandLine;
  401. chkUseFastChecks.Checked = Settings.UseFastChecks;
  402. chkShowRelativeDate.Checked = Settings.RelativeDate;
  403. chkCascadedContextMenu.Checked = Settings.ShellCascadeContextMenu;
  404. for (int i = 0; i < Settings.ShellVisibleMenuItems.Length; i++)
  405. {
  406. chlMenuEntries.SetItemChecked(i, Settings.ShellVisibleMenuItems[i] == '1');
  407. }
  408. if (string.IsNullOrEmpty(GitCommandHelpers.GetSsh()))
  409. OpenSSH.Checked = true;
  410. else if (GitCommandHelpers.Plink())
  411. Putty.Checked = true;
  412. else
  413. {
  414. OtherSsh.Text = GitCommandHelpers.GetSsh();
  415. Other.Checked = true;
  416. }
  417. EnableSshOptions();
  418. LoadScripts();
  419. }
  420. catch (Exception ex)
  421. {
  422. MessageBox.Show(this, _loadingSettingsFailed.Text + Environment.NewLine + ex);
  423. // Bail out before the user saves the incompletely loaded settings
  424. // and has their day ruined.
  425. DialogResult = DialogResult.Abort;
  426. }
  427. loadingSettings = false;
  428. }
  429. private void Ok_Click(object sender, EventArgs e)
  430. {
  431. Close();
  432. }
  433. private bool Save()
  434. {
  435. SaveScripts();
  436. if (Settings.RunningOnWindows())
  437. FormFixHome.CheckHomePath();
  438. GitCommandHelpers.SetEnvironmentVariable(true);
  439. Settings.StartWithRecentWorkingDir = chkStartWithRecentWorkingDir.Checked;
  440. Settings.PlaySpecialStartupSound = chkPlaySpecialStartupSound.Checked;
  441. Settings.UsePatienceDiffAlgorithm = chkUsePatienceDiffAlgorithm.Checked;
  442. Settings.TruncatePathMethod = _NO_TRANSLATE_truncatePathMethod.Text;
  443. Settings.ShowCurrentBranchInVisualStudio = chkShowCurrentBranchInVisualStudio.Checked;
  444. Settings.ShowErrorsWhenStagingFiles = chkShowErrorsWhenStagingFiles.Checked;
  445. Settings.IncludeUntrackedFilesInAutoStash = chkStashUntrackedFiles.Checked;
  446. Settings.FollowRenamesInFileHistory = chkFollowRenamesInFileHistory.Checked;
  447. if ((int)_NO_TRANSLATE_authorImageSize.Value != Settings.AuthorImageSize)
  448. {
  449. Settings.AuthorImageSize = (int)_NO_TRANSLATE_authorImageSize.Value;
  450. GravatarService.ClearImageCache();
  451. }
  452. Settings.Translation = Language.Text;
  453. Strings.Reinit();
  454. Settings.ShowGitStatusInBrowseToolbar = chkShowGitStatusInToolbar.Checked;
  455. Settings.AuthorImageCacheDays = (int)_NO_TRANSLATE_DaysToCacheImages.Value;
  456. Settings.Smtp = SmtpServer.Text;
  457. Settings.GitCommand = GitPath.Text;
  458. Settings.GitBinDir = GitBinPath.Text;
  459. Settings.ShowAuthorGravatar = ShowAuthorGravatar.Checked;
  460. Settings.GravatarFallbackService = noImageService.Text;
  461. Settings.CloseProcessDialog = chkCloseProcessDialog.Checked;
  462. Settings.ShowGitCommandLine = chkShowGitCommandLine.Checked;
  463. Settings.UseFastChecks = chkUseFastChecks.Checked;
  464. Settings.RelativeDate = chkShowRelativeDate.Checked;
  465. Settings.Dictionary = Dictionary.Text;
  466. Settings.MaxRevisionGraphCommits = (int)_NO_TRANSLATE_MaxCommits.Value;
  467. Settings.Plink = PlinkPath.Text;
  468. Settings.Puttygen = PuttygenPath.Text;
  469. Settings.Pageant = PageantPath.Text;
  470. Settings.AutoStartPageant = AutostartPageant.Checked;
  471. Settings.SetFilesEncoding(false, ComboToEncoding(Global_FilesEncoding));
  472. Settings.SetAppEncoding(false, ComboToEncoding(Global_AppEncoding));
  473. Settings.SetFilesEncoding(true, ComboToEncoding(Local_FilesEncoding));
  474. Settings.SetAppEncoding(true, ComboToEncoding(Local_AppEncoding));
  475. Settings.RevisionGridQuickSearchTimeout = (int)RevisionGridQuickSearchTimeout.Value;
  476. Settings.MulticolorBranches = MulticolorBranches.Checked;
  477. Settings.RevisionGraphDrawNonRelativesGray = DrawNonRelativesGray.Checked;
  478. Settings.RevisionGraphDrawNonRelativesTextGray = DrawNonRelativesTextGray.Checked;
  479. Settings.RevisionGraphShowWorkingDirChanges = chkShowCurrentChangesInRevisionGraph.Checked;
  480. Settings.ShowStashCount = chkShowStashCountInBrowseWindow.Checked;
  481. Settings.BranchBorders = BranchBorders.Checked;
  482. Settings.StripedBranchChange = StripedBanchChange.Checked;
  483. Settings.GraphColor = _NO_TRANSLATE_ColorGraphLabel.BackColor;
  484. Settings.TagColor = _NO_TRANSLATE_ColorTagLabel.BackColor;
  485. Settings.BranchColor = _NO_TRANSLATE_ColorBranchLabel.BackColor;
  486. Settings.RemoteBranchColor = _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor;
  487. Settings.OtherTagColor = _NO_TRANSLATE_ColorOtherLabel.BackColor;
  488. Settings.DiffAddedColor = _NO_TRANSLATE_ColorAddedLineLabel.BackColor;
  489. Settings.DiffRemovedColor = _NO_TRANSLATE_ColorRemovedLine.BackColor;
  490. Settings.DiffAddedExtraColor = _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor;
  491. Settings.DiffRemovedExtraColor = _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor;
  492. Settings.DiffFont = diffFont;
  493. Settings.DiffSectionColor = _NO_TRANSLATE_ColorSectionLabel.BackColor;
  494. Settings.IconColor = GetSelectedApplicationIconColor();
  495. Settings.IconStyle = IconStyle.Text;
  496. // Shell Extension settings
  497. Settings.ShellCascadeContextMenu = chkCascadedContextMenu.Checked;
  498. String l_ShellVisibleMenuItems = "";
  499. for (int i = 0; i < chlMenuEntries.Items.Count; i++)
  500. {
  501. if (chlMenuEntries.GetItemChecked(i))
  502. {
  503. l_ShellVisibleMenuItems += "1";
  504. }
  505. else
  506. {
  507. l_ShellVisibleMenuItems += "0";
  508. }
  509. }
  510. Settings.ShellVisibleMenuItems = l_ShellVisibleMenuItems;
  511. EnableSettings();
  512. if (!CanFindGitCmd())
  513. {
  514. if (MessageBox.Show(this, _cantFindGitMessage.Text, _cantFindGitMessageCaption.Text,
  515. MessageBoxButtons.YesNo) == DialogResult.Yes)
  516. return false;
  517. }
  518. else
  519. {
  520. handleCanFindGitCommand();
  521. }
  522. if (OpenSSH.Checked)
  523. GitCommandHelpers.UnsetSsh();
  524. if (Putty.Checked)
  525. GitCommandHelpers.SetSsh(PlinkPath.Text);
  526. if (Other.Checked)
  527. GitCommandHelpers.SetSsh(OtherSsh.Text);
  528. Settings.SaveSettings();
  529. return true;
  530. }
  531. private string GetSelectedApplicationIconColor()
  532. {
  533. if (BlueIcon.Checked)
  534. return "blue";
  535. if (LightblueIcon.Checked)
  536. return "lightblue";
  537. if (GreenIcon.Checked)
  538. return "green";
  539. if (PurpleIcon.Checked)
  540. return "purple";
  541. if (RedIcon.Checked)
  542. return "red";
  543. if (YellowIcon.Checked)
  544. return "yellow";
  545. if (RandomIcon.Checked)
  546. return "random";
  547. return "default";
  548. }
  549. private void handleCanFindGitCommand()
  550. {
  551. ConfigFile localConfig = Settings.Module.GetLocalConfig();
  552. ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
  553. if (string.IsNullOrEmpty(UserName.Text) || !UserName.Text.Equals(localConfig.GetValue("user.name")))
  554. localConfig.SetValue("user.name", UserName.Text);
  555. if (string.IsNullOrEmpty(UserEmail.Text) || !UserEmail.Text.Equals(localConfig.GetValue("user.email")))
  556. localConfig.SetValue("user.email", UserEmail.Text);
  557. localConfig.SetPathValue("core.editor", Editor.Text);
  558. localConfig.SetValue("merge.tool", LocalMergeTool.Text);
  559. if (KeepMergeBackup.CheckState == CheckState.Checked)
  560. localConfig.SetValue("mergetool.keepBackup", "true");
  561. else if (KeepMergeBackup.CheckState == CheckState.Unchecked)
  562. localConfig.SetValue("mergetool.keepBackup", "false");
  563. if (localAutoCrlfFalse.Checked) localConfig.SetValue("core.autocrlf", "false");
  564. if (localAutoCrlfInput.Checked) localConfig.SetValue("core.autocrlf", "input");
  565. if (localAutoCrlfTrue.Checked) localConfig.SetValue("core.autocrlf", "true");
  566. if (string.IsNullOrEmpty(GlobalUserName.Text) ||
  567. !GlobalUserName.Text.Equals(globalConfig.GetValue("user.name")))
  568. globalConfig.SetValue("user.name", GlobalUserName.Text);
  569. if (string.IsNullOrEmpty(GlobalUserEmail.Text) ||
  570. !GlobalUserEmail.Text.Equals(globalConfig.GetValue("user.email")))
  571. globalConfig.SetValue("user.email", GlobalUserEmail.Text);
  572. if (string.IsNullOrEmpty(CommitTemplatePath.Text) ||
  573. !CommitTemplatePath.Text.Equals(globalConfig.GetValue("commit.template")))
  574. globalConfig.SetValue("commit.template", CommitTemplatePath.Text);
  575. globalConfig.SetPathValue("core.editor", GlobalEditor.Text);
  576. SetGlobalDiffToolToConfig(globalConfig, GlobalDiffTool.Text);
  577. if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
  578. globalConfig.SetPathValue(string.Format("difftool.{0}.path", GlobalDiffTool.Text), DifftoolPath.Text);
  579. if (!string.IsNullOrEmpty(GlobalDiffTool.Text))
  580. globalConfig.SetPathValue(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text), DifftoolCmd.Text);
  581. globalConfig.SetValue("merge.tool", GlobalMergeTool.Text);
  582. if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
  583. globalConfig.SetPathValue(string.Format("mergetool.{0}.path", GlobalMergeTool.Text), MergetoolPath.Text);
  584. if (!string.IsNullOrEmpty(GlobalMergeTool.Text))
  585. globalConfig.SetPathValue(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text), MergeToolCmd.Text);
  586. if (GlobalKeepMergeBackup.CheckState == CheckState.Checked)
  587. globalConfig.SetValue("mergetool.keepBackup", "true");
  588. else if (GlobalKeepMergeBackup.CheckState == CheckState.Unchecked)
  589. globalConfig.SetValue("mergetool.keepBackup", "false");
  590. if (globalAutoCrlfFalse.Checked) globalConfig.SetValue("core.autocrlf", "false");
  591. if (globalAutoCrlfInput.Checked) globalConfig.SetValue("core.autocrlf", "input");
  592. if (globalAutoCrlfTrue.Checked) globalConfig.SetValue("core.autocrlf", "true");
  593. Action<Encoding, bool, string> setEncoding = delegate(Encoding e, bool local, string name)
  594. {
  595. string value = e == null ? "" : e.HeaderName;
  596. if (local)
  597. localConfig.SetValue(name, value);
  598. else
  599. globalConfig.SetValue(name, value);
  600. };
  601. setEncoding(Settings.GetLogOutputEncoding(false), false, "i18n.logoutputencoding");
  602. setEncoding(Settings.GetLogOutputEncoding(true), true, "i18n.logoutputencoding");
  603. setEncoding(Settings.GetCommitEncoding(false), false, "i18n.commitEncoding");
  604. setEncoding(Settings.GetCommitEncoding(true), true, "i18n.commitEncoding");
  605. setEncoding(Settings.GetFilesEncoding(false), false, "i18n.filesEncoding");
  606. setEncoding(Settings.GetFilesEncoding(true), true, "i18n.filesEncoding");
  607. globalConfig.Save();
  608. //Only save local settings when we are inside a valid working dir
  609. if (Settings.Module.ValidWorkingDir())
  610. localConfig.Save();
  611. }
  612. private static string GetRegistryValue(RegistryKey root, string subkey, string key)
  613. {
  614. string value = null;
  615. try
  616. {
  617. RegistryKey registryKey = root.OpenSubKey(subkey, false);
  618. if (registryKey != null)
  619. {
  620. using (registryKey)
  621. {
  622. value = registryKey.GetValue(key) as string;
  623. }
  624. }
  625. }
  626. catch (UnauthorizedAccessException)
  627. {
  628. MessageBox.Show(_cantReadRegistry.Text);
  629. }
  630. return value ?? string.Empty;
  631. }
  632. private static void SetRegistryValue(RegistryKey root, string subkey, string key, string value)
  633. {
  634. try
  635. {
  636. value = value.Replace("\\", "\\\\");
  637. string reg = "Windows Registry Editor Version 5.00" + Environment.NewLine + Environment.NewLine + "[" + root +
  638. "\\" + subkey + "]" + Environment.NewLine + "\"" + key + "\"=\"" + value + "\"";
  639. TextWriter tw = new StreamWriter(Path.GetTempPath() + "GitExtensions.reg", false);
  640. tw.Write(reg);
  641. tw.Close();
  642. Settings.Module.RunCmd("regedit", "\"" + Path.GetTempPath() + "GitExtensions.reg" + "\"");
  643. }
  644. catch (UnauthorizedAccessException)
  645. {
  646. MessageBox.Show(String.Format(_cantReadRegistryAddEntryManually.Text, root, subkey, key, value));
  647. }
  648. }
  649. public bool CheckSettings()
  650. {
  651. bool bValid = true;
  652. try
  653. {
  654. // once a check fails, we want bValid to stay false
  655. bValid = CheckGitCmdValid();
  656. bValid = CheckGlobalUserSettingsValid() && bValid;
  657. bValid = CheckMergeTool() && bValid;
  658. bValid = CheckDiffToolConfiguration() && bValid;
  659. bValid = CheckTranslationConfigSettings() && bValid;
  660. if (Settings.RunningOnWindows())
  661. {
  662. bValid = CheckGitExtensionsInstall() && bValid;
  663. bValid = CheckGitExtensionRegistrySettings() && bValid;
  664. bValid = CheckGitExe() && bValid;
  665. bValid = CheckSSHSettings() && bValid;
  666. }
  667. }
  668. catch (Exception ex)
  669. {
  670. MessageBox.Show(this, ex.Message);
  671. }
  672. CheckAtStartup.Checked = getCheckAtStartupChecked(bValid);
  673. return bValid;
  674. }
  675. private static bool CanFindGitCmd()
  676. {
  677. return !string.IsNullOrEmpty(Settings.Module.RunGitCmd(""));
  678. }
  679. private void GitExtensionsInstall_Click(object sender, EventArgs e)
  680. {
  681. SolveGitExtensionsDir();
  682. CheckSettings();
  683. }
  684. public static bool SolveGitExtensionsDir()
  685. {
  686. string fileName = Settings.GetGitExtensionsDirectory();
  687. if (Directory.Exists(fileName))
  688. {
  689. Settings.SetInstallDir(fileName);
  690. return true;
  691. }
  692. return false;
  693. }
  694. private void ShellExtensionsRegistered_Click(object sender, EventArgs e)
  695. {
  696. string path = Path.Combine(Settings.GetInstallDir(), GitExtensionsShellExName);
  697. if (!File.Exists(path))
  698. {
  699. path = Assembly.GetAssembly(GetType()).Location;
  700. path = Path.GetDirectoryName(path);
  701. path = Path.Combine(path, GitExtensionsShellExName);
  702. }
  703. if (File.Exists(path))
  704. {
  705. Settings.Module.RunCmd("regsvr32", string.Format("\"{0}\"", path));
  706. }
  707. else
  708. {
  709. MessageBox.Show(this, string.Format(_cantRegisterShellExtension.Text, GitExtensionsShellExName));
  710. }
  711. CheckSettings();
  712. }
  713. private void UserNameSet_Click(object sender, EventArgs e)
  714. {
  715. tabControl1.SelectTab(tpGlobalSettings);
  716. }
  717. private static string GetMergeTool()
  718. {
  719. return Settings.Module.GetGlobalSetting("merge.tool");
  720. }
  721. private static bool IsMergeTool(string toolName)
  722. {
  723. return GetMergeTool().Equals(toolName,
  724. StringComparison.CurrentCultureIgnoreCase);
  725. }
  726. public static bool SolveMergeToolForKDiff()
  727. {
  728. string mergeTool = GetMergeTool();
  729. if (string.IsNullOrEmpty(mergeTool))
  730. {
  731. mergeTool = "kdiff3";
  732. Settings.Module.SetGlobalSetting("merge.tool", mergeTool);
  733. }
  734. if (mergeTool.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  735. return SolveMergeToolPathForKDiff();
  736. return true;
  737. }
  738. public static bool SolveDiffToolForKDiff()
  739. {
  740. string diffTool = GetGlobalDiffToolFromConfig();
  741. if (string.IsNullOrEmpty(diffTool))
  742. {
  743. diffTool = "kdiff3";
  744. ConfigFile globalConfig = GitCommandHelpers.GetGlobalConfig();
  745. SetGlobalDiffToolToConfig(globalConfig, diffTool);
  746. globalConfig.Save();
  747. }
  748. if (diffTool.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  749. return SolveDiffToolPathForKDiff();
  750. return true;
  751. }
  752. public static bool SolveDiffToolPathForKDiff()
  753. {
  754. string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("difftool.kdiff3.path"));
  755. if (string.IsNullOrEmpty(kdiff3path))
  756. return false;
  757. Settings.Module.SetGlobalPathSetting("difftool.kdiff3.path", kdiff3path);
  758. return true;
  759. }
  760. public static bool SolveMergeToolPathForKDiff()
  761. {
  762. string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("mergetool.kdiff3.path"));
  763. if (string.IsNullOrEmpty(kdiff3path))
  764. return false;
  765. Settings.Module.SetGlobalPathSetting("mergetool.kdiff3.path", kdiff3path);
  766. return true;
  767. }
  768. private void ResolveDiffToolPath()
  769. {
  770. string kdiff3path = MergeToolsHelper.FindPathForKDiff(Settings.Module.GetGlobalSetting("difftool.kdiff3.path"));
  771. if (string.IsNullOrEmpty(kdiff3path))
  772. return;
  773. kdiff3path = MergeToolsHelper.FindFileInFolders("kdiff3.exe", MergetoolPath.Text);
  774. if (string.IsNullOrEmpty(kdiff3path))
  775. return;
  776. DifftoolPath.Text = kdiff3path;
  777. }
  778. private void DiffToolCmdSuggest_Click(object sender, EventArgs e)
  779. {
  780. if (!Settings.RunningOnWindows())
  781. return;
  782. string exeName;
  783. string exeFile = MergeToolsHelper.FindDiffToolExeFile(GlobalDiffTool.Text, out exeName);
  784. if (String.IsNullOrEmpty(exeFile))
  785. {
  786. DifftoolPath.SelectAll();
  787. DifftoolPath.SelectedText = "";
  788. DifftoolCmd.SelectAll();
  789. DifftoolCmd.SelectedText = "";
  790. if (sender != null)
  791. MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
  792. __diffToolSuggestCaption.Text);
  793. return;
  794. }
  795. DifftoolPath.SelectAll(); // allow Undo action
  796. DifftoolPath.SelectedText = exeFile;
  797. DifftoolCmd.SelectAll();
  798. DifftoolCmd.SelectedText = MergeToolsHelper.DiffToolCmdSuggest(GlobalDiffTool.Text, exeFile);
  799. }
  800. private void MergeToolCmdSuggest_Click(object sender, EventArgs e)
  801. {
  802. if (!Settings.RunningOnWindows())
  803. return;
  804. string exeName;
  805. string exeFile = MergeToolsHelper.FindMergeToolExeFile(GlobalMergeTool.Text, out exeName);
  806. if (String.IsNullOrEmpty(exeFile))
  807. {
  808. MergetoolPath.SelectAll();
  809. MergetoolPath.SelectedText = "";
  810. MergeToolCmd.SelectAll();
  811. MergeToolCmd.SelectedText = "";
  812. if (sender != null)
  813. MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
  814. __mergeToolSuggestCaption.Text);
  815. return;
  816. }
  817. MergetoolPath.SelectAll(); // allow Undo action
  818. MergetoolPath.SelectedText = exeFile;
  819. MergeToolCmd.SelectAll();
  820. MergeToolCmd.SelectedText = MergeToolsHelper.MergeToolcmdSuggest(GlobalMergeTool.Text, exeFile);
  821. }
  822. private void AutoConfigMergeToolCmd(bool silent)
  823. {
  824. string exeName;
  825. string exeFile = MergeToolsHelper.FindMergeToolExeFile(GlobalMergeTool.Text, out exeName);
  826. if (String.IsNullOrEmpty(exeFile))
  827. {
  828. MergetoolPath.Text = "";
  829. MergeToolCmd.Text = "";
  830. if (!silent)
  831. MessageBox.Show(this, String.Format(_toolSuggestPath.Text, exeName),
  832. __mergeToolSuggestCaption.Text);
  833. return;
  834. }
  835. MergetoolPath.Text = exeFile;
  836. MergeToolCmd.Text = MergeToolsHelper.AutoConfigMergeToolCmd(GlobalMergeTool.Text, exeFile);
  837. }
  838. private void DiffToolFix_Click(object sender, EventArgs e)
  839. {
  840. if (string.IsNullOrEmpty(GetGlobalDiffToolFromConfig()))
  841. {
  842. if (MessageBox.Show(this, _noDiffToolConfigured.Text, _noDiffToolConfiguredCaption.Text,
  843. MessageBoxButtons.YesNo) == DialogResult.Yes)
  844. {
  845. SolveDiffToolForKDiff();
  846. GlobalDiffTool.Text = "kdiff3";
  847. }
  848. else
  849. {
  850. tabControl1.SelectTab(tpGlobalSettings);
  851. return;
  852. }
  853. }
  854. if (GetGlobalDiffToolFromConfig().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  855. {
  856. SolveDiffToolPathForKDiff();
  857. }
  858. if (GetGlobalDiffToolFromConfig().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase) &&
  859. string.IsNullOrEmpty(Settings.Module.GetGlobalSetting("difftool.kdiff3.path")))
  860. {
  861. MessageBox.Show(this, _kdiff3NotFoundAuto.Text);
  862. tabControl1.SelectTab(tpGlobalSettings);
  863. return;
  864. }
  865. Rescan_Click(null, null);
  866. }
  867. private void MergeToolFix_Click(object sender, EventArgs e)
  868. {
  869. if (string.IsNullOrEmpty(GetMergeTool()))
  870. {
  871. if (
  872. MessageBox.Show(this, _noMergeToolConfigured.Text,
  873. _noMergeToolConfiguredCaption.Text, MessageBoxButtons.YesNo) == DialogResult.Yes)
  874. {
  875. SolveMergeToolForKDiff();
  876. GlobalMergeTool.Text = "kdiff3";
  877. }
  878. else
  879. {
  880. tabControl1.SelectTab(tpGlobalSettings);
  881. return;
  882. }
  883. }
  884. if (IsMergeTool("kdiff3"))
  885. {
  886. SolveMergeToolPathForKDiff();
  887. }
  888. else if (IsMergeTool("p4merge") || IsMergeTool("TortoiseMerge"))
  889. {
  890. AutoConfigMergeToolCmd(true);
  891. Settings.Module.SetGlobalPathSetting(
  892. string.Format("mergetool.{0}.cmd", GetMergeTool()), MergeToolCmd.Text);
  893. }
  894. if (IsMergeTool("kdiff3") &&
  895. string.IsNullOrEmpty(Settings.Module.GetGlobalSetting("mergetool.kdiff3.path")))
  896. {
  897. MessageBox.Show(this, _kdiff3NotFoundAuto.Text);
  898. tabControl1.SelectTab(tpGlobalSettings);
  899. return;
  900. }
  901. Rescan_Click(null, null);
  902. }
  903. private void BrowseMergeTool_Click(object sender, EventArgs e)
  904. {
  905. string mergeTool = GlobalMergeTool.Text.ToLowerInvariant();
  906. if (mergeTool == "kdiff3")
  907. MergetoolPath.Text = SelectFile(".", "kdiff3.exe (kdiff3.exe)|kdiff3.exe", MergetoolPath.Text);
  908. else if (mergeTool == "p4merge")
  909. MergetoolPath.Text = SelectFile(".", "p4merge.exe (p4merge.exe)|p4merge.exe", MergetoolPath.Text);
  910. else if (mergeTool == "tortoisemerge")
  911. MergetoolPath.Text = SelectFile(".", "TortoiseMerge.exe (TortoiseMerge.exe)|TortoiseMerge.exe",
  912. MergetoolPath.Text);
  913. else
  914. MergetoolPath.Text = SelectFile(".", "*.exe (*.exe)|*.exe", MergetoolPath.Text);
  915. }
  916. private void GlobalDiffTool_TextChanged(object sender, EventArgs e)
  917. {
  918. if (loadingSettings)
  919. return;
  920. DifftoolPath.Text = Settings.Module.GetGlobalSetting(string.Format("difftool.{0}.path", GlobalDiffTool.Text.Trim()));
  921. DifftoolCmd.Text = Settings.Module.GetGlobalSetting(string.Format("difftool.{0}.cmd", GlobalDiffTool.Text.Trim()));
  922. if (GlobalDiffTool.Text.Trim().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  923. ResolveDiffToolPath();
  924. DiffToolCmdSuggest_Click(null, null);
  925. }
  926. private void BrowseDiffTool_Click(object sender, EventArgs e)
  927. {
  928. if (GlobalDiffTool.Text.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  929. {
  930. DifftoolPath.Text = SelectFile(".", "kdiff3.exe (kdiff3.exe)|kdiff3.exe", DifftoolPath.Text);
  931. }
  932. else if (GlobalDiffTool.Text.Equals("p4merge", StringComparison.CurrentCultureIgnoreCase))
  933. DifftoolPath.Text = SelectFile(".", "p4merge.exe (p4merge.exe)|p4merge.exe", DifftoolPath.Text);
  934. else if (GlobalDiffTool.Text.Equals("tmerge", StringComparison.CurrentCultureIgnoreCase))
  935. DifftoolPath.Text = SelectFile(".", "TortoiseMerge.exe (TortoiseMerge.exe)|TortoiseMerge.exe",
  936. DifftoolPath.Text);
  937. else
  938. DifftoolPath.Text = SelectFile(".", "*.exe (*.exe)|*.exe", DifftoolPath.Text);
  939. }
  940. private void GlobalMergeTool_TextChanged(object sender, EventArgs e)
  941. {
  942. if (loadingSettings)
  943. return;
  944. MergetoolPath.Text = Settings.Module.GetGlobalSetting(string.Format("mergetool.{0}.path", GlobalMergeTool.Text.Trim()));
  945. MergeToolCmd.Text = Settings.Module.GetGlobalSetting(string.Format("mergetool.{0}.cmd", GlobalMergeTool.Text.Trim()));
  946. if (GlobalMergeTool.Text.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase) &&
  947. string.IsNullOrEmpty(MergeToolCmd.Text))
  948. MergeToolCmd.Enabled = false;
  949. else
  950. MergeToolCmd.Enabled = true;
  951. MergeToolCmdSuggest_Click(null, null);
  952. }
  953. private void GitFound_Click(object sender, EventArgs e)
  954. {
  955. if (!SolveGitCommand())
  956. {
  957. MessageBox.Show(this, _solveGitCommandFailed.Text, _solveGitCommandFailedCaption.Text);
  958. tabControl1.SelectTab(tpGit);
  959. return;
  960. }
  961. MessageBox.Show(this, String.Format(_gitCanBeRun.Text, Settings.GitCommand), _gitCanBeRunCaption.Text);
  962. GitPath.Text = Settings.GitCommand;
  963. Rescan_Click(null, null);
  964. }
  965. private void FormSettings_Load(object sender, EventArgs e)
  966. {
  967. if (DesignMode)
  968. return;
  969. EnableSettings();
  970. WindowState = FormWindowState.Normal;
  971. }
  972. private void EnableSettings()
  973. {
  974. bool canFindGitCmd = CanFindGitCmd();
  975. GlobalUserName.Enabled = canFindGitCmd;
  976. GlobalUserEmail.Enabled = canFindGitCmd;
  977. GlobalEditor.Enabled = canFindGitCmd;
  978. CommitTemplatePath.Enabled = canFindGitCmd;
  979. GlobalMergeTool.Enabled = canFindGitCmd;
  980. MergetoolPath.Enabled = canFindGitCmd;
  981. MergeToolCmd.Enabled = canFindGitCmd;
  982. GlobalKeepMergeBackup.Enabled = canFindGitCmd;
  983. InvalidGitPathGlobal.Visible = !canFindGitCmd;
  984. InvalidGitPathLocal.Visible = !canFindGitCmd;
  985. bool valid = Settings.Module.ValidWorkingDir() && canFindGitCmd;
  986. UserName.Enabled = valid;
  987. UserEmail.Enabled = valid;
  988. Editor.Enabled = valid;
  989. LocalMergeTool.Enabled = valid;
  990. KeepMergeBackup.Enabled = valid;
  991. localAutoCrlfFalse.Enabled = valid;
  992. localAutoCrlfInput.Enabled = valid;
  993. localAutoCrlfTrue.Enabled = valid;
  994. NoGitRepo.Visible = !valid;
  995. }
  996. private void CheckAtStartup_CheckedChanged(object sender, EventArgs e)
  997. {
  998. Settings.SetBool("checksettings", CheckAtStartup.Checked);
  999. }
  1000. private void Rescan_Click(object sender, EventArgs e)
  1001. {
  1002. Cursor.Current = Cursors.WaitCursor;
  1003. Save();
  1004. LoadSettings();
  1005. CheckSettings();
  1006. Cursor.Current = Cursors.Default;
  1007. }
  1008. private void BrowseGitPath_Click(object sender, EventArgs e)
  1009. {
  1010. SolveGitCommand();
  1011. var browseDialog = new OpenFileDialog
  1012. {
  1013. FileName = Settings.GitCommand,
  1014. Filter = "Git.cmd (git.cmd)|git.cmd|Git.exe (git.exe)|git.exe|Git (git)|git"
  1015. };
  1016. if (browseDialog.ShowDialog(this) == DialogResult.OK)
  1017. {
  1018. GitPath.Text = browseDialog.FileName;
  1019. }
  1020. }
  1021. private void TabPageGitExtensions_Click(object sender, EventArgs e)
  1022. {
  1023. GitPath.Text = Settings.GitCommand;
  1024. }
  1025. private void GitPath_TextChanged(object sender, EventArgs e)
  1026. {
  1027. if (loadingSettings)
  1028. return;
  1029. Settings.GitCommand = GitPath.Text;
  1030. LoadSettings();
  1031. }
  1032. private void GitBinFound_Click(object sender, EventArgs e)
  1033. {
  1034. if (!SolveLinuxToolsDir())
  1035. {
  1036. MessageBox.Show(this, _linuxToolsShNotFound.Text, _linuxToolsShNotFoundCaption.Text);
  1037. tabControl1.SelectTab(tpGit);
  1038. return;
  1039. }
  1040. MessageBox.Show(this, String.Format(_shCanBeRun.Text, Settings.GitBinDir), _shCanBeRunCaption.Text);
  1041. GitBinPath.Text = Settings.GitBinDir;
  1042. Rescan_Click(null, null);
  1043. }
  1044. private void OpenSSH_CheckedChanged(object sender, EventArgs e)
  1045. {
  1046. EnableSshOptions();
  1047. }
  1048. private void Putty_CheckedChanged(object sender, EventArgs e)
  1049. {
  1050. if (Putty.Checked)
  1051. {
  1052. AutoFindPuttyPaths();
  1053. }
  1054. EnableSshOptions();
  1055. }
  1056. private static IEnumerable<string> GetPuttyLocations()
  1057. {
  1058. string programFiles = Environment.GetEnvironmentVariable("ProgramFiles");
  1059. string programFilesX86 = null;
  1060. if (8 == IntPtr.Size
  1061. || !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))
  1062. programFilesX86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
  1063. yield return programFiles + @"\PuTTY\";
  1064. if (programFilesX86 != null)
  1065. yield return programFilesX86 + @"\PuTTY\";
  1066. yield return programFiles + @"\TortoiseGit\bin\";
  1067. if (programFilesX86 != null)
  1068. yield return programFilesX86 + @"\TortoiseGit\bin\";
  1069. yield return programFiles + @"\TortoiseSvn\bin\";
  1070. if (programFilesX86 != null)
  1071. yield return programFilesX86 + @"\TortoiseSvn\bin\";
  1072. yield return GetRegistryValue(Registry.LocalMachine,
  1073. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\PuTTY_is1",
  1074. "InstallLocation");
  1075. yield return Settings.GetInstallDir() + @"\PuTTY\";
  1076. }
  1077. private bool AutoFindPuttyPaths()
  1078. {
  1079. if (!Settings.RunningOnWindows())
  1080. return false;
  1081. foreach (var path in GetPuttyLocations())
  1082. {
  1083. if (AutoFindPuttyPathsInDir(path))
  1084. return true;
  1085. }
  1086. return false;
  1087. }
  1088. private bool AutoFindPuttyPathsInDir(string installdir)
  1089. {
  1090. if (!installdir.EndsWith("\\"))
  1091. installdir += "\\";
  1092. if (!File.Exists(PlinkPath.Text))
  1093. {
  1094. if (File.Exists(installdir + "plink.exe"))
  1095. PlinkPath.Text = installdir + "plink.exe";
  1096. if (!File.Exists(PlinkPath.Text))
  1097. {
  1098. if (File.Exists(installdir + "TortoisePlink.exe"))
  1099. PlinkPath.Text = installdir + "TortoisePlink.exe";
  1100. }
  1101. }
  1102. if (!File.Exists(PuttygenPath.Text))
  1103. {
  1104. if (File.Exists(installdir + "puttygen.exe"))
  1105. PuttygenPath.Text = installdir + "puttygen.exe";
  1106. }
  1107. if (!File.Exists(PageantPath.Text))
  1108. {
  1109. if (File.Exists(installdir + "pageant.exe"))
  1110. PageantPath.Text = installdir + "pageant.exe";
  1111. }
  1112. if (File.Exists(PlinkPath.Text) && File.Exists(PuttygenPath.Text) && File.Exists(PageantPath.Text))
  1113. return true;
  1114. return false;
  1115. }
  1116. private static string SelectFile(string initialDirectory, string filter, string prev)
  1117. {
  1118. var dialog = new OpenFileDialog
  1119. {
  1120. Filter = filter,
  1121. InitialDirectory = initialDirectory,
  1122. Title = _selectFile.Text
  1123. };
  1124. return (dialog.ShowDialog() == DialogResult.OK) ? dialog.FileName : prev;
  1125. }
  1126. private void OtherSshBrowse_Click(object sender, EventArgs e)
  1127. {
  1128. OtherSsh.Text = SelectFile(".", "Executable file (*.exe)|*.exe", OtherSsh.Text);
  1129. }
  1130. private void Other_CheckedChanged(object sender, EventArgs e)
  1131. {
  1132. EnableSshOptions();
  1133. }
  1134. private void EnableSshOptions()
  1135. {
  1136. OtherSsh.Enabled = Other.Checked;
  1137. OtherSshBrowse.Enabled = Other.Checked;
  1138. PlinkPath.Enabled = Putty.Checked;
  1139. PuttygenPath.Enabled = Putty.Checked;
  1140. PageantPath.Enabled = Putty.Checked;
  1141. PlinkBrowse.Enabled = Putty.Checked;
  1142. PuttygenBrowse.Enabled = Putty.Checked;
  1143. PageantBrowse.Enabled = Putty.Checked;
  1144. AutostartPageant.Enabled = Putty.Checked;
  1145. }
  1146. private void PuttyBrowse_Click(object sender, EventArgs e)
  1147. {
  1148. PlinkPath.Text = SelectFile(".",
  1149. "Plink.exe (plink.exe)|plink.exe|TortoisePlink.exe (tortoiseplink.exe)|tortoiseplink.exe",
  1150. PlinkPath.Text);
  1151. }
  1152. private void PuttygenBrowse_Click(object sender, EventArgs e)
  1153. {
  1154. PuttygenPath.Text = SelectFile(".", "puttygen.exe (puttygen.exe)|puttygen.exe", PuttygenPath.Text);
  1155. }
  1156. private void PageantBrowse_Click(object sender, EventArgs e)
  1157. {
  1158. PageantPath.Text = SelectFile(".", "pageant.exe (pageant.exe)|pageant.exe", PageantPath.Text);
  1159. }
  1160. private void SshConfig_Click(object sender, EventArgs e)
  1161. {
  1162. if (Putty.Checked)
  1163. {
  1164. if (AutoFindPuttyPaths())
  1165. MessageBox.Show(this, _puttyFoundAuto.Text, _puttyFoundAutoCaption.Text);
  1166. else
  1167. tabControl1.SelectTab(tpSsh);
  1168. }
  1169. }
  1170. private void BrowseGitBinPath_Click(object sender, EventArgs e)
  1171. {
  1172. SolveLinuxToolsDir();
  1173. var browseDialog = new FolderBrowserDialog { SelectedPath = Settings.GitBinDir };
  1174. if (browseDialog.ShowDialog(this) == DialogResult.OK)
  1175. {
  1176. GitBinPath.Text = browseDialog.SelectedPath;
  1177. }
  1178. }
  1179. private void FormSettings_Shown(object sender, EventArgs e)
  1180. {
  1181. Cursor.Current = Cursors.WaitCursor;
  1182. WindowState = FormWindowState.Normal;
  1183. RestorePosition("settings");
  1184. LoadSettings();
  1185. CheckSettings();
  1186. WindowState = FormWindowState.Normal;
  1187. Cursor.Current = Cursors.Default;
  1188. }
  1189. private void FormSettings_FormClosing(object sender, FormClosingEventArgs e)
  1190. {
  1191. Cursor.Current = Cursors.WaitCursor;
  1192. if (DialogResult != DialogResult.Abort && !Save())
  1193. e.Cancel = true;
  1194. Cursor.Current = Cursors.Default;
  1195. }
  1196. private void Dictionary_DropDown(object sender, EventArgs e)
  1197. {
  1198. try
  1199. {
  1200. Dictionary.Items.Clear();
  1201. Dictionary.Items.Add("None");
  1202. foreach (
  1203. string fileName in
  1204. Directory.GetFiles(Settings.GetDictionaryDir(), "*.dic", SearchOption.TopDirectoryOnly))
  1205. {
  1206. var file = new FileInfo(fileName);
  1207. Dictionary.Items.Add(file.Name.Replace(".dic", ""));
  1208. }
  1209. }
  1210. catch
  1211. {
  1212. MessageBox.Show(this, String.Format(_noDictFilesFound.Text, Settings.GetDictionaryDir()));
  1213. }
  1214. }
  1215. private void ColorAddedLineDiffLabel_Click(object sender, EventArgs e)
  1216. {
  1217. var colorDialog = new ColorDialog
  1218. {
  1219. Color = _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor
  1220. };
  1221. colorDialog.ShowDialog(this);
  1222. _NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor = colorDialog.Color;
  1223. _NO_TRANSLATE_ColorAddedLineDiffLabel.Text = colorDialog.Color.Name;
  1224. _NO_TRANSLATE_ColorAddedLineDiffLabel.ForeColor =
  1225. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor);
  1226. }
  1227. private void _ColorGraphLabel_Click(object sender, EventArgs e)
  1228. {
  1229. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorGraphLabel.BackColor };
  1230. colorDialog.ShowDialog(this);
  1231. _NO_TRANSLATE_ColorGraphLabel.BackColor = colorDialog.Color;
  1232. _NO_TRANSLATE_ColorGraphLabel.Text = colorDialog.Color.Name;
  1233. _NO_TRANSLATE_ColorGraphLabel.ForeColor =
  1234. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineDiffLabel.BackColor);
  1235. }
  1236. private void label28_Click(object sender, EventArgs e)
  1237. {
  1238. var colorDialog = new ColorDialog
  1239. {
  1240. Color = _NO_TRANSLATE_ColorAddedLineLabel.BackColor
  1241. };
  1242. colorDialog.ShowDialog(this);
  1243. _NO_TRANSLATE_ColorAddedLineLabel.BackColor = colorDialog.Color;
  1244. _NO_TRANSLATE_ColorAddedLineLabel.Text = colorDialog.Color.Name;
  1245. _NO_TRANSLATE_ColorAddedLineLabel.ForeColor =
  1246. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorAddedLineLabel.BackColor);
  1247. }
  1248. private void ColorRemovedLineDiffLabel_Click(object sender, EventArgs e)
  1249. {
  1250. var colorDialog = new ColorDialog
  1251. {
  1252. Color = _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor
  1253. };
  1254. colorDialog.ShowDialog(this);
  1255. _NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor = colorDialog.Color;
  1256. _NO_TRANSLATE_ColorRemovedLineDiffLabel.Text = colorDialog.Color.Name;
  1257. _NO_TRANSLATE_ColorRemovedLineDiffLabel.ForeColor =
  1258. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLineDiffLabel.BackColor);
  1259. }
  1260. private void ColorRemovedLine_Click(object sender, EventArgs e)
  1261. {
  1262. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorRemovedLine.BackColor };
  1263. colorDialog.ShowDialog(this);
  1264. _NO_TRANSLATE_ColorRemovedLine.BackColor = colorDialog.Color;
  1265. _NO_TRANSLATE_ColorRemovedLine.Text = colorDialog.Color.Name;
  1266. _NO_TRANSLATE_ColorRemovedLine.ForeColor =
  1267. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemovedLine.BackColor);
  1268. }
  1269. private void ColorSectionLabel_Click(object sender, EventArgs e)
  1270. {
  1271. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorSectionLabel.BackColor };
  1272. colorDialog.ShowDialog(this);
  1273. _NO_TRANSLATE_ColorSectionLabel.BackColor = colorDialog.Color;
  1274. _NO_TRANSLATE_ColorSectionLabel.Text = colorDialog.Color.Name;
  1275. _NO_TRANSLATE_ColorSectionLabel.ForeColor =
  1276. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorSectionLabel.BackColor);
  1277. }
  1278. private void ColorTagLabel_Click(object sender, EventArgs e)
  1279. {
  1280. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorTagLabel.BackColor };
  1281. colorDialog.ShowDialog(this);
  1282. _NO_TRANSLATE_ColorTagLabel.BackColor = colorDialog.Color;
  1283. _NO_TRANSLATE_ColorTagLabel.Text = colorDialog.Color.Name;
  1284. _NO_TRANSLATE_ColorTagLabel.ForeColor =
  1285. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorTagLabel.BackColor);
  1286. }
  1287. private void ColorBranchLabel_Click(object sender, EventArgs e)
  1288. {
  1289. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorBranchLabel.BackColor };
  1290. colorDialog.ShowDialog(this);
  1291. _NO_TRANSLATE_ColorBranchLabel.BackColor = colorDialog.Color;
  1292. _NO_TRANSLATE_ColorBranchLabel.Text = colorDialog.Color.Name;
  1293. _NO_TRANSLATE_ColorBranchLabel.ForeColor =
  1294. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorBranchLabel.BackColor);
  1295. }
  1296. private void ColorRemoteBranchLabel_Click(object sender, EventArgs e)
  1297. {
  1298. var colorDialog = new ColorDialog
  1299. {
  1300. Color = _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor
  1301. };
  1302. colorDialog.ShowDialog(this);
  1303. _NO_TRANSLATE_ColorRemoteBranchLabel.BackColor = colorDialog.Color;
  1304. _NO_TRANSLATE_ColorRemoteBranchLabel.Text = colorDialog.Color.Name;
  1305. _NO_TRANSLATE_ColorRemoteBranchLabel.ForeColor =
  1306. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorRemoteBranchLabel.BackColor);
  1307. }
  1308. private void ColorOtherLabel_Click(object sender, EventArgs e)
  1309. {
  1310. var colorDialog = new ColorDialog { Color = _NO_TRANSLATE_ColorOtherLabel.BackColor };
  1311. colorDialog.ShowDialog(this);
  1312. _NO_TRANSLATE_ColorOtherLabel.BackColor = colorDialog.Color;
  1313. _NO_TRANSLATE_ColorOtherLabel.Text = colorDialog.Color.Name;
  1314. _NO_TRANSLATE_ColorOtherLabel.ForeColor =
  1315. ColorHelper.GetForeColorForBackColor(_NO_TRANSLATE_ColorOtherLabel.BackColor);
  1316. }
  1317. private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
  1318. {
  1319. var tc = (TabControl) sender;
  1320. if (tc.SelectedTab == tpScriptsTab)
  1321. populateSplitbutton();
  1322. else if (tc.SelectedTab == tpHotkeys)
  1323. controlHotkeys.ReloadSettings();
  1324. if (GlobalMergeTool.Text.Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase) &&
  1325. string.IsNullOrEmpty(MergeToolCmd.Text))
  1326. MergeToolCmd.Enabled = false;
  1327. else
  1328. MergeToolCmd.Enabled = true;
  1329. }
  1330. private void populateSplitbutton()
  1331. {
  1332. System.Resources.ResourceManager rm =
  1333. new System.Resources.ResourceManager("GitUI.Properties.Resources",
  1334. System.Reflection.Assembly.GetExecutingAssembly());
  1335. // dummy request; for some strange reason the ResourceSets are not loaded untill after the first object request... bug?
  1336. rm.GetObject("dummy");
  1337. System.Resources.ResourceSet resourceSet = rm.GetResourceSet(System.Globalization.CultureInfo.CurrentUICulture, true, true);
  1338. contextMenuStrip_SplitButton.Items.Clear();
  1339. foreach (System.Collections.DictionaryEntry icon in resourceSet)
  1340. {
  1341. //add entry to toolstrip
  1342. if (icon.Value.GetType() == typeof(Icon))
  1343. {
  1344. //contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)((Icon)icon.Value).ToBitmap(), SplitButtonMenuItem_Click);
  1345. }
  1346. else if (icon.Value.GetType() == typeof(Bitmap))
  1347. {
  1348. contextMenuStrip_SplitButton.Items.Add(icon.Key.ToString(), (Image)icon.Value, SplitButtonMenuItem_Click);
  1349. }
  1350. //var aa = icon.Value.GetType();
  1351. }
  1352. resourceSet.Close();
  1353. rm.ReleaseAllResources();
  1354. }
  1355. public Bitmap ResizeBitmap(Bitmap b, int nWidth, int nHeight)
  1356. {
  1357. Bitmap result = new Bitmap(nWidth, nHeight);
  1358. using (Graphics g = Graphics.FromImage((Image)result))
  1359. g.DrawImage(b, 0, 0, nWidth, nHeight);
  1360. return result;
  1361. }
  1362. private void ClearImageCache_Click(object sender, EventArgs e)
  1363. {
  1364. GravatarService.ClearImageCache();
  1365. }
  1366. private void helpTranslate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1367. {
  1368. new FormTranslate().ShowDialog(this);
  1369. }
  1370. private void MulticolorBranches_CheckedChanged(object sender, EventArgs e)
  1371. {
  1372. if (MulticolorBranches.Checked)
  1373. {
  1374. _NO_TRANSLATE_ColorGraphLabel.Visible = false;
  1375. StripedBanchChange.Enabled = true;
  1376. }
  1377. else
  1378. {
  1379. _NO_TRANSLATE_ColorGraphLabel.Visible = true;
  1380. StripedBanchChange.Enabled = false;
  1381. }
  1382. }
  1383. private static bool getCheckAtStartupChecked(bool bValid)
  1384. {
  1385. var retValue = Settings.GetValue<string>("checksettings", null) == null || Settings.GetValue<string>("checksettings", null) == "true";
  1386. if (bValid && retValue)
  1387. {
  1388. Settings.SetValue("checksettings", false);
  1389. retValue = false;
  1390. }
  1391. return retValue;
  1392. }
  1393. private bool CheckTranslationConfigSettings()
  1394. {
  1395. translationConfig.Visible = true;
  1396. if (string.IsNullOrEmpty(Settings.Translation))
  1397. {
  1398. translationConfig.BackColor = Color.LightSalmon;
  1399. translationConfig.Text = _noLanguageConfigured.Text;
  1400. translationConfig_Fix.Visible = true;
  1401. return false;
  1402. }
  1403. translationConfig.BackColor = Color.LightGreen;
  1404. translationConfig_Fix.Visible = false;
  1405. translationConfig.Text = String.Format(_languageConfigured.Text, Settings.Translation);
  1406. return true;
  1407. }
  1408. private bool CheckSSHSettings()
  1409. {
  1410. SshConfig.Visible = true;
  1411. if (GitCommandHelpers.Plink())
  1412. {
  1413. if (!File.Exists(Settings.Plink) || !File.Exists(Settings.Puttygen) || !File.Exists(Settings.Pageant))
  1414. {
  1415. SshConfig.BackColor = Color.LightSalmon;
  1416. SshConfig.Text = _plinkputtyGenpageantNotFound.Text;
  1417. SshConfig_Fix.Visible = true;
  1418. return false;
  1419. }
  1420. SshConfig.BackColor = Color.LightGreen;
  1421. SshConfig_Fix.Visible = false;
  1422. SshConfig.Text = _puttyConfigured.Text;
  1423. return true;
  1424. }
  1425. SshConfig.BackColor = Color.LightGreen;
  1426. SshConfig_Fix.Visible = false;
  1427. if (string.IsNullOrEmpty(GitCommandHelpers.GetSsh()))
  1428. SshConfig.Text = _opensshUsed.Text;
  1429. else
  1430. SshConfig.Text = String.Format(_unknownSshClient.Text, GitCommandHelpers.GetSsh());
  1431. return true;
  1432. }
  1433. private bool CheckGitExe()
  1434. {
  1435. GitBinFound.Visible = true;
  1436. if (!File.Exists(Settings.GitBinDir + "sh.exe") && !File.Exists(Settings.GitBinDir + "sh") &&
  1437. !CheckIfFileIsInPath("sh.exe") && !CheckIfFileIsInPath("sh"))
  1438. {
  1439. GitBinFound.BackColor = Color.LightSalmon;
  1440. GitBinFound.Text = _linuxToolsSshNotFound.Text;
  1441. GitBinFound_Fix.Visible = true;
  1442. return false;
  1443. }
  1444. GitBinFound_Fix.Visible = false;
  1445. GitBinFound.BackColor = Color.LightGreen;
  1446. GitBinFound.Text = _linuxToolsSshFound.Text;
  1447. return true;
  1448. }
  1449. private bool CheckGitCmdValid()
  1450. {
  1451. GitFound.Visible = true;
  1452. if (!CanFindGitCmd())
  1453. {
  1454. GitFound.BackColor = Color.LightSalmon;
  1455. GitFound.Text = _gitNotFound.Text;
  1456. GitFound_Fix.Visible = true;
  1457. return false;
  1458. }
  1459. if (GitCommandHelpers.VersionInUse < GitVersion.LastSupportedVersion)
  1460. {
  1461. GitFound.BackColor = Color.LightSalmon;
  1462. GitFound.Text = String.Format(_wrongGitVersion.Text, GitCommandHelpers.VersionInUse, GitVersion.LastSupportedVersion);
  1463. GitFound_Fix.Visible = true;
  1464. return false;
  1465. }
  1466. GitFound_Fix.Visible = false;
  1467. GitFound.BackColor = Color.LightGreen;
  1468. GitFound.Text = String.Format(_gitVersionFound.Text, GitCommandHelpers.VersionInUse);
  1469. return true;
  1470. }
  1471. private bool CheckDiffToolConfiguration()
  1472. {
  1473. DiffTool.Visible = true;
  1474. if (string.IsNullOrEmpty(GetGlobalDiffToolFromConfig()))
  1475. {
  1476. DiffTool.BackColor = Color.LightSalmon;
  1477. DiffTool_Fix.Visible = true;
  1478. DiffTool.Text = _adviceDiffToolConfiguration.Text;
  1479. return false;
  1480. }
  1481. if (Settings.RunningOnWindows())
  1482. {
  1483. if (GetGlobalDiffToolFromConfig().Equals("kdiff3", StringComparison.CurrentCultureIgnoreCase))
  1484. {
  1485. string p = Settings.Module.GetGlobalSetting("difftool.kdiff3.path");
  1486. if (string.IsNullOrEmpty(p) || !File.Exists(p))
  1487. {
  1488. DiffTool.BackColor = Color.LightSalmon;
  1489. DiffTool.Text = _kdiffAsDiffConfiguredButNotFound.Text;
  1490. DiffTool_Fix.Visible = true;
  1491. return false;
  1492. }
  1493. DiffTool.BackColor = Color.LightGreen;
  1494. DiffTool.Text = _kdiffAsDiffConfigured.Text;
  1495. DiffTool_Fix.Visible = false;
  1496. return true;
  1497. }
  1498. }
  1499. string difftool = GetGlobalDiffToolFromConfig();
  1500. DiffTool.BackColor = Color.LightGreen;
  1501. DiffTool.Text = String.Format(_diffToolXConfigured.Text, difftool);
  1502. DiffTool_Fix.Visible = false;
  1503. return true;
  1504. }
  1505. private bool CheckMergeTool()
  1506. {
  1507. MergeTool.Visible = true;
  1508. if (string.IsNullOrEmpty(GetMergeTool()))
  1509. {
  1510. MergeTool.BackColor = Color.LightSalmon;
  1511. MergeTool.Text = _configureMergeTool.Text;
  1512. MergeTool_Fix.Visible = true;
  1513. return false;
  1514. }
  1515. if (Settings.RunningOnWindows())
  1516. {
  1517. if (IsMergeTool("kdiff3"))
  1518. {
  1519. string p = Settings.Module.GetGlobalSetting("mergetool.kdiff3.path");
  1520. if (string.IsNullOrEmpty(p) || !File.Exists(p))
  1521. {
  1522. MergeTool.BackColor = Color.LightSalmon;
  1523. MergeTool.Text = _kdiffAsMergeConfiguredButNotFound.Text;
  1524. MergeTool_Fix.Visible = true;
  1525. return false;
  1526. }
  1527. MergeTool.BackColor = Color.LightGreen;
  1528. MergeTool.Text = _kdiffAsMergeConfigured.Text;
  1529. MergeTool_Fix.Visible = false;
  1530. return true;
  1531. }
  1532. string mergetool = GetMergeTool().ToLowerInvariant();
  1533. if (mergetool == "p4merge" || mergetool == "tmerge")
  1534. {
  1535. string p = Settings.Module.GetGlobalSetting(string.Format("mergetool.{0}.cmd", mergetool));
  1536. if (string.IsNullOrEmpty(p))
  1537. {
  1538. MergeTool.BackColor = Color.LightSalmon;
  1539. MergeTool.Text = String.Format(_mergeToolXConfiguredNeedsCmd.Text, mergetool);
  1540. MergeTool_Fix.Visible = true;
  1541. return false;
  1542. }
  1543. MergeTool.BackColor = Color.LightGreen;
  1544. MergeTool.Text = String.Format(_customMergeToolXConfigured.Text, mergetool);
  1545. MergeTool_Fix.Visible = false;
  1546. return true;
  1547. }
  1548. }
  1549. MergeTool.BackColor = Color.LightGreen;
  1550. MergeTool.Text = _mergeToolXConfigured.Text;
  1551. MergeTool_Fix.Visible = false;
  1552. return true;
  1553. }
  1554. private bool CheckGlobalUserSettingsValid()
  1555. {
  1556. UserNameSet.Visible = true;
  1557. if (string.IsNullOrEmpty(Settings.Module.GetGlobalSetting("user.name")) ||
  1558. string.IsNullOrEmpty(Settings.Module.GetGlobalSetting("user.email")))
  1559. {
  1560. UserNameSet.BackColor = Color.LightSalmon;
  1561. UserNameSet.Text = _noEmailSet.Text;
  1562. UserNameSet_Fix.Visible = true;
  1563. return false;
  1564. }
  1565. UserNameSet.BackColor = Color.LightGreen;
  1566. UserNameSet.Text = _emailSet.Text;
  1567. UserNameSet_Fix.Visible = false;
  1568. return true;
  1569. }
  1570. private bool CheckGitExtensionRegistrySettings()
  1571. {
  1572. if (!Settings.RunningOnWindows())
  1573. return true;
  1574. ShellExtensionsRegistered.Visible = true;
  1575. if (string.IsNullOrEmpty(GetRegistryValue(Registry.LocalMachine,
  1576. "Software\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved",
  1577. "{3C16B20A-BA16-4156-916F-0A375ECFFE24}")) ||
  1578. string.IsNullOrEmpty(GetRegistryValue(Registry.ClassesRoot,
  1579. "*\\shellex\\ContextMenuHandlers\\GitExtensions2", null)) ||
  1580. string.IsNullOrEmpty(GetRegistryValue(Registry.ClassesRoot,
  1581. "Directory\\shellex\\ContextMenuHandlers\\GitExtensions2", null)) ||
  1582. string.IsNullOrEmpty(GetRegistryValue(Registry.ClassesRoot,
  1583. "Directory\\Background\\shellex\\ContextMenuHandlers\\GitExtensions2",
  1584. null)))
  1585. {
  1586. //Check if shell extensions are installed
  1587. string path = Path.Combine(Settings.GetInstallDir(), GitExtensionsShellExName);
  1588. if (!File.Exists(path))
  1589. {
  1590. ShellExtensionsRegistered.BackColor = Color.LightGreen;
  1591. ShellExtensionsRegistered.Text = String.Format(_shellExtNoInstalled.Text);
  1592. ShellExtensionsRegistered_Fix.Visible = false;
  1593. return true;
  1594. }
  1595. ShellExtensionsRegistered.BackColor = Color.LightSalmon;
  1596. ShellExtensionsRegistered.Text = String.Format(_shellExtNeedsToBeRegistered.Text, GitExtensionsShellExName);
  1597. ShellExtensionsRegistered_Fix.Visible = true;
  1598. return false;
  1599. }
  1600. ShellExtensionsRegistered.BackColor = Color.LightGreen;
  1601. ShellExtensionsRegistered.Text = _shellExtRegistered.Text;
  1602. ShellExtensionsRegistered_Fix.Visible = false;
  1603. return true;
  1604. }
  1605. private bool CheckGitExtensionsInstall()
  1606. {
  1607. if (!Settings.RunningOnWindows())
  1608. return true;
  1609. GitExtensionsInstall.Visible = true;
  1610. if (string.IsNullOrEmpty(Settings.GetInstallDir()))
  1611. {
  1612. GitExtensionsInstall.BackColor = Color.LightSalmon;
  1613. GitExtensionsInstall.Text = _registryKeyGitExtensionsMissing.Text;
  1614. GitExtensionsInstall_Fix.Visible = true;
  1615. return false;
  1616. }
  1617. if (Settings.GetInstallDir() != null && Settings.GetInstallDir().EndsWith(".exe"))
  1618. {
  1619. GitExtensionsInstall.BackColor = Color.LightSalmon;
  1620. GitExtensionsInstall.Text = _registryKeyGitExtensionsFaulty.Text;
  1621. GitExtensionsInstall_Fix.Visible = true;
  1622. return false;
  1623. }
  1624. GitExtensionsInstall.BackColor = Color.LightGreen;
  1625. GitExtensionsInstall.Text = _registryKeyGitExtensionsCorrect.Text;
  1626. GitExtensionsInstall_Fix.Visible = false;
  1627. return true;
  1628. }
  1629. private static IEnumerable<string> GetGitLocations()
  1630. {
  1631. yield return @"C:\cygwin\";
  1632. yield return
  1633. GetRegistryValue(Registry.LocalMachine,
  1634. "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1", "InstallLocation");
  1635. string programFiles = Environment.GetEnvironmentVariable("ProgramFiles");
  1636. string programFilesX86 = null;
  1637. if (8 == IntPtr.Size
  1638. || !String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432")))
  1639. programFilesX86 = Environment.GetEnvironmentVariable("ProgramFiles(x86)");
  1640. if (programFilesX86 != null)
  1641. yield return programFilesX86 + @"\Git\";
  1642. yield return programFiles + @"\Git\";
  1643. if (programFilesX86 != null)
  1644. yield return programFilesX86 + @"\msysgit\";
  1645. yield return programFiles + @"\msysgit\";
  1646. yield return @"C:\msysgit\";
  1647. }
  1648. public static bool CheckIfFileIsInPath(string fileName)
  1649. {
  1650. string path = string.Concat(Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.User), ";",
  1651. Environment.GetEnvironmentVariable("path", EnvironmentVariableTarget.Machine));
  1652. return path.Split(';').Any(dir => File.Exists(dir + " \\" + fileName) || File.Exists(dir + fileName));
  1653. }
  1654. public static bool SolveLinuxToolsDir()
  1655. {
  1656. if (!Settings.RunningOnWindows())
  1657. {
  1658. Settings.GitBinDir = "";
  1659. return true;
  1660. }
  1661. if (CheckIfFileIsInPath("sh.exe") || CheckIfFileIsInPath("sh"))
  1662. {
  1663. Settings.GitBinDir = "";
  1664. return true;
  1665. }
  1666. foreach (var path in GetGitLocations())
  1667. {
  1668. if (Directory.Exists(path + @"bin\"))
  1669. {
  1670. if (File.Exists(path + @"bin\sh.exe") || File.Exists(path + @"bin\sh"))
  1671. {
  1672. Settings.GitBinDir = path + @"bin\";
  1673. return true;
  1674. }
  1675. }
  1676. }
  1677. return false;
  1678. }
  1679. private static IEnumerable<string> GetWindowsCommandLocations()
  1680. {
  1681. if (!string.IsNullOrEmpty(Settings.GitCommand) && File.Exists(Settings.GitCommand))
  1682. yield return Settings.GitCommand;
  1683. foreach (var path in GetGitLocations())
  1684. {
  1685. if (Directory.Exists(path + @"bin\"))
  1686. yield return path + @"bin\git.exe";
  1687. }
  1688. foreach (var path in GetGitLocations())
  1689. {
  1690. if (Directory.Exists(path + @"cmd\"))
  1691. yield return path + @"cmd\git.cmd";
  1692. }
  1693. yield return "git";
  1694. yield return "git.cmd";
  1695. }
  1696. private static bool SolveGitCommand()
  1697. {
  1698. if (Settings.RunningOnWindows())
  1699. {
  1700. var command = (from cmd in GetWindowsCommandLocations()
  1701. let output = Settings.Module.RunCmd(cmd, string.Empty)
  1702. where !string.IsNullOrEmpty(output)
  1703. select cmd).FirstOrDefault();
  1704. if (command != null)
  1705. {
  1706. Settings.GitCommand = command;
  1707. return true;
  1708. }
  1709. return false;
  1710. }
  1711. Settings.GitCommand = "git";
  1712. return !string.IsNullOrEmpty(Settings.Module.RunGitCmd(""));
  1713. }
  1714. private void SaveScripts()
  1715. {
  1716. Settings.ownScripts = ScriptManager.SerializeIntoXml();
  1717. }
  1718. private void LoadScripts()
  1719. {
  1720. ScriptList.DataSource = ScriptManager.GetScripts();
  1721. }
  1722. private void ClearScriptDetails()
  1723. {
  1724. nameTextBox.Clear();
  1725. commandTextBox.Clear();
  1726. argumentsTextBox.Clear();
  1727. inMenuCheckBox.Checked = false;
  1728. }
  1729. private void RefreshScriptDetails()
  1730. {
  1731. if (ScriptList.SelectedRows.Count == 0)
  1732. return;
  1733. ScriptInfo scriptInfo = ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo;
  1734. nameTextBox.Text = scriptInfo.Name;
  1735. commandTextBox.Text = scriptInfo.Command;
  1736. argumentsTextBox.Text = scriptInfo.Arguments;
  1737. inMenuCheckBox.Checked = scriptInfo.AddToRevisionGridContextMenu;
  1738. scriptEnabled.Checked = scriptInfo.Enabled;
  1739. scriptNeedsConfirmation.Checked = scriptInfo.AskConfirmation;
  1740. scriptEvent.SelectedItem = scriptInfo.OnEvent;
  1741. sbtn_icon.Image = scriptInfo.GetIcon();
  1742. IconName = scriptInfo.Icon;
  1743. foreach (ToolStripItem item in contextMenuStrip_SplitButton.Items)
  1744. {
  1745. if (item.ToString() == IconName)
  1746. {
  1747. item.Font = new Font(item.Font, FontStyle.Bold);
  1748. }
  1749. }
  1750. }
  1751. private void addScriptButton_Click(object sender, EventArgs e)
  1752. {
  1753. ScriptList.ClearSelection();
  1754. ScriptManager.GetScripts().AddNew();
  1755. ScriptList.Rows[ScriptList.RowCount - 1].Selected = true;
  1756. ScriptList_SelectionChanged(null, null); //needed for linux
  1757. }
  1758. private void removeScriptButton_Click(object sender, EventArgs e)
  1759. {
  1760. if (ScriptList.SelectedRows.Count > 0)
  1761. {
  1762. ScriptManager.GetScripts().Remove(ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo);
  1763. ClearScriptDetails();
  1764. }
  1765. }
  1766. private void ScriptInfoFromEdits()
  1767. {
  1768. if (ScriptList.SelectedRows.Count > 0)
  1769. {
  1770. ScriptInfo selectedScriptInfo = ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo;
  1771. selectedScriptInfo.HotkeyCommandIdentifier = ScriptList.SelectedRows[0].Index + 9000;
  1772. selectedScriptInfo.Name = nameTextBox.Text;
  1773. selectedScriptInfo.Command = commandTextBox.Text;
  1774. selectedScriptInfo.Arguments = argumentsTextBox.Text;
  1775. selectedScriptInfo.AddToRevisionGridContextMenu = inMenuCheckBox.Checked;
  1776. selectedScriptInfo.Enabled = scriptEnabled.Checked;
  1777. selectedScriptInfo.AskConfirmation = scriptNeedsConfirmation.Checked;
  1778. selectedScriptInfo.OnEvent = (ScriptEvent)scriptEvent.SelectedItem;
  1779. selectedScriptInfo.Icon = IconName;
  1780. }
  1781. }
  1782. private void moveUpButton_Click(object sender, EventArgs e)
  1783. {
  1784. if (ScriptList.SelectedRows.Count > 0)
  1785. {
  1786. ScriptInfo scriptInfo = ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo;
  1787. int index = ScriptManager.GetScripts().IndexOf(scriptInfo);
  1788. ScriptManager.GetScripts().Remove(scriptInfo);
  1789. ScriptManager.GetScripts().Insert(Math.Max(index - 1, 0), scriptInfo);
  1790. ScriptList.ClearSelection();
  1791. ScriptList.Rows[Math.Max(index - 1, 0)].Selected = true;
  1792. ScriptList.Focus();
  1793. }
  1794. }
  1795. private void moveDownButton_Click(object sender, EventArgs e)
  1796. {
  1797. if (ScriptList.SelectedRows.Count > 0)
  1798. {
  1799. ScriptInfo scriptInfo = ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo;
  1800. int index = ScriptManager.GetScripts().IndexOf(scriptInfo);
  1801. ScriptManager.GetScripts().Remove(scriptInfo);
  1802. ScriptManager.GetScripts().Insert(Math.Min(index + 1, ScriptManager.GetScripts().Count), scriptInfo);
  1803. ScriptList.ClearSelection();
  1804. ScriptList.Rows[Math.Max(index + 1, 0)].Selected = true;
  1805. ScriptList.Focus();
  1806. }
  1807. }
  1808. private void browseScriptButton_Click(object sender, EventArgs e)
  1809. {
  1810. var ofd = new OpenFileDialog
  1811. {
  1812. InitialDirectory = "c:\\",
  1813. Filter = "Executable files (*.exe)|*.exe|All files (*.*)|*.*",
  1814. RestoreDirectory = true
  1815. };
  1816. if (ofd.ShowDialog(this) == DialogResult.OK)
  1817. commandTextBox.Text = ofd.FileName;
  1818. }
  1819. private void argumentsTextBox_Enter(object sender, EventArgs e)
  1820. {
  1821. helpLabel.Visible = true;
  1822. }
  1823. private void argumentsTextBox_Leave(object sender, EventArgs e)
  1824. {
  1825. helpLabel.Visible = false;
  1826. }
  1827. private void translationConfig_Click(object sender, EventArgs e)
  1828. {
  1829. new FormChooseTranslation().ShowDialog(this);
  1830. Translate();
  1831. Language.Text = Settings.Translation;
  1832. Rescan_Click(null, null);
  1833. }
  1834. private void downloadDictionary_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1835. {
  1836. Process.Start(@"https://github.com/spdr870/gitextensions/wiki/Spelling");
  1837. }
  1838. private void ScriptList_SelectionChanged(object sender, EventArgs e)
  1839. {
  1840. if (ScriptList.SelectedRows.Count > 0)
  1841. {
  1842. RefreshScriptDetails();
  1843. removeScriptButton.Enabled = true;
  1844. moveDownButton.Enabled = moveUpButton.Enabled = false;
  1845. if (ScriptList.SelectedRows[0].Index > 0)
  1846. moveUpButton.Enabled = true;
  1847. if (ScriptList.SelectedRows[0].Index < ScriptList.RowCount - 1)
  1848. moveDownButton.Enabled = true;
  1849. }
  1850. else
  1851. {
  1852. removeScriptButton.Enabled = false;
  1853. moveUpButton.Enabled = false;
  1854. moveDownButton.Enabled = false;
  1855. ClearScriptDetails();
  1856. }
  1857. }
  1858. private void ScriptInfoEdit_Validating(object sender, System.ComponentModel.CancelEventArgs e)
  1859. {
  1860. ScriptInfoFromEdits();
  1861. ScriptList.Refresh();
  1862. }
  1863. private void ScriptList_CellClick(object sender, DataGridViewCellEventArgs e)
  1864. {
  1865. ScriptList_SelectionChanged(null, null);//needed for linux
  1866. }
  1867. #region Hotkey commands
  1868. public const string HotkeySettingsName = "Scripts";
  1869. internal enum Commands
  1870. {
  1871. NothingYet
  1872. }
  1873. protected override bool ExecuteCommand(int cmd)
  1874. {
  1875. Commands command = (Commands)cmd;
  1876. switch (command)
  1877. {
  1878. default: ExecuteScriptCommand(cmd, Keys.None); break;
  1879. }
  1880. return true;
  1881. }
  1882. #endregion
  1883. private void ShowIconPreview()
  1884. {
  1885. string color = IconStyle.Text.ToLowerInvariant();
  1886. Icon icon = null;
  1887. switch (color)
  1888. {
  1889. case "default":
  1890. IconPreview.Image = (new Icon(GetApplicationIcon("Large", GetSelectedApplicationIconColor()), 32, 32)).ToBitmap();
  1891. IconPreviewSmall.Image = (new Icon(GetApplicationIcon("Small", GetSelectedApplicationIconColor()), 16, 16)).ToBitmap();
  1892. break;
  1893. case "small":
  1894. icon = GetApplicationIcon("Small", GetSelectedApplicationIconColor());
  1895. IconPreview.Image = (new Icon(icon, 32, 32)).ToBitmap();
  1896. IconPreviewSmall.Image = (new Icon(icon, 16, 16)).ToBitmap();
  1897. break;
  1898. case "large":
  1899. icon = GetApplicationIcon("Large", GetSelectedApplicationIconColor());
  1900. IconPreview.Image = (new Icon(icon, 32, 32)).ToBitmap();
  1901. IconPreviewSmall.Image = (new Icon(icon, 16, 16)).ToBitmap();
  1902. break;
  1903. case "cow":
  1904. icon = GetApplicationIcon("Cow", GetSelectedApplicationIconColor());
  1905. IconPreview.Image = (new Icon(icon, 32, 32)).ToBitmap();
  1906. IconPreviewSmall.Image = (new Icon(icon, 16, 16)).ToBitmap();
  1907. break;
  1908. }
  1909. }
  1910. private void IconStyle_SelectedIndexChanged(object sender, EventArgs e)
  1911. {
  1912. if (loadingSettings)
  1913. return;
  1914. ShowIconPreview();
  1915. }
  1916. private void IconColor_CheckedChanged(object sender, EventArgs e)
  1917. {
  1918. if (loadingSettings)
  1919. return;
  1920. ShowIconPreview();
  1921. }
  1922. private void diffFontChangeButton_Click(object sender, EventArgs e)
  1923. {
  1924. diffFontDialog.Font = diffFont;
  1925. DialogResult result = diffFontDialog.ShowDialog(this);
  1926. if (result == DialogResult.OK || result == DialogResult.Yes)
  1927. {
  1928. SetCurrentDiffFont(diffFontDialog.Font);
  1929. }
  1930. }
  1931. private void SetCurrentDiffFont(Font font)
  1932. {
  1933. diffFont = font;
  1934. diffFontChangeButton.Text =
  1935. string.Format("{0}, {1}", diffFont.FontFamily.Name, (int)diffFont.Size);
  1936. }
  1937. private void BrowseCommitTemplate_Click(object sender, EventArgs e)
  1938. {
  1939. CommitTemplatePath.Text = SelectFile(".", "*.txt (*.txt)|*.txt", CommitTemplatePath.Text);
  1940. }
  1941. private void SplitButtonMenuItem_Click(object sender, EventArgs e)
  1942. {
  1943. //reset bold item to regular
  1944. var item = contextMenuStrip_SplitButton.Items.OfType<ToolStripMenuItem>().First(s => s.Font.Bold);
  1945. item.Font = new Font(contextMenuStrip_SplitButton.Font, FontStyle.Regular);
  1946. //make new item bold
  1947. ((ToolStripMenuItem)sender).Font = new Font(((ToolStripMenuItem)sender).Font, FontStyle.Bold);
  1948. //set new image on button
  1949. sbtn_icon.Image = ResizeBitmap((Bitmap)((ToolStripMenuItem)sender).Image, 12, 12);
  1950. IconName = ((ToolStripMenuItem)sender).Text;
  1951. //store variables
  1952. ScriptInfoEdit_Validating(sender, new System.ComponentModel.CancelEventArgs());
  1953. }
  1954. private void scriptEvent_SelectedIndexChanged(object sender, EventArgs e)
  1955. {
  1956. if (scriptEvent.Text == ScriptEvent.ShowInUserMenuBar.ToString())
  1957. {
  1958. /*
  1959. string icon_name = IconName;
  1960. if (ScriptList.RowCount > 0)
  1961. {
  1962. ScriptInfo scriptInfo = ScriptList.SelectedRows[0].DataBoundItem as ScriptInfo;
  1963. icon_name = scriptInfo.Icon;
  1964. }*/
  1965. sbtn_icon.Visible = true;
  1966. lbl_icon.Visible = true;
  1967. }
  1968. else
  1969. {
  1970. //not a menubar item, so hide the text label and dropdown button
  1971. sbtn_icon.Visible = false;
  1972. lbl_icon.Visible = false;
  1973. }
  1974. }
  1975. private void downloadMsysgit_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  1976. {
  1977. Process.Start(@"http://code.google.com/p/msysgit/");
  1978. }
  1979. private void ChangeHomeButton_Click(object sender, EventArgs e)
  1980. {
  1981. Save();
  1982. new FormFixHome().ShowDialog(this);
  1983. LoadSettings();
  1984. Rescan_Click(null, null);
  1985. }
  1986. }
  1987. }