SelectMask.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <FileMasks.h>
  6. #include <CoreMain.h>
  7. #include <TextsWin.h>
  8. #include <HelpWin.h>
  9. #include <Tools.h>
  10. #include <VCLCommon.h>
  11. #include "SelectMask.h"
  12. #include "WinConfiguration.h"
  13. //---------------------------------------------------------------------------
  14. #pragma package(smart_init)
  15. #pragma link "HistoryComboBox"
  16. #ifndef NO_RESOURCES
  17. #pragma resource "*.dfm"
  18. #endif
  19. //---------------------------------------------------------------------------
  20. bool __fastcall DoSelectMaskDialog(TControl * Parent, bool Select, TFileFilter & Filter)
  21. {
  22. std::unique_ptr<TSelectMaskDialog> Dialog(new TSelectMaskDialog(Application));
  23. Dialog->Init((Select ? TSelectMaskDialog::smSelect : TSelectMaskDialog::smDeselect), Parent);
  24. DefaultFileFilter(Filter);
  25. Filter.Masks = WinConfiguration->SelectMask;
  26. Filter.Directories = WinConfiguration->SelectDirectories;
  27. bool Result = Dialog->Execute(Filter);
  28. if (Result)
  29. {
  30. WinConfiguration->SelectMask = Filter.Masks;
  31. WinConfiguration->SelectDirectories = Filter.Directories;
  32. }
  33. return Result;
  34. }
  35. //---------------------------------------------------------------------------
  36. bool __fastcall DoFilterMaskDialog(TControl * Parent, UnicodeString & Mask)
  37. {
  38. TFileFilter Filter;
  39. DefaultFileFilter(Filter);
  40. Filter.Masks = Mask;
  41. std::unique_ptr<TSelectMaskDialog> Dialog(new TSelectMaskDialog(Application));
  42. Dialog->Init(TSelectMaskDialog::smFilter, Parent);
  43. bool Result = Dialog->Execute(Filter);
  44. if (Result)
  45. {
  46. Mask = Filter.Masks;
  47. }
  48. return Result;
  49. }
  50. //---------------------------------------------------------------------------
  51. __fastcall TSelectMaskDialog::TSelectMaskDialog(TComponent * Owner) :
  52. TForm(Owner)
  53. {
  54. UseSystemSettings(this);
  55. HintLabel(HintText,
  56. FORMAT(L"%s\n \n%s\n \n%s\n \n%s", (LoadStr(MASK_HINT2), LoadStr(FILE_MASK_EX_HINT),
  57. LoadStr(COMBINING_MASKS_HINT), LoadStr(MASK_HELP))));
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TSelectMaskDialog::Init(TMode Mode, TControl * Parent)
  61. {
  62. int CaptionStr;
  63. switch (Mode)
  64. {
  65. case smSelect:
  66. CaptionStr = SELECT_MASK_SELECT_CAPTION;
  67. ClearButton->Hide();
  68. break;
  69. case smDeselect:
  70. CaptionStr = SELECT_MASK_DESELECT_CAPTION;
  71. ClearButton->Hide();
  72. break;
  73. case smFilter:
  74. CaptionStr = FILTER_MASK_CAPTION;
  75. ApplyToDirectoriesCheck->Hide();
  76. HelpKeyword = HELP_FILTER;
  77. break;
  78. }
  79. Caption = LoadStr(CaptionStr);
  80. FParent = Parent;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TSelectMaskDialog::FormCloseQuery(TObject *, bool & DebugUsedArg(CanClose))
  84. {
  85. if (ModalResult == DefaultResult(this))
  86. {
  87. if (MaskEdit->Focused())
  88. {
  89. MaskEditExit(NULL);
  90. }
  91. }
  92. }
  93. //---------------------------------------------------------------------------
  94. bool __fastcall TSelectMaskDialog::Execute(TFileFilter & FileFilter)
  95. {
  96. ApplyToDirectoriesCheck->Checked = FileFilter.Directories;
  97. MaskEdit->Text = FileFilter.Masks;
  98. MaskEdit->Items = WinConfiguration->History[L"Mask"];
  99. ActiveControl = MaskEdit;
  100. bool Result = (ShowModal() == DefaultResult(this));
  101. if (Result)
  102. {
  103. MaskEdit->SaveToHistory();
  104. WinConfiguration->History[L"Mask"] = MaskEdit->Items;
  105. FileFilter.Directories = ApplyToDirectoriesCheck->Checked;
  106. FileFilter.Masks = MaskEdit->Text;
  107. }
  108. return Result;
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TSelectMaskDialog::MaskEditExit(TObject * /*Sender*/)
  112. {
  113. ValidateMaskEdit(MaskEdit);
  114. }
  115. //---------------------------------------------------------------------------
  116. void __fastcall TSelectMaskDialog::HelpButtonClick(TObject * /*Sender*/)
  117. {
  118. FormHelp(this);
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TSelectMaskDialog::ClearButtonClick(TObject * /*Sender*/)
  122. {
  123. MaskEdit->Text = L"";
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TSelectMaskDialog::FormShow(TObject * /*Sender*/)
  127. {
  128. InstallPathWordBreakProc(MaskEdit);
  129. // Only now it is scaled
  130. CenterFormOn(this, FParent);
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TSelectMaskDialog::MaskButtonClick(TObject * /*Sender*/)
  134. {
  135. TFileMasks Masks = MaskEdit->Text;
  136. if (DoEditMaskDialog(Masks))
  137. {
  138. MaskEdit->Text = Masks.Masks;
  139. }
  140. }
  141. //---------------------------------------------------------------------------