Preferences.cpp 113 KB

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