Preferences.cpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <Common.h>
  6. #include <math.h>
  7. #include "Preferences.h"
  8. #include <CoreMain.h>
  9. #include <Terminal.h>
  10. #include <Bookmarks.h>
  11. #include "VCLCommon.h"
  12. #include "GUITools.h"
  13. #include "Tools.h"
  14. #include "TextsWin.h"
  15. #include "HelpWin.h"
  16. #include "WinInterface.h"
  17. #include "WinConfiguration.h"
  18. #include "Setup.h"
  19. //---------------------------------------------------------------------
  20. #pragma link "GeneralSettings"
  21. #pragma link "LogSettings"
  22. #pragma link "CopyParams"
  23. #pragma link "UpDownEdit"
  24. #pragma link "ComboEdit"
  25. #ifndef NO_RESOURCES
  26. #pragma resource "*.dfm"
  27. #endif
  28. //---------------------------------------------------------------------
  29. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  30. TPreferencesDialogData * DialogData)
  31. {
  32. bool Result;
  33. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(GetFormOwner());
  34. try
  35. {
  36. PreferencesDialog->PreferencesMode = APreferencesMode;
  37. Result = PreferencesDialog->Execute(DialogData);
  38. }
  39. __finally
  40. {
  41. delete PreferencesDialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  47. : TForm(AOwner)
  48. {
  49. SetCorrectFormParent(this);
  50. FNoUpdate = 0;
  51. FPreferencesMode = ::pmDefault;
  52. FEditorFont = new TFont();
  53. FEditorFont->Color = clWindowText;
  54. // color tends to reset in object inspector
  55. EditorFontLabel->Color = clWindow;
  56. // currently useless
  57. FAfterFilenameEditDialog = false;
  58. FCustomCommandList = new TCustomCommandList();
  59. FCustomCommandChanging = false;
  60. FListViewDragDest = -1;
  61. FCopyParamList = new TCopyParamList();
  62. FEditorList = new TEditorList();
  63. UseSystemSettings(this);
  64. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  65. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  66. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView2, true);
  67. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  68. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta);
  69. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  70. LoggingFrame->Init();
  71. InstallPathWordBreakProc(RandomSeedFileEdit);
  72. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  73. InstallPathWordBreakProc(PuttyPathEdit);
  74. HintLabel(ShellIconsText);
  75. HotTrackLabel(CopyParamLabel);
  76. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  77. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  78. }
  79. //---------------------------------------------------------------------------
  80. __fastcall TPreferencesDialog::~TPreferencesDialog()
  81. {
  82. SAFE_DESTROY(FEditorScrollOnDragOver);
  83. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  84. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  85. delete FEditorFont;
  86. delete FCustomCommandList;
  87. delete FCopyParamList;
  88. delete FEditorList;
  89. }
  90. //---------------------------------------------------------------------
  91. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  92. {
  93. FDialogData = DialogData;
  94. LoadConfiguration();
  95. bool Result = (ShowModal() == mrOk);
  96. if (Result)
  97. {
  98. SaveConfiguration();
  99. }
  100. return Result;
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  104. {
  105. Tree->FullExpand();
  106. int i = 0;
  107. while (i < Tree->Items->Count)
  108. {
  109. if ((!WinConfiguration->ExpertMode &&
  110. Tree->Items->Item[i]->SelectedIndex & 128))
  111. {
  112. Tree->Items->Delete(Tree->Items->Item[i]);
  113. }
  114. else
  115. {
  116. for (int pi = 0; pi < PageControl->PageCount; pi++)
  117. {
  118. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  119. {
  120. if (PageControl->Pages[pi]->Enabled)
  121. {
  122. // gets called multiple times occasionally
  123. // (e.g. when called from upload dialog invoked by /upload)
  124. if (!PageControl->Pages[pi]->Hint.IsEmpty())
  125. {
  126. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  127. PageControl->Pages[pi]->Hint = L"";
  128. }
  129. }
  130. else
  131. {
  132. Tree->Items->Delete(Tree->Items->Item[i]);
  133. i--;
  134. }
  135. break;
  136. }
  137. }
  138. i++;
  139. }
  140. }
  141. }
  142. //---------------------------------------------------------------------------
  143. void __fastcall TPreferencesDialog::LoadConfiguration()
  144. {
  145. FNoUpdate++;
  146. try
  147. {
  148. if (FPreferencesMode != pmLogin)
  149. {
  150. LoggingFrame->LoadConfiguration();
  151. GeneralSettingsFrame->LoadConfiguration();
  152. }
  153. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  154. BOOLPROP(DefaultDirIsHome);
  155. BOOLPROP(PreservePanelState);
  156. BOOLPROP(DeleteToRecycleBin);
  157. BOOLPROP(DDTransferConfirmation);
  158. BOOLPROP(DDWarnLackOfTempSpace);
  159. BOOLPROP(ShowHiddenFiles);
  160. BOOLPROP(FormatSizeBytes);
  161. BOOLPROP(RenameWholeName);
  162. BOOLPROP(ShowInaccesibleDirectories);
  163. BOOLPROP(CopyOnDoubleClickConfirmation);
  164. BOOLPROP(ConfirmTransferring);
  165. BOOLPROP(ConfirmOverwriting);
  166. BOOLPROP(ConfirmResume);
  167. BOOLPROP(ConfirmDeleting);
  168. BOOLPROP(ConfirmRecycling);
  169. BOOLPROP(ConfirmClosingSession);
  170. BOOLPROP(ConfirmExitOnCompletion);
  171. BOOLPROP(UseLocationProfiles);
  172. BOOLPROP(ConfirmCommandSession);
  173. BOOLPROP(ContinueOnError);
  174. BOOLPROP(DDAllowMoveInit);
  175. BOOLPROP(BeepOnFinish);
  176. BOOLPROP(TemporaryDirectoryAppendSession);
  177. BOOLPROP(TemporaryDirectoryAppendPath);
  178. BOOLPROP(TemporaryDirectoryCleanup);
  179. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  180. BOOLPROP(FullRowSelect);
  181. BeepOnFinishAfterEdit->AsInteger =
  182. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  183. BOOLPROP(BalloonNotifications);
  184. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  185. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  186. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  187. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  188. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  189. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  190. {
  191. DDSystemTemporaryDirectoryButton->Checked = true;
  192. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  193. }
  194. else
  195. {
  196. DDCustomTemporaryDirectoryButton->Checked = true;
  197. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  198. }
  199. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  200. {
  201. NortonLikeModeCombo->ItemIndex = 2;
  202. }
  203. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  204. {
  205. NortonLikeModeCombo->ItemIndex = 1;
  206. }
  207. else
  208. {
  209. NortonLikeModeCombo->ItemIndex = 0;
  210. }
  211. PreserveLocalDirectoryCheck->Checked =
  212. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  213. SwappedPanelsCheck->Checked =
  214. WinConfiguration->ScpCommander.SwappedPanels;
  215. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  216. ShowFullAddressCheck->Checked =
  217. WinConfiguration->ScpExplorer.ShowFullAddress;
  218. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  219. IniFileStorageButton2->Checked = (Configuration->Storage != stRegistry);
  220. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  221. // editor
  222. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  223. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  224. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  225. {
  226. EditorEncodingCombo->ItemIndex = 1;
  227. }
  228. else
  229. {
  230. EditorEncodingCombo->ItemIndex = 0;
  231. }
  232. FEditorFont->Name = WinConfiguration->Editor.FontName;
  233. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  234. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  235. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  236. (*FEditorList) = *WinConfiguration->EditorList;
  237. UpdateEditorListView();
  238. FCopyParams = GUIConfiguration->DefaultCopyParam;
  239. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  240. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  241. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  242. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  243. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  244. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  245. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  246. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  247. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  248. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  249. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  250. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  251. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  252. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  253. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  254. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  255. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  256. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  257. StorageGroup->Visible = WinConfiguration->ExpertMode;
  258. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  259. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  260. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  261. UpdateCustomCommandsView();
  262. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  263. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  264. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  265. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  266. // Queue
  267. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  268. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  269. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  270. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  271. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  272. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  273. RememberPasswordCheck->Checked = GUIConfiguration->QueueRememberPassword;
  274. if (WinConfiguration->QueueView.Show == qvShow)
  275. {
  276. QueueViewShowButton->Checked = true;
  277. }
  278. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  279. {
  280. QueueViewHideWhenEmptyButton->Checked = true;
  281. }
  282. else
  283. {
  284. QueueViewHideButton->Checked = true;
  285. }
  286. // window
  287. if (WinConfiguration->PathInCaption == picFull)
  288. {
  289. PathInCaptionFullButton->Checked = true;
  290. }
  291. else if (WinConfiguration->PathInCaption == picShort)
  292. {
  293. PathInCaptionShortButton->Checked = true;
  294. }
  295. else
  296. {
  297. PathInCaptionNoneButton->Checked = true;
  298. }
  299. BOOLPROP(MinimizeToTray);
  300. // panels
  301. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  302. BOOLPROP(AutoReadDirectoryAfterOp);
  303. BOOLPROP(RefreshRemotePanel);
  304. RefreshRemotePanelIntervalEdit->Value =
  305. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  306. // updates
  307. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  308. if (int(Updates.Period) <= 0)
  309. {
  310. UpdatesPeriodCombo->ItemIndex = 0;
  311. }
  312. else if (int(Updates.Period) <= 1)
  313. {
  314. UpdatesPeriodCombo->ItemIndex = 1;
  315. }
  316. else if (int(Updates.Period) <= 7)
  317. {
  318. UpdatesPeriodCombo->ItemIndex = 2;
  319. }
  320. else
  321. {
  322. UpdatesPeriodCombo->ItemIndex = 3;
  323. }
  324. CollectUsageCheck->Checked = Configuration->CollectUsage;
  325. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  326. switch (Updates.ConnectionType)
  327. {
  328. case ctDirect:
  329. default:
  330. UpdatesDirectCheck->Checked = true;
  331. break;
  332. case ctAuto:
  333. UpdatesAutoCheck->Checked = true;
  334. break;
  335. case ctProxy:
  336. UpdatesProxyCheck->Checked = true;
  337. break;
  338. }
  339. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  340. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  341. // presets
  342. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  343. UpdateCopyParamListView();
  344. BOOLPROP(CopyParamAutoSelectNotice);
  345. // interface
  346. if (WinConfiguration->Theme == L"OfficeXP")
  347. {
  348. ThemeCombo->ItemIndex = 1;
  349. }
  350. else if (WinConfiguration->Theme == L"Office2003")
  351. {
  352. ThemeCombo->ItemIndex = 2;
  353. }
  354. else
  355. {
  356. ThemeCombo->ItemIndex = 0;
  357. }
  358. // security
  359. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  360. // network
  361. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  362. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  363. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  364. #undef BOOLPROP
  365. }
  366. __finally
  367. {
  368. FNoUpdate--;
  369. }
  370. UpdateControls();
  371. }
  372. //---------------------------------------------------------------------------
  373. void __fastcall TPreferencesDialog::SaveConfiguration()
  374. {
  375. Configuration->BeginUpdate();
  376. try
  377. {
  378. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  379. if (FPreferencesMode != pmLogin)
  380. {
  381. LoggingFrame->SaveConfiguration();
  382. GeneralSettingsFrame->SaveConfiguration();
  383. }
  384. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  385. BOOLPROP(DefaultDirIsHome);
  386. BOOLPROP(PreservePanelState);
  387. BOOLPROP(DeleteToRecycleBin);
  388. BOOLPROP(DDTransferConfirmation);
  389. BOOLPROP(DDWarnLackOfTempSpace);
  390. BOOLPROP(ShowHiddenFiles);
  391. BOOLPROP(FormatSizeBytes);
  392. BOOLPROP(RenameWholeName);
  393. BOOLPROP(ShowInaccesibleDirectories);
  394. BOOLPROP(CopyOnDoubleClickConfirmation);
  395. BOOLPROP(ConfirmTransferring);
  396. BOOLPROP(ConfirmOverwriting);
  397. BOOLPROP(ConfirmResume);
  398. BOOLPROP(ConfirmDeleting);
  399. BOOLPROP(ConfirmRecycling);
  400. BOOLPROP(ConfirmClosingSession);
  401. BOOLPROP(ConfirmExitOnCompletion);
  402. BOOLPROP(UseLocationProfiles);
  403. BOOLPROP(ConfirmCommandSession);
  404. BOOLPROP(ContinueOnError);
  405. BOOLPROP(DDAllowMoveInit);
  406. BOOLPROP(BeepOnFinish);
  407. BOOLPROP(TemporaryDirectoryAppendSession);
  408. BOOLPROP(TemporaryDirectoryAppendPath);
  409. BOOLPROP(TemporaryDirectoryCleanup);
  410. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  411. BOOLPROP(FullRowSelect);
  412. GUIConfiguration->BeepOnFinishAfter =
  413. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  414. BOOLPROP(BalloonNotifications);
  415. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  416. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  417. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  418. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  419. if (DDSystemTemporaryDirectoryButton->Checked)
  420. {
  421. WinConfiguration->DDTemporaryDirectory = L"";
  422. }
  423. else
  424. {
  425. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  426. }
  427. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  428. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  429. if (NortonLikeModeCombo->ItemIndex == 2)
  430. {
  431. ScpCommander.NortonLikeMode = nlOff;
  432. }
  433. else if (NortonLikeModeCombo->ItemIndex == 1)
  434. {
  435. ScpCommander.NortonLikeMode = nlKeyboard;
  436. }
  437. else
  438. {
  439. ScpCommander.NortonLikeMode = nlOn;
  440. }
  441. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  442. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  443. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  444. WinConfiguration->ScpCommander = ScpCommander;
  445. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  446. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  447. WinConfiguration->ScpExplorer = ScpExplorer;
  448. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  449. // editor
  450. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  451. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  452. switch (EditorEncodingCombo->ItemIndex)
  453. {
  454. case 1:
  455. WinConfiguration->Editor.Encoding = CP_UTF8;
  456. break;
  457. default:
  458. WinConfiguration->Editor.Encoding = CP_ACP;
  459. break;
  460. }
  461. WinConfiguration->Editor.FontName = FEditorFont->Name;
  462. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  463. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  464. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  465. WinConfiguration->EditorList = FEditorList;
  466. // overwrites only TCopyParamType fields
  467. CopyParam = FCopyParams;
  468. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  469. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  470. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  471. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  472. Configuration->SessionReopenAuto =
  473. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  474. GUIConfiguration->SessionReopenAutoIdle =
  475. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  476. Configuration->SessionReopenAutoStall =
  477. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  478. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  479. WinConfiguration->CustomCommandList = FCustomCommandList;
  480. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  481. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  482. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  483. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  484. // Queue
  485. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  486. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  487. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  488. CopyParam.Queue = QueueCheck->Checked;
  489. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  490. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  491. GUIConfiguration->QueueRememberPassword = RememberPasswordCheck->Checked;
  492. if (QueueViewShowButton->Checked)
  493. {
  494. WinConfiguration->QueueView.Show = qvShow;
  495. }
  496. else if (QueueViewHideWhenEmptyButton->Checked)
  497. {
  498. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  499. }
  500. else
  501. {
  502. WinConfiguration->QueueView.Show = qvHide;
  503. }
  504. GUIConfiguration->DefaultCopyParam = CopyParam;
  505. // window
  506. if (PathInCaptionFullButton->Checked)
  507. {
  508. WinConfiguration->PathInCaption = picFull;
  509. }
  510. else if (PathInCaptionShortButton->Checked)
  511. {
  512. WinConfiguration->PathInCaption = picShort;
  513. }
  514. else
  515. {
  516. WinConfiguration->PathInCaption = picNone;
  517. }
  518. BOOLPROP(MinimizeToTray);
  519. // panels
  520. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  521. BOOLPROP(AutoReadDirectoryAfterOp);
  522. BOOLPROP(RefreshRemotePanel);
  523. WinConfiguration->RefreshRemotePanelInterval =
  524. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  525. // updates
  526. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  527. if (UpdatesPeriodCombo->ItemIndex == 0)
  528. {
  529. Updates.Period = 0;
  530. }
  531. else if (UpdatesPeriodCombo->ItemIndex == 1)
  532. {
  533. Updates.Period = 1;
  534. }
  535. else if (UpdatesPeriodCombo->ItemIndex == 2)
  536. {
  537. Updates.Period = 7;
  538. }
  539. else
  540. {
  541. Updates.Period = 30;
  542. }
  543. Configuration->CollectUsage = CollectUsageCheck->Checked;
  544. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  545. if (UpdatesDirectCheck->Checked)
  546. {
  547. Updates.ConnectionType = ctDirect;
  548. }
  549. else if (UpdatesAutoCheck->Checked)
  550. {
  551. Updates.ConnectionType = ctAuto;
  552. }
  553. else if (UpdatesProxyCheck->Checked)
  554. {
  555. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  556. {
  557. Updates.ConnectionType = ctProxy;
  558. }
  559. else
  560. {
  561. Updates.ConnectionType = ctDirect;
  562. }
  563. }
  564. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  565. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  566. WinConfiguration->Updates = Updates;
  567. // presets
  568. WinConfiguration->CopyParamList = FCopyParamList;
  569. BOOLPROP(CopyParamAutoSelectNotice);
  570. // interface
  571. if (ThemeCombo->ItemIndex == 1)
  572. {
  573. WinConfiguration->Theme = L"OfficeXP";
  574. }
  575. else if (ThemeCombo->ItemIndex == 2)
  576. {
  577. WinConfiguration->Theme = L"Office2003";
  578. }
  579. else
  580. {
  581. WinConfiguration->Theme = L"Default";
  582. }
  583. // network
  584. Configuration->ExternalIpAddress =
  585. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  586. #undef BOOLPROP
  587. }
  588. __finally
  589. {
  590. Configuration->EndUpdate();
  591. }
  592. }
  593. //---------------------------------------------------------------------------
  594. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  595. {
  596. if (PreferencesMode != value)
  597. {
  598. FPreferencesMode = value;
  599. GeneralSheet->Enabled = (value != pmLogin);
  600. LogSheet->Enabled = (value != pmLogin);
  601. }
  602. }
  603. //---------------------------------------------------------------------------
  604. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  605. {
  606. PrepareNavigationTree(NavigationTree);
  607. switch (PreferencesMode) {
  608. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  609. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  610. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  611. case pmTransfer: PageControl->ActivePage = TransferSheet; break;
  612. case pmLogging: PageControl->ActivePage = LogSheet; break;
  613. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  614. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  615. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  616. default: PageControl->ActivePage = PreferencesSheet; break;
  617. }
  618. PageControlChange(NULL);
  619. }
  620. //---------------------------------------------------------------------------
  621. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  622. {
  623. UpdateControls();
  624. }
  625. //---------------------------------------------------------------------------
  626. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  627. {
  628. UnicodeString Result;
  629. for (int Index = 1; Index <= Values.Length(); Index++)
  630. {
  631. if (Index > 1)
  632. {
  633. Result += L' ';
  634. if (EditorTabSizeEdit->AsInteger > 2)
  635. {
  636. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  637. }
  638. }
  639. Result += Values[Index];
  640. }
  641. return Result;
  642. }
  643. //---------------------------------------------------------------------------
  644. void __fastcall TPreferencesDialog::UpdateControls()
  645. {
  646. if (FNoUpdate == 0)
  647. {
  648. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  649. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  650. EnableControl(BalloonNotificationsCheck, ::TTrayIcon::SupportsBalloons());
  651. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  652. EnableControl(ResumeThresholdUnitLabel, ResumeThresholdEdit->Enabled);
  653. EnableControl(SessionReopenAutoEdit,
  654. SessionReopenAutoCheck->Checked || SessionReopenAutoIdleCheck->Checked);
  655. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  656. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  657. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  658. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  659. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  660. EnableControl(SessionReopenTimeoutEdit,
  661. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  662. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  663. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  664. EnableControl(CopyOnDoubleClickConfirmationCheck,
  665. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  666. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  667. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  668. UnicodeString EditorFontLabelText;
  669. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  670. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  671. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  672. EditorFontLabelText += TabSample(L"1234");
  673. EditorFontLabel->Caption = EditorFontLabelText;
  674. EditorFontLabel->Font = FEditorFont;
  675. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  676. EnableControl(EditCommandButton, CommandSelected);
  677. EnableControl(RemoveCommandButton, CommandSelected);
  678. EnableControl(UpCommandButton, CommandSelected &&
  679. CustomCommandsView->ItemIndex > 0);
  680. EnableControl(DownCommandButton, CommandSelected &&
  681. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  682. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  683. EnableControl(EditCopyParamButton, CopyParamSelected);
  684. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  685. EnableControl(RemoveCopyParamButton, CopyParamSelected);
  686. EnableControl(UpCopyParamButton, CopyParamSelected &&
  687. (CopyParamListView->ItemIndex > 0));
  688. EnableControl(DownCopyParamButton, CopyParamSelected &&
  689. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  690. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  691. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  692. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  693. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  694. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  695. DDCustomTemporaryDirectoryButton->Checked);
  696. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  697. DDAllowMoveInitCheck->Checked);
  698. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  699. TemporaryDirectoryCleanupCheck->Checked);
  700. IniFileStorageButton2->Caption =
  701. AnsiReplaceStr(IniFileStorageButton2->Caption, L"winscp.ini",
  702. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName)));
  703. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  704. bool EditorSelected = (EditorListView2->Selected != NULL);
  705. EnableControl(EditEditorButton, EditorSelected);
  706. EnableControl(RemoveEditorButton, EditorSelected);
  707. EnableControl(UpEditorButton, EditorSelected &&
  708. (EditorListView2->ItemIndex > 0));
  709. EnableControl(DownEditorButton, EditorSelected &&
  710. (EditorListView2->ItemIndex < EditorListView2->Items->Count - 1));
  711. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  712. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  713. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  714. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  715. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  716. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  717. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  718. EnableControl(TelnetForFtpInPuttyCheck, PuttyPasswordCheck2->Enabled);
  719. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  720. // network
  721. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  722. // transfer
  723. UnicodeString InfoStr = FCopyParams.GetInfoStr(L"; ", 0);
  724. CopyParamLabel->Caption = InfoStr;
  725. CopyParamLabel->Hint = InfoStr;
  726. CopyParamLabel->ShowHint =
  727. (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
  728. }
  729. }
  730. //---------------------------------------------------------------------------
  731. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  732. {
  733. if (FontDialog(FEditorFont))
  734. {
  735. UpdateControls();
  736. }
  737. }
  738. //---------------------------------------------------------------------------
  739. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  740. bool & /*CanClose*/)
  741. {
  742. if (ModalResult != mrCancel)
  743. {
  744. ExitActiveControl(this);
  745. }
  746. }
  747. //---------------------------------------------------------------------------
  748. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  749. {
  750. UnicodeString IconName, Params;
  751. int SpecialFolder;
  752. if (Sender == DesktopIconButton)
  753. {
  754. IconName = AppName;
  755. int Result =
  756. MessageDialog(LoadStr(CREATE_DESKTOP_ICON), qtConfirmation,
  757. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  758. switch (Result)
  759. {
  760. case qaYes:
  761. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  762. break;
  763. case qaNo:
  764. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  765. break;
  766. default:
  767. Abort();
  768. break;
  769. }
  770. }
  771. else
  772. {
  773. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  774. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  775. {
  776. if (Sender == SendToHookButton)
  777. {
  778. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppName));
  779. SpecialFolder = CSIDL_SENDTO;
  780. Params = L"/upload";
  781. }
  782. else if (Sender == QuickLaunchIconButton)
  783. {
  784. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  785. AppName;
  786. SpecialFolder = CSIDL_APPDATA;
  787. }
  788. }
  789. else
  790. {
  791. Abort();
  792. }
  793. }
  794. CreateDesktopShortCut(IconName,
  795. Application->ExeName, Params, L"", SpecialFolder);
  796. }
  797. //---------------------------------------------------------------------------
  798. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  799. TListItem * Item)
  800. {
  801. assert(FCustomCommandList != NULL);
  802. int Index = Item->Index;
  803. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  804. const TCustomCommandType * Command = FCustomCommandList->Commands[Index];
  805. UnicodeString Caption = StripHotkey(Command->Name);
  806. if (Command->ShortCut != 0)
  807. {
  808. Caption = FORMAT(L"%s (%s)", (Caption, ShortCutToText(Command->ShortCut)));
  809. }
  810. Item->Caption = Caption;
  811. assert(!Item->SubItems->Count);
  812. Item->SubItems->Add(Command->Command);
  813. int Params = Command->Params;
  814. Item->SubItems->Add(LoadStr(
  815. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  816. UnicodeString ParamsStr;
  817. #define ADDPARAM(PARAM, STR) \
  818. if (FLAGSET(Params, PARAM)) \
  819. ParamsStr += (ParamsStr.IsEmpty() ? L"" : L"/") + LoadStr(STR);
  820. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  821. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  822. #undef ADDPARAM
  823. Item->SubItems->Add(ParamsStr);
  824. }
  825. //---------------------------------------------------------------------------
  826. void __fastcall TPreferencesDialog::ListViewSelectItem(
  827. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  828. {
  829. UpdateControls();
  830. }
  831. //---------------------------------------------------------------------------
  832. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  833. {
  834. CustomCommandsView->Items->Count = FCustomCommandList->Count;
  835. AdjustListColumnsWidth(CustomCommandsView, FCustomCommandList->Count);
  836. CustomCommandsView->Invalidate();
  837. }
  838. //---------------------------------------------------------------------------
  839. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  840. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  841. {
  842. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  843. {
  844. RemoveCommandButtonClick(NULL);
  845. }
  846. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  847. {
  848. AddEditCommandButtonClick(AddCommandButton);
  849. }
  850. }
  851. //---------------------------------------------------------------------------
  852. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  853. TObject * /*Sender*/)
  854. {
  855. if (EditCommandButton->Enabled)
  856. {
  857. AddEditCommandButtonClick(EditCommandButton);
  858. }
  859. }
  860. //---------------------------------------------------------------------------
  861. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  862. {
  863. bool Edit = (Sender == EditCommandButton);
  864. TCustomCommandType Command;
  865. if (Edit)
  866. {
  867. int Index = CustomCommandsView->ItemIndex;
  868. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  869. Command = *FCustomCommandList->Commands[Index];
  870. }
  871. TShortCuts ShortCuts;
  872. if (WinConfiguration->SharedBookmarks != NULL)
  873. {
  874. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  875. }
  876. FCustomCommandList->ShortCuts(ShortCuts);
  877. if (DoCustomCommandDialog(Command, FCustomCommandList,
  878. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  879. {
  880. int Index = CustomCommandsView->ItemIndex;
  881. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  882. if (Edit)
  883. {
  884. FCustomCommandList->Change(Index, ACommand);
  885. }
  886. else
  887. {
  888. if (Index >= 0)
  889. {
  890. FCustomCommandList->Insert(Index, ACommand);
  891. }
  892. else
  893. {
  894. FCustomCommandList->Add(ACommand);
  895. Index = FCustomCommandList->Count - 1;
  896. }
  897. }
  898. UpdateCustomCommandsView();
  899. CustomCommandsView->ItemIndex = Index;
  900. UpdateControls();
  901. }
  902. }
  903. //---------------------------------------------------------------------------
  904. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  905. TObject * /*Sender*/)
  906. {
  907. assert(CustomCommandsView->ItemIndex >= 0 &&
  908. CustomCommandsView->ItemIndex < FCustomCommandList->Count);
  909. FCustomCommandList->Delete(CustomCommandsView->ItemIndex);
  910. UpdateCustomCommandsView();
  911. UpdateControls();
  912. }
  913. //---------------------------------------------------------------------------
  914. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  915. {
  916. if (Source >= 0 && Source < FCustomCommandList->Count &&
  917. Dest >= 0 && Dest < FCustomCommandList->Count)
  918. {
  919. FCustomCommandList->Move(Source, Dest);
  920. // workaround for bug in VCL
  921. CustomCommandsView->ItemIndex = -1;
  922. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  923. CustomCommandsView->ItemIndex = Dest;
  924. UpdateCustomCommandsView();
  925. UpdateControls();
  926. }
  927. }
  928. //---------------------------------------------------------------------------
  929. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  930. {
  931. CustomCommandMove(CustomCommandsView->ItemIndex,
  932. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  933. }
  934. //---------------------------------------------------------------------------
  935. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  936. {
  937. if (ListView == CopyParamListView)
  938. {
  939. return FCopyParamScrollOnDragOver;
  940. }
  941. else if (ListView == CustomCommandsView)
  942. {
  943. return FCustomCommandsScrollOnDragOver;
  944. }
  945. else if (ListView == EditorListView2)
  946. {
  947. return FEditorScrollOnDragOver;
  948. }
  949. else
  950. {
  951. assert(false);
  952. return NULL;
  953. }
  954. }
  955. //---------------------------------------------------------------------------
  956. void __fastcall TPreferencesDialog::ListViewStartDrag(
  957. TObject * Sender, TDragObject *& /*DragObject*/)
  958. {
  959. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  960. FListViewDragDest = -1;
  961. ScrollOnDragOver(Sender)->StartDrag();
  962. }
  963. //---------------------------------------------------------------------------
  964. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  965. {
  966. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  967. FListViewDragDest = Item ? Item->Index : -1;
  968. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  969. }
  970. //---------------------------------------------------------------------------
  971. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  972. TObject * Sender, TObject * Source, int X, int Y)
  973. {
  974. if (Source == CustomCommandsView)
  975. {
  976. if (AllowListViewDrag(Sender, X, Y))
  977. {
  978. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  979. }
  980. }
  981. }
  982. //---------------------------------------------------------------------------
  983. void __fastcall TPreferencesDialog::ListViewDragOver(
  984. TObject * Sender, TObject * Source, int X, int Y,
  985. TDragState /*State*/, bool & Accept)
  986. {
  987. if (Source == Sender)
  988. {
  989. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  990. // (when dropped on item itself, when it was dragged over another item before,
  991. // that another item remains highlighted forever)
  992. Accept = true;
  993. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  994. }
  995. }
  996. //---------------------------------------------------------------------------
  997. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  998. {
  999. if (Source >= 0 && Source < FCopyParamList->Count &&
  1000. Dest >= 0 && Dest < FCopyParamList->Count)
  1001. {
  1002. FCopyParamList->Move(Source, Dest);
  1003. // workaround for bug in VCL
  1004. CopyParamListView->ItemIndex = -1;
  1005. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1006. CopyParamListView->ItemIndex = Dest;
  1007. UpdateCopyParamListView();
  1008. UpdateControls();
  1009. }
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1013. TObject * Sender, TObject * Source, int X, int Y)
  1014. {
  1015. if (Source == CopyParamListView)
  1016. {
  1017. if (AllowListViewDrag(Sender, X, Y))
  1018. {
  1019. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1020. }
  1021. }
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1025. {
  1026. CopyParamMove(CopyParamListView->ItemIndex,
  1027. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1031. TObject * /*Sender*/)
  1032. {
  1033. assert(CopyParamListView->ItemIndex >= 0 &&
  1034. CopyParamListView->ItemIndex < FCopyParamList->Count);
  1035. FCopyParamList->Delete(CopyParamListView->ItemIndex);
  1036. UpdateCopyParamListView();
  1037. UpdateControls();
  1038. }
  1039. //---------------------------------------------------------------------------
  1040. void __fastcall TPreferencesDialog::AddEditCopyParamButtonClick(
  1041. TObject * Sender)
  1042. {
  1043. TCopyParamPresetMode Mode;
  1044. if (Sender == EditCopyParamButton)
  1045. {
  1046. Mode = cpmEdit;
  1047. }
  1048. else if (Sender == DuplicateCopyParamButton)
  1049. {
  1050. Mode = cpmDuplicate;
  1051. }
  1052. else
  1053. {
  1054. Mode = cpmAdd;
  1055. }
  1056. int Index = CopyParamListView->ItemIndex;
  1057. TCopyParamRuleData * CopyParamRuleData =
  1058. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1059. if (DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData))
  1060. {
  1061. UpdateCopyParamListView();
  1062. CopyParamListView->ItemIndex = Index;
  1063. // when using duplicate button, focu remains on original item
  1064. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1065. UpdateControls();
  1066. }
  1067. }
  1068. //---------------------------------------------------------------------------
  1069. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1070. TObject * /*Sender*/)
  1071. {
  1072. if (EditCopyParamButton->Enabled)
  1073. {
  1074. AddEditCopyParamButtonClick(EditCopyParamButton);
  1075. }
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1079. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1080. {
  1081. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1082. {
  1083. RemoveCopyParamButtonClick(NULL);
  1084. }
  1085. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1086. {
  1087. AddEditCopyParamButtonClick(AddCopyParamButton);
  1088. }
  1089. }
  1090. //---------------------------------------------------------------------------
  1091. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1092. {
  1093. if (Source >= 0 && Source < FEditorList->Count &&
  1094. Dest >= 0 && Dest < FEditorList->Count)
  1095. {
  1096. FEditorList->Move(Source, Dest);
  1097. // workaround for bug in VCL
  1098. EditorListView2->ItemIndex = -1;
  1099. EditorListView2->ItemFocused = EditorListView2->Selected;
  1100. EditorListView2->ItemIndex = Dest;
  1101. UpdateEditorListView();
  1102. UpdateControls();
  1103. }
  1104. }
  1105. //---------------------------------------------------------------------------
  1106. void __fastcall TPreferencesDialog::EditorListView2DragDrop(TObject * Sender,
  1107. TObject * Source, int X, int Y)
  1108. {
  1109. if (Source == EditorListView2)
  1110. {
  1111. if (AllowListViewDrag(Sender, X, Y))
  1112. {
  1113. EditorMove(FListViewDragSource, FListViewDragDest);
  1114. }
  1115. }
  1116. }
  1117. //---------------------------------------------------------------------------
  1118. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1119. {
  1120. EditorMove(EditorListView2->ItemIndex,
  1121. EditorListView2->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1122. }
  1123. //---------------------------------------------------------------------------
  1124. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1125. TObject * /*Sender*/)
  1126. {
  1127. assert(EditorListView2->ItemIndex >= 0 &&
  1128. EditorListView2->ItemIndex < FEditorList->Count);
  1129. FEditorList->Delete(EditorListView2->ItemIndex);
  1130. UpdateEditorListView();
  1131. UpdateControls();
  1132. }
  1133. //---------------------------------------------------------------------------
  1134. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1135. {
  1136. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1137. int Index = EditorListView2->ItemIndex;
  1138. TEditorPreferences * Editor;
  1139. if (Mode == epmEdit)
  1140. {
  1141. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1142. }
  1143. else
  1144. {
  1145. Editor = new TEditorPreferences();
  1146. }
  1147. try
  1148. {
  1149. bool DummyRemember = false;
  1150. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1151. {
  1152. if (Mode == epmEdit)
  1153. {
  1154. FEditorList->Change(Index, Editor);
  1155. }
  1156. else
  1157. {
  1158. if (Index < 0)
  1159. {
  1160. Index = FEditorList->Count;
  1161. FEditorList->Add(Editor);
  1162. }
  1163. else
  1164. {
  1165. FEditorList->Insert(Index, Editor);
  1166. }
  1167. }
  1168. // ownership of the object lost
  1169. Editor = NULL;
  1170. UpdateEditorListView();
  1171. EditorListView2->ItemIndex = Index;
  1172. UpdateControls();
  1173. }
  1174. }
  1175. __finally
  1176. {
  1177. delete Editor;
  1178. }
  1179. }
  1180. //---------------------------------------------------------------------------
  1181. void __fastcall TPreferencesDialog::EditorListView2DblClick(TObject * /*Sender*/)
  1182. {
  1183. if (EditEditorButton->Enabled)
  1184. {
  1185. AddEditEditorButtonClick(EditEditorButton);
  1186. }
  1187. }
  1188. //---------------------------------------------------------------------------
  1189. void __fastcall TPreferencesDialog::EditorListView2KeyDown(TObject * /*Sender*/,
  1190. WORD & Key, TShiftState /*Shift*/)
  1191. {
  1192. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1193. {
  1194. RemoveEditorButtonClick(NULL);
  1195. }
  1196. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1197. {
  1198. AddEditEditorButtonClick(AddEditorButton);
  1199. }
  1200. }
  1201. //---------------------------------------------------------------------------
  1202. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1203. {
  1204. EditorListView2->Items->Count = FEditorList->Count;
  1205. AdjustListColumnsWidth(EditorListView2, FEditorList->Count);
  1206. EditorListView2->Invalidate();
  1207. }
  1208. //---------------------------------------------------------------------------
  1209. void __fastcall TPreferencesDialog::EditorListView2Data(TObject * /*Sender*/,
  1210. TListItem * Item)
  1211. {
  1212. int Index = Item->Index;
  1213. assert(Index >= 0 && Index <= FEditorList->Count);
  1214. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1215. Item->Caption = Editor->Data->FileMask.Masks;
  1216. Item->SubItems->Add(Editor->Name);
  1217. if (Editor->Data->Editor == edExternal)
  1218. {
  1219. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1220. }
  1221. }
  1222. //---------------------------------------------------------------------------
  1223. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1224. TTreeNode *Node)
  1225. {
  1226. if (Node->SelectedIndex)
  1227. {
  1228. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  1229. {
  1230. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  1231. {
  1232. PageControl->ActivePage = PageControl->Pages[Index];
  1233. // reshow the accelerators, etc
  1234. ResetSystemSettings(this);
  1235. return;
  1236. }
  1237. }
  1238. }
  1239. assert(false);
  1240. }
  1241. //---------------------------------------------------------------------------
  1242. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1243. {
  1244. bool Found = false;
  1245. if (PageControl->ActivePage->Tag)
  1246. {
  1247. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1248. {
  1249. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  1250. PageControl->ActivePage->Tag)
  1251. {
  1252. NavigationTree->Items->Item[Index]->Selected = true;
  1253. Found = true;
  1254. }
  1255. }
  1256. }
  1257. assert(Found);
  1258. if (Found)
  1259. {
  1260. UpdateControls();
  1261. }
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1265. {
  1266. if (Message.CharCode == VK_TAB)
  1267. {
  1268. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1269. if (Shift.Contains(ssCtrl))
  1270. {
  1271. TTreeNode * Node = NavigationTree->Selected;
  1272. if (!Shift.Contains(ssShift))
  1273. {
  1274. Node = Node->GetNext();
  1275. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1276. }
  1277. else
  1278. {
  1279. if (Node->GetPrev()) Node = Node->GetPrev();
  1280. else
  1281. while (Node->GetNext()) Node = Node->GetNext();
  1282. }
  1283. Node->Selected = True;
  1284. Message.Result = 1;
  1285. return;
  1286. }
  1287. }
  1288. TForm::Dispatch(&Message);
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1292. {
  1293. assert(Message.HelpInfo != NULL);
  1294. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1295. {
  1296. // invoke help for active page (not for whole form), regardless of focus
  1297. // (e.g. even if focus is on control outside pagecontrol)
  1298. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1299. }
  1300. TForm::Dispatch(&Message);
  1301. }
  1302. //---------------------------------------------------------------------------
  1303. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1304. {
  1305. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1306. assert(M);
  1307. if (M->Msg == CM_DIALOGKEY)
  1308. {
  1309. CMDialogKey(*((TWMKeyDown *)Message));
  1310. }
  1311. else if (M->Msg == WM_HELP)
  1312. {
  1313. WMHelp(*((TWMHelp *)Message));
  1314. }
  1315. else
  1316. {
  1317. TForm::Dispatch(Message);
  1318. }
  1319. }
  1320. //---------------------------------------------------------------------------
  1321. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  1322. TObject * /*Sender*/)
  1323. {
  1324. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  1325. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL) == qaYes)
  1326. {
  1327. RegisterAsUrlHandler();
  1328. }
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1332. {
  1333. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1334. SetFocus();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1338. TObject * /*Sender*/)
  1339. {
  1340. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1341. if (MessageDialog(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath)),
  1342. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1343. {
  1344. AddSearchPath(AppPath);
  1345. }
  1346. }
  1347. //---------------------------------------------------------------------------
  1348. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1349. TObject * Sender)
  1350. {
  1351. EditorFontButtonClick(Sender);
  1352. }
  1353. //---------------------------------------------------------------------------
  1354. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1355. {
  1356. CopyParamListView->Items->Count = FCopyParamList->Count;
  1357. AdjustListColumnsWidth(CopyParamListView, FCopyParamList->Count);
  1358. CopyParamListView->Invalidate();
  1359. }
  1360. //---------------------------------------------------------------------------
  1361. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1362. TListItem * Item)
  1363. {
  1364. int Index = Item->Index;
  1365. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1366. Item->Caption = StripHotkey(FCopyParamList->Names[Index]);
  1367. Item->SubItems->Add(BooleanToStr(FCopyParamList->Rules[Index] != NULL));
  1368. }
  1369. //---------------------------------------------------------------------------
  1370. void __fastcall TPreferencesDialog::CopyParamListViewInfoTip(
  1371. TObject * /*Sender*/, TListItem * Item, UnicodeString & InfoTip)
  1372. {
  1373. int Index = Item->Index;
  1374. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1375. const TCopyParamType * CopyParam = FCopyParamList->CopyParams[Index];
  1376. const TCopyParamRule * Rule = FCopyParamList->Rules[Index];
  1377. InfoTip = CopyParam->GetInfoStr(L"; ", 0);
  1378. if (Rule != NULL)
  1379. {
  1380. InfoTip += L"\n-\n" + Rule->GetInfoStr(L"; ");
  1381. }
  1382. }
  1383. //---------------------------------------------------------------------------
  1384. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1385. {
  1386. FormHelp(this);
  1387. }
  1388. //---------------------------------------------------------------------------
  1389. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1390. TObject * /*Sender*/)
  1391. {
  1392. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY),
  1393. LoadStr(PREFERENCES_PUTTY_FILTER), false, false);
  1394. }
  1395. //---------------------------------------------------------------------------
  1396. void __fastcall TPreferencesDialog::PuttyPathResetButtonClick(
  1397. TObject * /*Sender*/)
  1398. {
  1399. PuttyPathEdit->Text = WinConfiguration->DefaultPuttyPath;
  1400. }
  1401. //---------------------------------------------------------------------------
  1402. void __fastcall TPreferencesDialog::ExportButtonClick(TObject * /*Sender*/)
  1403. {
  1404. UnicodeString PersonalDirectory;
  1405. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
  1406. UnicodeString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1407. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
  1408. if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), L"ini", FileName))
  1409. {
  1410. Configuration->Export(FileName);
  1411. }
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1415. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1416. {
  1417. FBeforeDialogPath = Name;
  1418. Name = ExpandEnvironmentVariables(Name);
  1419. }
  1420. //---------------------------------------------------------------------------
  1421. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1422. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1423. {
  1424. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1425. {
  1426. Name = FBeforeDialogPath;
  1427. }
  1428. }
  1429. //---------------------------------------------------------------------------
  1430. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1431. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1432. {
  1433. AllowCollapse = false;
  1434. }
  1435. //---------------------------------------------------------------------------
  1436. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1437. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1438. {
  1439. ScrollOnDragOver(Sender)->EndDrag();
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TPreferencesDialog::RandomSeedFileEditCreateEditDialog(
  1443. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1444. {
  1445. USEDPARAM(DialogKind);
  1446. assert(DialogKind == dkOpen);
  1447. Dialog = new TOpenDialog(dynamic_cast<TComponent *>(Sender));
  1448. }
  1449. //---------------------------------------------------------------------------
  1450. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1451. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  1452. {
  1453. if (Value == 0)
  1454. {
  1455. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1456. Handled = true;
  1457. }
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1461. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  1462. {
  1463. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1464. {
  1465. Value = 0;
  1466. Handled = true;
  1467. }
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  1471. TObject * /*Sender*/)
  1472. {
  1473. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  1474. {
  1475. try
  1476. {
  1477. if (UseMasterPasswordCheck->Checked)
  1478. {
  1479. if (DoChangeMasterPasswordDialog())
  1480. {
  1481. MessageDialog(LoadStr(MASTER_PASSWORD_SET), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1482. }
  1483. }
  1484. else
  1485. {
  1486. if (DoMasterPasswordDialog())
  1487. {
  1488. WinConfiguration->ClearMasterPassword();
  1489. MessageDialog(LoadStr(MASTER_PASSWORD_CLEARED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1490. }
  1491. }
  1492. }
  1493. __finally
  1494. {
  1495. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  1496. UpdateControls();
  1497. }
  1498. }
  1499. }
  1500. //---------------------------------------------------------------------------
  1501. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  1502. TObject * /*Sender*/)
  1503. {
  1504. if (DoChangeMasterPasswordDialog())
  1505. {
  1506. MessageDialog(LoadStr(MASTER_PASSWORD_CHANGED), qtInformation, qaOK, HELP_MASTER_PASSWORD);
  1507. }
  1508. }
  1509. //---------------------------------------------------------------------------
  1510. void __fastcall TPreferencesDialog::CopyParamGroupClick(TObject * /*Sender*/)
  1511. {
  1512. if (DoCopyParamCustomDialog(FCopyParams, 0))
  1513. {
  1514. UpdateControls();
  1515. }
  1516. }
  1517. //---------------------------------------------------------------------------
  1518. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  1519. {
  1520. TStrings * Data = new TStringList();
  1521. try
  1522. {
  1523. Data->Text = GetUsageData();
  1524. UnicodeString Message =
  1525. LoadStr(Data->Text.IsEmpty() ? USAGE_DATA_NONE : USAGE_DATA);
  1526. MoreMessageDialog(Message, Data, qtInformation, qaOK, HELP_USAGE);
  1527. }
  1528. __finally
  1529. {
  1530. delete Data;
  1531. }
  1532. }
  1533. //---------------------------------------------------------------------------