CopyLocal.cpp 5.7 KB

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