1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2010-2012, 2014 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "StringUtils.h"
23 class CSelectFileFilter
{
25 CSelectFileFilter(UINT stringId
);
26 CSelectFileFilter() {}
27 ~CSelectFileFilter() {}
29 operator const TCHAR
*() { return buffer
.get(); }
30 void Load(UINT stringId
);
31 UINT
GetCount() const { return (UINT
)filternames
.size(); }
32 operator const COMDLG_FILTERSPEC
*() { return filterspec
.get(); }
35 std::unique_ptr
<TCHAR
[]> buffer
;
36 std::unique_ptr
<COMDLG_FILTERSPEC
[]> filterspec
;
37 std::vector
<CString
> filternames
;
38 std::vector
<CString
> filtermasks
;
43 inline CSelectFileFilter::CSelectFileFilter(UINT stringId
)
48 inline void CSelectFileFilter::Load(UINT stringId
)
52 sFilter
.LoadString(stringId
);
53 const int bufferLength
= sFilter
.GetLength()+4;
54 buffer
.reset(new TCHAR
[bufferLength
]);
55 _tcscpy_s (buffer
.get(), bufferLength
, sFilter
);
56 CStringUtils::PipesToNulls(buffer
.get());
62 temp
= sFilter
.Tokenize(_T("|"), pos
);
67 filternames
.push_back(temp
);
68 temp
= sFilter
.Tokenize(_T("|"), pos
);
69 filtermasks
.push_back(temp
);
71 filterspec
.reset(new COMDLG_FILTERSPEC
[filternames
.size()]);
72 for (size_t i
= 0; i
< filternames
.size(); ++i
)
74 filterspec
[i
].pszName
= filternames
[i
];
75 filterspec
[i
].pszSpec
= filtermasks
[i
];
79 inline void CSelectFileFilter::ResetAll()
82 // First release the struct that references the vectors, then clear the vectors