Preferences.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <StrUtils.hpp>
  5. #include <Common.h>
  6. #include "Preferences.h"
  7. #include <CoreMain.h>
  8. #include <Terminal.h>
  9. #include "VCLCommon.h"
  10. #include "GUITools.h"
  11. #include "Tools.h"
  12. #include "TextsWin.h"
  13. #include "HelpWin.h"
  14. #include "WinInterface.h"
  15. #include "WinConfiguration.h"
  16. #include "Setup.h"
  17. //---------------------------------------------------------------------
  18. #pragma link "GeneralSettings"
  19. #pragma link "LogSettings"
  20. #pragma link "CopyParams"
  21. #pragma link "UpDownEdit"
  22. #pragma link "IEComboBox"
  23. #pragma link "HistoryComboBox"
  24. #pragma link "PasswordEdit"
  25. #ifndef NO_RESOURCES
  26. #pragma resource "*.dfm"
  27. #endif
  28. //---------------------------------------------------------------------
  29. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode,
  30. TPreferencesDialogData * DialogData)
  31. {
  32. bool Result;
  33. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
  34. try
  35. {
  36. PreferencesDialog->PreferencesMode = APreferencesMode;
  37. Result = PreferencesDialog->Execute(DialogData);
  38. }
  39. __finally
  40. {
  41. delete PreferencesDialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  47. : TForm(AOwner)
  48. {
  49. SetCorrectFormParent(this);
  50. FNoUpdate = 0;
  51. FPreferencesMode = pmDefault;
  52. CopyParamsFrame->Direction = pdAll;
  53. FEditorFont = new TFont();
  54. FEditorFont->Color = clWindowText;
  55. // color tends to reset in object inspector
  56. EditorFontLabel->Color = clWindow;
  57. // currently useless
  58. FAfterFilenameEditDialog = false;
  59. FCustomCommands = new TCustomCommands();
  60. FCustomCommandChanging = false;
  61. FListViewDragDest = -1;
  62. FCopyParamList = new TCopyParamList();
  63. FEditorList = new TEditorList();
  64. UseSystemSettings(this);
  65. FCustomCommandsScrollOnDragOver = new TListViewScrollOnDragOver(CustomCommandsView, true);
  66. FCopyParamScrollOnDragOver = new TListViewScrollOnDragOver(CopyParamListView, true);
  67. FEditorScrollOnDragOver = new TListViewScrollOnDragOver(EditorListView, true);
  68. LoggingFrame->Init();
  69. InstallPathWordBreakProc(RandomSeedFileEdit);
  70. InstallPathWordBreakProc(DDTemporaryDirectoryEdit);
  71. InstallPathWordBreakProc(PuttyPathEdit);
  72. HintLabel(ShellIconsText);
  73. }
  74. //---------------------------------------------------------------------------
  75. __fastcall TPreferencesDialog::~TPreferencesDialog()
  76. {
  77. SAFE_DESTROY(FEditorScrollOnDragOver);
  78. SAFE_DESTROY(FCopyParamScrollOnDragOver);
  79. SAFE_DESTROY(FCustomCommandsScrollOnDragOver);
  80. delete FEditorFont;
  81. delete FCustomCommands;
  82. delete FCopyParamList;
  83. delete FEditorList;
  84. }
  85. //---------------------------------------------------------------------
  86. bool __fastcall TPreferencesDialog::Execute(TPreferencesDialogData * DialogData)
  87. {
  88. FDialogData = DialogData;
  89. LoadConfiguration();
  90. CopyParamsFrame->BeforeExecute();
  91. bool Result = (ShowModal() == mrOk);
  92. if (Result)
  93. {
  94. CopyParamsFrame->AfterExecute();
  95. SaveConfiguration();
  96. }
  97. return Result;
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  101. {
  102. Tree->FullExpand();
  103. int i = 0;
  104. while (i < Tree->Items->Count)
  105. {
  106. if ((!WinConfiguration->ExpertMode &&
  107. Tree->Items->Item[i]->SelectedIndex & 128))
  108. {
  109. Tree->Items->Delete(Tree->Items->Item[i]);
  110. }
  111. else
  112. {
  113. for (int pi = 0; pi < PageControl->PageCount; pi++)
  114. {
  115. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  116. {
  117. if (PageControl->Pages[pi]->Enabled)
  118. {
  119. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  120. PageControl->Pages[pi]->Hint = "";
  121. }
  122. else
  123. {
  124. Tree->Items->Delete(Tree->Items->Item[i]);
  125. i--;
  126. }
  127. break;
  128. }
  129. }
  130. i++;
  131. }
  132. }
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TPreferencesDialog::LoadConfiguration()
  136. {
  137. FNoUpdate++;
  138. try
  139. {
  140. if (FPreferencesMode != pmLogin)
  141. {
  142. LoggingFrame->LoadConfiguration();
  143. GeneralSettingsFrame->LoadConfiguration();
  144. }
  145. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  146. BOOLPROP(DefaultDirIsHome);
  147. BOOLPROP(PreservePanelState);
  148. BOOLPROP(DeleteToRecycleBin);
  149. BOOLPROP(DDTransferConfirmation);
  150. BOOLPROP(DDWarnLackOfTempSpace);
  151. BOOLPROP(ShowHiddenFiles);
  152. BOOLPROP(ShowInaccesibleDirectories);
  153. BOOLPROP(CopyOnDoubleClickConfirmation);
  154. BOOLPROP(ConfirmTransferring);
  155. BOOLPROP(ConfirmOverwriting);
  156. BOOLPROP(ConfirmResume);
  157. BOOLPROP(ConfirmDeleting);
  158. BOOLPROP(ConfirmRecycling);
  159. BOOLPROP(ConfirmClosingSession);
  160. BOOLPROP(ConfirmExitOnCompletion);
  161. BOOLPROP(UseLocationProfiles);
  162. BOOLPROP(ConfirmCommandSession);
  163. BOOLPROP(ContinueOnError);
  164. BOOLPROP(DDAllowMoveInit);
  165. BOOLPROP(BeepOnFinish);
  166. BOOLPROP(TemporaryDirectoryCleanup);
  167. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  168. BeepOnFinishAfterEdit->AsInteger =
  169. static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * (24*60*60);
  170. BOOLPROP(BalloonNotifications);
  171. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  172. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  173. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  174. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  175. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  176. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  177. {
  178. DDSystemTemporaryDirectoryButton->Checked = true;
  179. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  180. }
  181. else
  182. {
  183. DDCustomTemporaryDirectoryButton->Checked = true;
  184. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  185. }
  186. if (WinConfiguration->ScpCommander.NortonLikeMode == nlOff)
  187. {
  188. NortonLikeModeCombo->ItemIndex = 2;
  189. }
  190. else if (WinConfiguration->ScpCommander.NortonLikeMode == nlKeyboard)
  191. {
  192. NortonLikeModeCombo->ItemIndex = 1;
  193. }
  194. else
  195. {
  196. NortonLikeModeCombo->ItemIndex = 0;
  197. }
  198. PreserveLocalDirectoryCheck->Checked =
  199. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  200. SwappedPanelsCheck->Checked =
  201. WinConfiguration->ScpCommander.SwappedPanels;
  202. FullRowSelectCheck->Checked = WinConfiguration->ScpCommander.FullRowSelect;
  203. ShowFullAddressCheck->Checked =
  204. WinConfiguration->ScpExplorer.ShowFullAddress;
  205. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  206. IniFileStorageButton2->Checked = (Configuration->Storage == stIniFile);
  207. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  208. // editor
  209. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  210. EditorTabSizeEdit->AsInteger = WinConfiguration->Editor.TabSize;
  211. FEditorFont->Name = WinConfiguration->Editor.FontName;
  212. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  213. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  214. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  215. (*FEditorList) = *WinConfiguration->EditorList;
  216. UpdateEditorListView();
  217. CopyParamsFrame->Params = GUIConfiguration->DefaultCopyParam;
  218. ResumeOnButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOn;
  219. ResumeSmartButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsSmart;
  220. ResumeOffButton->Checked = GUIConfiguration->DefaultCopyParam.ResumeSupport == rsOff;
  221. ResumeThresholdEdit->Value = GUIConfiguration->DefaultCopyParam.ResumeThreshold / 1024;
  222. SessionReopenAutoCheck->Checked = (Configuration->SessionReopenAuto > 0);
  223. SessionReopenAutoEdit->Value = (Configuration->SessionReopenAuto > 0 ?
  224. (Configuration->SessionReopenAuto / 1000): 5);
  225. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  226. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  227. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  228. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  229. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  230. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  231. StorageGroup->Visible = WinConfiguration->ExpertMode;
  232. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  233. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  234. FCustomCommands->Assign(WinConfiguration->CustomCommands);
  235. UpdateCustomCommandsView();
  236. PuttyPathEdit->Text = GUIConfiguration->PuttyPath;
  237. PuttyPasswordCheck2->Checked = GUIConfiguration->PuttyPassword;
  238. AutoOpenInPuttyCheck->Checked = WinConfiguration->AutoOpenInPutty;
  239. TelnetForFtpInPuttyCheck->Checked = WinConfiguration->TelnetForFtpInPutty;
  240. // Queue
  241. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  242. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  243. QueueCheck->Checked = GUIConfiguration->DefaultCopyParam.Queue;
  244. QueueNoConfirmationCheck->Checked = GUIConfiguration->DefaultCopyParam.QueueNoConfirmation;
  245. RememberPasswordCheck->Checked = GUIConfiguration->QueueRememberPassword;
  246. if (WinConfiguration->QueueView.Show == qvShow)
  247. {
  248. QueueViewShowButton->Checked = true;
  249. }
  250. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  251. {
  252. QueueViewHideWhenEmptyButton->Checked = true;
  253. }
  254. else
  255. {
  256. QueueViewHideButton->Checked = true;
  257. }
  258. // window
  259. if (WinConfiguration->PathInCaption == picFull)
  260. {
  261. PathInCaptionFullButton->Checked = true;
  262. }
  263. else if (WinConfiguration->PathInCaption == picShort)
  264. {
  265. PathInCaptionShortButton->Checked = true;
  266. }
  267. else
  268. {
  269. PathInCaptionNoneButton->Checked = true;
  270. }
  271. BOOLPROP(MinimizeToTray);
  272. // panels
  273. DoubleClickActionCombo->ItemIndex = WinConfiguration->DoubleClickAction;
  274. BOOLPROP(AutoReadDirectoryAfterOp);
  275. // updates
  276. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  277. if (int(Updates.Period) <= 0)
  278. {
  279. UpdatesNeverButton->Checked = true;
  280. }
  281. else if (int(Updates.Period) <= 1)
  282. {
  283. UpdatesDailyButton->Checked = true;
  284. }
  285. else if (int(Updates.Period) <= 7)
  286. {
  287. UpdatesWeeklyButton->Checked = true;
  288. }
  289. else
  290. {
  291. UpdatesMonthlyButton->Checked = true;
  292. }
  293. switch (Updates.ConnectionType)
  294. {
  295. case ctDirect:
  296. default:
  297. UpdatesDirectCheck->Checked = true;
  298. break;
  299. case ctAuto:
  300. UpdatesAutoCheck->Checked = true;
  301. break;
  302. case ctProxy:
  303. UpdatesProxyCheck->Checked = true;
  304. break;
  305. }
  306. UpdatesProxyHostEdit->Text = Updates.ProxyHost;
  307. UpdatesProxyPortEdit->AsInteger = Updates.ProxyPort;
  308. // presets
  309. (*FCopyParamList) = *WinConfiguration->CopyParamList;
  310. UpdateCopyParamListView();
  311. BOOLPROP(CopyParamAutoSelectNotice);
  312. // interface
  313. if (WinConfiguration->Theme == "OfficeXP")
  314. {
  315. ThemeCombo->ItemIndex = 1;
  316. }
  317. else if (WinConfiguration->Theme == "Office2003")
  318. {
  319. ThemeCombo->ItemIndex = 2;
  320. }
  321. else
  322. {
  323. ThemeCombo->ItemIndex = 0;
  324. }
  325. #undef BOOLPROP
  326. }
  327. __finally
  328. {
  329. FNoUpdate--;
  330. }
  331. UpdateControls();
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TPreferencesDialog::SaveConfiguration()
  335. {
  336. Configuration->BeginUpdate();
  337. try
  338. {
  339. TGUICopyParamType CopyParam = GUIConfiguration->DefaultCopyParam;
  340. if (FPreferencesMode != pmLogin)
  341. {
  342. LoggingFrame->SaveConfiguration();
  343. GeneralSettingsFrame->SaveConfiguration();
  344. }
  345. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  346. BOOLPROP(DefaultDirIsHome);
  347. BOOLPROP(PreservePanelState);
  348. BOOLPROP(DeleteToRecycleBin);
  349. BOOLPROP(DDTransferConfirmation);
  350. BOOLPROP(DDWarnLackOfTempSpace);
  351. BOOLPROP(ShowHiddenFiles);
  352. BOOLPROP(ShowInaccesibleDirectories);
  353. BOOLPROP(CopyOnDoubleClickConfirmation);
  354. BOOLPROP(ConfirmTransferring);
  355. BOOLPROP(ConfirmOverwriting);
  356. BOOLPROP(ConfirmResume);
  357. BOOLPROP(ConfirmDeleting);
  358. BOOLPROP(ConfirmRecycling);
  359. BOOLPROP(ConfirmClosingSession);
  360. BOOLPROP(ConfirmExitOnCompletion);
  361. BOOLPROP(UseLocationProfiles);
  362. BOOLPROP(ConfirmCommandSession);
  363. BOOLPROP(ContinueOnError);
  364. BOOLPROP(DDAllowMoveInit);
  365. BOOLPROP(BeepOnFinish);
  366. BOOLPROP(TemporaryDirectoryCleanup);
  367. BOOLPROP(ConfirmTemporaryDirectoryCleanup);
  368. GUIConfiguration->BeepOnFinishAfter =
  369. static_cast<double>(BeepOnFinishAfterEdit->Value / (24*60*60));
  370. BOOLPROP(BalloonNotifications);
  371. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  372. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  373. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  374. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  375. if (DDSystemTemporaryDirectoryButton->Checked)
  376. {
  377. WinConfiguration->DDTemporaryDirectory = "";
  378. }
  379. else
  380. {
  381. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  382. }
  383. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  384. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  385. if (NortonLikeModeCombo->ItemIndex == 2)
  386. {
  387. ScpCommander.NortonLikeMode = nlOff;
  388. }
  389. else if (NortonLikeModeCombo->ItemIndex == 1)
  390. {
  391. ScpCommander.NortonLikeMode = nlKeyboard;
  392. }
  393. else
  394. {
  395. ScpCommander.NortonLikeMode = nlOn;
  396. }
  397. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  398. ScpCommander.SwappedPanels = SwappedPanelsCheck->Checked;
  399. ScpCommander.FullRowSelect = FullRowSelectCheck->Checked;
  400. WinConfiguration->ScpCommander = ScpCommander;
  401. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  402. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  403. WinConfiguration->ScpExplorer = ScpExplorer;
  404. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  405. // editor
  406. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  407. WinConfiguration->Editor.TabSize = EditorTabSizeEdit->AsInteger;
  408. WinConfiguration->Editor.FontName = FEditorFont->Name;
  409. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  410. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  411. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  412. WinConfiguration->EditorList = FEditorList;
  413. // overwrites only TCopyParamType fields
  414. CopyParam = CopyParamsFrame->Params;
  415. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  416. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  417. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  418. CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
  419. Configuration->SessionReopenAuto =
  420. (SessionReopenAutoCheck->Checked ? (SessionReopenAutoEdit->Value * 1000) : 0);
  421. WinConfiguration->CustomCommands = FCustomCommands;
  422. GUIConfiguration->PuttyPath = PuttyPathEdit->Text;
  423. GUIConfiguration->PuttyPassword = PuttyPasswordCheck2->Checked;
  424. WinConfiguration->AutoOpenInPutty = AutoOpenInPuttyCheck->Checked;
  425. WinConfiguration->TelnetForFtpInPutty = TelnetForFtpInPuttyCheck->Checked;
  426. // Queue
  427. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  428. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  429. CopyParam.Queue = QueueCheck->Checked;
  430. CopyParam.QueueNoConfirmation = QueueNoConfirmationCheck->Checked;
  431. GUIConfiguration->QueueRememberPassword = RememberPasswordCheck->Checked;
  432. if (QueueViewShowButton->Checked)
  433. {
  434. WinConfiguration->QueueView.Show = qvShow;
  435. }
  436. else if (QueueViewHideWhenEmptyButton->Checked)
  437. {
  438. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  439. }
  440. else
  441. {
  442. WinConfiguration->QueueView.Show = qvHide;
  443. }
  444. GUIConfiguration->DefaultCopyParam = CopyParam;
  445. // window
  446. if (PathInCaptionFullButton->Checked)
  447. {
  448. WinConfiguration->PathInCaption = picFull;
  449. }
  450. else if (PathInCaptionShortButton->Checked)
  451. {
  452. WinConfiguration->PathInCaption = picShort;
  453. }
  454. else
  455. {
  456. WinConfiguration->PathInCaption = picNone;
  457. }
  458. BOOLPROP(MinimizeToTray);
  459. // panels
  460. WinConfiguration->DoubleClickAction = (TDoubleClickAction)DoubleClickActionCombo->ItemIndex;
  461. BOOLPROP(AutoReadDirectoryAfterOp);
  462. // updates
  463. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  464. if (UpdatesNeverButton->Checked)
  465. {
  466. Updates.Period = 0;
  467. }
  468. else if (UpdatesDailyButton->Checked)
  469. {
  470. Updates.Period = 1;
  471. }
  472. else if (UpdatesWeeklyButton->Checked)
  473. {
  474. Updates.Period = 7;
  475. }
  476. else
  477. {
  478. Updates.Period = 30;
  479. }
  480. if (UpdatesDirectCheck->Checked)
  481. {
  482. Updates.ConnectionType = ctDirect;
  483. }
  484. else if (UpdatesAutoCheck->Checked)
  485. {
  486. Updates.ConnectionType = ctAuto;
  487. }
  488. else if (UpdatesProxyCheck->Checked)
  489. {
  490. if (!UpdatesProxyHostEdit->Text.IsEmpty())
  491. {
  492. Updates.ConnectionType = ctProxy;
  493. }
  494. else
  495. {
  496. Updates.ConnectionType = ctDirect;
  497. }
  498. }
  499. Updates.ProxyHost = UpdatesProxyHostEdit->Text;
  500. Updates.ProxyPort = UpdatesProxyPortEdit->AsInteger;
  501. WinConfiguration->Updates = Updates;
  502. // presets
  503. WinConfiguration->CopyParamList = FCopyParamList;
  504. BOOLPROP(CopyParamAutoSelectNotice);
  505. // interface
  506. if (ThemeCombo->ItemIndex == 1)
  507. {
  508. WinConfiguration->Theme = "OfficeXP";
  509. }
  510. else if (ThemeCombo->ItemIndex == 2)
  511. {
  512. WinConfiguration->Theme = "Office2003";
  513. }
  514. else
  515. {
  516. WinConfiguration->Theme = "Default";
  517. }
  518. #undef BOOLPROP
  519. }
  520. __finally
  521. {
  522. Configuration->EndUpdate();
  523. }
  524. }
  525. //---------------------------------------------------------------------------
  526. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  527. {
  528. if (PreferencesMode != value)
  529. {
  530. FPreferencesMode = value;
  531. GeneralSheet->Enabled = (value != pmLogin);
  532. LogSheet->Enabled = (value != pmLogin);
  533. }
  534. }
  535. //---------------------------------------------------------------------------
  536. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  537. {
  538. PrepareNavigationTree(NavigationTree);
  539. switch (PreferencesMode) {
  540. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  541. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  542. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  543. case pmTransfer: PageControl->ActivePage = TransferSheet; break;
  544. case pmLogging: PageControl->ActivePage = LogSheet; break;
  545. case pmUpdates: PageControl->ActivePage = UpdatesSheet; break;
  546. case pmPresets: PageControl->ActivePage = CopyParamListSheet; break;
  547. case pmEditors: PageControl->ActivePage = EditorSheet; break;
  548. default: PageControl->ActivePage = PreferencesSheet; break;
  549. }
  550. PageControlChange(NULL);
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  554. {
  555. UpdateControls();
  556. }
  557. //---------------------------------------------------------------------------
  558. AnsiString __fastcall TPreferencesDialog::TabSample(AnsiString Values)
  559. {
  560. AnsiString Result;
  561. for (int Index = 1; Index <= Values.Length(); Index++)
  562. {
  563. if (Index > 1)
  564. {
  565. Result += ' ';
  566. if (EditorTabSizeEdit->AsInteger > 2)
  567. {
  568. Result += AnsiString::StringOfChar(' ', EditorTabSizeEdit->AsInteger - 2);
  569. }
  570. }
  571. Result += Values[Index];
  572. }
  573. return Result;
  574. }
  575. //---------------------------------------------------------------------------
  576. void __fastcall TPreferencesDialog::UpdateControls()
  577. {
  578. if (FNoUpdate == 0)
  579. {
  580. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  581. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  582. EnableControl(BalloonNotificationsCheck, TTrayIcon::SupportsBalloons());
  583. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  584. EnableControl(ResumeThresholdUnitLabel, ResumeThresholdEdit->Enabled);
  585. EnableControl(SessionReopenAutoEdit, SessionReopenAutoCheck->Checked);
  586. EnableControl(SessionReopenAutoLabel, SessionReopenAutoEdit->Enabled);
  587. EnableControl(SessionReopenAutoSecLabel, SessionReopenAutoEdit->Enabled);
  588. EnableControl(CopyOnDoubleClickConfirmationCheck,
  589. (DoubleClickActionCombo->ItemIndex == 1) && ConfirmTransferringCheck->Checked);
  590. AnsiString EditorFontLabelText;
  591. EditorFontLabelText = FMTLOAD(EDITOR_FONT_FMT,
  592. (FEditorFont->Name, FEditorFont->Size)) + "\n\n";
  593. EditorFontLabelText += TabSample("ABCD") + "\n";
  594. EditorFontLabelText += TabSample("1234");
  595. EditorFontLabel->Caption = EditorFontLabelText;
  596. EditorFontLabel->Font = FEditorFont;
  597. bool CommandSelected = (CustomCommandsView->Selected != NULL);
  598. EnableControl(EditCommandButton, CommandSelected);
  599. EnableControl(RemoveCommandButton, CommandSelected);
  600. EnableControl(UpCommandButton, CommandSelected &&
  601. CustomCommandsView->ItemIndex > 0);
  602. EnableControl(DownCommandButton, CommandSelected &&
  603. (CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1));
  604. bool CopyParamSelected = (CopyParamListView->Selected != NULL);
  605. EnableControl(EditCopyParamButton, CopyParamSelected);
  606. EnableControl(DuplicateCopyParamButton, CopyParamSelected);
  607. EnableControl(RemoveCopyParamButton, CopyParamSelected);
  608. EnableControl(UpCopyParamButton, CopyParamSelected &&
  609. (CopyParamListView->ItemIndex > 0));
  610. EnableControl(DownCopyParamButton, CopyParamSelected &&
  611. (CopyParamListView->ItemIndex < CopyParamListView->Items->Count - 1));
  612. EnableControl(CopyParamAutoSelectNoticeCheck, FCopyParamList->AnyRule);
  613. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  614. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  615. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  616. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  617. DDCustomTemporaryDirectoryButton->Checked);
  618. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  619. DDAllowMoveInitCheck->Checked);
  620. EnableControl(ConfirmTemporaryDirectoryCleanupCheck,
  621. TemporaryDirectoryCleanupCheck->Checked);
  622. IniFileStorageButton2->Caption =
  623. AnsiReplaceStr(IniFileStorageButton2->Caption, "winscp.ini",
  624. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName)));
  625. EditorFontLabel->WordWrap = EditorWordWrapCheck->Checked;
  626. bool EditorSelected = (EditorListView->Selected != NULL);
  627. EnableControl(EditEditorButton, EditorSelected);
  628. EnableControl(RemoveEditorButton, EditorSelected);
  629. EnableControl(UpEditorButton, EditorSelected &&
  630. (EditorListView->ItemIndex > 0));
  631. EnableControl(DownEditorButton, EditorSelected &&
  632. (EditorListView->ItemIndex < EditorListView->Items->Count - 1));
  633. EnableControl(UpdatesProxyHostEdit, UpdatesProxyCheck->Checked);
  634. EnableControl(UpdatesProxyHostLabel, UpdatesProxyHostEdit->Enabled);
  635. EnableControl(UpdatesProxyPortEdit, UpdatesProxyCheck->Checked);
  636. EnableControl(UpdatesProxyPortLabel, UpdatesProxyPortEdit->Enabled);
  637. EnableControl(PuttyPasswordCheck2, !PuttyPathEdit->Text.IsEmpty());
  638. EnableControl(AutoOpenInPuttyCheck, PuttyPasswordCheck2->Enabled);
  639. EnableControl(TelnetForFtpInPuttyCheck, PuttyPasswordCheck2->Enabled);
  640. }
  641. }
  642. //---------------------------------------------------------------------------
  643. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  644. {
  645. if (FontDialog(FEditorFont))
  646. {
  647. UpdateControls();
  648. }
  649. }
  650. //---------------------------------------------------------------------------
  651. void __fastcall TPreferencesDialog::FilenameEditExit(TObject * Sender)
  652. {
  653. // duplicated in TExternalEditorDialog::FilenameEditExit
  654. THistoryComboBox * FilenameEdit = dynamic_cast<THistoryComboBox *>(Sender);
  655. try
  656. {
  657. AnsiString Filename = FilenameEdit->Text;
  658. if (!Filename.IsEmpty())
  659. {
  660. ReformatFileNameCommand(Filename);
  661. FilenameEdit->Text = Filename;
  662. }
  663. ControlChange(Sender);
  664. }
  665. catch(...)
  666. {
  667. FilenameEdit->SelectAll();
  668. FilenameEdit->SetFocus();
  669. throw;
  670. }
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TPreferencesDialog::FilenameEditChange(
  674. TObject * Sender)
  675. {
  676. // duplicated in TExternalEditorDialog::FilenameEditChange
  677. if (FAfterFilenameEditDialog)
  678. {
  679. FAfterFilenameEditDialog = false;
  680. FilenameEditExit(Sender);
  681. }
  682. else
  683. {
  684. ControlChange(Sender);
  685. }
  686. }
  687. //---------------------------------------------------------------------------
  688. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  689. bool & /*CanClose*/)
  690. {
  691. if (ModalResult != mrCancel)
  692. {
  693. ExitActiveControl(this);
  694. }
  695. }
  696. //---------------------------------------------------------------------------
  697. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  698. {
  699. AnsiString IconName, Params;
  700. int SpecialFolder;
  701. if (Sender == DesktopIconButton)
  702. {
  703. IconName = AppNameVersion;
  704. int Result =
  705. MessageDialog(LoadStr(CREATE_DESKTOP_ICON), qtConfirmation,
  706. qaYes | qaNo | qaCancel, HELP_CREATE_ICON);
  707. switch (Result)
  708. {
  709. case qaYes:
  710. SpecialFolder = CSIDL_COMMON_DESKTOPDIRECTORY;
  711. break;
  712. case qaNo:
  713. SpecialFolder = CSIDL_DESKTOPDIRECTORY;
  714. break;
  715. default:
  716. Abort();
  717. break;
  718. }
  719. }
  720. else
  721. {
  722. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  723. qtConfirmation, qaYes | qaNo, HELP_CREATE_ICON) == qaYes)
  724. {
  725. if (Sender == SendToHookButton)
  726. {
  727. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppNameVersion));
  728. SpecialFolder = CSIDL_SENDTO;
  729. Params = "/upload";
  730. }
  731. else if (Sender == QuickLaunchIconButton)
  732. {
  733. IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
  734. AppNameVersion;
  735. SpecialFolder = CSIDL_APPDATA;
  736. }
  737. }
  738. else
  739. {
  740. Abort();
  741. }
  742. }
  743. CreateDesktopShortCut(IconName,
  744. Application->ExeName, Params, "", SpecialFolder);
  745. }
  746. //---------------------------------------------------------------------------
  747. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  748. TListItem * Item)
  749. {
  750. assert(FCustomCommands);
  751. int Index = Item->Index;
  752. assert(Index >= 0 && Index <= FCustomCommands->Count);
  753. Item->Caption = StringReplace(FCustomCommands->Names[Index], "&", "",
  754. TReplaceFlags() << rfReplaceAll);
  755. assert(!Item->SubItems->Count);
  756. AnsiString Name = FCustomCommands->Names[Index];
  757. Item->SubItems->Add(FCustomCommands->Values[Name]);
  758. int Params = FCustomCommands->Params[Name];
  759. Item->SubItems->Add(LoadStr(
  760. FLAGSET(Params, ccLocal) ? CUSTOM_COMMAND_LOCAL : CUSTOM_COMMAND_REMOTE));
  761. AnsiString ParamsStr;
  762. #define ADDPARAM(PARAM, STR) \
  763. if (FLAGSET(Params, PARAM)) \
  764. ParamsStr += (ParamsStr.IsEmpty() ? "" : "/") + LoadStr(STR);
  765. ADDPARAM(ccApplyToDirectories, CUSTOM_COMMAND_DIRECTORIES);
  766. ADDPARAM(ccRecursive, CUSTOM_COMMAND_RECURSE);
  767. #undef ADDPARAM
  768. Item->SubItems->Add(ParamsStr);
  769. }
  770. //---------------------------------------------------------------------------
  771. void __fastcall TPreferencesDialog::ListViewSelectItem(
  772. TObject * /*Sender*/, TListItem * /*Item*/, bool /*Selected*/)
  773. {
  774. UpdateControls();
  775. }
  776. //---------------------------------------------------------------------------
  777. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  778. {
  779. CustomCommandsView->Items->Count = FCustomCommands->Count;
  780. AdjustListColumnsWidth(CustomCommandsView, FCustomCommands->Count);
  781. CustomCommandsView->Invalidate();
  782. }
  783. //---------------------------------------------------------------------------
  784. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  785. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  786. {
  787. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  788. {
  789. RemoveCommandButtonClick(NULL);
  790. }
  791. if (AddCommandButton->Enabled && (Key == VK_INSERT))
  792. {
  793. AddEditCommandButtonClick(AddCommandButton);
  794. }
  795. }
  796. //---------------------------------------------------------------------------
  797. void __fastcall TPreferencesDialog::CustomCommandsViewDblClick(
  798. TObject * /*Sender*/)
  799. {
  800. if (EditCommandButton->Enabled)
  801. {
  802. AddEditCommandButtonClick(EditCommandButton);
  803. }
  804. }
  805. //---------------------------------------------------------------------------
  806. void __fastcall TPreferencesDialog::AddEditCommandButtonClick(TObject * Sender)
  807. {
  808. bool Edit = (Sender == EditCommandButton);
  809. AnsiString Description;
  810. AnsiString Command;
  811. int Params = 0;
  812. if (Edit)
  813. {
  814. int Index = CustomCommandsView->ItemIndex;
  815. assert(Index >= 0 && Index <= FCustomCommands->Count);
  816. Description = FCustomCommands->Names[Index];
  817. Command = FCustomCommands->Values[Description];
  818. Params = FCustomCommands->Params[Description];
  819. }
  820. if (DoCustomCommandDialog(Description, Command, Params, FCustomCommands,
  821. (Edit ? ccmEdit : ccmAdd), 0, NULL))
  822. {
  823. int Index = CustomCommandsView->ItemIndex;
  824. AnsiString Record = FORMAT("%s=%s", (Description, Command));
  825. if (Edit)
  826. {
  827. FCustomCommands->Strings[Index] = Record;
  828. }
  829. else
  830. {
  831. if (Index >= 0)
  832. {
  833. FCustomCommands->Insert(Index, Record);
  834. }
  835. else
  836. {
  837. Index = FCustomCommands->Add(Record);
  838. }
  839. }
  840. FCustomCommands->Params[Description] = Params;
  841. UpdateCustomCommandsView();
  842. CustomCommandsView->ItemIndex = Index;
  843. UpdateControls();
  844. }
  845. }
  846. //---------------------------------------------------------------------------
  847. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  848. TObject * /*Sender*/)
  849. {
  850. assert(CustomCommandsView->ItemIndex >= 0 &&
  851. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  852. FCustomCommands->Delete(CustomCommandsView->ItemIndex);
  853. UpdateCustomCommandsView();
  854. UpdateControls();
  855. }
  856. //---------------------------------------------------------------------------
  857. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  858. {
  859. if (Source >= 0 && Source < FCustomCommands->Count &&
  860. Dest >= 0 && Dest < FCustomCommands->Count)
  861. {
  862. FCustomCommands->Move(Source, Dest);
  863. // workaround for bug in VCL
  864. CustomCommandsView->ItemIndex = -1;
  865. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  866. CustomCommandsView->ItemIndex = Dest;
  867. UpdateCustomCommandsView();
  868. UpdateControls();
  869. }
  870. }
  871. //---------------------------------------------------------------------------
  872. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  873. {
  874. CustomCommandMove(CustomCommandsView->ItemIndex,
  875. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  876. }
  877. //---------------------------------------------------------------------------
  878. TListViewScrollOnDragOver * __fastcall TPreferencesDialog::ScrollOnDragOver(TObject * ListView)
  879. {
  880. if (ListView == CopyParamListView)
  881. {
  882. return FCopyParamScrollOnDragOver;
  883. }
  884. else if (ListView == CustomCommandsView)
  885. {
  886. return FCustomCommandsScrollOnDragOver;
  887. }
  888. else if (ListView == EditorListView)
  889. {
  890. return FEditorScrollOnDragOver;
  891. }
  892. else
  893. {
  894. assert(false);
  895. return NULL;
  896. }
  897. }
  898. //---------------------------------------------------------------------------
  899. void __fastcall TPreferencesDialog::ListViewStartDrag(
  900. TObject * Sender, TDragObject *& /*DragObject*/)
  901. {
  902. FListViewDragSource = dynamic_cast<TListView*>(Sender)->ItemIndex;
  903. FListViewDragDest = -1;
  904. ScrollOnDragOver(Sender)->StartDrag();
  905. }
  906. //---------------------------------------------------------------------------
  907. bool __fastcall TPreferencesDialog::AllowListViewDrag(TObject * Sender, int X, int Y)
  908. {
  909. TListItem * Item = dynamic_cast<TListView*>(Sender)->GetItemAt(X, Y);
  910. FListViewDragDest = Item ? Item->Index : -1;
  911. return (FListViewDragDest >= 0) && (FListViewDragDest != FListViewDragSource);
  912. }
  913. //---------------------------------------------------------------------------
  914. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  915. TObject * Sender, TObject * Source, int X, int Y)
  916. {
  917. if (Source == CustomCommandsView)
  918. {
  919. if (AllowListViewDrag(Sender, X, Y))
  920. {
  921. CustomCommandMove(FListViewDragSource, FListViewDragDest);
  922. }
  923. }
  924. }
  925. //---------------------------------------------------------------------------
  926. void __fastcall TPreferencesDialog::ListViewDragOver(
  927. TObject * Sender, TObject * Source, int X, int Y,
  928. TDragState /*State*/, bool & Accept)
  929. {
  930. if (Source == Sender)
  931. {
  932. // cannot use AllowListViewDrag(X, Y) because of bug in VCL
  933. // (when dropped on item itself, when it was dragged over another item before,
  934. // that another item remains highlighted forever)
  935. Accept = true;
  936. ScrollOnDragOver(Source)->DragOver(TPoint(X, Y));
  937. }
  938. }
  939. //---------------------------------------------------------------------------
  940. void __fastcall TPreferencesDialog::CopyParamMove(int Source, int Dest)
  941. {
  942. if (Source >= 0 && Source < FCopyParamList->Count &&
  943. Dest >= 0 && Dest < FCopyParamList->Count)
  944. {
  945. FCopyParamList->Move(Source, Dest);
  946. // workaround for bug in VCL
  947. CopyParamListView->ItemIndex = -1;
  948. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  949. CopyParamListView->ItemIndex = Dest;
  950. UpdateCopyParamListView();
  951. UpdateControls();
  952. }
  953. }
  954. //---------------------------------------------------------------------------
  955. void __fastcall TPreferencesDialog::CopyParamListViewDragDrop(
  956. TObject * Sender, TObject * Source, int X, int Y)
  957. {
  958. if (Source == CopyParamListView)
  959. {
  960. if (AllowListViewDrag(Sender, X, Y))
  961. {
  962. CopyParamMove(FListViewDragSource, FListViewDragDest);
  963. }
  964. }
  965. }
  966. //---------------------------------------------------------------------------
  967. void __fastcall TPreferencesDialog::UpDownCopyParamButtonClick(TObject * Sender)
  968. {
  969. CopyParamMove(CopyParamListView->ItemIndex,
  970. CopyParamListView->ItemIndex + (Sender == UpCopyParamButton ? -1 : 1));
  971. }
  972. //---------------------------------------------------------------------------
  973. void __fastcall TPreferencesDialog::RemoveCopyParamButtonClick(
  974. TObject * /*Sender*/)
  975. {
  976. assert(CopyParamListView->ItemIndex >= 0 &&
  977. CopyParamListView->ItemIndex < FCopyParamList->Count);
  978. FCopyParamList->Delete(CopyParamListView->ItemIndex);
  979. UpdateCopyParamListView();
  980. UpdateControls();
  981. }
  982. //---------------------------------------------------------------------------
  983. void __fastcall TPreferencesDialog::AddEditCopyParamButtonClick(
  984. TObject * Sender)
  985. {
  986. TCopyParamPresetMode Mode;
  987. if (Sender == EditCopyParamButton)
  988. {
  989. Mode = cpmEdit;
  990. }
  991. else if (Sender == DuplicateCopyParamButton)
  992. {
  993. Mode = cpmDuplicate;
  994. }
  995. else
  996. {
  997. Mode = cpmAdd;
  998. }
  999. int Index = CopyParamListView->ItemIndex;
  1000. TCopyParamRuleData * CopyParamRuleData =
  1001. (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
  1002. if (DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData))
  1003. {
  1004. UpdateCopyParamListView();
  1005. CopyParamListView->ItemIndex = Index;
  1006. // when using duplicate button, focu remains on original item
  1007. CopyParamListView->ItemFocused = CopyParamListView->Selected;
  1008. UpdateControls();
  1009. }
  1010. }
  1011. //---------------------------------------------------------------------------
  1012. void __fastcall TPreferencesDialog::CopyParamListViewDblClick(
  1013. TObject * /*Sender*/)
  1014. {
  1015. if (EditCopyParamButton->Enabled)
  1016. {
  1017. AddEditCopyParamButtonClick(EditCopyParamButton);
  1018. }
  1019. }
  1020. //---------------------------------------------------------------------------
  1021. void __fastcall TPreferencesDialog::CopyParamListViewKeyDown(
  1022. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  1023. {
  1024. if (RemoveCopyParamButton->Enabled && (Key == VK_DELETE))
  1025. {
  1026. RemoveCopyParamButtonClick(NULL);
  1027. }
  1028. if (AddCopyParamButton->Enabled && (Key == VK_INSERT))
  1029. {
  1030. AddEditCopyParamButtonClick(AddCopyParamButton);
  1031. }
  1032. }
  1033. //---------------------------------------------------------------------------
  1034. void __fastcall TPreferencesDialog::EditorMove(int Source, int Dest)
  1035. {
  1036. if (Source >= 0 && Source < FEditorList->Count &&
  1037. Dest >= 0 && Dest < FEditorList->Count)
  1038. {
  1039. FEditorList->Move(Source, Dest);
  1040. // workaround for bug in VCL
  1041. EditorListView->ItemIndex = -1;
  1042. EditorListView->ItemFocused = EditorListView->Selected;
  1043. EditorListView->ItemIndex = Dest;
  1044. UpdateEditorListView();
  1045. UpdateControls();
  1046. }
  1047. }
  1048. //---------------------------------------------------------------------------
  1049. void __fastcall TPreferencesDialog::EditorListViewDragDrop(TObject * Sender,
  1050. TObject * Source, int X, int Y)
  1051. {
  1052. if (Source == EditorListView)
  1053. {
  1054. if (AllowListViewDrag(Sender, X, Y))
  1055. {
  1056. EditorMove(FListViewDragSource, FListViewDragDest);
  1057. }
  1058. }
  1059. }
  1060. //---------------------------------------------------------------------------
  1061. void __fastcall TPreferencesDialog::UpDownEditorButtonClick(TObject *Sender)
  1062. {
  1063. EditorMove(EditorListView->ItemIndex,
  1064. EditorListView->ItemIndex + (Sender == UpEditorButton ? -1 : 1));
  1065. }
  1066. //---------------------------------------------------------------------------
  1067. void __fastcall TPreferencesDialog::RemoveEditorButtonClick(
  1068. TObject * /*Sender*/)
  1069. {
  1070. assert(EditorListView->ItemIndex >= 0 &&
  1071. EditorListView->ItemIndex < FEditorList->Count);
  1072. FEditorList->Delete(EditorListView->ItemIndex);
  1073. UpdateEditorListView();
  1074. UpdateControls();
  1075. }
  1076. //---------------------------------------------------------------------------
  1077. void __fastcall TPreferencesDialog::AddEditEditorButtonClick(TObject * Sender)
  1078. {
  1079. TEditorPreferencesMode Mode = (Sender == EditEditorButton ? epmEdit : epmAdd);
  1080. int Index = EditorListView->ItemIndex;
  1081. TEditorPreferences * Editor;
  1082. if (Mode == epmEdit)
  1083. {
  1084. Editor = new TEditorPreferences(*FEditorList->Editors[Index]);
  1085. }
  1086. else
  1087. {
  1088. Editor = new TEditorPreferences();
  1089. }
  1090. try
  1091. {
  1092. if (DoEditorPreferencesDialog(Editor, Mode))
  1093. {
  1094. if (Mode == epmEdit)
  1095. {
  1096. FEditorList->Change(Index, Editor);
  1097. }
  1098. else
  1099. {
  1100. if (Index < 0)
  1101. {
  1102. Index = FEditorList->Count;
  1103. FEditorList->Add(Editor);
  1104. }
  1105. else
  1106. {
  1107. FEditorList->Insert(Index, Editor);
  1108. }
  1109. }
  1110. // ownership of the object lost
  1111. Editor = NULL;
  1112. UpdateEditorListView();
  1113. EditorListView->ItemIndex = Index;
  1114. UpdateControls();
  1115. }
  1116. }
  1117. __finally
  1118. {
  1119. delete Editor;
  1120. }
  1121. }
  1122. //---------------------------------------------------------------------------
  1123. void __fastcall TPreferencesDialog::EditorListViewDblClick(TObject * /*Sender*/)
  1124. {
  1125. if (EditEditorButton->Enabled)
  1126. {
  1127. AddEditEditorButtonClick(EditEditorButton);
  1128. }
  1129. }
  1130. //---------------------------------------------------------------------------
  1131. void __fastcall TPreferencesDialog::EditorListViewKeyDown(TObject * /*Sender*/,
  1132. WORD & Key, TShiftState /*Shift*/)
  1133. {
  1134. if (RemoveEditorButton->Enabled && (Key == VK_DELETE))
  1135. {
  1136. RemoveEditorButtonClick(NULL);
  1137. }
  1138. if (AddEditorButton->Enabled && (Key == VK_INSERT))
  1139. {
  1140. AddEditEditorButtonClick(AddEditorButton);
  1141. }
  1142. }
  1143. //---------------------------------------------------------------------------
  1144. void __fastcall TPreferencesDialog::UpdateEditorListView()
  1145. {
  1146. EditorListView->Items->Count = FEditorList->Count;
  1147. AdjustListColumnsWidth(EditorListView, FEditorList->Count);
  1148. EditorListView->Invalidate();
  1149. }
  1150. //---------------------------------------------------------------------------
  1151. void __fastcall TPreferencesDialog::EditorListViewData(TObject * /*Sender*/,
  1152. TListItem * Item)
  1153. {
  1154. int Index = Item->Index;
  1155. assert(Index >= 0 && Index <= FEditorList->Count);
  1156. const TEditorPreferences * Editor = FEditorList->Editors[Index];
  1157. Item->Caption = Editor->Data.FileMask.Masks;
  1158. Item->SubItems->Add(Editor->Name);
  1159. if (Editor->Data.Editor == edExternal)
  1160. {
  1161. Item->SubItems->Add(BooleanToStr(Editor->Data.MDIExternalEditor));
  1162. Item->SubItems->Add(BooleanToStr(Editor->Data.ExternalEditorText));
  1163. }
  1164. }
  1165. //---------------------------------------------------------------------------
  1166. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  1167. TTreeNode *Node)
  1168. {
  1169. if (Node->SelectedIndex)
  1170. {
  1171. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  1172. {
  1173. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  1174. {
  1175. PageControl->ActivePage = PageControl->Pages[Index];
  1176. // reshow the accelerators, etc
  1177. ResetSystemSettings(this);
  1178. return;
  1179. }
  1180. }
  1181. }
  1182. assert(false);
  1183. }
  1184. //---------------------------------------------------------------------------
  1185. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  1186. {
  1187. bool Found = false;
  1188. if (PageControl->ActivePage->Tag)
  1189. {
  1190. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  1191. {
  1192. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  1193. PageControl->ActivePage->Tag)
  1194. {
  1195. NavigationTree->Items->Item[Index]->Selected = true;
  1196. Found = true;
  1197. }
  1198. }
  1199. }
  1200. assert(Found);
  1201. if (Found)
  1202. {
  1203. UpdateControls();
  1204. }
  1205. }
  1206. //---------------------------------------------------------------------------
  1207. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  1208. {
  1209. if (Message.CharCode == VK_TAB)
  1210. {
  1211. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  1212. if (Shift.Contains(ssCtrl))
  1213. {
  1214. TTreeNode * Node = NavigationTree->Selected;
  1215. if (!Shift.Contains(ssShift))
  1216. {
  1217. Node = Node->GetNext();
  1218. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  1219. }
  1220. else
  1221. {
  1222. if (Node->GetPrev()) Node = Node->GetPrev();
  1223. else
  1224. while (Node->GetNext()) Node = Node->GetNext();
  1225. }
  1226. Node->Selected = True;
  1227. Message.Result = 1;
  1228. return;
  1229. }
  1230. }
  1231. TForm::Dispatch(&Message);
  1232. }
  1233. //---------------------------------------------------------------------------
  1234. void __fastcall TPreferencesDialog::WMHelp(TWMHelp & Message)
  1235. {
  1236. assert(Message.HelpInfo != NULL);
  1237. if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
  1238. {
  1239. // invoke help for active page (not for whole form), regardless of focus
  1240. // (e.g. even if focus is on control outside pagecontrol)
  1241. Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
  1242. }
  1243. TForm::Dispatch(&Message);
  1244. }
  1245. //---------------------------------------------------------------------------
  1246. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  1247. {
  1248. TMessage * M = reinterpret_cast<TMessage*>(Message);
  1249. assert(M);
  1250. if (M->Msg == CM_DIALOGKEY)
  1251. {
  1252. CMDialogKey(*((TWMKeyDown *)Message));
  1253. }
  1254. else if (M->Msg == WM_HELP)
  1255. {
  1256. WMHelp(*((TWMHelp *)Message));
  1257. }
  1258. else
  1259. {
  1260. TForm::Dispatch(Message);
  1261. }
  1262. }
  1263. //---------------------------------------------------------------------------
  1264. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  1265. TObject * /*Sender*/)
  1266. {
  1267. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  1268. qtConfirmation, qaYes | qaNo, HELP_REGISTER_URL) == qaYes)
  1269. {
  1270. RegisterAsUrlHandler();
  1271. }
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  1275. {
  1276. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  1277. SetFocus();
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. void __fastcall TPreferencesDialog::AddSearchPathButtonClick(
  1281. TObject * /*Sender*/)
  1282. {
  1283. AnsiString AppPath = ExtractFilePath(Application->ExeName);
  1284. if (MessageDialog(FMTLOAD(CONFIRM_ADD_SEARCH_PATH, (AppPath)),
  1285. qtConfirmation, qaYes | qaNo, HELP_ADD_SEARCH_PATH) == qaYes)
  1286. {
  1287. AddSearchPath(AppPath);
  1288. }
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TPreferencesDialog::EditorFontLabelDblClick(
  1292. TObject * Sender)
  1293. {
  1294. EditorFontButtonClick(Sender);
  1295. }
  1296. //---------------------------------------------------------------------------
  1297. void __fastcall TPreferencesDialog::UpdateCopyParamListView()
  1298. {
  1299. CopyParamListView->Items->Count = FCopyParamList->Count;
  1300. AdjustListColumnsWidth(CopyParamListView, FCopyParamList->Count);
  1301. CopyParamListView->Invalidate();
  1302. }
  1303. //---------------------------------------------------------------------------
  1304. void __fastcall TPreferencesDialog::CopyParamListViewData(TObject * /*Sender*/,
  1305. TListItem * Item)
  1306. {
  1307. int Index = Item->Index;
  1308. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1309. Item->Caption = StringReplace(FCopyParamList->Names[Index], "&", "",
  1310. TReplaceFlags() << rfReplaceAll);
  1311. Item->SubItems->Add(BooleanToStr(FCopyParamList->Rules[Index] != NULL));
  1312. }
  1313. //---------------------------------------------------------------------------
  1314. void __fastcall TPreferencesDialog::CopyParamListViewInfoTip(
  1315. TObject * /*Sender*/, TListItem * Item, AnsiString & InfoTip)
  1316. {
  1317. int Index = Item->Index;
  1318. assert(Index >= 0 && Index <= FCopyParamList->Count);
  1319. const TCopyParamType * CopyParam = FCopyParamList->CopyParams[Index];
  1320. const TCopyParamRule * Rule = FCopyParamList->Rules[Index];
  1321. InfoTip = CopyParam->GetInfoStr("; ", 0);
  1322. if (Rule != NULL)
  1323. {
  1324. InfoTip += "\n-\n" + Rule->GetInfoStr("; ");
  1325. }
  1326. }
  1327. //---------------------------------------------------------------------------
  1328. void __fastcall TPreferencesDialog::HelpButtonClick(TObject * /*Sender*/)
  1329. {
  1330. FormHelp(this);
  1331. }
  1332. //---------------------------------------------------------------------------
  1333. void __fastcall TPreferencesDialog::PuttyPathBrowseButtonClick(
  1334. TObject * /*Sender*/)
  1335. {
  1336. BrowseForExecutable(PuttyPathEdit, LoadStr(PREFERENCES_SELECT_PUTTY),
  1337. LoadStr(PREFERENCES_PUTTY_FILTER), false, false);
  1338. }
  1339. //---------------------------------------------------------------------------
  1340. void __fastcall TPreferencesDialog::PuttyPathResetButtonClick(
  1341. TObject * /*Sender*/)
  1342. {
  1343. PuttyPathEdit->Text = WinConfiguration->DefaultPuttyPath;
  1344. }
  1345. //---------------------------------------------------------------------------
  1346. void __fastcall TPreferencesDialog::ExportButtonClick(TObject * /*Sender*/)
  1347. {
  1348. AnsiString PersonalDirectory;
  1349. ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
  1350. AnsiString FileName = IncludeTrailingBackslash(PersonalDirectory) +
  1351. ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
  1352. if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), "ini", FileName))
  1353. {
  1354. Configuration->Export(FileName);
  1355. }
  1356. }
  1357. //---------------------------------------------------------------------------
  1358. void __fastcall TPreferencesDialog::PathEditBeforeDialog(
  1359. TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
  1360. {
  1361. FBeforeDialogPath = Name;
  1362. Name = ExpandEnvironmentVariables(Name);
  1363. }
  1364. //---------------------------------------------------------------------------
  1365. void __fastcall TPreferencesDialog::PathEditAfterDialog(
  1366. TObject * /*Sender*/, AnsiString & Name, bool & /*Action*/)
  1367. {
  1368. if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
  1369. {
  1370. Name = FBeforeDialogPath;
  1371. }
  1372. }
  1373. //---------------------------------------------------------------------------
  1374. void __fastcall TPreferencesDialog::NavigationTreeCollapsing(
  1375. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
  1376. {
  1377. AllowCollapse = false;
  1378. }
  1379. //---------------------------------------------------------------------------
  1380. void __fastcall TPreferencesDialog::ListViewEndDrag(
  1381. TObject * Sender, TObject * /*Target*/, int /*X*/, int /*Y*/)
  1382. {
  1383. ScrollOnDragOver(Sender)->EndDrag();
  1384. }
  1385. //---------------------------------------------------------------------------
  1386. void __fastcall TPreferencesDialog::RandomSeedFileEditCreateEditDialog(
  1387. TObject * Sender, TFileDialogKind DialogKind, TOpenDialog *& Dialog)
  1388. {
  1389. USEDPARAM(DialogKind);
  1390. assert(DialogKind == dkOpen);
  1391. Dialog = CreateOpenDialog(dynamic_cast<TComponent *>(Sender));
  1392. }
  1393. //---------------------------------------------------------------------------