Custom.cpp 21 KB

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