CopyLocal.cpp 5.8 KB

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