Move prune (all remotes) setting to git config page
[TortoiseGit.git] / src / TortoiseProc / Settings / SetOverlayIcons.cpp
blob6fd2df8c1e98fe3152f7180532ff9b56190b1bd6
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011, 2013-2014, 2016, 2020 - TortoiseGit
4 // Copyright (C) 2003-2008, 2014 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "TortoiseProc.h"
22 #include "DirFileEnum.h"
23 #include "SetOverlayIcons.h"
24 #include "StringUtils.h"
25 #include "PathUtils.h"
26 #include "LoadIconEx.h"
28 IMPLEMENT_DYNAMIC(CSetOverlayIcons, ISettingsPropPage)
29 CSetOverlayIcons::CSetOverlayIcons()
30 : ISettingsPropPage(CSetOverlayIcons::IDD)
32 m_regNormal = CRegString(L"Software\\TortoiseOverlays\\NormalIcon");
33 m_regModified = CRegString(L"Software\\TortoiseOverlays\\ModifiedIcon");
34 m_regConflicted = CRegString(L"Software\\TortoiseOverlays\\ConflictIcon");
35 m_regReadOnly = CRegString(L"Software\\TortoiseOverlays\\ReadOnlyIcon");
36 m_regDeleted = CRegString(L"Software\\TortoiseOverlays\\DeletedIcon");
37 m_regLocked = CRegString(L"Software\\TortoiseOverlays\\LockedIcon");
38 m_regAdded = CRegString(L"Software\\TortoiseOverlays\\AddedIcon");
39 m_regIgnored = CRegString(L"Software\\TortoiseOverlays\\IgnoredIcon");
40 m_regUnversioned = CRegString(L"Software\\TortoiseOverlays\\UnversionedIcon");
41 m_selIndex = CB_ERR;
44 CSetOverlayIcons::~CSetOverlayIcons()
48 void CSetOverlayIcons::DoDataExchange(CDataExchange* pDX)
50 ISettingsPropPage::DoDataExchange(pDX);
51 DDX_Control(pDX, IDC_ICONSETCOMBO, m_cIconSet);
52 DDX_Control(pDX, IDC_ICONLIST, m_cIconList);
56 BEGIN_MESSAGE_MAP(CSetOverlayIcons, ISettingsPropPage)
57 ON_BN_CLICKED(IDC_LISTRADIO, OnBnClickedListradio)
58 ON_BN_CLICKED(IDC_SYMBOLRADIO, OnBnClickedSymbolradio)
59 ON_CBN_SELCHANGE(IDC_ICONSETCOMBO, OnCbnSelchangeIconsetcombo)
60 END_MESSAGE_MAP()
62 BOOL CSetOverlayIcons::OnInitDialog()
64 ISettingsPropPage::OnInitDialog();
66 AdjustControlSize(IDC_LISTRADIO);
67 AdjustControlSize(IDC_SYMBOLRADIO);
69 m_cIconList.SetExtendedStyle(LVS_EX_DOUBLEBUFFER | LVS_EX_INFOTIP | LVS_EX_SUBITEMIMAGES);
70 // get the path to our icon sets
71 TCHAR buf[MAX_PATH] = {0};
72 SHGetSpecialFolderPath(m_hWnd, buf, CSIDL_PROGRAM_FILES_COMMON, true);
73 m_sIconPath = buf;
74 m_sIconPath += L"\\TortoiseOverlays\\Icons";
75 // list all the icon sets
76 CDirFileEnum filefinder(m_sIconPath);
77 bool isDir = false;
78 CString item;
79 while (filefinder.NextFile(item, &isDir))
81 if (!isDir)
82 continue;
83 m_cIconSet.AddString(CPathUtils::GetFileNameFromPath(item));
85 CheckRadioButton(IDC_LISTRADIO, IDC_SYMBOLRADIO, IDC_LISTRADIO);
86 CString sModifiedIcon = m_regModified;
87 if (sModifiedIcon.IsEmpty())
89 // no custom icon set, use the default
90 sModifiedIcon = m_sIconPath + L"\\XPStyle\\ModifiedIcon.ico";
92 if (!CStringUtils::StartsWithI(sModifiedIcon, m_sIconPath))
94 // an icon set outside our own installation? We don't support that,
95 // so fall back to the default!
96 sModifiedIcon = m_sIconPath + L"\\XPStyle\\ModifiedIcon.ico";
98 // the name of the icon set is the folder of the icon location
99 m_sOriginalIconSet = sModifiedIcon.Mid(m_sIconPath.GetLength()+1);
100 m_sOriginalIconSet = m_sOriginalIconSet.Left(m_sOriginalIconSet.ReverseFind('\\'));
101 // now we have the name of the icon set. Set the combobox to show
102 // that as selected
103 CString ComboItem;
104 for (int i=0; i<m_cIconSet.GetCount(); ++i)
106 m_cIconSet.GetLBText(i, ComboItem);
107 if (ComboItem.CompareNoCase(m_sOriginalIconSet)==0)
108 m_cIconSet.SetCurSel(i);
111 m_sNormal.LoadString(IDS_STATUSNORMAL);
112 m_sModified.LoadString(IDS_STATUSMODIFIED);
113 m_sConflicted.LoadString(IDS_STATUSCONFLICTED);
114 m_sDeleted.LoadString(IDS_STATUSDELETED);
115 m_sAdded.LoadString(IDS_STATUSADDED);
116 m_sIgnored.LoadString(IDS_STATUSIGNORED);
117 m_sUnversioned.LoadString(IDS_STATUSUNVERSIONED);
119 m_sReadOnly.LoadString(IDS_SETTINGS_READONLYNAME);
120 m_sLocked.LoadString(IDS_SETTINGS_LOCKEDNAME);
122 SetWindowTheme(m_hWnd, L"Explorer", nullptr);
124 ShowIconSet(true);
126 return TRUE;
129 void CSetOverlayIcons::ShowIconSet(bool bSmallIcons)
131 m_cIconList.SetRedraw(FALSE);
132 m_cIconList.DeleteAllItems();
133 m_ImageList.DeleteImageList();
134 m_ImageListBig.DeleteImageList();
135 int smallIconWidth = GetSystemMetrics(SM_CXSMICON);
136 int smallIconHeight = GetSystemMetrics(SM_CYSMICON);
137 int normalIconWidth = GetSystemMetrics(SM_CXICON);
138 int normalIconHeight = GetSystemMetrics(SM_CYICON);
139 m_ImageList.Create(smallIconWidth, smallIconHeight, ILC_COLOR32 | ILC_MASK | ILC_HIGHQUALITYSCALE, 20, 10);
140 m_ImageListBig.Create(normalIconWidth, normalIconHeight, ILC_COLOR32 | ILC_MASK | ILC_HIGHQUALITYSCALE, 20, 10);
141 m_cIconList.SetImageList(&m_ImageList, LVSIL_SMALL);
142 m_cIconList.SetImageList(&m_ImageListBig, LVSIL_NORMAL);
144 // find all the icons of the selected icon set
145 CString sIconSet;
146 int index = m_cIconSet.GetCurSel();
147 if (index == CB_ERR)
149 // nothing selected. Shouldn't happen!
150 return;
152 m_cIconSet.GetLBText(index, sIconSet);
153 CString sIconSetPath = m_sIconPath + L'\\' + sIconSet;
155 CImageList * pImageList = bSmallIcons ? &m_ImageList : &m_ImageListBig;
156 int iconWidth = (bSmallIcons ? smallIconWidth : normalIconWidth);
157 int iconHeight = (bSmallIcons ? smallIconHeight : normalIconHeight);
158 CAutoIcon hNormalOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\NormalIcon.ico", iconWidth, iconHeight);
159 index = pImageList->Add(hNormalOverlay);
160 VERIFY(pImageList->SetOverlayImage(index, 1));
161 CAutoIcon hModifiedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\ModifiedIcon.ico", iconWidth, iconHeight);
162 index = pImageList->Add(hModifiedOverlay);
163 VERIFY(pImageList->SetOverlayImage(index, 2));
164 CAutoIcon hConflictedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\ConflictIcon.ico", iconWidth, iconHeight);
165 index = pImageList->Add(hConflictedOverlay);
166 VERIFY(pImageList->SetOverlayImage(index, 3));
167 CAutoIcon hReadOnlyOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\ReadOnlyIcon.ico", iconWidth, iconHeight);
168 index = pImageList->Add(hReadOnlyOverlay);
169 VERIFY(pImageList->SetOverlayImage(index, 4));
170 CAutoIcon hDeletedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\DeletedIcon.ico", iconWidth, iconHeight);
171 index = pImageList->Add(hDeletedOverlay);
172 VERIFY(pImageList->SetOverlayImage(index, 5));
173 CAutoIcon hLockedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\LockedIcon.ico", iconWidth, iconHeight);
174 index = pImageList->Add(hLockedOverlay);
175 VERIFY(pImageList->SetOverlayImage(index, 6));
176 CAutoIcon hAddedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\AddedIcon.ico", iconWidth, iconHeight);
177 index = pImageList->Add(hAddedOverlay);
178 VERIFY(pImageList->SetOverlayImage(index, 7));
179 CAutoIcon hIgnoredOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\IgnoredIcon.ico", iconWidth, iconHeight);
180 index = pImageList->Add(hIgnoredOverlay);
181 VERIFY(pImageList->SetOverlayImage(index, 8));
182 CAutoIcon hUnversionedOverlay = LoadIconEx(nullptr, sIconSetPath + L"\\UnversionedIcon.ico", iconWidth, iconHeight);
183 index = pImageList->Add(hUnversionedOverlay);
184 VERIFY(pImageList->SetOverlayImage(index, 9));
186 // create an image list with different file icons
187 SHFILEINFO sfi = { 0 };
189 UINT flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
190 if (bSmallIcons)
191 flags |= SHGFI_SMALLICON;
192 else
193 flags |= SHGFI_LARGEICON;
194 SHGetFileInfo(
195 L"Doesn't matter",
196 FILE_ATTRIBUTE_DIRECTORY,
197 &sfi, sizeof sfi,
198 flags);
200 int folderindex = pImageList->Add(sfi.hIcon); //folder
201 DestroyIcon(sfi.hIcon);
202 //folders
203 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sNormal, folderindex);
204 VERIFY(m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(1), TVIS_OVERLAYMASK));
205 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sModified, folderindex);
206 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(2), TVIS_OVERLAYMASK);
207 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sConflicted, folderindex);
208 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(3), TVIS_OVERLAYMASK);
209 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sReadOnly, folderindex);
210 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(4), TVIS_OVERLAYMASK);
211 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sDeleted, folderindex);
212 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(5), TVIS_OVERLAYMASK);
213 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sLocked, folderindex);
214 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(6), TVIS_OVERLAYMASK);
215 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sAdded, folderindex);
216 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(7), TVIS_OVERLAYMASK);
217 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sIgnored, folderindex);
218 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(8), TVIS_OVERLAYMASK);
219 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sUnversioned, folderindex);
220 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(9), TVIS_OVERLAYMASK);
222 AddFileTypeGroup(L".cpp", bSmallIcons);
223 AddFileTypeGroup(L".h", bSmallIcons);
224 AddFileTypeGroup(L".txt", bSmallIcons);
225 AddFileTypeGroup(L".java", bSmallIcons);
226 AddFileTypeGroup(L".doc", bSmallIcons);
227 AddFileTypeGroup(L".pl", bSmallIcons);
228 AddFileTypeGroup(L".php", bSmallIcons);
229 AddFileTypeGroup(L".asp", bSmallIcons);
230 AddFileTypeGroup(L".cs", bSmallIcons);
231 AddFileTypeGroup(L".vb", bSmallIcons);
232 AddFileTypeGroup(L".xml", bSmallIcons);
233 AddFileTypeGroup(L".pas", bSmallIcons);
234 AddFileTypeGroup(L".dpr", bSmallIcons);
235 AddFileTypeGroup(L".dfm", bSmallIcons);
236 AddFileTypeGroup(L".res", bSmallIcons);
237 AddFileTypeGroup(L".asmx", bSmallIcons);
238 AddFileTypeGroup(L".aspx", bSmallIcons);
239 AddFileTypeGroup(L".resx", bSmallIcons);
240 AddFileTypeGroup(L".vbp", bSmallIcons);
241 AddFileTypeGroup(L".frm", bSmallIcons);
242 AddFileTypeGroup(L".frx", bSmallIcons);
243 AddFileTypeGroup(L".bas", bSmallIcons);
244 AddFileTypeGroup(L".config", bSmallIcons);
245 AddFileTypeGroup(L".css", bSmallIcons);
246 AddFileTypeGroup(L".acsx", bSmallIcons);
247 AddFileTypeGroup(L".jpg", bSmallIcons);
248 AddFileTypeGroup(L".png", bSmallIcons);
249 m_cIconList.SetRedraw(TRUE);
251 void CSetOverlayIcons::AddFileTypeGroup(CString sFileType, bool bSmallIcons)
253 UINT flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
254 if (bSmallIcons)
255 flags |= SHGFI_SMALLICON;
256 else
257 flags |= SHGFI_LARGEICON;
258 SHFILEINFO sfi = { 0 };
260 SHGetFileInfo(
261 sFileType,
262 FILE_ATTRIBUTE_NORMAL,
263 &sfi, sizeof sfi,
264 flags);
266 int imageindex = 0;
267 if (bSmallIcons)
268 imageindex = m_ImageList.Add(sfi.hIcon);
269 else
270 imageindex = m_ImageListBig.Add(sfi.hIcon);
272 DestroyIcon(sfi.hIcon);
273 int index = 0;
274 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sNormal+sFileType, imageindex);
275 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(1), TVIS_OVERLAYMASK);
276 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sModified+sFileType, imageindex);
277 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(2), TVIS_OVERLAYMASK);
278 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sConflicted+sFileType, imageindex);
279 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(3), TVIS_OVERLAYMASK);
280 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sReadOnly+sFileType, imageindex);
281 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(4), TVIS_OVERLAYMASK);
282 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sDeleted+sFileType, imageindex);
283 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(5), TVIS_OVERLAYMASK);
284 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sLocked+sFileType, imageindex);
285 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(6), TVIS_OVERLAYMASK);
286 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sAdded+sFileType, imageindex);
287 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(7), TVIS_OVERLAYMASK);
288 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sIgnored+sFileType, imageindex);
289 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(8), TVIS_OVERLAYMASK);
290 index = m_cIconList.InsertItem(m_cIconList.GetItemCount(), m_sUnversioned+sFileType, imageindex);
291 m_cIconList.SetItemState(index, INDEXTOOVERLAYMASK(9), TVIS_OVERLAYMASK);
294 void CSetOverlayIcons::OnBnClickedListradio()
296 m_cIconList.ModifyStyle(LVS_TYPEMASK, LVS_LIST);
297 ShowIconSet(true);
300 void CSetOverlayIcons::OnBnClickedSymbolradio()
302 m_cIconList.ModifyStyle(LVS_TYPEMASK, LVS_ICON);
303 ShowIconSet(false);
306 void CSetOverlayIcons::OnCbnSelchangeIconsetcombo()
308 bool bSmallIcons = (GetCheckedRadioButton(IDC_LISTRADIO, IDC_SYMBOLRADIO) == IDC_LISTRADIO);
309 ShowIconSet(bSmallIcons);
310 m_selIndex = m_cIconSet.GetCurSel();
311 if (m_selIndex != CB_ERR)
312 m_cIconSet.GetLBText(m_selIndex, m_sIconSet);
313 if (m_sIconSet.CompareNoCase(m_sOriginalIconSet)!=0)
314 SetModified();
317 BOOL CSetOverlayIcons::OnApply()
319 UpdateData();
321 if ((!m_sIconSet.IsEmpty())&&(m_sIconSet.CompareNoCase(m_sOriginalIconSet)!=0))
323 // the selected icon set has changed.
324 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\NormalIcon.ico", m_regNormal);
325 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\ModifiedIcon.ico", m_regModified);
326 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\ConflictIcon.ico", m_regConflicted);
327 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\ReadOnlyIcon.ico", m_regReadOnly);
328 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\DeletedIcon.ico", m_regDeleted);
329 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\LockedIcon.ico", m_regLocked);
330 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\AddedIcon.ico", m_regAdded);
331 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\IgnoredIcon.ico", m_regIgnored);
332 Store(m_sIconPath + L'\\' + m_sIconSet + L"\\UnversionedIcon.ico", m_regUnversioned);
334 m_restart = Restart_System;
335 m_sOriginalIconSet = m_sIconSet;
337 SetModified(FALSE);
338 return ISettingsPropPage::OnApply();