Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.8, 0.8.1, and 0.8.2

shellext: show overlay icons on directories

Note: with this version, 'add' wins over 'modified' (original behaviour
as imported from CuteHg)

Changeset ad0ae5321a32

Parent 68d1b473e75a

by Adrian Buehlmann

Changes to one file · Browse files at ad0ae5321a32 Showing diff from parent 68d1b473e75a Diff from another changeset...

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
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
 #include "stdafx.h"  #include "ShellExt.h"  #include "TortoiseUtils.h"  #include "StringUtils.h"  #include "PipeUtils.h"  #include "dirstate.h"    #include <shlwapi.h>      STDMETHODIMP CShellExt::GetOverlayInfo(LPWSTR pwszIconFile, int cchMax,   int *pIndex, DWORD *pdwFlags)  {   *pIndex = 0;   *pdwFlags = ISIOI_ICONFILE;     // get installation path   std::string dir = GetTHgProgRoot();   if (dir.empty())   {   TDEBUG_TRACE("GetOverlayInfo: THG root is empty");   wcsncpy(pwszIconFile, L"", cchMax);   return S_OK;   }     // find icon per overlay type   std::wstring dirWide = MultibyteToWide(dir);   wcsncpy(pwszIconFile, dirWide.c_str(), cchMax);   cchMax -= static_cast<int>(dirWide.size()) + 1;  /*   switch (myTortoiseClass)   {   case TORTOISE_OLE_ADDED:   wcsncat(pwszIconFile, L"\\icons\\status\\added.ico", cchMax);   break;   case TORTOISE_OLE_MODIFIED:   wcsncat(pwszIconFile, L"\\icons\\status\\changed.ico", cchMax);   break;   case TORTOISE_OLE_UNCHANGED:   wcsncat(pwszIconFile, L"\\icons\\status\\unchanged.ico", cchMax);   break;   default:   break;   }  */   std::string path = WideToMultibyte(pwszIconFile);   TDEBUG_TRACE("GetOverlayInfo: icon path = " << path);     return S_OK;  }    STDMETHODIMP CShellExt::GetPriority(int *pPriority)  {   *pPriority = 1;   return S_OK;  }      STDMETHODIMP CShellExt::IsMemberOf(LPCWSTR pwszPath, DWORD /* dwAttrib */)  {   std::string mbstr = WideToMultibyte(pwszPath);     TDEBUG_TRACE("IsMemberOf: search for " << mbstr.c_str());     char path[MAX_PATH] = "";   strncat(path, mbstr.c_str(), MAX_PATH);     std::string hgroot = GetHgRepoRoot(path);     if (hgroot.empty())   {   TDEBUG_TRACE("IsMemberOf: Not a Hg repo (hgroot is empty)");   return S_FALSE;   }     TDEBUG_TRACE("IsMemberOf: hgroot = " << hgroot);   - if (PathIsDirectory(path)) - return S_FALSE; -   size_t offset = hgroot.length();   if (path[offset] == '\\')   offset++;   const char* relpathptr = path + offset;     char relpath[MAX_PATH] = "";   strncat(relpath, relpathptr, MAX_PATH);     char status = 0;   - if (!HgQueryDirstateFile(hgroot.c_str(), path, relpath, &status)) + if (PathIsDirectory(path))   { - TDEBUG_TRACE("IsMemberOf: HgQueryDirstateFile returns false"); - return S_FALSE; + if (!strlen(relpath)) + return S_FALSE; // don't show icon on repo root dir + + if (strncmp(relpath, ".hg", 3) == 0) + return S_FALSE; // don't descend into .hg dir + + if (!HgQueryDirstateDirectory(hgroot.c_str(), path, relpath, &status)) + { + TDEBUG_TRACE("IsMemberOf: HgQueryDirstateDirectory returns false"); + return S_FALSE; + } + } + else + { + if (!HgQueryDirstateFile(hgroot.c_str(), path, relpath, &status)) + { + TDEBUG_TRACE("IsMemberOf: HgQueryDirstateFile returns false"); + return S_FALSE; + }   }     TDEBUG_TRACE("IsMemberOf: status = " << status);     if (myTortoiseClass == TORTOISE_OLE_ADDED && status == 'A')   return S_OK;   else if (myTortoiseClass == TORTOISE_OLE_MODIFIED && status == 'M')   return S_OK;   else if (myTortoiseClass == TORTOISE_OLE_UNCHANGED && status == 'C')   return S_OK;     return S_FALSE;  }