Preferences.cpp 43 KB

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