Clone
ixen
committed
on 20 Nov 20
Added simple regex validation on rule edit dialogs and filter dialog. Aligned rule edit dialogs' buttons.
src/ch/FilterDlg.cpp (+14 -2)
4 4 //
5 5 //  This program is free software; you can redistribute it and/or modify
6 6 //  it under the terms of the GNU Library General Public License
7 7 //  (version 2) as published by the Free Software Foundation;
8 8 //
9 9 //  This program is distributed in the hope that it will be useful,
10 10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 12 //  GNU General Public License for more details.
13 13 //
14 14 //  You should have received a copy of the GNU Library General Public
15 15 //  License along with this program; if not, write to the
16 16 //  Free Software Foundation, Inc.,
17 17 //  59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18 18 // ============================================================================
19 19 #include "stdafx.h"
20 20 #include "ch.h"
21 21 #include "FilterDlg.h"
22 22 #include "resource.h"
23 23 #include "../libstring/TStringArray.h"
  24 #include <regex>
24 25
25 26 #ifdef _DEBUG
26 27 #define new DEBUG_NEW
27 28 #undef THIS_FILE
28 29 static char THIS_FILE[] = __FILE__;
29 30 #endif
30 31
31 32 /////////////////////////////////////////////////////////////////////////////
32 33 // CFilterDlg dialog
33 34
34 35 CFilterDlg::CFilterDlg()
35 36         :CLanguageDialog(IDD_FILTER_DIALOG),
36 37         m_iArchive(FALSE),
37 38         m_bAttributes(FALSE),
38 39         m_bDate1(FALSE),
39 40         m_bDate2(FALSE),
40 41         m_iDirectory(FALSE),
41 42         m_bFilter(FALSE),
42 43         m_iHidden(FALSE),
43 44         m_iReadOnly(FALSE),
 
322 323         GetDlgItem(IDC_DATE2_CHECK)->EnableWindow(m_bDate1 && bSecond);
323 324         m_ctlDateType1.EnableWindow(m_bDate1);
324 325         m_ctlDateType2.EnableWindow(m_bDate1 && m_bDate2 && bSecond);
325 326         m_ctlDate1.EnableWindow(m_bDate1);
326 327         m_ctlDate2.EnableWindow(m_bDate1 && m_bDate2 && bSecond);
327 328         m_ctlTime1.EnableWindow(m_bDate1);
328 329         m_ctlTime2.EnableWindow(m_bDate1 && m_bDate2 && bSecond);
329 330
330 331         // attrib
331 332         GetDlgItem(IDC_ARCHIVE_CHECK)->EnableWindow(m_bAttributes);
332 333         GetDlgItem(IDC_READONLY_CHECK)->EnableWindow(m_bAttributes);
333 334         GetDlgItem(IDC_HIDDEN_CHECK)->EnableWindow(m_bAttributes);
334 335         GetDlgItem(IDC_SYSTEM_CHECK)->EnableWindow(m_bAttributes);
335 336         GetDlgItem(IDC_DIRECTORY_CHECK)->EnableWindow(m_bAttributes);
336 337 }
337 338
338 339 void CFilterDlg::OnOK()
339 340 {
340 341         UpdateData(TRUE);
341 342
342           // TFileFilter --> dialogu - mask
343 343         CString strText;
344 344         m_ctlIncludeMask.GetWindowText(strText);
345 345         m_ffFilter.SetUseMask(((m_bFilter != 0) && !strText.IsEmpty()));
346 346         m_ffFilter.SetCombinedMask((PCTSTR)strText);
347 347
348 348         m_ctlExcludeMask.GetWindowText(strText);
349 349         m_ffFilter.SetUseExcludeMask((m_bExclude != 0) && !strText.IsEmpty());
350 350         m_ffFilter.SetCombinedExcludeMask((PCTSTR)strText);
351 351
352 352         // size
353 353         m_ffFilter.SetUseSize1(m_bSize != 0);
354 354         m_ffFilter.SetUseSize2(m_bSize2 != 0);
355 355
356 356         m_ffFilter.SetSizeType1((chengine::ECompareType)m_ctlSizeType1.GetCurSel());
357 357         m_ffFilter.SetSizeType2((chengine::ECompareType)m_ctlSizeType2.GetCurSel());
358 358
359 359         m_ffFilter.SetSize1(static_cast<unsigned __int64>(m_uiSize1)*static_cast<unsigned __int64>(GetMultiplier(m_ctlSize1Multi.GetCurSel())));
360 360         m_ffFilter.SetSize2(static_cast<unsigned __int64>(m_uiSize2)*static_cast<unsigned __int64>(GetMultiplier(m_ctlSize2Multi.GetCurSel())));
361 361
362 362         // date
 
369 369         CTime tTime;
370 370         m_ffFilter.SetUseDate1(m_ctlDate1.GetTime(tDate) == GDT_VALID);
371 371         m_ffFilter.SetUseTime1(m_ctlTime1.GetTime(tTime) == GDT_VALID);
372 372         m_ffFilter.SetDateTime1(chengine::TDateTime(tDate.GetYear(), tDate.GetMonth(), tDate.GetDay(), tTime.GetHour(), tTime.GetMinute(), tTime.GetSecond()));
373 373         
374 374         m_ffFilter.SetUseDate2(m_ctlDate2.GetTime(tDate) == GDT_VALID);
375 375         m_ffFilter.SetUseTime2(m_ctlTime2.GetTime(tTime) == GDT_VALID);
376 376         m_ffFilter.SetDateTime2(chengine::TDateTime(tDate.GetYear(), tDate.GetMonth(), tDate.GetDay(), tTime.GetHour(), tTime.GetMinute(), tTime.GetSecond()));
377 377
378 378         m_ffFilter.SetUseDateTime1((m_bDate1 != 0) && (m_ffFilter.GetUseDate1() || m_ffFilter.GetUseTime1()));
379 379         m_ffFilter.SetUseDateTime2((m_bDate2 != 0) && (m_ffFilter.GetUseDate2() || m_ffFilter.GetUseTime2()));
380 380
381 381         // attributes
382 382         m_ffFilter.SetUseAttributes(m_bAttributes != 0);
383 383         m_ffFilter.SetArchive(m_iArchive);
384 384         m_ffFilter.SetReadOnly(m_iReadOnly);
385 385         m_ffFilter.SetHidden(m_iHidden);
386 386         m_ffFilter.SetSystem(m_iSystem);
387 387         m_ffFilter.SetDirectory(m_iDirectory);
388 388
  389         if(!FilterTypesMenuWrapper::ValidateFilter(m_ffFilter.GetIncludeMask()))
  390         {
  391                 m_ctlIncludeMask.SetFocus();
  392                 return;
  393         }
  394
  395         if(!FilterTypesMenuWrapper::ValidateFilter(m_ffFilter.GetExcludeMask()))
  396         {
  397                 m_ctlExcludeMask.SetFocus();
  398                 return;
  399         }
  400
389 401         CLanguageDialog::OnOK();
390 402 }
391 403
392 404 BOOL CFilterDlg::OnCommand(WPARAM wParam, LPARAM lParam)
393 405 {
394 406         if(HIWORD(wParam) == 0)
395 407         {
396 408                 if(LOWORD(wParam) >= ID_POPUP_FILTER_FILE_WILDCARD && LOWORD(wParam) <= ID_POPUP_FILTER_SEPARATOR_CHAR)
397 409                 {
398 410                         CComboBox& rCombo = m_filterTypesWrapper.IsTrackingIncludeMask() ? m_ctlIncludeMask : m_ctlExcludeMask;
399 411                         m_filterTypesWrapper.OnCommand(LOWORD(wParam), rCombo);
400 412                 }
401 413         }
402 414         return ictranslate::CLanguageDialog::OnCommand(wParam, lParam);
403 415 }
404 416
405 417 int CFilterDlg::GetMultiplier(int iIndex)
406 418 {
407 419         switch (iIndex)
408 420         {