Preferences.cpp 103 KB

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