CopyLocal.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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"Upload File"; // TODO
  31. ACaption = LoadStr(COPY_LOCAL_COPY_CAPTION);
  32. }
  33. else
  34. {
  35. ImageName = L"Upload File Remove Original"; // TODO
  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. UseSystemSettings(this);
  47. }
  48. //---------------------------------------------------------------------------
  49. bool TCopyLocalDialog::Execute(UnicodeString & TargetDirectory, UnicodeString & FileMask, int & OutputOptions)
  50. {
  51. DirectoryEdit->Items = CustomWinConfiguration->History[L"LocalTarget"];
  52. SetDirectoryAndFileMask(TargetDirectory, FileMask);
  53. NeverShowAgainCheck->Checked = FLAGSET(OutputOptions, clooDoNotShowAgain);
  54. DebugAssert((OutputOptions & ~clooDoNotShowAgain) == 0);
  55. bool Result = (ShowModal() == DefaultResult(this));
  56. if (Result)
  57. {
  58. ValidateDirectoryEdit();
  59. DirectoryEdit->SaveToHistory();
  60. CustomWinConfiguration->History[L"LocalTarget"] = DirectoryEdit->Items;
  61. FileMask = GetFileMask();
  62. TargetDirectory = GetDirectory();
  63. OutputOptions = FLAGMASK(NeverShowAgainCheck->Checked, clooDoNotShowAgain);
  64. if (ShortCutHintPanel->Visible)
  65. {
  66. CustomWinConfiguration->CopyShortCutHintShown = true;
  67. }
  68. }
  69. return Result;
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TCopyLocalDialog::ShortCutHintLabelClick(TObject *)
  73. {
  74. DoPreferencesDialog(pmCommander);
  75. }
  76. //---------------------------------------------------------------------------
  77. void __fastcall TCopyLocalDialog::FormShow(TObject *)
  78. {
  79. InstallPathWordBreakProc(DirectoryEdit);
  80. // Does not work when set from a contructor
  81. ShortCutHintPanel->Color = Application->HintColor;
  82. UpdateControls();
  83. }
  84. //---------------------------------------------------------------------------
  85. void TCopyLocalDialog::UpdateControls()
  86. {
  87. }
  88. //---------------------------------------------------------------------------
  89. void TCopyLocalDialog::ValidateDirectoryEdit()
  90. {
  91. if (DirectoryExistsFix(DirectoryEdit->Text))
  92. {
  93. DirectoryEdit->Text = IncludeTrailingBackslash(DirectoryEdit->Text) + AnyMask;
  94. }
  95. }
  96. //---------------------------------------------------------------------------
  97. void __fastcall TCopyLocalDialog::DirectoryEditExit(TObject *)
  98. {
  99. ValidateDirectoryEdit();
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TCopyLocalDialog::FormCloseQuery(TObject *, bool & CanClose)
  103. {
  104. if (ModalResult == DefaultResult(this))
  105. {
  106. ExitActiveControl(this);
  107. CanClose =
  108. CopyDialogValidateLocalDirectory(GetDirectory(), DirectoryEdit) &&
  109. CopyDialogValidateFileMask(GetFileMask(), DirectoryEdit, FLAGSET(FOptions, cloMultipleFiles), false);
  110. }
  111. }
  112. //---------------------------------------------------------------------------
  113. void TCopyLocalDialog::SetDirectoryAndFileMask(const UnicodeString & Directory, const UnicodeString & FileMask)
  114. {
  115. DirectoryEdit->Text = IncludeTrailingBackslash(Directory) + FileMask;
  116. }
  117. //---------------------------------------------------------------------------
  118. UnicodeString TCopyLocalDialog::GetDirectory()
  119. {
  120. UnicodeString Result = DirectoryEdit->Text;
  121. Result = ExtractFilePath(Result);
  122. if (!Result.IsEmpty())
  123. {
  124. Result = IncludeTrailingBackslash(Result);
  125. }
  126. return Result;
  127. }
  128. //---------------------------------------------------------------------------
  129. UnicodeString TCopyLocalDialog::GetFileMask()
  130. {
  131. return ExtractFileName(DirectoryEdit->Text);
  132. }
  133. //---------------------------------------------------------------------------
  134. void __fastcall TCopyLocalDialog::HelpButtonClick(TObject *)
  135. {
  136. FormHelp(this);
  137. }
  138. //---------------------------------------------------------------------------
  139. void __fastcall TCopyLocalDialog::LocalDirectoryBrowseButtonClick(TObject *)
  140. {
  141. UnicodeString ADirectory = GetDirectory();
  142. if (SelectDirectory(ADirectory, LoadStr(SELECT_LOCAL_DIRECTORY), false))
  143. {
  144. SetDirectoryAndFileMask(ADirectory, GetFileMask());
  145. UpdateControls();
  146. }
  147. }
  148. //---------------------------------------------------------------------------