SelectMask.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 <Tools.h>
  9. #include <VCLCommon.h>
  10. #include "SelectMask.h"
  11. #include "WinConfiguration.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma link "HistoryComboBox"
  15. #ifndef NO_RESOURCES
  16. #pragma resource "*.dfm"
  17. #endif
  18. //---------------------------------------------------------------------------
  19. bool __fastcall DoSelectMaskDialog(TCustomDirView * Parent, bool Select,
  20. TFileFilter * Filter, TConfiguration * Configuration)
  21. {
  22. bool Result;
  23. TSelectMaskDialog * Dialog = new TSelectMaskDialog(Application);
  24. try
  25. {
  26. CenterFormOn(Dialog, Parent);
  27. Dialog->Init(Select ? TSelectMaskDialog::smSelect : TSelectMaskDialog::smDeselect);
  28. DefaultFileFilter(*Filter);
  29. Filter->Masks = WinConfiguration->SelectMask;
  30. Filter->Directories = WinConfiguration->SelectDirectories;
  31. Dialog->FileFilter = *Filter;
  32. Result = Dialog->Execute();
  33. if (Result)
  34. {
  35. *Filter = Dialog->FileFilter;
  36. WinConfiguration->SelectMask = Filter->Masks;
  37. WinConfiguration->SelectDirectories = Filter->Directories;
  38. }
  39. }
  40. __finally
  41. {
  42. delete Dialog;
  43. }
  44. return Result;
  45. }
  46. //---------------------------------------------------------------------------
  47. bool __fastcall DoFilterMaskDialog(TCustomDirView * Parent,
  48. TFileFilter * Filter)
  49. {
  50. bool Result;
  51. TSelectMaskDialog * Dialog = new TSelectMaskDialog(Application);
  52. try
  53. {
  54. CenterFormOn(Dialog, Parent);
  55. Dialog->Init(TSelectMaskDialog::smFilter);
  56. Dialog->FileFilter = *Filter;
  57. Result = Dialog->Execute();
  58. if (Result)
  59. {
  60. *Filter = Dialog->FileFilter;
  61. }
  62. }
  63. __finally
  64. {
  65. delete Dialog;
  66. }
  67. return Result;
  68. }
  69. //---------------------------------------------------------------------------
  70. __fastcall TSelectMaskDialog::TSelectMaskDialog(TComponent* Owner)
  71. : TForm(Owner)
  72. {
  73. DefaultFileFilter(FFileFilter);
  74. SetFileFilter(FFileFilter);
  75. UseSystemSettings(this);
  76. HintLabel(HintText,
  77. FORMAT(L"%s\n \n%s\n \n%s\n \n%s", (LoadStr(MASK_HINT2), LoadStr(FILE_MASK_EX_HINT),
  78. LoadStr(COMBINING_MASKS_HINT), LoadStr(MASK_HELP))));
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TSelectMaskDialog::Init(TMode Mode)
  82. {
  83. int CaptionStr;
  84. switch (Mode)
  85. {
  86. case smSelect:
  87. CaptionStr = SELECT_MASK_SELECT_CAPTION;
  88. ClearButton->Hide();
  89. break;
  90. case smDeselect:
  91. CaptionStr = SELECT_MASK_DESELECT_CAPTION;
  92. ClearButton->Hide();
  93. break;
  94. case smFilter:
  95. CaptionStr = FILTER_MASK_CAPTION;
  96. ApplyToDirectoriesCheck->Hide();
  97. HelpKeyword = L"ui_filter";
  98. break;
  99. }
  100. Caption = LoadStr(CaptionStr);
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TSelectMaskDialog::FormCloseQuery(TObject * /*Sender*/,
  104. bool & /*CanClose*/)
  105. {
  106. if (ModalResult == DefaultResult(this))
  107. {
  108. if (MaskEdit->Focused())
  109. {
  110. MaskEditExit(NULL);
  111. }
  112. }
  113. }
  114. //---------------------------------------------------------------------------
  115. bool __fastcall TSelectMaskDialog::Execute()
  116. {
  117. MaskEdit->Items = WinConfiguration->History[L"Mask"];
  118. ActiveControl = MaskEdit;
  119. bool Result = (ShowModal() == DefaultResult(this));
  120. if (Result)
  121. {
  122. MaskEdit->SaveToHistory();
  123. WinConfiguration->History[L"Mask"] = MaskEdit->Items;
  124. }
  125. return Result;
  126. } /* TSelectMaskDialog::Execute */
  127. //---------------------------------------------------------------------------
  128. void __fastcall TSelectMaskDialog::SetFileFilter(TFileFilter value)
  129. {
  130. FFileFilter = value;
  131. ApplyToDirectoriesCheck->Checked = FFileFilter.Directories;
  132. MaskEdit->Text = FFileFilter.Masks;
  133. } /* TSelectMaskDialog::SetFileFilter */
  134. //---------------------------------------------------------------------------
  135. TFileFilter __fastcall TSelectMaskDialog::GetFileFilter()
  136. {
  137. TFileFilter Result = FFileFilter;
  138. Result.Directories = ApplyToDirectoriesCheck->Checked;
  139. Result.Masks = MaskEdit->Text;
  140. return Result;
  141. } /* TSelectMaskDialog::GetFileFilter */
  142. //---------------------------------------------------------------------------
  143. void __fastcall TSelectMaskDialog::MaskEditExit(TObject * /*Sender*/)
  144. {
  145. ValidateMaskEdit(MaskEdit);
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall TSelectMaskDialog::HelpButtonClick(TObject * /*Sender*/)
  149. {
  150. FormHelp(this);
  151. }
  152. //---------------------------------------------------------------------------
  153. void __fastcall TSelectMaskDialog::ClearButtonClick(TObject * /*Sender*/)
  154. {
  155. MaskEdit->Text = L"";
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TSelectMaskDialog::FormShow(TObject * /*Sender*/)
  159. {
  160. InstallPathWordBreakProc(MaskEdit);
  161. }
  162. //---------------------------------------------------------------------------