Preferences.cpp 50 KB

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