Preferences.cpp 103 KB

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