Preferences.cpp 90 KB

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