Custom.cpp 25 KB

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