1
0

Preferences.cpp 110 KB

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