Custom.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Dialogs.hpp>
  5. //---------------------------------------------------------------------
  6. #include <Common.h>
  7. #include <CustomWinConfiguration.h>
  8. #include <WinInterface.h>
  9. #include <VCLCommon.h>
  10. #include <TextsWin.h>
  11. #include <HelpWin.h>
  12. #include <CoreMain.h>
  13. #include <PasTools.hpp>
  14. #include <ProgParams.h>
  15. #include <Tools.h>
  16. #include <HistoryComboBox.hpp>
  17. #include <Math.hpp>
  18. #include "Custom.h"
  19. //---------------------------------------------------------------------
  20. #pragma link "PasswordEdit"
  21. #ifndef NO_RESOURCES
  22. #pragma resource "*.dfm"
  23. #endif
  24. //---------------------------------------------------------------------
  25. __fastcall TCustomDialog::TCustomDialog(UnicodeString AHelpKeyword)
  26. : TForm(GetFormOwner())
  27. {
  28. UseSystemSettings(this);
  29. FPos = ScaleByTextHeight(this, 8);
  30. FHorizontalMargin = ScaleByTextHeight(this, 8);
  31. FIndent = FHorizontalMargin;
  32. HelpKeyword = AHelpKeyword;
  33. TBorderIcons BI = BorderIcons;
  34. if (HelpKeyword.IsEmpty())
  35. {
  36. BI >> biHelp;
  37. OKButton->Left = CancelButton->Left;
  38. CancelButton->Left = HelpButton->Left;
  39. HelpButton->Visible = false;
  40. }
  41. else
  42. {
  43. BI << biHelp;
  44. }
  45. BorderIcons = BI;
  46. }
  47. //---------------------------------------------------------------------
  48. bool __fastcall TCustomDialog::Execute()
  49. {
  50. Changed();
  51. return (ShowModal() == DefaultResult(this));
  52. }
  53. //---------------------------------------------------------------------
  54. void __fastcall TCustomDialog::DoChange(bool & /*CanSubmit*/)
  55. {
  56. // noop
  57. }
  58. //---------------------------------------------------------------------
  59. void __fastcall TCustomDialog::Changed()
  60. {
  61. bool CanSubmit = true;
  62. DoChange(CanSubmit);
  63. EnableControl(OKButton, CanSubmit);
  64. }
  65. //---------------------------------------------------------------------
  66. void __fastcall TCustomDialog::Change(TObject * /*Sender*/)
  67. {
  68. Changed();
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TCustomDialog::HelpButtonClick(TObject * /*Sender*/)
  72. {
  73. FormHelp(this);
  74. }
  75. //---------------------------------------------------------------------------
  76. void __fastcall TCustomDialog::DoShow()
  77. {
  78. OKButton->TabOrder = FCount;
  79. CancelButton->TabOrder = static_cast<short>(FCount + 1);
  80. HelpButton->TabOrder = static_cast<short>(FCount + 2);
  81. Changed();
  82. TForm::DoShow();
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TCustomDialog::DoValidate()
  86. {
  87. // noop
  88. }
  89. //---------------------------------------------------------------------------
  90. bool __fastcall TCustomDialog::CloseQuery()
  91. {
  92. if (ModalResult == DefaultResult(this))
  93. {
  94. DoValidate();
  95. }
  96. return TForm::CloseQuery();
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
  100. {
  101. TImage * Image = new TImage(this);
  102. Image->Name = L"Image";
  103. Image->Parent = this;
  104. LoadResourceImage(Image, ImageName);
  105. Image->SetBounds(FIndent, FPos + ScaleByTextHeight(this, 3), 32, 32);
  106. FIndent += Image->Width + ScaleByTextHeight(this, 12);
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TCustomDialog::AddWinControl(TWinControl * Control)
  110. {
  111. Control->TabOrder = FCount;
  112. FCount++;
  113. }
  114. //---------------------------------------------------------------------------
  115. TCheckBox * __fastcall TCustomDialog::CreateAndAddCheckBox(const UnicodeString & Caption)
  116. {
  117. TCheckBox * CheckBox = new TCheckBox(this);
  118. CheckBox->Caption = Caption;
  119. AddButtonControl(CheckBox);
  120. return CheckBox;
  121. }
  122. //---------------------------------------------------------------------------
  123. TLabel * __fastcall TCustomDialog::CreateLabel(UnicodeString Label)
  124. {
  125. TLabel * Result = new TLabel(this);
  126. Result->Caption = Label;
  127. return Result;
  128. }
  129. //---------------------------------------------------------------------------
  130. void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * Label)
  131. {
  132. int PrePos = FPos;
  133. Label->Parent = this;
  134. Label->Left = FIndent;
  135. Label->Top = FPos;
  136. FPos += Label->Height + ScaleByTextHeight(this, 4);
  137. Edit->Parent = this;
  138. Edit->Left = FIndent;
  139. Edit->Top = FPos;
  140. Edit->Width = ClientWidth - Edit->Left - FHorizontalMargin;
  141. // this updates Height property to real value
  142. Edit->HandleNeeded();
  143. FPos += Edit->Height + ScaleByTextHeight(this, 8);
  144. if (Label->FocusControl == NULL)
  145. {
  146. Label->FocusControl = Edit;
  147. }
  148. else
  149. {
  150. assert(Label->FocusControl == Edit);
  151. }
  152. ClientHeight = ClientHeight + (FPos - PrePos);
  153. AddWinControl(Edit);
  154. }
  155. //---------------------------------------------------------------------------
  156. void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label)
  157. {
  158. AddEditLikeControl(Edit, Label);
  159. TEdit * PublicEdit = reinterpret_cast<TEdit *>(Edit);
  160. if (PublicEdit->OnChange == NULL)
  161. {
  162. PublicEdit->OnChange = Change;
  163. }
  164. }
  165. //---------------------------------------------------------------------------
  166. void __fastcall TCustomDialog::AddComboBox(TCustomCombo * Combo, TLabel * Label)
  167. {
  168. AddEditLikeControl(Combo, Label);
  169. TComboBox * PublicCombo = reinterpret_cast<TComboBox *>(Combo);
  170. if (PublicCombo->OnChange == NULL)
  171. {
  172. PublicCombo->OnChange = Change;
  173. }
  174. }
  175. //---------------------------------------------------------------------------
  176. void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
  177. {
  178. int PrePos = FPos;
  179. Control->Parent = this;
  180. Control->Left = FIndent + ScaleByTextHeight(this, 6);
  181. Control->Top = FPos;
  182. Control->Width = ClientWidth - Control->Left - FHorizontalMargin;
  183. // this updates Height property to real value
  184. Control->HandleNeeded();
  185. // buttons do not scale with text on their own
  186. Control->Height = ScaleByTextHeight(Control, Control->Height);
  187. FPos += Control->Height + ScaleByTextHeight(this, 8);
  188. ClientHeight = ClientHeight + (FPos - PrePos);
  189. AddWinControl(Control);
  190. TCheckBox * PublicControl = reinterpret_cast<TCheckBox *>(Control);
  191. if (PublicControl->OnClick == NULL)
  192. {
  193. PublicControl->OnClick = Change;
  194. }
  195. }
  196. //---------------------------------------------------------------------------
  197. //---------------------------------------------------------------------------
  198. class TSaveSessionDialog : public TCustomDialog
  199. {
  200. public:
  201. __fastcall TSaveSessionDialog(TComponent* AOwner);
  202. void __fastcall Init(bool CanSavePassword, bool NotRecommendedSavingPassword,
  203. TStrings * AdditionalFolders);
  204. bool __fastcall Execute(UnicodeString & SessionName, bool & SavePassword,
  205. bool & CreateShortcut, const UnicodeString & OriginalSessionName);
  206. protected:
  207. virtual void __fastcall DoValidate();
  208. virtual void __fastcall DoChange(bool & CanSubmit);
  209. private:
  210. UnicodeString FOriginalSessionName;
  211. TEdit * SessionNameEdit;
  212. TComboBox * FolderCombo;
  213. TCheckBox * SavePasswordCheck;
  214. TCheckBox * CreateShortcutCheck;
  215. UnicodeString FRootFolder;
  216. UnicodeString __fastcall GetSessionName();
  217. };
  218. //---------------------------------------------------------------------------
  219. // Need to have an Owner argument for SafeFormCreate
  220. __fastcall TSaveSessionDialog::TSaveSessionDialog(TComponent* /*AOwner*/) :
  221. TCustomDialog(HELP_SESSION_SAVE)
  222. {
  223. }
  224. //---------------------------------------------------------------------------
  225. void __fastcall TSaveSessionDialog::Init(bool CanSavePassword,
  226. bool NotRecommendedSavingPassword, TStrings * AdditionalFolders)
  227. {
  228. Caption = LoadStr(SAVE_SESSION_CAPTION);
  229. SessionNameEdit = new TEdit(this);
  230. AddEdit(SessionNameEdit, CreateLabel(LoadStr(SAVE_SESSION_PROMPT)));
  231. FRootFolder = LoadStr(SAVE_SESSION_ROOT_FOLDER2);
  232. std::unique_ptr<TStringList> Folders(new TStringList());
  233. if (AdditionalFolders != NULL)
  234. {
  235. Folders->AddStrings(AdditionalFolders);
  236. }
  237. for (int Index = 0; Index < StoredSessions->Count; Index++)
  238. {
  239. TSessionData * Data = StoredSessions->Sessions[Index];
  240. if (!Data->Special && !Data->IsWorkspace)
  241. {
  242. UnicodeString Folder = Data->FolderName;
  243. if (!Folder.IsEmpty() && Folders->IndexOf(Folder) < 0)
  244. {
  245. Folders->Add(Folder);
  246. }
  247. }
  248. }
  249. assert(!Folders->CaseSensitive);
  250. Folders->Sort();
  251. FolderCombo = new TComboBox(this);
  252. AddComboBox(FolderCombo, CreateLabel(LoadStr(SAVE_SESSION_FOLDER)));
  253. FolderCombo->DropDownCount = Max(FolderCombo->DropDownCount, 16);
  254. FolderCombo->Items->Add(FRootFolder);
  255. FolderCombo->Items->AddStrings(Folders.get());
  256. SavePasswordCheck = CreateAndAddCheckBox(
  257. LoadStr(NotRecommendedSavingPassword ? SAVE_SESSION_PASSWORD :
  258. (CustomWinConfiguration->UseMasterPassword ? SAVE_SESSION_PASSWORD_MASTER : SAVE_SESSION_PASSWORD_RECOMMENDED)));
  259. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  260. EnableControl(SavePasswordCheck, CanSavePassword);
  261. }
  262. //---------------------------------------------------------------------------
  263. bool __fastcall TSaveSessionDialog::Execute(
  264. UnicodeString & SessionName, bool & SavePassword, bool & CreateShortcut,
  265. const UnicodeString & OriginalSessionName)
  266. {
  267. FOriginalSessionName = OriginalSessionName;
  268. SessionNameEdit->Text = TSessionData::ExtractLocalName(SessionName);
  269. UnicodeString Folder = TSessionData::ExtractFolderName(SessionName);
  270. if (Folder.IsEmpty())
  271. {
  272. FolderCombo->Text = FRootFolder;
  273. }
  274. else
  275. {
  276. FolderCombo->Text = Folder;
  277. }
  278. SavePasswordCheck->Checked = SavePassword;
  279. CreateShortcutCheck->Checked = CreateShortcut;
  280. bool Result = TCustomDialog::Execute();
  281. if (Result)
  282. {
  283. SessionName = GetSessionName();
  284. SavePassword = SavePasswordCheck->Checked;
  285. CreateShortcut = CreateShortcutCheck->Checked;
  286. }
  287. return Result;
  288. }
  289. //---------------------------------------------------------------------------
  290. UnicodeString __fastcall TSaveSessionDialog::GetSessionName()
  291. {
  292. UnicodeString Folder;
  293. if (FolderCombo->Text != FRootFolder)
  294. {
  295. Folder = FolderCombo->Text;
  296. }
  297. return TSessionData::ComposePath(Folder, SessionNameEdit->Text);
  298. }
  299. //---------------------------------------------------------------------------
  300. void __fastcall TSaveSessionDialog::DoValidate()
  301. {
  302. TSessionData::ValidateName(SessionNameEdit->Text);
  303. SessionNameValidate(GetSessionName(), FOriginalSessionName);
  304. UnicodeString Folder = TSessionData::ExtractFolderName(GetSessionName());
  305. if (!Folder.IsEmpty() && StoredSessions->IsWorkspace(Folder))
  306. {
  307. throw Exception(FMTLOAD(WORKSPACE_NOT_FOLDER, (Folder)));
  308. }
  309. if (SavePasswordCheck->Enabled && SavePasswordCheck->Checked &&
  310. CustomWinConfiguration->UseMasterPassword)
  311. {
  312. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  313. }
  314. TCustomDialog::DoValidate();
  315. }
  316. //---------------------------------------------------------------------------
  317. void __fastcall TSaveSessionDialog::DoChange(bool & CanSubmit)
  318. {
  319. CanSubmit = !SessionNameEdit->Text.IsEmpty();
  320. TCustomDialog::DoChange(CanSubmit);
  321. }
  322. //---------------------------------------------------------------------------
  323. TSessionData * __fastcall DoSaveSession(TSessionData * SessionData,
  324. TSessionData * OriginalSession, bool ForceDialog,
  325. TStrings * AdditionalFolders)
  326. {
  327. bool SavePassword = false;
  328. bool * PSavePassword;
  329. bool NotRecommendedSavingPassword =
  330. !CustomWinConfiguration->UseMasterPassword &&
  331. !SameText(SessionData->UserName, AnonymousUserName);
  332. if (Configuration->DisablePasswordStoring ||
  333. !SessionData->HasAnySessionPassword())
  334. {
  335. PSavePassword = NULL;
  336. }
  337. else
  338. {
  339. PSavePassword = &SavePassword;
  340. SavePassword =
  341. ((OriginalSession != NULL) && OriginalSession->HasAnySessionPassword()) ||
  342. !NotRecommendedSavingPassword;
  343. }
  344. UnicodeString SessionName = SessionData->SessionName;
  345. bool Result;
  346. bool CreateShortcut = false;
  347. if (!ForceDialog && ((PSavePassword == NULL) || SavePassword))
  348. {
  349. CustomWinConfiguration->AskForMasterPasswordIfNotSetAndNeededToPersistSessionData(SessionData);
  350. Result = true;
  351. }
  352. else
  353. {
  354. // This can be a standalone dialog when used with save URL (from GetLoginData)
  355. TSaveSessionDialog * Dialog = SafeFormCreate<TSaveSessionDialog>();
  356. try
  357. {
  358. Dialog->Init((PSavePassword != NULL), NotRecommendedSavingPassword, AdditionalFolders);
  359. Result = Dialog->Execute(SessionName, SavePassword, CreateShortcut, SessionData->Name);
  360. }
  361. __finally
  362. {
  363. delete Dialog;
  364. }
  365. }
  366. TSessionData * NewSession = NULL;
  367. if (Result)
  368. {
  369. if ((PSavePassword != NULL) && !SavePassword)
  370. {
  371. SessionData->ClearSessionPasswords();
  372. }
  373. NewSession =
  374. StoredSessions->NewSession(SessionName, SessionData);
  375. // modified only, explicit
  376. StoredSessions->Save(false, true);
  377. if (!SessionData->HostKey.IsEmpty())
  378. {
  379. SessionData->CacheHostKeyIfNotCached();
  380. }
  381. if (CreateShortcut)
  382. {
  383. TOperationVisualizer Visualizer;
  384. UnicodeString AdditionalParams =
  385. TProgramParams::FormatSwitch(DESKTOP_SWITCH) + L" " +
  386. TProgramParams::FormatSwitch(UPLOAD_IF_ANY_SWITCH);
  387. CreateDesktopSessionShortCut(SessionName, L"", AdditionalParams, -1, SITE_ICON);
  388. }
  389. }
  390. return NewSession;
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall SessionNameValidate(const UnicodeString & Text,
  394. const UnicodeString & OriginalName)
  395. {
  396. TSessionData::ValidatePath(Text);
  397. assert(StoredSessions);
  398. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  399. if (Data && Data->Special)
  400. {
  401. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  402. qtError, qaOK, HELP_NONE);
  403. Abort();
  404. }
  405. else if ((Data != NULL) && !Data->IsSameName(OriginalName) &&
  406. MessageDialog(MainInstructions(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text))),
  407. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  408. {
  409. Abort();
  410. }
  411. }
  412. //---------------------------------------------------------------------------
  413. //---------------------------------------------------------------------------
  414. class TSaveWorkspaceDialog : public TCustomDialog
  415. {
  416. public:
  417. __fastcall TSaveWorkspaceDialog(bool CanSavePasswords,
  418. bool NotRecommendedSavingPasswords);
  419. bool __fastcall Execute(
  420. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  421. bool & EnableAutoSave);
  422. protected:
  423. virtual void __fastcall DoValidate();
  424. virtual void __fastcall DoChange(bool & CanSubmit);
  425. private:
  426. TComboBox * WorkspaceNameCombo;
  427. TCheckBox * SavePasswordsCheck;
  428. TCheckBox * CreateShortcutCheck;
  429. TCheckBox * EnableAutoSaveCheck;
  430. };
  431. //---------------------------------------------------------------------------
  432. __fastcall TSaveWorkspaceDialog::TSaveWorkspaceDialog(
  433. bool CanSavePasswords, bool NotRecommendedSavingPasswords) :
  434. TCustomDialog(HELP_WORKSPACE_SAVE)
  435. {
  436. Caption = LoadStr(SAVE_WORKSPACE_CAPTION);
  437. WorkspaceNameCombo = new TComboBox(this);
  438. WorkspaceNameCombo->AutoComplete = false;
  439. AddComboBox(WorkspaceNameCombo, CreateLabel(LoadStr(SAVE_WORKSPACE_PROMPT)));
  440. WorkspaceNameCombo->DropDownCount = Max(WorkspaceNameCombo->DropDownCount, 16);
  441. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  442. WorkspaceNameCombo->Items->AddStrings(Workspaces.get());
  443. SavePasswordsCheck = CreateAndAddCheckBox(
  444. LoadStr(NotRecommendedSavingPasswords ? SAVE_WORKSPACE_PASSWORDS :
  445. (CustomWinConfiguration->UseMasterPassword ?
  446. SAVE_WORKSPACE_PASSWORDS_MASTER : SAVE_WORKSPACE_PASSWORDS_RECOMMENDED)));
  447. EnableControl(SavePasswordsCheck, CanSavePasswords);
  448. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  449. EnableAutoSaveCheck = CreateAndAddCheckBox(LoadStr(SAVE_WORKSPACE_AUTO));
  450. }
  451. //---------------------------------------------------------------------------
  452. bool __fastcall TSaveWorkspaceDialog::Execute(
  453. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  454. bool & EnableAutoSave)
  455. {
  456. WorkspaceNameCombo->Text = WorkspaceName;
  457. SavePasswordsCheck->Checked = SavePasswords;
  458. CreateShortcutCheck->Checked = CreateShortcut;
  459. EnableAutoSaveCheck->Checked = EnableAutoSave;
  460. bool Result = TCustomDialog::Execute();
  461. if (Result)
  462. {
  463. WorkspaceName = WorkspaceNameCombo->Text;
  464. SavePasswords = SavePasswordsCheck->Checked;
  465. CreateShortcut = CreateShortcutCheck->Checked;
  466. EnableAutoSave = EnableAutoSaveCheck->Checked;
  467. }
  468. return Result;
  469. }
  470. //---------------------------------------------------------------------------
  471. void __fastcall TSaveWorkspaceDialog::DoValidate()
  472. {
  473. TSessionData::ValidateName(WorkspaceNameCombo->Text);
  474. if (StoredSessions->IsFolder(WorkspaceNameCombo->Text))
  475. {
  476. throw Exception(FMTLOAD(FOLDER_NOT_WORKSPACE, (WorkspaceNameCombo->Text)));
  477. }
  478. if (SavePasswordsCheck->Enabled && SavePasswordsCheck->Checked &&
  479. CustomWinConfiguration->UseMasterPassword)
  480. {
  481. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  482. }
  483. TCustomDialog::DoValidate();
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TSaveWorkspaceDialog::DoChange(bool & CanSubmit)
  487. {
  488. CanSubmit = !WorkspaceNameCombo->Text.IsEmpty();
  489. TCustomDialog::DoChange(CanSubmit);
  490. }
  491. //---------------------------------------------------------------------------
  492. bool __fastcall DoSaveWorkspaceDialog(UnicodeString & WorkspaceName,
  493. bool * SavePasswords, bool NotRecommendedSavingPasswords,
  494. bool & CreateShortcut, bool & EnableAutoSave)
  495. {
  496. std::unique_ptr<TSaveWorkspaceDialog> Dialog(
  497. new TSaveWorkspaceDialog((SavePasswords != NULL), NotRecommendedSavingPasswords));
  498. bool Dummy = false;
  499. if (SavePasswords == NULL)
  500. {
  501. SavePasswords = &Dummy;
  502. }
  503. return
  504. Dialog->Execute(
  505. WorkspaceName, *SavePasswords, CreateShortcut, EnableAutoSave);
  506. }
  507. //---------------------------------------------------------------------------
  508. //---------------------------------------------------------------------------
  509. class TShortCutDialog : public TCustomDialog
  510. {
  511. public:
  512. __fastcall TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword);
  513. bool __fastcall Execute(TShortCut & ShortCut);
  514. private:
  515. TComboBox * ShortCutCombo;
  516. };
  517. //---------------------------------------------------------------------------
  518. __fastcall TShortCutDialog::TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword) :
  519. TCustomDialog(HelpKeyword)
  520. {
  521. Caption = LoadStr(SHORTCUT_CAPTION);
  522. ShortCutCombo = new TComboBox(this);
  523. AddComboBox(ShortCutCombo, CreateLabel(LoadStr(SHORTCUT_LABEL)));
  524. InitializeShortCutCombo(ShortCutCombo, ShortCuts);
  525. }
  526. //---------------------------------------------------------------------------
  527. bool __fastcall TShortCutDialog::Execute(TShortCut & ShortCut)
  528. {
  529. SetShortCutCombo(ShortCutCombo, ShortCut);
  530. bool Result = TCustomDialog::Execute();
  531. if (Result)
  532. {
  533. ShortCut = GetShortCutCombo(ShortCutCombo);
  534. }
  535. return Result;
  536. }
  537. //---------------------------------------------------------------------------
  538. bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
  539. const TShortCuts & ShortCuts, UnicodeString HelpKeyword)
  540. {
  541. bool Result;
  542. TShortCutDialog * Dialog = new TShortCutDialog(ShortCuts, HelpKeyword);
  543. try
  544. {
  545. Result = Dialog->Execute(ShortCut);
  546. }
  547. __finally
  548. {
  549. delete Dialog;
  550. }
  551. return Result;
  552. }
  553. //---------------------------------------------------------------------------
  554. //---------------------------------------------------------------------------
  555. class TRemoteMoveDialog : public TCustomDialog
  556. {
  557. public:
  558. __fastcall TRemoteMoveDialog();
  559. bool __fastcall Execute(UnicodeString & Target, UnicodeString & FileMask);
  560. protected:
  561. DYNAMIC void __fastcall DoShow();
  562. private:
  563. THistoryComboBox * Combo;
  564. };
  565. //---------------------------------------------------------------------------
  566. __fastcall TRemoteMoveDialog::TRemoteMoveDialog() :
  567. TCustomDialog(HELP_REMOTE_MOVE)
  568. {
  569. Caption = LoadStr(REMOTE_MOVE_TITLE);
  570. // The same as TRemoteTransferDialog
  571. ClientWidth = ScaleByTextHeight(this, 420);
  572. AddImage(L"REMOTE_MOVE_FILE");
  573. Combo = new THistoryComboBox(this);
  574. Combo->AutoComplete = false;
  575. AddComboBox(Combo, CreateLabel(LoadStr(REMOTE_TRANSFER_PROMPT2)));
  576. }
  577. //---------------------------------------------------------------------------
  578. bool __fastcall TRemoteMoveDialog::Execute(UnicodeString & Target, UnicodeString & FileMask)
  579. {
  580. Combo->Items = CustomWinConfiguration->History[L"RemoteTarget"];
  581. Combo->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
  582. bool Result = TCustomDialog::Execute();
  583. if (Result)
  584. {
  585. Target = UnixExtractFilePath(Combo->Text);
  586. FileMask = UnixExtractFileName(Combo->Text);
  587. Combo->SaveToHistory();
  588. CustomWinConfiguration->History[L"RemoteTarget"] = Combo->Items;
  589. }
  590. return Result;
  591. }
  592. //---------------------------------------------------------------------------
  593. void __fastcall TRemoteMoveDialog::DoShow()
  594. {
  595. TCustomDialog::DoShow();
  596. InstallPathWordBreakProc(Combo);
  597. }
  598. //---------------------------------------------------------------------------
  599. bool __fastcall DoRemoteMoveDialog(UnicodeString & Target, UnicodeString & FileMask)
  600. {
  601. std::unique_ptr<TRemoteMoveDialog> Dialog(new TRemoteMoveDialog());
  602. return Dialog->Execute(Target, FileMask);
  603. }