CopyLocal.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. //---------------------------------------------------------------------------
  2. #include <FormsPCH.h>
  3. #pragma hdrstop
  4. #include "CopyLocal.h"
  5. #include "ComboEdit.hpp"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "HistoryComboBox"
  9. #pragma resource "*.dfm"
  10. //---------------------------------------------------------------------------
  11. bool DoCopyLocalDialog(bool Move, int Options, UnicodeString & TargetDirectory, UnicodeString & FileMask, int & OutputOptions)
  12. {
  13. std::unique_ptr<TCopyLocalDialog> Dialog(new TCopyLocalDialog(GetFormOwner(), Move, Options));
  14. return Dialog->Execute(TargetDirectory, FileMask, OutputOptions);
  15. }
  16. //---------------------------------------------------------------------------
  17. TCopyLocalDialog::TCopyLocalDialog(TComponent * Owner, bool Move, int Options)
  18. : TForm(Owner)
  19. {
  20. FOptions = Options;
  21. UnicodeString ACaption;
  22. UnicodeString ImageName;
  23. if (!Move)
  24. {
  25. ImageName = L"Duplicate L to R";
  26. ACaption = LoadStr(COPY_LOCAL_COPY_CAPTION);
  27. }
  28. else
  29. {
  30. ImageName = L"Move L to R";
  31. ACaption = LoadStr(COPY_LOCAL_MOVE_CAPTION);
  32. }
  33. Caption = ACaption;
  34. LoadDialogImage(Image, ImageName);
  35. HotTrackLabel(ShortCutHintLabel);
  36. if (FLAGCLEAR(FOptions, cloShortCutHint) || CustomWinConfiguration->CopyShortCutHintShown)
  37. {
  38. ShortCutHintPanel->Visible = false;
  39. ClientHeight = ClientHeight - ShortCutHintPanel->Height;
  40. }
  41. AutoSizeCheckBox(NeverShowAgainCheck);
  42. UseSystemSettings(this);
  43. }
  44. //---------------------------------------------------------------------------
  45. bool TCopyLocalDialog::Execute(UnicodeString & TargetDirectory, UnicodeString & FileMask, int & OutputOptions)
  46. {
  47. DirectoryEdit->Items = CustomWinConfiguration->History[L"LocalTarget"];
  48. SetDirectoryAndFileMask(TargetDirectory, FileMask);
  49. NeverShowAgainCheck->Checked = FLAGSET(OutputOptions, clooDoNotShowAgain);
  50. DebugAssert((OutputOptions & ~clooDoNotShowAgain) == 0);
  51. bool Result = (ShowModal() == DefaultResult(this));
  52. if (Result)
  53. {
  54. ValidateDirectoryEdit();
  55. DirectoryEdit->SaveToHistory();
  56. CustomWinConfiguration->History[L"LocalTarget"] = DirectoryEdit->Items;
  57. FileMask = GetFileMask();
  58. TargetDirectory = GetDirectory();
  59. OutputOptions = FLAGMASK(NeverShowAgainCheck->Checked, clooDoNotShowAgain);
  60. if (ShortCutHintPanel->Visible)
  61. {
  62. CustomWinConfiguration->CopyShortCutHintShown = true;
  63. }
  64. }
  65. return Result;
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TCopyLocalDialog::ShortCutHintLabelClick(TObject *)
  69. {
  70. DoPreferencesDialog(pmCommander);
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TCopyLocalDialog::FormShow(TObject *)
  74. {
  75. InstallPathWordBreakProc(DirectoryEdit);
  76. // Does not work when set from a constructor
  77. ShortCutHintPanel->Color = Application->HintColor;
  78. UpdateControls();
  79. }
  80. //---------------------------------------------------------------------------
  81. void TCopyLocalDialog::UpdateControls()
  82. {
  83. }
  84. //---------------------------------------------------------------------------
  85. void TCopyLocalDialog::ValidateDirectoryEdit()
  86. {
  87. if (DirectoryExistsFix(DirectoryEdit->Text))
  88. {
  89. DirectoryEdit->Text = IncludeTrailingBackslash(DirectoryEdit->Text) + AnyMask;
  90. }
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TCopyLocalDialog::DirectoryEditExit(TObject *)
  94. {
  95. ValidateDirectoryEdit();
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TCopyLocalDialog::FormCloseQuery(TObject *, bool & CanClose)
  99. {
  100. if (ModalResult == DefaultResult(this))
  101. {
  102. ExitActiveControl(this);
  103. CanClose =
  104. CopyDialogValidateLocalDirectory(GetDirectory(), DirectoryEdit) &&
  105. CopyDialogValidateFileMask(GetFileMask(), DirectoryEdit, FLAGSET(FOptions, cloMultipleFiles), false);
  106. }
  107. }
  108. //---------------------------------------------------------------------------
  109. void TCopyLocalDialog::SetDirectoryAndFileMask(const UnicodeString & Directory, const UnicodeString & FileMask)
  110. {
  111. DirectoryEdit->Text = IncludeTrailingBackslash(Directory) + FileMask;
  112. }
  113. //---------------------------------------------------------------------------
  114. UnicodeString TCopyLocalDialog::GetDirectory()
  115. {
  116. UnicodeString Result = DirectoryEdit->Text;
  117. Result = ExtractFilePath(Result);
  118. if (!Result.IsEmpty())
  119. {
  120. Result = IncludeTrailingBackslash(Result);
  121. }
  122. return Result;
  123. }
  124. //---------------------------------------------------------------------------
  125. UnicodeString TCopyLocalDialog::GetFileMask()
  126. {
  127. return ExtractFileName(DirectoryEdit->Text);
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TCopyLocalDialog::HelpButtonClick(TObject *)
  131. {
  132. FormHelp(this);
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TCopyLocalDialog::LocalDirectoryBrowseButtonClick(TObject *)
  136. {
  137. UnicodeString ADirectory = GetDirectory();
  138. if (SelectDirectory(ADirectory, LoadStr(SELECT_LOCAL_DIRECTORY)))
  139. {
  140. SetDirectoryAndFileMask(ADirectory, GetFileMask());
  141. UpdateControls();
  142. }
  143. }
  144. //---------------------------------------------------------------------------
  145. void __fastcall TCopyLocalDialog::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  146. {
  147. DebugUsedParam2(OldDPI, NewDPI);
  148. AutoSizeCheckBox(NeverShowAgainCheck);
  149. }
  150. //---------------------------------------------------------------------------