Preferences.cpp 104 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967
  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. // workaround for bug in VCL
  1477. CustomCommandsView->ItemIndex = -1;
  1478. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  1479. CustomCommandsView->ItemIndex = Dest;
  1480. UpdateCustomCommandsView();
  1481. UpdateControls();
  1482. }
  1483. //---------------------------------------------------------------------------
  1484. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  1485. {
  1486. CustomCommandMove(CustomCommandsView->ItemIndex,
  1487. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  1488. }
  1489. //---------------------------------------------------------------------------
  1490. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  1491. {
  1492. if (ListView == CopyParamListView)
  1493. {
  1494. return FCopyParamScrollOnDragOver;
  1495. }
  1496. else if (ListView == CustomCommandsView)
  1497. {
  1498. return FCustomCommandsScrollOnDragOver;
  1499. }
  1500. else if (ListView == EditorListView3)
  1501. {
  1502. return FEditorScrollOnDragOver;
  1503. }
  1504. else
  1505. {
  1506. DebugFail();
  1507. return NULL;
  1508. }
  1509. }
  1510. //---------------------------------------------------------------------------
  1511. void __fastcall TPreferencesDialog::ListViewStartDrag(
  1512. TObject * Sender, TDragObject *& /*DragObject*/)
  1513. {
  1514. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  1515. FListViewDragDest = -1;
  1516. ScrollOnDragOver(Sender)->StartDrag();
  1517. }
  1518. //---------------------------------------------------------------------------
  1519. static int __fastcall PointToListViewIndex(TObject * Sender, int X, int Y)
  1520. {
  1521. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  1522. return Item ? Item->Index : -1;
  1523. }
  1524. //---------------------------------------------------------------------------
  1525. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  1526. {
  1527. FListViewDragDest = PointToListViewIndex(Sender, X, Y);
  1528. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  1532. TObject * Sender, TObject * Source, int X, int Y)
  1533. {
  1534. if (Source == CustomCommandsView)
  1535. {
  1536. if (AllowListViewDrag(Sender, X, Y) &&
  1537. (GetCommandList(FListViewDragSource) == GetCommandList(FListViewDragDest)))
  1538. {
  1539. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  1540. }
  1541. }
  1542. }
  1543. //---------------------------------------------------------------------------
  1544. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  1545. TObject *Sender, TObject *Source, int X, int Y, TDragState State, bool & Accept)
  1546. {
  1547. ListViewDragOver(Sender, Source, X, Y, State, Accept);
  1548. if (Source == Sender)
  1549. {
  1550. int Dest = PointToListViewIndex(Sender, X, Y);
  1551. if (GetCommandList(FListViewDragSource) != GetCommandList(Dest))
  1552. {
  1553. Accept = false;
  1554. }
  1555. }
  1556. }
  1557. //---------------------------------------------------------------------------
  1558. void __fastcall TPreferencesDialog::ListViewDragOver(
  1559. TObject * Sender, TObject * Source, int X, int Y,
  1560. TDragState /*State*/, bool & Accept)
  1561. {
  1562. if (Source == Sender)
  1563. {
  1564. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  1565. // (when dropped on item itself, when it was dragged over another item before,
  1566. // that another item remains highlighted forever)
  1567. Accept = true;
  1568. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  1569. }
  1570. }
  1571. //---------------------------------------------------------------------------
  1572. const TCopyParamType * TPreferencesDialog::GetCopyParam(int Index)
  1573. {
  1574. if (Index == 0)
  1575. {
  1576. return &FCopyParams;
  1577. }
  1578. else
  1579. {
  1580. return FCopyParamList->CopyParams[Index - 1];
  1581. }
  1582. }
  1583. //---------------------------------------------------------------------------
  1584. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  1585. {
  1586. if (Source >= 1 && Source < (1 + FCopyParamList->Count) &&
  1587. Dest >= 0 && Dest < (1 + FCopyParamList->Count))
  1588. {
  1589. if (Dest == 0)
  1590. {
  1591. Dest = 1;
  1592. }
  1593. FCopyParamList->Move(Source - 1, Dest - 1);
  1594. // workaround for bug in VCL
  1595. CopyParamListView->ItemIndex = -1;
  1596. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1597. CopyParamListView->ItemIndex = Dest;
  1598. UpdateCopyParamListView();
  1599. UpdateControls();
  1600. }
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  1604. TObject * Sender, TObject * Source, int X, int Y)
  1605. {
  1606. if (Source == CopyParamListView)
  1607. {
  1608. if (AllowListViewDrag(Sender, X, Y))
  1609. {
  1610. CopyParamMove(FListViewDragSource, FListViewDragDest);
  1611. }
  1612. }
  1613. }
  1614. //---------------------------------------------------------------------------
  1615. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  1616. {
  1617. CopyParamMove(CopyParamListView->ItemIndex,
  1618. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  1619. }
  1620. //---------------------------------------------------------------------------
  1621. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  1622. TObject * /*Sender*/)
  1623. {
  1624. DebugAssert(CopyParamListView->ItemIndex >= 1 &&
  1625. CopyParamListView->ItemIndex < (1 + FCopyParamList->Count));
  1626. FCopyParamList->Delete(CopyParamListView->ItemIndex - 1);
  1627. UpdateCopyParamListView();
  1628. UpdateControls();
  1629. }
  1630. //---------------------------------------------------------------------------
  1631. void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
  1632. {
  1633. int Index = CopyParamListView->ItemIndex;
  1634. bool Result;
  1635. if ((Index == 0) && (Mode == cpmEdit))
  1636. {
  1637. Result = DoCopyParamCustomDialog(FCopyParams, 0);
  1638. }
  1639. else
  1640. {
  1641. TCopyParamRuleData * CopyParamRuleData =
  1642. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1643. // negative (when default is selected) means add to the end
  1644. Index--;
  1645. TCopyParamType DefaultCopyParams;
  1646. // For cpmAdd use defaults.
  1647. if (Mode == cpmDuplicate)
  1648. {
  1649. // Only used, when duplicating default settings (Index < 0)
  1650. DefaultCopyParams = FCopyParams;
  1651. }
  1652. else if (Mode == cpmEdit)
  1653. {
  1654. // For cpmEdit, DefaultCopyParams is never used.
  1655. DebugAssert(Index >= 0);
  1656. }
  1657. Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
  1658. if (Result)
  1659. {
  1660. UpdateCopyParamListView();
  1661. CopyParamListView->ItemIndex = Index + 1;
  1662. // when using duplicate button, focus remains on original item
  1663. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1664. }
  1665. }
  1666. if (Result)
  1667. {
  1668. UpdateControls();
  1669. }
  1670. }
  1671. //---------------------------------------------------------------------------
  1672. void __fastcall TPreferencesDialog::AddCopyParamButtonClick(TObject * /*Sender*/)
  1673. {
  1674. AddEditCopyParam(cpmAdd);
  1675. }
  1676. //---------------------------------------------------------------------------
  1677. void __fastcall TPreferencesDialog::EditCopyParamButtonClick(TObject * /*Sender*/)
  1678. {
  1679. AddEditCopyParam(cpmEdit);
  1680. }
  1681. //---------------------------------------------------------------------------
  1682. void __fastcall TPreferencesDialog::DuplicateCopyParamButtonClick(TObject * /*Sender*/)
  1683. {
  1684. AddEditCopyParam(cpmDuplicate);
  1685. }
  1686. //---------------------------------------------------------------------------
  1687. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1688. TObject * /*Sender*/)
  1689. {
  1690. if (EditCopyParamButton->Enabled)
  1691. {
  1692. AddEditCopyParam(cpmEdit);
  1693. }
  1694. }
  1695. //---------------------------------------------------------------------------
  1696. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1697. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1698. {
  1699. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1700. {
  1701. RemoveCopyParamButtonClick(NULL);
  1702. }
  1703. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1704. {
  1705. AddEditCopyParam(cpmAdd);
  1706. }
  1707. }
  1708. //---------------------------------------------------------------------------
  1709. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1710. {
  1711. if (Source >= 0 && Source < FEditorList->Count &&
  1712. Dest >= 0 && Dest < FEditorList->Count)
  1713. {
  1714. FEditorList->Move(Source, Dest);
  1715. // workaround for bug in VCL
  1716. EditorListView3->ItemIndex = -1;
  1717. EditorListView3->ItemFocused = EditorListView3->Selected;
  1718. EditorListView3->ItemIndex = Dest;
  1719. UpdateEditorListView();
  1720. UpdateControls();
  1721. }
  1722. }
  1723. //---------------------------------------------------------------------------
  1724. void __fastcall TPreferencesDialog::EditorListView3DragDrop(TObject * Sender,
  1725. TObject * Source, int X, int Y)
  1726. {
  1727. if (Source == EditorListView3)
  1728. {
  1729. if (AllowListViewDrag(Sender, X, Y))
  1730. {
  1731. EditorMove(FListViewDragSource, FListViewDragDest);
  1732. }
  1733. }
  1734. }
  1735. //---------------------------------------------------------------------------
  1736. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1737. {
  1738. EditorMove(EditorListView3->ItemIndex,
  1739. EditorListView3->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1740. }
  1741. //---------------------------------------------------------------------------
  1742. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1743. TObject * /*Sender*/)
  1744. {
  1745. DebugAssert(EditorListView3->ItemIndex >= 0 &&
  1746. EditorListView3->ItemIndex < FEditorList->Count);
  1747. FEditorList->Delete(EditorListView3->ItemIndex);
  1748. UpdateEditorListView();
  1749. UpdateControls();
  1750. }
  1751. //---------------------------------------------------------------------------
  1752. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1753. {
  1754. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1755. int Index = EditorListView3->ItemIndex;
  1756. TEditorPreferences * Editor;
  1757. if (Mode == epmEdit)
  1758. {
  1759. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1760. }
  1761. else
  1762. {
  1763. Editor = new TEditorPreferences();
  1764. }
  1765. try
  1766. {
  1767. bool DummyRemember = false;
  1768. if (DoEditorPreferencesDialog(Editor->GetData(), DummyRemember, Mode, true))
  1769. {
  1770. if (Mode == epmEdit)
  1771. {
  1772. FEditorList->Change(Index, Editor);
  1773. }
  1774. else
  1775. {
  1776. if (Index < 0)
  1777. {
  1778. Index = FEditorList->Count;
  1779. FEditorList->Add(Editor);
  1780. }
  1781. else
  1782. {
  1783. FEditorList->Insert(Index, Editor);
  1784. }
  1785. }
  1786. // ownership of the object lost
  1787. Editor = NULL;
  1788. UpdateEditorListView();
  1789. EditorListView3->ItemIndex = Index;
  1790. UpdateControls();
  1791. }
  1792. }
  1793. __finally
  1794. {
  1795. delete Editor;
  1796. }
  1797. }
  1798. //---------------------------------------------------------------------------
  1799. void __fastcall TPreferencesDialog::EditorListView3DblClick(TObject * /*Sender*/)
  1800. {
  1801. if (EditEditorButton->Enabled)
  1802. {
  1803. AddEditEditorButtonClick(EditEditorButton);
  1804. }
  1805. }
  1806. //---------------------------------------------------------------------------
  1807. void __fastcall TPreferencesDialog::EditorListView3KeyDown(TObject * /*Sender*/,
  1808. WORD & Key, TShiftState /*Shift*/)
  1809. {
  1810. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1811. {
  1812. RemoveEditorButtonClick(NULL);
  1813. }
  1814. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1815. {
  1816. AddEditEditorButtonClick(AddEditorButton);
  1817. }
  1818. }
  1819. //---------------------------------------------------------------------------
  1820. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1821. {
  1822. EditorListView3->Items->Count = FEditorList->Count;
  1823. AutoSizeListColumnsWidth(EditorListView3);
  1824. EditorListView3->Invalidate();
  1825. }
  1826. //---------------------------------------------------------------------------
  1827. void __fastcall TPreferencesDialog::EditorListView3Data(TObject * /*Sender*/,
  1828. TListItem * Item)
  1829. {
  1830. // WORKAROUND We get here on Wine after destructor is called
  1831. if (FEditorList != NULL)
  1832. {
  1833. int Index = Item->Index;
  1834. DebugAssert(Index >= 0 && Index <= FEditorList->Count);
  1835. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1836. Item->Caption = Editor->Name;
  1837. Item->SubItems->Add(Editor->Data->FileMask.Masks);
  1838. if (Editor->Data->Editor == edExternal)
  1839. {
  1840. Item->SubItems->Add(BooleanToStr(Editor->Data->ExternalEditorText));
  1841. }
  1842. }
  1843. }
  1844. //---------------------------------------------------------------------------
  1845. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1846. TTreeNode * Node)
  1847. {
  1848. if (DebugAlwaysTrue(Node->SelectedIndex > 0))
  1849. {
  1850. PageControl->ActivePage = DebugNotNull(FindPageForTreeNode(Node));
  1851. // reshow the accelerators, etc
  1852. ResetSystemSettings(this);
  1853. // This is particularly here to enable EditCopyParamButton,
  1854. // as for some reason CopyParamListView->Selected is NULL until
  1855. // its page is shown for the first time
  1856. UpdateControls();
  1857. }
  1858. }
  1859. //---------------------------------------------------------------------------
  1860. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1861. {
  1862. // this is probably only ever called from FormShow (explicitly)
  1863. bool Found = false;
  1864. if (DebugAlwaysTrue(PageControl->ActivePage->Tag > 0))
  1865. {
  1866. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1867. {
  1868. if (NavigationTree->Items->Item[Index]->SelectedIndex ==
  1869. PageControl->ActivePage->Tag)
  1870. {
  1871. NavigationTree->Items->Item[Index]->Selected = true;
  1872. Found = true;
  1873. }
  1874. }
  1875. }
  1876. if (DebugAlwaysTrue(Found))
  1877. {
  1878. UpdateControls();
  1879. }
  1880. }
  1881. //---------------------------------------------------------------------------
  1882. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1883. {
  1884. if (Message.CharCode == VK_TAB)
  1885. {
  1886. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1887. if (Shift.Contains(ssCtrl))
  1888. {
  1889. TTreeNode * Node = NavigationTree->Selected;
  1890. if (!Shift.Contains(ssShift))
  1891. {
  1892. Node = Node->GetNext();
  1893. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1894. }
  1895. else
  1896. {
  1897. if (Node->GetPrev()) Node = Node->GetPrev();
  1898. else
  1899. while (Node->GetNext()) Node = Node->GetNext();
  1900. }
  1901. Node->Selected = True;
  1902. Message.Result = 1;
  1903. return;
  1904. }
  1905. }
  1906. TForm::Dispatch(&Message);
  1907. }
  1908. //---------------------------------------------------------------------------
  1909. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1910. {
  1911. DebugAssert(Message.HelpInfo != NULL);
  1912. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1913. {
  1914. // invoke help for active page (not for whole form), regardless of focus
  1915. // (e.g. even if focus is on control outside pagecontrol)
  1916. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1917. }
  1918. TForm::Dispatch(&Message);
  1919. }
  1920. //---------------------------------------------------------------------------
  1921. void __fastcall TPreferencesDialog::CMDpiChanged(TMessage & Message)
  1922. {
  1923. // To update font sizes - Note that they get scaled automatically, but as we use our own algorithm,
  1924. // we may end up using a slightly different size, so apply it straight away for consistency
  1925. UpdateControls();
  1926. TForm::Dispatch(&Message);
  1927. }
  1928. //---------------------------------------------------------------------------
  1929. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1930. {
  1931. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1932. DebugAssert(M);
  1933. if (M->Msg == CM_DIALOGKEY)
  1934. {
  1935. CMDialogKey(*((TWMKeyDown *)Message));
  1936. }
  1937. else if (M->Msg == CM_DPICHANGED)
  1938. {
  1939. CMDpiChanged(*M);
  1940. }
  1941. else if (M->Msg == WM_HELP)
  1942. {
  1943. WMHelp(*((TWMHelp *)Message));
  1944. }
  1945. else
  1946. {
  1947. TForm::Dispatch(Message);
  1948. }
  1949. }
  1950. //---------------------------------------------------------------------------
  1951. void __fastcall TPreferencesDialog::RegisterAsUrlHandlersButtonClick(
  1952. TObject * /*Sender*/)
  1953. {
  1954. MenuPopup(RegisterAsUrlHandlerMenu, RegisterAsUrlHandlersButton);
  1955. }
  1956. //---------------------------------------------------------------------------
  1957. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerItemClick(TObject * /*Sender*/)
  1958. {
  1959. unsigned int Result =
  1960. MessageDialog(MainInstructions(LoadStr(CONFIRM_REGISTER_URL2)),
  1961. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1962. if (Result == qaYes)
  1963. {
  1964. TInstantOperationVisualizer Visualizer;
  1965. RegisterForDefaultProtocols();
  1966. }
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. void __fastcall TPreferencesDialog::UnregisterForDefaultProtocolsItemClick(TObject * /*Sender*/)
  1970. {
  1971. unsigned int Result =
  1972. MessageDialog(MainInstructions(LoadStr(CONFIRM_UNREGISTER_URL)),
  1973. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL);
  1974. if (Result == qaYes)
  1975. {
  1976. TInstantOperationVisualizer Visualizer;
  1977. UnregisterForProtocols();
  1978. }
  1979. }
  1980. //---------------------------------------------------------------------------
  1981. void __fastcall TPreferencesDialog::MakeDefaultHandlerItemClick(TObject * /*Sender*/)
  1982. {
  1983. TOperationVisualizer Visualizer;
  1984. LaunchAdvancedAssociationUI();
  1985. }
  1986. //---------------------------------------------------------------------------
  1987. void __fastcall TPreferencesDialog::DDLabelClick(TObject * Sender)
  1988. {
  1989. ((Sender != DDFakeFileDisabledLabel) ? DDFakeFileEnabledButton : DDFakeFileDisabledButton)->SetFocus();
  1990. }
  1991. //---------------------------------------------------------------------------
  1992. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1993. TObject * /*Sender*/)
  1994. {
  1995. UnicodeString AppPath = ExtractFilePath(Application->ExeName);
  1996. if (MessageDialog(MainInstructions(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath))),
  1997. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1998. {
  1999. TInstantOperationVisualizer Visualizer;
  2000. AddSearchPath(AppPath);
  2001. }
  2002. }
  2003. //---------------------------------------------------------------------------
  2004. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  2005. TObject * Sender)
  2006. {
  2007. EditorFontButtonClick(Sender);
  2008. }
  2009. //---------------------------------------------------------------------------
  2010. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  2011. {
  2012. CopyParamListView->Items->Count = 1 + FCopyParamList->Count;
  2013. AutoSizeListColumnsWidth(CopyParamListView);
  2014. CopyParamListView->Invalidate();
  2015. }
  2016. //---------------------------------------------------------------------------
  2017. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  2018. TListItem * Item)
  2019. {
  2020. // WORKAROUND We get here on Wine after destructor is called
  2021. if (FCopyParamList != NULL)
  2022. {
  2023. UnicodeString Name;
  2024. UnicodeString Rule;
  2025. int Index = Item->Index;
  2026. if (Index == 0)
  2027. {
  2028. Name = StripHotkey(LoadStr(COPY_PARAM_DEFAULT));
  2029. }
  2030. else
  2031. {
  2032. DebugAssert(Index >= 1 && Index <= 1 + FCopyParamList->Count);
  2033. Name = StripHotkey(FCopyParamList->Names[Index - 1]);
  2034. Rule = BooleanToStr(FCopyParamList->Rules[Index - 1] != NULL);
  2035. }
  2036. Item->Caption = Name;
  2037. Item->SubItems->Add(Rule);
  2038. }
  2039. }
  2040. //---------------------------------------------------------------------------
  2041. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  2042. {
  2043. FormHelp(this);
  2044. }
  2045. //---------------------------------------------------------------------------
  2046. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  2047. TObject * /*Sender*/)
  2048. {
  2049. UnicodeString Executables = FORMAT("%s;%s", (OriginalPuttyExecutable, KittyExecutable));
  2050. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY2),
  2051. FMTLOAD(PREFERENCES_PUTTY_FILTER2, (Executables)), false, false);
  2052. }
  2053. //---------------------------------------------------------------------------
  2054. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  2055. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2056. {
  2057. FBeforeDialogPath = Name;
  2058. Name = ExpandEnvironmentVariables(Name);
  2059. }
  2060. //---------------------------------------------------------------------------
  2061. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  2062. TObject * /*Sender*/, UnicodeString & Name, bool & /*Action*/)
  2063. {
  2064. if (IsPathToSameFile(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  2065. {
  2066. Name = FBeforeDialogPath;
  2067. }
  2068. }
  2069. //---------------------------------------------------------------------------
  2070. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  2071. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  2072. {
  2073. AllowCollapse = false;
  2074. }
  2075. //---------------------------------------------------------------------------
  2076. void __fastcall TPreferencesDialog::ListViewEndDrag(
  2077. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  2078. {
  2079. ScrollOnDragOver(Sender)->EndDrag();
  2080. }
  2081. //---------------------------------------------------------------------------
  2082. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditSetValue(
  2083. TObject * /*Sender*/, Extended Value, UnicodeString & Text, bool & Handled)
  2084. {
  2085. if (Value == 0)
  2086. {
  2087. Text = LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED);
  2088. Handled = true;
  2089. }
  2090. }
  2091. //---------------------------------------------------------------------------
  2092. void __fastcall TPreferencesDialog::SessionReopenTimeoutEditGetValue(
  2093. TObject * /*Sender*/, UnicodeString Text, Extended & Value, bool & Handled)
  2094. {
  2095. if (AnsiSameText(Text, LoadStr(PREFERENCES_RECONNECT_TIMEOUT_UNLIMITED)))
  2096. {
  2097. Value = 0;
  2098. Handled = true;
  2099. }
  2100. }
  2101. //---------------------------------------------------------------------------
  2102. bool __fastcall TPreferencesDialog::CanSetMasterPassword()
  2103. {
  2104. bool Result;
  2105. bool Retry;
  2106. do
  2107. {
  2108. Retry = false;
  2109. Result = !AnyOtherInstanceOfSelf();
  2110. if (!Result)
  2111. {
  2112. unsigned int Answer =
  2113. MessageDialog(
  2114. LoadStr(MASTER_PASSWORD_OTHER_INSTANCE),
  2115. qtConfirmation, qaRetry | qaIgnore | qaCancel,
  2116. HELP_MASTER_PASSWORD);
  2117. switch (Answer)
  2118. {
  2119. case qaRetry:
  2120. Retry = true;
  2121. break;
  2122. case qaIgnore:
  2123. Result = true;
  2124. break;
  2125. case qaCancel:
  2126. default:
  2127. // noop
  2128. break;
  2129. }
  2130. }
  2131. }
  2132. while (Retry && !Result);
  2133. return Result;
  2134. }
  2135. //---------------------------------------------------------------------------
  2136. void __fastcall TPreferencesDialog::MasterPasswordChanged(
  2137. UnicodeString Message, TStrings * RecryptPasswordErrors)
  2138. {
  2139. // Save master password.
  2140. // This is unlikely to fail, as storage is written explicitly already
  2141. // when writing the recrypted passwords
  2142. Configuration->SaveExplicit();
  2143. TQueryType QueryType = qtInformation;
  2144. if (RecryptPasswordErrors->Count > 0)
  2145. {
  2146. Message = FMTLOAD(MASTER_PASSWORD_RECRYPT_ERRORS, (Message));
  2147. QueryType = qtWarning;
  2148. }
  2149. MoreMessageDialog(
  2150. Message, RecryptPasswordErrors, QueryType, qaOK, HELP_MASTER_PASSWORD);
  2151. }
  2152. //---------------------------------------------------------------------------
  2153. void __fastcall TPreferencesDialog::ChangeMasterPassword(UnicodeString Message)
  2154. {
  2155. UnicodeString NewPassword;
  2156. if (DoChangeMasterPasswordDialog(NewPassword))
  2157. {
  2158. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2159. WinConfiguration->ChangeMasterPassword(NewPassword, RecryptPasswordErrors.get());
  2160. MasterPasswordChanged(Message, RecryptPasswordErrors.get());
  2161. }
  2162. }
  2163. //---------------------------------------------------------------------------
  2164. void __fastcall TPreferencesDialog::UseMasterPasswordCheckClick(
  2165. TObject * /*Sender*/)
  2166. {
  2167. if (UseMasterPasswordCheck->Checked != WinConfiguration->UseMasterPassword)
  2168. {
  2169. try
  2170. {
  2171. if (CanSetMasterPassword())
  2172. {
  2173. if (UseMasterPasswordCheck->Checked)
  2174. {
  2175. ChangeMasterPassword(LoadStr(MASTER_PASSWORD_SET2));
  2176. }
  2177. else
  2178. {
  2179. if (DoMasterPasswordDialog())
  2180. {
  2181. std::unique_ptr<TStrings> RecryptPasswordErrors(new TStringList());
  2182. WinConfiguration->ClearMasterPassword(RecryptPasswordErrors.get());
  2183. MasterPasswordChanged(LoadStr(MASTER_PASSWORD_CLEARED2), RecryptPasswordErrors.get());
  2184. }
  2185. }
  2186. }
  2187. }
  2188. __finally
  2189. {
  2190. UseMasterPasswordCheck->Checked = WinConfiguration->UseMasterPassword;
  2191. UpdateControls();
  2192. }
  2193. }
  2194. }
  2195. //---------------------------------------------------------------------------
  2196. void __fastcall TPreferencesDialog::SetMasterPasswordButtonClick(
  2197. TObject * /*Sender*/)
  2198. {
  2199. if (CanSetMasterPassword())
  2200. {
  2201. ChangeMasterPassword(MainInstructions(LoadStr(MASTER_PASSWORD_CHANGED)));
  2202. }
  2203. }
  2204. //---------------------------------------------------------------------------
  2205. void __fastcall TPreferencesDialog::UsageViewButtonClick(TObject * /*Sender*/)
  2206. {
  2207. DoUsageStatisticsDialog();
  2208. }
  2209. //---------------------------------------------------------------------------
  2210. void __fastcall TPreferencesDialog::CopyParamLabelClick(TObject * /*Sender*/)
  2211. {
  2212. if (EditCopyParamButton->Enabled)
  2213. {
  2214. AddEditCopyParam(cpmEdit);
  2215. }
  2216. }
  2217. //---------------------------------------------------------------------------
  2218. void __fastcall TPreferencesDialog::CopyParamListViewCustomDrawItem(
  2219. TCustomListView * Sender, TListItem * Item,
  2220. TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2221. {
  2222. if (Item->Index == 0)
  2223. {
  2224. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2225. }
  2226. }
  2227. //---------------------------------------------------------------------------
  2228. void __fastcall TPreferencesDialog::SelectPuttyRegistryStorageKey(const UnicodeString & Key)
  2229. {
  2230. PuttyRegistryStorageKeyEdit->ItemIndex =
  2231. PuttyRegistryStorageKeyEdit->Items->IndexOf(Key);
  2232. }
  2233. //---------------------------------------------------------------------------
  2234. void __fastcall TPreferencesDialog::PuttyPathEditChange(TObject * /*Sender*/)
  2235. {
  2236. UnicodeString PuttyPath = PuttyPathEdit->Text;
  2237. if (ContainsText(PuttyPath, OriginalPuttyExecutable))
  2238. {
  2239. SelectPuttyRegistryStorageKey(OriginalPuttyRegistryStorageKey);
  2240. }
  2241. else if (ContainsText(PuttyPath, KittyExecutable))
  2242. {
  2243. SelectPuttyRegistryStorageKey(KittyRegistryStorageKey);
  2244. }
  2245. UpdateControls();
  2246. }
  2247. //---------------------------------------------------------------------------
  2248. void __fastcall TPreferencesDialog::NavigationTreeChanging(TObject * /*Sender*/,
  2249. TTreeNode * Node, bool & /*AllowChange*/)
  2250. {
  2251. TTabSheet * Sheet = FindPageForTreeNode(Node);
  2252. // delay load as this can be time consuming
  2253. if (Sheet == LanguagesSheet)
  2254. {
  2255. LoadLanguages();
  2256. }
  2257. }
  2258. //---------------------------------------------------------------------------
  2259. void __fastcall TPreferencesDialog::LanguagesGetMoreButtonClick(TObject * /*Sender*/)
  2260. {
  2261. OpenBrowser(ProgramUrl(LoadStr(LOCALES_URL)));
  2262. }
  2263. //---------------------------------------------------------------------------
  2264. void __fastcall TPreferencesDialog::CommanderClick(TObject * /*Sender*/)
  2265. {
  2266. CommanderInterfaceButton2->SetFocus();
  2267. }
  2268. //---------------------------------------------------------------------------
  2269. void __fastcall TPreferencesDialog::ExplorerClick(TObject * /*Sender*/)
  2270. {
  2271. ExplorerInterfaceButton2->SetFocus();
  2272. }
  2273. //---------------------------------------------------------------------------
  2274. void __fastcall TPreferencesDialog::PanelFontLabelDblClick(TObject * Sender)
  2275. {
  2276. PanelFontButtonClick(Sender);
  2277. }
  2278. //---------------------------------------------------------------------------
  2279. void __fastcall TPreferencesDialog::UpdatesAuthenticationEmailEditExit(TObject * /*Sender*/)
  2280. {
  2281. if (FVerifiedUpdatesAuthenticationEmail != UpdatesAuthenticationEmailEdit->Text)
  2282. {
  2283. if (!UpdatesAuthenticationEmailEdit->Text.IsEmpty())
  2284. {
  2285. TUpdatesConfiguration Updates = SaveUpdates();
  2286. {
  2287. TInstantOperationVisualizer Visualizer;
  2288. QueryUpdates(Updates);
  2289. }
  2290. UnicodeString AuthenticationError = Updates.Results.AuthenticationError;
  2291. if (!AuthenticationError.IsEmpty())
  2292. {
  2293. AuthenticationError = FormatUpdatesMessage(AuthenticationError);
  2294. if (HasParagraphs(AuthenticationError))
  2295. {
  2296. AuthenticationError = MainInstructionsFirstParagraph(AuthenticationError);
  2297. }
  2298. else
  2299. {
  2300. AuthenticationError = MainInstructions(AuthenticationError);
  2301. }
  2302. UnicodeString HelpUrl = GetEnableAutomaticUpdatesUrl();
  2303. unsigned int Result =
  2304. MoreMessageDialog(AuthenticationError, NULL, qtError, qaIgnore | qaAbort, HelpUrl);
  2305. if (Result == qaAbort)
  2306. {
  2307. Abort();
  2308. }
  2309. }
  2310. }
  2311. FVerifiedUpdatesAuthenticationEmail = UpdatesAuthenticationEmailEdit->Text;
  2312. }
  2313. }
  2314. //---------------------------------------------------------------------------
  2315. void __fastcall TPreferencesDialog::UpdatesLinkClick(TObject * /*Sender*/)
  2316. {
  2317. EnableAutomaticUpdates();
  2318. }
  2319. //---------------------------------------------------------------------------
  2320. void __fastcall TPreferencesDialog::CustomCommandsViewWindowProc(TMessage & Message)
  2321. {
  2322. FOrigCustomCommandsViewWindowProc(Message);
  2323. if (Message.Msg == CN_NOTIFY)
  2324. {
  2325. TWMNotify & NotifyMessage = reinterpret_cast<TWMNotify &>(Message);
  2326. if (NotifyMessage.NMHdr->code == NM_CUSTOMDRAW)
  2327. {
  2328. // request CDDS_ITEMPOSTPAINT notification
  2329. Message.Result |= CDRF_NOTIFYPOSTPAINT | CDRF_NOTIFYSUBITEMDRAW;
  2330. TNMLVCustomDraw * CustomDraw = reinterpret_cast<TNMLVCustomDraw *>(NotifyMessage.NMHdr);
  2331. int Index = CustomDraw->nmcd.dwItemSpec;
  2332. int CommandIndex = GetCommandIndex(Index);
  2333. TCustomCommandList * List = GetCommandList(Index);
  2334. // after end of every list, except for the last last list
  2335. if ((CommandIndex == List->Count - 1) && (Index < CustomCommandsView->Items->Count - 1) &&
  2336. FLAGSET(CustomDraw->nmcd.dwDrawStage, CDDS_ITEMPOSTPAINT))
  2337. {
  2338. TRect Rect;
  2339. Rect.Top = CustomDraw->iSubItem;
  2340. Rect.Left = LVIR_BOUNDS;
  2341. CustomCommandsView->Perform(LVM_GETSUBITEMRECT, CustomDraw->nmcd.dwItemSpec, reinterpret_cast<LPARAM>(&Rect));
  2342. HDC DC = CustomDraw->nmcd.hdc;
  2343. SelectObject(DC, GetStockObject(DC_PEN));
  2344. SetDCPenColor(DC, ColorToRGB(clWindowFrame));
  2345. MoveToEx(DC, Rect.Left, Rect.Bottom - 1, NULL);
  2346. LineTo(DC, Rect.Right, Rect.Bottom - 1);
  2347. }
  2348. }
  2349. }
  2350. }
  2351. //---------------------------------------------------------------------------
  2352. void __fastcall TPreferencesDialog::ExtensionHttpError(THttp * /*Sender*/, int Status, const UnicodeString & Message)
  2353. {
  2354. if ((Status / 10) == 49)
  2355. {
  2356. // HTTP 49x indicate user-friendly error message from winscp.net, throw it without HTTP status code
  2357. throw Exception(Message);
  2358. }
  2359. }
  2360. //---------------------------------------------------------------------------
  2361. void __fastcall TPreferencesDialog::AddExtension()
  2362. {
  2363. const UnicodeString HistoryKey(L"ExtensionPath");
  2364. std::unique_ptr<TStrings> History(CloneStrings(CustomWinConfiguration->History[HistoryKey]));
  2365. UnicodeString Path;
  2366. if (InputDialog(LoadStr(ADD_EXTENSION_CAPTION), LoadStr(ADD_EXTENSION_PROMPT), Path,
  2367. HELP_NONE, History.get(), true) &&
  2368. !Path.IsEmpty())
  2369. {
  2370. CustomWinConfiguration->History[HistoryKey] = History.get();
  2371. bool Trusted;
  2372. bool Latest;
  2373. UnicodeString FileName;
  2374. UnicodeString ExtensionPath;
  2375. std::unique_ptr<TStringList> Lines(new TStringList());
  2376. std::unique_ptr<TCustomCommandType> CustomCommand;
  2377. bool IsUrl = IsHttpOrHttpsUrl(Path);
  2378. try
  2379. {
  2380. UnicodeString ProvisionaryId;
  2381. if (IsUrl)
  2382. {
  2383. UnicodeString Url = Path;
  2384. Url = SecureUrl(Url);
  2385. bool WinSCPURL = IsWinSCPUrl(Url);
  2386. if (WinSCPURL)
  2387. {
  2388. Url = ProgramUrl(Url);
  2389. // The EncodeUrlString should not be necessary, but as we get the value from registry, let's be safe
  2390. Url = AppendUrlParams(Url, FORMAT(L"netframework=%s", (EncodeUrlString(GetNetVersionStr()))));
  2391. Url = AppendUrlParams(Url, FORMAT(L"powershell=%s", (EncodeUrlString(GetPowerShellVersionStr()))));
  2392. Url = AppendUrlParams(Url, FORMAT(L"windows=%s", (EncodeUrlString(WindowsVersion()))));
  2393. Url = CampaignUrl(Url);
  2394. }
  2395. TOperationVisualizer Visualizer;
  2396. std::unique_ptr<THttp> Http(CreateHttp());
  2397. Http->URL = Url;
  2398. std::unique_ptr<TStrings> Headers(new TStringList());
  2399. Headers->Values[L"Accept"] = L"text/winscpextension,text/plain";
  2400. Http->RequestHeaders = Headers.get();
  2401. Http->OnError = ExtensionHttpError;
  2402. Http->Get();
  2403. UnicodeString TrustedStr = Http->ResponseHeaders->Values[L"WinSCP-Extension-Trusted"];
  2404. Trusted = WinSCPURL && (StrToIntDef(TrustedStr, 0) != 0);
  2405. FileName = MakeValidFileName(Http->ResponseHeaders->Values[L"WinSCP-Extension-Id"]);
  2406. if (FileName.IsEmpty())
  2407. {
  2408. FileName = MakeValidFileName(ExtractFileNameFromUrl(Path));
  2409. }
  2410. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2411. Lines->Text = Http->Response;
  2412. Latest = Http->ResponseHeaders->Values[L"WinSCP-Extension-Skipped"].Trim().IsEmpty();
  2413. }
  2414. else
  2415. {
  2416. if (!FileExists(ApiPath(Path)))
  2417. {
  2418. throw Exception(MainInstructions(FMTLOAD(FILE_NOT_EXISTS, (Path))));
  2419. }
  2420. Trusted = true;
  2421. Latest = true;
  2422. UnicodeString Id = WinConfiguration->GetExtensionId(Path);
  2423. FileName = ExtractFileName(Path);
  2424. if (!Id.IsEmpty())
  2425. {
  2426. ExtensionPath = Path;
  2427. ProvisionaryId = Id;
  2428. }
  2429. else
  2430. {
  2431. ProvisionaryId = WinConfiguration->GetProvisionaryExtensionId(FileName);
  2432. }
  2433. LoadScriptFromFile(Path, Lines.get());
  2434. }
  2435. // validate syntax
  2436. CustomCommand.reset(new TCustomCommandType());
  2437. // Provisionary Id, just for the ExtensionStringTranslation, so that the test for EXTENSION_DUPLICATE below works
  2438. CustomCommand->Id = ProvisionaryId;
  2439. CustomCommand->LoadExtension(Lines.get(), FileName);
  2440. }
  2441. catch (Exception & E)
  2442. {
  2443. throw ExtException(&E, MainInstructions(FMTLOAD(EXTENSION_LOAD_ERROR, (Path))));
  2444. }
  2445. if (!ExtensionPath.IsEmpty())
  2446. {
  2447. int Index = FExtensionList->FindIndexByFileName(Path);
  2448. if (Index >= 0)
  2449. {
  2450. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2451. CustomCommandsView->ItemFocused->MakeVisible(false);
  2452. CustomCommandsView->SetFocus();
  2453. throw Exception(MainInstructions(LoadStr(EXTENSION_INSTALLED_ALREADY)));
  2454. }
  2455. }
  2456. if (FExtensionList->Find(CustomCommand->Name) != NULL)
  2457. {
  2458. throw Exception(MainInstructions(FMTLOAD(EXTENSION_DUPLICATE, (StripHotkey(CustomCommand->Name)))));
  2459. }
  2460. if (ExtensionPath.IsEmpty())
  2461. {
  2462. if (TCustomCommandType::GetExtensionId(FileName).IsEmpty())
  2463. {
  2464. UnicodeString FileNameOnly = ExtractFileNameOnly(FileName);
  2465. if (FileNameOnly.IsEmpty())
  2466. {
  2467. FileName = MakeValidFileName(StripHotkey(CustomCommand->Name)) + WinSCPExtensionExt;
  2468. }
  2469. else
  2470. {
  2471. FileName = ExtractFileNameOnly(FileName) + WinSCPExtensionExt + ExtractFileExt(FileName);
  2472. }
  2473. }
  2474. }
  2475. if (Trusted ||
  2476. (MessageDialog(MainInstructions(LoadStr(EXTENSION_UNTRUSTED)), qtWarning, qaOK | qaCancel) == qaOK))
  2477. {
  2478. if (ExtensionPath.IsEmpty())
  2479. {
  2480. UnicodeString UserExtensionsPath = WinConfiguration->GetUserExtensionsPath();
  2481. if (!DirectoryExists(UserExtensionsPath) &&
  2482. !ForceDirectories(UserExtensionsPath))
  2483. {
  2484. throw EOSExtException(MainInstructions(FMTLOAD(CREATE_LOCAL_DIR_ERROR, (UserExtensionsPath))));
  2485. }
  2486. ExtensionPath = IncludeTrailingBackslash(UserExtensionsPath) + FileName;
  2487. int Counter = 1;
  2488. UnicodeString OriginalExtensionPath = ExtensionPath;
  2489. int P = Pos(UpperCase(WinSCPExtensionExt), UpperCase(OriginalExtensionPath));
  2490. while (FileExists(ApiPath(ExtensionPath)))
  2491. {
  2492. Counter++;
  2493. ExtensionPath = WinConfiguration->UniqueExtensionName(LeftStr(OriginalExtensionPath, P - 1), Counter) + RightStr(OriginalExtensionPath, OriginalExtensionPath.Length() - P + 1);
  2494. }
  2495. Lines->SaveToFile(ApiPath(ExtensionPath));
  2496. FAddedExtensions->Add(ExtensionPath);
  2497. }
  2498. int Index = GetListCommandIndex(FExtensionList);
  2499. std::unique_ptr<TCustomCommandType> CustomCommand(new TCustomCommandType());
  2500. CustomCommand->Id = WinConfiguration->GetExtensionId(ExtensionPath);
  2501. CustomCommand->LoadExtension(ExtensionPath);
  2502. Index = AddCommandToList(FExtensionList, Index, CustomCommand.release());
  2503. UpdateCustomCommandsView();
  2504. CustomCommandsView->ItemIndex = GetCommandListIndex(FExtensionList, Index);
  2505. CustomCommandsView->ItemFocused->MakeVisible(false);
  2506. UpdateControls();
  2507. if (!Latest)
  2508. {
  2509. MessageDialog(LoadStr(EXTENSION_NOT_LATEST), qtInformation, qaOK);
  2510. }
  2511. if (IsUrl)
  2512. {
  2513. Configuration->Usage->Inc(L"ExtensionAddsFromUrl");
  2514. }
  2515. else
  2516. {
  2517. Configuration->Usage->Inc(L"ExtensionAddsFromFile");
  2518. }
  2519. }
  2520. }
  2521. }
  2522. //---------------------------------------------------------------------------
  2523. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  2524. {
  2525. if (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList)
  2526. {
  2527. AddEditCommand(false);
  2528. }
  2529. else
  2530. {
  2531. AddExtension();
  2532. }
  2533. }
  2534. //---------------------------------------------------------------------------
  2535. void __fastcall TPreferencesDialog::AddCustomCommandMenuItemClick(TObject * /*Sender*/)
  2536. {
  2537. AddEditCommand(false);
  2538. }
  2539. //---------------------------------------------------------------------------
  2540. void __fastcall TPreferencesDialog::AddExtensionMenuItemClick(TObject * /*Sender*/)
  2541. {
  2542. AddExtension();
  2543. }
  2544. //---------------------------------------------------------------------------
  2545. void __fastcall TPreferencesDialog::EditCommandButtonClick(TObject * /*Sender*/)
  2546. {
  2547. AddEditCommand(true);
  2548. }
  2549. //---------------------------------------------------------------------------
  2550. void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Sender*/)
  2551. {
  2552. AddCustomCommandMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FCustomCommandList);
  2553. AddExtensionMenuItem->Default = (GetCommandList(CustomCommandsView->ItemIndex) == FExtensionList);
  2554. MenuPopup(AddCommandMenu, AddCommandButton);
  2555. }
  2556. //---------------------------------------------------------------------------
  2557. UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
  2558. {
  2559. TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
  2560. UnicodeString Result;
  2561. if (Terminal != NULL)
  2562. {
  2563. Result = Terminal->SessionData->SessionKey;
  2564. }
  2565. return Result;
  2566. }
  2567. //---------------------------------------------------------------------------
  2568. void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
  2569. {
  2570. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  2571. int Index = (Item != NULL) ? Item->Index : -1;
  2572. if (Index != FCustomCommandsHintItem)
  2573. {
  2574. Application->CancelHint();
  2575. UnicodeString Hint;
  2576. if (Index >= 0)
  2577. {
  2578. TCustomCommandList * List = GetCommandList(Index);
  2579. const TCustomCommandType * Command = List->Commands[GetCommandIndex(Index)];
  2580. Hint = StripHotkey(Command->Name);
  2581. if (Command->ShortCut != 0)
  2582. {
  2583. Hint = FORMAT(L"%s (%s)", (Hint, ShortCutToText(Command->ShortCut)));
  2584. }
  2585. if (!Command->Description.IsEmpty())
  2586. {
  2587. Hint += L"\n" + Command->Description;
  2588. }
  2589. Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
  2590. if (List == FExtensionList)
  2591. {
  2592. Hint += L"\n" + Command->FileName;
  2593. }
  2594. }
  2595. CustomCommandsView->Hint = Hint;
  2596. FCustomCommandsHintItem = Index;
  2597. }
  2598. }
  2599. //---------------------------------------------------------------------------
  2600. void __fastcall TPreferencesDialog::BackgroundConfirmationsLinkClick(TObject * /*Sender*/)
  2601. {
  2602. PageControl->ActivePage = QueueSheet;
  2603. PageControlChange(NULL);
  2604. QueueNoConfirmationCheck->SetFocus();
  2605. QueueNoConfirmationCheck->Perform(WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
  2606. }
  2607. //---------------------------------------------------------------------------
  2608. void __fastcall TPreferencesDialog::ConfigureCommandButtonClick(TObject * /*Sender*/)
  2609. {
  2610. ConfigureCommand();
  2611. }
  2612. //---------------------------------------------------------------------------
  2613. void __fastcall TPreferencesDialog::ConfigureCommand()
  2614. {
  2615. int Index = CustomCommandsView->ItemIndex;
  2616. TCustomCommandList * CommandList = GetCommandList(Index);
  2617. int CommandIndex = GetCommandIndex(Index);
  2618. const TCustomCommandType * Command = CommandList->Commands[CommandIndex];
  2619. UnicodeString Site = GetSessionKey();
  2620. if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
  2621. Site.IsEmpty())
  2622. {
  2623. throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
  2624. }
  2625. TShortCut ShortCut = Command->ShortCut;
  2626. TShortCuts ShortCuts = GetShortCuts();
  2627. if (DoCustomCommandOptionsDialog(
  2628. Command, FCustomCommandOptions.get(), &ShortCut, TCustomCommandType::ofConfig, NULL, GetSessionKey(), &ShortCuts))
  2629. {
  2630. TCustomCommandType * UpdatedCommand = new TCustomCommandType(*Command);
  2631. UpdatedCommand->ShortCut = ShortCut;
  2632. CommandList->Change(CommandIndex, UpdatedCommand);
  2633. UpdateCustomCommandsView();
  2634. }
  2635. }
  2636. //---------------------------------------------------------------------------
  2637. void __fastcall TPreferencesDialog::LanguagesViewCustomDrawItem(
  2638. TCustomListView * Sender, TListItem * Item, TCustomDrawState /*State*/, bool & /*DefaultDraw*/)
  2639. {
  2640. TLocaleInfo * LocaleInfo = static_cast<TLocaleInfo *>(Item->Data);
  2641. if (LocaleInfo->Locale == WinConfiguration->DefaultLocale)
  2642. {
  2643. Sender->Canvas->Font->Style = Sender->Canvas->Font->Style << fsBold;
  2644. }
  2645. if (LocaleInfo->Completeness < 0)
  2646. {
  2647. Sender->Canvas->Font->Color = clRed;
  2648. }
  2649. else if (LocaleInfo->Completeness < 100)
  2650. {
  2651. Sender->Canvas->Font->Color = clGrayText;
  2652. }
  2653. }
  2654. //---------------------------------------------------------------------------
  2655. void __fastcall TPreferencesDialog::LogMaxSizeComboExit(TObject * /*Sender*/)
  2656. {
  2657. __int64 Size;
  2658. if (!TryStrToSize(LogMaxSizeCombo->Text, Size))
  2659. {
  2660. LogMaxSizeCombo->SetFocus();
  2661. throw Exception(FMTLOAD(SIZE_INVALID, (LogMaxSizeCombo->Text)));
  2662. }
  2663. else
  2664. {
  2665. LogMaxSizeCombo->Text = SizeToStr(Size);
  2666. }
  2667. }
  2668. //---------------------------------------------------------------------------
  2669. void __fastcall TPreferencesDialog::PuttyPathEditExit(TObject * /*Sender*/)
  2670. {
  2671. try
  2672. {
  2673. UnicodeString Program, AParams, Dir;
  2674. SplitCommand(PuttyPathEdit->Text, Program, AParams, Dir);
  2675. }
  2676. catch(...)
  2677. {
  2678. PuttyPathEdit->SelectAll();
  2679. PuttyPathEdit->SetFocus();
  2680. throw;
  2681. }
  2682. }
  2683. //---------------------------------------------------------------------------
  2684. void __fastcall TPreferencesDialog::AutomaticIniFileStorageLabelGetStatus(TCustomPathLabel * /*Sender*/, bool & Active)
  2685. {
  2686. Active = AutomaticIniFileStorageButton->Checked;
  2687. }
  2688. //---------------------------------------------------------------------------
  2689. UnicodeString __fastcall TPreferencesDialog::GetCustomIniFileStorageName()
  2690. {
  2691. UnicodeString Result;
  2692. if (CustomIniFileStorageButton->Checked)
  2693. {
  2694. Result = CustomIniFileStorageEdit->Text;
  2695. }
  2696. return Result;
  2697. }
  2698. //---------------------------------------------------------------------------
  2699. void __fastcall TPreferencesDialog::CustomIniFileStorageChanged()
  2700. {
  2701. UnicodeString CustomIniFileStorageName = GetCustomIniFileStorageName();
  2702. if (!CustomIniFileStorageName.IsEmpty() &&
  2703. !IsPathToSameFile(CustomIniFileStorageName, FCustomIniFileStorageName) &&
  2704. FileExists(CustomIniFileStorageName))
  2705. {
  2706. UnicodeString Message = FORMAT(LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 1), (CustomIniFileStorageName));
  2707. TMessageParams Params;
  2708. TQueryButtonAlias Aliases[2];
  2709. Aliases[0].Button = qaYes;
  2710. Aliases[0].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 2);
  2711. Aliases[1].Button = qaNo;
  2712. Aliases[1].Alias = LoadStrPart(CUSTOM_INI_FILE_OVERWRITE, 3);
  2713. Params.Aliases = Aliases;
  2714. Params.AliasesCount = 2;
  2715. unsigned int Result = MessageDialog(Message, qtConfirmation, qaYes | qaNo | qaCancel, HELP_MOVE_CONFIGURATION, &Params);
  2716. if (Result == qaYes)
  2717. {
  2718. // noop
  2719. }
  2720. else if (Result == qaNo)
  2721. {
  2722. Configuration->ScheduleCustomIniFileStorageUse(GetCustomIniFileStorageName());
  2723. ExecuteNewInstance(L"");
  2724. TerminateApplication();
  2725. }
  2726. else
  2727. {
  2728. Abort();
  2729. }
  2730. }
  2731. FCustomIniFileStorageName = CustomIniFileStorageName;
  2732. }
  2733. //---------------------------------------------------------------------------
  2734. void __fastcall TPreferencesDialog::CustomIniFileStorageEditExit(TObject * /*Sender*/)
  2735. {
  2736. CustomIniFileStorageChanged();
  2737. }
  2738. //---------------------------------------------------------------------------
  2739. void __fastcall TPreferencesDialog::CustomIniFileStorageEditAfterDialog(TObject * Sender, UnicodeString & Name, bool & Action)
  2740. {
  2741. PathEditAfterDialog(Sender, Name, Action);
  2742. if (Action)
  2743. {
  2744. CustomIniFileStorageEdit->Text = Name;
  2745. CustomIniFileStorageChanged();
  2746. }
  2747. }
  2748. //---------------------------------------------------------------------------
  2749. void __fastcall TPreferencesDialog::CustomIniFileStorageButtonClick(TObject * /*Sender*/)
  2750. {
  2751. UpdateControls();
  2752. // Handler is shown also when Checked is set from LoadConfiguration
  2753. if (FNoUpdate == 0)
  2754. {
  2755. // Focus to force validation
  2756. CustomIniFileStorageEdit->SetFocus();
  2757. }
  2758. }
  2759. //---------------------------------------------------------------------------