SelectMask.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include <FileMasks.h>
  6. #include <ScpMain.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. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------------
  17. bool __fastcall DoSelectMaskDialog(TCustomDirView * Parent, bool Select,
  18. TFileFilter * Filter, TConfiguration * Configuration)
  19. {
  20. bool Result;
  21. TSelectMaskDialog * Dialog = new TSelectMaskDialog(Application);
  22. try
  23. {
  24. CenterFormOn(Dialog, Parent);
  25. Dialog->Select = Select;
  26. DefaultFileFilter(*Filter);
  27. Filter->Masks = WinConfiguration->SelectMask;
  28. Filter->Directories = WinConfiguration->SelectDirectories;
  29. Dialog->FileFilter = *Filter;
  30. Result = Dialog->Execute();
  31. if (Result)
  32. {
  33. *Filter = Dialog->FileFilter;
  34. WinConfiguration->SelectMask = Filter->Masks;
  35. WinConfiguration->SelectDirectories = Filter->Directories;
  36. }
  37. }
  38. __finally
  39. {
  40. delete Dialog;
  41. }
  42. return Result;
  43. }
  44. //---------------------------------------------------------------------------
  45. __fastcall TSelectMaskDialog::TSelectMaskDialog(TComponent* Owner)
  46. : TForm(Owner)
  47. {
  48. DefaultFileFilter(FFileFilter);
  49. SetFileFilter(FFileFilter);
  50. UseSystemFont(this);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TSelectMaskDialog::FormCloseQuery(TObject * /*Sender*/,
  54. bool &CanClose)
  55. {
  56. if (ModalResult != mrCancel)
  57. {
  58. TFileMasks Masks = MaskEdit->Text;
  59. int Start, Length;
  60. if (!Masks.IsValid(Start, Length))
  61. {
  62. CanClose = false;
  63. SimpleErrorDialog(FMTLOAD(MASK_ERROR, (Masks.Masks.SubString(Start+1, Length))));
  64. // After closing dialog whole text is selected, we want to select only invalid mask
  65. MaskEdit->SetFocus();
  66. MaskEdit->SelStart = Start;
  67. MaskEdit->SelLength = Length;
  68. }
  69. }
  70. }
  71. //---------------------------------------------------------------------------
  72. bool __fastcall TSelectMaskDialog::Execute()
  73. {
  74. MaskEdit->Items->Text = WinConfiguration->MaskHistory;
  75. ActiveControl = MaskEdit;
  76. bool Result = (ShowModal() == mrOk);
  77. if (Result)
  78. {
  79. MaskEdit->SaveToHistory();
  80. WinConfiguration->MaskHistory = MaskEdit->Items->Text;
  81. }
  82. return Result;
  83. } /* TSelectMaskDialog::Execute */
  84. //---------------------------------------------------------------------------
  85. void __fastcall TSelectMaskDialog::SetSelect(Boolean value)
  86. {
  87. if (FSelect != value)
  88. {
  89. FSelect = value;
  90. Caption = LoadStr(Select ? SELECT_MASK_SELECT_CAPTION : SELECT_MASK_DESELECT_CAPTION);
  91. }
  92. } /* TSelectMaskDialog::SetSelect */
  93. //---------------------------------------------------------------------------
  94. void __fastcall TSelectMaskDialog::SetFileFilter(TFileFilter value)
  95. {
  96. FFileFilter = value;
  97. IncludingDirectoriesCheck->Checked = FFileFilter.Directories;
  98. MaskEdit->Text = FFileFilter.Masks;
  99. } /* TSelectMaskDialog::SetFileFilter */
  100. //---------------------------------------------------------------------------
  101. TFileFilter __fastcall TSelectMaskDialog::GetFileFilter()
  102. {
  103. TFileFilter Result = FFileFilter;
  104. Result.Directories = IncludingDirectoriesCheck->Checked;
  105. Result.Masks = MaskEdit->Text;
  106. return Result;
  107. } /* TSelectMaskDialog::GetFileFilter */