Preferences.cpp 83 KB

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