Preferences.cpp 114 KB

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