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(DDFakeFileDisabledPanel, 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. MakeDefaultHandlerItem->Visible = IsWinVista();
  1365. // languages
  1366. LanguageChangeLabel->Visible =
  1367. DebugAlwaysTrue(!GUIConfiguration->CanApplyLocaleImmediately) &&
  1368. (LanguagesView->ItemFocused != NULL) &&
  1369. (static_cast<TLocaleInfo *>(LanguagesView->ItemFocused->Data)->Locale != GUIConfiguration->AppliedLocale);
  1370. // logging
  1371. EnableControl(LogProtocolCombo2, EnableLoggingCheck->Checked);
  1372. EnableControl(LogFileNameEdit3, LogProtocolCombo2->Enabled);
  1373. EnableControl(LogFileNameHintText, LogFileNameEdit3->Enabled);
  1374. EnableControl(LogFileAppendButton, LogFileNameEdit3->Enabled);
  1375. EnableControl(LogFileOverwriteButton, LogFileNameEdit3->Enabled);
  1376. EnableControl(LogMaxSizeCheck, LogFileNameEdit3->Enabled);
  1377. EnableControl(LogMaxSizeCombo, LogMaxSizeCheck->Enabled && LogMaxSizeCheck->Checked);
  1378. EnableControl(LogMaxSizeCountCheck, LogMaxSizeCombo->Enabled);
  1379. EnableControl(LogMaxSizeCountEdit, LogMaxSizeCountCheck->Enabled && LogMaxSizeCountCheck->Checked);
  1380. EnableControl(LogMaxSizeCountFilesLabel, LogMaxSizeCountEdit->Enabled);
  1381. EnableControl(LogSensitiveCheck, LogProtocolCombo2->Enabled);
  1382. EnableControl(ActionsLogFileNameEdit, EnableActionsLoggingCheck->Checked);
  1383. EnableControl(ActionsLogFileNameHintText, ActionsLogFileNameEdit->Enabled);
  1384. LogProtocolHintLabel->Visible = (LogProtocolCombo2->ItemIndex - BelowNormalLogLevels >= 2);
  1385. // interface
  1386. InterfaceChangeLabel->Visible =
  1387. !CustomWinConfiguration->CanApplyInterfaceImmediately &&
  1388. (GetInterface() != CustomWinConfiguration->AppliedInterface);
  1389. // background
  1390. EnableControl(ParallelTransferCheck, QueueParallelCheck->Checked);
  1391. EnableControl(ParallelTransferThresholdCombo, ParallelTransferCheck->Enabled && ParallelTransferCheck->Checked);
  1392. EnableControl(ParallelTransferThresholdUnitLabel, ParallelTransferThresholdCombo->Enabled);
  1393. }
  1394. }
  1395. //---------------------------------------------------------------------------
  1396. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  1397. {
  1398. if (FontDialog(FEditorFont.get()))
  1399. {
  1400. UpdateControls();
  1401. }
  1402. }
  1403. //---------------------------------------------------------------------------
  1404. void __fastcall TPreferencesDialog::EditorFontColorChange(TColor Color)
  1405. {
  1406. FEditorFont->Color = Color;
  1407. UpdateControls();
  1408. }
  1409. //---------------------------------------------------------------------------
  1410. void __fastcall TPreferencesDialog::EditorFontColorButtonClick(TObject * /*Sender*/)
  1411. {
  1412. // WORKAROUND: Compiler keeps crashing randomly (but frequently) with
  1413. // "internal error" when passing menu directly to unique_ptr.
  1414. // Splitting it to two statements seems to help.
  1415. // The same hack exists in TSiteAdvancedDialog::ColorButtonClick, TOpenLocalPathHandler::Open and TSelectMaskDialog::ColorButtonClick
  1416. TPopupMenu * Menu = CreateColorPopupMenu(FEditorFont->Color, EditorFontColorChange);
  1417. // Popup menu has to survive the popup as TBX calls click handler asynchronously (post).
  1418. FColorPopupMenu.reset(Menu);
  1419. MenuPopup(Menu, EditorFontColorButton);
  1420. }
  1421. //---------------------------------------------------------------------------
  1422. void __fastcall TPreferencesDialog::EditorBackgroundColorChange(TColor Color)
  1423. {
  1424. FEditorBackgroundColor = Color;
  1425. UpdateControls();
  1426. }
  1427. //---------------------------------------------------------------------------
  1428. void __fastcall TPreferencesDialog::EditorBackgroundColorButtonClick(TObject * /*Sender*/)
  1429. {
  1430. // See comment in EditorFontColorButtonClick.
  1431. // We are using session color (contrary to editor text color) for background
  1432. // for a consistency with color selection menu on editor toolbar.
  1433. TTBXPopupMenu * PopupMenu = new TTBXPopupMenu(Application);
  1434. FColorPopupMenu.reset(PopupMenu);
  1435. CreateEditorBackgroundColorMenu(PopupMenu->Items, FEditorBackgroundColor, EditorBackgroundColorChange);
  1436. MenuPopup(FColorPopupMenu.get(), EditorBackgroundColorButton);
  1437. }
  1438. //---------------------------------------------------------------------------
  1439. void __fastcall TPreferencesDialog::PanelFontButtonClick(TObject * /*Sender*/)
  1440. {
  1441. if (FontDialog(FPanelFont.get()))
  1442. {
  1443. PanelFontCheck->Checked = true;
  1444. UpdateControls();
  1445. }
  1446. }
  1447. //---------------------------------------------------------------------------
  1448. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  1449. bool & /*CanClose*/)
  1450. {
  1451. if (ModalResult == DefaultResult(this))
  1452. {
  1453. ExitActiveControl(this);
  1454. }
  1455. }
  1456. //---------------------------------------------------------------------------
  1457. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  1458. {
  1459. UnicodeString IconName, Params;
  1460. int SpecialFolder;
  1461. if (Sender == DesktopIconButton)
  1462. {
  1463. IconName = AppName;
  1464. int Result =
  1465. MessageDialog(LoadStr(CREATE_DESKTOP_ICON2), qtConfirmation,
  1466. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  1467. switch (Result)
  1468. {
  1469. case qaYes:
  1470. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  1471. break;
  1472. case qaNo:
  1473. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  1474. break;
  1475. default:
  1476. Abort();
  1477. break;
  1478. }
  1479. }
  1480. else if (Sender == SendToHookButton)
  1481. {
  1482. if (MessageDialog(MainInstructions(LoadStr(CONFIRM_CREATE_ICON)),
  1483. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  1484. {
  1485. IconName = FMTLOAD(SENDTO_HOOK_NAME2, (AppName));
  1486. SpecialFolder = CSIDL_SENDTO;
  1487. Params = TProgramParams::FormatSwitch(UPLOAD_SWITCH);
  1488. }
  1489. else
  1490. {
  1491. Abort();
  1492. }
  1493. }
  1494. else
  1495. {
  1496. DebugFail();
  1497. Abort();
  1498. }
  1499. TInstantOperationVisualizer Visualizer;
  1500. CreateAppDesktopShortCut(IconName, Params, L"", SpecialFolder);
  1501. }
  1502. //---------------------------------------------------------------------------
  1503. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  1504. TListItem * Item)
  1505. {
  1506. // WORKAROUND We get here on Wine after destructor is called
  1507. if ((FCustomCommandList != NULL) && (FExtensionList != NULL))
  1508. {
  1509. int Index = Item->Index;
  1510. const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
  1511. UnicodeString Caption = StripHotkey(Command->Name);
  1512. Item->Caption = Caption;
  1513. DebugAssert(!Item->SubItems->Count);
  1514. Item->SubItems->Add(Command->Command);
  1515. Item->SubItems->Add(LoadStr(
  1516. FLAGSET(Command->Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  1517. }
  1518. }
  1519. //---------------------------------------------------------------------------
  1520. void __fastcall TPreferencesDialog::ListViewSelectItem(
  1521. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  1522. {
  1523. UpdateControls();
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  1527. {
  1528. CustomCommandsView->Items->Count = FCustomCommandList->Count + FExtensionList->Count;
  1529. AutoSizeListColumnsWidth(CustomCommandsView, 1);
  1530. CustomCommandsView->Invalidate();
  1531. // particularly after command is edited/configured, make sure the hint is updated,
  1532. // even if we manage to display a hint for the same command as before the change
  1533. FCustomCommandsHintItem = NULL;
  1534. }
  1535. //---------------------------------------------------------------------------
  1536. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  1537. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1538. {
  1539. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  1540. {
  1541. RemoveCommandButtonClick(NULL);
  1542. }
  1543. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  1544. {
  1545. AddEditCommand(false);
  1546. }
  1547. }
  1548. //---------------------------------------------------------------------------
  1549. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  1550. TObject * /*Sender*/)
  1551. {
  1552. if (EditCommandButton->Enabled)
  1553. {
  1554. AddEditCommand(true);
  1555. }
  1556. else if (ConfigureCommandButton->Enabled)
  1557. {
  1558. ConfigureCommand();
  1559. }
  1560. }
  1561. //---------------------------------------------------------------------------
  1562. static int __fastcall AddCommandToList(TCustomCommandList * List, int Index, TCustomCommandType * Command)
  1563. {
  1564. if (Index >= 0)
  1565. {
  1566. List->Insert(Index, Command);
  1567. }
  1568. else
  1569. {
  1570. List->Add(Command);
  1571. Index = List->Count - 1;
  1572. }
  1573. return Index;
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. TShortCuts __fastcall TPreferencesDialog::GetShortCuts()
  1577. {
  1578. TShortCuts ShortCuts;
  1579. if (WinConfiguration->SharedBookmarks != NULL)
  1580. {
  1581. WinConfiguration->SharedBookmarks->ShortCuts(ShortCuts);
  1582. }
  1583. FCustomCommandList->ShortCuts(ShortCuts);
  1584. FExtensionList->ShortCuts(ShortCuts);
  1585. return ShortCuts;
  1586. }
  1587. //---------------------------------------------------------------------------
  1588. void __fastcall TPreferencesDialog::AddEditCommand(bool Edit)
  1589. {
  1590. TCustomCommandType Command;
  1591. if (Edit)
  1592. {
  1593. int Index = CustomCommandsView->ItemIndex;
  1594. DebugAssert(GetCommandList(Index) == FCustomCommandList);
  1595. Command = *FCustomCommandList->Commands[GetCommandIndex(Index)];
  1596. }
  1597. TShortCuts ShortCuts = GetShortCuts();
  1598. if (DoCustomCommandDialog(Command, FCustomCommandList,
  1599. (Edit ? ccmEdit : ccmAdd), 0, NULL, &ShortCuts))
  1600. {
  1601. int Index = GetListCommandIndex(FCustomCommandList);
  1602. TCustomCommandType * ACommand = new TCustomCommandType(Command);
  1603. if (Edit)
  1604. {
  1605. DebugAssert(Index < FCustomCommandList->Count);
  1606. FCustomCommandList->Change(Index, ACommand);
  1607. }
  1608. else
  1609. {
  1610. Index = AddCommandToList(FCustomCommandList, Index, ACommand);
  1611. }
  1612. UpdateCustomCommandsView();
  1613. CustomCommandsView->ItemIndex = GetCommandListIndex(FCustomCommandList, Index);
  1614. CustomCommandsView->ItemFocused->MakeVisible(false);
  1615. UpdateControls();
  1616. }
  1617. }
  1618. //---------------------------------------------------------------------------
  1619. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  1620. TObject * /*Sender*/)
  1621. {
  1622. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1623. int Index = GetCommandIndex(CustomCommandsView->ItemIndex);
  1624. if (List == FExtensionList)
  1625. {
  1626. const TCustomCommandType * CustomComand = List->Commands[Index];
  1627. // If the extension was added in this "preferences session", remove the file
  1628. int PathIndex = FAddedExtensions->IndexOf(CustomComand->FileName);
  1629. if (PathIndex >= 0)
  1630. {
  1631. FAddedExtensions->Delete(PathIndex);
  1632. DeleteFile(ApiPath(CustomComand->FileName));
  1633. }
  1634. }
  1635. List->Delete(Index);
  1636. UpdateCustomCommandsView();
  1637. UpdateControls();
  1638. }
  1639. //---------------------------------------------------------------------------
  1640. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  1641. {
  1642. TCustomCommandList * List = GetCommandList(CustomCommandsView->ItemIndex);
  1643. int SourceIndex = GetCommandIndex(Source);
  1644. int DestIndex = GetCommandIndex(Dest);
  1645. List->Move(SourceIndex, DestIndex);
  1646. CustomCommandsView->ItemIndex = Dest;
  1647. UpdateCustomCommandsView();
  1648. UpdateControls();
  1649. }
  1650. //---------------------------------------------------------------------------
  1651. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1652. {
  1653. CustomCommandMove(CustomCommandsView->ItemIndex,
  1654. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1655. }
  1656. //---------------------------------------------------------------------------
  1657. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1658. {
  1659. if (ListView == CopyParamListView)
  1660. {
  1661. return FCopyParamScrollOnDragOver;
  1662. }
  1663. else if (ListView == CustomCommandsView)
  1664. {
  1665. return FCustomCommandsScrollOnDragOver;
  1666. }
  1667. else if (ListView == EditorListView3)
  1668. {
  1669. return FEditorScrollOnDragOver;
  1670. }
  1671. else if (ListView == FileColorsView)
  1672. {
  1673. return FFileColorScrollOnDragOver;
  1674. }
  1675. else
  1676. {
  1677. DebugFail();
  1678. return NULL;
  1679. }
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1683. TObject * Sender, TDragObject *& /*DragObject*/)
  1684. {
  1685. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1686. FListViewDragDest = -1;
  1687. ScrollOnDragOver(Sender)->StartDrag();
  1688. }
  1689. //---------------------------------------------------------------------------
  1690. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1691. {
  1692. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1693. return Item ? Item->Index : -1;
  1694. }
  1695. //---------------------------------------------------------------------------
  1696. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1697. {
  1698. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1699. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1703. TObject * Sender, TObject * Source, int X, int Y)
  1704. {
  1705. if (Source == CustomCommandsView)
  1706. {
  1707. if (AllowListViewDrag(Sender, X, Y) &&
  1708. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1709. {
  1710. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1711. }
  1712. }
  1713. }
  1714. //---------------------------------------------------------------------------
  1715. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1716. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1717. {
  1718. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1719. if (Source == Sender)
  1720. {
  1721. int Dest = PointToListViewIndex(Sender, X, Y);
  1722. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1723. {
  1724. Accept = false;
  1725. }
  1726. }
  1727. }
  1728. //---------------------------------------------------------------------------
  1729. void __fastcall TPreferencesDialog::ListViewDragOver(
  1730. TObject * Sender, TObject * Source, int X, int Y,
  1731. TDragState /*State*/, bool & Accept)
  1732. {
  1733. if (Source == Sender)
  1734. {
  1735. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1736. // (when dropped on item itself, when it was dragged over another item before,
  1737. // that another item remains highlighted forever)
  1738. Accept = true;
  1739. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1740. }
  1741. }
  1742. //---------------------------------------------------------------------------
  1743. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1744. {
  1745. if (Index == 0)
  1746. {
  1747. return &FCopyParams;
  1748. }
  1749. else
  1750. {
  1751. return FCopyParamList->CopyParams[Index - 1];
  1752. }
  1753. }
  1754. //---------------------------------------------------------------------------
  1755. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1756. {
  1757. DebugAssert((Source > 0) && (Dest > 0));
  1758. FCopyParamList->Move(Source - 1, Dest - 1);
  1759. CopyParamListView->ItemIndex = Dest;
  1760. UpdateCopyParamListView();
  1761. UpdateControls();
  1762. }
  1763. //---------------------------------------------------------------------------
  1764. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1765. TObject * Sender, TObject * Source, int X, int Y)
  1766. {
  1767. if (Source == CopyParamListView)
  1768. {
  1769. if ((FListViewDragSource > 0) &&
  1770. AllowListViewDrag(Sender, X, Y) &&
  1771. (FListViewDragDest > 0))
  1772. {
  1773. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1774. }
  1775. }
  1776. }
  1777. //---------------------------------------------------------------------------
  1778. void __fastcall TPreferencesDialog::CopyParamListViewDragOver(
  1779. TObject * Sender, TObject * Source, int X, int Y, TDragState State, bool & Accept)
  1780. {
  1781. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1782. if (Source == Sender)
  1783. {
  1784. int Dest = PointToListViewIndex(Sender, X, Y);
  1785. if ((FListViewDragSource == 0) || (Dest == 0))
  1786. {
  1787. Accept = false;
  1788. }
  1789. }
  1790. }
  1791. //---------------------------------------------------------------------------
  1792. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1793. {
  1794. CopyParamMove(CopyParamListView->ItemIndex,
  1795. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1796. }
  1797. //---------------------------------------------------------------------------
  1798. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1799. TObject * /*Sender*/)
  1800. {
  1801. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1802. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1803. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1804. UpdateCopyParamListView();
  1805. UpdateControls();
  1806. }
  1807. //---------------------------------------------------------------------------
  1808. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1809. {
  1810. int Index = CopyParamListView->ItemIndex;
  1811. bool Result;
  1812. if ((Index == 0) && (Mode == cpmEdit))
  1813. {
  1814. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1815. }
  1816. else
  1817. {
  1818. TCopyParamRuleData * CopyParamRuleData =
  1819. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1820. // negative (when default is selected) means add to the end
  1821. Index--;
  1822. TCopyParamType DefaultCopyParams;
  1823. // For cpmAdd use defaults.
  1824. if (Mode == cpmDuplicate)
  1825. {
  1826. // Only used, when duplicating default settings (Index < 0)
  1827. DefaultCopyParams = FCopyParams;
  1828. }
  1829. else if (Mode == cpmEdit)
  1830. {
  1831. // For cpmEdit, DefaultCopyParams is never used.
  1832. DebugAssert(Index >= 0);
  1833. }
  1834. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1835. if (Result)
  1836. {
  1837. UpdateCopyParamListView();
  1838. CopyParamListView->ItemIndex = Index + 1;
  1839. // when using duplicate button, focus remains on original item
  1840. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1841. }
  1842. }
  1843. if (Result)
  1844. {
  1845. UpdateControls();
  1846. }
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1850. {
  1851. AddEditCopyParam(cpmAdd);
  1852. }
  1853. //---------------------------------------------------------------------------
  1854. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1855. {
  1856. AddEditCopyParam(cpmEdit);
  1857. }
  1858. //---------------------------------------------------------------------------
  1859. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1860. {
  1861. AddEditCopyParam(cpmDuplicate);
  1862. }
  1863. //---------------------------------------------------------------------------
  1864. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1865. TObject * /*Sender*/)
  1866. {
  1867. if (EditCopyParamButton->Enabled)
  1868. {
  1869. AddEditCopyParam(cpmEdit);
  1870. }
  1871. }
  1872. //---------------------------------------------------------------------------
  1873. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1874. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1875. {
  1876. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1877. {
  1878. RemoveCopyParamButtonClick(NULL);
  1879. }
  1880. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1881. {
  1882. AddEditCopyParam(cpmAdd);
  1883. }
  1884. }
  1885. //---------------------------------------------------------------------------
  1886. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1887. {
  1888. FEditorList->Move(Source, Dest);
  1889. EditorListView3->ItemIndex = Dest;
  1890. UpdateEditorListView();
  1891. UpdateControls();
  1892. }
  1893. //---------------------------------------------------------------------------
  1894. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1895. TObject * Source, int X, int Y)
  1896. {
  1897. if (Source == EditorListView3)
  1898. {
  1899. if (AllowListViewDrag(Sender, X, Y))
  1900. {
  1901. EditorMove(FListViewDragSource, FListViewDragDest);
  1902. }
  1903. }
  1904. }
  1905. //---------------------------------------------------------------------------
  1906. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1907. {
  1908. EditorMove(EditorListView3->ItemIndex,
  1909. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1910. }
  1911. //---------------------------------------------------------------------------
  1912. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1913. TObject * /*Sender*/)
  1914. {
  1915. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1916. EditorListView3->ItemIndex < FEditorList->Count);
  1917. FEditorList->Delete(EditorListView3->ItemIndex);
  1918. UpdateEditorListView();
  1919. UpdateControls();
  1920. }
  1921. //---------------------------------------------------------------------------
  1922. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1923. {
  1924. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1925. int Index = EditorListView3->ItemIndex;
  1926. TEditorPreferences * Editor;
  1927. if (Mode == epmEdit)
  1928. {
  1929. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1930. }
  1931. else
  1932. {
  1933. Editor = new TEditorPreferences();
  1934. }
  1935. try
  1936. {
  1937. bool DummyRemember = false;
  1938. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1939. {
  1940. if (Mode == epmEdit)
  1941. {
  1942. FEditorList->Change(Index, Editor);
  1943. }
  1944. else
  1945. {
  1946. if (Index < 0)
  1947. {
  1948. Index = FEditorList->Count;
  1949. FEditorList->Add(Editor);
  1950. }
  1951. else
  1952. {
  1953. FEditorList->Insert(Index, Editor);
  1954. }
  1955. }
  1956. // ownership of the object lost
  1957. Editor = NULL;
  1958. UpdateEditorListView();
  1959. EditorListView3->ItemIndex = Index;
  1960. UpdateControls();
  1961. }
  1962. }
  1963. __finally
  1964. {
  1965. delete Editor;
  1966. }
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1970. {
  1971. if (EditEditorButton->Enabled)
  1972. {
  1973. AddEditEditorButtonClick(EditEditorButton);
  1974. }
  1975. }
  1976. //---------------------------------------------------------------------------
  1977. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1978. WORD & Key, TShiftState /*Shift*/)
  1979. {
  1980. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1981. {
  1982. RemoveEditorButtonClick(NULL);
  1983. }
  1984. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1985. {
  1986. AddEditEditorButtonClick(AddEditorButton);
  1987. }
  1988. }
  1989. //---------------------------------------------------------------------------
  1990. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1991. {
  1992. EditorListView3->Items->Count = FEditorList->Count;
  1993. AutoSizeListColumnsWidth(EditorListView3);
  1994. EditorListView3->Invalidate();
  1995. }
  1996. //---------------------------------------------------------------------------
  1997. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1998. TListItem * Item)
  1999. {
  2000. // WORKAROUND We get here on Wine after destructor is called
  2001. if (FEditorList != NULL)
  2002. {
  2003. int Index = Item->Index;
  2004. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  2005. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  2006. Item->Caption = Editor->Name;
  2007. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  2008. if (Editor->Data->Editor == edExternal)
  2009. {
  2010. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  2011. }
  2012. }
  2013. }
  2014. //---------------------------------------------------------------------------
  2015. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  2016. TTreeNode * Node)
  2017. {
  2018. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  2019. {
  2020. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  2021. // reshow the accelerators, etc
  2022. ResetSystemSettings(this);
  2023. // This is particularly here to enable EditCopyParamButton,
  2024. // as for some reason CopyParamListView->Selected is NULL until
  2025. // its page is shown for the first time
  2026. UpdateControls();
  2027. }
  2028. }
  2029. //---------------------------------------------------------------------------
  2030. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  2031. {
  2032. // this is probably only ever called from FormShow (explicitly)
  2033. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  2034. {
  2035. TTreeNode * Node = FindTreeNodeForPage(PageControl->ActivePage);
  2036. if (Node != NULL)
  2037. {
  2038. Node->Selected = true;
  2039. UpdateControls();
  2040. }
  2041. }
  2042. }
  2043. //---------------------------------------------------------------------------
  2044. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  2045. {
  2046. if ((Message.CharCode == VK_TAB) ||
  2047. ((Message.CharCode >= VK_LEFT) && (Message.CharCode >= VK_DOWN)))
  2048. {
  2049. FHideFocus = false;
  2050. }
  2051. if (Message.CharCode == VK_TAB)
  2052. {
  2053. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  2054. if (Shift.Contains(ssCtrl))
  2055. {
  2056. TTreeNode * Node = NavigationTree->Selected;
  2057. if (!Shift.Contains(ssShift))
  2058. {
  2059. Node = Node->GetNext();
  2060. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  2061. }
  2062. else
  2063. {
  2064. if (Node->GetPrev()) Node = Node->GetPrev();
  2065. else
  2066. while (Node->GetNext()) Node = Node->GetNext();
  2067. }
  2068. Node->Selected = True;
  2069. Message.Result = 1;
  2070. return;
  2071. }
  2072. }
  2073. else if ((Message.CharCode == VK_ESCAPE) && (FSearchResults.get() != NULL))
  2074. {
  2075. SearchEdit->Clear();
  2076. NavigationTree->SetFocus();
  2077. Message.Result = 1;
  2078. return;
  2079. }
  2080. TForm::Dispatch(&Message);
  2081. }
  2082. //---------------------------------------------------------------------------
  2083. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  2084. {
  2085. DebugAssert(Message.HelpInfo != NULL);
  2086. TControl * Control = FindControl(static_cast<HWND>(Message.HelpInfo->hItemHandle));
  2087. // Invoke help for the active page (not for whole form), regardless of a focus
  2088. // (e.g. even if the focus is on a control outside pagecontrol).
  2089. // Except when the control has its own help (SearchEdit).
  2090. if (((Control == NULL) || Control->HelpKeyword.IsEmpty()) &&
  2091. (Message.HelpInfo->iContextType == HELPINFO_WINDOW))
  2092. {
  2093. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  2094. }
  2095. TForm::Dispatch(&Message);
  2096. }
  2097. //---------------------------------------------------------------------------
  2098. void __fastcall TPreferencesDialog::FormAfterMonitorDpiChanged(TObject *, int OldDPI, int NewDPI)
  2099. {
  2100. DebugUsedParam2(OldDPI, NewDPI);
  2101. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  2102. // we may end up using a slightly different size, so apply it straight away for consistency
  2103. UpdateControls();
  2104. }
  2105. //---------------------------------------------------------------------------
  2106. void TPreferencesDialog::WMActivate(TWMActivate & Message)
  2107. {
  2108. if ((Message.Active != WA_INACTIVE) && (PageControl->ActivePage == SecuritySheet))
  2109. {
  2110. SshHostCAsRefresh();
  2111. }
  2112. TForm::Dispatch(&Message);
  2113. }
  2114. //---------------------------------------------------------------------------
  2115. void TPreferencesDialog::CMFocusChanged(TMessage & Message)
  2116. {
  2117. if (FHideFocus)
  2118. {
  2119. FHideFocus = false;
  2120. HideFocus(UIS_SET);
  2121. }
  2122. UpdateControls();
  2123. TForm::Dispatch(&Message);
  2124. }
  2125. //---------------------------------------------------------------------------
  2126. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  2127. {
  2128. TMessage * M = reinterpret_cast<TMessage*>(Message);
  2129. DebugAssert(M);
  2130. if (M->Msg == CM_DIALOGKEY)
  2131. {
  2132. CMDialogKey(*((TWMKeyDown *)Message));
  2133. }
  2134. else if (M->Msg == WM_HELP)
  2135. {
  2136. WMHelp(*((TWMHelp *)Message));
  2137. }
  2138. else if (M->Msg == WM_ACTIVATE)
  2139. {
  2140. WMActivate(*((TWMActivate *)Message));
  2141. }
  2142. else if (M->Msg == CM_FOCUSCHANGED)
  2143. {
  2144. CMFocusChanged(*M);
  2145. }
  2146. else
  2147. {
  2148. TForm::Dispatch(Message);
  2149. }
  2150. }
  2151. //---------------------------------------------------------------------------
  2152. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  2153. TObject * /*Sender*/)
  2154. {
  2155. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  2156. }
  2157. //---------------------------------------------------------------------------
  2158. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  2159. {
  2160. unsigned int Result =
  2161. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  2162. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2163. if (Result == qaYes)
  2164. {
  2165. TInstantOperationVisualizer Visualizer;
  2166. RegisterForDefaultProtocols();
  2167. }
  2168. }
  2169. //---------------------------------------------------------------------------
  2170. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  2171. {
  2172. unsigned int Result =
  2173. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  2174. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  2175. if (Result == qaYes)
  2176. {
  2177. TInstantOperationVisualizer Visualizer;
  2178. UnregisterForProtocols();
  2179. }
  2180. }
  2181. //---------------------------------------------------------------------------
  2182. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  2183. {
  2184. TOperationVisualizer Visualizer;
  2185. LaunchAdvancedAssociationUI();
  2186. }
  2187. //---------------------------------------------------------------------------
  2188. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  2189. {
  2190. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  2191. }
  2192. //---------------------------------------------------------------------------
  2193. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  2194. TObject * /*Sender*/)
  2195. {
  2196. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  2197. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  2198. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  2199. {
  2200. TInstantOperationVisualizer Visualizer;
  2201. AddSearchPath(AppPath);
  2202. }
  2203. }
  2204. //---------------------------------------------------------------------------
  2205. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2206. TObject * Sender)
  2207. {
  2208. EditorFontButtonClick(Sender);
  2209. }
  2210. //---------------------------------------------------------------------------
  2211. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2212. {
  2213. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2214. AutoSizeListColumnsWidth(CopyParamListView);
  2215. CopyParamListView->Invalidate();
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2219. TListItem * Item)
  2220. {
  2221. // WORKAROUND We get here on Wine after destructor is called
  2222. if (FCopyParamList != NULL)
  2223. {
  2224. UnicodeString Name;
  2225. UnicodeString Rule;
  2226. int Index = Item->Index;
  2227. if (Index == 0)
  2228. {
  2229. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2230. }
  2231. else
  2232. {
  2233. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2234. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2235. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2236. }
  2237. Item->Caption = Name;
  2238. Item->SubItems->Add(Rule);
  2239. }
  2240. }
  2241. //---------------------------------------------------------------------------
  2242. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2243. {
  2244. FormHelp(this);
  2245. }
  2246. //---------------------------------------------------------------------------
  2247. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2248. TObject * /*Sender*/)
  2249. {
  2250. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2251. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2252. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2253. }
  2254. //---------------------------------------------------------------------------
  2255. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2256. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2257. {
  2258. FBeforeDialogPath = Name;
  2259. Name = ExpandEnvironmentVariables(Name);
  2260. }
  2261. //---------------------------------------------------------------------------
  2262. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2263. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2264. {
  2265. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2266. {
  2267. Name = FBeforeDialogPath;
  2268. }
  2269. }
  2270. //---------------------------------------------------------------------------
  2271. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2272. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2273. {
  2274. AllowCollapse = false;
  2275. }
  2276. //---------------------------------------------------------------------------
  2277. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2278. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2279. {
  2280. ScrollOnDragOver(Sender)->EndDrag();
  2281. }
  2282. //---------------------------------------------------------------------------
  2283. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2284. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2285. {
  2286. if (Value == 0)
  2287. {
  2288. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2289. Handled = true;
  2290. }
  2291. }
  2292. //---------------------------------------------------------------------------
  2293. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2294. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2295. {
  2296. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2297. {
  2298. Value = 0;
  2299. Handled = true;
  2300. }
  2301. }
  2302. //---------------------------------------------------------------------------
  2303. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2304. {
  2305. bool Result;
  2306. bool Retry;
  2307. do
  2308. {
  2309. Retry = false;
  2310. Result = !AnyOtherInstanceOfSelf();
  2311. if (!Result)
  2312. {
  2313. unsigned int Answer =
  2314. MessageDialog(
  2315. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2316. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2317. HELP_MASTER_PASSWORD);
  2318. switch (Answer)
  2319. {
  2320. case qaRetry:
  2321. Retry = true;
  2322. break;
  2323. case qaIgnore:
  2324. Result = true;
  2325. break;
  2326. case qaCancel:
  2327. default:
  2328. // noop
  2329. break;
  2330. }
  2331. }
  2332. }
  2333. while (Retry && !Result);
  2334. return Result;
  2335. }
  2336. //---------------------------------------------------------------------------
  2337. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2338. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2339. {
  2340. // Save master password.
  2341. // This is unlikely to fail, as storage is written explicitly already
  2342. // when writing the recrypted passwords
  2343. Configuration->SaveExplicit();
  2344. TQueryType QueryType = qtInformation;
  2345. if (RecryptPasswordErrors->Count > 0)
  2346. {
  2347. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2348. QueryType = qtWarning;
  2349. }
  2350. MoreMessageDialog(
  2351. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2352. }
  2353. //---------------------------------------------------------------------------
  2354. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2355. {
  2356. UnicodeString NewPassword;
  2357. if (DoChangeMasterPasswordDialog(NewPassword))
  2358. {
  2359. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2360. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2361. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2362. }
  2363. }
  2364. //---------------------------------------------------------------------------
  2365. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2366. TObject * /*Sender*/)
  2367. {
  2368. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2369. {
  2370. try
  2371. {
  2372. if (CanSetMasterPassword())
  2373. {
  2374. if (UseMasterPasswordCheck->Checked)
  2375. {
  2376. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2377. }
  2378. else
  2379. {
  2380. if (DoMasterPasswordDialog())
  2381. {
  2382. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2383. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2384. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2385. }
  2386. }
  2387. }
  2388. }
  2389. __finally
  2390. {
  2391. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2392. UpdateControls();
  2393. }
  2394. }
  2395. }
  2396. //---------------------------------------------------------------------------
  2397. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2398. TObject * /*Sender*/)
  2399. {
  2400. if (CanSetMasterPassword())
  2401. {
  2402. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2403. }
  2404. }
  2405. //---------------------------------------------------------------------------
  2406. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2407. {
  2408. DoUsageStatisticsDialog();
  2409. }
  2410. //---------------------------------------------------------------------------
  2411. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2412. {
  2413. if (EditCopyParamButton->Enabled)
  2414. {
  2415. AddEditCopyParam(cpmEdit);
  2416. }
  2417. }
  2418. //---------------------------------------------------------------------------
  2419. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2420. TCustomListView * Sender, TListItem * Item,
  2421. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2422. {
  2423. if (Item->Index == 0)
  2424. {
  2425. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2426. }
  2427. }
  2428. //---------------------------------------------------------------------------
  2429. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2430. {
  2431. PuttyRegistryStorageKeyEdit->ItemIndex =
  2432. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2433. }
  2434. //---------------------------------------------------------------------------
  2435. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2436. {
  2437. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2438. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2439. {
  2440. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2441. }
  2442. else if (ContainsText(PuttyPath, KittyExecutable))
  2443. {
  2444. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2445. }
  2446. UpdateControls();
  2447. }
  2448. //---------------------------------------------------------------------------
  2449. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2450. TTreeNode * Node, bool & /*AllowChange*/)
  2451. {
  2452. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2453. // delay load as this can be time consuming
  2454. if (Sheet == LanguagesSheet)
  2455. {
  2456. LoadLanguages();
  2457. }
  2458. else if (Sheet == SecuritySheet)
  2459. {
  2460. SshHostCAsRefresh();
  2461. }
  2462. }
  2463. //---------------------------------------------------------------------------
  2464. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2465. {
  2466. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2467. }
  2468. //---------------------------------------------------------------------------
  2469. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2470. {
  2471. CommanderInterfaceButton2->SetFocus();
  2472. }
  2473. //---------------------------------------------------------------------------
  2474. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2475. {
  2476. ExplorerInterfaceButton2->SetFocus();
  2477. }
  2478. //---------------------------------------------------------------------------
  2479. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2480. {
  2481. PanelFontButtonClick(Sender);
  2482. }
  2483. //---------------------------------------------------------------------------
  2484. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2485. {
  2486. if (!IsCancelButtonBeingClicked(this))
  2487. {
  2488. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2489. {
  2490. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2491. {
  2492. TUpdatesConfiguration Updates = SaveUpdates();
  2493. {
  2494. TInstantOperationVisualizer Visualizer;
  2495. QueryUpdates(Updates);
  2496. }
  2497. if (!Updates.Results.AuthenticationError.IsEmpty())
  2498. {
  2499. UnicodeString AuthenticationError;
  2500. FormatUpdatesMessage(AuthenticationError, Updates.Results.AuthenticationError, Updates);
  2501. if (HasParagraphs(AuthenticationError))
  2502. {
  2503. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2504. }
  2505. else
  2506. {
  2507. AuthenticationError = MainInstructions(AuthenticationError);
  2508. }
  2509. unsigned int Result =
  2510. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HELP_AUTOMATIC_UPDATE);
  2511. if (Result == qaAbort)
  2512. {
  2513. Abort();
  2514. }
  2515. }
  2516. }
  2517. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2518. }
  2519. }
  2520. }
  2521. //---------------------------------------------------------------------------
  2522. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2523. {
  2524. EnableAutomaticUpdates();
  2525. }
  2526. //---------------------------------------------------------------------------
  2527. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2528. {
  2529. FOrigCustomCommandsViewWindowProc(Message);
  2530. if (Message.Msg == CN_NOTIFY)
  2531. {
  2532. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2533. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2534. {
  2535. // request CDDS_ITEMPOSTPAINT notification
  2536. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2537. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2538. int Index = CustomDraw->nmcd.dwItemSpec;
  2539. int CommandIndex = GetCommandIndex(Index);
  2540. TCustomCommandList * List = GetCommandList(Index);
  2541. // after end of every list, except for the last last list
  2542. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2543. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2544. {
  2545. TRect Rect;
  2546. Rect.Top = CustomDraw->iSubItem;
  2547. Rect.Left = LVIR_BOUNDS;
  2548. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2549. HDC DC = CustomDraw->nmcd.hdc;
  2550. SelectObject(DC, GetStockObject(DC_PEN));
  2551. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2552. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2553. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2554. }
  2555. }
  2556. }
  2557. }
  2558. //---------------------------------------------------------------------------
  2559. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2560. {
  2561. if ((Status / 10) == 49)
  2562. {
  2563. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2564. throw Exception(Message);
  2565. }
  2566. }
  2567. //---------------------------------------------------------------------------
  2568. void __fastcall TPreferencesDialog::AddExtension()
  2569. {
  2570. const UnicodeString HistoryKey(L"ExtensionPath");
  2571. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2572. UnicodeString Path;
  2573. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2574. HELP_ADD_EXTENSION, History.get(), true, NULL, true, 400) &&
  2575. !Path.IsEmpty())
  2576. {
  2577. CustomWinConfiguration->History[HistoryKey] = History.get();
  2578. bool Trusted;
  2579. bool Latest;
  2580. UnicodeString FileName;
  2581. UnicodeString ExtensionPath;
  2582. UnicodeString LinesSourcePath;
  2583. std::unique_ptr<TStringList> Lines(new TStringList());
  2584. std::unique_ptr<TCustomCommandType> CustomCommand;
  2585. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2586. try
  2587. {
  2588. UnicodeString ProvisionaryId;
  2589. if (IsUrl)
  2590. {
  2591. UnicodeString Url = Path;
  2592. Url = SecureUrl(Url);
  2593. bool WinSCPURL = IsWinSCPUrl(Url);
  2594. if (WinSCPURL)
  2595. {
  2596. Url = ProgramUrl(Url);
  2597. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2598. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2599. Url = AppendUrlParams(Url, FORMAT(L"netcore=%s", (EncodeUrlString(GetNetCoreVersionStr()))));
  2600. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2601. Url = AppendUrlParams(Url, FORMAT(L"pwsh=%s", (EncodeUrlString(GetPowerShellCoreVersionStr()))));
  2602. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2603. Url = CampaignUrl(Url);
  2604. }
  2605. TOperationVisualizer Visualizer;
  2606. std::unique_ptr<THttp> Http(CreateHttp());
  2607. Http->URL = Url;
  2608. std::unique_ptr<TStrings> Headers(new TStringList());
  2609. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2610. Http->RequestHeaders = Headers.get();
  2611. Http->OnError = ExtensionHttpError;
  2612. Http->Get();
  2613. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2614. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2615. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2616. if (FileName.IsEmpty())
  2617. {
  2618. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2619. }
  2620. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2621. Lines->Text = Http->Response;
  2622. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2623. }
  2624. else
  2625. {
  2626. if (!FileExists(ApiPath(Path)))
  2627. {
  2628. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2629. }
  2630. Trusted = true;
  2631. Latest = true;
  2632. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2633. FileName = ExtractFileName(Path);
  2634. if (!Id.IsEmpty())
  2635. {
  2636. ExtensionPath = Path;
  2637. ProvisionaryId = Id;
  2638. }
  2639. else
  2640. {
  2641. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2642. }
  2643. LinesSourcePath = Path;
  2644. LoadScriptFromFile(Path, Lines.get());
  2645. }
  2646. // validate syntax
  2647. CustomCommand.reset(new TCustomCommandType());
  2648. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2649. CustomCommand->Id = ProvisionaryId;
  2650. CustomCommand->LoadExtension(Lines.get(), FileName);
  2651. }
  2652. catch (Exception & E)
  2653. {
  2654. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2655. }
  2656. if (!ExtensionPath.IsEmpty())
  2657. {
  2658. int Index = FExtensionList->FindIndexByFileName(Path);
  2659. if (Index >= 0)
  2660. {
  2661. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2662. CustomCommandsView->ItemFocused->MakeVisible(false);
  2663. CustomCommandsView->SetFocus();
  2664. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2665. }
  2666. }
  2667. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2668. {
  2669. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2670. }
  2671. if (ExtensionPath.IsEmpty())
  2672. {
  2673. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2674. {
  2675. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2676. if (FileNameOnly.IsEmpty())
  2677. {
  2678. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2679. }
  2680. else
  2681. {
  2682. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2683. }
  2684. }
  2685. }
  2686. if (Trusted ||
  2687. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2688. {
  2689. if (ExtensionPath.IsEmpty())
  2690. {
  2691. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2692. if (!DirectoryExists(UserExtensionsPath) &&
  2693. !ForceDirectories(UserExtensionsPath))
  2694. {
  2695. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2696. }
  2697. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2698. int Counter = 1;
  2699. UnicodeString OriginalExtensionPath = ExtensionPath;
  2700. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2701. while (FileExists(ApiPath(ExtensionPath)))
  2702. {
  2703. Counter++;
  2704. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2705. }
  2706. if (!LinesSourcePath.IsEmpty())
  2707. {
  2708. // Copy as is, exactly preserving the file encoding
  2709. TFile::Copy(ApiPath(LinesSourcePath), ApiPath(ExtensionPath));
  2710. }
  2711. else
  2712. {
  2713. Lines->WriteBOM = false;
  2714. Lines->SaveToFile(ApiPath(ExtensionPath));
  2715. }
  2716. FAddedExtensions->Add(ExtensionPath);
  2717. }
  2718. int Index = GetListCommandIndex(FExtensionList);
  2719. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2720. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2721. CustomCommand->LoadExtension(ExtensionPath);
  2722. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2723. UpdateCustomCommandsView();
  2724. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2725. CustomCommandsView->ItemFocused->MakeVisible(false);
  2726. UpdateControls();
  2727. if (!Latest)
  2728. {
  2729. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2730. }
  2731. if (IsUrl)
  2732. {
  2733. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2734. }
  2735. else
  2736. {
  2737. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2738. }
  2739. }
  2740. }
  2741. }
  2742. //---------------------------------------------------------------------------
  2743. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2744. {
  2745. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2746. {
  2747. AddEditCommand(false);
  2748. }
  2749. else
  2750. {
  2751. AddExtension();
  2752. }
  2753. }
  2754. //---------------------------------------------------------------------------
  2755. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2756. {
  2757. AddEditCommand(false);
  2758. }
  2759. //---------------------------------------------------------------------------
  2760. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2761. {
  2762. AddExtension();
  2763. }
  2764. //---------------------------------------------------------------------------
  2765. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2766. {
  2767. AddEditCommand(true);
  2768. }
  2769. //---------------------------------------------------------------------------
  2770. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2771. {
  2772. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2773. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2774. MenuPopup(AddCommandMenu, AddCommandButton);
  2775. }
  2776. //---------------------------------------------------------------------------
  2777. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2778. {
  2779. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2780. UnicodeString Result;
  2781. if (Terminal != NULL)
  2782. {
  2783. Result = Terminal->SessionData->SessionKey;
  2784. }
  2785. return Result;
  2786. }
  2787. //---------------------------------------------------------------------------
  2788. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2789. {
  2790. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2791. int Index = (Item != NULL) ? Item->Index : -1;
  2792. if (Index != FCustomCommandsHintItem)
  2793. {
  2794. Application->CancelHint();
  2795. UnicodeString Hint;
  2796. if (Index >= 0)
  2797. {
  2798. TCustomCommandList * List = GetCommandList(Index);
  2799. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2800. Hint = StripHotkey(Command->Name);
  2801. if (Command->ShortCut != 0)
  2802. {
  2803. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2804. }
  2805. if (!Command->Description.IsEmpty())
  2806. {
  2807. Hint += L"\n" + Command->Description;
  2808. }
  2809. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2810. if (List == FExtensionList)
  2811. {
  2812. Hint += L"\n" + Command->FileName;
  2813. }
  2814. }
  2815. CustomCommandsView->Hint = Hint;
  2816. FCustomCommandsHintItem = Index;
  2817. }
  2818. }
  2819. //---------------------------------------------------------------------------
  2820. void TPreferencesDialog::HideFocus(int State)
  2821. {
  2822. Perform(WM_CHANGEUISTATE, MAKEWPARAM(State, UISF_HIDEFOCUS), 0);
  2823. }
  2824. //---------------------------------------------------------------------------
  2825. void TPreferencesDialog::SetFocusIfEnabled(TControl * Control)
  2826. {
  2827. TWinControl * WinControl = dynamic_cast<TWinControl *>(Control);
  2828. if ((WinControl != NULL) && WinControl->Enabled)
  2829. {
  2830. WinControl->SetFocus();
  2831. }
  2832. else if (Control->Parent != NULL)
  2833. {
  2834. SetFocusIfEnabled(Control->Parent);
  2835. }
  2836. }
  2837. //---------------------------------------------------------------------------
  2838. void TPreferencesDialog::FocusAndHighlightControl(TControl * Control, const UnicodeString & Text)
  2839. {
  2840. bool HighlightInside = true;
  2841. TLabel * Label = dynamic_cast<TLabel *>(Control);
  2842. if ((Label != NULL) && (Label->FocusControl != NULL))
  2843. {
  2844. Control = Label->FocusControl;
  2845. HighlightInside = false;
  2846. }
  2847. TRadioButton * RadioButton = dynamic_cast<TRadioButton *>(Control);
  2848. // cannot focus non-checked radio as that would check it
  2849. if ((RadioButton != NULL) && !RadioButton->Checked)
  2850. {
  2851. TWinControl * RadioParent = RadioButton->Parent;
  2852. bool Found = false;
  2853. for (int Index = 0; Index < RadioParent->ControlCount; Index++)
  2854. {
  2855. TRadioButton * RadioSibling = dynamic_cast<TRadioButton *>(RadioParent->Controls[Index]);
  2856. if ((RadioSibling != NULL) && RadioSibling->Checked)
  2857. {
  2858. SetFocusIfEnabled(RadioSibling);
  2859. Found = true;
  2860. break;
  2861. }
  2862. }
  2863. if (!Found)
  2864. {
  2865. SetFocusIfEnabled(RadioParent);
  2866. }
  2867. }
  2868. else
  2869. {
  2870. SetFocusIfEnabled(Control);
  2871. if (HighlightInside)
  2872. {
  2873. TComboBox * ComboBox = dynamic_cast<TComboBox *>(Control);
  2874. if ((ComboBox != NULL) && (ComboBox->Style == csDropDownList) && (ComboBox->Text != Text))
  2875. {
  2876. ComboBox->DroppedDown = true;
  2877. }
  2878. }
  2879. }
  2880. FHideFocus = ((Perform(WM_QUERYUISTATE, 0, 0) & UISF_HIDEFOCUS) != 0);
  2881. HideFocus(UIS_CLEAR);
  2882. }
  2883. //---------------------------------------------------------------------------
  2884. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2885. {
  2886. SetActivePage(QueueSheet);
  2887. FocusAndHighlightControl(QueueNoConfirmationCheck, EmptyStr);
  2888. }
  2889. //---------------------------------------------------------------------------
  2890. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2891. {
  2892. ConfigureCommand();
  2893. }
  2894. //---------------------------------------------------------------------------
  2895. void __fastcall TPreferencesDialog::ConfigureCommand()
  2896. {
  2897. int Index = CustomCommandsView->ItemIndex;
  2898. TCustomCommandList * CommandList = GetCommandList(Index);
  2899. int CommandIndex = GetCommandIndex(Index);
  2900. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2901. UnicodeString Site = GetSessionKey();
  2902. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2903. Site.IsEmpty())
  2904. {
  2905. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2906. }
  2907. TShortCut ShortCut = Command->ShortCut;
  2908. TShortCuts ShortCuts = GetShortCuts();
  2909. if (DoCustomCommandOptionsDialog(
  2910. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2911. {
  2912. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2913. UpdatedCommand->ShortCut = ShortCut;
  2914. CommandList->Change(CommandIndex, UpdatedCommand);
  2915. UpdateCustomCommandsView();
  2916. }
  2917. }
  2918. //---------------------------------------------------------------------------
  2919. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2920. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2921. {
  2922. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2923. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2924. {
  2925. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2926. }
  2927. if (LocaleInfo->Completeness < 0)
  2928. {
  2929. Sender->Canvas->Font->Color = clRed;
  2930. }
  2931. else if (LocaleInfo->Completeness < 100)
  2932. {
  2933. Sender->Canvas->Font->Color = clGrayText;
  2934. }
  2935. }
  2936. //---------------------------------------------------------------------------
  2937. void __fastcall TPreferencesDialog::SizeComboExit(TObject * Sender)
  2938. {
  2939. __int64 Size;
  2940. if (!IsCancelButtonBeingClicked(this))
  2941. {
  2942. TComboBox * ComboBox = DebugNotNull(dynamic_cast<TComboBox *>(Sender));
  2943. if (!TryStrToSize(ComboBox->Text, Size))
  2944. {
  2945. ComboBox->SetFocus();
  2946. throw Exception(FMTLOAD(SIZE_INVALID, (ComboBox->Text)));
  2947. }
  2948. else
  2949. {
  2950. ComboBox->Text = SizeToStr(Size);
  2951. }
  2952. }
  2953. }
  2954. //---------------------------------------------------------------------------
  2955. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2956. {
  2957. if (!IsCancelButtonBeingClicked(this))
  2958. {
  2959. try
  2960. {
  2961. UnicodeString Program, AParams, Dir;
  2962. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2963. }
  2964. catch(...)
  2965. {
  2966. PuttyPathEdit->SelectAll();
  2967. PuttyPathEdit->SetFocus();
  2968. throw;
  2969. }
  2970. }
  2971. }
  2972. //---------------------------------------------------------------------------
  2973. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2974. {
  2975. Active = AutomaticIniFileStorageButton->Checked;
  2976. }
  2977. //---------------------------------------------------------------------------
  2978. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2979. {
  2980. UnicodeString Result;
  2981. if (CustomIniFileStorageButton->Checked)
  2982. {
  2983. Result = CustomIniFileStorageEdit->Text;
  2984. }
  2985. return Result;
  2986. }
  2987. //---------------------------------------------------------------------------
  2988. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2989. {
  2990. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2991. UnicodeString CustomIniFileStorageNameExpanded = ExpandEnvironmentVariables(CustomIniFileStorageName);
  2992. if (!CustomIniFileStorageName.IsEmpty() &&
  2993. // Not expanding, as we want to allow change from explicit path to path with variables and vice versa
  2994. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2995. FileExists(CustomIniFileStorageNameExpanded))
  2996. {
  2997. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageNameExpanded));
  2998. TMessageParams Params;
  2999. TQueryButtonAlias Aliases[2];
  3000. Aliases[0].Button = qaYes;
  3001. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  3002. Aliases[1].Button = qaNo;
  3003. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  3004. Params.Aliases = Aliases;
  3005. Params.AliasesCount = 2;
  3006. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  3007. if (Result == qaYes)
  3008. {
  3009. // noop
  3010. }
  3011. else if (Result == qaNo)
  3012. {
  3013. // Similar to TLoginDialog::ImportActionExecute
  3014. Configuration->ScheduleCustomIniFileStorageUse(CustomIniFileStorageName);
  3015. ExecuteSelf(EmptyStr);
  3016. TerminateApplication();
  3017. }
  3018. else
  3019. {
  3020. Abort();
  3021. }
  3022. }
  3023. FCustomIniFileStorageName = CustomIniFileStorageName;
  3024. }
  3025. //---------------------------------------------------------------------------
  3026. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  3027. {
  3028. if (!IsCancelButtonBeingClicked(this))
  3029. {
  3030. CustomIniFileStorageChanged();
  3031. }
  3032. else
  3033. {
  3034. // Reset the value to prevent accidental overwrite of an INI file, in case the dialog cancel does not complete
  3035. CustomIniFileStorageEdit->Text = FCustomIniFileStorageName;
  3036. }
  3037. }
  3038. //---------------------------------------------------------------------------
  3039. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  3040. {
  3041. PathEditAfterDialog(Sender, Name, Action);
  3042. if (Action)
  3043. {
  3044. CustomIniFileStorageEdit->Text = Name;
  3045. CustomIniFileStorageChanged();
  3046. }
  3047. }
  3048. //---------------------------------------------------------------------------
  3049. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  3050. {
  3051. UpdateControls();
  3052. // Handler is called also when Checked is set from LoadConfiguration
  3053. if (FNoUpdate == 0)
  3054. {
  3055. // Focus to force validation
  3056. CustomIniFileStorageEdit->SetFocus();
  3057. }
  3058. }
  3059. //---------------------------------------------------------------------------
  3060. void __fastcall TPreferencesDialog::UpdateFileColorsView()
  3061. {
  3062. FileColorsView->Items->Count = FFileColors.size();
  3063. AutoSizeListColumnsWidth(FileColorsView);
  3064. }
  3065. //---------------------------------------------------------------------------
  3066. void __fastcall TPreferencesDialog::FileColorsViewData(TObject *, TListItem * Item)
  3067. {
  3068. Item->Caption = FFileColors[Item->Index].FileMask.Masks;
  3069. }
  3070. //---------------------------------------------------------------------------
  3071. void __fastcall TPreferencesDialog::FileColorsViewCustomDrawItem(
  3072. TCustomListView * Sender, TListItem * Item, TCustomDrawState, bool & DebugUsedArg(DefaultDraw))
  3073. {
  3074. Sender->Canvas->Font->Color = FFileColors[Item->Index].Color;
  3075. }
  3076. //---------------------------------------------------------------------------
  3077. void __fastcall TPreferencesDialog::AddEditFileColor(bool Edit)
  3078. {
  3079. TFileColorData FileColorData;
  3080. int Index = FileColorsView->ItemIndex;
  3081. if (Edit)
  3082. {
  3083. FileColorData = FFileColors[Index];
  3084. }
  3085. else
  3086. {
  3087. FileColorData.FileMask = AnyMask;
  3088. }
  3089. if (DoFileColorDialog(FileColorData))
  3090. {
  3091. if (Edit)
  3092. {
  3093. FFileColors[Index] = FileColorData;
  3094. }
  3095. else
  3096. {
  3097. if (Index < 0)
  3098. {
  3099. FFileColors.push_back(FileColorData);
  3100. }
  3101. else
  3102. {
  3103. FFileColors.insert(&FFileColors[Index], FileColorData);
  3104. }
  3105. }
  3106. UpdateFileColorsView();
  3107. FileColorsView->ItemIndex = Index;
  3108. UpdateControls();
  3109. }
  3110. }
  3111. //---------------------------------------------------------------------------
  3112. void __fastcall TPreferencesDialog::AddEditFileColorButtonClick(TObject * Sender)
  3113. {
  3114. bool Edit = (Sender == EditFileColorButton);
  3115. AddEditFileColor(Edit);
  3116. }
  3117. //---------------------------------------------------------------------------
  3118. void __fastcall TPreferencesDialog::FileColorMove(int Source, int Dest)
  3119. {
  3120. FFileColors.insert(FFileColors.begin() + Dest + ((Dest > Source) ? 1 : 0), FFileColors[Source]);
  3121. FFileColors.erase(FFileColors.begin() + Source + ((Dest < Source) ? 1 : 0));
  3122. FileColorsView->ItemIndex = Dest;
  3123. UpdateFileColorsView();
  3124. UpdateControls();
  3125. }
  3126. //---------------------------------------------------------------------------
  3127. void __fastcall TPreferencesDialog::FileColorsViewDragDrop(TObject * Sender, TObject * Source, int X, int Y)
  3128. {
  3129. if (Source == FileColorsView)
  3130. {
  3131. if (AllowListViewDrag(Sender, X, Y))
  3132. {
  3133. FileColorMove(FListViewDragSource, FListViewDragDest);
  3134. }
  3135. }
  3136. }
  3137. //---------------------------------------------------------------------------
  3138. void __fastcall TPreferencesDialog::FileColorsViewKeyDown(TObject *, WORD & Key, TShiftState)
  3139. {
  3140. if (RemoveFileColorButton->Enabled && (Key == VK_DELETE))
  3141. {
  3142. RemoveFileColorButtonClick(NULL);
  3143. }
  3144. if (DebugAlwaysTrue(AddFileColorButton->Enabled) && (Key == VK_INSERT))
  3145. {
  3146. AddEditFileColor(false);
  3147. }
  3148. }
  3149. //---------------------------------------------------------------------------
  3150. void __fastcall TPreferencesDialog::RemoveFileColorButtonClick(TObject *)
  3151. {
  3152. FFileColors.erase(FFileColors.begin() + FileColorsView->ItemIndex);
  3153. UpdateFileColorsView();
  3154. UpdateControls();
  3155. }
  3156. //---------------------------------------------------------------------------
  3157. void __fastcall TPreferencesDialog::FileColorsViewDblClick(TObject *)
  3158. {
  3159. if (EditFileColorButton->Enabled)
  3160. {
  3161. AddEditFileColor(true);
  3162. }
  3163. }
  3164. //---------------------------------------------------------------------------
  3165. void __fastcall TPreferencesDialog::UpDownFileColorButtonClick(TObject * Sender)
  3166. {
  3167. int DestIndex = FileColorsView->ItemIndex + (Sender == UpFileColorButton ? -1 : 1);
  3168. FileColorMove(FileColorsView->ItemIndex, DestIndex);
  3169. }
  3170. //---------------------------------------------------------------------------
  3171. void __fastcall TPreferencesDialog::LocalPortNumberMinEditExit(TObject *)
  3172. {
  3173. if (LocalPortNumberMinEdit->AsInteger > LocalPortNumberMaxEdit->AsInteger)
  3174. {
  3175. LocalPortNumberMaxEdit->Value = LocalPortNumberMaxEdit->MaxValue;
  3176. }
  3177. }
  3178. //---------------------------------------------------------------------------
  3179. void __fastcall TPreferencesDialog::LocalPortNumberMaxEditExit(TObject *)
  3180. {
  3181. if (LocalPortNumberMaxEdit->AsInteger < LocalPortNumberMinEdit->AsInteger)
  3182. {
  3183. if (LocalPortNumberMaxEdit->AsInteger >= PrivatePortMin)
  3184. {
  3185. LocalPortNumberMinEdit->AsInteger = PrivatePortMin;
  3186. }
  3187. else
  3188. {
  3189. LocalPortNumberMinEdit->Value = LocalPortNumberMinEdit->MinValue;
  3190. }
  3191. }
  3192. }
  3193. //---------------------------------------------------------------------------
  3194. UnicodeString TPreferencesDialog::Bullet(const UnicodeString & S)
  3195. {
  3196. // Keep in sync with similar function in installer
  3197. UnicodeString Result = S;
  3198. UnicodeString Dash(L"-");
  3199. UnicodeString Bullet(L"\u2022 ");
  3200. if (StartsStr(Dash, Result))
  3201. {
  3202. Result = Bullet + Result.SubString(Dash.Length() + 1, Result.Length() - Dash.Length());
  3203. }
  3204. Result = ReplaceStr(Result, sLineBreak + 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. //---------------------------------------------------------------------------