1
0

Preferences.cpp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192
  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. #include "ProgParams.h"
  20. //---------------------------------------------------------------------
  21. #pragma link "CopyParams"
  22. #pragma link "UpDownEdit"
  23. #pragma link "ComboEdit"
  24. #ifndef NO_RESOURCES
  25. #pragma link "HistoryComboBox"
  26. #pragma resource "*.dfm"
  27. #endif
  28. //---------------------------------------------------------------------
  29. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  30. TPreferencesDialogData * DialogData)
  31. {
  32. bool Result;
  33. TPreferencesDialog * PreferencesDialog =
  34. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  35. try
  36. {
  37. Result = PreferencesDialog->Execute(DialogData);
  38. if (Result)
  39. {
  40. Configuration->SaveExplicit();
  41. }
  42. }
  43. __finally
  44. {
  45. delete PreferencesDialog;
  46. }
  47. return Result;
  48. }
  49. //---------------------------------------------------------------------
  50. __fastcall TPreferencesDialog::TPreferencesDialog(
  51. TComponent* AOwner, TPreferencesMode PreferencesMode)
  52. : TForm(AOwner)
  53. {
  54. SetCorrectFormParent(this);
  55. FNoUpdate = 0;
  56. FPreferencesMode = PreferencesMode;
  57. FEditorFont.reset(new TFont());
  58. FEditorFont->Color = clWindowText;
  59. FPanelFont.reset(new TFont());
  60. FPanelFont->Color = clWindowText;
  61. // currently useless
  62. FAfterFilenameEditDialog = false;
  63. FCustomCommandList = new TCustomCommandList();
  64. FCustomCommandChanging = false;
  65. FListViewDragDest = -1;
  66. FCopyParamList = new TCopyParamList();
  67. FEditorList = new TEditorList();
  68. UseSystemSettings(this);
  69. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  70. FixListColumnWidth(CustomCommandsView, -2);
  71. FixListColumnWidth(CustomCommandsView, -1);
  72. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  73. FixListColumnWidth(CopyParamListView, -1);
  74. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  75. FixListColumnWidth(EditorListView3, -1);
  76. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  77. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta);
  78. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  79. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  80. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  81. HintLabel(ShellIconsText2);
  82. HotTrackLabel(CopyParamLabel);
  83. HintLabel(PuttyPathHintText, LoadStr(PUTTY_PATTERNS_HINT));
  84. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  85. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  86. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  87. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  88. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  89. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  90. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  91. MenuButton(RegisterAsUrlHandlersButton);
  92. }
  93. //---------------------------------------------------------------------------
  94. __fastcall TPreferencesDialog::~TPreferencesDialog()
  95. {
  96. SAFE_DESTROY(FEditorScrollOnDragOver);
  97. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  98. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  99. delete FCustomCommandList;
  100. FCustomCommandList = NULL;
  101. delete FCopyParamList;
  102. FCopyParamList = NULL;
  103. delete FEditorList;
  104. FEditorList = NULL;
  105. }
  106. //---------------------------------------------------------------------
  107. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  108. {
  109. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  110. FDialogData = DialogData;
  111. LoadConfiguration();
  112. bool Result = (ShowModal() == DefaultResult(this));
  113. if (Result)
  114. {
  115. SaveConfiguration();
  116. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  117. }
  118. return Result;
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TPreferencesDialog::LoadLanguages()
  122. {
  123. if (!FLanguagesLoaded)
  124. {
  125. LanguagesView->Items->Clear();
  126. TStrings * Locales = GUIConfiguration->Locales;
  127. for (int Index = 0; Index < Locales->Count; Index++)
  128. {
  129. TListItem * Item = LanguagesView->Items->Add();
  130. Item->Caption = Locales->Strings[Index];
  131. Item->Data = Locales->Objects[Index];
  132. Item->Focused =
  133. (reinterpret_cast<LCID>(Locales->Objects[Index]) == GUIConfiguration->Locale);
  134. Item->Selected = Item->Focused;
  135. }
  136. FLanguagesLoaded = false;
  137. }
  138. }
  139. //---------------------------------------------------------------------------
  140. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  141. {
  142. for (int pi = 0; pi < PageControl->PageCount; pi++)
  143. {
  144. TTabSheet * Sheet = PageControl->Pages[pi];
  145. if (Sheet->Tag == Node->SelectedIndex)
  146. {
  147. return Sheet;
  148. }
  149. }
  150. FAIL;
  151. return NULL;
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  155. {
  156. Tree->FullExpand();
  157. int i = 0;
  158. while (i < Tree->Items->Count)
  159. {
  160. TTreeNode * Node = Tree->Items->Item[i];
  161. TTabSheet * Sheet = FindPageForTreeNode(Node);
  162. if (NOT_NULL(Sheet))
  163. {
  164. if (Sheet->Enabled)
  165. {
  166. // gets called multiple times occasionally
  167. // (e.g. when called from upload dialog invoked by /upload)
  168. if (!Sheet->Caption.IsEmpty())
  169. {
  170. Node->Text = Sheet->Caption;
  171. Sheet->Caption = L"";
  172. }
  173. }
  174. else
  175. {
  176. Tree->Items->Delete(Node);
  177. i--;
  178. }
  179. }
  180. i++;
  181. }
  182. }
  183. //---------------------------------------------------------------------------
  184. void __fastcall TPreferencesDialog::LoadConfiguration()
  185. {
  186. FNoUpdate++;
  187. try
  188. {
  189. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  190. BOOLPROP(DefaultDirIsHome);
  191. BOOLPROP(PreservePanelState);
  192. BOOLPROP(DeleteToRecycleBin);
  193. BOOLPROP(DDTransferConfirmation);
  194. BOOLPROP(DDWarnLackOfTempSpace);
  195. BOOLPROP(ShowHiddenFiles);
  196. BOOLPROP(RenameWholeName);
  197. BOOLPROP(ShowInaccesibleDirectories);
  198. BOOLPROP(CopyOnDoubleClickConfirmation);
  199. BOOLPROP(ConfirmTransferring);
  200. BOOLPROP(ConfirmOverwriting);
  201. BOOLPROP(ConfirmResume);
  202. BOOLPROP(ConfirmDeleting);
  203. BOOLPROP(ConfirmRecycling);
  204. BOOLPROP(ConfirmClosingSession);
  205. BOOLPROP(ConfirmExitOnCompletion);
  206. BOOLPROP(ConfirmCommandSession);
  207. BOOLPROP(ContinueOnError);
  208. BOOLPROP(DDAllowMoveInit);
  209. BOOLPROP(BeepOnFinish);
  210. BOOLPROP(TemporaryDirectoryAppendSession);
  211. BOOLPROP(TemporaryDirectoryAppendPath);
  212. BOOLPROP(TemporaryDirectoryDeterministic);
  213. BOOLPROP(TemporaryDirectoryCleanup);
  214. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  215. BOOLPROP(FullRowSelect);
  216. if (WinConfiguration->DDTransferConfirmation == asAuto)
  217. {
  218. // allow grayed state only initially,
  219. // once the off state is confirmed, never allow returning
  220. // to the undefined state
  221. DDTransferConfirmationCheck->AllowGrayed = true;
  222. }
  223. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck, WinConfiguration->DDTransferConfirmation);
  224. BeepOnFinishAfterEdit->AsInteger =
  225. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  226. BOOLPROP(BalloonNotifications);
  227. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  228. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  229. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  230. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  231. {
  232. DDSystemTemporaryDirectoryButton->Checked = true;
  233. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  234. }
  235. else
  236. {
  237. DDCustomTemporaryDirectoryButton->Checked = true;
  238. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  239. }
  240. // Commander
  241. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  242. {
  243. NortonLikeModeCombo->ItemIndex = 2;
  244. }
  245. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  246. {
  247. NortonLikeModeCombo->ItemIndex = 1;
  248. }
  249. else
  250. {
  251. NortonLikeModeCombo->ItemIndex = 0;
  252. }
  253. SwappedPanelsCheck->Checked =
  254. WinConfiguration->ScpCommander.SwappedPanels;
  255. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  256. ExplorerKeyboardShortcutsCombo->ItemIndex =
  257. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  258. BOOLPROP(UseLocationProfiles);
  259. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  260. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  261. // Local panel
  262. PreserveLocalDirectoryCheck->Checked =
  263. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  264. SystemContextMenuCheck->Checked =
  265. WinConfiguration->ScpCommander.SystemContextMenu;
  266. // Explorer
  267. ShowFullAddressCheck->Checked =
  268. WinConfiguration->ScpExplorer.ShowFullAddress;
  269. // select none when stNul
  270. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  271. IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
  272. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  273. // editor
  274. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  275. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  276. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  277. {
  278. EditorEncodingCombo->ItemIndex = 1;
  279. }
  280. else
  281. {
  282. EditorEncodingCombo->ItemIndex = 0;
  283. }
  284. TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
  285. (*FEditorList) = *WinConfiguration->EditorList;
  286. UpdateEditorListView();
  287. FCopyParams = GUIConfiguration->DefaultCopyParam;
  288. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  289. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  290. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  291. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  292. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  293. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  294. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  295. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  296. SessionReopenAutoIdleEdit->Value = (GUIConfiguration->SessionReopenAutoIdle > 0 ?
  297. (GUIConfiguration->SessionReopenAutoIdle / MSecsPerSec) : 5);
  298. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  299. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  300. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  301. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  302. GeneralSheet->Enabled = WinConfiguration->ExpertMode;
  303. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  304. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  305. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  306. StorageGroup->Visible = WinConfiguration->ExpertMode;
  307. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  308. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  309. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  310. UpdateCustomCommandsView();
  311. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  312. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  313. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  314. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  315. SelectPuttyRegistryStorageKey(GUIConfiguration->PuttyRegistryStorageKey);
  316. // Queue
  317. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  318. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  319. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  320. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  321. QueueIndividuallyCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueIndividually;
  322. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  323. if (!GUIConfiguration->QueueKeepDoneItems)
  324. {
  325. QueueKeepDoneItemsForCombo->ItemIndex = 0;
  326. }
  327. else if (GUIConfiguration->QueueKeepDoneItemsFor < 0)
  328. {
  329. QueueKeepDoneItemsForCombo->ItemIndex = 5;
  330. }
  331. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15)
  332. {
  333. QueueKeepDoneItemsForCombo->ItemIndex = 1;
  334. }
  335. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60)
  336. {
  337. QueueKeepDoneItemsForCombo->ItemIndex = 2;
  338. }
  339. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15 * 60)
  340. {
  341. QueueKeepDoneItemsForCombo->ItemIndex = 3;
  342. }
  343. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60 * 60)
  344. {
  345. QueueKeepDoneItemsForCombo->ItemIndex = 4;
  346. }
  347. if (WinConfiguration->QueueView.Show == qvShow)
  348. {
  349. QueueViewShowButton->Checked = true;
  350. }
  351. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  352. {
  353. QueueViewHideWhenEmptyButton->Checked = true;
  354. }
  355. else
  356. {
  357. QueueViewHideButton->Checked = true;
  358. }
  359. // window
  360. AutoSaveWorkspaceCheck->Checked = WinConfiguration->AutoSaveWorkspace;
  361. AutoWorkspaceCombo->Text =
  362. DefaultStr(WinConfiguration->AutoWorkspace,
  363. // It will rarely happen that LastWorkspace is set, while AutoWorkspace not.
  364. // It can happen only when user saved workspace before opening the Preferences
  365. // dialog for the first time
  366. DefaultStr(WinConfiguration->LastWorkspace, LoadStr(NEW_WORKSPACE)));
  367. AutoSaveWorkspacePasswordsCheck->Checked = WinConfiguration->AutoSaveWorkspacePasswords;
  368. if (WinConfiguration->PathInCaption == picFull)
  369. {
  370. PathInCaptionFullButton->Checked = true;
  371. }
  372. else if (WinConfiguration->PathInCaption == picShort)
  373. {
  374. PathInCaptionShortButton->Checked = true;
  375. }
  376. else
  377. {
  378. PathInCaptionNoneButton->Checked = true;
  379. }
  380. BOOLPROP(MinimizeToTray);
  381. BOOLPROP(ExternalSessionInExistingInstance);
  382. // panels
  383. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  384. BOOLPROP(AutoReadDirectoryAfterOp);
  385. BOOLPROP(RefreshRemotePanel);
  386. RefreshRemotePanelIntervalEdit->Value =
  387. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  388. switch (WinConfiguration->FormatSizeBytes)
  389. {
  390. case fbNone:
  391. FormatSizeBytesCombo->ItemIndex = 0;
  392. break;
  393. case fbKilobytes:
  394. FormatSizeBytesCombo->ItemIndex = 1;
  395. break;
  396. case fbShort:
  397. FormatSizeBytesCombo->ItemIndex = 2;
  398. break;
  399. default:
  400. FAIL;
  401. }
  402. bool CustomPanelFont = !WinConfiguration->PanelFont.FontName.IsEmpty();
  403. PanelFontCheck->Checked = CustomPanelFont;
  404. if (CustomPanelFont)
  405. {
  406. TWinConfiguration::RestoreFont(WinConfiguration->PanelFont, FPanelFont.get());
  407. }
  408. else
  409. {
  410. FPanelFont->Assign(WinConfiguration->SystemIconFont);
  411. }
  412. // updates
  413. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  414. if (int(Updates.Period) <= 0)
  415. {
  416. UpdatesPeriodCombo->ItemIndex = 0;
  417. }
  418. else if (int(Updates.Period) <= 1)
  419. {
  420. UpdatesPeriodCombo->ItemIndex = 1;
  421. }
  422. else if (int(Updates.Period) <= 7)
  423. {
  424. UpdatesPeriodCombo->ItemIndex = 2;
  425. }
  426. else
  427. {
  428. UpdatesPeriodCombo->ItemIndex = 3;
  429. }
  430. UpdatesShowOnStartup->Checked = Updates.ShowOnStartup;
  431. CollectUsageCheck->Checked = Configuration->CollectUsage;
  432. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  433. switch (Updates.ConnectionType)
  434. {
  435. case ctDirect:
  436. default:
  437. UpdatesDirectCheck->Checked = true;
  438. break;
  439. case ctAuto:
  440. UpdatesAutoCheck->Checked = true;
  441. break;
  442. case ctProxy:
  443. UpdatesProxyCheck->Checked = true;
  444. break;
  445. }
  446. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  447. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  448. // presets
  449. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  450. UpdateCopyParamListView();
  451. CopyParamListView->ItemIndex = 0;
  452. BOOLPROP(CopyParamAutoSelectNotice);
  453. // interface
  454. switch (CustomWinConfiguration->Interface)
  455. {
  456. case ifCommander:
  457. CommanderInterfaceButton2->Checked = true;
  458. break;
  459. case ifExplorer:
  460. ExplorerInterfaceButton2->Checked = true;
  461. break;
  462. default:
  463. FAIL;
  464. break;
  465. }
  466. if (WinConfiguration->Theme == L"OfficeXP")
  467. {
  468. ThemeCombo->ItemIndex = 1;
  469. }
  470. else if (WinConfiguration->Theme == L"Office2003")
  471. {
  472. ThemeCombo->ItemIndex = 2;
  473. }
  474. else
  475. {
  476. ThemeCombo->ItemIndex = 0;
  477. }
  478. // security
  479. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  480. SessionRememberPasswordCheck->Checked = GUIConfiguration->SessionRememberPassword;
  481. // network
  482. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  483. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  484. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  485. TryFtpWhenSshFailsCheck->Checked = Configuration->TryFtpWhenSshFails;
  486. // logging
  487. EnableLoggingCheck->Checked = Configuration->Logging;
  488. LogProtocolCombo->ItemIndex = Configuration->LogProtocol;
  489. LogToFileCheck->Checked = Configuration->LogToFile;
  490. LogFileNameEdit3->Text =
  491. !Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
  492. if (Configuration->LogFileAppend)
  493. {
  494. LogFileAppendButton->Checked = true;
  495. }
  496. else
  497. {
  498. LogFileOverwriteButton->Checked = true;
  499. }
  500. LogShowWindowCheck->Checked = (CustomWinConfiguration->LogView == lvWindow);
  501. if (Configuration->LogWindowComplete)
  502. {
  503. LogWindowCompleteButton->Checked = true;
  504. }
  505. else
  506. {
  507. LogWindowLinesButton->Checked = true;
  508. }
  509. if (!Configuration->LogWindowComplete)
  510. {
  511. LogWindowLinesEdit->AsInteger = Configuration->LogWindowLines;
  512. }
  513. else
  514. {
  515. LogWindowLinesEdit->AsInteger = 500;
  516. }
  517. BOOLPROP(LogSensitive);
  518. EnableActionsLoggingCheck->Checked = Configuration->LogActions;
  519. ActionsLogFileNameEdit->Text = Configuration->ActionsLogFileName;
  520. #undef BOOLPROP
  521. }
  522. __finally
  523. {
  524. FNoUpdate--;
  525. }
  526. UpdateControls();
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TPreferencesDialog::SaveConfiguration()
  530. {
  531. Configuration->BeginUpdate();
  532. try
  533. {
  534. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  535. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  536. BOOLPROP(DefaultDirIsHome);
  537. BOOLPROP(PreservePanelState);
  538. BOOLPROP(DeleteToRecycleBin);
  539. BOOLPROP(DDWarnLackOfTempSpace);
  540. BOOLPROP(ShowHiddenFiles);
  541. BOOLPROP(RenameWholeName);
  542. BOOLPROP(ShowInaccesibleDirectories);
  543. BOOLPROP(CopyOnDoubleClickConfirmation);
  544. BOOLPROP(ConfirmTransferring);
  545. BOOLPROP(ConfirmOverwriting);
  546. BOOLPROP(ConfirmResume);
  547. BOOLPROP(ConfirmDeleting);
  548. BOOLPROP(ConfirmRecycling);
  549. BOOLPROP(ConfirmClosingSession);
  550. BOOLPROP(ConfirmExitOnCompletion);
  551. BOOLPROP(ConfirmCommandSession);
  552. BOOLPROP(ContinueOnError);
  553. BOOLPROP(DDAllowMoveInit);
  554. BOOLPROP(BeepOnFinish);
  555. BOOLPROP(TemporaryDirectoryAppendSession);
  556. BOOLPROP(TemporaryDirectoryAppendPath);
  557. BOOLPROP(TemporaryDirectoryDeterministic);
  558. BOOLPROP(TemporaryDirectoryCleanup);
  559. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  560. BOOLPROP(FullRowSelect);
  561. WinConfiguration->DDTransferConfirmation =
  562. CheckBoxAutoSwitchSave(DDTransferConfirmationCheck);
  563. GUIConfiguration->BeepOnFinishAfter =
  564. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  565. BOOLPROP(BalloonNotifications);
  566. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  567. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  568. if (DDSystemTemporaryDirectoryButton->Checked)
  569. {
  570. WinConfiguration->DDTemporaryDirectory = L"";
  571. }
  572. else
  573. {
  574. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  575. }
  576. // Commander
  577. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  578. if (NortonLikeModeCombo->ItemIndex == 2)
  579. {
  580. ScpCommander.NortonLikeMode = nlOff;
  581. }
  582. else if (NortonLikeModeCombo->ItemIndex == 1)
  583. {
  584. ScpCommander.NortonLikeMode = nlKeyboard;
  585. }
  586. else
  587. {
  588. ScpCommander.NortonLikeMode = nlOn;
  589. }
  590. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  591. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  592. ScpCommander.ExplorerKeyboardShortcuts =
  593. (ExplorerKeyboardShortcutsCombo->ItemIndex != 0);
  594. BOOLPROP(UseLocationProfiles);
  595. ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  596. ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  597. // Local panel
  598. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  599. ScpCommander.SystemContextMenu = SystemContextMenuCheck->Checked;
  600. WinConfiguration->ScpCommander = ScpCommander;
  601. // Explorer
  602. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  603. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  604. WinConfiguration->ScpExplorer = ScpExplorer;
  605. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  606. // editor
  607. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  608. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  609. switch (EditorEncodingCombo->ItemIndex)
  610. {
  611. case 1:
  612. WinConfiguration->Editor.Encoding = CP_UTF8;
  613. break;
  614. default:
  615. WinConfiguration->Editor.Encoding = CP_ACP;
  616. break;
  617. }
  618. TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
  619. WinConfiguration->EditorList = FEditorList;
  620. // overwrites only TCopyParamType fields
  621. CopyParam = FCopyParams;
  622. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  623. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  624. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  625. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  626. Configuration->SessionReopenAuto =
  627. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  628. GUIConfiguration->SessionReopenAutoIdle =
  629. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoIdleEdit->AsInteger * MSecsPerSec) : 0);
  630. Configuration->SessionReopenAutoStall =
  631. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  632. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  633. WinConfiguration->CustomCommandList = FCustomCommandList;
  634. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  635. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  636. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  637. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  638. // do not overwrite custom keys
  639. if (PuttyRegistryStorageKeyEdit->ItemIndex >= 0)
  640. {
  641. GUIConfiguration->PuttyRegistryStorageKey = PuttyRegistryStorageKeyEdit->Text;
  642. }
  643. // Queue
  644. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  645. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  646. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  647. CopyParam.Queue = QueueCheck->Checked;
  648. CopyParam.QueueIndividually = QueueIndividuallyCheck->Checked;
  649. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  650. GUIConfiguration->QueueKeepDoneItems = (QueueKeepDoneItemsForCombo->ItemIndex != 0);
  651. switch (QueueKeepDoneItemsForCombo->ItemIndex)
  652. {
  653. case 0:
  654. GUIConfiguration->QueueKeepDoneItemsFor = 0;
  655. break;
  656. case 1:
  657. GUIConfiguration->QueueKeepDoneItemsFor = 15;
  658. break;
  659. case 2:
  660. GUIConfiguration->QueueKeepDoneItemsFor = 60;
  661. break;
  662. case 3:
  663. GUIConfiguration->QueueKeepDoneItemsFor = 15 * 60;
  664. break;
  665. case 4:
  666. GUIConfiguration->QueueKeepDoneItemsFor = 60 * 60;
  667. break;
  668. default:
  669. GUIConfiguration->QueueKeepDoneItemsFor = -1;
  670. break;
  671. }
  672. if (QueueViewShowButton->Checked)
  673. {
  674. WinConfiguration->QueueView.Show = qvShow;
  675. }
  676. else if (QueueViewHideWhenEmptyButton->Checked)
  677. {
  678. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  679. }
  680. else
  681. {
  682. WinConfiguration->QueueView.Show = qvHide;
  683. }
  684. GUIConfiguration->DefaultCopyParam = CopyParam;
  685. // window
  686. WinConfiguration->AutoSaveWorkspace =
  687. !AutoWorkspaceCombo->Text.IsEmpty() &&
  688. AutoSaveWorkspaceCheck->Checked;
  689. if (!AutoWorkspaceCombo->Text.IsEmpty())
  690. {
  691. WinConfiguration->AutoWorkspace = AutoWorkspaceCombo->Text;
  692. }
  693. WinConfiguration->AutoSaveWorkspacePasswords = AutoSaveWorkspacePasswordsCheck->Checked;
  694. if (PathInCaptionFullButton->Checked)
  695. {
  696. WinConfiguration->PathInCaption = picFull;
  697. }
  698. else if (PathInCaptionShortButton->Checked)
  699. {
  700. WinConfiguration->PathInCaption = picShort;
  701. }
  702. else
  703. {
  704. WinConfiguration->PathInCaption = picNone;
  705. }
  706. BOOLPROP(MinimizeToTray);
  707. BOOLPROP(ExternalSessionInExistingInstance);
  708. // panels
  709. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  710. BOOLPROP(AutoReadDirectoryAfterOp);
  711. BOOLPROP(RefreshRemotePanel);
  712. WinConfiguration->RefreshRemotePanelInterval =
  713. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  714. switch (FormatSizeBytesCombo->ItemIndex)
  715. {
  716. case 0:
  717. WinConfiguration->FormatSizeBytes = fbNone;
  718. break;
  719. case 1:
  720. WinConfiguration->FormatSizeBytes = fbKilobytes;
  721. break;
  722. case 2:
  723. WinConfiguration->FormatSizeBytes = fbShort;
  724. break;
  725. default:
  726. FAIL;
  727. }
  728. TFontConfiguration PanelFontConfiguration;
  729. if (PanelFontCheck->Checked)
  730. {
  731. TWinConfiguration::StoreFont(FPanelFont.get(), PanelFontConfiguration);
  732. }
  733. WinConfiguration->PanelFont = PanelFontConfiguration;
  734. // updates
  735. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  736. if (UpdatesPeriodCombo->ItemIndex == 0)
  737. {
  738. Updates.Period = 0;
  739. }
  740. else if (UpdatesPeriodCombo->ItemIndex == 1)
  741. {
  742. Updates.Period = 1;
  743. }
  744. else if (UpdatesPeriodCombo->ItemIndex == 2)
  745. {
  746. Updates.Period = 7;
  747. }
  748. else
  749. {
  750. Updates.Period = 30;
  751. }
  752. Updates.ShowOnStartup = UpdatesShowOnStartup->Checked;
  753. Configuration->CollectUsage = CollectUsageCheck->Checked;
  754. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  755. if (UpdatesDirectCheck->Checked)
  756. {
  757. Updates.ConnectionType = ctDirect;
  758. }
  759. else if (UpdatesAutoCheck->Checked)
  760. {
  761. Updates.ConnectionType = ctAuto;
  762. }
  763. else if (UpdatesProxyCheck->Checked)
  764. {
  765. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  766. {
  767. Updates.ConnectionType = ctProxy;
  768. }
  769. else
  770. {
  771. Updates.ConnectionType = ctDirect;
  772. }
  773. }
  774. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  775. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  776. WinConfiguration->Updates = Updates;
  777. // presets
  778. WinConfiguration->CopyParamList = FCopyParamList;
  779. BOOLPROP(CopyParamAutoSelectNotice);
  780. // interface
  781. if (GetInterface() != CustomWinConfiguration->Interface)
  782. {
  783. Configuration->Usage->Inc(L"InterfaceChanges");
  784. }
  785. CustomWinConfiguration->Interface = GetInterface();
  786. if (ThemeCombo->ItemIndex == 1)
  787. {
  788. WinConfiguration->Theme = L"OfficeXP";
  789. }
  790. else if (ThemeCombo->ItemIndex == 2)
  791. {
  792. WinConfiguration->Theme = L"Office2003";
  793. }
  794. else
  795. {
  796. WinConfiguration->Theme = L"Default";
  797. }
  798. // network
  799. Configuration->ExternalIpAddress =
  800. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  801. Configuration->TryFtpWhenSshFails = TryFtpWhenSshFailsCheck->Checked;
  802. // security
  803. GUIConfiguration->SessionRememberPassword = SessionRememberPasswordCheck->Checked;
  804. // logging
  805. Configuration->Logging = EnableLoggingCheck->Checked;
  806. Configuration->LogProtocol = LogProtocolCombo->ItemIndex;
  807. Configuration->LogFileName = LogToFileCheck->Checked ? LogFileNameEdit3->Text : UnicodeString();
  808. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  809. CustomWinConfiguration->LogView = LogShowWindowCheck->Checked ? lvWindow : lvNone;
  810. Configuration->LogWindowComplete = LogWindowCompleteButton->Checked;
  811. if (!LogWindowCompleteButton->Checked)
  812. {
  813. Configuration->LogWindowLines = LogWindowLinesEdit->AsInteger;
  814. }
  815. BOOLPROP(LogSensitive);
  816. Configuration->LogActions = EnableActionsLoggingCheck->Checked;
  817. Configuration->ActionsLogFileName = ActionsLogFileNameEdit->Text;
  818. // languages
  819. // As this dialog does not explicitly support run-time locale changing,
  820. // make this last, otherwise we lose some settings (or even worse
  821. // we end-up saving default text box values=control names as our configuration)
  822. if (LanguagesView->ItemFocused != NULL)
  823. {
  824. GUIConfiguration->Locale =
  825. reinterpret_cast<LCID>(LanguagesView->ItemFocused->Data);
  826. }
  827. // This possibly fails, make it last, so that the other settings are preserved.
  828. // Do nothing when no option is selected (i.e. storage is stNul).
  829. if (RegistryStorageButton->Checked)
  830. {
  831. Configuration->Storage = stRegistry;
  832. }
  833. else if (IniFileStorageButton2->Checked)
  834. {
  835. Configuration->Storage = stIniFile;
  836. }
  837. #undef BOOLPROP
  838. }
  839. __finally
  840. {
  841. Configuration->EndUpdate();
  842. }
  843. }
  844. //---------------------------------------------------------------------------
  845. TInterface __fastcall TPreferencesDialog::GetInterface()
  846. {
  847. return CommanderInterfaceButton2->Checked ? ifCommander : ifExplorer;
  848. }
  849. //---------------------------------------------------------------------------
  850. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  851. {
  852. InstallPathWordBreakProc(RandomSeedFileEdit);
  853. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  854. InstallPathWordBreakProc(PuttyPathEdit);
  855. InstallPathWordBreakProc(LogFileNameEdit3);
  856. InstallPathWordBreakProc(ActionsLogFileNameEdit);
  857. PrepareNavigationTree(NavigationTree);
  858. switch (FPreferencesMode) {
  859. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  860. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  861. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  862. case pmLogging: PageControl->ActivePage = LogSheet; break;
  863. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  864. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  865. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  866. case pmCommander: PageControl->ActivePage = CommanderSheet; break;
  867. default: PageControl->ActivePage = PreferencesSheet; break;
  868. }
  869. PageControlChange(NULL);
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  873. {
  874. UpdateControls();
  875. }
  876. //---------------------------------------------------------------------------
  877. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  878. {
  879. UnicodeString Result;
  880. for (int Index = 1; Index <= Values.Length(); Index++)
  881. {
  882. if (Index > 1)
  883. {
  884. Result += L' ';
  885. if (EditorTabSizeEdit->AsInteger > 2)
  886. {
  887. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  888. }
  889. }
  890. Result += Values[Index];
  891. }
  892. return Result;
  893. }
  894. //---------------------------------------------------------------------------
  895. void __fastcall TPreferencesDialog::UpdateControls()
  896. {
  897. if (FNoUpdate == 0)
  898. {
  899. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  900. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  901. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  902. EnableControl(ResumeThresholdUnitLabel2, ResumeThresholdEdit->Enabled);
  903. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  904. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  905. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  906. EnableControl(SessionReopenAutoIdleEdit, SessionReopenAutoIdleCheck->Checked);
  907. EnableControl(SessionReopenAutoIdleLabel, SessionReopenAutoIdleEdit->Enabled);
  908. EnableControl(SessionReopenAutoIdleSecLabel, SessionReopenAutoIdleEdit->Enabled);
  909. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  910. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  911. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  912. EnableControl(SessionReopenTimeoutEdit,
  913. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  914. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  915. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  916. EnableControl(CopyOnDoubleClickConfirmationCheck,
  917. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  918. TFont * ActualPanelFont = PanelFontCheck->Checked ? FPanelFont.get() : WinConfiguration->SystemIconFont;
  919. UnicodeString PanelFontLabelText;
  920. PanelFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  921. (ActualPanelFont->Name, ActualPanelFont->Size));
  922. PanelFontLabel->Caption = PanelFontLabelText;
  923. if (!SameFont(PanelFontLabel->Font, ActualPanelFont))
  924. {
  925. PanelFontLabel->Font = ActualPanelFont;
  926. }
  927. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  928. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  929. UnicodeString EditorFontLabelText;
  930. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  931. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  932. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  933. EditorFontLabelText += TabSample(L"1234");
  934. EditorFontLabel->Caption = EditorFontLabelText;
  935. if (!SameFont(EditorFontLabel->Font, FEditorFont.get()))
  936. {
  937. EditorFontLabel->Font = FEditorFont.get();
  938. }
  939. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  940. EnableControl(EditCommandButton, CommandSelected);
  941. EnableControl(RemoveCommandButton, CommandSelected);
  942. EnableControl(UpCommandButton, CommandSelected &&
  943. CustomCommandsView->ItemIndex > 0);
  944. EnableControl(DownCommandButton, CommandSelected &&
  945. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  946. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  947. EnableControl(EditCopyParamButton, CopyParamSelected);
  948. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  949. EnableControl(RemoveCopyParamButton,
  950. CopyParamSelected && (CopyParamListView->ItemIndex >= 1));
  951. EnableControl(UpCopyParamButton,
  952. CopyParamSelected && (CopyParamListView->ItemIndex > 1));
  953. EnableControl(DownCopyParamButton,
  954. CopyParamSelected &&
  955. (CopyParamListView->ItemIndex >= 1) &&
  956. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  957. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  958. UnicodeString InfoStr;
  959. if (CopyParamSelected)
  960. {
  961. const TCopyParamType * SelectedCopyParam = GetCopyParam(CopyParamListView->ItemIndex);
  962. InfoStr = SelectedCopyParam->GetInfoStr(L"; ", 0);
  963. if (CopyParamListView->ItemIndex >= 1)
  964. {
  965. const TCopyParamRule * Rule = FCopyParamList->Rules[CopyParamListView->ItemIndex - 1];
  966. if (Rule != NULL)
  967. {
  968. InfoStr += L"\n" + FORMAT(ReplaceStr(LoadStr(COPY_PARAM_RULE), L"\n", L" "), (Rule->GetInfoStr(L"; ")));
  969. }
  970. }
  971. }
  972. CopyParamLabel->Caption = InfoStr;
  973. CopyParamLabel->Hint = InfoStr;
  974. CopyParamLabel->ShowHint =
  975. (CopyParamLabel->Canvas->TextWidth(InfoStr) > (CopyParamLabel->Width * 3 / 2));
  976. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  977. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  978. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  979. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  980. DDCustomTemporaryDirectoryButton->Checked);
  981. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  982. DDAllowMoveInitCheck->Checked);
  983. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  984. TemporaryDirectoryCleanupCheck->Checked);
  985. // allow only when some of the known storages is selected,
  986. // and particularly do not allow switching storage, when we start with stNul,
  987. // as that would destroy the stored configuration
  988. EnableControl(StorageGroup, RegistryStorageButton->Checked || IniFileStorageButton2->Checked);
  989. IniFileStorageButton2->Caption =
  990. AnsiReplaceStr(IniFileStorageButton2->Caption, L"(winscp.ini)",
  991. FORMAT(L"(%s)", (ExpandEnvironmentVariables(Configuration->IniFileStorageName))));
  992. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  993. bool EditorSelected = (EditorListView3->Selected != NULL);
  994. EnableControl(EditEditorButton, EditorSelected);
  995. EnableControl(RemoveEditorButton, EditorSelected);
  996. EnableControl(UpEditorButton, EditorSelected &&
  997. (EditorListView3->ItemIndex > 0));
  998. EnableControl(DownEditorButton, EditorSelected &&
  999. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1000. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1001. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1002. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1003. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1004. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1005. bool IsSiteCommand = false;
  1006. try
  1007. {
  1008. TRemoteCustomCommand RemoteCustomCommand;
  1009. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1010. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1011. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1012. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1013. }
  1014. catch (...)
  1015. {
  1016. // noop
  1017. }
  1018. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  1019. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  1020. EnableControl(TelnetForFtpInPuttyCheck,
  1021. PuttyPasswordCheck2->Enabled && !IsSiteCommand);
  1022. EnableControl(PuttyRegistryStorageKeyEdit,
  1023. PuttyPasswordCheck2->Enabled && !IsSiteCommand);
  1024. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1025. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1026. // network
  1027. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1028. // window
  1029. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1030. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1031. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1032. !Configuration->DisablePasswordStoring &&
  1033. AutoWorkspaceCombo->Enabled);
  1034. // integration
  1035. // There's no quick launch in Windows 7
  1036. EnableControl(QuickLaunchIconButton, !::IsWin7());
  1037. MakeDefaultHandlerItem->Visible = IsWinVista();
  1038. // languages
  1039. LanguageChangeLabel->Visible =
  1040. !GUIConfiguration->CanApplyLocaleImmediately &&
  1041. (LanguagesView->ItemFocused != NULL) &&
  1042. (reinterpret_cast<LCID>(LanguagesView->ItemFocused->Data) != GUIConfiguration->AppliedLocale);
  1043. // logging
  1044. EnableControl(LogProtocolCombo, EnableLoggingCheck->Checked);
  1045. EnableControl(LogToFileCheck, LogProtocolCombo->Enabled);
  1046. EnableControl(LogFileNameEdit3, LogToFileCheck->Enabled && LogToFileCheck->Checked);
  1047. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1048. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1049. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1050. EnableControl(LogShowWindowCheck, LogProtocolCombo->Enabled);
  1051. EnableControl(LogWindowCompleteButton, LogShowWindowCheck->Enabled && LogShowWindowCheck->Checked);
  1052. EnableControl(LogWindowLinesButton, LogWindowCompleteButton->Enabled);
  1053. EnableControl(LogWindowLinesEdit, LogWindowLinesButton->Enabled && LogWindowLinesButton->Checked);
  1054. EnableControl(LogWindowLinesText, LogWindowLinesEdit->Enabled);
  1055. EnableControl(LogSensitiveCheck, LogProtocolCombo->Enabled);
  1056. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1057. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1058. // interface
  1059. InterfaceChangeLabel->Visible =
  1060. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1061. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1062. }
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1066. {
  1067. if (FontDialog(FEditorFont.get()))
  1068. {
  1069. UpdateControls();
  1070. }
  1071. }
  1072. //---------------------------------------------------------------------------
  1073. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1074. {
  1075. if (FontDialog(FPanelFont.get()))
  1076. {
  1077. PanelFontCheck->Checked = true;
  1078. UpdateControls();
  1079. }
  1080. }
  1081. //---------------------------------------------------------------------------
  1082. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1083. bool & /*CanClose*/)
  1084. {
  1085. if (ModalResult == DefaultResult(this))
  1086. {
  1087. ExitActiveControl(this);
  1088. }
  1089. }
  1090. //---------------------------------------------------------------------------
  1091. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1092. {
  1093. UnicodeString IconName, Params;
  1094. int SpecialFolder;
  1095. if (Sender == DesktopIconButton)
  1096. {
  1097. IconName = AppName;
  1098. int Result =
  1099. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1100. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1101. switch (Result)
  1102. {
  1103. case qaYes:
  1104. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1105. break;
  1106. case qaNo:
  1107. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1108. break;
  1109. default:
  1110. Abort();
  1111. break;
  1112. }
  1113. }
  1114. else
  1115. {
  1116. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1117. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1118. {
  1119. if (Sender == SendToHookButton)
  1120. {
  1121. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppName));
  1122. SpecialFolder = CSIDL_SENDTO;
  1123. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1124. }
  1125. else if (Sender == QuickLaunchIconButton)
  1126. {
  1127. IconName = L"Microsoft\\Internet Explorer\\Quick Launch\\" +
  1128. AppName;
  1129. SpecialFolder = CSIDL_APPDATA;
  1130. }
  1131. }
  1132. else
  1133. {
  1134. Abort();
  1135. }
  1136. }
  1137. TInstantOperationVisualizer Visualizer;
  1138. CreateDesktopShortCut(IconName,
  1139. Application->ExeName, Params, L"", SpecialFolder);
  1140. }
  1141. //---------------------------------------------------------------------------
  1142. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1143. TListItem * Item)
  1144. {
  1145. // WORKAROUND We get here on Wine after destructor is called
  1146. if (FCustomCommandList != NULL)
  1147. {
  1148. int Index = Item->Index;
  1149. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  1150. const TCustomCommandType * Command = FCustomCommandList->Commands[Index];
  1151. UnicodeString Caption = StripHotkey(Command->Name);
  1152. if (Command->ShortCut != 0)
  1153. {
  1154. Caption = FORMAT(L"%s (%s)", (Caption, ShortCutToText(Command->ShortCut)));
  1155. }
  1156. Item->Caption = Caption;
  1157. assert(!Item->SubItems->Count);
  1158. Item->SubItems->Add(Command->Command);
  1159. int Params = Command->Params;
  1160. Item->SubItems->Add(LoadStr(
  1161. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1162. UnicodeString ParamsStr;
  1163. #define ADDPARAM(PARAM, STR) \
  1164. if (FLAGSET(Params, PARAM)) \
  1165. ParamsStr += (ParamsStr.IsEmpty() ? L"" : L"/") + LoadStr(STR);
  1166. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  1167. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  1168. #undef ADDPARAM
  1169. Item->SubItems->Add(ParamsStr);
  1170. }
  1171. }
  1172. //---------------------------------------------------------------------------
  1173. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1174. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1175. {
  1176. UpdateControls();
  1177. }
  1178. //---------------------------------------------------------------------------
  1179. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1180. {
  1181. CustomCommandsView->Items->Count = FCustomCommandList->Count;
  1182. AutoSizeListColumnsWidth(CustomCommandsView);
  1183. CustomCommandsView->Invalidate();
  1184. }
  1185. //---------------------------------------------------------------------------
  1186. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1187. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1188. {
  1189. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1190. {
  1191. RemoveCommandButtonClick(NULL);
  1192. }
  1193. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1194. {
  1195. AddEditCommandButtonClick(AddCommandButton);
  1196. }
  1197. }
  1198. //---------------------------------------------------------------------------
  1199. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1200. TObject * /*Sender*/)
  1201. {
  1202. if (EditCommandButton->Enabled)
  1203. {
  1204. AddEditCommandButtonClick(EditCommandButton);
  1205. }
  1206. }
  1207. //---------------------------------------------------------------------------
  1208. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  1209. {
  1210. bool Edit = (Sender == EditCommandButton);
  1211. TCustomCommandType Command;
  1212. if (Edit)
  1213. {
  1214. int Index = CustomCommandsView->ItemIndex;
  1215. assert(Index >= 0 && Index <= FCustomCommandList->Count);
  1216. Command = *FCustomCommandList->Commands[Index];
  1217. }
  1218. TShortCuts ShortCuts;
  1219. if (WinConfiguration->SharedBookmarks != NULL)
  1220. {
  1221. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1222. }
  1223. FCustomCommandList->ShortCuts(ShortCuts);
  1224. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1225. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1226. {
  1227. int Index = CustomCommandsView->ItemIndex;
  1228. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1229. if (Edit)
  1230. {
  1231. FCustomCommandList->Change(Index, ACommand);
  1232. }
  1233. else
  1234. {
  1235. if (Index >= 0)
  1236. {
  1237. FCustomCommandList->Insert(Index, ACommand);
  1238. }
  1239. else
  1240. {
  1241. FCustomCommandList->Add(ACommand);
  1242. Index = FCustomCommandList->Count - 1;
  1243. }
  1244. }
  1245. UpdateCustomCommandsView();
  1246. CustomCommandsView->ItemIndex = Index;
  1247. UpdateControls();
  1248. }
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1252. TObject * /*Sender*/)
  1253. {
  1254. assert(CustomCommandsView->ItemIndex >= 0 &&
  1255. CustomCommandsView->ItemIndex < FCustomCommandList->Count);
  1256. FCustomCommandList->Delete(CustomCommandsView->ItemIndex);
  1257. UpdateCustomCommandsView();
  1258. UpdateControls();
  1259. }
  1260. //---------------------------------------------------------------------------
  1261. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1262. {
  1263. if (Source >= 0 && Source < FCustomCommandList->Count &&
  1264. Dest >= 0 && Dest < FCustomCommandList->Count)
  1265. {
  1266. FCustomCommandList->Move(Source, Dest);
  1267. // workaround for bug in VCL
  1268. CustomCommandsView->ItemIndex = -1;
  1269. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  1270. CustomCommandsView->ItemIndex = Dest;
  1271. UpdateCustomCommandsView();
  1272. UpdateControls();
  1273. }
  1274. }
  1275. //---------------------------------------------------------------------------
  1276. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1277. {
  1278. CustomCommandMove(CustomCommandsView->ItemIndex,
  1279. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1280. }
  1281. //---------------------------------------------------------------------------
  1282. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1283. {
  1284. if (ListView == CopyParamListView)
  1285. {
  1286. return FCopyParamScrollOnDragOver;
  1287. }
  1288. else if (ListView == CustomCommandsView)
  1289. {
  1290. return FCustomCommandsScrollOnDragOver;
  1291. }
  1292. else if (ListView == EditorListView3)
  1293. {
  1294. return FEditorScrollOnDragOver;
  1295. }
  1296. else
  1297. {
  1298. FAIL;
  1299. return NULL;
  1300. }
  1301. }
  1302. //---------------------------------------------------------------------------
  1303. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1304. TObject * Sender, TDragObject *& /*DragObject*/)
  1305. {
  1306. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1307. FListViewDragDest = -1;
  1308. ScrollOnDragOver(Sender)->StartDrag();
  1309. }
  1310. //---------------------------------------------------------------------------
  1311. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1312. {
  1313. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1314. FListViewDragDest = Item ? Item->Index : -1;
  1315. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1316. }
  1317. //---------------------------------------------------------------------------
  1318. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1319. TObject * Sender, TObject * Source, int X, int Y)
  1320. {
  1321. if (Source == CustomCommandsView)
  1322. {
  1323. if (AllowListViewDrag(Sender, X, Y))
  1324. {
  1325. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1326. }
  1327. }
  1328. }
  1329. //---------------------------------------------------------------------------
  1330. void __fastcall TPreferencesDialog::ListViewDragOver(
  1331. TObject * Sender, TObject * Source, int X, int Y,
  1332. TDragState /*State*/, bool & Accept)
  1333. {
  1334. if (Source == Sender)
  1335. {
  1336. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1337. // (when dropped on item itself, when it was dragged over another item before,
  1338. // that another item remains highlighted forever)
  1339. Accept = true;
  1340. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1341. }
  1342. }
  1343. //---------------------------------------------------------------------------
  1344. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1345. {
  1346. if (Index == 0)
  1347. {
  1348. return &FCopyParams;
  1349. }
  1350. else
  1351. {
  1352. return FCopyParamList->CopyParams[Index - 1];
  1353. }
  1354. }
  1355. //---------------------------------------------------------------------------
  1356. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1357. {
  1358. if (Source >= 1 && Source < (1 + FCopyParamList->Count) &&
  1359. Dest >= 0 && Dest < (1 + FCopyParamList->Count))
  1360. {
  1361. if (Dest == 0)
  1362. {
  1363. Dest = 1;
  1364. }
  1365. FCopyParamList->Move(Source - 1, Dest - 1);
  1366. // workaround for bug in VCL
  1367. CopyParamListView->ItemIndex = -1;
  1368. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1369. CopyParamListView->ItemIndex = Dest;
  1370. UpdateCopyParamListView();
  1371. UpdateControls();
  1372. }
  1373. }
  1374. //---------------------------------------------------------------------------
  1375. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1376. TObject * Sender, TObject * Source, int X, int Y)
  1377. {
  1378. if (Source == CopyParamListView)
  1379. {
  1380. if (AllowListViewDrag(Sender, X, Y))
  1381. {
  1382. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1383. }
  1384. }
  1385. }
  1386. //---------------------------------------------------------------------------
  1387. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1388. {
  1389. CopyParamMove(CopyParamListView->ItemIndex,
  1390. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1391. }
  1392. //---------------------------------------------------------------------------
  1393. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1394. TObject * /*Sender*/)
  1395. {
  1396. assert(CopyParamListView->ItemIndex >= 1 &&
  1397. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1398. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1399. UpdateCopyParamListView();
  1400. UpdateControls();
  1401. }
  1402. //---------------------------------------------------------------------------
  1403. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1404. {
  1405. int Index = CopyParamListView->ItemIndex;
  1406. bool Result;
  1407. if ((Index == 0) && (Mode == cpmEdit))
  1408. {
  1409. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1410. }
  1411. else
  1412. {
  1413. TCopyParamRuleData * CopyParamRuleData =
  1414. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1415. // negative (when default is selected) means add to the end
  1416. Index--;
  1417. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, FCopyParams);
  1418. if (Result)
  1419. {
  1420. UpdateCopyParamListView();
  1421. CopyParamListView->ItemIndex = Index + 1;
  1422. // when using duplicate button, focus remains on original item
  1423. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1424. }
  1425. }
  1426. if (Result)
  1427. {
  1428. UpdateControls();
  1429. }
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1433. {
  1434. AddEditCopyParam(cpmAdd);
  1435. }
  1436. //---------------------------------------------------------------------------
  1437. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1438. {
  1439. AddEditCopyParam(cpmEdit);
  1440. }
  1441. //---------------------------------------------------------------------------
  1442. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1443. {
  1444. AddEditCopyParam(cpmDuplicate);
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1448. TObject * /*Sender*/)
  1449. {
  1450. if (EditCopyParamButton->Enabled)
  1451. {
  1452. AddEditCopyParam(cpmEdit);
  1453. }
  1454. }
  1455. //---------------------------------------------------------------------------
  1456. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1457. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1458. {
  1459. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1460. {
  1461. RemoveCopyParamButtonClick(NULL);
  1462. }
  1463. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1464. {
  1465. AddEditCopyParam(cpmAdd);
  1466. }
  1467. }
  1468. //---------------------------------------------------------------------------
  1469. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1470. {
  1471. if (Source >= 0 && Source < FEditorList->Count &&
  1472. Dest >= 0 && Dest < FEditorList->Count)
  1473. {
  1474. FEditorList->Move(Source, Dest);
  1475. // workaround for bug in VCL
  1476. EditorListView3->ItemIndex = -1;
  1477. EditorListView3->ItemFocused = EditorListView3->Selected;
  1478. EditorListView3->ItemIndex = Dest;
  1479. UpdateEditorListView();
  1480. UpdateControls();
  1481. }
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1485. TObject * Source, int X, int Y)
  1486. {
  1487. if (Source == EditorListView3)
  1488. {
  1489. if (AllowListViewDrag(Sender, X, Y))
  1490. {
  1491. EditorMove(FListViewDragSource, FListViewDragDest);
  1492. }
  1493. }
  1494. }
  1495. //---------------------------------------------------------------------------
  1496. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1497. {
  1498. EditorMove(EditorListView3->ItemIndex,
  1499. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1500. }
  1501. //---------------------------------------------------------------------------
  1502. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1503. TObject * /*Sender*/)
  1504. {
  1505. assert(EditorListView3->ItemIndex >= 0 &&
  1506. EditorListView3->ItemIndex < FEditorList->Count);
  1507. FEditorList->Delete(EditorListView3->ItemIndex);
  1508. UpdateEditorListView();
  1509. UpdateControls();
  1510. }
  1511. //---------------------------------------------------------------------------
  1512. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1513. {
  1514. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1515. int Index = EditorListView3->ItemIndex;
  1516. TEditorPreferences * Editor;
  1517. if (Mode == epmEdit)
  1518. {
  1519. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1520. }
  1521. else
  1522. {
  1523. Editor = new TEditorPreferences();
  1524. }
  1525. try
  1526. {
  1527. bool DummyRemember = false;
  1528. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1529. {
  1530. if (Mode == epmEdit)
  1531. {
  1532. FEditorList->Change(Index, Editor);
  1533. }
  1534. else
  1535. {
  1536. if (Index < 0)
  1537. {
  1538. Index = FEditorList->Count;
  1539. FEditorList->Add(Editor);
  1540. }
  1541. else
  1542. {
  1543. FEditorList->Insert(Index, Editor);
  1544. }
  1545. }
  1546. // ownership of the object lost
  1547. Editor = NULL;
  1548. UpdateEditorListView();
  1549. EditorListView3->ItemIndex = Index;
  1550. UpdateControls();
  1551. }
  1552. }
  1553. __finally
  1554. {
  1555. delete Editor;
  1556. }
  1557. }
  1558. //---------------------------------------------------------------------------
  1559. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1560. {
  1561. if (EditEditorButton->Enabled)
  1562. {
  1563. AddEditEditorButtonClick(EditEditorButton);
  1564. }
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1568. WORD & Key, TShiftState /*Shift*/)
  1569. {
  1570. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1571. {
  1572. RemoveEditorButtonClick(NULL);
  1573. }
  1574. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1575. {
  1576. AddEditEditorButtonClick(AddEditorButton);
  1577. }
  1578. }
  1579. //---------------------------------------------------------------------------
  1580. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1581. {
  1582. EditorListView3->Items->Count = FEditorList->Count;
  1583. AutoSizeListColumnsWidth(EditorListView3);
  1584. EditorListView3->Invalidate();
  1585. }
  1586. //---------------------------------------------------------------------------
  1587. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1588. TListItem * Item)
  1589. {
  1590. // WORKAROUND We get here on Wine after destructor is called
  1591. if (FEditorList != NULL)
  1592. {
  1593. int Index = Item->Index;
  1594. assert(Index >= 0 && Index <= FEditorList->Count);
  1595. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1596. Item->Caption = Editor->Name;
  1597. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1598. if (Editor->Data->Editor == edExternal)
  1599. {
  1600. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1601. }
  1602. }
  1603. }
  1604. //---------------------------------------------------------------------------
  1605. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1606. TTreeNode * Node)
  1607. {
  1608. if (ALWAYS_TRUE(Node->SelectedIndex > 0))
  1609. {
  1610. PageControl->ActivePage = NOT_NULL(FindPageForTreeNode(Node));
  1611. // reshow the accelerators, etc
  1612. ResetSystemSettings(this);
  1613. // This is particularly here to enable EditCopyParamButton,
  1614. // as to some reason CopyParamListView->Selected is NULL until
  1615. // its page is shown for the first time
  1616. UpdateControls();
  1617. }
  1618. }
  1619. //---------------------------------------------------------------------------
  1620. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1621. {
  1622. // this is probably only ever called from FormShow (explicitly)
  1623. bool Found = false;
  1624. if (ALWAYS_TRUE(PageControl->ActivePage->Tag > 0))
  1625. {
  1626. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1627. {
  1628. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1629. PageControl->ActivePage->Tag)
  1630. {
  1631. NavigationTree->Items->Item[Index]->Selected = true;
  1632. Found = true;
  1633. }
  1634. }
  1635. }
  1636. if (ALWAYS_TRUE(Found))
  1637. {
  1638. UpdateControls();
  1639. }
  1640. }
  1641. //---------------------------------------------------------------------------
  1642. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1643. {
  1644. if (Message.CharCode == VK_TAB)
  1645. {
  1646. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1647. if (Shift.Contains(ssCtrl))
  1648. {
  1649. TTreeNode * Node = NavigationTree->Selected;
  1650. if (!Shift.Contains(ssShift))
  1651. {
  1652. Node = Node->GetNext();
  1653. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1654. }
  1655. else
  1656. {
  1657. if (Node->GetPrev()) Node = Node->GetPrev();
  1658. else
  1659. while (Node->GetNext()) Node = Node->GetNext();
  1660. }
  1661. Node->Selected = True;
  1662. Message.Result = 1;
  1663. return;
  1664. }
  1665. }
  1666. TForm::Dispatch(&Message);
  1667. }
  1668. //---------------------------------------------------------------------------
  1669. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1670. {
  1671. assert(Message.HelpInfo != NULL);
  1672. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1673. {
  1674. // invoke help for active page (not for whole form), regardless of focus
  1675. // (e.g. even if focus is on control outside pagecontrol)
  1676. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1677. }
  1678. TForm::Dispatch(&Message);
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1682. {
  1683. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1684. assert(M);
  1685. if (M->Msg == CM_DIALOGKEY)
  1686. {
  1687. CMDialogKey(*((TWMKeyDown *)Message));
  1688. }
  1689. else if (M->Msg == WM_HELP)
  1690. {
  1691. WMHelp(*((TWMHelp *)Message));
  1692. }
  1693. else
  1694. {
  1695. TForm::Dispatch(Message);
  1696. }
  1697. }
  1698. //---------------------------------------------------------------------------
  1699. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  1700. TObject * /*Sender*/)
  1701. {
  1702. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  1706. {
  1707. unsigned int Result =
  1708. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  1709. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1710. if (Result == qaYes)
  1711. {
  1712. TInstantOperationVisualizer Visualizer;
  1713. RegisterForDefaultProtocols();
  1714. }
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  1718. {
  1719. unsigned int Result =
  1720. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  1721. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1722. if (Result == qaYes)
  1723. {
  1724. TInstantOperationVisualizer Visualizer;
  1725. UnregisterForProtocols();
  1726. }
  1727. }
  1728. //---------------------------------------------------------------------------
  1729. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  1730. {
  1731. TOperationVisualizer Visualizer;
  1732. LaunchAdvancedAssociationUI();
  1733. }
  1734. //---------------------------------------------------------------------------
  1735. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1736. {
  1737. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1738. SetFocus();
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1742. TObject * /*Sender*/)
  1743. {
  1744. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1745. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  1746. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1747. {
  1748. TInstantOperationVisualizer Visualizer;
  1749. AddSearchPath(AppPath);
  1750. }
  1751. }
  1752. //---------------------------------------------------------------------------
  1753. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1754. TObject * Sender)
  1755. {
  1756. EditorFontButtonClick(Sender);
  1757. }
  1758. //---------------------------------------------------------------------------
  1759. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1760. {
  1761. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  1762. AutoSizeListColumnsWidth(CopyParamListView);
  1763. CopyParamListView->Invalidate();
  1764. }
  1765. //---------------------------------------------------------------------------
  1766. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1767. TListItem * Item)
  1768. {
  1769. // WORKAROUND We get here on Wine after destructor is called
  1770. if (FCopyParamList != NULL)
  1771. {
  1772. UnicodeString Name;
  1773. UnicodeString Rule;
  1774. int Index = Item->Index;
  1775. if (Index == 0)
  1776. {
  1777. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  1778. }
  1779. else
  1780. {
  1781. assert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  1782. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  1783. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  1784. }
  1785. Item->Caption = Name;
  1786. Item->SubItems->Add(Rule);
  1787. }
  1788. }
  1789. //---------------------------------------------------------------------------
  1790. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1791. {
  1792. FormHelp(this);
  1793. }
  1794. //---------------------------------------------------------------------------
  1795. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1796. TObject * /*Sender*/)
  1797. {
  1798. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  1799. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  1800. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  1801. }
  1802. //---------------------------------------------------------------------------
  1803. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1804. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1805. {
  1806. FBeforeDialogPath = Name;
  1807. Name = ExpandEnvironmentVariables(Name);
  1808. }
  1809. //---------------------------------------------------------------------------
  1810. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1811. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  1812. {
  1813. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1814. {
  1815. Name = FBeforeDialogPath;
  1816. }
  1817. }
  1818. //---------------------------------------------------------------------------
  1819. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1820. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1821. {
  1822. AllowCollapse = false;
  1823. }
  1824. //---------------------------------------------------------------------------
  1825. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1826. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1827. {
  1828. ScrollOnDragOver(Sender)->EndDrag();
  1829. }
  1830. //---------------------------------------------------------------------------
  1831. void __fastcall TPreferencesDialog::PathEditCreateEditDialog(
  1832. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1833. {
  1834. USEDPARAM(DialogKind);
  1835. assert(DialogKind == dkOpen);
  1836. Dialog = new TOpenDialog(dynamic_cast<TComponent *>(Sender));
  1837. }
  1838. //---------------------------------------------------------------------------
  1839. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  1840. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  1841. {
  1842. if (Value == 0)
  1843. {
  1844. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  1845. Handled = true;
  1846. }
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  1850. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  1851. {
  1852. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  1853. {
  1854. Value = 0;
  1855. Handled = true;
  1856. }
  1857. }
  1858. //---------------------------------------------------------------------------
  1859. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  1860. {
  1861. bool Result;
  1862. bool Retry;
  1863. do
  1864. {
  1865. Retry = false;
  1866. Result = !AnyOtherInstanceOfSelf();
  1867. if (!Result)
  1868. {
  1869. unsigned int Answer =
  1870. MessageDialog(
  1871. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  1872. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  1873. HELP_MASTER_PASSWORD);
  1874. switch (Answer)
  1875. {
  1876. case qaRetry:
  1877. Retry = true;
  1878. break;
  1879. case qaIgnore:
  1880. Result = true;
  1881. break;
  1882. case qaCancel:
  1883. default:
  1884. // noop
  1885. break;
  1886. }
  1887. }
  1888. }
  1889. while (Retry && !Result);
  1890. return Result;
  1891. }
  1892. //---------------------------------------------------------------------------
  1893. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  1894. UnicodeString Message, TStrings * RecryptPasswordErrors)
  1895. {
  1896. // Save master password.
  1897. // This is unlikely to fail, as storage is written explicitly already
  1898. // when writing the recrypted passwords
  1899. Configuration->SaveExplicit();
  1900. TQueryType QueryType = qtInformation;
  1901. if (RecryptPasswordErrors->Count > 0)
  1902. {
  1903. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  1904. QueryType = qtWarning;
  1905. }
  1906. MoreMessageDialog(
  1907. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  1908. }
  1909. //---------------------------------------------------------------------------
  1910. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  1911. {
  1912. UnicodeString NewPassword;
  1913. if (DoChangeMasterPasswordDialog(NewPassword))
  1914. {
  1915. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  1916. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  1917. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  1918. }
  1919. }
  1920. //---------------------------------------------------------------------------
  1921. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  1922. TObject * /*Sender*/)
  1923. {
  1924. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  1925. {
  1926. try
  1927. {
  1928. if (CanSetMasterPassword())
  1929. {
  1930. if (UseMasterPasswordCheck->Checked)
  1931. {
  1932. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  1933. }
  1934. else
  1935. {
  1936. if (DoMasterPasswordDialog())
  1937. {
  1938. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  1939. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  1940. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  1941. }
  1942. }
  1943. }
  1944. }
  1945. __finally
  1946. {
  1947. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  1948. UpdateControls();
  1949. }
  1950. }
  1951. }
  1952. //---------------------------------------------------------------------------
  1953. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  1954. TObject * /*Sender*/)
  1955. {
  1956. if (CanSetMasterPassword())
  1957. {
  1958. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  1959. }
  1960. }
  1961. //---------------------------------------------------------------------------
  1962. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  1963. {
  1964. std::unique_ptr<TStrings> Data(TextToStringList(GetUsageData()));
  1965. UnicodeString Message =
  1966. Data->Text.IsEmpty() ? MainInstructions(LoadStr(USAGE_DATA_NONE)) : LoadStr(USAGE_DATA2);
  1967. MoreMessageDialog(Message, Data.get(), qtInformation, qaOK, HELP_USAGE);
  1968. }
  1969. //---------------------------------------------------------------------------
  1970. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  1971. {
  1972. if (EditCopyParamButton->Enabled)
  1973. {
  1974. AddEditCopyParam(cpmEdit);
  1975. }
  1976. }
  1977. //---------------------------------------------------------------------------
  1978. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  1979. TCustomListView * Sender, TListItem * Item,
  1980. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  1981. {
  1982. if (Item->Index == 0)
  1983. {
  1984. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  1985. }
  1986. }
  1987. //---------------------------------------------------------------------------
  1988. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  1989. {
  1990. PuttyRegistryStorageKeyEdit->ItemIndex =
  1991. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  1992. }
  1993. //---------------------------------------------------------------------------
  1994. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  1995. {
  1996. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1997. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  1998. {
  1999. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2000. }
  2001. else if (ContainsText(PuttyPath, KittyExecutable))
  2002. {
  2003. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2004. }
  2005. UpdateControls();
  2006. }
  2007. //---------------------------------------------------------------------------
  2008. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2009. TTreeNode * Node, bool & /*AllowChange*/)
  2010. {
  2011. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2012. // delay load as this can be time consuming
  2013. if (Sheet == LanguagesSheet)
  2014. {
  2015. LoadLanguages();
  2016. }
  2017. }
  2018. //---------------------------------------------------------------------------
  2019. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2020. {
  2021. OpenBrowser(LoadStr(LOCALES_URL));
  2022. }
  2023. //---------------------------------------------------------------------------
  2024. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2025. {
  2026. CommanderInterfaceButton2->SetFocus();
  2027. }
  2028. //---------------------------------------------------------------------------
  2029. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2030. {
  2031. ExplorerInterfaceButton2->SetFocus();
  2032. }
  2033. //---------------------------------------------------------------------------
  2034. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2035. {
  2036. PanelFontButtonClick(Sender);
  2037. }
  2038. //---------------------------------------------------------------------------