Preferences.cpp 120 KB

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