Preferences.cpp 133 KB

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