-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
AppearanceSettingsPage.cs
181 lines (151 loc) · 6.87 KB
/
AppearanceSettingsPage.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
using System;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using GitCommands;
using GitUI.Avatars;
using ResourceManager;
namespace GitUI.CommandsDialogs.SettingsDialog.Pages
{
public partial class AppearanceSettingsPage : SettingsPageWithHeader
{
private readonly TranslationString _noDictFile = new TranslationString("None");
private readonly TranslationString _noDictFilesFound = new TranslationString("No dictionary files found in: {0}");
public AppearanceSettingsPage()
{
InitializeComponent();
InitializeComplete();
NoImageService.Items.AddRange(Enum.GetNames(typeof(DefaultImageType)));
}
protected override void OnRuntimeLoad()
{
base.OnRuntimeLoad();
// align 1st columns across all tables
tlpnlGeneral.AdjustWidthToSize(0, truncateLongFilenames, lblCacheDays, lblNoImageService, lblLanguage, lblSpellingDictionary);
tlpnlAuthor.AdjustWidthToSize(0, truncateLongFilenames, lblCacheDays, lblNoImageService, lblLanguage, lblSpellingDictionary);
tlpnlLanguage.AdjustWidthToSize(0, truncateLongFilenames, lblCacheDays, lblNoImageService, lblLanguage, lblSpellingDictionary);
// align 2nd columns across all tables
truncatePathMethod.AdjustWidthToFitContent();
Language.AdjustWidthToFitContent();
tlpnlGeneral.AdjustWidthToSize(1, truncatePathMethod, NoImageService, Language);
tlpnlAuthor.AdjustWidthToSize(1, truncatePathMethod, NoImageService, Language);
tlpnlLanguage.AdjustWidthToSize(1, truncatePathMethod, NoImageService, Language);
}
public static SettingsPageReference GetPageReference()
{
return new SettingsPageReferenceByType(typeof(AppearanceSettingsPage));
}
protected override void SettingsToPage()
{
chkEnableAutoScale.Checked = AppSettings.EnableAutoScale;
chkShowCurrentBranchInVisualStudio.Checked = AppSettings.ShowCurrentBranchInVisualStudio;
_NO_TRANSLATE_DaysToCacheImages.Value = AppSettings.AvatarImageCacheDays;
ShowAuthorAvatar.Checked = AppSettings.ShowAuthorAvatarInCommitInfo;
NoImageService.Text = AppSettings.GravatarDefaultImageType.ToString();
Language.Items.Clear();
Language.Items.Add("English");
Language.Items.AddRange(Translator.GetAllTranslations());
Language.Text = AppSettings.Translation;
truncatePathMethod.SelectedIndex = GetTruncatePathMethodIndex(AppSettings.TruncatePathMethod);
Dictionary.Items.Clear();
Dictionary.Items.Add(_noDictFile.Text);
if (AppSettings.Dictionary.Equals("none", StringComparison.InvariantCultureIgnoreCase))
{
Dictionary.SelectedIndex = 0;
}
else
{
string dictionaryFile = string.Concat(Path.Combine(AppSettings.GetDictionaryDir(), AppSettings.Dictionary), ".dic");
if (File.Exists(dictionaryFile))
{
Dictionary.Items.Add(AppSettings.Dictionary);
Dictionary.Text = AppSettings.Dictionary;
}
else
{
Dictionary.SelectedIndex = 0;
}
}
chkShowRelativeDate.Checked = AppSettings.RelativeDate;
return;
int GetTruncatePathMethodIndex(TruncatePathMethod method)
{
switch (method)
{
case TruncatePathMethod.Compact:
return 1;
case TruncatePathMethod.TrimStart:
return 2;
case TruncatePathMethod.FileNameOnly:
return 3;
default:
return 0;
}
}
}
protected override void PageToSettings()
{
AppSettings.EnableAutoScale = chkEnableAutoScale.Checked;
AppSettings.TruncatePathMethod = GetTruncatePathMethodString(truncatePathMethod.SelectedIndex);
AppSettings.ShowCurrentBranchInVisualStudio = chkShowCurrentBranchInVisualStudio.Checked;
AppSettings.Translation = Language.Text;
Strings.Reinitialize();
AppSettings.AvatarImageCacheDays = (int)_NO_TRANSLATE_DaysToCacheImages.Value;
AppSettings.ShowAuthorAvatarInCommitInfo = ShowAuthorAvatar.Checked;
if (Enum.TryParse<DefaultImageType>(NoImageService.Text, ignoreCase: true, out var type))
{
AppSettings.GravatarDefaultImageType = type;
}
AppSettings.RelativeDate = chkShowRelativeDate.Checked;
AppSettings.Dictionary = Dictionary.SelectedIndex == 0 ? "none" : Dictionary.Text;
return;
TruncatePathMethod GetTruncatePathMethodString(int index)
{
switch (index)
{
case 1:
return TruncatePathMethod.Compact;
case 2:
return TruncatePathMethod.TrimStart;
case 3:
return TruncatePathMethod.FileNameOnly;
default:
return TruncatePathMethod.None;
}
}
}
private void Dictionary_DropDown(object sender, EventArgs e)
{
try
{
string currentDictionary = Dictionary.Text;
Dictionary.Items.Clear();
Dictionary.Items.Add(_noDictFile.Text);
foreach (
string fileName in
Directory.GetFiles(AppSettings.GetDictionaryDir(), "*.dic", SearchOption.TopDirectoryOnly))
{
var file = new FileInfo(fileName);
Dictionary.Items.Add(file.Name.Replace(".dic", ""));
}
Dictionary.Text = currentDictionary;
}
catch
{
MessageBox.Show(this, string.Format(_noDictFilesFound.Text, AppSettings.GetDictionaryDir()));
}
}
private void ClearImageCache_Click(object sender, EventArgs e)
{
ThreadHelper.JoinableTaskFactory.Run(AvatarService.Default.ClearCacheAsync);
}
private void helpTranslate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "TranslationApp.exe"));
}
private void downloadDictionary_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Process.Start(@"https://github.com/gitextensions/gitextensions/wiki/Spelling");
}
}
}