Preferences.cpp 46 KB

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