Fix typo in doc
[TortoiseGit.git] / src / TortoiseProc / GitStatusListCtrlHelpers.cpp
blob5e6604c061835935e6e5765fbf7f20f65f6bfc9a
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2017 - TortoiseGit
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.
21 #include "stdafx.h"
22 #include "GitStatusListCtrl.h"
23 #include "TGitPath.h"
24 #include "ColumnManager.h"
26 // sorter utility class
27 CSorter::CSorter ( ColumnManager* columnManager
28 , int sortedColumn
29 , bool ascending)
30 : columnManager (columnManager)
31 , sortedColumn (sortedColumn)
32 , ascending (ascending)
34 s_bSortLogical = !CRegDWORD(L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_CURRENT_USER);
35 if (s_bSortLogical)
36 s_bSortLogical = !CRegDWORD(L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer\\NoStrCmpLogical", 0, false, HKEY_LOCAL_MACHINE);
39 bool CSorter::operator() (const CTGitPath* entry1 , const CTGitPath* entry2) const
41 #define SGN(x) ((x)==0?0:((x)>0?1:-1))
43 int result = 0;
44 switch (sortedColumn)
46 case 7: // File size
48 if (result == 0)
50 __int64 fileSize1 = entry1->IsDirectory() ? 0 : entry1->GetFileSize();
51 __int64 fileSize2 = entry2->IsDirectory() ? 0 : entry2->GetFileSize();
53 result = SGN(fileSize1 - fileSize2);
55 break;
57 case 6: //Last Modification Date
59 if (result == 0)
61 __int64 writetime1 = entry1->GetLastWriteTime();
62 __int64 writetime2 = entry2->GetLastWriteTime();
64 FILETIME* filetime1 = (FILETIME*)(__int64*)&writetime1;
65 FILETIME* filetime2 = (FILETIME*)(__int64*)&writetime2;
67 result = CompareFileTime(filetime1, filetime2);
69 break;
71 case 5: //Del Number
73 if (result == 0)
74 result = SGN(A2L(entry1->m_StatDel) - A2L(entry2->m_StatDel));
75 break;
77 case 4: //Add Number
79 if (result == 0)
80 result = SGN(A2L(entry1->m_StatAdd) - A2L(entry2->m_StatAdd));
81 break;
84 case 3: // Status
86 if (result == 0)
87 result = entry1->GetActionName(entry1->m_Action).CompareNoCase(entry2->GetActionName(entry2->m_Action));
88 break;
90 case 2: //Ext file
92 if (result == 0)
94 if (s_bSortLogical)
95 result = StrCmpLogicalW(entry1->GetFileExtension(), entry2->GetFileExtension());
96 else
97 result = StrCmpI(entry1->GetFileExtension(), entry2->GetFileExtension());
99 break;
101 case 1: // File name
103 if (result == 0)
105 if (s_bSortLogical)
106 result = StrCmpLogicalW(entry1->GetFileOrDirectoryName(), entry2->GetFileOrDirectoryName());
107 else
108 result = StrCmpI(entry1->GetFileOrDirectoryName(), entry2->GetFileOrDirectoryName());
110 break;
112 case 0: // Full path column
114 if (result == 0)
116 if (s_bSortLogical)
117 result = StrCmpLogicalW(entry1->GetGitPathString(), entry2->GetGitPathString());
118 else
119 result = StrCmpI(entry1->GetGitPathString(), entry2->GetGitPathString());
121 break;
123 } // switch (m_nSortedColumn)
124 // sort by path name as second priority
125 if (sortedColumn > 0 && result == 0)
127 if (s_bSortLogical)
128 result = StrCmpLogicalW(entry1->GetGitPathString(), entry2->GetGitPathString());
129 else
130 result = StrCmpI(entry1->GetGitPathString(), entry2->GetGitPathString());
132 if (!ascending)
133 result = -result;
135 return result < 0;