Custom.cpp 25 KB

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