Preferences.cpp 103 KB

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