CopyLocal.cpp 5.6 KB

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