Preferences.cpp 79 KB

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