Sync translations with Transifex
[TortoiseGit.git] / src / Utils / SelectFileFilter.h
blob8f61a29ab910304c874a77dc319c804aaae80076
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.
19 #pragma once
21 #include "StringUtils.h"
23 class CSelectFileFilter {
24 public:
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(); }
34 private:
35 std::unique_ptr<TCHAR[]> buffer;
36 std::unique_ptr<COMDLG_FILTERSPEC[]> filterspec;
37 std::vector<CString> filternames;
38 std::vector<CString> filtermasks;
40 void ResetAll();
43 inline CSelectFileFilter::CSelectFileFilter(UINT stringId)
45 Load(stringId);
48 inline void CSelectFileFilter::Load(UINT stringId)
50 ResetAll();
51 CString sFilter;
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());
58 int pos = 0;
59 CString temp;
60 for (;;)
62 temp = sFilter.Tokenize(_T("|"), pos);
63 if (temp.IsEmpty())
65 break;
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()
81 buffer.reset();
82 // First release the struct that references the vectors, then clear the vectors
83 filterspec.reset();
84 filternames.clear();
85 filtermasks.clear();