Preferences.cpp 114 KB

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