| |
1 |
1 |
#include "stdafx.h" |
| |
2 |
2 |
#include "FilterTypesMenuWrapper.h" |
| |
3 |
3 |
#include "ch.h" |
| |
4 |
4 |
#include "resource.h" |
| |
5 |
5 |
#include "../libstring/TStringArray.h" |
| |
6 |
6 |
#include <regex> |
| |
|
7 |
#include "../libchcore/TCoreException.h" |
| |
7 |
8 |
|
| |
8 |
9 |
void FilterTypesMenuWrapper::Init() |
| |
9 |
10 |
{ |
| |
10 |
11 |
HMENU hMenu = GetResManager().LoadMenu(MAKEINTRESOURCE(IDR_FILTER_TYPE_MENU)); |
| |
11 |
12 |
m_menuFilterType.Attach(hMenu); |
| |
12 |
13 |
|
| |
13 |
14 |
CMenu* pPopup = m_menuFilterType.GetSubMenu(0); |
| |
14 |
15 |
for(int iIndex = 0; iIndex < pPopup->GetMenuItemCount(); ++iIndex) |
| |
15 |
16 |
{ |
| |
16 |
17 |
int iCmd = pPopup->GetMenuItemID(iIndex); |
| |
17 |
18 |
if(iCmd > 0) |
| |
18 |
19 |
{ |
| |
19 |
20 |
CString strText; |
| |
20 |
21 |
pPopup->GetMenuString(iIndex, strText, MF_BYPOSITION); |
| |
21 |
22 |
m_mapFilterEntries.insert({ iCmd, (PCTSTR)strText }); |
| |
22 |
23 |
} |
| |
23 |
24 |
} |
| |
24 |
25 |
} |
| |
25 |
26 |
|
| |
26 |
27 |
void FilterTypesMenuWrapper::StartTracking(bool bIncludeMask, CWnd& rParent, int iBtnID) |
|
| |
45 |
46 |
{ |
| |
46 |
47 |
CString strText; |
| |
47 |
48 |
rCombo.GetWindowText(strText); |
| |
48 |
49 |
|
| |
49 |
50 |
CString strParsed = arrStrings.GetAt(0).c_str(); |
| |
50 |
51 |
if(!strText.IsEmpty() && strText.Right(1) != L";" && strParsed != L";") |
| |
51 |
52 |
strText += L";"; |
| |
52 |
53 |
|
| |
53 |
54 |
rCombo.SetWindowText(strText + strParsed); |
| |
54 |
55 |
} |
| |
55 |
56 |
} |
| |
56 |
57 |
} |
| |
57 |
58 |
|
| |
58 |
59 |
bool FilterTypesMenuWrapper::ValidateFilter(const chcore::TStringPatternArray& arrPattern) |
| |
59 |
60 |
{ |
| |
60 |
61 |
CStringA strMsg; |
| |
61 |
62 |
try |
| |
62 |
63 |
{ |
| |
63 |
64 |
arrPattern.MatchesAny(chcore::PathFromString(L"")); |
| |
64 |
65 |
} |
| |
65 |
|
catch(const std::regex_error& e) |
| |
|
66 |
catch(const chcore::TCoreException& e) |
| |
66 |
67 |
{ |
| |
67 |
|
strMsg = e.what(); |
| |
|
68 |
const size_t BufferSize = 8192; |
| |
|
69 |
wchar_t szData[BufferSize] = {}; |
| |
|
70 |
|
| |
|
71 |
e.GetErrorInfo(szData, BufferSize); |
| |
|
72 |
strMsg = szData; |
| |
68 |
73 |
} |
| |
69 |
74 |
|
| |
70 |
75 |
if(!strMsg.IsEmpty()) |
| |
71 |
76 |
{ |
| |
72 |
77 |
CString strFmt; |
| |
73 |
78 |
strFmt.Format(L"%S", (PCSTR)strMsg); |
| |
74 |
79 |
|
| |
75 |
80 |
ictranslate::CFormat fmt(GetResManager().LoadString(IDS_INVALID_FILTER_STRING)); |
| |
76 |
81 |
fmt.SetParam(_T("%err"), strFmt); |
| |
77 |
82 |
AfxMessageBox(fmt.ToString()); |
| |
78 |
83 |
return false; |
| |
79 |
84 |
} |
| |
80 |
85 |
|
| |
81 |
86 |
return true; |
| |
82 |
87 |
} |