Preferences.cpp 133 KB

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