Preferences.cpp 114 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <System.IOUtils.hpp>
  6. #include <Common.h>
  7. #include <math.h>
  8. #include "Preferences.h"
  9. #include "Custom.h"
  10. #include <CoreMain.h>
  11. #include <Terminal.h>
  12. #include <Bookmarks.h>
  13. #include "VCLCommon.h"
  14. #include "GUITools.h"
  15. #include "Tools.h"
  16. #include "TextsCore.h"
  17. #include "TextsWin.h"
  18. #include "HelpWin.h"
  19. #include "WinInterface.h"
  20. #include "WinConfiguration.h"
  21. #include "Setup.h"
  22. #include "ProgParams.h"
  23. #include "Http.h"
  24. #include "TerminalManager.h"
  25. //---------------------------------------------------------------------
  26. #pragma link "CopyParams"
  27. #pragma link "UpDownEdit"
  28. #pragma link "ComboEdit"
  29. #pragma link "HistoryComboBox"
  30. #pragma link "PathLabel"
  31. #pragma resource "*.dfm"
  32. //---------------------------------------------------------------------
  33. const int PrivatePortMin = 49152; // https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers#Dynamic,_private_or_ephemeral_ports
  34. //---------------------------------------------------------------------
  35. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  36. TPreferencesDialogData * DialogData)
  37. {
  38. bool Result;
  39. TPreferencesDialog * PreferencesDialog =
  40. new TPreferencesDialog(GetFormOwner(), APreferencesMode);
  41. try
  42. {
  43. Result = PreferencesDialog->Execute(DialogData);
  44. if (Result)
  45. {
  46. CheckConfigurationForceSave();
  47. Configuration->SaveExplicit();
  48. }
  49. }
  50. __finally
  51. {
  52. delete PreferencesDialog;
  53. }
  54. return Result;
  55. }
  56. //---------------------------------------------------------------------
  57. __fastcall TPreferencesDialog::TPreferencesDialog(
  58. TComponent* AOwner, TPreferencesMode PreferencesMode)
  59. : TForm(AOwner)
  60. {
  61. SetCorrectFormParent(this);
  62. FNoUpdate = 0;
  63. FPreferencesMode = PreferencesMode;
  64. FEditorFont.reset(new TFont());
  65. FEditorFont->Color = clWindowText;
  66. FPanelFont.reset(new TFont());
  67. FPanelFont->Color = clWindowText;
  68. // currently useless
  69. FAfterFilenameEditDialog = false;
  70. FCustomCommandList = new TCustomCommandList();
  71. FCustomCommandChanging = false;
  72. FExtensionList = new TCustomCommandList();
  73. FListViewDragDest = -1;
  74. FCopyParamList = new TCopyParamList();
  75. FEditorList = new TEditorList();
  76. FAutomaticUpdatesPossible = IsInstalled();
  77. FCustomCommandsHintItem = NULL;
  78. FAddedExtensions.reset(CreateSortedStringList());
  79. FCustomCommandOptions.reset(new TStringList());
  80. UseSystemSettings(this);
  81. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  82. FixListColumnWidth(CustomCommandsView, -1);
  83. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  84. FixListColumnWidth(CopyParamListView, -1);
  85. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView3, true);
  86. FixListColumnWidth(EditorListView3, -1);
  87. FFileColorScrollOnDragOver = new TListViewScrollOnDragOver(FileColorsView, true);
  88. FOrigCustomCommandsViewWindowProc = CustomCommandsView->WindowProc;
  89. CustomCommandsView->WindowProc = CustomCommandsViewWindowProc;
  90. ComboAutoSwitchInitialize(UpdatesBetaVersionsCombo);
  91. EnableControl(UpdatesBetaVersionsCombo, !WinConfiguration->IsBeta && !IsUWP());
  92. EnableControl(UpdatesBetaVersionsLabel, UpdatesBetaVersionsCombo->Enabled);
  93. HintLabel(LogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  94. HintLabel(ActionsLogFileNameHintText, LoadStr(LOG_FILE_HINT3));
  95. HintLabel(ShellIconsText2);
  96. HotTrackLabel(CopyParamLabel);
  97. std::unique_ptr<TStrings> PuttyPathHintStrings(TextToStringList(LoadStr(PUTTY_PATTERNS_HINT2)));
  98. PuttyPathHintStrings->Insert(7, LoadStr(PATTERNS_HINT_K));
  99. HintLabel(PuttyPathHintText, TrimRight(StringsToText(PuttyPathHintStrings.get())));
  100. EditorEncodingCombo->Items->Add(DefaultEncodingName());
  101. EditorEncodingCombo->Items->Add(LoadStr(UTF8_NAME));
  102. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  103. AutoWorkspaceCombo->Items->AddStrings(Workspaces.get());
  104. AutoSaveWorkspacePasswordsCheck->Caption = LoadStr(SAVE_WORKSPACE_PASSWORDS);
  105. PuttyRegistryStorageKeyEdit->Items->Add(OriginalPuttyRegistryStorageKey);
  106. PuttyRegistryStorageKeyEdit->Items->Add(KittyRegistryStorageKey);
  107. MenuButton(RegisterAsUrlHandlersButton);
  108. MenuButton(EditorFontColorButton);
  109. MenuButton(EditorBackgroundColorButton);
  110. LoadDialogImage(CommanderInterfacePicture, L"Commander");
  111. LoadDialogImage(ExplorerInterfacePicture, L"Explorer");
  112. LinkLabel(UpdatesLink);
  113. LinkAppLabel(BackgroundConfirmationsLink);
  114. AutoSizeButton(UsageViewButton);
  115. AutomaticIniFileStorageLabel->Caption = ExpandEnvironmentVariables(Configuration->GetAutomaticIniFileStorageName(false));
  116. QueueTransferLimitEdit->MaxValue = WinConfiguration->QueueTransferLimitMax;
  117. CommanderDescriptionLabel2->Caption = Bullet(CommanderDescriptionLabel2->Caption);
  118. ExplorerDescriptionLabel->Caption = Bullet(ExplorerDescriptionLabel->Caption);
  119. if (IsUWP())
  120. {
  121. UpdatesSheet->Caption = LoadStr(PREFERENCES_STATISTICS_CAPTION);
  122. int ProxyOffset = UpdatesProxyGroup->Top - UpdatesOptionsGroup->Top - UpdatesOptionsGroup->Height;
  123. UpdatesGroup2->Visible = false;
  124. UpdatesOptionsGroup->Top = UpdatesGroup2->Top;
  125. UpdatesBetaVersionsCombo->Visible = false;
  126. UpdatesBetaVersionsLabel->Visible = false;
  127. int Offset = UsageViewButton->Top - UpdatesBetaVersionsCombo->Top;
  128. CollectUsageCheck->Top = CollectUsageCheck->Top - Offset;
  129. UsageViewButton->Top = UsageViewButton->Top - Offset;
  130. UpdatesOptionsGroup->Height = UpdatesOptionsGroup->Height - Offset;
  131. UpdatesProxyGroup->Top = UpdatesOptionsGroup->Top + UpdatesOptionsGroup->Height + ProxyOffset;
  132. }
  133. HideComponentsPanel(this);
  134. }
  135. //---------------------------------------------------------------------------
  136. __fastcall TPreferencesDialog::~TPreferencesDialog()
  137. {
  138. SAFE_DESTROY(FFileColorScrollOnDragOver);
  139. SAFE_DESTROY(FEditorScrollOnDragOver);
  140. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  141. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  142. delete FCustomCommandList;
  143. FCustomCommandList = NULL;
  144. delete FExtensionList;
  145. FExtensionList = NULL;
  146. delete FCopyParamList;
  147. FCopyParamList = NULL;
  148. delete FEditorList;
  149. FEditorList = NULL;
  150. }
  151. //---------------------------------------------------------------------
  152. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  153. {
  154. PuttyPathEdit->Items = CustomWinConfiguration->History[L"PuttyPath"];
  155. FDialogData = DialogData;
  156. bool Result = (ShowModal() == DefaultResult(this));
  157. if (Result)
  158. {
  159. SaveConfiguration();
  160. CustomWinConfiguration->History[L"PuttyPath"] = PuttyPathEdit->Items;
  161. }
  162. else
  163. {
  164. for (int Index = 0; Index < FAddedExtensions->Count; Index++)
  165. {
  166. DeleteFile(ApiPath(FAddedExtensions->Strings[Index]));
  167. }
  168. }
  169. return Result;
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TPreferencesDialog::LoadLanguages()
  173. {
  174. if (!FLanguagesLoaded)
  175. {
  176. LanguagesView->Items->Clear();
  177. LCID Locale = GUIConfiguration->Locale;
  178. if (Locale == NULL)
  179. {
  180. DebugAssert(GUIConfiguration->AppliedLocale == WinConfiguration->DefaultLocale);
  181. Locale = WinConfiguration->DefaultLocale;
  182. }
  183. TObjectList * Locales = GUIConfiguration->Locales;
  184. for (int Index = 0; Index < Locales->Count; Index++)
  185. {
  186. TListItem * Item = LanguagesView->Items->Add();
  187. TLocaleInfo * LocaleInfo = DebugNotNull(dynamic_cast<TLocaleInfo *>(Locales->Items[Index]));
  188. Item->Caption = LocaleInfo->Name;
  189. Item->Data = LocaleInfo;
  190. Item->Focused = (LocaleInfo->Locale == Locale);
  191. Item->Selected = Item->Focused;
  192. }
  193. AutoSizeListColumnsWidth(LanguagesView);
  194. FLanguagesLoaded = true;
  195. }
  196. }
  197. //---------------------------------------------------------------------------
  198. TTabSheet * __fastcall TPreferencesDialog::FindPageForTreeNode(TTreeNode * Node)
  199. {
  200. for (int pi = 0; pi < PageControl->PageCount; pi++)
  201. {
  202. TTabSheet * Sheet = PageControl->Pages[pi];
  203. if (Sheet->Tag == Node->SelectedIndex)
  204. {
  205. return Sheet;
  206. }
  207. }
  208. DebugFail();
  209. return NULL;
  210. }
  211. //---------------------------------------------------------------------------
  212. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  213. {
  214. Tree->FullExpand();
  215. int i = 0;
  216. while (i < Tree->Items->Count)
  217. {
  218. TTreeNode * Node = Tree->Items->Item[i];
  219. TTabSheet * Sheet = FindPageForTreeNode(Node);
  220. if (DebugNotNull(Sheet))
  221. {
  222. if (Sheet->Enabled)
  223. {
  224. // gets called multiple times occasionally
  225. // (e.g. when called from upload dialog invoked by /upload)
  226. if (!Sheet->Caption.IsEmpty())
  227. {
  228. Node->Text = Sheet->Caption;
  229. Sheet->Caption = L"";
  230. }
  231. }
  232. else
  233. {
  234. Tree->Items->Delete(Node);
  235. i--;
  236. }
  237. }
  238. i++;
  239. }
  240. }
  241. //---------------------------------------------------------------------------
  242. void __fastcall TPreferencesDialog::LoadConfiguration()
  243. {
  244. FNoUpdate++;
  245. try
  246. {
  247. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  248. BOOLPROP(DefaultDirIsHome);
  249. BOOLPROP(PreservePanelState);
  250. BOOLPROP(DeleteToRecycleBin);
  251. BOOLPROP(DDWarnLackOfTempSpace);
  252. BOOLPROP(ShowHiddenFiles);
  253. BOOLPROP(RenameWholeName);
  254. BOOLPROP(ShowInaccesibleDirectories);
  255. BOOLPROP(CopyOnDoubleClickConfirmation);
  256. BOOLPROP(ConfirmTransferring);
  257. BOOLPROP(ConfirmOverwriting);
  258. BOOLPROP(ConfirmResume);
  259. BOOLPROP(ConfirmDeleting);
  260. BOOLPROP(ConfirmRecycling);
  261. BOOLPROP(ConfirmExitOnCompletion);
  262. BOOLPROP(ConfirmCommandSession);
  263. BOOLPROP(ContinueOnError);
  264. BOOLPROP(SynchronizeSummary);
  265. BOOLPROP(BeepOnFinish);
  266. BOOLPROP(TemporaryDirectoryAppendSession);
  267. BOOLPROP(TemporaryDirectoryAppendPath);
  268. BOOLPROP(TemporaryDirectoryDeterministic);
  269. BOOLPROP(TemporaryDirectoryCleanup);
  270. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  271. BOOLPROP(FullRowSelect);
  272. BOOLPROP(NaturalOrderNumericalSorting);
  273. BOOLPROP(AlwaysSortDirectoriesByName);
  274. ConfirmClosingSessionCheck2->Checked = WinConfiguration->ConfirmClosingSession;
  275. if (WinConfiguration->DDTransferConfirmation == asAuto)
  276. {
  277. // allow grayed state only initially,
  278. // once the off state is confirmed, never allow returning
  279. // to the undefined state
  280. DDTransferConfirmationCheck2->AllowGrayed = true;
  281. }
  282. CheckBoxAutoSwitchLoad(DDTransferConfirmationCheck2, WinConfiguration->DDTransferConfirmation);
  283. BeepOnFinishAfterEdit->AsInteger =
  284. int(static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * SecsPerDay);
  285. BOOLPROP(BalloonNotifications);
  286. DDFakeFileEnabledButton->Checked = WinConfiguration->DDFakeFile;
  287. DDFakeFileDisabledButton->Checked = !DDFakeFileEnabledButton->Checked;
  288. DDDrivesMemo->Lines->CommaText = WinConfiguration->DDDrives;
  289. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  290. {
  291. DDSystemTemporaryDirectoryButton->Checked = true;
  292. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  293. }
  294. else
  295. {
  296. DDCustomTemporaryDirectoryButton->Checked = true;
  297. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  298. }
  299. // Commander
  300. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  301. {
  302. NortonLikeModeCombo->ItemIndex = 2;
  303. }
  304. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  305. {
  306. NortonLikeModeCombo->ItemIndex = 1;
  307. }
  308. else
  309. {
  310. NortonLikeModeCombo->ItemIndex = 0;
  311. }
  312. SwappedPanelsCheck->Checked =
  313. WinConfiguration->ScpCommander.SwappedPanels;
  314. TreeOnLeftCheck->Checked = WinConfiguration->ScpCommander.TreeOnLeft;
  315. ExplorerKeyboardShortcutsCombo->ItemIndex =
  316. WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts ? 1 : 0;
  317. BOOLPROP(UseLocationProfiles);
  318. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  319. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  320. // Local panel
  321. PreserveLocalDirectoryCheck->Checked =
  322. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  323. SystemContextMenuCheck->Checked =
  324. WinConfiguration->ScpCommander.SystemContextMenu;
  325. // Explorer
  326. ShowFullAddressCheck->Checked =
  327. WinConfiguration->ScpExplorer.ShowFullAddress;
  328. // select none when stNul
  329. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  330. AutomaticIniFileStorageButton->Checked =
  331. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && Configuration->CustomIniFileStorageName.IsEmpty();
  332. CustomIniFileStorageButton->Checked =
  333. (Configuration->Storage == stIniFile) && Configuration->ExplicitIniFileStorageName.IsEmpty() && !Configuration->CustomIniFileStorageName.IsEmpty();
  334. CustomIniFileStorageEdit->Text = Configuration->CustomIniFileStorageName;
  335. if (Configuration->CustomIniFileStorageName.IsEmpty())
  336. {
  337. CustomIniFileStorageEdit->Text = Configuration->GetDefaultIniFileExportPath();
  338. }
  339. else
  340. {
  341. CustomIniFileStorageEdit->Text = Configuration->CustomIniFileStorageName;
  342. }
  343. FCustomIniFileStorageName = GetCustomIniFileStorageName();
  344. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  345. // editor
  346. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  347. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  348. if (WinConfiguration->Editor.Encoding == CP_UTF8)
  349. {
  350. EditorEncodingCombo->ItemIndex = 1;
  351. }
  352. else
  353. {
  354. EditorEncodingCombo->ItemIndex = 0;
  355. }
  356. TWinConfiguration::RestoreFont(WinConfiguration->Editor.Font, FEditorFont.get());
  357. FEditorFont->Color = WinConfiguration->Editor.FontColor;
  358. FEditorBackgroundColor = WinConfiguration->Editor.BackgroundColor;
  359. (*FEditorList) = *WinConfiguration->EditorList;
  360. UpdateEditorListView();
  361. BOOLPROP(EditorCheckNotModified);
  362. FCopyParams = GUIConfiguration->DefaultCopyParam;
  363. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  364. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  365. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  366. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  367. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  368. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  369. (Configuration->SessionReopenAuto / MSecsPerSec) : 5);
  370. SessionReopenAutoIdleCheck->Checked = (GUIConfiguration->SessionReopenAutoIdle > 0);
  371. SessionReopenAutoIdleEdit->Value = (GUIConfiguration->SessionReopenAutoIdle > 0 ?
  372. (GUIConfiguration->SessionReopenAutoIdle / MSecsPerSec) : 5);
  373. SessionReopenAutoStallCheck->Checked = (Configuration->SessionReopenAutoStall > 0);
  374. SessionReopenAutoStallEdit->Value = (Configuration->SessionReopenAutoStall > 0 ?
  375. (Configuration->SessionReopenAutoStall / MSecsPerSec) : SecsPerMin);
  376. SessionReopenTimeoutEdit->Value = (Configuration->SessionReopenTimeout / MSecsPerSec);
  377. GeneralSheet->Enabled = WinConfiguration->ExpertMode;
  378. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  379. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  380. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  381. StorageGroup->Visible = WinConfiguration->ExpertMode;
  382. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  383. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  384. FCustomCommandList->Assign(WinConfiguration->CustomCommandList);
  385. FExtensionList->Assign(WinConfiguration->ExtensionList);
  386. UpdateCustomCommandsView();
  387. FCustomCommandOptions->Assign(WinConfiguration->CustomCommandOptions);
  388. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  389. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  390. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  391. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  392. SelectPuttyRegistryStorageKey(GUIConfiguration->PuttyRegistryStorageKey);
  393. // Queue
  394. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  395. EnableQueueByDefaultCheck->Checked = WinConfiguration->EnableQueueByDefault;
  396. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  397. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  398. QueueParallelCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueParallel;
  399. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  400. if (!GUIConfiguration->QueueKeepDoneItems)
  401. {
  402. QueueKeepDoneItemsForCombo->ItemIndex = 0;
  403. }
  404. else if (GUIConfiguration->QueueKeepDoneItemsFor < 0)
  405. {
  406. QueueKeepDoneItemsForCombo->ItemIndex = 5;
  407. }
  408. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15)
  409. {
  410. QueueKeepDoneItemsForCombo->ItemIndex = 1;
  411. }
  412. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60)
  413. {
  414. QueueKeepDoneItemsForCombo->ItemIndex = 2;
  415. }
  416. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 15 * 60)
  417. {
  418. QueueKeepDoneItemsForCombo->ItemIndex = 3;
  419. }
  420. else if (GUIConfiguration->QueueKeepDoneItemsFor <= 60 * 60)
  421. {
  422. QueueKeepDoneItemsForCombo->ItemIndex = 4;
  423. }
  424. if (WinConfiguration->QueueView.Show == qvShow)
  425. {
  426. QueueViewShowButton->Checked = true;
  427. }
  428. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  429. {
  430. QueueViewHideWhenEmptyButton->Checked = true;
  431. }
  432. else
  433. {
  434. QueueViewHideButton->Checked = true;
  435. }
  436. // window
  437. AutoSaveWorkspaceCheck->Checked = WinConfiguration->AutoSaveWorkspace;
  438. AutoWorkspaceCombo->Text =
  439. DefaultStr(WinConfiguration->AutoWorkspace,
  440. // It will rarely happen that LastWorkspace is set, while AutoWorkspace not.
  441. // It can happen only when user saved workspace before opening the Preferences
  442. // dialog for the first time
  443. DefaultStr(WinConfiguration->LastWorkspace, LoadStr(NEW_WORKSPACE)));
  444. AutoSaveWorkspacePasswordsCheck->Checked = WinConfiguration->AutoSaveWorkspacePasswords;
  445. if (WinConfiguration->PathInCaption == picFull)
  446. {
  447. PathInCaptionFullButton->Checked = true;
  448. }
  449. else if (WinConfiguration->PathInCaption == picShort)
  450. {
  451. PathInCaptionShortButton->Checked = true;
  452. }
  453. else
  454. {
  455. PathInCaptionNoneButton->Checked = true;
  456. }
  457. BOOLPROP(MinimizeToTray);
  458. BOOLPROP(ExternalSessionInExistingInstance);
  459. BOOLPROP(ShowLoginWhenNoSession);
  460. BOOLPROP(KeepOpenWhenNoSession);
  461. BOOLPROP(ShowTips);
  462. // panels
  463. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  464. BOOLPROP(AutoReadDirectoryAfterOp);
  465. BOOLPROP(RefreshRemotePanel);
  466. RefreshRemotePanelIntervalEdit->Value =
  467. int(static_cast<double>(WinConfiguration->RefreshRemotePanelInterval) * SecsPerDay);
  468. switch (WinConfiguration->FormatSizeBytes)
  469. {
  470. case fbNone:
  471. FormatSizeBytesCombo->ItemIndex = 0;
  472. break;
  473. case fbKilobytes:
  474. FormatSizeBytesCombo->ItemIndex = 1;
  475. break;
  476. case fbShort:
  477. FormatSizeBytesCombo->ItemIndex = 2;
  478. break;
  479. default:
  480. DebugFail();
  481. }
  482. switch (WinConfiguration->PanelSearch)
  483. {
  484. case isOff:
  485. PanelSearchCombo->ItemIndex = -1;
  486. break;
  487. case isNameStartOnly:
  488. PanelSearchCombo->ItemIndex = 0;
  489. break;
  490. case isName:
  491. PanelSearchCombo->ItemIndex = 1;
  492. break;
  493. case isAll:
  494. PanelSearchCombo->ItemIndex = 2;
  495. break;
  496. default:
  497. DebugFail();
  498. }
  499. bool CustomPanelFont = !WinConfiguration->PanelFont.FontName.IsEmpty();
  500. PanelFontCheck->Checked = CustomPanelFont;
  501. if (CustomPanelFont)
  502. {
  503. TWinConfiguration::RestoreFont(WinConfiguration->PanelFont, FPanelFont.get());
  504. }
  505. else
  506. {
  507. // Default to system icon font, when starting customization
  508. FPanelFont->Assign(Screen->IconFont);
  509. }
  510. // file colors
  511. TFileColorData::LoadList(WinConfiguration->FileColors, FFileColors);
  512. UpdateFileColorsView();
  513. // updates
  514. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  515. if (int(Updates.Period) <= 0)
  516. {
  517. UpdatesPeriodCombo->ItemIndex = 0;
  518. }
  519. else if (int(Updates.Period) <= 1)
  520. {
  521. UpdatesPeriodCombo->ItemIndex = 1;
  522. }
  523. else if (int(Updates.Period) <= 7)
  524. {
  525. UpdatesPeriodCombo->ItemIndex = 2;
  526. }
  527. else
  528. {
  529. UpdatesPeriodCombo->ItemIndex = 3;
  530. }
  531. UpdatesShowOnStartup->Checked = Updates.ShowOnStartup;
  532. UpdatesAuthenticationEmailEdit->Text = Updates.AuthenticationEmail;
  533. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  534. CollectUsageCheck->Checked = Configuration->CollectUsage;
  535. ComboAutoSwitchLoad(UpdatesBetaVersionsCombo, Updates.BetaVersions);
  536. switch (Updates.ConnectionType)
  537. {
  538. case ctDirect:
  539. default:
  540. UpdatesDirectCheck->Checked = true;
  541. break;
  542. case ctAuto:
  543. UpdatesAutoCheck->Checked = true;
  544. break;
  545. case ctProxy:
  546. UpdatesProxyCheck->Checked = true;
  547. break;
  548. }
  549. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  550. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  551. // presets
  552. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  553. UpdateCopyParamListView();
  554. CopyParamListView->ItemIndex = 0;
  555. BOOLPROP(CopyParamAutoSelectNotice);
  556. // interface
  557. ComboAutoSwitchLoad(ThemeCombo, WinConfiguration->DarkTheme);
  558. switch (CustomWinConfiguration->Interface)
  559. {
  560. case ifCommander:
  561. CommanderInterfaceButton2->Checked = true;
  562. break;
  563. case ifExplorer:
  564. ExplorerInterfaceButton2->Checked = true;
  565. break;
  566. default:
  567. DebugFail();
  568. break;
  569. }
  570. // security
  571. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  572. SessionRememberPasswordCheck->Checked = GUIConfiguration->SessionRememberPassword;
  573. // network
  574. RetrieveExternalIpAddressButton->Checked = Configuration->ExternalIpAddress.IsEmpty();
  575. CustomExternalIpAddressButton->Checked = !RetrieveExternalIpAddressButton->Checked;
  576. CustomExternalIpAddressEdit->Text = Configuration->ExternalIpAddress;
  577. LocalPortNumberCheck->Checked = Configuration->HasLocalPortNumberLimits();
  578. LocalPortNumberMinEdit->AsInteger =
  579. (Configuration->LocalPortNumberMin > 0 ? Configuration->LocalPortNumberMin : PrivatePortMin);
  580. LocalPortNumberMaxEdit->AsInteger =
  581. (Configuration->LocalPortNumberMax >= LocalPortNumberMinEdit->AsInteger ? Configuration->LocalPortNumberMax : static_cast<int>(LocalPortNumberMaxEdit->MaxValue));
  582. TryFtpWhenSshFailsCheck->Checked = Configuration->TryFtpWhenSshFails;
  583. // logging
  584. EnableLoggingCheck->Checked = Configuration->Logging;
  585. LogProtocolCombo2->ItemIndex = Configuration->LogProtocol + BelowNormalLogLevels;
  586. LogFileNameEdit3->Text =
  587. !Configuration->LogFileName.IsEmpty() ? Configuration->LogFileName : Configuration->DefaultLogFileName;
  588. if (Configuration->LogFileAppend)
  589. {
  590. LogFileAppendButton->Checked = true;
  591. }
  592. else
  593. {
  594. LogFileOverwriteButton->Checked = true;
  595. }
  596. LogMaxSizeCheck->Checked = (Configuration->LogMaxSize > 0);
  597. LogMaxSizeCombo->Text = SizeToStr((Configuration->LogMaxSize > 0) ? Configuration->LogMaxSize : (1 * 1024 * 1024));
  598. LogMaxSizeCountCheck->Checked = (Configuration->LogMaxCount > 0);
  599. LogMaxSizeCountEdit->AsInteger = ((Configuration->LogMaxCount > 0) ? Configuration->LogMaxCount : 5);
  600. BOOLPROP(LogSensitive);
  601. EnableActionsLoggingCheck->Checked = Configuration->LogActions;
  602. ActionsLogFileNameEdit->Text = Configuration->ActionsLogFileName;
  603. #undef BOOLPROP
  604. }
  605. __finally
  606. {
  607. FNoUpdate--;
  608. }
  609. UpdateControls();
  610. }
  611. //---------------------------------------------------------------------------
  612. void __fastcall TPreferencesDialog::SaveConfiguration()
  613. {
  614. Configuration->BeginUpdate();
  615. try
  616. {
  617. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  618. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  619. BOOLPROP(DefaultDirIsHome);
  620. BOOLPROP(PreservePanelState);
  621. BOOLPROP(DeleteToRecycleBin);
  622. BOOLPROP(DDWarnLackOfTempSpace);
  623. BOOLPROP(ShowHiddenFiles);
  624. BOOLPROP(RenameWholeName);
  625. BOOLPROP(ShowInaccesibleDirectories);
  626. BOOLPROP(CopyOnDoubleClickConfirmation);
  627. BOOLPROP(ConfirmTransferring);
  628. BOOLPROP(ConfirmOverwriting);
  629. BOOLPROP(ConfirmResume);
  630. BOOLPROP(ConfirmDeleting);
  631. BOOLPROP(ConfirmRecycling);
  632. BOOLPROP(ConfirmExitOnCompletion);
  633. BOOLPROP(ConfirmCommandSession);
  634. BOOLPROP(ContinueOnError);
  635. BOOLPROP(SynchronizeSummary);
  636. BOOLPROP(BeepOnFinish);
  637. BOOLPROP(TemporaryDirectoryAppendSession);
  638. BOOLPROP(TemporaryDirectoryAppendPath);
  639. BOOLPROP(TemporaryDirectoryDeterministic);
  640. BOOLPROP(TemporaryDirectoryCleanup);
  641. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  642. BOOLPROP(FullRowSelect);
  643. BOOLPROP(NaturalOrderNumericalSorting);
  644. BOOLPROP(AlwaysSortDirectoriesByName);
  645. WinConfiguration->ConfirmClosingSession = ConfirmClosingSessionCheck2->Checked;
  646. WinConfiguration->DDTransferConfirmation =
  647. CheckBoxAutoSwitchSave(DDTransferConfirmationCheck2);
  648. GUIConfiguration->BeepOnFinishAfter =
  649. static_cast<double>(BeepOnFinishAfterEdit->Value / SecsPerDay);
  650. BOOLPROP(BalloonNotifications);
  651. WinConfiguration->DDFakeFile = DDFakeFileEnabledButton->Checked;
  652. WinConfiguration->DDDrives = DDDrivesMemo->Lines->CommaText;
  653. if (DDSystemTemporaryDirectoryButton->Checked)
  654. {
  655. WinConfiguration->DDTemporaryDirectory = L"";
  656. }
  657. else
  658. {
  659. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  660. }
  661. // Commander
  662. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  663. if (NortonLikeModeCombo->ItemIndex == 2)
  664. {
  665. ScpCommander.NortonLikeMode = nlOff;
  666. }
  667. else if (NortonLikeModeCombo->ItemIndex == 1)
  668. {
  669. ScpCommander.NortonLikeMode = nlKeyboard;
  670. }
  671. else
  672. {
  673. ScpCommander.NortonLikeMode = nlOn;
  674. }
  675. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  676. ScpCommander.TreeOnLeft = TreeOnLeftCheck->Checked;
  677. ScpCommander.ExplorerKeyboardShortcuts =
  678. (ExplorerKeyboardShortcutsCombo->ItemIndex != 0);
  679. BOOLPROP(UseLocationProfiles);
  680. ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  681. ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  682. // Local panel
  683. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  684. ScpCommander.SystemContextMenu = SystemContextMenuCheck->Checked;
  685. WinConfiguration->ScpCommander = ScpCommander;
  686. // Explorer
  687. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  688. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  689. WinConfiguration->ScpExplorer = ScpExplorer;
  690. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  691. // editor
  692. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  693. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  694. switch (EditorEncodingCombo->ItemIndex)
  695. {
  696. case 1:
  697. WinConfiguration->Editor.Encoding = CP_UTF8;
  698. break;
  699. default:
  700. WinConfiguration->Editor.Encoding = CP_ACP;
  701. break;
  702. }
  703. TWinConfiguration::StoreFont(FEditorFont.get(), WinConfiguration->Editor.Font);
  704. WinConfiguration->Editor.FontColor = FEditorFont->Color;
  705. WinConfiguration->Editor.BackgroundColor = FEditorBackgroundColor;
  706. WinConfiguration->EditorList = FEditorList;
  707. BOOLPROP(EditorCheckNotModified);
  708. // overwrites only TCopyParamType fields
  709. CopyParam = FCopyParams;
  710. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  711. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  712. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  713. CopyParam.ResumeThreshold = ResumeThresholdEdit->AsInteger * 1024;
  714. Configuration->SessionReopenAuto =
  715. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->AsInteger * MSecsPerSec) : 0);
  716. GUIConfiguration->SessionReopenAutoIdle =
  717. (SessionReopenAutoIdleCheck->Checked ? (SessionReopenAutoIdleEdit->AsInteger * MSecsPerSec) : 0);
  718. Configuration->SessionReopenAutoStall =
  719. (SessionReopenAutoStallCheck->Checked ? (SessionReopenAutoStallEdit->AsInteger * MSecsPerSec) : 0);
  720. Configuration->SessionReopenTimeout = (SessionReopenTimeoutEdit->AsInteger * MSecsPerSec);
  721. WinConfiguration->CustomCommandList = FCustomCommandList;
  722. WinConfiguration->ExtensionList = FExtensionList;
  723. WinConfiguration->CustomCommandOptions = FCustomCommandOptions.get();
  724. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  725. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  726. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  727. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  728. // do not overwrite custom keys
  729. if (PuttyRegistryStorageKeyEdit->ItemIndex >= 0)
  730. {
  731. GUIConfiguration->PuttyRegistryStorageKey = PuttyRegistryStorageKeyEdit->Text;
  732. }
  733. // Queue
  734. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  735. WinConfiguration->EnableQueueByDefault = EnableQueueByDefaultCheck->Checked;
  736. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  737. CopyParam.Queue = QueueCheck->Checked;
  738. CopyParam.QueueParallel = QueueParallelCheck->Checked;
  739. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  740. GUIConfiguration->QueueKeepDoneItems = (QueueKeepDoneItemsForCombo->ItemIndex != 0);
  741. switch (QueueKeepDoneItemsForCombo->ItemIndex)
  742. {
  743. case 0:
  744. GUIConfiguration->QueueKeepDoneItemsFor = 0;
  745. break;
  746. case 1:
  747. GUIConfiguration->QueueKeepDoneItemsFor = 15;
  748. break;
  749. case 2:
  750. GUIConfiguration->QueueKeepDoneItemsFor = 60;
  751. break;
  752. case 3:
  753. GUIConfiguration->QueueKeepDoneItemsFor = 15 * 60;
  754. break;
  755. case 4:
  756. GUIConfiguration->QueueKeepDoneItemsFor = 60 * 60;
  757. break;
  758. default:
  759. GUIConfiguration->QueueKeepDoneItemsFor = -1;
  760. break;
  761. }
  762. if (QueueViewShowButton->Checked)
  763. {
  764. WinConfiguration->QueueView.Show = qvShow;
  765. }
  766. else if (QueueViewHideWhenEmptyButton->Checked)
  767. {
  768. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  769. }
  770. else
  771. {
  772. WinConfiguration->QueueView.Show = qvHide;
  773. }
  774. GUIConfiguration->DefaultCopyParam = CopyParam;
  775. // window
  776. WinConfiguration->AutoSaveWorkspace =
  777. !AutoWorkspaceCombo->Text.IsEmpty() &&
  778. AutoSaveWorkspaceCheck->Checked;
  779. if (!AutoWorkspaceCombo->Text.IsEmpty())
  780. {
  781. WinConfiguration->AutoWorkspace = AutoWorkspaceCombo->Text;
  782. }
  783. WinConfiguration->AutoSaveWorkspacePasswords = AutoSaveWorkspacePasswordsCheck->Checked;
  784. if (PathInCaptionFullButton->Checked)
  785. {
  786. WinConfiguration->PathInCaption = picFull;
  787. }
  788. else if (PathInCaptionShortButton->Checked)
  789. {
  790. WinConfiguration->PathInCaption = picShort;
  791. }
  792. else
  793. {
  794. WinConfiguration->PathInCaption = picNone;
  795. }
  796. BOOLPROP(MinimizeToTray);
  797. BOOLPROP(ExternalSessionInExistingInstance);
  798. BOOLPROP(ShowLoginWhenNoSession);
  799. BOOLPROP(KeepOpenWhenNoSession);
  800. BOOLPROP(ShowTips);
  801. // panels
  802. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  803. BOOLPROP(AutoReadDirectoryAfterOp);
  804. BOOLPROP(RefreshRemotePanel);
  805. WinConfiguration->RefreshRemotePanelInterval =
  806. static_cast<double>(RefreshRemotePanelIntervalEdit->Value / SecsPerDay);
  807. switch (FormatSizeBytesCombo->ItemIndex)
  808. {
  809. case 0:
  810. WinConfiguration->FormatSizeBytes = fbNone;
  811. break;
  812. case 1:
  813. WinConfiguration->FormatSizeBytes = fbKilobytes;
  814. break;
  815. case 2:
  816. WinConfiguration->FormatSizeBytes = fbShort;
  817. break;
  818. default:
  819. DebugFail();
  820. }
  821. switch (PanelSearchCombo->ItemIndex)
  822. {
  823. case -1:
  824. WinConfiguration->PanelSearch = isOff;
  825. break;
  826. case 0:
  827. WinConfiguration->PanelSearch = isNameStartOnly;
  828. break;
  829. case 1:
  830. WinConfiguration->PanelSearch = isName;
  831. break;
  832. case 2:
  833. WinConfiguration->PanelSearch = isAll;
  834. break;
  835. default:
  836. DebugFail();
  837. }
  838. TFontConfiguration PanelFontConfiguration;
  839. if (PanelFontCheck->Checked)
  840. {
  841. TWinConfiguration::StoreFont(FPanelFont.get(), PanelFontConfiguration);
  842. }
  843. WinConfiguration->PanelFont = PanelFontConfiguration;
  844. // file colors
  845. WinConfiguration->FileColors = TFileColorData::SaveList(FFileColors);
  846. // updates
  847. TUpdatesConfiguration Updates = SaveUpdates();
  848. if ((Configuration->CollectUsage != CollectUsageCheck->Checked) && IsUWP())
  849. {
  850. if (CollectUsageCheck->Checked)
  851. {
  852. if (Updates.Period == TDateTime(0))
  853. {
  854. Updates.Period = DefaultUpdatesPeriod;
  855. }
  856. }
  857. else
  858. {
  859. Updates.Period = 0;
  860. }
  861. }
  862. WinConfiguration->Updates = Updates;
  863. Configuration->CollectUsage = CollectUsageCheck->Checked;
  864. // presets
  865. WinConfiguration->CopyParamList = FCopyParamList;
  866. BOOLPROP(CopyParamAutoSelectNotice);
  867. // interface
  868. WinConfiguration->DarkTheme = ComboAutoSwitchSave(ThemeCombo);
  869. if (GetInterface() != CustomWinConfiguration->Interface)
  870. {
  871. Configuration->Usage->Inc(L"InterfaceChanges");
  872. }
  873. CustomWinConfiguration->Interface = GetInterface();
  874. // network
  875. Configuration->ExternalIpAddress =
  876. (CustomExternalIpAddressButton->Checked ? CustomExternalIpAddressEdit->Text : UnicodeString());
  877. Configuration->LocalPortNumberMin = LocalPortNumberCheck->Checked ? LocalPortNumberMinEdit->AsInteger : 0;
  878. Configuration->LocalPortNumberMax = LocalPortNumberCheck->Checked ? LocalPortNumberMaxEdit->AsInteger : 0;
  879. Configuration->TryFtpWhenSshFails = TryFtpWhenSshFailsCheck->Checked;
  880. // security
  881. GUIConfiguration->SessionRememberPassword = SessionRememberPasswordCheck->Checked;
  882. // logging
  883. Configuration->Logging = EnableLoggingCheck->Checked && !LogFileNameEdit3->Text.IsEmpty();
  884. Configuration->LogProtocol = LogProtocolCombo2->ItemIndex - BelowNormalLogLevels;
  885. Configuration->LogFileName = LogFileNameEdit3->Text;
  886. Configuration->LogFileAppend = LogFileAppendButton->Checked;
  887. __int64 LogMaxSize;
  888. // TryStrToSize can fail, only if LogMaxSizeComboExit is bypassed due to IsCancelButtonBeingClicked
  889. if (LogMaxSizeCheck->Checked && TryStrToSize(LogMaxSizeCombo->Text, LogMaxSize))
  890. {
  891. Configuration->LogMaxSize = LogMaxSize;
  892. }
  893. else
  894. {
  895. Configuration->LogMaxSize = 0;
  896. }
  897. Configuration->LogMaxCount = (LogMaxSizeCountCheck->Checked ? LogMaxSizeCountEdit->AsInteger : 0);
  898. BOOLPROP(LogSensitive);
  899. Configuration->LogActions = EnableActionsLoggingCheck->Checked;
  900. Configuration->ActionsLogFileName = ActionsLogFileNameEdit->Text;
  901. // languages
  902. if (LanguagesView->ItemFocused != NULL)
  903. {
  904. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data);
  905. LCID Locale;
  906. // Do not change the locale settings, unless changed explicitly by user
  907. // to allow an automatic upgrade to new translation once the UI language translation
  908. // becomes available
  909. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  910. {
  911. Locale = NULL;
  912. }
  913. else
  914. {
  915. Locale = LocaleInfo->Locale;
  916. }
  917. GUIConfiguration->Locale = Locale;
  918. }
  919. #undef BOOLPROP
  920. }
  921. __finally
  922. {
  923. Configuration->EndUpdate();
  924. }
  925. bool MoveStorage = true;
  926. TStorage Storage;
  927. if (RegistryStorageButton->Checked)
  928. {
  929. Storage = stRegistry;
  930. }
  931. else if (AutomaticIniFileStorageButton->Checked)
  932. {
  933. Storage = stIniFile;
  934. }
  935. else if (CustomIniFileStorageButton->Checked)
  936. {
  937. Storage = stIniFile;
  938. }
  939. else
  940. {
  941. MoveStorage = false;
  942. }
  943. if (MoveStorage)
  944. {
  945. Configuration->MoveStorage(Storage, GetCustomIniFileStorageName());
  946. }
  947. }
  948. //---------------------------------------------------------------------------
  949. TUpdatesConfiguration __fastcall TPreferencesDialog::SaveUpdates()
  950. {
  951. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  952. if (UpdatesPeriodCombo->ItemIndex == 0)
  953. {
  954. Updates.Period = 0;
  955. }
  956. else if (UpdatesPeriodCombo->ItemIndex == 1)
  957. {
  958. Updates.Period = 1;
  959. }
  960. else if (UpdatesPeriodCombo->ItemIndex == 2)
  961. {
  962. Updates.Period = 7;
  963. }
  964. else
  965. {
  966. Updates.Period = 30;
  967. }
  968. Updates.ShowOnStartup = UpdatesShowOnStartup->Checked;
  969. Updates.AuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  970. Updates.BetaVersions = ComboAutoSwitchSave(UpdatesBetaVersionsCombo);
  971. if (UpdatesDirectCheck->Checked)
  972. {
  973. Updates.ConnectionType = ctDirect;
  974. }
  975. else if (UpdatesAutoCheck->Checked)
  976. {
  977. Updates.ConnectionType = ctAuto;
  978. }
  979. else if (UpdatesProxyCheck->Checked)
  980. {
  981. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  982. {
  983. Updates.ConnectionType = ctProxy;
  984. }
  985. else
  986. {
  987. Updates.ConnectionType = ctDirect;
  988. }
  989. }
  990. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  991. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  992. return Updates;
  993. }
  994. //---------------------------------------------------------------------------
  995. TInterface __fastcall TPreferencesDialog::GetInterface()
  996. {
  997. return CommanderInterfaceButton2->Checked ? ifCommander : ifExplorer;
  998. }
  999. //---------------------------------------------------------------------------
  1000. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  1001. {
  1002. // Load only now, particularly so that we have handles allocated already.
  1003. // If called before ShowModal, we end up recreating the handles,
  1004. // what causes flicker of the currently focused window
  1005. LoadConfiguration();
  1006. InstallPathWordBreakProc(RandomSeedFileEdit);
  1007. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  1008. InstallPathWordBreakProc(PuttyPathEdit);
  1009. InstallPathWordBreakProc(LogFileNameEdit3);
  1010. InstallPathWordBreakProc(ActionsLogFileNameEdit);
  1011. ListView_SetExtendedListViewStyle(CustomCommandsView->Handle, (ListView_GetExtendedListViewStyle(CustomCommandsView->Handle) & ~LVS_EX_INFOTIP));
  1012. PrepareNavigationTree(NavigationTree);
  1013. switch (FPreferencesMode) {
  1014. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  1015. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  1016. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  1017. case pmLogging: PageControl->ActivePage = LogSheet; break;
  1018. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  1019. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  1020. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  1021. case pmCommander: PageControl->ActivePage = CommanderSheet; break;
  1022. case pmEditorInternal: PageControl->ActivePage = EditorInternalSheet; break;
  1023. case pmFileColors: PageControl->ActivePage = FileColorsSheet; break;
  1024. default: PageControl->ActivePage = PreferencesSheet; break;
  1025. }
  1026. PageControlChange(NULL);
  1027. ActiveControl = NavigationTree;
  1028. }
  1029. //---------------------------------------------------------------------------
  1030. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  1031. {
  1032. UpdateControls();
  1033. }
  1034. //---------------------------------------------------------------------------
  1035. UnicodeString __fastcall TPreferencesDialog::TabSample(UnicodeString Values)
  1036. {
  1037. UnicodeString Result;
  1038. for (int Index = 1; Index <= Values.Length(); Index++)
  1039. {
  1040. if (Index > 1)
  1041. {
  1042. Result += L' ';
  1043. if (EditorTabSizeEdit->AsInteger > 2)
  1044. {
  1045. Result += UnicodeString::StringOfChar(L' ', EditorTabSizeEdit->AsInteger - 2);
  1046. }
  1047. }
  1048. Result += Values[Index];
  1049. }
  1050. return Result;
  1051. }
  1052. //---------------------------------------------------------------------------
  1053. TCustomCommandList * __fastcall TPreferencesDialog::GetCommandList(int Index)
  1054. {
  1055. if (Index < FCustomCommandList->Count)
  1056. {
  1057. return FCustomCommandList;
  1058. }
  1059. else
  1060. {
  1061. return FExtensionList;
  1062. }
  1063. }
  1064. //---------------------------------------------------------------------------
  1065. int __fastcall TPreferencesDialog::GetCommandIndex(int Index)
  1066. {
  1067. if (Index >= FCustomCommandList->Count)
  1068. {
  1069. Index -= FCustomCommandList->Count;
  1070. }
  1071. return Index;
  1072. }
  1073. //---------------------------------------------------------------------------
  1074. int __fastcall TPreferencesDialog::GetListCommandIndex(TCustomCommandList * List)
  1075. {
  1076. int Index;
  1077. if (GetCommandList(CustomCommandsView->ItemIndex) == List)
  1078. {
  1079. Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1080. }
  1081. else
  1082. {
  1083. Index = -1;
  1084. }
  1085. return Index;
  1086. }
  1087. //---------------------------------------------------------------------------
  1088. int __fastcall TPreferencesDialog::GetCommandListIndex(TCustomCommandList * List, int Index)
  1089. {
  1090. if (List == FExtensionList)
  1091. {
  1092. Index += FCustomCommandList->Count;
  1093. }
  1094. return Index;
  1095. }
  1096. //---------------------------------------------------------------------------
  1097. void __fastcall TPreferencesDialog::UpdateControls()
  1098. {
  1099. if (FNoUpdate == 0)
  1100. {
  1101. EnableControl(DDTransferConfirmationCheck2, ConfirmTransferringCheck->Checked);
  1102. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  1103. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  1104. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  1105. EnableControl(ResumeThresholdUnitLabel2, ResumeThresholdEdit->Enabled);
  1106. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  1107. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  1108. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  1109. EnableControl(SessionReopenAutoIdleEdit, SessionReopenAutoIdleCheck->Checked);
  1110. EnableControl(SessionReopenAutoIdleLabel, SessionReopenAutoIdleEdit->Enabled);
  1111. EnableControl(SessionReopenAutoIdleSecLabel, SessionReopenAutoIdleEdit->Enabled);
  1112. EnableControl(SessionReopenAutoStallEdit, SessionReopenAutoStallCheck->Checked);
  1113. EnableControl(SessionReopenAutoStallLabel, SessionReopenAutoStallEdit->Enabled);
  1114. EnableControl(SessionReopenAutoStallSecLabel, SessionReopenAutoStallEdit->Enabled);
  1115. EnableControl(SessionReopenTimeoutEdit,
  1116. SessionReopenAutoEdit->Enabled || SessionReopenAutoStallCheck->Checked);
  1117. EnableControl(SessionReopenTimeoutLabel, SessionReopenTimeoutEdit->Enabled);
  1118. EnableControl(SessionReopenTimeoutSecLabel,SessionReopenTimeoutEdit->Enabled);
  1119. EnableControl(CopyOnDoubleClickConfirmationCheck,
  1120. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  1121. TFont * ActualPanelFont = PanelFontCheck->Checked ? FPanelFont.get() : Screen->IconFont;
  1122. std::unique_ptr<TFont> PanelFont(new TFont());
  1123. PanelFont->Assign(ActualPanelFont);
  1124. if (PanelFontCheck->Checked)
  1125. {
  1126. PanelFont->Height = ScaleByPixelsPerInchFromSystem(PanelFont->Height, this);
  1127. }
  1128. else
  1129. {
  1130. PanelFont->Height = ScaleByPixelsPerInchFromSystem(PanelFont->Height, this);
  1131. }
  1132. UnicodeString PanelFontLabelText;
  1133. PanelFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  1134. (ActualPanelFont->Name, ActualPanelFont->Size));
  1135. PanelFontLabel->Caption = PanelFontLabelText;
  1136. if (!SameFont(PanelFontLabel->Font, PanelFont.get()))
  1137. {
  1138. PanelFontLabel->Font = PanelFont.get();
  1139. }
  1140. EnableControl(RefreshRemotePanelIntervalEdit, RefreshRemotePanelCheck->Checked);
  1141. EnableControl(RefreshRemoteDirectoryUnitLabel, RefreshRemotePanelCheck->Checked);
  1142. UnicodeString EditorFontLabelText;
  1143. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  1144. (FEditorFont->Name, FEditorFont->Size)) + L"\n\n";
  1145. EditorFontLabelText += TabSample(L"ABCD") + L"\n";
  1146. EditorFontLabelText += TabSample(L"1234");
  1147. EditorFontLabel->Caption = EditorFontLabelText;
  1148. EditorFontLabel->Color = GetWindowColor(FEditorBackgroundColor);
  1149. std::unique_ptr<TFont> EditorFont(new TFont());
  1150. EditorFont->Assign(FEditorFont.get());
  1151. EditorFont->Color = GetWindowTextColor(EditorFontLabel->Color, FEditorFont->Color);
  1152. EditorFont->Size = ScaleByPixelsPerInchFromSystem(FEditorFont->Size, this);
  1153. if (!SameFont(EditorFontLabel->Font, EditorFont.get()) ||
  1154. (EditorFontLabel->Font->Color != EditorFont->Color))
  1155. {
  1156. EditorFontLabel->Font = EditorFont.get();
  1157. }
  1158. TCustomCommandList * CommandList = GetCommandList(CustomCommandsView->ItemIndex);
  1159. int CommandIndex = GetCommandIndex(CustomCommandsView->ItemIndex);
  1160. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  1161. bool CustomCommandSelected = CommandSelected && (CommandList == FCustomCommandList);
  1162. bool ExtensionSelected = CommandSelected && (CommandList == FExtensionList);
  1163. EnableControl(EditCommandButton, CustomCommandSelected);
  1164. EditCommandButton->Visible = !ExtensionSelected;
  1165. EnableControl(ConfigureCommandButton, ExtensionSelected);
  1166. ConfigureCommandButton->Visible = ExtensionSelected;
  1167. EnableControl(RemoveCommandButton, CommandSelected);
  1168. EnableControl(UpCommandButton, CommandSelected && (CommandIndex > 0));
  1169. EnableControl(DownCommandButton, CommandSelected && (CommandIndex < CommandList->Count - 1));
  1170. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  1171. EnableControl(EditCopyParamButton, CopyParamSelected);
  1172. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  1173. EnableControl(RemoveCopyParamButton,
  1174. CopyParamSelected && (CopyParamListView->ItemIndex >= 1));
  1175. EnableControl(UpCopyParamButton,
  1176. CopyParamSelected && (CopyParamListView->ItemIndex > 1));
  1177. EnableControl(DownCopyParamButton,
  1178. CopyParamSelected &&
  1179. (CopyParamListView->ItemIndex >= 1) &&
  1180. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  1181. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  1182. UnicodeString InfoStr;
  1183. if (CopyParamSelected)
  1184. {
  1185. const TCopyParamType * SelectedCopyParam = GetCopyParam(CopyParamListView->ItemIndex);
  1186. InfoStr = SelectedCopyParam->GetInfoStr(L"; ", 0);
  1187. if (CopyParamListView->ItemIndex >= 1)
  1188. {
  1189. const TCopyParamRule * Rule = FCopyParamList->Rules[CopyParamListView->ItemIndex - 1];
  1190. if (Rule != NULL)
  1191. {
  1192. InfoStr += L"\n" + FORMAT(ReplaceStr(LoadStr(COPY_PARAM_RULE), L"\n", L" "), (Rule->GetInfoStr(L"; ")));
  1193. }
  1194. }
  1195. }
  1196. SetLabelHintPopup(CopyParamLabel, InfoStr);
  1197. if (WinConfiguration->IsDDExtBroken())
  1198. {
  1199. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_BROKEN);
  1200. DragExtStatusLabel->Enabled = false;
  1201. DragExtStatusLabel->Font->Color = clWindowText;
  1202. }
  1203. else if (!WinConfiguration->DDExtInstalled)
  1204. {
  1205. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_INSTALLED);
  1206. DragExtStatusLabel->Enabled = false;
  1207. DragExtStatusLabel->Font->Color = clWindowText;
  1208. }
  1209. else if (!WinConfiguration->IsDDExtRunning())
  1210. {
  1211. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_NOT_RUNNING);
  1212. DragExtStatusLabel->Enabled = DDFakeFileEnabledButton->Checked;
  1213. DragExtStatusLabel->Font->Color = clGrayText;
  1214. }
  1215. else
  1216. {
  1217. DragExtStatusLabel->Caption = LoadStr(PREFERENCES_DRAGEXT_RUNNING);
  1218. DragExtStatusLabel->Enabled = DDFakeFileEnabledButton->Checked;
  1219. DragExtStatusLabel->Font->Color = clWindowText;
  1220. }
  1221. EnableControl(DDDrivesMemo, DDFakeFileEnabledButton->Checked);
  1222. EnableControl(DDDrivesLabel, DDDrivesMemo->Enabled);
  1223. EnableControl(DDFakeFileDisabledPanel, DDFakeFileDisabledButton->Checked);
  1224. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  1225. DDCustomTemporaryDirectoryButton->Checked);
  1226. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  1227. TemporaryDirectoryCleanupCheck->Checked);
  1228. // do not allow switching storage, when we start with stNul,
  1229. // as that would destroy the stored configuration
  1230. EnableControl(StorageGroup, Configuration->Storage != stNul);
  1231. AutomaticIniFileStorageLabel->UpdateStatus();
  1232. EnableControl(CustomIniFileStorageEdit, CustomIniFileStorageButton->Checked);
  1233. // editors
  1234. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  1235. bool EditorSelected = (EditorListView3->Selected != NULL);
  1236. EnableControl(EditEditorButton, EditorSelected);
  1237. EnableControl(RemoveEditorButton, EditorSelected);
  1238. EnableControl(UpEditorButton, EditorSelected &&
  1239. (EditorListView3->ItemIndex > 0));
  1240. EnableControl(DownEditorButton, EditorSelected &&
  1241. (EditorListView3->ItemIndex < EditorListView3->Items->Count - 1));
  1242. // file colors
  1243. bool FileColorSelected = (FileColorsView->Selected != NULL);
  1244. EnableControl(EditFileColorButton, FileColorSelected);
  1245. EnableControl(RemoveFileColorButton, FileColorSelected);
  1246. EnableControl(UpFileColorButton, FileColorSelected && (FileColorsView->ItemIndex > 0));
  1247. EnableControl(DownFileColorButton, FileColorSelected && (FileColorsView->ItemIndex < FileColorsView->Items->Count - 1));
  1248. // updates
  1249. EnableControl(UpdatesAuthenticationEmailEdit, FAutomaticUpdatesPossible);
  1250. EnableControl(UpdatesAuthenticationEmailLabel, UpdatesAuthenticationEmailEdit->Enabled);
  1251. EnableControl(UpdatesShowOnStartup, !IsUWP());
  1252. EnableControl(UsageViewButton, CollectUsageCheck->Checked);
  1253. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  1254. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  1255. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  1256. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  1257. bool IsSiteCommand = false;
  1258. bool IsPasswordCommand = false;
  1259. try
  1260. {
  1261. TRemoteCustomCommand RemoteCustomCommand;
  1262. TInteractiveCustomCommand InteractiveCustomCommand(&RemoteCustomCommand);
  1263. UnicodeString PuttyPath = PuttyPathEdit->Text;
  1264. PuttyPath = InteractiveCustomCommand.Complete(PuttyPath, false);
  1265. IsSiteCommand = RemoteCustomCommand.IsSiteCommand(PuttyPath);
  1266. IsPasswordCommand = RemoteCustomCommand.IsPasswordCommand(PuttyPath);
  1267. }
  1268. catch (...)
  1269. {
  1270. // noop
  1271. }
  1272. bool AnyPuttyPath = !PuttyPathEdit->Text.IsEmpty();
  1273. EnableControl(PuttyPasswordCheck2, AnyPuttyPath && !IsPasswordCommand);
  1274. EnableControl(AutoOpenInPuttyCheck, AnyPuttyPath);
  1275. EnableControl(TelnetForFtpInPuttyCheck,
  1276. AnyPuttyPath && !IsSiteCommand);
  1277. EnableControl(PuttyRegistryStorageKeyEdit,
  1278. AnyPuttyPath && !IsSiteCommand && !IsUWP());
  1279. EnableControl(PuttyRegistryStorageKeyLabel, PuttyRegistryStorageKeyEdit->Enabled);
  1280. EnableControl(SetMasterPasswordButton, WinConfiguration->UseMasterPassword);
  1281. // network
  1282. EnableControl(CustomExternalIpAddressEdit, CustomExternalIpAddressButton->Checked);
  1283. EnableControl(LocalPortNumberMinEdit, LocalPortNumberCheck->Checked);
  1284. EnableControl(LocalPortNumberMaxEdit, LocalPortNumberCheck->Checked);
  1285. EnableControl(LocalPortNumberRangeLabel, LocalPortNumberCheck->Checked);
  1286. // window
  1287. EnableControl(AutoWorkspaceCombo, AutoSaveWorkspaceCheck->Checked);
  1288. EnableControl(AutoWorkspaceLabel, AutoWorkspaceCombo->Enabled);
  1289. EnableControl(AutoSaveWorkspacePasswordsCheck,
  1290. !Configuration->DisablePasswordStoring &&
  1291. AutoWorkspaceCombo->Enabled);
  1292. EnableControl(ShowTipsCheck, AnyTips());
  1293. // integration
  1294. EnableControl(ShellIconsGroup, !IsUWP());
  1295. MakeDefaultHandlerItem->Visible = IsWinVista();
  1296. // languages
  1297. LanguageChangeLabel->Visible =
  1298. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1299. (LanguagesView->ItemFocused != NULL) &&
  1300. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1301. // logging
  1302. EnableControl(LogProtocolCombo2, EnableLoggingCheck->Checked);
  1303. EnableControl(LogFileNameEdit3, LogProtocolCombo2->Enabled);
  1304. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1305. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1306. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1307. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1308. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1309. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1310. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1311. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1312. EnableControl(LogSensitiveCheck, LogProtocolCombo2->Enabled);
  1313. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1314. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1315. LogProtocolHintLabel->Visible = (LogProtocolCombo2->ItemIndex - BelowNormalLogLevels >= 2);
  1316. // interface
  1317. InterfaceChangeLabel->Visible =
  1318. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1319. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1320. }
  1321. }
  1322. //---------------------------------------------------------------------------
  1323. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1324. {
  1325. if (FontDialog(FEditorFont.get()))
  1326. {
  1327. UpdateControls();
  1328. }
  1329. }
  1330. //---------------------------------------------------------------------------
  1331. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1332. {
  1333. FEditorFont->Color = Color;
  1334. UpdateControls();
  1335. }
  1336. //---------------------------------------------------------------------------
  1337. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1338. {
  1339. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1340. // "internal error" when passing menu directly to unique_ptr.
  1341. // Splitting it to two statements seems to help.
  1342. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick, TOpenLocalPathHandler::Open and TSelectMaskDialog::ColorButtonClick
  1343. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1344. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1345. FColorPopupMenu.reset(Menu);
  1346. MenuPopup(Menu, EditorFontColorButton);
  1347. }
  1348. //---------------------------------------------------------------------------
  1349. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1350. {
  1351. FEditorBackgroundColor = Color;
  1352. UpdateControls();
  1353. }
  1354. //---------------------------------------------------------------------------
  1355. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1356. {
  1357. // See comment in EditorFontColorButtonClick.
  1358. // We are using session color (contrary to editor text color) for background
  1359. // for a consistency with color selection menu on editor toolbar.
  1360. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1361. FColorPopupMenu.reset(PopupMenu);
  1362. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1363. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1367. {
  1368. if (FontDialog(FPanelFont.get()))
  1369. {
  1370. PanelFontCheck->Checked = true;
  1371. UpdateControls();
  1372. }
  1373. }
  1374. //---------------------------------------------------------------------------
  1375. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1376. bool & /*CanClose*/)
  1377. {
  1378. if (ModalResult == DefaultResult(this))
  1379. {
  1380. ExitActiveControl(this);
  1381. }
  1382. }
  1383. //---------------------------------------------------------------------------
  1384. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1385. {
  1386. UnicodeString IconName, Params;
  1387. int SpecialFolder;
  1388. if (Sender == DesktopIconButton)
  1389. {
  1390. IconName = AppName;
  1391. int Result =
  1392. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1393. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1394. switch (Result)
  1395. {
  1396. case qaYes:
  1397. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1398. break;
  1399. case qaNo:
  1400. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1401. break;
  1402. default:
  1403. Abort();
  1404. break;
  1405. }
  1406. }
  1407. else if (Sender == SendToHookButton)
  1408. {
  1409. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1410. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1411. {
  1412. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1413. SpecialFolder = CSIDL_SENDTO;
  1414. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1415. }
  1416. else
  1417. {
  1418. Abort();
  1419. }
  1420. }
  1421. else
  1422. {
  1423. DebugFail();
  1424. Abort();
  1425. }
  1426. TInstantOperationVisualizer Visualizer;
  1427. CreateAppDesktopShortCut(IconName, Params, L"", SpecialFolder);
  1428. }
  1429. //---------------------------------------------------------------------------
  1430. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1431. TListItem * Item)
  1432. {
  1433. // WORKAROUND We get here on Wine after destructor is called
  1434. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1435. {
  1436. int Index = Item->Index;
  1437. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1438. UnicodeString Caption = StripHotkey(Command->Name);
  1439. Item->Caption = Caption;
  1440. DebugAssert(!Item->SubItems->Count);
  1441. Item->SubItems->Add(Command->Command);
  1442. Item->SubItems->Add(LoadStr(
  1443. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1444. }
  1445. }
  1446. //---------------------------------------------------------------------------
  1447. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1448. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1449. {
  1450. UpdateControls();
  1451. }
  1452. //---------------------------------------------------------------------------
  1453. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1454. {
  1455. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1456. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1457. CustomCommandsView->Invalidate();
  1458. // particularly after command is edited/configured, make sure the hint is updated,
  1459. // even if we manage to display a hint for the same command as before the change
  1460. FCustomCommandsHintItem = NULL;
  1461. }
  1462. //---------------------------------------------------------------------------
  1463. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1464. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1465. {
  1466. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1467. {
  1468. RemoveCommandButtonClick(NULL);
  1469. }
  1470. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1471. {
  1472. AddEditCommand(false);
  1473. }
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1477. TObject * /*Sender*/)
  1478. {
  1479. if (EditCommandButton->Enabled)
  1480. {
  1481. AddEditCommand(true);
  1482. }
  1483. else if (ConfigureCommandButton->Enabled)
  1484. {
  1485. ConfigureCommand();
  1486. }
  1487. }
  1488. //---------------------------------------------------------------------------
  1489. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1490. {
  1491. if (Index >= 0)
  1492. {
  1493. List->Insert(Index, Command);
  1494. }
  1495. else
  1496. {
  1497. List->Add(Command);
  1498. Index = List->Count - 1;
  1499. }
  1500. return Index;
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1504. {
  1505. TShortCuts ShortCuts;
  1506. if (WinConfiguration->SharedBookmarks != NULL)
  1507. {
  1508. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1509. }
  1510. FCustomCommandList->ShortCuts(ShortCuts);
  1511. FExtensionList->ShortCuts(ShortCuts);
  1512. return ShortCuts;
  1513. }
  1514. //---------------------------------------------------------------------------
  1515. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1516. {
  1517. TCustomCommandType Command;
  1518. if (Edit)
  1519. {
  1520. int Index = CustomCommandsView->ItemIndex;
  1521. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1522. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1523. }
  1524. TShortCuts ShortCuts = GetShortCuts();
  1525. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1526. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1527. {
  1528. int Index = GetListCommandIndex(FCustomCommandList);
  1529. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1530. if (Edit)
  1531. {
  1532. DebugAssert(Index < FCustomCommandList->Count);
  1533. FCustomCommandList->Change(Index, ACommand);
  1534. }
  1535. else
  1536. {
  1537. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1538. }
  1539. UpdateCustomCommandsView();
  1540. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1541. CustomCommandsView->ItemFocused->MakeVisible(false);
  1542. UpdateControls();
  1543. }
  1544. }
  1545. //---------------------------------------------------------------------------
  1546. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1547. TObject * /*Sender*/)
  1548. {
  1549. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1550. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1551. if (List == FExtensionList)
  1552. {
  1553. const TCustomCommandType * CustomComand = List->Commands[Index];
  1554. // If the extension was added in this "preferences session", remove the file
  1555. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1556. if (PathIndex >= 0)
  1557. {
  1558. FAddedExtensions->Delete(PathIndex);
  1559. DeleteFile(ApiPath(CustomComand->FileName));
  1560. }
  1561. }
  1562. List->Delete(Index);
  1563. UpdateCustomCommandsView();
  1564. UpdateControls();
  1565. }
  1566. //---------------------------------------------------------------------------
  1567. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1568. {
  1569. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1570. int SourceIndex = GetCommandIndex(Source);
  1571. int DestIndex = GetCommandIndex(Dest);
  1572. List->Move(SourceIndex, DestIndex);
  1573. CustomCommandsView->ItemIndex = Dest;
  1574. UpdateCustomCommandsView();
  1575. UpdateControls();
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1579. {
  1580. CustomCommandMove(CustomCommandsView->ItemIndex,
  1581. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1585. {
  1586. if (ListView == CopyParamListView)
  1587. {
  1588. return FCopyParamScrollOnDragOver;
  1589. }
  1590. else if (ListView == CustomCommandsView)
  1591. {
  1592. return FCustomCommandsScrollOnDragOver;
  1593. }
  1594. else if (ListView == EditorListView3)
  1595. {
  1596. return FEditorScrollOnDragOver;
  1597. }
  1598. else if (ListView == FileColorsView)
  1599. {
  1600. return FFileColorScrollOnDragOver;
  1601. }
  1602. else
  1603. {
  1604. DebugFail();
  1605. return NULL;
  1606. }
  1607. }
  1608. //---------------------------------------------------------------------------
  1609. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1610. TObject * Sender, TDragObject *& /*DragObject*/)
  1611. {
  1612. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1613. FListViewDragDest = -1;
  1614. ScrollOnDragOver(Sender)->StartDrag();
  1615. }
  1616. //---------------------------------------------------------------------------
  1617. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1618. {
  1619. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1620. return Item ? Item->Index : -1;
  1621. }
  1622. //---------------------------------------------------------------------------
  1623. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1624. {
  1625. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1626. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1627. }
  1628. //---------------------------------------------------------------------------
  1629. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1630. TObject * Sender, TObject * Source, int X, int Y)
  1631. {
  1632. if (Source == CustomCommandsView)
  1633. {
  1634. if (AllowListViewDrag(Sender, X, Y) &&
  1635. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1636. {
  1637. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1638. }
  1639. }
  1640. }
  1641. //---------------------------------------------------------------------------
  1642. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1643. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1644. {
  1645. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1646. if (Source == Sender)
  1647. {
  1648. int Dest = PointToListViewIndex(Sender, X, Y);
  1649. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1650. {
  1651. Accept = false;
  1652. }
  1653. }
  1654. }
  1655. //---------------------------------------------------------------------------
  1656. void __fastcall TPreferencesDialog::ListViewDragOver(
  1657. TObject * Sender, TObject * Source, int X, int Y,
  1658. TDragState /*State*/, bool & Accept)
  1659. {
  1660. if (Source == Sender)
  1661. {
  1662. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1663. // (when dropped on item itself, when it was dragged over another item before,
  1664. // that another item remains highlighted forever)
  1665. Accept = true;
  1666. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1667. }
  1668. }
  1669. //---------------------------------------------------------------------------
  1670. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1671. {
  1672. if (Index == 0)
  1673. {
  1674. return &FCopyParams;
  1675. }
  1676. else
  1677. {
  1678. return FCopyParamList->CopyParams[Index - 1];
  1679. }
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1683. {
  1684. DebugAssert((Source > 0) && (Dest > 0));
  1685. FCopyParamList->Move(Source - 1, Dest - 1);
  1686. CopyParamListView->ItemIndex = Dest;
  1687. UpdateCopyParamListView();
  1688. UpdateControls();
  1689. }
  1690. //---------------------------------------------------------------------------
  1691. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1692. TObject * Sender, TObject * Source, int X, int Y)
  1693. {
  1694. if (Source == CopyParamListView)
  1695. {
  1696. if ((FListViewDragSource > 0) &&
  1697. AllowListViewDrag(Sender, X, Y) &&
  1698. (FListViewDragDest > 0))
  1699. {
  1700. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1701. }
  1702. }
  1703. }
  1704. //---------------------------------------------------------------------------
  1705. void __fastcall TPreferencesDialog::CopyParamListViewDragOver(
  1706. TObject * Sender, TObject * Source, int X, int Y, TDragState State, bool & Accept)
  1707. {
  1708. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1709. if (Source == Sender)
  1710. {
  1711. int Dest = PointToListViewIndex(Sender, X, Y);
  1712. if ((FListViewDragSource == 0) || (Dest == 0))
  1713. {
  1714. Accept = false;
  1715. }
  1716. }
  1717. }
  1718. //---------------------------------------------------------------------------
  1719. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1720. {
  1721. CopyParamMove(CopyParamListView->ItemIndex,
  1722. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1723. }
  1724. //---------------------------------------------------------------------------
  1725. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1726. TObject * /*Sender*/)
  1727. {
  1728. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1729. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1730. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1731. UpdateCopyParamListView();
  1732. UpdateControls();
  1733. }
  1734. //---------------------------------------------------------------------------
  1735. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1736. {
  1737. int Index = CopyParamListView->ItemIndex;
  1738. bool Result;
  1739. if ((Index == 0) && (Mode == cpmEdit))
  1740. {
  1741. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1742. }
  1743. else
  1744. {
  1745. TCopyParamRuleData * CopyParamRuleData =
  1746. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1747. // negative (when default is selected) means add to the end
  1748. Index--;
  1749. TCopyParamType DefaultCopyParams;
  1750. // For cpmAdd use defaults.
  1751. if (Mode == cpmDuplicate)
  1752. {
  1753. // Only used, when duplicating default settings (Index < 0)
  1754. DefaultCopyParams = FCopyParams;
  1755. }
  1756. else if (Mode == cpmEdit)
  1757. {
  1758. // For cpmEdit, DefaultCopyParams is never used.
  1759. DebugAssert(Index >= 0);
  1760. }
  1761. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1762. if (Result)
  1763. {
  1764. UpdateCopyParamListView();
  1765. CopyParamListView->ItemIndex = Index + 1;
  1766. // when using duplicate button, focus remains on original item
  1767. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1768. }
  1769. }
  1770. if (Result)
  1771. {
  1772. UpdateControls();
  1773. }
  1774. }
  1775. //---------------------------------------------------------------------------
  1776. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1777. {
  1778. AddEditCopyParam(cpmAdd);
  1779. }
  1780. //---------------------------------------------------------------------------
  1781. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1782. {
  1783. AddEditCopyParam(cpmEdit);
  1784. }
  1785. //---------------------------------------------------------------------------
  1786. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1787. {
  1788. AddEditCopyParam(cpmDuplicate);
  1789. }
  1790. //---------------------------------------------------------------------------
  1791. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1792. TObject * /*Sender*/)
  1793. {
  1794. if (EditCopyParamButton->Enabled)
  1795. {
  1796. AddEditCopyParam(cpmEdit);
  1797. }
  1798. }
  1799. //---------------------------------------------------------------------------
  1800. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1801. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1802. {
  1803. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1804. {
  1805. RemoveCopyParamButtonClick(NULL);
  1806. }
  1807. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1808. {
  1809. AddEditCopyParam(cpmAdd);
  1810. }
  1811. }
  1812. //---------------------------------------------------------------------------
  1813. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1814. {
  1815. FEditorList->Move(Source, Dest);
  1816. EditorListView3->ItemIndex = Dest;
  1817. UpdateEditorListView();
  1818. UpdateControls();
  1819. }
  1820. //---------------------------------------------------------------------------
  1821. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1822. TObject * Source, int X, int Y)
  1823. {
  1824. if (Source == EditorListView3)
  1825. {
  1826. if (AllowListViewDrag(Sender, X, Y))
  1827. {
  1828. EditorMove(FListViewDragSource, FListViewDragDest);
  1829. }
  1830. }
  1831. }
  1832. //---------------------------------------------------------------------------
  1833. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1834. {
  1835. EditorMove(EditorListView3->ItemIndex,
  1836. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1837. }
  1838. //---------------------------------------------------------------------------
  1839. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1840. TObject * /*Sender*/)
  1841. {
  1842. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1843. EditorListView3->ItemIndex < FEditorList->Count);
  1844. FEditorList->Delete(EditorListView3->ItemIndex);
  1845. UpdateEditorListView();
  1846. UpdateControls();
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1850. {
  1851. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1852. int Index = EditorListView3->ItemIndex;
  1853. TEditorPreferences * Editor;
  1854. if (Mode == epmEdit)
  1855. {
  1856. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1857. }
  1858. else
  1859. {
  1860. Editor = new TEditorPreferences();
  1861. }
  1862. try
  1863. {
  1864. bool DummyRemember = false;
  1865. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1866. {
  1867. if (Mode == epmEdit)
  1868. {
  1869. FEditorList->Change(Index, Editor);
  1870. }
  1871. else
  1872. {
  1873. if (Index < 0)
  1874. {
  1875. Index = FEditorList->Count;
  1876. FEditorList->Add(Editor);
  1877. }
  1878. else
  1879. {
  1880. FEditorList->Insert(Index, Editor);
  1881. }
  1882. }
  1883. // ownership of the object lost
  1884. Editor = NULL;
  1885. UpdateEditorListView();
  1886. EditorListView3->ItemIndex = Index;
  1887. UpdateControls();
  1888. }
  1889. }
  1890. __finally
  1891. {
  1892. delete Editor;
  1893. }
  1894. }
  1895. //---------------------------------------------------------------------------
  1896. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1897. {
  1898. if (EditEditorButton->Enabled)
  1899. {
  1900. AddEditEditorButtonClick(EditEditorButton);
  1901. }
  1902. }
  1903. //---------------------------------------------------------------------------
  1904. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1905. WORD & Key, TShiftState /*Shift*/)
  1906. {
  1907. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1908. {
  1909. RemoveEditorButtonClick(NULL);
  1910. }
  1911. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1912. {
  1913. AddEditEditorButtonClick(AddEditorButton);
  1914. }
  1915. }
  1916. //---------------------------------------------------------------------------
  1917. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1918. {
  1919. EditorListView3->Items->Count = FEditorList->Count;
  1920. AutoSizeListColumnsWidth(EditorListView3);
  1921. EditorListView3->Invalidate();
  1922. }
  1923. //---------------------------------------------------------------------------
  1924. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1925. TListItem * Item)
  1926. {
  1927. // WORKAROUND We get here on Wine after destructor is called
  1928. if (FEditorList != NULL)
  1929. {
  1930. int Index = Item->Index;
  1931. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1932. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1933. Item->Caption = Editor->Name;
  1934. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1935. if (Editor->Data->Editor == edExternal)
  1936. {
  1937. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1938. }
  1939. }
  1940. }
  1941. //---------------------------------------------------------------------------
  1942. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1943. TTreeNode * Node)
  1944. {
  1945. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1946. {
  1947. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1948. // reshow the accelerators, etc
  1949. ResetSystemSettings(this);
  1950. // This is particularly here to enable EditCopyParamButton,
  1951. // as for some reason CopyParamListView->Selected is NULL until
  1952. // its page is shown for the first time
  1953. UpdateControls();
  1954. }
  1955. }
  1956. //---------------------------------------------------------------------------
  1957. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1958. {
  1959. // this is probably only ever called from FormShow (explicitly)
  1960. bool Found = false;
  1961. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1962. {
  1963. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1964. {
  1965. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1966. PageControl->ActivePage->Tag)
  1967. {
  1968. NavigationTree->Items->Item[Index]->Selected = true;
  1969. Found = true;
  1970. }
  1971. }
  1972. }
  1973. if (DebugAlwaysTrue(Found))
  1974. {
  1975. UpdateControls();
  1976. }
  1977. }
  1978. //---------------------------------------------------------------------------
  1979. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1980. {
  1981. if (Message.CharCode == VK_TAB)
  1982. {
  1983. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1984. if (Shift.Contains(ssCtrl))
  1985. {
  1986. TTreeNode * Node = NavigationTree->Selected;
  1987. if (!Shift.Contains(ssShift))
  1988. {
  1989. Node = Node->GetNext();
  1990. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1991. }
  1992. else
  1993. {
  1994. if (Node->GetPrev()) Node = Node->GetPrev();
  1995. else
  1996. while (Node->GetNext()) Node = Node->GetNext();
  1997. }
  1998. Node->Selected = True;
  1999. Message.Result = 1;
  2000. return;
  2001. }
  2002. }
  2003. TForm::Dispatch(&Message);
  2004. }
  2005. //---------------------------------------------------------------------------
  2006. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  2007. {
  2008. DebugAssert(Message.HelpInfo != NULL);
  2009. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  2010. {
  2011. // invoke help for active page (not for whole form), regardless of focus
  2012. // (e.g. even if focus is on control outside pagecontrol)
  2013. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  2014. }
  2015. TForm::Dispatch(&Message);
  2016. }
  2017. //---------------------------------------------------------------------------
  2018. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  2019. {
  2020. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  2021. // we may end up using a slightly different size, so apply it straight away for consistency
  2022. UpdateControls();
  2023. TForm::Dispatch(&Message);
  2024. }
  2025. //---------------------------------------------------------------------------
  2026. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  2027. {
  2028. TMessage * M = reinterpret_cast<TMessage*>(Message);
  2029. DebugAssert(M);
  2030. if (M->Msg == CM_DIALOGKEY)
  2031. {
  2032. CMDialogKey(*((TWMKeyDown *)Message));
  2033. }
  2034. else if (M->Msg == CM_DPICHANGED)
  2035. {
  2036. CMDpiChanged(*M);
  2037. }
  2038. else if (M->Msg == WM_HELP)
  2039. {
  2040. WMHelp(*((TWMHelp *)Message));
  2041. }
  2042. else
  2043. {
  2044. TForm::Dispatch(Message);
  2045. }
  2046. }
  2047. //---------------------------------------------------------------------------
  2048. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  2049. TObject * /*Sender*/)
  2050. {
  2051. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  2052. }
  2053. //---------------------------------------------------------------------------
  2054. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  2055. {
  2056. unsigned int Result =
  2057. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  2058. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2059. if (Result == qaYes)
  2060. {
  2061. TInstantOperationVisualizer Visualizer;
  2062. RegisterForDefaultProtocols();
  2063. }
  2064. }
  2065. //---------------------------------------------------------------------------
  2066. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  2067. {
  2068. unsigned int Result =
  2069. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  2070. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2071. if (Result == qaYes)
  2072. {
  2073. TInstantOperationVisualizer Visualizer;
  2074. UnregisterForProtocols();
  2075. }
  2076. }
  2077. //---------------------------------------------------------------------------
  2078. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  2079. {
  2080. TOperationVisualizer Visualizer;
  2081. LaunchAdvancedAssociationUI();
  2082. }
  2083. //---------------------------------------------------------------------------
  2084. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  2085. {
  2086. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  2087. }
  2088. //---------------------------------------------------------------------------
  2089. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  2090. TObject * /*Sender*/)
  2091. {
  2092. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  2093. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  2094. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  2095. {
  2096. TInstantOperationVisualizer Visualizer;
  2097. AddSearchPath(AppPath);
  2098. }
  2099. }
  2100. //---------------------------------------------------------------------------
  2101. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2102. TObject * Sender)
  2103. {
  2104. EditorFontButtonClick(Sender);
  2105. }
  2106. //---------------------------------------------------------------------------
  2107. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2108. {
  2109. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2110. AutoSizeListColumnsWidth(CopyParamListView);
  2111. CopyParamListView->Invalidate();
  2112. }
  2113. //---------------------------------------------------------------------------
  2114. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2115. TListItem * Item)
  2116. {
  2117. // WORKAROUND We get here on Wine after destructor is called
  2118. if (FCopyParamList != NULL)
  2119. {
  2120. UnicodeString Name;
  2121. UnicodeString Rule;
  2122. int Index = Item->Index;
  2123. if (Index == 0)
  2124. {
  2125. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2126. }
  2127. else
  2128. {
  2129. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2130. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2131. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2132. }
  2133. Item->Caption = Name;
  2134. Item->SubItems->Add(Rule);
  2135. }
  2136. }
  2137. //---------------------------------------------------------------------------
  2138. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2139. {
  2140. FormHelp(this);
  2141. }
  2142. //---------------------------------------------------------------------------
  2143. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2144. TObject * /*Sender*/)
  2145. {
  2146. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2147. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2148. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2149. }
  2150. //---------------------------------------------------------------------------
  2151. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2152. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2153. {
  2154. FBeforeDialogPath = Name;
  2155. Name = ExpandEnvironmentVariables(Name);
  2156. }
  2157. //---------------------------------------------------------------------------
  2158. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2159. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2160. {
  2161. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2162. {
  2163. Name = FBeforeDialogPath;
  2164. }
  2165. }
  2166. //---------------------------------------------------------------------------
  2167. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2168. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2169. {
  2170. AllowCollapse = false;
  2171. }
  2172. //---------------------------------------------------------------------------
  2173. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2174. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2175. {
  2176. ScrollOnDragOver(Sender)->EndDrag();
  2177. }
  2178. //---------------------------------------------------------------------------
  2179. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2180. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2181. {
  2182. if (Value == 0)
  2183. {
  2184. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2185. Handled = true;
  2186. }
  2187. }
  2188. //---------------------------------------------------------------------------
  2189. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2190. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2191. {
  2192. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2193. {
  2194. Value = 0;
  2195. Handled = true;
  2196. }
  2197. }
  2198. //---------------------------------------------------------------------------
  2199. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2200. {
  2201. bool Result;
  2202. bool Retry;
  2203. do
  2204. {
  2205. Retry = false;
  2206. Result = !AnyOtherInstanceOfSelf();
  2207. if (!Result)
  2208. {
  2209. unsigned int Answer =
  2210. MessageDialog(
  2211. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2212. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2213. HELP_MASTER_PASSWORD);
  2214. switch (Answer)
  2215. {
  2216. case qaRetry:
  2217. Retry = true;
  2218. break;
  2219. case qaIgnore:
  2220. Result = true;
  2221. break;
  2222. case qaCancel:
  2223. default:
  2224. // noop
  2225. break;
  2226. }
  2227. }
  2228. }
  2229. while (Retry && !Result);
  2230. return Result;
  2231. }
  2232. //---------------------------------------------------------------------------
  2233. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2234. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2235. {
  2236. // Save master password.
  2237. // This is unlikely to fail, as storage is written explicitly already
  2238. // when writing the recrypted passwords
  2239. Configuration->SaveExplicit();
  2240. TQueryType QueryType = qtInformation;
  2241. if (RecryptPasswordErrors->Count > 0)
  2242. {
  2243. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2244. QueryType = qtWarning;
  2245. }
  2246. MoreMessageDialog(
  2247. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2248. }
  2249. //---------------------------------------------------------------------------
  2250. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2251. {
  2252. UnicodeString NewPassword;
  2253. if (DoChangeMasterPasswordDialog(NewPassword))
  2254. {
  2255. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2256. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2257. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2258. }
  2259. }
  2260. //---------------------------------------------------------------------------
  2261. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2262. TObject * /*Sender*/)
  2263. {
  2264. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2265. {
  2266. try
  2267. {
  2268. if (CanSetMasterPassword())
  2269. {
  2270. if (UseMasterPasswordCheck->Checked)
  2271. {
  2272. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2273. }
  2274. else
  2275. {
  2276. if (DoMasterPasswordDialog())
  2277. {
  2278. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2279. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2280. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2281. }
  2282. }
  2283. }
  2284. }
  2285. __finally
  2286. {
  2287. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2288. UpdateControls();
  2289. }
  2290. }
  2291. }
  2292. //---------------------------------------------------------------------------
  2293. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2294. TObject * /*Sender*/)
  2295. {
  2296. if (CanSetMasterPassword())
  2297. {
  2298. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2299. }
  2300. }
  2301. //---------------------------------------------------------------------------
  2302. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2303. {
  2304. DoUsageStatisticsDialog();
  2305. }
  2306. //---------------------------------------------------------------------------
  2307. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2308. {
  2309. if (EditCopyParamButton->Enabled)
  2310. {
  2311. AddEditCopyParam(cpmEdit);
  2312. }
  2313. }
  2314. //---------------------------------------------------------------------------
  2315. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2316. TCustomListView * Sender, TListItem * Item,
  2317. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2318. {
  2319. if (Item->Index == 0)
  2320. {
  2321. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2322. }
  2323. }
  2324. //---------------------------------------------------------------------------
  2325. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2326. {
  2327. PuttyRegistryStorageKeyEdit->ItemIndex =
  2328. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2329. }
  2330. //---------------------------------------------------------------------------
  2331. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2332. {
  2333. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2334. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2335. {
  2336. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2337. }
  2338. else if (ContainsText(PuttyPath, KittyExecutable))
  2339. {
  2340. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2341. }
  2342. UpdateControls();
  2343. }
  2344. //---------------------------------------------------------------------------
  2345. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2346. TTreeNode * Node, bool & /*AllowChange*/)
  2347. {
  2348. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2349. // delay load as this can be time consuming
  2350. if (Sheet == LanguagesSheet)
  2351. {
  2352. LoadLanguages();
  2353. }
  2354. }
  2355. //---------------------------------------------------------------------------
  2356. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2357. {
  2358. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2359. }
  2360. //---------------------------------------------------------------------------
  2361. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2362. {
  2363. CommanderInterfaceButton2->SetFocus();
  2364. }
  2365. //---------------------------------------------------------------------------
  2366. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2367. {
  2368. ExplorerInterfaceButton2->SetFocus();
  2369. }
  2370. //---------------------------------------------------------------------------
  2371. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2372. {
  2373. PanelFontButtonClick(Sender);
  2374. }
  2375. //---------------------------------------------------------------------------
  2376. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2377. {
  2378. if (!IsCancelButtonBeingClicked(this))
  2379. {
  2380. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2381. {
  2382. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2383. {
  2384. TUpdatesConfiguration Updates = SaveUpdates();
  2385. {
  2386. TInstantOperationVisualizer Visualizer;
  2387. QueryUpdates(Updates);
  2388. }
  2389. if (!Updates.Results.AuthenticationError.IsEmpty())
  2390. {
  2391. UnicodeString AuthenticationError;
  2392. FormatUpdatesMessage(AuthenticationError, Updates.Results.AuthenticationError, Updates);
  2393. if (HasParagraphs(AuthenticationError))
  2394. {
  2395. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2396. }
  2397. else
  2398. {
  2399. AuthenticationError = MainInstructions(AuthenticationError);
  2400. }
  2401. unsigned int Result =
  2402. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HELP_AUTOMATIC_UPDATE);
  2403. if (Result == qaAbort)
  2404. {
  2405. Abort();
  2406. }
  2407. }
  2408. }
  2409. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2410. }
  2411. }
  2412. }
  2413. //---------------------------------------------------------------------------
  2414. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2415. {
  2416. EnableAutomaticUpdates();
  2417. }
  2418. //---------------------------------------------------------------------------
  2419. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2420. {
  2421. FOrigCustomCommandsViewWindowProc(Message);
  2422. if (Message.Msg == CN_NOTIFY)
  2423. {
  2424. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2425. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2426. {
  2427. // request CDDS_ITEMPOSTPAINT notification
  2428. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2429. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2430. int Index = CustomDraw->nmcd.dwItemSpec;
  2431. int CommandIndex = GetCommandIndex(Index);
  2432. TCustomCommandList * List = GetCommandList(Index);
  2433. // after end of every list, except for the last last list
  2434. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2435. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2436. {
  2437. TRect Rect;
  2438. Rect.Top = CustomDraw->iSubItem;
  2439. Rect.Left = LVIR_BOUNDS;
  2440. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2441. HDC DC = CustomDraw->nmcd.hdc;
  2442. SelectObject(DC, GetStockObject(DC_PEN));
  2443. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2444. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2445. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2446. }
  2447. }
  2448. }
  2449. }
  2450. //---------------------------------------------------------------------------
  2451. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2452. {
  2453. if ((Status / 10) == 49)
  2454. {
  2455. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2456. throw Exception(Message);
  2457. }
  2458. }
  2459. //---------------------------------------------------------------------------
  2460. void __fastcall TPreferencesDialog::AddExtension()
  2461. {
  2462. const UnicodeString HistoryKey(L"ExtensionPath");
  2463. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2464. UnicodeString Path;
  2465. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2466. HELP_ADD_EXTENSION, History.get(), true, NULL, true, 400) &&
  2467. !Path.IsEmpty())
  2468. {
  2469. CustomWinConfiguration->History[HistoryKey] = History.get();
  2470. bool Trusted;
  2471. bool Latest;
  2472. UnicodeString FileName;
  2473. UnicodeString ExtensionPath;
  2474. UnicodeString LinesSourcePath;
  2475. std::unique_ptr<TStringList> Lines(new TStringList());
  2476. std::unique_ptr<TCustomCommandType> CustomCommand;
  2477. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2478. try
  2479. {
  2480. UnicodeString ProvisionaryId;
  2481. if (IsUrl)
  2482. {
  2483. UnicodeString Url = Path;
  2484. Url = SecureUrl(Url);
  2485. bool WinSCPURL = IsWinSCPUrl(Url);
  2486. if (WinSCPURL)
  2487. {
  2488. Url = ProgramUrl(Url);
  2489. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2490. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2491. Url = AppendUrlParams(Url, FORMAT(L"netcore=%s", (EncodeUrlString(GetNetCoreVersionStr()))));
  2492. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2493. Url = AppendUrlParams(Url, FORMAT(L"pwsh=%s", (EncodeUrlString(GetPowerShellCoreVersionStr()))));
  2494. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2495. Url = CampaignUrl(Url);
  2496. }
  2497. TOperationVisualizer Visualizer;
  2498. std::unique_ptr<THttp> Http(CreateHttp());
  2499. Http->URL = Url;
  2500. std::unique_ptr<TStrings> Headers(new TStringList());
  2501. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2502. Http->RequestHeaders = Headers.get();
  2503. Http->OnError = ExtensionHttpError;
  2504. Http->Get();
  2505. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2506. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2507. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2508. if (FileName.IsEmpty())
  2509. {
  2510. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2511. }
  2512. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2513. Lines->Text = Http->Response;
  2514. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2515. }
  2516. else
  2517. {
  2518. if (!FileExists(ApiPath(Path)))
  2519. {
  2520. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2521. }
  2522. Trusted = true;
  2523. Latest = true;
  2524. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2525. FileName = ExtractFileName(Path);
  2526. if (!Id.IsEmpty())
  2527. {
  2528. ExtensionPath = Path;
  2529. ProvisionaryId = Id;
  2530. }
  2531. else
  2532. {
  2533. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2534. }
  2535. LinesSourcePath = Path;
  2536. LoadScriptFromFile(Path, Lines.get());
  2537. }
  2538. // validate syntax
  2539. CustomCommand.reset(new TCustomCommandType());
  2540. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2541. CustomCommand->Id = ProvisionaryId;
  2542. CustomCommand->LoadExtension(Lines.get(), FileName);
  2543. }
  2544. catch (Exception & E)
  2545. {
  2546. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2547. }
  2548. if (!ExtensionPath.IsEmpty())
  2549. {
  2550. int Index = FExtensionList->FindIndexByFileName(Path);
  2551. if (Index >= 0)
  2552. {
  2553. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2554. CustomCommandsView->ItemFocused->MakeVisible(false);
  2555. CustomCommandsView->SetFocus();
  2556. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2557. }
  2558. }
  2559. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2560. {
  2561. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2562. }
  2563. if (ExtensionPath.IsEmpty())
  2564. {
  2565. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2566. {
  2567. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2568. if (FileNameOnly.IsEmpty())
  2569. {
  2570. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2571. }
  2572. else
  2573. {
  2574. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2575. }
  2576. }
  2577. }
  2578. if (Trusted ||
  2579. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2580. {
  2581. if (ExtensionPath.IsEmpty())
  2582. {
  2583. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2584. if (!DirectoryExists(UserExtensionsPath) &&
  2585. !ForceDirectories(UserExtensionsPath))
  2586. {
  2587. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2588. }
  2589. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2590. int Counter = 1;
  2591. UnicodeString OriginalExtensionPath = ExtensionPath;
  2592. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2593. while (FileExists(ApiPath(ExtensionPath)))
  2594. {
  2595. Counter++;
  2596. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2597. }
  2598. if (!LinesSourcePath.IsEmpty())
  2599. {
  2600. // Copy as is, exactly preserving the file encoding
  2601. TFile::Copy(ApiPath(LinesSourcePath), ApiPath(ExtensionPath));
  2602. }
  2603. else
  2604. {
  2605. Lines->WriteBOM = false;
  2606. Lines->SaveToFile(ApiPath(ExtensionPath));
  2607. }
  2608. FAddedExtensions->Add(ExtensionPath);
  2609. }
  2610. int Index = GetListCommandIndex(FExtensionList);
  2611. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2612. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2613. CustomCommand->LoadExtension(ExtensionPath);
  2614. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2615. UpdateCustomCommandsView();
  2616. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2617. CustomCommandsView->ItemFocused->MakeVisible(false);
  2618. UpdateControls();
  2619. if (!Latest)
  2620. {
  2621. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2622. }
  2623. if (IsUrl)
  2624. {
  2625. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2626. }
  2627. else
  2628. {
  2629. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2630. }
  2631. }
  2632. }
  2633. }
  2634. //---------------------------------------------------------------------------
  2635. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2636. {
  2637. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2638. {
  2639. AddEditCommand(false);
  2640. }
  2641. else
  2642. {
  2643. AddExtension();
  2644. }
  2645. }
  2646. //---------------------------------------------------------------------------
  2647. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2648. {
  2649. AddEditCommand(false);
  2650. }
  2651. //---------------------------------------------------------------------------
  2652. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2653. {
  2654. AddExtension();
  2655. }
  2656. //---------------------------------------------------------------------------
  2657. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2658. {
  2659. AddEditCommand(true);
  2660. }
  2661. //---------------------------------------------------------------------------
  2662. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2663. {
  2664. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2665. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2666. MenuPopup(AddCommandMenu, AddCommandButton);
  2667. }
  2668. //---------------------------------------------------------------------------
  2669. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2670. {
  2671. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2672. UnicodeString Result;
  2673. if (Terminal != NULL)
  2674. {
  2675. Result = Terminal->SessionData->SessionKey;
  2676. }
  2677. return Result;
  2678. }
  2679. //---------------------------------------------------------------------------
  2680. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2681. {
  2682. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2683. int Index = (Item != NULL) ? Item->Index : -1;
  2684. if (Index != FCustomCommandsHintItem)
  2685. {
  2686. Application->CancelHint();
  2687. UnicodeString Hint;
  2688. if (Index >= 0)
  2689. {
  2690. TCustomCommandList * List = GetCommandList(Index);
  2691. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2692. Hint = StripHotkey(Command->Name);
  2693. if (Command->ShortCut != 0)
  2694. {
  2695. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2696. }
  2697. if (!Command->Description.IsEmpty())
  2698. {
  2699. Hint += L"\n" + Command->Description;
  2700. }
  2701. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2702. if (List == FExtensionList)
  2703. {
  2704. Hint += L"\n" + Command->FileName;
  2705. }
  2706. }
  2707. CustomCommandsView->Hint = Hint;
  2708. FCustomCommandsHintItem = Index;
  2709. }
  2710. }
  2711. //---------------------------------------------------------------------------
  2712. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2713. {
  2714. PageControl->ActivePage = QueueSheet;
  2715. PageControlChange(NULL);
  2716. QueueNoConfirmationCheck->SetFocus();
  2717. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2718. }
  2719. //---------------------------------------------------------------------------
  2720. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2721. {
  2722. ConfigureCommand();
  2723. }
  2724. //---------------------------------------------------------------------------
  2725. void __fastcall TPreferencesDialog::ConfigureCommand()
  2726. {
  2727. int Index = CustomCommandsView->ItemIndex;
  2728. TCustomCommandList * CommandList = GetCommandList(Index);
  2729. int CommandIndex = GetCommandIndex(Index);
  2730. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2731. UnicodeString Site = GetSessionKey();
  2732. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2733. Site.IsEmpty())
  2734. {
  2735. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2736. }
  2737. TShortCut ShortCut = Command->ShortCut;
  2738. TShortCuts ShortCuts = GetShortCuts();
  2739. if (DoCustomCommandOptionsDialog(
  2740. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2741. {
  2742. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2743. UpdatedCommand->ShortCut = ShortCut;
  2744. CommandList->Change(CommandIndex, UpdatedCommand);
  2745. UpdateCustomCommandsView();
  2746. }
  2747. }
  2748. //---------------------------------------------------------------------------
  2749. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2750. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2751. {
  2752. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2753. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2754. {
  2755. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2756. }
  2757. if (LocaleInfo->Completeness < 0)
  2758. {
  2759. Sender->Canvas->Font->Color = clRed;
  2760. }
  2761. else if (LocaleInfo->Completeness < 100)
  2762. {
  2763. Sender->Canvas->Font->Color = clGrayText;
  2764. }
  2765. }
  2766. //---------------------------------------------------------------------------
  2767. void __fastcall TPreferencesDialog::LogMaxSizeComboExit(TObject * /*Sender*/)
  2768. {
  2769. __int64 Size;
  2770. if (!IsCancelButtonBeingClicked(this))
  2771. {
  2772. if (!TryStrToSize(LogMaxSizeCombo->Text, Size))
  2773. {
  2774. LogMaxSizeCombo->SetFocus();
  2775. throw Exception(FMTLOAD(SIZE_INVALID, (LogMaxSizeCombo->Text)));
  2776. }
  2777. else
  2778. {
  2779. LogMaxSizeCombo->Text = SizeToStr(Size);
  2780. }
  2781. }
  2782. }
  2783. //---------------------------------------------------------------------------
  2784. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2785. {
  2786. if (!IsCancelButtonBeingClicked(this))
  2787. {
  2788. try
  2789. {
  2790. UnicodeString Program, AParams, Dir;
  2791. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2792. }
  2793. catch(...)
  2794. {
  2795. PuttyPathEdit->SelectAll();
  2796. PuttyPathEdit->SetFocus();
  2797. throw;
  2798. }
  2799. }
  2800. }
  2801. //---------------------------------------------------------------------------
  2802. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2803. {
  2804. Active = AutomaticIniFileStorageButton->Checked;
  2805. }
  2806. //---------------------------------------------------------------------------
  2807. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2808. {
  2809. UnicodeString Result;
  2810. if (CustomIniFileStorageButton->Checked)
  2811. {
  2812. Result = CustomIniFileStorageEdit->Text;
  2813. }
  2814. return Result;
  2815. }
  2816. //---------------------------------------------------------------------------
  2817. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2818. {
  2819. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2820. UnicodeString CustomIniFileStorageNameExpanded = ExpandEnvironmentVariables(CustomIniFileStorageName);
  2821. if (!CustomIniFileStorageName.IsEmpty() &&
  2822. // Not expanding, as we want to allow change from explicit path to path with variables and vice versa
  2823. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2824. FileExists(CustomIniFileStorageNameExpanded))
  2825. {
  2826. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageNameExpanded));
  2827. TMessageParams Params;
  2828. TQueryButtonAlias Aliases[2];
  2829. Aliases[0].Button = qaYes;
  2830. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2831. Aliases[1].Button = qaNo;
  2832. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2833. Params.Aliases = Aliases;
  2834. Params.AliasesCount = 2;
  2835. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2836. if (Result == qaYes)
  2837. {
  2838. // noop
  2839. }
  2840. else if (Result == qaNo)
  2841. {
  2842. // Similar to TLoginDialog::ImportActionExecute
  2843. Configuration->ScheduleCustomIniFileStorageUse(CustomIniFileStorageName);
  2844. ExecuteSelf(EmptyStr);
  2845. TerminateApplication();
  2846. }
  2847. else
  2848. {
  2849. Abort();
  2850. }
  2851. }
  2852. FCustomIniFileStorageName = CustomIniFileStorageName;
  2853. }
  2854. //---------------------------------------------------------------------------
  2855. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2856. {
  2857. if (!IsCancelButtonBeingClicked(this))
  2858. {
  2859. CustomIniFileStorageChanged();
  2860. }
  2861. else
  2862. {
  2863. // Reset the value to prevent accidental overwrite of an INI file, in case the dialog cancel does not complete
  2864. CustomIniFileStorageEdit->Text = FCustomIniFileStorageName;
  2865. }
  2866. }
  2867. //---------------------------------------------------------------------------
  2868. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2869. {
  2870. PathEditAfterDialog(Sender, Name, Action);
  2871. if (Action)
  2872. {
  2873. CustomIniFileStorageEdit->Text = Name;
  2874. CustomIniFileStorageChanged();
  2875. }
  2876. }
  2877. //---------------------------------------------------------------------------
  2878. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2879. {
  2880. UpdateControls();
  2881. // Handler is called also when Checked is set from LoadConfiguration
  2882. if (FNoUpdate == 0)
  2883. {
  2884. // Focus to force validation
  2885. CustomIniFileStorageEdit->SetFocus();
  2886. }
  2887. }
  2888. //---------------------------------------------------------------------------
  2889. void __fastcall TPreferencesDialog::UpdateFileColorsView()
  2890. {
  2891. FileColorsView->Items->Count = FFileColors.size();
  2892. AutoSizeListColumnsWidth(FileColorsView);
  2893. }
  2894. //---------------------------------------------------------------------------
  2895. void __fastcall TPreferencesDialog::FileColorsViewData(TObject *, TListItem * Item)
  2896. {
  2897. Item->Caption = FFileColors[Item->Index].FileMask.Masks;
  2898. }
  2899. //---------------------------------------------------------------------------
  2900. void __fastcall TPreferencesDialog::FileColorsViewCustomDrawItem(
  2901. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  2902. {
  2903. Sender->Canvas->Font->Color = FFileColors[Item->Index].Color;
  2904. }
  2905. //---------------------------------------------------------------------------
  2906. void __fastcall TPreferencesDialog::AddEditFileColor(bool Edit)
  2907. {
  2908. TFileColorData FileColorData;
  2909. int Index = FileColorsView->ItemIndex;
  2910. if (Edit)
  2911. {
  2912. FileColorData = FFileColors[Index];
  2913. }
  2914. else
  2915. {
  2916. FileColorData.FileMask = AnyMask;
  2917. }
  2918. if (DoFileColorDialog(FileColorData))
  2919. {
  2920. if (Edit)
  2921. {
  2922. FFileColors[Index] = FileColorData;
  2923. }
  2924. else
  2925. {
  2926. if (Index < 0)
  2927. {
  2928. FFileColors.push_back(FileColorData);
  2929. }
  2930. else
  2931. {
  2932. FFileColors.insert(&FFileColors[Index], FileColorData);
  2933. }
  2934. }
  2935. UpdateFileColorsView();
  2936. FileColorsView->ItemIndex = Index;
  2937. UpdateControls();
  2938. }
  2939. }
  2940. //---------------------------------------------------------------------------
  2941. void __fastcall TPreferencesDialog::AddEditFileColorButtonClick(TObject * Sender)
  2942. {
  2943. bool Edit = (Sender == EditFileColorButton);
  2944. AddEditFileColor(Edit);
  2945. }
  2946. //---------------------------------------------------------------------------
  2947. void __fastcall TPreferencesDialog::FileColorMove(int Source, int Dest)
  2948. {
  2949. FFileColors.insert(FFileColors.begin() + Dest + ((Dest > Source) ? 1 : 0), FFileColors[Source]);
  2950. FFileColors.erase(FFileColors.begin() + Source + ((Dest < Source) ? 1 : 0));
  2951. FileColorsView->ItemIndex = Dest;
  2952. UpdateFileColorsView();
  2953. UpdateControls();
  2954. }
  2955. //---------------------------------------------------------------------------
  2956. void __fastcall TPreferencesDialog::FileColorsViewDragDrop(TObject * Sender, TObject * Source, int X, int Y)
  2957. {
  2958. if (Source == FileColorsView)
  2959. {
  2960. if (AllowListViewDrag(Sender, X, Y))
  2961. {
  2962. FileColorMove(FListViewDragSource, FListViewDragDest);
  2963. }
  2964. }
  2965. }
  2966. //---------------------------------------------------------------------------
  2967. void __fastcall TPreferencesDialog::FileColorsViewKeyDown(TObject *, WORD & Key, TShiftState)
  2968. {
  2969. if (RemoveFileColorButton->Enabled && (Key == VK_DELETE))
  2970. {
  2971. RemoveFileColorButtonClick(NULL);
  2972. }
  2973. if (DebugAlwaysTrue(AddFileColorButton->Enabled) && (Key == VK_INSERT))
  2974. {
  2975. AddEditFileColor(false);
  2976. }
  2977. }
  2978. //---------------------------------------------------------------------------
  2979. void __fastcall TPreferencesDialog::RemoveFileColorButtonClick(TObject *)
  2980. {
  2981. FFileColors.erase(FFileColors.begin() + FileColorsView->ItemIndex);
  2982. UpdateFileColorsView();
  2983. UpdateControls();
  2984. }
  2985. //---------------------------------------------------------------------------
  2986. void __fastcall TPreferencesDialog::FileColorsViewDblClick(TObject *)
  2987. {
  2988. if (EditFileColorButton->Enabled)
  2989. {
  2990. AddEditFileColor(true);
  2991. }
  2992. }
  2993. //---------------------------------------------------------------------------
  2994. void __fastcall TPreferencesDialog::UpDownFileColorButtonClick(TObject * Sender)
  2995. {
  2996. int DestIndex = FileColorsView->ItemIndex + (Sender == UpFileColorButton ? -1 : 1);
  2997. FileColorMove(FileColorsView->ItemIndex, DestIndex);
  2998. }
  2999. //---------------------------------------------------------------------------
  3000. void __fastcall TPreferencesDialog::LocalPortNumberMinEditExit(TObject *)
  3001. {
  3002. if (LocalPortNumberMinEdit->AsInteger > LocalPortNumberMaxEdit->AsInteger)
  3003. {
  3004. LocalPortNumberMaxEdit->Value = LocalPortNumberMaxEdit->MaxValue;
  3005. }
  3006. }
  3007. //---------------------------------------------------------------------------
  3008. void __fastcall TPreferencesDialog::LocalPortNumberMaxEditExit(TObject *)
  3009. {
  3010. if (LocalPortNumberMaxEdit->AsInteger < LocalPortNumberMinEdit->AsInteger)
  3011. {
  3012. if (LocalPortNumberMaxEdit->AsInteger >= PrivatePortMin)
  3013. {
  3014. LocalPortNumberMinEdit->AsInteger = PrivatePortMin;
  3015. }
  3016. else
  3017. {
  3018. LocalPortNumberMinEdit->Value = LocalPortNumberMinEdit->MinValue;
  3019. }
  3020. }
  3021. }
  3022. //---------------------------------------------------------------------------
  3023. UnicodeString TPreferencesDialog::Bullet(const UnicodeString & S)
  3024. {
  3025. // Keep in sync with similar function in installer
  3026. UnicodeString Result = S;
  3027. UnicodeString Dash(L"-");
  3028. UnicodeString Bullet(L"\u2022 ");
  3029. if (StartsStr(Dash, Result))
  3030. {
  3031. Result = Bullet + Result.SubString(Dash.Length() + 1, Result.Length() - Dash.Length());
  3032. }
  3033. Result = ReplaceStr(Result, sLineBreak + Dash, sLineBreak + Bullet);
  3034. return Result;
  3035. }
  3036. //---------------------------------------------------------------------------