Custom.cpp 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223
  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. FGroupBox = NULL;
  36. HelpKeyword = AHelpKeyword;
  37. TBorderIcons BI = BorderIcons;
  38. if (HelpKeyword.IsEmpty())
  39. {
  40. BI >> biHelp;
  41. OKButton->Left = CancelButton->Left;
  42. CancelButton->Left = HelpButton->Left;
  43. HelpButton->Visible = false;
  44. }
  45. else
  46. {
  47. BI << biHelp;
  48. }
  49. BorderIcons = BI;
  50. }
  51. //---------------------------------------------------------------------
  52. bool __fastcall TCustomDialog::Execute()
  53. {
  54. Changed();
  55. return (ShowModal() == DefaultResult(this));
  56. }
  57. //---------------------------------------------------------------------
  58. void __fastcall TCustomDialog::DoChange(bool & /*CanSubmit*/)
  59. {
  60. // noop
  61. }
  62. //---------------------------------------------------------------------
  63. void __fastcall TCustomDialog::Changed()
  64. {
  65. bool CanSubmit = true;
  66. DoChange(CanSubmit);
  67. EnableControl(OKButton, CanSubmit);
  68. }
  69. //---------------------------------------------------------------------
  70. void __fastcall TCustomDialog::Change(TObject * /*Sender*/)
  71. {
  72. Changed();
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TCustomDialog::DoHelp()
  76. {
  77. FormHelp(this);
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TCustomDialog::HelpButtonClick(TObject * /*Sender*/)
  81. {
  82. DoHelp();
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TCustomDialog::DoShow()
  86. {
  87. OKButton->TabOrder = FCount;
  88. CancelButton->TabOrder = static_cast<short>(FCount + 1);
  89. HelpButton->TabOrder = static_cast<short>(FCount + 2);
  90. Changed();
  91. TForm::DoShow();
  92. }
  93. //---------------------------------------------------------------------------
  94. void __fastcall TCustomDialog::DoValidate()
  95. {
  96. // noop
  97. }
  98. //---------------------------------------------------------------------------
  99. bool __fastcall TCustomDialog::CloseQuery()
  100. {
  101. if (ModalResult == DefaultResult(this))
  102. {
  103. DoValidate();
  104. }
  105. return TForm::CloseQuery();
  106. }
  107. //---------------------------------------------------------------------------
  108. void __fastcall TCustomDialog::AddImage(const UnicodeString & ImageName)
  109. {
  110. TImage * Image = new TImage(this);
  111. Image->Name = L"Image";
  112. Image->Parent = GetDefaultParent();
  113. LoadDialogImage(Image, ImageName);
  114. Image->SetBounds(FIndent, FPos + ScaleByTextHeight(this, 3), Image->Picture->Width, Image->Picture->Height);
  115. FIndent += Image->Width + ScaleByTextHeight(this, 12);
  116. }
  117. //---------------------------------------------------------------------------
  118. int __fastcall TCustomDialog::GetMaxControlWidth(TControl * Control)
  119. {
  120. return GetDefaultParent()->ClientWidth - Control->Left - FHorizontalMargin;
  121. }
  122. //---------------------------------------------------------------------------
  123. TWinControl * __fastcall TCustomDialog::GetDefaultParent()
  124. {
  125. return (FGroupBox != NULL) ? FGroupBox : static_cast<TWinControl *>(this);
  126. }
  127. //---------------------------------------------------------------------------
  128. void __fastcall TCustomDialog::AdjustHeight(TControl * Control)
  129. {
  130. FPos = Control->Top + Control->Height + FControlPadding;
  131. int Delta = (FPos - FPrePos);
  132. ClientHeight = ClientHeight + Delta;
  133. if (FGroupBox != NULL)
  134. {
  135. FGroupBox->Height = FGroupBox->Height + Delta;
  136. }
  137. FPrePos = FPos;
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TCustomDialog::AddWinControl(TWinControl * Control)
  141. {
  142. Control->TabOrder = FCount;
  143. FCount++;
  144. }
  145. //---------------------------------------------------------------------------
  146. TCheckBox * __fastcall TCustomDialog::CreateAndAddCheckBox(const UnicodeString & Caption)
  147. {
  148. TCheckBox * CheckBox = new TCheckBox(this);
  149. CheckBox->Caption = Caption;
  150. AddButtonControl(CheckBox);
  151. return CheckBox;
  152. }
  153. //---------------------------------------------------------------------------
  154. TLabel * __fastcall TCustomDialog::CreateLabel(UnicodeString Label)
  155. {
  156. TLabel * Result = new TLabel(this);
  157. Result->Caption = Label;
  158. return Result;
  159. }
  160. //---------------------------------------------------------------------------
  161. void __fastcall TCustomDialog::AddEditLikeControl(TWinControl * Edit, TLabel * Label, bool OneLine)
  162. {
  163. Edit->Parent = GetDefaultParent();
  164. // this updates Height property to real value
  165. Edit->HandleNeeded();
  166. Label->Parent = GetDefaultParent();
  167. Label->Left = FIndent;
  168. if (OneLine)
  169. {
  170. DebugAssert(Edit->Height > Label->Height);
  171. Label->Top = FPos + ((Edit->Height - Label->Height) / 2);
  172. }
  173. else
  174. {
  175. Label->Top = FPos;
  176. FPos += Label->Height + ScaleByTextHeight(this, 4);
  177. }
  178. Edit->Top = FPos;
  179. if (OneLine)
  180. {
  181. Edit->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Edit->Width;
  182. }
  183. else
  184. {
  185. Edit->Left = FIndent;
  186. Edit->Width = GetMaxControlWidth(Edit);
  187. }
  188. AdjustHeight(Edit);
  189. if (Label->FocusControl == NULL)
  190. {
  191. Label->FocusControl = Edit;
  192. }
  193. else
  194. {
  195. DebugAssert(Label->FocusControl == Edit);
  196. }
  197. AddWinControl(Edit);
  198. }
  199. //---------------------------------------------------------------------------
  200. void __fastcall TCustomDialog::AddEdit(TCustomEdit * Edit, TLabel * Label)
  201. {
  202. AddEditLikeControl(Edit, Label, false);
  203. TEdit * PublicEdit = reinterpret_cast<TEdit *>(Edit);
  204. if (PublicEdit->OnChange == NULL)
  205. {
  206. PublicEdit->OnChange = Change;
  207. }
  208. }
  209. //---------------------------------------------------------------------------
  210. void __fastcall TCustomDialog::AddComboBox(TCustomCombo * Combo, TLabel * Label, TStrings * Items, bool OneLine)
  211. {
  212. AddEditLikeControl(Combo, Label, OneLine);
  213. if (Items != NULL)
  214. {
  215. Combo->Items = Items;
  216. }
  217. if (OneLine)
  218. {
  219. int Width = 0;
  220. for (int Index = 0; Index < Combo->Items->Count; Index++)
  221. {
  222. Width = Max(Width, Combo->Canvas->TextWidth(Combo->Items->Strings[Index]));
  223. }
  224. Width += ScaleByTextHeight(Combo, 4 + 16 + 14);
  225. Width = Max(Width, HelpButton->Width);
  226. Combo->Width = Width;
  227. Combo->Left = GetDefaultParent()->ClientWidth - FHorizontalMargin - Width;
  228. }
  229. TComboBox * PublicCombo = reinterpret_cast<TComboBox *>(Combo);
  230. if (PublicCombo->OnChange == NULL)
  231. {
  232. PublicCombo->OnChange = Change;
  233. }
  234. }
  235. //---------------------------------------------------------------------------
  236. void __fastcall TCustomDialog::ScaleButtonControl(TButtonControl * Control)
  237. {
  238. // this updates Height property to real value
  239. Control->HandleNeeded();
  240. // buttons do not scale with text on their own
  241. Control->Height = ScaleByTextHeight(Control, Control->Height);
  242. }
  243. //---------------------------------------------------------------------------
  244. void __fastcall TCustomDialog::AddButtonControl(TButtonControl * Control)
  245. {
  246. Control->Parent = GetDefaultParent();
  247. Control->Left = FIndent + ScaleByTextHeight(this, 6);
  248. Control->Top = FPos;
  249. Control->Width = GetMaxControlWidth(Control);
  250. ScaleButtonControl(Control);
  251. AdjustHeight(Control);
  252. AddWinControl(Control);
  253. TCheckBox * PublicControl = reinterpret_cast<TCheckBox *>(Control);
  254. if (PublicControl->OnClick == NULL)
  255. {
  256. PublicControl->OnClick = Change;
  257. }
  258. }
  259. //---------------------------------------------------------------------------
  260. void __fastcall TCustomDialog::AddText(TLabel * Label)
  261. {
  262. Label->Parent = GetDefaultParent();
  263. Label->WordWrap = true;
  264. Label->Left = FIndent;
  265. Label->Width = GetMaxControlWidth(Label);
  266. Label->Top = FPos;
  267. Label->ShowAccelChar = false;
  268. TRect TextRect;
  269. SetRect(&TextRect, 0, 0, Label->Width, 0);
  270. DrawText(Label->Canvas->Handle, Label->Caption.c_str(), Label->Caption.Length() + 1, &TextRect,
  271. DT_EXPANDTABS | DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX |
  272. Label->DrawTextBiDiModeFlagsReadingOnly());
  273. Label->Height = TextRect.Height();
  274. AdjustHeight(Label);
  275. }
  276. //---------------------------------------------------------------------------
  277. void __fastcall TCustomDialog::AddText(TStaticText * Label)
  278. {
  279. Label->Parent = GetDefaultParent();
  280. Label->Left = FIndent;
  281. Label->Width = GetMaxControlWidth(Label);
  282. Label->Top = FPos;
  283. Label->ShowAccelChar = false;
  284. AdjustHeight(Label);
  285. AddWinControl(Label);
  286. }
  287. //---------------------------------------------------------------------------
  288. void __fastcall TCustomDialog::AddSeparator()
  289. {
  290. TBevel * Bevel = new TBevel(this);
  291. Bevel->Parent = GetDefaultParent();
  292. Bevel->Left = FIndent;
  293. Bevel->Top = FPos;
  294. Bevel->Height = 2;
  295. Bevel->Width = GetMaxControlWidth(Bevel);
  296. AdjustHeight(Bevel);
  297. }
  298. //---------------------------------------------------------------------------
  299. void __fastcall TCustomDialog::StartGroup(const UnicodeString & Caption)
  300. {
  301. if (FGroupBox != NULL)
  302. {
  303. FIndent = FGroupBox->Left;
  304. FPos = FGroupBox->Top + FGroupBox->Height + FControlPadding;
  305. FPrePos = FPos;
  306. FGroupBox = NULL;
  307. }
  308. TGroupBox * GroupBox = new TGroupBox(this);
  309. GroupBox->Parent = this;
  310. GroupBox->Caption = Caption;
  311. GroupBox->Left = FIndent;
  312. GroupBox->Top = FPos;
  313. GroupBox->Height = ScaleByTextHeight(GroupBox, 20);
  314. GroupBox->Width = GetMaxControlWidth(GroupBox);
  315. AdjustHeight(GroupBox);
  316. FPos = ScaleByTextHeight(this, 16);
  317. FPrePos = FPos;
  318. FIndent = FHorizontalMargin;
  319. FGroupBox = GroupBox;
  320. }
  321. //---------------------------------------------------------------------------
  322. //---------------------------------------------------------------------------
  323. class TSaveSessionDialog : public TCustomDialog
  324. {
  325. public:
  326. __fastcall TSaveSessionDialog(TComponent* AOwner);
  327. void __fastcall Init(bool CanSavePassword, bool NotRecommendedSavingPassword,
  328. TStrings * AdditionalFolders);
  329. bool __fastcall Execute(UnicodeString & SessionName, bool & SavePassword,
  330. bool & CreateShortcut, const UnicodeString & OriginalSessionName);
  331. protected:
  332. virtual void __fastcall DoValidate();
  333. virtual void __fastcall DoChange(bool & CanSubmit);
  334. private:
  335. UnicodeString FOriginalSessionName;
  336. TEdit * SessionNameEdit;
  337. TComboBox * FolderCombo;
  338. TCheckBox * SavePasswordCheck;
  339. TCheckBox * CreateShortcutCheck;
  340. UnicodeString FRootFolder;
  341. UnicodeString __fastcall GetSessionName();
  342. };
  343. //---------------------------------------------------------------------------
  344. // Need to have an Owner argument for SafeFormCreate
  345. __fastcall TSaveSessionDialog::TSaveSessionDialog(TComponent* /*AOwner*/) :
  346. TCustomDialog(HELP_SESSION_SAVE)
  347. {
  348. }
  349. //---------------------------------------------------------------------------
  350. void __fastcall TSaveSessionDialog::Init(bool CanSavePassword,
  351. bool NotRecommendedSavingPassword, TStrings * AdditionalFolders)
  352. {
  353. Caption = LoadStr(SAVE_SESSION_CAPTION);
  354. SessionNameEdit = new TEdit(this);
  355. AddEdit(SessionNameEdit, CreateLabel(LoadStr(SAVE_SESSION_PROMPT)));
  356. FRootFolder = LoadStr(SAVE_SESSION_ROOT_FOLDER2);
  357. std::unique_ptr<TStringList> Folders(new TStringList());
  358. if (AdditionalFolders != NULL)
  359. {
  360. Folders->AddStrings(AdditionalFolders);
  361. }
  362. for (int Index = 0; Index < StoredSessions->Count; Index++)
  363. {
  364. TSessionData * Data = StoredSessions->Sessions[Index];
  365. if (!Data->Special && !Data->IsWorkspace)
  366. {
  367. UnicodeString Folder = Data->FolderName;
  368. if (!Folder.IsEmpty() && Folders->IndexOf(Folder) < 0)
  369. {
  370. Folders->Add(Folder);
  371. }
  372. }
  373. }
  374. DebugAssert(!Folders->CaseSensitive);
  375. Folders->Sort();
  376. FolderCombo = new TComboBox(this);
  377. AddComboBox(FolderCombo, CreateLabel(LoadStr(SAVE_SESSION_FOLDER)));
  378. FolderCombo->DropDownCount = Max(FolderCombo->DropDownCount, 16);
  379. FolderCombo->Items->Add(FRootFolder);
  380. FolderCombo->Items->AddStrings(Folders.get());
  381. SavePasswordCheck = CreateAndAddCheckBox(
  382. LoadStr(NotRecommendedSavingPassword ? SAVE_SESSION_PASSWORD :
  383. (CustomWinConfiguration->UseMasterPassword ? SAVE_SESSION_PASSWORD_MASTER : SAVE_SESSION_PASSWORD_RECOMMENDED)));
  384. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  385. EnableControl(SavePasswordCheck, CanSavePassword);
  386. }
  387. //---------------------------------------------------------------------------
  388. bool __fastcall TSaveSessionDialog::Execute(
  389. UnicodeString & SessionName, bool & SavePassword, bool & CreateShortcut,
  390. const UnicodeString & OriginalSessionName)
  391. {
  392. FOriginalSessionName = OriginalSessionName;
  393. SessionNameEdit->Text = TSessionData::ExtractLocalName(SessionName);
  394. UnicodeString Folder = TSessionData::ExtractFolderName(SessionName);
  395. if (Folder.IsEmpty())
  396. {
  397. FolderCombo->Text = FRootFolder;
  398. }
  399. else
  400. {
  401. FolderCombo->Text = Folder;
  402. }
  403. SavePasswordCheck->Checked = SavePassword;
  404. CreateShortcutCheck->Checked = CreateShortcut;
  405. bool Result = TCustomDialog::Execute();
  406. if (Result)
  407. {
  408. SessionName = GetSessionName();
  409. SavePassword = SavePasswordCheck->Checked;
  410. CreateShortcut = CreateShortcutCheck->Checked;
  411. }
  412. return Result;
  413. }
  414. //---------------------------------------------------------------------------
  415. UnicodeString __fastcall TSaveSessionDialog::GetSessionName()
  416. {
  417. UnicodeString Folder;
  418. if (FolderCombo->Text != FRootFolder)
  419. {
  420. Folder = FolderCombo->Text;
  421. }
  422. return TSessionData::ComposePath(Folder, SessionNameEdit->Text);
  423. }
  424. //---------------------------------------------------------------------------
  425. void __fastcall TSaveSessionDialog::DoValidate()
  426. {
  427. TSessionData::ValidateName(SessionNameEdit->Text);
  428. SessionNameValidate(GetSessionName(), FOriginalSessionName);
  429. UnicodeString Folder = TSessionData::ExtractFolderName(GetSessionName());
  430. if (!Folder.IsEmpty() && StoredSessions->IsWorkspace(Folder))
  431. {
  432. throw Exception(FMTLOAD(WORKSPACE_NOT_FOLDER, (Folder)));
  433. }
  434. if (SavePasswordCheck->Enabled && SavePasswordCheck->Checked &&
  435. CustomWinConfiguration->UseMasterPassword)
  436. {
  437. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  438. }
  439. TCustomDialog::DoValidate();
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TSaveSessionDialog::DoChange(bool & CanSubmit)
  443. {
  444. CanSubmit = !SessionNameEdit->Text.IsEmpty();
  445. TCustomDialog::DoChange(CanSubmit);
  446. }
  447. //---------------------------------------------------------------------------
  448. TSessionData * __fastcall DoSaveSession(TSessionData * SessionData,
  449. TSessionData * OriginalSession, bool ForceDialog,
  450. TStrings * AdditionalFolders)
  451. {
  452. bool SavePassword = false;
  453. bool * PSavePassword;
  454. bool NotRecommendedSavingPassword =
  455. !CustomWinConfiguration->UseMasterPassword &&
  456. !SameText(SessionData->UserName, AnonymousUserName);
  457. if (Configuration->DisablePasswordStoring ||
  458. !SessionData->HasAnySessionPassword())
  459. {
  460. PSavePassword = NULL;
  461. }
  462. else
  463. {
  464. PSavePassword = &SavePassword;
  465. SavePassword =
  466. ((OriginalSession != NULL) && OriginalSession->HasAnySessionPassword()) ||
  467. !NotRecommendedSavingPassword;
  468. }
  469. UnicodeString SessionName = SessionData->SessionName;
  470. bool Result;
  471. bool CreateShortcut = false;
  472. if (!ForceDialog && ((PSavePassword == NULL) || SavePassword))
  473. {
  474. CustomWinConfiguration->AskForMasterPasswordIfNotSetAndNeededToPersistSessionData(SessionData);
  475. Result = true;
  476. }
  477. else
  478. {
  479. // This can be a standalone dialog when used with save URL (from GetLoginData)
  480. TSaveSessionDialog * Dialog = SafeFormCreate<TSaveSessionDialog>();
  481. try
  482. {
  483. Dialog->Init((PSavePassword != NULL), NotRecommendedSavingPassword, AdditionalFolders);
  484. Result = Dialog->Execute(SessionName, SavePassword, CreateShortcut, SessionData->Name);
  485. }
  486. __finally
  487. {
  488. delete Dialog;
  489. }
  490. }
  491. TSessionData * NewSession = NULL;
  492. if (Result)
  493. {
  494. if ((PSavePassword != NULL) && !SavePassword)
  495. {
  496. SessionData->ClearSessionPasswords();
  497. }
  498. NewSession =
  499. StoredSessions->NewSession(SessionName, SessionData);
  500. // modified only, explicit
  501. StoredSessions->Save(false, true);
  502. if (!SessionData->HostKey.IsEmpty())
  503. {
  504. SessionData->CacheHostKeyIfNotCached();
  505. }
  506. if (CreateShortcut)
  507. {
  508. TOperationVisualizer Visualizer;
  509. UnicodeString AdditionalParams =
  510. TProgramParams::FormatSwitch(DESKTOP_SWITCH) + L" " +
  511. TProgramParams::FormatSwitch(UPLOAD_IF_ANY_SWITCH);
  512. CreateDesktopSessionShortCut(SessionName, L"", AdditionalParams, -1, SITE_ICON);
  513. }
  514. }
  515. return NewSession;
  516. }
  517. //---------------------------------------------------------------------------
  518. void __fastcall SessionNameValidate(const UnicodeString & Text,
  519. const UnicodeString & OriginalName)
  520. {
  521. TSessionData::ValidatePath(Text);
  522. DebugAssert(StoredSessions);
  523. TSessionData * Data = (TSessionData *)StoredSessions->FindByName(Text);
  524. if (Data && Data->Special)
  525. {
  526. MessageDialog(FMTLOAD(CANNOT_OVERWRITE_SPECIAL_SESSION, (Text)),
  527. qtError, qaOK, HELP_NONE);
  528. Abort();
  529. }
  530. else if ((Data != NULL) && !Data->IsSameName(OriginalName) &&
  531. MessageDialog(MainInstructions(FMTLOAD(CONFIRM_OVERWRITE_SESSION, (Text))),
  532. qtConfirmation, qaYes | qaNo, HELP_SESSION_SAVE_OVERWRITE) != qaYes)
  533. {
  534. Abort();
  535. }
  536. }
  537. //---------------------------------------------------------------------------
  538. //---------------------------------------------------------------------------
  539. class TSaveWorkspaceDialog : public TCustomDialog
  540. {
  541. public:
  542. __fastcall TSaveWorkspaceDialog(bool CanSavePasswords,
  543. bool NotRecommendedSavingPasswords);
  544. bool __fastcall Execute(
  545. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  546. bool & EnableAutoSave);
  547. protected:
  548. virtual void __fastcall DoValidate();
  549. virtual void __fastcall DoChange(bool & CanSubmit);
  550. private:
  551. TComboBox * WorkspaceNameCombo;
  552. TCheckBox * SavePasswordsCheck;
  553. TCheckBox * CreateShortcutCheck;
  554. TCheckBox * EnableAutoSaveCheck;
  555. };
  556. //---------------------------------------------------------------------------
  557. __fastcall TSaveWorkspaceDialog::TSaveWorkspaceDialog(
  558. bool CanSavePasswords, bool NotRecommendedSavingPasswords) :
  559. TCustomDialog(HELP_WORKSPACE_SAVE)
  560. {
  561. Caption = LoadStr(SAVE_WORKSPACE_CAPTION);
  562. WorkspaceNameCombo = new TComboBox(this);
  563. WorkspaceNameCombo->AutoComplete = false;
  564. AddComboBox(WorkspaceNameCombo, CreateLabel(LoadStr(SAVE_WORKSPACE_PROMPT)));
  565. WorkspaceNameCombo->DropDownCount = Max(WorkspaceNameCombo->DropDownCount, 16);
  566. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  567. WorkspaceNameCombo->Items->AddStrings(Workspaces.get());
  568. SavePasswordsCheck = CreateAndAddCheckBox(
  569. LoadStr(NotRecommendedSavingPasswords ? SAVE_WORKSPACE_PASSWORDS :
  570. (CustomWinConfiguration->UseMasterPassword ?
  571. SAVE_WORKSPACE_PASSWORDS_MASTER : SAVE_WORKSPACE_PASSWORDS_RECOMMENDED)));
  572. EnableControl(SavePasswordsCheck, CanSavePasswords);
  573. CreateShortcutCheck = CreateAndAddCheckBox(LoadStr(SAVE_SITE_WORKSPACE_SHORTCUT));
  574. EnableAutoSaveCheck = CreateAndAddCheckBox(LoadStr(SAVE_WORKSPACE_AUTO));
  575. }
  576. //---------------------------------------------------------------------------
  577. bool __fastcall TSaveWorkspaceDialog::Execute(
  578. UnicodeString & WorkspaceName, bool & SavePasswords, bool & CreateShortcut,
  579. bool & EnableAutoSave)
  580. {
  581. WorkspaceNameCombo->Text = WorkspaceName;
  582. SavePasswordsCheck->Checked = SavePasswords;
  583. CreateShortcutCheck->Checked = CreateShortcut;
  584. EnableAutoSaveCheck->Checked = EnableAutoSave;
  585. bool Result = TCustomDialog::Execute();
  586. if (Result)
  587. {
  588. WorkspaceName = WorkspaceNameCombo->Text;
  589. SavePasswords = SavePasswordsCheck->Checked;
  590. CreateShortcut = CreateShortcutCheck->Checked;
  591. EnableAutoSave = EnableAutoSaveCheck->Checked;
  592. }
  593. return Result;
  594. }
  595. //---------------------------------------------------------------------------
  596. void __fastcall TSaveWorkspaceDialog::DoValidate()
  597. {
  598. TSessionData::ValidateName(WorkspaceNameCombo->Text);
  599. if (StoredSessions->IsFolder(WorkspaceNameCombo->Text))
  600. {
  601. throw Exception(FMTLOAD(FOLDER_NOT_WORKSPACE, (WorkspaceNameCombo->Text)));
  602. }
  603. if (SavePasswordsCheck->Enabled && SavePasswordsCheck->Checked &&
  604. CustomWinConfiguration->UseMasterPassword)
  605. {
  606. CustomWinConfiguration->AskForMasterPasswordIfNotSet();
  607. }
  608. TCustomDialog::DoValidate();
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TSaveWorkspaceDialog::DoChange(bool & CanSubmit)
  612. {
  613. CanSubmit = !WorkspaceNameCombo->Text.IsEmpty();
  614. TCustomDialog::DoChange(CanSubmit);
  615. }
  616. //---------------------------------------------------------------------------
  617. bool __fastcall DoSaveWorkspaceDialog(UnicodeString & WorkspaceName,
  618. bool * SavePasswords, bool NotRecommendedSavingPasswords,
  619. bool & CreateShortcut, bool & EnableAutoSave)
  620. {
  621. std::unique_ptr<TSaveWorkspaceDialog> Dialog(
  622. new TSaveWorkspaceDialog((SavePasswords != NULL), NotRecommendedSavingPasswords));
  623. bool Dummy = false;
  624. if (SavePasswords == NULL)
  625. {
  626. SavePasswords = &Dummy;
  627. }
  628. return
  629. Dialog->Execute(
  630. WorkspaceName, *SavePasswords, CreateShortcut, EnableAutoSave);
  631. }
  632. //---------------------------------------------------------------------------
  633. //---------------------------------------------------------------------------
  634. class TShortCutDialog : public TCustomDialog
  635. {
  636. public:
  637. __fastcall TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword);
  638. bool __fastcall Execute(TShortCut & ShortCut);
  639. private:
  640. TComboBox * ShortCutCombo;
  641. };
  642. //---------------------------------------------------------------------------
  643. __fastcall TShortCutDialog::TShortCutDialog(const TShortCuts & ShortCuts, UnicodeString HelpKeyword) :
  644. TCustomDialog(HelpKeyword)
  645. {
  646. Caption = LoadStr(SHORTCUT_CAPTION);
  647. ShortCutCombo = new TComboBox(this);
  648. AddComboBox(ShortCutCombo, CreateLabel(LoadStr(SHORTCUT_LABEL)));
  649. InitializeShortCutCombo(ShortCutCombo, ShortCuts);
  650. }
  651. //---------------------------------------------------------------------------
  652. bool __fastcall TShortCutDialog::Execute(TShortCut & ShortCut)
  653. {
  654. SetShortCutCombo(ShortCutCombo, ShortCut);
  655. bool Result = TCustomDialog::Execute();
  656. if (Result)
  657. {
  658. ShortCut = GetShortCutCombo(ShortCutCombo);
  659. }
  660. return Result;
  661. }
  662. //---------------------------------------------------------------------------
  663. bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
  664. const TShortCuts & ShortCuts, UnicodeString HelpKeyword)
  665. {
  666. bool Result;
  667. TShortCutDialog * Dialog = new TShortCutDialog(ShortCuts, HelpKeyword);
  668. try
  669. {
  670. Result = Dialog->Execute(ShortCut);
  671. }
  672. __finally
  673. {
  674. delete Dialog;
  675. }
  676. return Result;
  677. }
  678. //---------------------------------------------------------------------------
  679. //---------------------------------------------------------------------------
  680. class TRemoteMoveDialog : public TCustomDialog
  681. {
  682. public:
  683. __fastcall TRemoteMoveDialog(bool Multi);
  684. bool __fastcall Execute(UnicodeString & Target, UnicodeString & FileMask);
  685. protected:
  686. DYNAMIC void __fastcall DoShow();
  687. virtual void __fastcall DoValidate();
  688. UnicodeString __fastcall GetFileMask();
  689. private:
  690. THistoryComboBox * Combo;
  691. bool FMulti;
  692. };
  693. //---------------------------------------------------------------------------
  694. __fastcall TRemoteMoveDialog::TRemoteMoveDialog(bool Multi) :
  695. TCustomDialog(HELP_REMOTE_MOVE)
  696. {
  697. Caption = LoadStr(REMOTE_MOVE_TITLE);
  698. // The same as TRemoteTransferDialog
  699. ClientWidth = ScaleByTextHeight(this, 420);
  700. FMulti = Multi;
  701. AddImage(L"Move To");
  702. Combo = new THistoryComboBox(this);
  703. Combo->AutoComplete = false;
  704. AddComboBox(Combo, CreateLabel(LoadStr(REMOTE_TRANSFER_PROMPT2)));
  705. }
  706. //---------------------------------------------------------------------------
  707. bool __fastcall TRemoteMoveDialog::Execute(UnicodeString & Target, UnicodeString & FileMask)
  708. {
  709. Combo->Items = CustomWinConfiguration->History[L"RemoteTarget"];
  710. Combo->Text = UnixIncludeTrailingBackslash(Target) + FileMask;
  711. bool Result = TCustomDialog::Execute();
  712. if (Result)
  713. {
  714. Target = UnixExtractFilePath(Combo->Text);
  715. FileMask = GetFileMask();
  716. Combo->SaveToHistory();
  717. CustomWinConfiguration->History[L"RemoteTarget"] = Combo->Items;
  718. }
  719. return Result;
  720. }
  721. //---------------------------------------------------------------------------
  722. UnicodeString __fastcall TRemoteMoveDialog::GetFileMask()
  723. {
  724. return UnixExtractFileName(Combo->Text);
  725. }
  726. //---------------------------------------------------------------------------
  727. void __fastcall TRemoteMoveDialog::DoShow()
  728. {
  729. TCustomDialog::DoShow();
  730. InstallPathWordBreakProc(Combo);
  731. }
  732. //---------------------------------------------------------------------------
  733. void __fastcall TRemoteMoveDialog::DoValidate()
  734. {
  735. if (!IsFileNameMask(GetFileMask()) && FMulti)
  736. {
  737. UnicodeString Message =
  738. FormatMultiFilesToOneConfirmation(Combo->Text, true);
  739. if (MessageDialog(Message, qtConfirmation, qaOK | qaCancel, HELP_NONE) == qaCancel)
  740. {
  741. Abort();
  742. }
  743. }
  744. TCustomDialog::DoValidate();
  745. }
  746. //---------------------------------------------------------------------------
  747. bool __fastcall DoRemoteMoveDialog(bool Multi, UnicodeString & Target, UnicodeString & FileMask)
  748. {
  749. std::unique_ptr<TRemoteMoveDialog> Dialog(new TRemoteMoveDialog(Multi));
  750. return Dialog->Execute(Target, FileMask);
  751. }
  752. //---------------------------------------------------------------------------
  753. //---------------------------------------------------------------------------
  754. class TCustomCommandOptionsDialog : public TCustomDialog
  755. {
  756. public:
  757. __fastcall TCustomCommandOptionsDialog(
  758. const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags);
  759. bool __fastcall Execute();
  760. protected:
  761. virtual void __fastcall DoHelp();
  762. private:
  763. const TCustomCommandType * FCommand;
  764. TStrings * FCustomCommandOptions;
  765. std::vector<TControl *> FControls;
  766. std::vector<std::vector<UnicodeString> > FValues;
  767. unsigned int FFlags;
  768. UnicodeString __fastcall HistoryKey(const TCustomCommandType::TOption & Option);
  769. THistoryComboBox * __fastcall CreateHistoryComboBox(const TCustomCommandType::TOption & Option, const UnicodeString & Value);
  770. void __fastcall BrowseButtonClick(TObject * Sender);
  771. void __fastcall LinkLabelClick(TObject * Sender);
  772. UnicodeString __fastcall SaveHistoryComboBoxValue(TControl * Control, const TCustomCommandType::TOption & Option);
  773. void __fastcall AddOptionComboBox(
  774. TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option,
  775. std::vector<UnicodeString> & Values);
  776. UnicodeString __fastcall GetComboBoxValue(TControl * Control, const UnicodeString & Default);
  777. };
  778. //---------------------------------------------------------------------------
  779. __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
  780. const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags) :
  781. TCustomDialog(HELP_EXTENSION_OPTIONS)
  782. {
  783. FCommand = Command;
  784. FFlags = Flags;
  785. FCustomCommandOptions = CustomCommandOptions;
  786. Caption = FMTLOAD(EXTENSION_OPTIONS_CAPTION, (StripEllipsis(StripHotkey(FCommand->Name))));
  787. Width = ScaleByTextHeight(this, 400);
  788. int ControlIndex = 0;
  789. for (int OptionIndex = 0; OptionIndex < FCommand->OptionsCount; OptionIndex++)
  790. {
  791. const TCustomCommandType::TOption & Option = FCommand->GetOption(OptionIndex);
  792. if ((Option.Flags & FFlags) != 0)
  793. {
  794. UnicodeString OptionKey = FCommand->GetOptionKey(Option);
  795. UnicodeString Value;
  796. if (FCustomCommandOptions->IndexOfName(OptionKey) >= 0)
  797. {
  798. Value = FCustomCommandOptions->Values[OptionKey];
  799. }
  800. else
  801. {
  802. Value = Option.Default;
  803. }
  804. TControl * Control = NULL;
  805. std::vector<UnicodeString> Values;
  806. if (Option.Kind == TCustomCommandType::okUnknown)
  807. {
  808. Control = NULL;
  809. }
  810. else if (Option.Kind == TCustomCommandType::okLabel)
  811. {
  812. TLabel * Label = CreateLabel(Option.Caption);
  813. AddText(Label);
  814. Control = Label;
  815. }
  816. else if (Option.Kind == TCustomCommandType::okLink)
  817. {
  818. TStaticText * Label = new TStaticText(this);
  819. Label->Caption = Option.Caption;
  820. if (IsHttpOrHttpsUrl(Label->Caption))
  821. {
  822. Label->Caption = SecureUrl(Label->Caption);
  823. LinkLabel(Label);
  824. Label->TabStop = true;
  825. }
  826. else if (!Option.Default.IsEmpty() && IsHttpOrHttpsUrl(Option.Default))
  827. {
  828. Label->OnClick = LinkLabelClick;
  829. LinkLabel(Label);
  830. Label->TabStop = true;
  831. }
  832. else
  833. {
  834. // keep it plain text, as we have no URL
  835. }
  836. AddText(Label);
  837. Control = Label;
  838. }
  839. else if (Option.Kind == TCustomCommandType::okGroup)
  840. {
  841. StartGroup(Option.Caption);
  842. }
  843. else if (Option.Kind == TCustomCommandType::okSeparator)
  844. {
  845. AddSeparator();
  846. }
  847. else if (Option.Kind == TCustomCommandType::okTextBox)
  848. {
  849. Control = CreateHistoryComboBox(Option, Value);
  850. }
  851. else if (Option.Kind == TCustomCommandType::okFile)
  852. {
  853. THistoryComboBox * ComboBox = CreateHistoryComboBox(Option, Value);
  854. TButton * Button = new TButton(this);
  855. Button->Parent = GetDefaultParent();
  856. Button->Width = HelpButton->Width;
  857. Button->Left = GetDefaultParent()->ClientWidth - Button->Width - HorizontalMargin;
  858. ComboBox->Width = Button->Left - ComboBox->Left - ScaleByTextHeight(this, 6);
  859. Button->Top = ComboBox->Top - ScaleByTextHeight(this, 2);
  860. Button->Tag = ControlIndex;
  861. Button->Caption = LoadStr(EXTENSION_OPTIONS_BROWSE);
  862. Button->OnClick = BrowseButtonClick;
  863. ScaleButtonControl(Button);
  864. AddWinControl(Button);
  865. Control = ComboBox;
  866. }
  867. else if (Option.Kind == TCustomCommandType::okDropDownList)
  868. {
  869. TComboBox * ComboBox = new TComboBox(this);
  870. ComboBox->Style = csDropDownList;
  871. AddOptionComboBox(ComboBox, Value, Option, Values);
  872. Control = ComboBox;
  873. }
  874. else if (Option.Kind == TCustomCommandType::okComboBox)
  875. {
  876. TComboBox * ComboBox = new TComboBox(this);
  877. ComboBox->Style = csDropDown;
  878. AddOptionComboBox(ComboBox, Value, Option, Values);
  879. if (ComboBox->ItemIndex < 0)
  880. {
  881. ComboBox->Text = Value;
  882. }
  883. Control = ComboBox;
  884. }
  885. else if (Option.Kind == TCustomCommandType::okCheckBox)
  886. {
  887. TCheckBox * CheckBox = CreateAndAddCheckBox(Option.Caption);
  888. CheckBox->Checked =
  889. (Option.Params.size() >= 1) &&
  890. (Value == Option.Params[0]);
  891. Control = CheckBox;
  892. }
  893. else
  894. {
  895. DebugFail();
  896. }
  897. if (Control != NULL)
  898. {
  899. Control->Tag = ControlIndex;
  900. }
  901. FControls.push_back(Control);
  902. FValues.push_back(Values);
  903. ControlIndex++;
  904. DebugAssert(static_cast<int>(FControls.size()) == ControlIndex);
  905. }
  906. }
  907. }
  908. //---------------------------------------------------------------------------
  909. void __fastcall TCustomCommandOptionsDialog::AddOptionComboBox(
  910. TComboBox * ComboBox, const UnicodeString & Value, const TCustomCommandType::TOption & Option, std::vector<UnicodeString> & Values)
  911. {
  912. std::unique_ptr<TStringList> Items(new TStringList());
  913. int ItemIndex = -1;
  914. TCustomCommandType::TOption::TParams::const_iterator ParamI = Option.Params.begin();
  915. while (ParamI != Option.Params.end())
  916. {
  917. UnicodeString Item = (*ParamI);
  918. int P = Item.Pos(L"=");
  919. UnicodeString ParamValue;
  920. if (P > 0)
  921. {
  922. ParamValue = Item.SubString(1, P - 1);
  923. Item.Delete(1, P);
  924. }
  925. else
  926. {
  927. ParamValue = Item;
  928. }
  929. Items->Add(Item);
  930. if (Value == ParamValue)
  931. {
  932. ItemIndex = Items->Count - 1;
  933. }
  934. Values.push_back(ParamValue);
  935. ParamI++;
  936. }
  937. AddComboBox(ComboBox, CreateLabel(Option.Caption), Items.get(), true);
  938. ComboBox->ItemIndex = ItemIndex;
  939. }
  940. //---------------------------------------------------------------------------
  941. void __fastcall TCustomCommandOptionsDialog::LinkLabelClick(TObject * Sender)
  942. {
  943. TStaticText * Label = DebugNotNull(dynamic_cast<TStaticText *>(Sender));
  944. const TCustomCommandType::TOption & Option = FCommand->GetOption(Label->Tag);
  945. OpenBrowser(SecureUrl(Option.Default));
  946. }
  947. //---------------------------------------------------------------------------
  948. void __fastcall TCustomCommandOptionsDialog::BrowseButtonClick(TObject * Sender)
  949. {
  950. TButton * Button = DebugNotNull(dynamic_cast<TButton *>(Sender));
  951. int Index = Button->Tag;
  952. THistoryComboBox * ComboBox = dynamic_cast<THistoryComboBox *>(FControls[Index]);
  953. std::unique_ptr<TOpenDialog> OpenDialog(new TOpenDialog(Application));
  954. UnicodeString Caption = FCommand->GetOption(Index).Caption;
  955. Caption = StripHotkey(Caption);
  956. if (!Caption.IsEmpty() && (Caption[Caption.Length()] == L':'))
  957. {
  958. Caption.SetLength(Caption.Length() - 1);
  959. }
  960. OpenDialog->Title = FMTLOAD(EXTENSION_OPTIONS_BROWSE_TITLE, (Caption));
  961. UnicodeString ExpandedValue = ExpandEnvironmentVariables(ComboBox->Text);
  962. OpenDialog->FileName = ExpandedValue;
  963. UnicodeString InitialDir = ExtractFilePath(ExpandedValue);
  964. if (!InitialDir.IsEmpty())
  965. {
  966. OpenDialog->InitialDir = InitialDir;
  967. }
  968. if (OpenDialog->Execute())
  969. {
  970. if (OpenDialog->FileName != ExpandedValue)
  971. {
  972. ComboBox->Text = OpenDialog->FileName;
  973. }
  974. }
  975. }
  976. //---------------------------------------------------------------------------
  977. THistoryComboBox * __fastcall TCustomCommandOptionsDialog::CreateHistoryComboBox(
  978. const TCustomCommandType::TOption & Option, const UnicodeString & Value)
  979. {
  980. THistoryComboBox * ComboBox = new THistoryComboBox(this);
  981. ComboBox->AutoComplete = false;
  982. AddComboBox(ComboBox, CreateLabel(Option.Caption));
  983. ComboBox->Items = CustomWinConfiguration->History[HistoryKey(Option)];
  984. ComboBox->Text = Value;
  985. return ComboBox;
  986. }
  987. //---------------------------------------------------------------------------
  988. UnicodeString __fastcall TCustomCommandOptionsDialog::HistoryKey(const TCustomCommandType::TOption & Option)
  989. {
  990. UnicodeString Result = FCommand->GetOptionKey(Option);
  991. Result = CustomWinConfiguration->GetValidHistoryKey(Result);
  992. return L"CustomCommandOption_" + Result;
  993. }
  994. //---------------------------------------------------------------------------
  995. bool __fastcall TCustomCommandOptionsDialog::Execute()
  996. {
  997. bool Result = TCustomDialog::Execute();
  998. if (Result)
  999. {
  1000. int ControlIndex = 0;
  1001. for (int OptionIndex = 0; OptionIndex < FCommand->OptionsCount; OptionIndex++)
  1002. {
  1003. const TCustomCommandType::TOption & Option = FCommand->GetOption(OptionIndex);
  1004. if ((Option.Flags & FFlags) != 0)
  1005. {
  1006. if ((Option.Kind != TCustomCommandType::okUnknown) &&
  1007. Option.IsControl)
  1008. {
  1009. UnicodeString OptionKey = FCommand->GetOptionKey(Option);
  1010. TControl * Control = FControls[ControlIndex];
  1011. UnicodeString Value;
  1012. if (Option.Kind == TCustomCommandType::okTextBox)
  1013. {
  1014. Value = SaveHistoryComboBoxValue(Control, Option);
  1015. }
  1016. else if (Option.Kind == TCustomCommandType::okFile)
  1017. {
  1018. Value = SaveHistoryComboBoxValue(Control, Option);
  1019. }
  1020. else if (Option.Kind == TCustomCommandType::okDropDownList)
  1021. {
  1022. Value = GetComboBoxValue(Control, Option.Default);
  1023. }
  1024. else if (Option.Kind == TCustomCommandType::okComboBox)
  1025. {
  1026. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
  1027. Value = GetComboBoxValue(Control, ComboBox->Text);
  1028. }
  1029. else if (Option.Kind == TCustomCommandType::okCheckBox)
  1030. {
  1031. TCheckBox * CheckBox = DebugNotNull(dynamic_cast<TCheckBox *>(Control));
  1032. int Index = (CheckBox->Checked ? 0 : 1);
  1033. Value = (Index < static_cast<int>(Option.Params.size())) ? Option.Params[Index] : UnicodeString();
  1034. }
  1035. else
  1036. {
  1037. DebugFail();
  1038. }
  1039. // The default value setter deletes the "name" when the value is empty.
  1040. // It would cause us to fall back to the default value, but we want to remember the empty value.
  1041. if (Value.IsEmpty())
  1042. {
  1043. int Index = FCustomCommandOptions->IndexOfName(OptionKey);
  1044. if (Index < 0)
  1045. {
  1046. Index = FCustomCommandOptions->Add(L"");
  1047. }
  1048. UnicodeString Line = OptionKey + FCustomCommandOptions->NameValueSeparator;
  1049. FCustomCommandOptions->Strings[Index] = Line;
  1050. }
  1051. else
  1052. {
  1053. FCustomCommandOptions->Values[OptionKey] = Value;
  1054. }
  1055. }
  1056. ControlIndex++;
  1057. }
  1058. }
  1059. }
  1060. return Result;
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. UnicodeString __fastcall TCustomCommandOptionsDialog::GetComboBoxValue(
  1064. TControl * Control, const UnicodeString & Default)
  1065. {
  1066. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Control));
  1067. UnicodeString Result;
  1068. if (ComboBox->ItemIndex < 0)
  1069. {
  1070. Result = Default;
  1071. }
  1072. else
  1073. {
  1074. Result = FValues[Control->Tag][ComboBox->ItemIndex];
  1075. }
  1076. return Result;
  1077. }
  1078. //---------------------------------------------------------------------------
  1079. UnicodeString __fastcall TCustomCommandOptionsDialog::SaveHistoryComboBoxValue(
  1080. TControl * Control, const TCustomCommandType::TOption & Option)
  1081. {
  1082. THistoryComboBox * ComboBox = DebugNotNull(dynamic_cast<THistoryComboBox *>(Control));
  1083. ComboBox->SaveToHistory();
  1084. CustomWinConfiguration->History[HistoryKey(Option)] = ComboBox->Items;
  1085. return ComboBox->Text;
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. void __fastcall TCustomCommandOptionsDialog::DoHelp()
  1089. {
  1090. UnicodeString HelpPage;
  1091. if (!FCommand->OptionsPage.IsEmpty())
  1092. {
  1093. HelpPage = FCommand->OptionsPage;
  1094. }
  1095. else
  1096. {
  1097. HelpPage = FCommand->HomePage;
  1098. }
  1099. if (!HelpPage.IsEmpty())
  1100. {
  1101. OpenBrowser(HelpPage);
  1102. }
  1103. else
  1104. {
  1105. TCustomDialog::DoHelp();
  1106. }
  1107. }
  1108. //---------------------------------------------------------------------------
  1109. bool __fastcall DoCustomCommandOptionsDialog(
  1110. const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags)
  1111. {
  1112. std::unique_ptr<TCustomCommandOptionsDialog> Dialog(
  1113. new TCustomCommandOptionsDialog(Command, CustomCommandOptions, Flags));
  1114. return Dialog->Execute();
  1115. }