Preferences.cpp 44 KB

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