Fixed issue #4126: Capitalize the first letter in the Push dialog
[TortoiseGit.git] / src / TortoiseProc / GitStatusListCtrlHelpers.cpp
blob942233a1365cfc1e7b19c0c51a3948f6a6ae05e9
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2014 - TortoiseSVN
4 // Copyright (C) 2008-2017, 2019 - 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 8: // LFS Locks
48 if (result == 0)
49 result = entry1->m_LFSLockOwner.CompareNoCase(entry2->m_LFSLockOwner);
50 break;
52 case 7: // File size
54 if (result == 0)
56 __int64 fileSize1 = entry1->IsDirectory() ? 0 : entry1->GetFileSize();
57 __int64 fileSize2 = entry2->IsDirectory() ? 0 : entry2->GetFileSize();
59 result = SGN(fileSize1 - fileSize2);
61 break;
63 case 6: //Last Modification Date
65 if (result == 0)
67 __int64 writetime1 = entry1->GetLastWriteTime();
68 __int64 writetime2 = entry2->GetLastWriteTime();
70 result = SGN(writetime1 - writetime2);
72 break;
74 case 5: //Del Number
76 if (result == 0)
77 result = SGN(A2L(entry1->m_StatDel) - A2L(entry2->m_StatDel));
78 break;
80 case 4: //Add Number
82 if (result == 0)
83 result = SGN(A2L(entry1->m_StatAdd) - A2L(entry2->m_StatAdd));
84 break;
87 case 3: // Status
89 if (result == 0)
90 result = entry1->GetActionName(entry1->m_Action).CompareNoCase(entry2->GetActionName(entry2->m_Action));
91 break;
93 case 2: //Ext file
95 if (result == 0)
97 if (s_bSortLogical)
98 result = StrCmpLogicalW(entry1->GetFileExtension(), entry2->GetFileExtension());
99 else
100 result = StrCmpI(entry1->GetFileExtension(), entry2->GetFileExtension());
102 break;
104 case 1: // File name
106 if (result == 0)
108 if (s_bSortLogical)
109 result = StrCmpLogicalW(entry1->GetFileOrDirectoryName(), entry2->GetFileOrDirectoryName());
110 else
111 result = StrCmpI(entry1->GetFileOrDirectoryName(), entry2->GetFileOrDirectoryName());
113 break;
115 case 0: // Full path column
117 if (result == 0)
119 if (s_bSortLogical)
120 result = StrCmpLogicalW(entry1->GetGitPathString(), entry2->GetGitPathString());
121 else
122 result = StrCmpI(entry1->GetGitPathString(), entry2->GetGitPathString());
124 break;
126 } // switch (m_nSortedColumn)
127 // sort by path name as second priority
128 if (sortedColumn > 0 && result == 0)
130 if (s_bSortLogical)
131 result = StrCmpLogicalW(entry1->GetGitPathString(), entry2->GetGitPathString());
132 else
133 result = StrCmpI(entry1->GetGitPathString(), entry2->GetGitPathString());
135 if (!ascending)
136 result = -result;
138 return result < 0;