Preferences.cpp 133 KB

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