Preferences.cpp 109 KB

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