2 * @file ctextmarkerdlg.cpp
\r
4 * @brief Implementation of Marker-dialog.
\r
8 #include "resource.h"
\r
9 #include "ctextmarkerdlg.h"
\r
10 #include "ccrystaltextmarkers.h"
\r
11 #include "DDXHelper.h"
\r
12 #include "../ccrystaltextview.h"
\r
13 #include <algorithm>
\r
16 #define new DEBUG_NEW
\r
19 /////////////////////////////////////////////////////////////////////////////
\r
20 // CTextMarkerDlg dialog
\r
23 CTextMarkerDlg::CTextMarkerDlg (CCrystalTextMarkers & markers, const CString& sText, DWORD dwFlags)
\r
24 : CDialog (CTextMarkerDlg::IDD, nullptr)
\r
25 , m_markers(markers)
\r
26 , m_nCurItemIndex(0)
\r
27 , m_tempMarkers(markers)
\r
28 , m_nBgColorIndex(0)
\r
29 , m_bMatchCase((dwFlags & FIND_MATCH_CASE) != 0)
\r
30 , m_bWholeWord((dwFlags & FIND_WHOLE_WORD) != 0)
\r
31 , m_bRegExp((dwFlags & FIND_REGEXP) != 0)
\r
32 , m_bMarkersEnabled(markers.GetEnabled())
\r
34 if (!sText.IsEmpty())
\r
36 m_tempMarkers.SetMarker(m_tempMarkers.MakeNewId(), sText, dwFlags,
\r
37 static_cast<COLORINDEX>(static_cast<int>(COLORINDEX_MARKERBKGND1) + (m_tempMarkers.GetMarkers().size() % 3)));
\r
41 void CTextMarkerDlg::
\r
42 DoDataExchange (CDataExchange * pDX)
\r
44 CDialog::DoDataExchange (pDX);
\r
45 //{{AFX_DATA_MAP(CTextMarkerDlg)
\r
46 DDX_Control(pDX, IDC_EDIT_MARKER_LIST, m_listMarkers);
\r
47 if (!pDX->m_bSaveAndValidate)
\r
48 UpdateDataListView(false);
\r
49 DDX_Control(pDX, IDC_EDIT_WHOLE_WORD, m_ctlWholeWord);
\r
50 DDX_Control(pDX, IDC_EDIT_MARKER_BGCOLORIDX, m_ctlBgColorIdx);
\r
51 DDX_Text(pDX, IDC_EDIT_FINDTEXT, m_sFindWhat);
\r
52 DDX_CBIndex(pDX, IDC_EDIT_MARKER_BGCOLORIDX, m_nBgColorIndex);
\r
53 DDX_Check(pDX, IDC_EDIT_MATCH_CASE, m_bMatchCase);
\r
54 DDX_Check(pDX, IDC_EDIT_REGEXP, m_bRegExp);
\r
55 DDX_Check(pDX, IDC_EDIT_WHOLE_WORD, m_bWholeWord);
\r
56 DDX_Check(pDX, IDC_EDIT_MARKERS_ENABLED, m_bMarkersEnabled);
\r
57 if (pDX->m_bSaveAndValidate)
\r
58 UpdateDataListView(true);
\r
60 m_ctlWholeWord.EnableWindow(m_bRegExp ? FALSE : TRUE);
\r
64 BEGIN_MESSAGE_MAP (CTextMarkerDlg, CDialog)
\r
65 //{{AFX_MSG_MAP(CTextMarkerDlg)
\r
66 ON_BN_CLICKED(IDC_EDIT_REGEXP, OnBnclickedEditRegExp)
\r
67 ON_BN_CLICKED(IDC_EDIT_MARKER_NEW, &CTextMarkerDlg::OnBnClickedEditMarkerNew)
\r
68 ON_BN_CLICKED(IDC_EDIT_MARKER_DELETE, &CTextMarkerDlg::OnBnClickedEditMarkerDelete)
\r
69 ON_BN_CLICKED(ID_APPLY_NOW, &CTextMarkerDlg::OnBnClickedApplyNow)
\r
70 ON_NOTIFY(LVN_ITEMCHANGED, IDC_EDIT_MARKER_LIST, &CTextMarkerDlg::OnItemchangedEditMarkerList)
\r
71 ON_CBN_EDITCHANGE(IDC_EDIT_FINDTEXT, &CTextMarkerDlg::OnEditchangeEditFindtext)
\r
72 ON_NOTIFY(LVN_ITEMCHANGING, IDC_EDIT_MARKER_LIST, &CTextMarkerDlg::OnItemchangingEditMarkerList)
\r
76 /////////////////////////////////////////////////////////////////////////////
\r
77 // CTextMarkerDlg message handlers
\r
79 BOOL CTextMarkerDlg::OnInitDialog ()
\r
81 LangTranslateDialog(m_hWnd);
\r
82 CDialog::OnInitDialog ();
\r
84 CString fmt{LoadResString(IDS_MARKER_COLOR_FMT).c_str()};
\r
85 for (int i = 0; i < 3; ++i)
\r
88 str.Format(fmt, i + 1);
\r
89 m_ctlBgColorIdx.InsertString(-1, str);
\r
92 m_listMarkers.SetExtendedStyle(LVS_EX_CHECKBOXES | LVS_EX_ONECLICKACTIVATE | LVS_EX_FULLROWSELECT);
\r
93 std::vector<CString> keys;
\r
94 for (const auto& marker : m_tempMarkers.GetMarkers())
\r
95 keys.push_back(marker.first);
\r
96 std::sort(keys.begin(), keys.end());
\r
98 for (const auto& key: keys)
\r
100 const auto& marker = m_tempMarkers.GetMarkers()[key];
\r
101 if (marker.bUserDefined)
\r
103 m_listMarkers.InsertItem(LVIF_TEXT | LVIF_PARAM,
\r
104 m_listMarkers.GetItemCount(),
\r
105 marker.sFindWhat, 0, 0, 0,
\r
106 reinterpret_cast<LPARAM>((const tchar_t *)(m_tempMarkers.GetMarkers().find(key)->first)));
\r
107 m_listMarkers.SetCheck(i, marker.bVisible);
\r
112 m_listMarkers.SetItemState(static_cast<int>(i - 1),
\r
113 LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
\r
119 int CTextMarkerDlg::GetSelectedItemIndex() const
\r
121 for (int i = 0; i < m_listMarkers.GetItemCount(); ++i)
\r
123 if ((m_listMarkers.GetItemState(i, LVIS_SELECTED) & LVIS_SELECTED) != 0)
\r
129 void CTextMarkerDlg::UpdateDataListView(bool bSaveAndValidate)
\r
131 if (!bSaveAndValidate)
\r
133 for (int i = 0; i < m_listMarkers.GetItemCount(); ++i)
\r
135 const tchar_t *pKey = reinterpret_cast<tchar_t *>(m_listMarkers.GetItemData(i));
\r
136 CCrystalTextMarkers::Marker& marker = m_tempMarkers.GetMarkers().at(pKey);
\r
137 if (m_listMarkers.GetItemState(i, LVIS_SELECTED))
\r
139 m_sFindWhat = marker.sFindWhat;
\r
140 m_nBgColorIndex = static_cast<int>(marker.nBgColorIndex) - COLORINDEX_MARKERBKGND1;
\r
141 if (m_nBgColorIndex < 0)
\r
142 m_nBgColorIndex = 0;
\r
143 m_bWholeWord = (marker.dwFlags & FIND_WHOLE_WORD) != 0;
\r
144 m_bMatchCase = (marker.dwFlags & FIND_MATCH_CASE) != 0;
\r
145 m_bRegExp = (marker.dwFlags & FIND_REGEXP) != 0;
\r
147 m_bWholeWord = false;
\r
153 for (int i = 0; i < m_listMarkers.GetItemCount(); ++i)
\r
155 const tchar_t *pKey = reinterpret_cast<tchar_t *>(m_listMarkers.GetItemData(i));
\r
156 CCrystalTextMarkers::Marker& marker = m_tempMarkers.GetMarkers().at(pKey);
\r
157 if (m_listMarkers.GetItemState(i, LVIS_SELECTED))
\r
159 marker.sFindWhat = m_sFindWhat;
\r
160 marker.nBgColorIndex = static_cast<COLORINDEX>(m_nBgColorIndex + COLORINDEX_MARKERBKGND1);
\r
161 marker.dwFlags = GetLastSearchFlags();
\r
167 DWORD CTextMarkerDlg::GetLastSearchFlags() const
\r
170 (m_bMatchCase ? FIND_MATCH_CASE : 0) |
\r
171 (m_bWholeWord ? FIND_WHOLE_WORD : 0) |
\r
172 (m_bRegExp ? FIND_REGEXP : 0);
\r
175 void CTextMarkerDlg::OnBnclickedEditRegExp()
\r
180 void CTextMarkerDlg::OnBnClickedEditMarkerNew()
\r
182 CString name = m_tempMarkers.MakeNewId();
\r
183 CString sFindWhat = LoadResString(IDS_MARKER_NEW_PATTERN).c_str();
\r
184 m_tempMarkers.SetMarker(name, sFindWhat, GetLastSearchFlags(),
\r
185 static_cast<COLORINDEX>(static_cast<int>(COLORINDEX_MARKERBKGND1) + (m_tempMarkers.GetMarkers().size() % 3)));
\r
186 int i = GetSelectedItemIndex();
\r
188 m_listMarkers.SetItemState(i, 0, LVIS_SELECTED);
\r
189 m_listMarkers.InsertItem(LVIF_TEXT | LVIF_STATE | LVIF_PARAM,
\r
190 m_listMarkers.GetItemCount(), sFindWhat, LVIS_SELECTED, LVIS_SELECTED, 0,
\r
191 reinterpret_cast<LPARAM>((const tchar_t *)(m_tempMarkers.GetMarkers().find(name)->first)));
\r
192 m_listMarkers.SetCheck(m_listMarkers.GetItemCount() - 1, 1);
\r
195 void CTextMarkerDlg::OnBnClickedEditMarkerDelete()
\r
197 int i = GetSelectedItemIndex();
\r
200 const tchar_t *pKey = reinterpret_cast<tchar_t *>(m_listMarkers.GetItemData(i));
\r
201 m_listMarkers.DeleteItem(i);
\r
202 m_tempMarkers.GetMarkers().erase(pKey);
\r
203 if (i >= m_listMarkers.GetItemCount() - 1)
\r
204 i = m_listMarkers.GetItemCount() - 1;
\r
206 m_listMarkers.SetItemState(i, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED);
\r
209 void CTextMarkerDlg::OnBnClickedApplyNow()
\r
212 for (int i = 0; i < m_listMarkers.GetItemCount(); ++i)
\r
214 const tchar_t *pKey = reinterpret_cast<tchar_t *>(m_listMarkers.GetItemData(i));
\r
215 m_tempMarkers.GetMarkers()[pKey].bVisible = !!m_listMarkers.GetCheck(i);
\r
217 m_tempMarkers.SetEnabled(m_bMarkersEnabled);
\r
218 m_markers = m_tempMarkers;
\r
219 m_markers.UpdateViews();
\r
222 void CTextMarkerDlg::OnOK()
\r
224 OnBnClickedApplyNow();
\r
228 void CTextMarkerDlg::OnEditchangeEditFindtext()
\r
230 int i = GetSelectedItemIndex();
\r
234 GetDlgItemText(IDC_EDIT_FINDTEXT, sFindWhat);
\r
235 m_listMarkers.SetItemText(i, 0, sFindWhat);
\r
238 void CTextMarkerDlg::OnItemchangingEditMarkerList(NMHDR *, LRESULT *pResult)
\r
244 void CTextMarkerDlg::OnItemchangedEditMarkerList(NMHDR *, LRESULT *pResult)
\r