OSDN Git Service

Status List intergrate to LogDlg
[tortoisegit/TortoiseGitJp.git] / src / Git / GitStatusListCtrl.h
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "TGitPath.h"\r
21 #include "GitStatus.h"\r
22 #include "GitRev.h"\r
23 #include "GitConfig.h"\r
24 #include "Colors.h"\r
25 #include "XPTheme.h"\r
26 \r
27 #define SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN (-1)\r
28 \r
29 // these defines must be in the order the columns are inserted!\r
30 #define SVNSLC_COLFILENAME                      0x000000002\r
31 #define SVNSLC_COLEXT                           0x000000004\r
32 #define SVNSLC_COLSTATUS                        0x000000008\r
33 #define SVNSLC_COLTEXTSTATUS            0x000000010\r
34 #define SVNSLC_COLPROPSTATUS            0x000000020\r
35 #define SVNSLC_COLAUTHOR                        0x000000040\r
36 #define SVNSLC_COLREVISION                      0x000000080\r
37 #define SVNSLC_COLDATE                          0x000000100\r
38 #define SVNSLC_COLMODIFICATIONDATE      0x000000200\r
39 #define SVNSLC_COLADD                           0x000000400\r
40 #define SVNSLC_COLDEL                           0x000000600\r
41 #define SVNSLC_NUMCOLUMNS                       12\r
42 \r
43 //#define SVNSLC_COLREMOTESTATUS                0x000000010\r
44 //#define SVNSLC_COLREMOTETEXT          0x000000080\r
45 //#define SVNSLC_COLREMOTEPROP          0x000000100\r
46 //#define SVNSLC_COLURL                         0x000000200\r
47 //#define SVNSLC_COLLOCK                                0x000000400\r
48 //#define SVNSLC_COLLOCKCOMMENT         0x000000800\r
49 \r
50 //#define       SVNSLC_COLREMOTEREVISION        0x000004000\r
51 \r
52 //#define SVNSLC_COLSVNNEEDSLOCK                0x000010000\r
53 //#define SVNSLC_COLCOPYFROM                    0x000020000\r
54 \r
55 \r
56 #define SVNSLC_SHOWUNVERSIONED  0x000000001\r
57 #define SVNSLC_SHOWNORMAL               0x000000002\r
58 #define SVNSLC_SHOWMODIFIED             0x000000004\r
59 #define SVNSLC_SHOWADDED                0x000000008\r
60 #define SVNSLC_SHOWREMOVED              0x000000010\r
61 #define SVNSLC_SHOWCONFLICTED   0x000000020\r
62 #define SVNSLC_SHOWMISSING              0x000000040\r
63 #define SVNSLC_SHOWREPLACED             0x000000080\r
64 #define SVNSLC_SHOWMERGED               0x000000100\r
65 #define SVNSLC_SHOWIGNORED              0x000000200\r
66 #define SVNSLC_SHOWOBSTRUCTED   0x000000400\r
67 #define SVNSLC_SHOWEXTERNAL             0x000000800\r
68 #define SVNSLC_SHOWINCOMPLETE   0x000001000\r
69 #define SVNSLC_SHOWINEXTERNALS  0x000002000\r
70 #define SVNSLC_SHOWREMOVEDANDPRESENT 0x000004000\r
71 #define SVNSLC_SHOWLOCKS                0x000008000\r
72 #define SVNSLC_SHOWDIRECTFILES  0x000010000\r
73 #define SVNSLC_SHOWDIRECTFOLDER 0x000020000\r
74 #define SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO 0x000040000\r
75 #define SVNSLC_SHOWSWITCHED             0x000080000\r
76 #define SVNSLC_SHOWINCHANGELIST 0x000100000\r
77 \r
78 #define SVNSLC_SHOWDIRECTS              (SVNSLC_SHOWDIRECTFILES | SVNSLC_SHOWDIRECTFOLDER)\r
79 \r
80 \r
81 #define SVNSLC_SHOWVERSIONED (SVNSLC_SHOWNORMAL|SVNSLC_SHOWMODIFIED|\\r
82 SVNSLC_SHOWADDED|SVNSLC_SHOWREMOVED|SVNSLC_SHOWCONFLICTED|SVNSLC_SHOWMISSING|\\r
83 SVNSLC_SHOWREPLACED|SVNSLC_SHOWMERGED|SVNSLC_SHOWIGNORED|SVNSLC_SHOWOBSTRUCTED|\\r
84 SVNSLC_SHOWEXTERNAL|SVNSLC_SHOWINCOMPLETE|SVNSLC_SHOWINEXTERNALS|\\r
85 SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)\r
86 \r
87 #define SVNSLC_SHOWVERSIONEDBUTNORMAL (SVNSLC_SHOWMODIFIED|SVNSLC_SHOWADDED|\\r
88 SVNSLC_SHOWREMOVED|SVNSLC_SHOWCONFLICTED|SVNSLC_SHOWMISSING|\\r
89 SVNSLC_SHOWREPLACED|SVNSLC_SHOWMERGED|SVNSLC_SHOWIGNORED|SVNSLC_SHOWOBSTRUCTED|\\r
90 SVNSLC_SHOWEXTERNAL|SVNSLC_SHOWINCOMPLETE|SVNSLC_SHOWINEXTERNALS|\\r
91 SVNSLC_SHOWEXTERNALFROMDIFFERENTREPO)\r
92 \r
93 #define SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALSFROMDIFFERENTREPOS (SVNSLC_SHOWMODIFIED|\\r
94 SVNSLC_SHOWADDED|SVNSLC_SHOWREMOVED|SVNSLC_SHOWCONFLICTED|SVNSLC_SHOWMISSING|\\r
95 SVNSLC_SHOWREPLACED|SVNSLC_SHOWMERGED|SVNSLC_SHOWIGNORED|SVNSLC_SHOWOBSTRUCTED|\\r
96 SVNSLC_SHOWINCOMPLETE|SVNSLC_SHOWEXTERNAL|SVNSLC_SHOWINEXTERNALS)\r
97 \r
98 #define SVNSLC_SHOWVERSIONEDBUTNORMALANDEXTERNALS (SVNSLC_SHOWMODIFIED|\\r
99         SVNSLC_SHOWADDED|SVNSLC_SHOWREMOVED|SVNSLC_SHOWCONFLICTED|SVNSLC_SHOWMISSING|\\r
100         SVNSLC_SHOWREPLACED|SVNSLC_SHOWMERGED|SVNSLC_SHOWIGNORED|SVNSLC_SHOWOBSTRUCTED|\\r
101         SVNSLC_SHOWINCOMPLETE)\r
102 \r
103 #define SVNSLC_SHOWALL (SVNSLC_SHOWVERSIONED|SVNSLC_SHOWUNVERSIONED)\r
104 \r
105 #define SVNSLC_POPALL                                   0xFFFFFFFF\r
106 #define SVNSLC_POPCOMPAREWITHBASE               0x00000001\r
107 #define SVNSLC_POPCOMPARE                               0x00000002\r
108 #define SVNSLC_POPGNUDIFF                               0x00000004\r
109 #define SVNSLC_POPREVERT                                0x00000008\r
110 #define SVNSLC_POPUPDATE                                0x00000010\r
111 #define SVNSLC_POPSHOWLOG                               0x00000020\r
112 #define SVNSLC_POPOPEN                                  0x00000040\r
113 #define SVNSLC_POPDELETE                                0x00000080\r
114 #define SVNSLC_POPADD                                   0x00000100\r
115 #define SVNSLC_POPIGNORE                                0x00000200\r
116 #define SVNSLC_POPCONFLICT                              0x00000400\r
117 #define SVNSLC_POPRESOLVE                               0x00000800\r
118 #define SVNSLC_POPLOCK                                  0x00001000\r
119 #define SVNSLC_POPUNLOCK                                0x00002000\r
120 #define SVNSLC_POPUNLOCKFORCE                   0x00004000\r
121 #define SVNSLC_POPEXPLORE                               0x00008000\r
122 #define SVNSLC_POPCOMMIT                                0x00010000\r
123 #define SVNSLC_POPPROPERTIES                    0x00020000\r
124 #define SVNSLC_POPREPAIRMOVE                    0x00040000\r
125 #define SVNSLC_POPCHANGELISTS                   0x00080000\r
126 #define SVNSLC_POPBLAME                                 0x00100000\r
127 \r
128 #define SVNSLC_IGNORECHANGELIST                 _T("ignore-on-commit")\r
129 \r
130 // This gives up to 64 standard properties and menu entries\r
131 // plus 192 user-defined properties (should be plenty).\r
132 // User-defined properties will start at column SVNSLC_NUMCOLUMNS+1\r
133 // but in the registry, we will record them starting at SVNSLC_USERPROPCOLOFFSET.\r
134 \r
135 #define SVNSLC_USERPROPCOLOFFSET        0x40\r
136 #define SVNSLC_USERPROPCOLLIMIT         0xff\r
137 #define SVNSLC_MAXCOLUMNCOUNT           0xff\r
138 \r
139 // Supporting extreamly long user props makes no sense here --\r
140 // especially for binary properties. CString uses a pool allocator\r
141 // that works for up to 256 chars. Make sure we are well below that.\r
142 \r
143 #define SVNSLC_MAXUSERPROPLENGTH        0x70\r
144 \r
145 typedef int (__cdecl *GENERICCOMPAREFN)(const void * elem1, const void * elem2);\r
146 typedef CComCritSecLock<CComCriticalSection> Locker;\r
147 \r
148 /**\r
149  * \ingroup SVN\r
150  * A List control, based on the MFC CListCtrl which shows a list of\r
151  * files with their Subversion status. The control also provides a context\r
152  * menu to do some Subversion tasks on the selected files.\r
153  *\r
154  * This is the main control used in many dialogs to show a list of files to\r
155  * work on.\r
156  */\r
157 class CGitStatusListCtrl :\r
158         public CListCtrl\r
159 {\r
160 public:\r
161         int GetColumnIndex(int colmask);\r
162         /**\r
163          * Sent to the parent window (using ::SendMessage) after a context menu\r
164          * command has finished if the item count has changed.\r
165          */\r
166         static const UINT SVNSLNM_ITEMCOUNTCHANGED;\r
167         /**\r
168          * Sent to the parent window (using ::SendMessage) when the control needs\r
169          * to be refreshed. Since this is done usually in the parent window using\r
170          * a thread, this message is used to tell the parent to do exactly that.\r
171          */\r
172         static const UINT SVNSLNM_NEEDSREFRESH;\r
173 \r
174         /**\r
175          * Sent to the parent window (using ::SendMessage) when the user drops\r
176          * files on the control. The LPARAM is a pointer to a TCHAR string\r
177          * containing the dropped path.\r
178          */\r
179         static const UINT SVNSLNM_ADDFILE;\r
180 \r
181         /**\r
182          * Sent to the parent window (using ::SendMessage) when the user checks/unchecks\r
183          * one or more items in the control. The WPARAM contains the number of\r
184          * checked items in the control.\r
185          */\r
186         static const UINT SVNSLNM_CHECKCHANGED;\r
187 \r
188         CGitStatusListCtrl(void);\r
189         ~CGitStatusListCtrl(void);\r
190 \r
191         /**\r
192          * \ingroup TortoiseProc\r
193          * Helper class for CGitStatusListCtrl which represents\r
194          * the data for each file shown.\r
195          */\r
196 \r
197         class FileEntry\r
198         {\r
199         public:\r
200                 FileEntry() : status(git_wc_status_unversioned)\r
201 //                      , copyfrom_rev(GIT_REV_ZERO)\r
202                         , last_commit_date(0)\r
203                         , last_commit_rev(GIT_REV_ZERO)\r
204 //                      , remoterev(GIT_REV_ZERO)\r
205                         , textstatus(git_wc_status_unversioned)\r
206                         , propstatus(git_wc_status_unversioned)\r
207 //                      , remotestatus(git_wc_status_unversioned)\r
208 //                      , remotetextstatus(git_wc_status_unversioned)\r
209 //                      , remotepropstatus(git_wc_status_unversioned)\r
210                         , copied(false)\r
211                         , switched(false)\r
212                         , checked(false)\r
213                         , inunversionedfolder(false)\r
214                         , inexternal(false)\r
215                         , differentrepo(false)\r
216                         , direct(false)\r
217                         , isfolder(false)\r
218                         , isNested(false)\r
219                         , Revision(GIT_REV_ZERO)\r
220                         , isConflicted(false)\r
221 //                      , present_props()\r
222                         , needslock(false)\r
223 ///                     , working_size(SVN_WC_ENTRY_WORKING_SIZE_UNKNOWN)\r
224                         , keeplocal(false)\r
225 //                      , depth(git_depth_unknown)\r
226                 {\r
227                 }\r
228                 const CTGitPath& GetPath() const\r
229                 {\r
230                         return path;\r
231                 }\r
232                 const bool IsChecked() const\r
233                 {\r
234                         return checked;\r
235                 }\r
236                 CString GetRelativeGitPath() const\r
237                 {\r
238                         if (path.IsEquivalentTo(basepath))\r
239                                 return path.GetGitPathString();\r
240                         return path.GetGitPathString().Mid(basepath.GetGitPathString().GetLength()+1);\r
241                 }\r
242 //              const bool IsLocked() const\r
243 //              {\r
244 //                      return !(lock_token.IsEmpty() && lock_remotetoken.IsEmpty());\r
245 //              }\r
246 //              const bool HasNeedsLock() const\r
247 //              {\r
248 //                      return needslock;\r
249 //              }\r
250                 const bool IsFolder() const\r
251                 {\r
252                         return isfolder;\r
253                 }\r
254                 const bool IsInExternal() const\r
255                 {\r
256                         return inexternal;\r
257                 }\r
258                 const bool IsNested() const\r
259                 {\r
260                         return isNested;\r
261                 }\r
262                 const bool IsFromDifferentRepository() const\r
263                 {\r
264                         return differentrepo;\r
265                 }\r
266                 CString GetDisplayName() const\r
267                 {\r
268                         CString const& chopped = path.GetDisplayString(&basepath);\r
269                         if (!chopped.IsEmpty())\r
270                         {\r
271                                 return chopped;\r
272                         }\r
273                         else\r
274                         {\r
275                                 // "Display name" must not be empty.\r
276                                 return path.GetFileOrDirectoryName();\r
277                         }\r
278                 }\r
279                 CString GetChangeList() const\r
280                 {\r
281                         return changelist;\r
282                 }\r
283 //              CString GetURL() const\r
284 //              {\r
285 //                      return url;\r
286 //              }\r
287         public:\r
288                 git_wc_status_kind              status;                                 ///< local status\r
289                 git_wc_status_kind              textstatus;                             ///< local text status\r
290                 git_wc_status_kind              propstatus;                             ///< local property status\r
291                 \r
292         private:\r
293                 CTGitPath                               path;                                   ///< full path of the file\r
294                 CTGitPath                               basepath;                               ///< common ancestor path of all files\r
295                 \r
296                 CString                                 changelist;                             ///< the name of the changelist the item belongs to\r
297                 \r
298                 CString                                 last_commit_author;             ///< the author which last committed this item\r
299                 CTime                                   last_commit_date;               ///< the date when this item was last committed\r
300                 git_revnum_t                    last_commit_rev;                ///< the revision where this item was last committed\r
301                 \r
302                 git_revnum_t                    remoterev;                              ///< the revision in HEAD of the repository\r
303                 bool                                    copied;                                 ///< if the file/folder is added-with-history\r
304                 bool                                    switched;                               ///< if the file/folder is switched to another url\r
305                 bool                                    checked;                                ///< if the file is checked in the list control\r
306                 bool                                    inunversionedfolder;    ///< if the file is inside an unversioned folder\r
307                 bool                                    inexternal;                             ///< if the item is in an external folder\r
308                 bool                                    differentrepo;                  ///< if the item is from a different repository than the rest\r
309                 bool                                    direct;                                 ///< directly included (TRUE) or just a child of a folder\r
310                 bool                                    isfolder;                               ///< TRUE if entry refers to a folder\r
311                 bool                                    isNested;                               ///< TRUE if the folder from a different repository and/or path\r
312                 bool                                    isConflicted;                   ///< TRUE if a file entry is conflicted, i.e. if it has the conflicted paths set\r
313                 bool                                    needslock;                              ///< TRUE if the Git:needs-lock property is set\r
314                 git_revnum_t                    Revision;                               ///< the base revision\r
315 //              PropertyList                    present_props;                  ///< cacheable properties present in BASE\r
316                 bool                                    keeplocal;                              ///< Whether a local copy of this entry should be kept in the working copy after a deletion has been committed\r
317                 git_depth_t                             depth;                                  ///< the depth of this entry\r
318                 friend class CGitStatusListCtrl;\r
319                 friend class CGitStatusListCtrlDropTarget;\r
320         friend class CSorter;\r
321         };\r
322         /**\r
323          * \ingroup TortoiseProc\r
324          * Helper class for CGitStatusListCtrl that represents\r
325          * the columns visible and their order as well as \r
326      * persisting that data in the registry.\r
327      *\r
328      * It assigns logical index values to the (potential) columns:\r
329      * 0 .. GitSLC_NUMCOLUMNS-1 contain the standard attributes\r
330      * GitSLC_USERPROPCOLOFFSET .. GitSLC_MAXCOLUMNCOUNT are user props.\r
331      *\r
332      * The column vector contains the columns that are actually\r
333      * available in the control.\r
334      *\r
335      * Since the set of userprops may change from one WC to another,\r
336      * we also store the settings (width and order) for those\r
337      * userprops that are not used in this WC.\r
338      *\r
339      * A userprop is considered "in use", if the respective column\r
340      * is not hidden or if at least one item has this property set.\r
341          */\r
342         class ColumnManager\r
343         {\r
344     public:\r
345 \r
346         /// construction / destruction\r
347 \r
348         ColumnManager (CListCtrl* control) : control (control) {};\r
349         ~ColumnManager() {};\r
350 \r
351         /// registry access\r
352 \r
353         void ReadSettings (DWORD defaultColumns, const CString& containerName);\r
354         void WriteSettings() const;\r
355 \r
356         /// read column definitions\r
357 \r
358         int GetColumnCount() const;                     ///< total number of columns\r
359         bool IsVisible (int column) const;\r
360                 int GetInvisibleCount() const;\r
361         bool IsRelevant (int column) const;\r
362         bool IsUserProp (int column) const;\r
363         CString GetName (int column) const;\r
364         int GetWidth (int column, bool useDefaults = false) const;\r
365         int GetVisibleWidth (int column, bool useDefaults) const;\r
366 \r
367         /// switch columns on and off\r
368 \r
369         void SetVisible (int column, bool visible);\r
370 \r
371         /// tracking column modifications\r
372 \r
373         void ColumnMoved (int column, int position);\r
374         void ColumnResized (int column);\r
375 \r
376         /// call these to update the user-prop list\r
377         /// (will also auto-insert /-remove new list columns)\r
378 \r
379         void UpdateUserPropList (const std::vector<FileEntry*>& files);\r
380         void UpdateRelevance ( const std::vector<FileEntry*>& files\r
381                              , const std::vector<size_t>& visibleFiles);\r
382 \r
383         /// don't clutter the context menu with irrelevant prop info\r
384 \r
385         bool AnyUnusedProperties() const;\r
386         void RemoveUnusedProps();\r
387 \r
388         /// bring everything back to its "natural" order\r
389 \r
390         void ResetColumns (DWORD defaultColumns);\r
391 \r
392     private:\r
393 \r
394         /// initialization utilities\r
395 \r
396         void ParseUserPropSettings ( const CString& userPropList\r
397                                    , const CString& shownUserProps);\r
398         void ParseWidths (const CString& widths);\r
399         void SetStandardColumnVisibility (DWORD visibility);\r
400         void ParseColumnOrder (const CString& widths);\r
401         \r
402         /// map internal column order onto visible column order\r
403         /// (all invisibles in front)\r
404 \r
405         std::vector<int> GetGridColumnOrder();\r
406         void ApplyColumnOrder();\r
407 \r
408         /// utilities used when writing data to the registry\r
409 \r
410         DWORD GetSelectedStandardColumns() const;\r
411         CString GetUserPropList() const;\r
412         CString GetShownUserProps() const;\r
413         CString GetWidthString() const;\r
414         CString GetColumnOrderString() const;\r
415 \r
416         /// our parent control and its data\r
417 \r
418         CListCtrl* control;\r
419 \r
420         /// where to store in the registry\r
421 \r
422         CString registryPrefix;\r
423 \r
424         /// all columns in their "natural" order\r
425 \r
426         struct ColumnInfo\r
427         {\r
428             int index;          ///< is a user prop when < GitSLC_USERPROPCOLOFFSET\r
429             int width;\r
430             bool visible;\r
431             bool relevant;      ///< set to @a visible, if no *shown* item has that property\r
432         };\r
433 \r
434         std::vector<ColumnInfo> columns;\r
435 \r
436         /// user-defined properties\r
437 \r
438         struct UserProp\r
439         {\r
440             CString name;       ///< is a user prop when < GitSLC_USERPROPCOLOFFSET\r
441             int width;\r
442         };\r
443 \r
444         std::vector<UserProp> userProps;\r
445 \r
446         /// stored result from last UpdateUserPropList() call\r
447 \r
448         std::set<CString> itemProps;\r
449 \r
450         /// global column ordering including unused user props\r
451 \r
452         std::vector<int> columnOrder;\r
453 \r
454     };/**\r
455          * \ingroup TortoiseProc\r
456          * Simple utility class that defines the sort column order.\r
457          */\r
458     class CSorter\r
459     {\r
460     public:\r
461 \r
462         CSorter ( ColumnManager* columnManager\r
463                 , int sortedColumn\r
464                 , bool ascending);\r
465 \r
466         bool operator() ( const CTGitPath* entry1\r
467                         , const CTGitPath* entry2) const;\r
468 \r
469     private:\r
470 \r
471         ColumnManager* columnManager;\r
472         int sortedColumn;\r
473         bool ascending;\r
474     };\r
475 \r
476         /**\r
477          * Initializes the control, sets up the columns.\r
478          * \param dwColumns mask of columns to show. Use the GitSLC_COLxxx defines.\r
479          * \param sColumnInfoContainer Name of a registry key\r
480          *                             where the position and visibility of each column\r
481          *                             is saved and used from. If the registry key\r
482          *                             doesn't exist, the default order is used\r
483          *                             and dwColumns tells which columns are visible.\r
484          * \param dwContextMenus mask of context menus to be active, not all make sense for every use of this control.\r
485          *                       Use the GitSLC_POPxxx defines.\r
486          * \param bHasCheckboxes TRUE if the control should show check boxes on the left of each file entry.\r
487          */\r
488         void Init(DWORD dwColumns, const CString& sColumnInfoContainer, DWORD dwContextMenus = (SVNSLC_POPALL ^ SVNSLC_POPCOMMIT), bool bHasCheckboxes = true);\r
489         /**\r
490          * Sets a background image for the list control.\r
491          * The image is shown in the right bottom corner.\r
492          * \param nID the resource ID of the bitmap to use as the background\r
493          */\r
494         bool SetBackgroundImage(UINT nID);\r
495         /**\r
496          * Makes the 'ignore' context menu only ignore the files and not add the\r
497          * folder which gets the Git:ignore property changed to the list.\r
498          * This is needed e.g. for the Add-dialog, where the modified folder\r
499          * showing up would break the resulting "add" command.\r
500          */\r
501         void SetIgnoreRemoveOnly(bool bRemoveOnly = true) {m_bIgnoreRemoveOnly = bRemoveOnly;}\r
502         /**\r
503          * The unversioned items are by default shown after all other files in the list.\r
504          * If that behavior should be changed, set this value to false.\r
505          */\r
506         void PutUnversionedLast(bool bLast) {m_bUnversionedLast = bLast;}\r
507         /**\r
508          * Fetches the Subversion status of all files and stores the information\r
509          * about them in an internal array.\r
510          * \param sFilePath path to a file which contains a list of files and/or folders for which to\r
511          *                  fetch the status, separated by newlines.\r
512          * \param bUpdate TRUE if the remote status is requested too.\r
513          * \return TRUE on success.\r
514          */\r
515         BOOL GetStatus ( const CTGitPathList& pathList\r
516                    , bool bUpdate = false\r
517                    , bool bShowIgnores = false\r
518                                    , bool bShowUnRev=false\r
519                    , bool bShowUserProps = false);\r
520 \r
521         /**\r
522          * Populates the list control with the previously (with GetStatus) gathered status information.\r
523          * \param dwShow mask of file types to show. Use the GitSLC_SHOWxxx defines.\r
524          * \param dwCheck mask of file types to check. Use GitLC_SHOWxxx defines. Default (0) means 'use the entry's stored check status'\r
525          */\r
526         void Show(DWORD dwShow, DWORD dwCheck = 0, bool bShowFolders = true);\r
527         void Show(DWORD dwShow, const CTGitPathList& checkedList, bool bShowFolders = true);\r
528 \r
529         /**\r
530          * Copies the selected entries in the control to the clipboard. The entries\r
531          * are separated by newlines.\r
532          * \param dwCols the columns to copy. Each column is separated by a tab.\r
533          */\r
534         bool CopySelectedEntriesToClipboard(DWORD dwCols);\r
535 \r
536         /**\r
537          * If during the call to GetStatus() some Git:externals are found from different\r
538          * repositories than the first one checked, then this method returns TRUE.\r
539          */\r
540         BOOL HasExternalsFromDifferentRepos() const {return m_bHasExternalsFromDifferentRepos;}\r
541 \r
542         /**\r
543          * If during the call to GetStatus() some Git:externals are found then this method returns TRUE.\r
544          */\r
545         BOOL HasExternals() const {return m_bHasExternals;}\r
546 \r
547         /**\r
548          * If unversioned files are found (but not necessarily shown) TRUE is returned.\r
549          */\r
550         BOOL HasUnversionedItems() {return m_bHasUnversionedItems;}\r
551 \r
552         /**\r
553          * If there are any locks in the working copy, TRUE is returned\r
554          */\r
555         BOOL HasLocks() const {return m_bHasLocks;}\r
556 \r
557         /**\r
558          * If there are any change lists defined in the working copy, TRUE is returned\r
559          */\r
560         BOOL HasChangeLists() const {return m_bHasChangeLists;}\r
561 \r
562         /**\r
563          * Returns the file entry data for the list control index.\r
564          */\r
565         CGitStatusListCtrl::FileEntry * GetListEntry(UINT_PTR index);\r
566 \r
567         /**\r
568          * Returns the file entry data for the specified path.\r
569          * \note The entry might not be shown in the list control.\r
570          */\r
571         CGitStatusListCtrl::FileEntry * GetListEntry(const CTGitPath& path);\r
572 \r
573         /**\r
574          * Returns the index of the list control entry with the specified path,\r
575          * or -1 if the path is not in the list control.\r
576          */\r
577         int GetIndex(const CTGitPath& path);\r
578 \r
579         /**\r
580          * Returns the file entry data for the specified path in the list control.\r
581          */\r
582         CGitStatusListCtrl::FileEntry * GetVisibleListEntry(const CTGitPath& path);\r
583 \r
584         /**\r
585          * Returns a String containing some statistics like number of modified, normal, deleted,...\r
586          * files.\r
587          */\r
588         CString GetStatisticsString();\r
589 \r
590         /**\r
591          * Set a static control which will be updated automatically with\r
592          * the number of selected and total files shown in the list control.\r
593          */\r
594         void SetStatLabel(CWnd * pStatLabel){m_pStatLabel = pStatLabel;};\r
595 \r
596         /**\r
597          * Set a tri-state checkbox which is updated automatically if the\r
598          * user checks/unchecks file entries in the list control to indicate\r
599          * if all files are checked, none are checked or some are checked.\r
600          */\r
601         void SetSelectButton(CButton * pButton) {m_pSelectButton = pButton;}\r
602 \r
603         /**\r
604          * Set a button which is de-/activated automatically. The button is\r
605          * only set active if at least one item is selected.\r
606          */\r
607         void SetConfirmButton(CButton * pButton) {m_pConfirmButton = pButton;}\r
608 \r
609         /**\r
610          * Select/unselect all entries in the list control.\r
611          * \param bSelect TRUE to check, FALSE to uncheck.\r
612          */\r
613         void SelectAll(bool bSelect, bool bIncludeNoCommits = false);\r
614 \r
615         /** Set a checkbox on an entry in the listbox\r
616          * Keeps the listctrl checked state and the FileEntry's checked flag in sync\r
617          */\r
618         void SetEntryCheck(CTGitPath* pEntry, int listboxIndex, bool bCheck);\r
619 \r
620         /** Write a list of the checked items' paths into a path list\r
621          */\r
622         void WriteCheckedNamesToPathList(CTGitPathList& pathList);\r
623 \r
624         /** fills in \a lMin and \a lMax with the lowest/highest revision of all\r
625          * files/folders in the working copy.\r
626          * \param bShownOnly if true, the min/max revisions are calculated only for shown items\r
627          * \param bCheckedOnly if true, the min/max revisions are calculated only for items \r
628          *                   which are checked.\r
629          * \remark Since an item can only be checked if it is visible/shown in the list control\r
630          *         bShownOnly is automatically set to true if bCheckedOnly is true\r
631          */\r
632         void GetMinMaxRevisions(git_revnum_t& rMin, git_revnum_t& rMax, bool bShownOnly, bool bCheckedOnly);\r
633 \r
634         /**\r
635          * Returns the parent directory of all entries in the control.\r
636          * if \a bStrict is set to false, then the paths passed to the control\r
637          * to fetch the status (in GetStatus()) are used if possible.\r
638          */\r
639         CTGitPath GetCommonDirectory(bool bStrict);\r
640 \r
641         /**\r
642          * Returns the parent url of all entries in the control.\r
643          * if \a bStrict is set to false, then the paths passed to the control\r
644          * to fetch the status (in GetStatus()) are used if possible.\r
645          */\r
646         CTGitPath GetCommonURL(bool bStrict);\r
647 \r
648         /**\r
649          * Sets a pointer to a boolean variable which is checked periodically\r
650          * during the status fetching. As soon as the variable changes to true,\r
651          * the operations stops.\r
652          */\r
653         void SetCancelBool(bool * pbCanceled) {m_pbCanceled = pbCanceled;}\r
654 \r
655         /**\r
656          * Sets the string shown in the control while the status is fetched.\r
657          * If not set, it defaults to "please wait..."\r
658          */\r
659         void SetBusyString(const CString& str) {m_sBusy = str;}\r
660         void SetBusyString(UINT id) {m_sBusy.LoadString(id);}\r
661 \r
662         /**\r
663          * Sets the string shown in the control if no items are shown. This\r
664          * can happen for example if there's nothing modified and the unversioned\r
665          * files aren't shown either, so there's nothing to commit.\r
666          * If not set, it defaults to "file list is empty".\r
667          */\r
668         void SetEmptyString(const CString& str) {m_sEmpty = str;}\r
669         void SetEmptyString(UINT id) {m_sEmpty.LoadString(id);}\r
670 \r
671         /**\r
672          * Determines if the control should recurse into unversioned folders\r
673          * when fetching the status. The default behavior is defined by the\r
674          * registry key HKCU\Software\TortoiseGit\UnversionedRecurse, which\r
675          * is read in the Init() method.\r
676          * If you want to change the behavior, call this method *after*\r
677          * calling Init().\r
678          */\r
679         void SetUnversionedRecurse(bool bUnversionedRecurse) {m_bUnversionedRecurse = bUnversionedRecurse;}\r
680 \r
681         /**\r
682          * Returns the number of selected items\r
683          */\r
684         LONG GetSelected(){return m_nSelected;};\r
685 \r
686         /**\r
687          * Enables dropping of files on the control.\r
688          */\r
689         bool EnableFileDrop();\r
690 \r
691         /**\r
692          * Checks if the path already exists in the list.\r
693          */\r
694         bool HasPath(const CTGitPath& path);\r
695         /**\r
696          * Checks if the path is shown/visible in the list control.\r
697          */\r
698         bool IsPathShown(const CTGitPath& path);\r
699         /**\r
700          * Forces the children to be checked when the parent folder is checked,\r
701          * and the parent folder to be unchecked if one of its children is unchecked.\r
702          */\r
703         void CheckChildrenWithParent(bool bCheck) {m_bCheckChildrenWithParent = bCheck;}\r
704 \r
705         /**\r
706          * Allows checking the items if change lists are present. If set to false,\r
707          * items are not checked if at least one changelist is available.\r
708          */\r
709         void CheckIfChangelistsArePresent(bool bCheck) {m_bCheckIfGroupsExist = bCheck;}\r
710         /**\r
711          * Returns the currently used show flags passed to the Show() method.\r
712          */\r
713         DWORD GetShowFlags() {return m_dwShow;}\r
714 public:\r
715         CString GetLastErrorMessage() {return m_sLastError;}\r
716 \r
717         void Block(BOOL block, BOOL blockUI) {m_bBlock = block; m_bBlockUI = blockUI;}\r
718 \r
719         LONG                                            m_nTargetCount;         ///< number of targets in the file passed to GetStatus()\r
720 \r
721         CString                                         m_sURL;                         ///< the URL of the target or "(multiple targets)"\r
722 \r
723         GitRev                                          m_HeadRev;                      ///< the HEAD revision of the repository if bUpdate was TRUE\r
724 \r
725         CString                                         m_sUUID;                        ///< the UUID of the associated repository\r
726 \r
727         DECLARE_MESSAGE_MAP()\r
728 \r
729 private:\r
730         void SaveColumnWidths(bool bSaveToRegistry = false);\r
731         void Sort();    ///< Sorts the control by columns\r
732         void AddEntry(FileEntry * entry, WORD langID, int listIndex);   ///< add an entry to the control\r
733         void RemoveListEntry(int index);        ///< removes an entry from the listcontrol and both arrays\r
734         bool BuildStatistics(); ///< build the statistics and correct the case of files/folders\r
735         void StartDiff(int fileindex);  ///< start the external diff program\r
736 \r
737     /// fetch all user properties for all items\r
738     void FetchUserProperties();\r
739 \r
740         /// Process one line of the command file supplied to GetStatus\r
741         bool FetchStatusForSingleTarget(GitConfig& config, GitStatus& status, const CTGitPath& target, \r
742                 bool bFetchStatusFromRepository, CStringA& strCurrentRepositoryUUID, CTGitPathList& arExtPaths, \r
743                 bool bAllDirect, git_depth_t depth = git_depth_infinity, bool bShowIgnores = false);\r
744 \r
745         /// Create 'status' data for each item in an unversioned folder\r
746         void AddUnversionedFolder(const CTGitPath& strFolderName, const CTGitPath& strBasePath, GitConfig * config);\r
747 \r
748         /// Read the all the other status items which result from a single GetFirstStatus call\r
749         void ReadRemainingItemsStatus(GitStatus& status, const CTGitPath& strBasePath, CStringA& strCurrentRepositoryUUID, CTGitPathList& arExtPaths, GitConfig * config, bool bAllDirect);\r
750 \r
751         /// Clear the status vector (contains custodial pointers)\r
752         void ClearStatusArray();\r
753 \r
754         /// Sort predicate function - Compare the paths of two entries without regard to case\r
755         static bool EntryPathCompareNoCase(const FileEntry* pEntry1, const FileEntry* pEntry2);\r
756 \r
757         /// Predicate used to build a list of only the versioned entries of the FileEntry array\r
758         static bool IsEntryVersioned(const FileEntry* pEntry1);\r
759 \r
760         /// Look up the relevant show flags for a particular Git status value\r
761         DWORD GetShowFlagsFromGitStatus(git_wc_status_kind status);\r
762 \r
763         /// Build a FileEntry item and add it to the FileEntry array\r
764         const FileEntry* AddNewFileEntry(\r
765                 const git_wc_status2_t* pGitStatus,  // The return from the Git GetStatus functions\r
766                 const CTGitPath& path,                          // The path of the item we're adding\r
767                 const CTGitPath& basePath,                      // The base directory for this status build\r
768                 bool bDirectItem,                                       // Was this item the first found by GetFirstFileStatus or by a subsequent GetNextFileStatus call\r
769                 bool bInExternal,                                       // Are we in an 'external' folder\r
770                 bool bEntryfromDifferentRepo            // if the entry is from a different repository\r
771                 );\r
772 \r
773         /// Adjust the checkbox-state on all descendants of a specific item\r
774         void SetCheckOnAllDescendentsOf(const FileEntry* parentEntry, bool bCheck);\r
775 \r
776         /// Build a path list of all the selected items in the list (NOTE - SELECTED, not CHECKED)\r
777         void FillListOfSelectedItemPaths(CTGitPathList& pathList, bool bNoIgnored = false);\r
778 \r
779         /// Enables/Disables group view and adds all groups to the list control.\r
780         /// If bForce is true, then group view is enabled and the 'null' group is added.\r
781         bool PrepareGroups(bool bForce = false);\r
782         /// Returns the group number to which the group header belongs\r
783         /// If the point is not over a group header, -1 is returned\r
784         int GetGroupFromPoint(POINT * ppt);\r
785         /// Returns the number of change lists the selection has\r
786         size_t GetNumberOfChangelistsInSelection();\r
787 \r
788         /// Puts the item to the corresponding group\r
789         bool SetItemGroup(int item, int groupindex);\r
790 \r
791         void CheckEntry(int index, int nListItems);\r
792         void UncheckEntry(int index, int nListItems);\r
793 \r
794         /// sends an GitSLNM_CHECKCHANGED notification to the parent\r
795         void NotifyCheck();\r
796 \r
797         int CellRectFromPoint(CPoint& point, RECT *cellrect, int *col) const;\r
798 \r
799         void OnContextMenuList(CWnd * pWnd, CPoint point);\r
800         void OnContextMenuGroup(CWnd * pWnd, CPoint point);\r
801         void OnContextMenuHeader(CWnd * pWnd, CPoint point);\r
802 \r
803         virtual void PreSubclassWindow();\r
804         virtual BOOL PreTranslateMessage(MSG* pMsg);\r
805         virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;\r
806         afx_msg void OnBeginDrag(NMHDR* pNMHDR, LRESULT* pResult);\r
807         afx_msg BOOL OnToolTipText(UINT id, NMHDR *pNMHDR, LRESULT *pResult);\r
808         afx_msg void OnHdnItemclick(NMHDR *pNMHDR, LRESULT *pResult);\r
809         afx_msg void OnLvnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);\r
810         afx_msg BOOL OnLvnItemchanged(NMHDR *pNMHDR, LRESULT *pResult);\r
811     afx_msg void OnColumnResized(NMHDR *pNMHDR, LRESULT *pResult);\r
812     afx_msg void OnColumnMoved(NMHDR *pNMHDR, LRESULT *pResult);\r
813     afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);\r
814 \r
815         void CreateChangeList(const CString& name);\r
816 \r
817         afx_msg void OnNMDblclk(NMHDR *pNMHDR, LRESULT *pResult);\r
818         afx_msg void OnLvnGetInfoTip(NMHDR *pNMHDR, LRESULT *pResult);\r
819         afx_msg void OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult);\r
820         afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);\r
821         afx_msg UINT OnGetDlgCode();\r
822         afx_msg void OnNMReturn(NMHDR *pNMHDR, LRESULT *pResult);\r
823         afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);\r
824         afx_msg void OnPaint();\r
825         afx_msg void OnHdnBegintrack(NMHDR *pNMHDR, LRESULT *pResult);\r
826         afx_msg void OnHdnItemchanging(NMHDR *pNMHDR, LRESULT *pResult);\r
827         afx_msg void OnDestroy();\r
828 \r
829 private:\r
830         bool *                                          m_pbCanceled;\r
831         bool                                        m_bAscending;               ///< sort direction\r
832         int                                             m_nSortedColumn;        ///< which column to sort\r
833         bool                                            m_bHasCheckboxes;\r
834         bool                                            m_bUnversionedLast;\r
835         bool                                            m_bHasExternalsFromDifferentRepos;\r
836         bool                                            m_bHasExternals;\r
837         BOOL                                            m_bHasUnversionedItems;\r
838         bool                                            m_bHasLocks;\r
839         bool                                            m_bHasChangeLists;\r
840         //typedef std::vector<FileEntry*> FileEntryVector;\r
841         //FileEntryVector                               m_arStatusArray;\r
842         std::vector<CTGitPath*>         m_arStatusArray;\r
843         std::vector<size_t>                     m_arListArray;\r
844         std::map<CString, int>      m_changelists;\r
845         bool                                            m_bHasIgnoreGroup;\r
846         //CTGitPathList                         m_ConflictFileList;\r
847         CTGitPathList                           m_StatusFileList;\r
848         CTGitPathList                           m_UnRevFileList;\r
849         CTGitPathList                           m_IgnoreFileList;\r
850         //CTGitPathList                         m_StatusUrlList;\r
851         CString                                         m_sLastError;\r
852 \r
853         LONG                                            m_nUnversioned;\r
854         LONG                                            m_nNormal;\r
855         LONG                                            m_nModified;\r
856         LONG                                            m_nAdded;\r
857         LONG                                            m_nDeleted;\r
858         LONG                                            m_nConflicted;\r
859         LONG                                            m_nTotal;\r
860         LONG                                            m_nSelected;\r
861 \r
862         DWORD                                           m_dwDefaultColumns;\r
863         DWORD                                           m_dwShow;\r
864         bool                                            m_bShowFolders;\r
865         bool                                            m_bShowIgnores;\r
866         bool                                            m_bUpdate;\r
867         DWORD                                           m_dwContextMenus;\r
868         BOOL                                            m_bBlock;\r
869         BOOL                                            m_bBlockUI;\r
870         bool                                            m_bBusy;\r
871         bool                                            m_bEmpty;\r
872         bool                                            m_bIgnoreRemoveOnly;\r
873         bool                                            m_bCheckIfGroupsExist;\r
874         bool                                            m_bFileDropsEnabled;\r
875         bool                                            m_bOwnDrag;\r
876 \r
877         int                                                     m_nIconFolder;\r
878 \r
879         CWnd *                                          m_pStatLabel;\r
880         CButton *                                       m_pSelectButton;\r
881         CButton *                                       m_pConfirmButton;\r
882         CColors                                         m_Colors;\r
883 \r
884         CString                                         m_sEmpty;\r
885         CString                                         m_sBusy;\r
886         CString                                         m_sNoPropValueText;\r
887 \r
888         bool                                            m_bUnversionedRecurse;\r
889 \r
890         bool                                            m_bCheckChildrenWithParent;\r
891         CGitStatusListCtrlDropTarget * m_pDropTarget;\r
892 \r
893     ColumnManager               m_ColumnManager;\r
894 \r
895         std::map<CString,bool>          m_mapFilenameToChecked; ///< Remember manually de-/selected items\r
896         CComCriticalSection                     m_critSec;\r
897 \r
898         friend class CGitStatusListCtrlDropTarget;\r
899 public:\r
900         enum\r
901         {\r
902                 FILELIST_MODIFY= 0x1,\r
903                 FILELIST_UNVER = 0x2,\r
904                 FILELIST_IGNORE =0x4\r
905         };\r
906 public:\r
907         int UpdateFileList(git_revnum_t hash,CTGitPathList *List=NULL);\r
908         int UpdateFileList(int mask, bool once=true,CTGitPathList *List=NULL);\r
909         int UpdateUnRevFileList(CTGitPathList *List=NULL);\r
910         int UpdateIgnoreFileList(CTGitPathList *List=NULL);\r
911         \r
912         int UpdateWithGitPathList(CTGitPathList &list);\r
913 \r
914         void AddEntry(CTGitPath* path, WORD langID, int ListIndex);\r
915         int m_FileLoaded;\r
916 \r
917 public:\r
918         CXPTheme        m_Theme;\r
919 };\r
920 \r
921 #if 0\r
922 class CGitStatusListCtrlDropTarget : public CIDropTarget\r
923 {\r
924 public:\r
925         CGitStatusListCtrlDropTarget(CGitStatusListCtrl * pGitStatusListCtrl):CIDropTarget(pGitStatusListCtrl->m_hWnd){m_pGitStatusListCtrl = pGitStatusListCtrl;}\r
926 \r
927         virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium, DWORD * /*pdwEffect*/, POINTL pt);\r
928         virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD __RPC_FAR *pdwEffect);\r
929 private:\r
930         CGitStatusListCtrl * m_pGitStatusListCtrl;\r
931 };\r
932 #endif