Preferences.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "Preferences.h"
  6. #include <ScpMain.h>
  7. #include <Terminal.h>
  8. #include "VCLCommon.h"
  9. #include "GUITools.h"
  10. #include "Tools.h"
  11. #include "TextsWin.h"
  12. #include "WinInterface.h"
  13. #include "WinConfiguration.h"
  14. //---------------------------------------------------------------------
  15. #pragma link "GeneralSettings"
  16. #pragma link "LogSettings"
  17. #pragma link "XPGroupBox"
  18. #pragma link "CopyParams"
  19. #pragma link "UpDownEdit"
  20. #pragma link "IEComboBox"
  21. #pragma resource "*.dfm"
  22. //---------------------------------------------------------------------
  23. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode)
  24. {
  25. bool Result;
  26. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
  27. try
  28. {
  29. PreferencesDialog->PreferencesMode = APreferencesMode;
  30. Result = PreferencesDialog->Execute();
  31. }
  32. __finally
  33. {
  34. delete PreferencesDialog;
  35. }
  36. return Result;
  37. }
  38. //---------------------------------------------------------------------
  39. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  40. : TForm(AOwner)
  41. {
  42. FPreferencesMode = pmDefault;
  43. LoggingFrame->OnGetDefaultLogFileName = LoggingGetDefaultLogFileName;
  44. CopyParamsFrame->Direction = pdAll;
  45. FEditorFont = new TFont();
  46. FAfterExternalEditorDialog = false;
  47. FCustomCommands = new TCustomCommands();
  48. FCustomCommandChanging = false;
  49. FCustomCommandDragDest = -1;
  50. UseSystemSettings(this);
  51. }
  52. //---------------------------------------------------------------------------
  53. __fastcall TPreferencesDialog::~TPreferencesDialog()
  54. {
  55. LoggingFrame->OnGetDefaultLogFileName = NULL;
  56. delete FEditorFont;
  57. delete FCustomCommands;
  58. }
  59. //---------------------------------------------------------------------
  60. bool __fastcall TPreferencesDialog::Execute()
  61. {
  62. LoadConfiguration();
  63. CopyParamsFrame->BeforeExecute();
  64. bool Result = (ShowModal() == mrOk);
  65. if (Result)
  66. {
  67. CopyParamsFrame->AfterExecute();
  68. SaveConfiguration();
  69. }
  70. return Result;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TPreferencesDialog::PrepareNavigationTree(TTreeView * Tree)
  74. {
  75. Tree->FullExpand();
  76. int i = 0;
  77. while (i < Tree->Items->Count)
  78. {
  79. if ((!WinConfiguration->ExpertMode &&
  80. Tree->Items->Item[i]->SelectedIndex & 128))
  81. {
  82. Tree->Items->Delete(Tree->Items->Item[i]);
  83. }
  84. else
  85. {
  86. for (int pi = 0; pi < PageControl->PageCount; pi++)
  87. {
  88. if (PageControl->Pages[pi]->Tag == (Tree->Items->Item[i]->SelectedIndex & 127))
  89. {
  90. if (PageControl->Pages[pi]->Enabled)
  91. {
  92. Tree->Items->Item[i]->Text = PageControl->Pages[pi]->Hint;
  93. }
  94. else
  95. {
  96. Tree->Items->Delete(Tree->Items->Item[i]);
  97. i--;
  98. }
  99. break;
  100. }
  101. }
  102. i++;
  103. }
  104. }
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TPreferencesDialog::LoggingGetDefaultLogFileName(
  108. TObject * /*Sender*/, AnsiString & DefaultLogFileName)
  109. {
  110. DefaultLogFileName = "";
  111. }
  112. //---------------------------------------------------------------------------
  113. void __fastcall TPreferencesDialog::LoadConfiguration()
  114. {
  115. if (FPreferencesMode != pmLogin)
  116. {
  117. LoggingFrame->LoadConfiguration();
  118. GeneralSettingsFrame->LoadConfiguration();
  119. }
  120. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  121. BOOLPROP(DefaultDirIsHome);
  122. BOOLPROP(DeleteToRecycleBin);
  123. BOOLPROP(DDTransferConfirmation);
  124. BOOLPROP(DDWarnLackOfTempSpace);
  125. BOOLPROP(ShowHiddenFiles);
  126. BOOLPROP(ShowInaccesibleDirectories);
  127. BOOLPROP(CopyOnDoubleClick);
  128. BOOLPROP(CopyOnDoubleClickConfirmation);
  129. BOOLPROP(ConfirmOverwriting);
  130. BOOLPROP(ConfirmResume);
  131. BOOLPROP(ConfirmDeleting);
  132. BOOLPROP(ConfirmClosingSession);
  133. BOOLPROP(ConfirmExitOnCompletion);
  134. BOOLPROP(UseLocationProfiles);
  135. BOOLPROP(ConfirmCommandSession);
  136. BOOLPROP(ContinueOnError);
  137. BOOLPROP(DDAllowMoveInit);
  138. BOOLPROP(BeepOnFinish);
  139. #undef BOOLPROP
  140. BeepOnFinishAfterEdit->AsInteger =
  141. static_cast<double>(GUIConfiguration->BeepOnFinishAfter) * (24*60*60);
  142. CompareByTimeCheck->Checked = WinConfiguration->ScpCommander.CompareByTime;
  143. CompareBySizeCheck->Checked = WinConfiguration->ScpCommander.CompareBySize;
  144. DDExtEnabledButton->Checked = WinConfiguration->DDExtEnabled;
  145. DDExtDisabledButton->Checked = !DDExtEnabledButton->Checked;
  146. DDWarnOnMoveCheck->Checked = !WinConfiguration->DDAllowMove;
  147. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  148. {
  149. DDSystemTemporaryDirectoryButton->Checked = true;
  150. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  151. }
  152. else
  153. {
  154. DDCustomTemporaryDirectoryButton->Checked = true;
  155. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  156. }
  157. ExplorerStyleSelectionCheck->Checked =
  158. WinConfiguration->ScpCommander.ExplorerStyleSelection;
  159. PreserveLocalDirectoryCheck->Checked =
  160. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  161. ShowFullAddressCheck->Checked =
  162. WinConfiguration->ScpExplorer.ShowFullAddress;
  163. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  164. IniFileStorageButton->Checked = (Configuration->Storage == stIniFile);
  165. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  166. // editor
  167. EditorSingleEditorOnCheck->Checked = WinConfiguration->Editor.SingleEditor;
  168. EditorSingleEditorOffCheck->Checked = !WinConfiguration->Editor.SingleEditor;
  169. EditorInternalButton->Checked = WinConfiguration->Editor.Editor == edInternal;
  170. EditorExternalButton->Checked = WinConfiguration->Editor.Editor == edExternal;
  171. AnsiString ExternalEditor = WinConfiguration->Editor.ExternalEditor;
  172. if (!ExternalEditor.IsEmpty())
  173. {
  174. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  175. }
  176. ExternalEditorEdit->Text = ExternalEditor;
  177. ExternalEditorTextCheck->Checked = WinConfiguration->Editor.ExternalEditorText;
  178. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  179. FEditorFont->Name = WinConfiguration->Editor.FontName;
  180. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  181. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  182. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  183. CopyParamsFrame->Params = GUIConfiguration->CopyParam;
  184. ResumeOnButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsOn;
  185. ResumeSmartButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsSmart;
  186. ResumeOffButton->Checked = GUIConfiguration->CopyParam.ResumeSupport == rsOff;
  187. ResumeThresholdEdit->Value = GUIConfiguration->CopyParam.ResumeThreshold / 1024;
  188. TransferSheet->Enabled = WinConfiguration->ExpertMode;
  189. GeneralSheet->Enabled = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  190. ExplorerSheet->Enabled = WinConfiguration->ExpertMode;
  191. CommanderSheet->Enabled = WinConfiguration->ExpertMode;
  192. GeneralSheet->Enabled = (PreferencesMode != pmLogin);
  193. EditorSheet->Enabled = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  194. StorageGroup->Visible = WinConfiguration->ExpertMode;
  195. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  196. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  197. FCustomCommands->Assign(WinConfiguration->CustomCommands);
  198. CustomCommandDescEdit->Text = "";
  199. CustomCommandEdit->Text = "";
  200. UpdateCustomCommandsView();
  201. PuttyPathEdit->FileName = WinConfiguration->PuttyPath;
  202. // Queue
  203. QueueTransferLimitEdit->AsInteger = GUIConfiguration->QueueTransfersLimit;
  204. QueueAutoPopupCheck->Checked = GUIConfiguration->QueueAutoPopup;
  205. QueueCheck->Checked = GUIConfiguration->CopyParam.Queue;
  206. RememberPasswordCheck->Checked = Configuration->RememberPassword;
  207. if (WinConfiguration->QueueView.Show == qvShow)
  208. {
  209. QueueViewShowButton->Checked = true;
  210. }
  211. else if (WinConfiguration->QueueView.Show == qvHideWhenEmpty)
  212. {
  213. QueueViewHideWhenEmptyButton->Checked = true;
  214. }
  215. else
  216. {
  217. QueueViewHideButton->Checked = true;
  218. }
  219. UpdateControls();
  220. }
  221. //---------------------------------------------------------------------------
  222. void __fastcall TPreferencesDialog::SaveConfiguration()
  223. {
  224. Configuration->BeginUpdate();
  225. try
  226. {
  227. TGUICopyParamType CopyParam = GUIConfiguration->CopyParam;
  228. if (FPreferencesMode != pmLogin)
  229. {
  230. LoggingFrame->SaveConfiguration();
  231. GeneralSettingsFrame->SaveConfiguration();
  232. }
  233. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  234. BOOLPROP(DefaultDirIsHome);
  235. BOOLPROP(DeleteToRecycleBin);
  236. BOOLPROP(DDTransferConfirmation);
  237. BOOLPROP(DDWarnLackOfTempSpace);
  238. BOOLPROP(ShowHiddenFiles);
  239. BOOLPROP(ShowInaccesibleDirectories);
  240. BOOLPROP(CopyOnDoubleClick);
  241. BOOLPROP(CopyOnDoubleClickConfirmation);
  242. BOOLPROP(ConfirmOverwriting);
  243. BOOLPROP(ConfirmResume);
  244. BOOLPROP(ConfirmDeleting);
  245. BOOLPROP(ConfirmClosingSession);
  246. BOOLPROP(ConfirmExitOnCompletion);
  247. BOOLPROP(UseLocationProfiles);
  248. BOOLPROP(ConfirmCommandSession);
  249. BOOLPROP(ContinueOnError);
  250. BOOLPROP(DDAllowMoveInit);
  251. BOOLPROP(BeepOnFinish);
  252. #undef BOOLPROP
  253. GUIConfiguration->BeepOnFinishAfter =
  254. static_cast<double>(BeepOnFinishAfterEdit->Value / (24*60*60));
  255. WinConfiguration->ScpCommander.CompareByTime = CompareByTimeCheck->Checked;
  256. WinConfiguration->ScpCommander.CompareBySize = CompareBySizeCheck->Checked;
  257. WinConfiguration->DDAllowMove = !DDWarnOnMoveCheck->Checked;
  258. WinConfiguration->DDExtEnabled = DDExtEnabledButton->Checked;
  259. if (DDSystemTemporaryDirectoryButton->Checked)
  260. {
  261. WinConfiguration->DDTemporaryDirectory = "";
  262. }
  263. else
  264. {
  265. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  266. }
  267. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  268. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  269. ScpCommander.ExplorerStyleSelection = ExplorerStyleSelectionCheck->Checked;
  270. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  271. WinConfiguration->ScpCommander = ScpCommander;
  272. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  273. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  274. WinConfiguration->ScpExplorer = ScpExplorer;
  275. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  276. // editor
  277. WinConfiguration->Editor.SingleEditor = EditorSingleEditorOnCheck->Checked;
  278. WinConfiguration->Editor.Editor =
  279. (EditorInternalButton->Checked || ExternalEditorEdit->Text.IsEmpty()) ?
  280. edInternal : edExternal;
  281. WinConfiguration->Editor.ExternalEditor = ExternalEditorEdit->Text;
  282. WinConfiguration->Editor.ExternalEditorText = ExternalEditorTextCheck->Checked;
  283. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  284. WinConfiguration->Editor.FontName = FEditorFont->Name;
  285. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  286. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  287. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  288. // overwrites only TCopyParamType fields
  289. CopyParam = CopyParamsFrame->Params;
  290. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  291. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  292. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  293. CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
  294. WinConfiguration->CustomCommands = FCustomCommands;
  295. WinConfiguration->PuttyPath = PuttyPathEdit->FileName;
  296. // Queue
  297. GUIConfiguration->QueueTransfersLimit = QueueTransferLimitEdit->AsInteger;
  298. GUIConfiguration->QueueAutoPopup = QueueAutoPopupCheck->Checked;
  299. CopyParam.Queue = QueueCheck->Checked;
  300. Configuration->RememberPassword = RememberPasswordCheck->Checked;
  301. if (QueueViewShowButton->Checked)
  302. {
  303. WinConfiguration->QueueView.Show = qvShow;
  304. }
  305. else if (QueueViewHideWhenEmptyButton->Checked)
  306. {
  307. WinConfiguration->QueueView.Show = qvHideWhenEmpty;
  308. }
  309. else
  310. {
  311. WinConfiguration->QueueView.Show = qvHide;
  312. }
  313. GUIConfiguration->CopyParam = CopyParam;
  314. }
  315. __finally
  316. {
  317. Configuration->EndUpdate();
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  322. {
  323. if (PreferencesMode != value)
  324. {
  325. FPreferencesMode = value;
  326. GeneralSheet->Enabled = (value != pmLogin);
  327. LogSheet->Enabled = (value != pmLogin);
  328. }
  329. }
  330. //---------------------------------------------------------------------------
  331. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  332. {
  333. PrepareNavigationTree(NavigationTree);
  334. for (int Index = 0; Index < PageControl->PageCount; Index++)
  335. {
  336. PageControl->Pages[Index]->TabVisible = false;
  337. }
  338. // change form height by height of hidden tabs
  339. ClientHeight -= 50;
  340. switch (PreferencesMode) {
  341. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  342. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  343. case pmQueue: PageControl->ActivePage = QueueSheet; break;
  344. case pmTransfer: PageControl->ActivePage = TransferSheet; break;
  345. default: PageControl->ActivePage = PreferencesSheet; break;
  346. }
  347. PageControlChange(NULL);
  348. }
  349. //---------------------------------------------------------------------------
  350. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  351. {
  352. UpdateControls();
  353. }
  354. //---------------------------------------------------------------------------
  355. void __fastcall TPreferencesDialog::UpdateControls()
  356. {
  357. EnableControl(CopyOnDoubleClickConfirmationCheck, CopyOnDoubleClickCheck->Checked);
  358. EnableControl(BeepOnFinishAfterEdit, BeepOnFinishCheck->Checked);
  359. EnableControl(BeepOnFinishAfterText, BeepOnFinishCheck->Checked);
  360. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  361. EditorFontLabel->Caption = FMTLOAD(EDITOR_FONT_FMT,
  362. (FEditorFont->Name, FEditorFont->Size));
  363. bool CommandComplete = !CustomCommandDescEdit->Text.IsEmpty() &&
  364. !CustomCommandEdit->Text.IsEmpty();
  365. EnableControl(AddCommandButton, CommandComplete);
  366. EnableControl(SaveCommandButton, CommandComplete &&
  367. CustomCommandsView->Selected &&
  368. (CustomCommandDescEdit->Text != FCustomCommands->Names[CustomCommandsView->ItemIndex] ||
  369. CustomCommandEdit->Text != FCustomCommands->Values[
  370. FCustomCommands->Names[CustomCommandsView->ItemIndex]] ||
  371. CustomCommandParams() != FCustomCommands->Params[
  372. FCustomCommands->Names[CustomCommandsView->ItemIndex]]));
  373. EnableControl(RemoveCommandButton, CustomCommandsView->Selected);
  374. EnableControl(UpCommandButton, CustomCommandsView->ItemIndex > 0);
  375. EnableControl(DownCommandButton, CustomCommandsView->ItemIndex >= 0 &&
  376. CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1);
  377. EnableControl(DDExtEnabledButton, WinConfiguration->DDExtInstalled);
  378. EnableControl(DDExtEnabledLabel, WinConfiguration->DDExtInstalled);
  379. EnableControl(DDExtDisabledPanel, DDExtDisabledButton->Checked);
  380. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Enabled &&
  381. DDCustomTemporaryDirectoryButton->Checked);
  382. EnableControl(DDWarnOnMoveCheck, DDExtDisabledButton->Checked &&
  383. DDAllowMoveInitCheck->Checked);
  384. }
  385. //---------------------------------------------------------------------------
  386. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  387. {
  388. TFontDialog * Dialog = new TFontDialog(Application);
  389. try
  390. {
  391. Dialog->Device = fdScreen;
  392. Dialog->Options = TFontDialogOptions() << fdForceFontExist;
  393. Dialog->Font = FEditorFont;
  394. if (Dialog->Execute())
  395. {
  396. FEditorFont->Assign(Dialog->Font);
  397. UpdateControls();
  398. }
  399. }
  400. __finally
  401. {
  402. delete Dialog;
  403. }
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TPreferencesDialog::ExternalEditorEditExit(TObject * /*Sender*/)
  407. {
  408. try
  409. {
  410. AnsiString ExternalEditor = ExternalEditorEdit->Text;
  411. if (!ExternalEditor.IsEmpty())
  412. {
  413. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  414. ExternalEditorEdit->Text = ExternalEditor;
  415. }
  416. }
  417. catch(...)
  418. {
  419. ExternalEditorEdit->SelectAll();
  420. ExternalEditorEdit->SetFocus();
  421. throw;
  422. }
  423. }
  424. //---------------------------------------------------------------------------
  425. void __fastcall TPreferencesDialog::ExternalEditorEditAfterDialog(
  426. TObject * /*Sender*/, AnsiString & /*Name*/, bool & Action)
  427. {
  428. if (Action)
  429. {
  430. FAfterExternalEditorDialog = true;
  431. }
  432. }
  433. //---------------------------------------------------------------------------
  434. void __fastcall TPreferencesDialog::ExternalEditorEditChange(
  435. TObject *Sender)
  436. {
  437. if (FAfterExternalEditorDialog)
  438. {
  439. FAfterExternalEditorDialog = false;
  440. ExternalEditorEditExit(Sender);
  441. }
  442. }
  443. //---------------------------------------------------------------------------
  444. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  445. bool & /*CanClose*/)
  446. {
  447. if (ModalResult != mrCancel)
  448. {
  449. if (ExternalEditorEdit->Focused())
  450. {
  451. ExternalEditorEditExit(NULL);
  452. }
  453. CopyParamsFrame->Validate();
  454. }
  455. }
  456. //---------------------------------------------------------------------------
  457. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  458. {
  459. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  460. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  461. {
  462. AnsiString IconName, Params;
  463. int SpecialFolder;
  464. if (Sender == SendToHookButton)
  465. {
  466. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppNameVersion));
  467. SpecialFolder = CSIDL_SENDTO;
  468. Params = "/upload";
  469. }
  470. else if (Sender == QuickLaunchIconButton)
  471. {
  472. IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
  473. AppNameVersion;
  474. SpecialFolder = CSIDL_APPDATA;
  475. }
  476. else
  477. {
  478. IconName = AppNameVersion;
  479. SpecialFolder = Sender == DesktopIconButton ?
  480. CSIDL_DESKTOPDIRECTORY :CSIDL_COMMON_DESKTOPDIRECTORY;
  481. }
  482. CreateDesktopShortCut(IconName,
  483. Application->ExeName, Params, "", SpecialFolder);
  484. }
  485. }
  486. //---------------------------------------------------------------------------
  487. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  488. TListItem * Item)
  489. {
  490. assert(FCustomCommands);
  491. int Index = Item->Index;
  492. assert(Index >= 0 && Index <= FCustomCommands->Count);
  493. Item->Caption = StringReplace(FCustomCommands->Names[Index], "&", "",
  494. TReplaceFlags() << rfReplaceAll);
  495. assert(!Item->SubItems->Count);
  496. AnsiString Name = FCustomCommands->Names[Index];
  497. Item->SubItems->Add(FCustomCommands->Values[Name]);
  498. int Params = FCustomCommands->Params[Name];
  499. AnsiString ParamsStr;
  500. if ((Params & ccApplyToDirectories) && (Params & ccRecursive))
  501. {
  502. ParamsStr = FMTLOAD(CUSTOM_COMMAND_PARAMFMT,
  503. (LoadStr(CUSTOM_COMMAND_DIRECTORIES), LoadStr(CUSTOM_COMMAND_RECURSE)));
  504. }
  505. else if (Params & ccApplyToDirectories)
  506. {
  507. ParamsStr = LoadStr(CUSTOM_COMMAND_DIRECTORIES);
  508. }
  509. else if (Params & ccRecursive)
  510. {
  511. ParamsStr = LoadStr(CUSTOM_COMMAND_RECURSE);
  512. }
  513. Item->SubItems->Add(ParamsStr);
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TPreferencesDialog::CustomCommandsViewSelectItem(
  517. TObject * /*Sender*/, TListItem * Item, bool Selected)
  518. {
  519. if (Item && Selected)
  520. {
  521. assert(Item);
  522. int Index = Item->Index;
  523. assert(Index >= 0 && Index <= FCustomCommands->Count);
  524. CustomCommandDescEdit->Text = FCustomCommands->Names[Index];
  525. AnsiString Name = FCustomCommands->Names[Index];
  526. CustomCommandEdit->Text = FCustomCommands->Values[Name];
  527. int Params = FCustomCommands->Params[Name];
  528. CustomCommandApplyToDirectoriesCheck->Checked = Params & ccApplyToDirectories;
  529. CustomCommandRecursiveCheck->Checked = Params & ccRecursive;
  530. }
  531. UpdateControls();
  532. }
  533. //---------------------------------------------------------------------------
  534. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  535. {
  536. CustomCommandsView->Items->Count = FCustomCommands->Count;
  537. AdjustListColumnsWidth(CustomCommandsView);
  538. CustomCommandsView->Invalidate();
  539. }
  540. //---------------------------------------------------------------------------
  541. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  542. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  543. {
  544. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  545. {
  546. RemoveCommandButtonClick(NULL);
  547. }
  548. }
  549. //---------------------------------------------------------------------------
  550. AnsiString __fastcall TPreferencesDialog::CustomCommandString(int Index)
  551. {
  552. if (CustomCommandDescEdit->Text.Pos("="))
  553. {
  554. throw Exception(FMTLOAD(CUSTOM_COMMAND_INVALID, ("=")));
  555. }
  556. int I = FCustomCommands->IndexOfName(CustomCommandDescEdit->Text);
  557. if (I >= 0 && (Index < 0 || I != Index))
  558. {
  559. throw Exception(FMTLOAD(CUSTOM_COMMAND_DUPLICATE, (CustomCommandDescEdit->Text)));
  560. }
  561. return FORMAT("%s=%s", (CustomCommandDescEdit->Text, CustomCommandEdit->Text));
  562. }
  563. //---------------------------------------------------------------------------
  564. int __fastcall TPreferencesDialog::CustomCommandParams()
  565. {
  566. return
  567. (CustomCommandApplyToDirectoriesCheck->Checked ? ccApplyToDirectories : 0) |
  568. (CustomCommandRecursiveCheck->Checked ? ccRecursive : 0);
  569. }
  570. //---------------------------------------------------------------------------
  571. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  572. {
  573. int Index;
  574. if (CustomCommandsView->ItemIndex >= 0)
  575. {
  576. FCustomCommands->Insert(CustomCommandsView->ItemIndex, CustomCommandString());
  577. Index = CustomCommandsView->ItemIndex;
  578. }
  579. else
  580. {
  581. Index = FCustomCommands->Add(CustomCommandString());
  582. }
  583. FCustomCommands->Params[CustomCommandDescEdit->Text] = CustomCommandParams();
  584. CustomCommandsView->ItemIndex = Index;
  585. UpdateCustomCommandsView();
  586. UpdateControls();
  587. }
  588. //---------------------------------------------------------------------------
  589. void __fastcall TPreferencesDialog::SaveCommandButtonClick(TObject * /*Sender*/)
  590. {
  591. assert(CustomCommandsView->ItemIndex >= 0 &&
  592. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  593. FCustomCommands->Strings[CustomCommandsView->ItemIndex] =
  594. CustomCommandString(CustomCommandsView->ItemIndex);
  595. FCustomCommands->Params[CustomCommandDescEdit->Text] = CustomCommandParams();
  596. UpdateCustomCommandsView();
  597. UpdateControls();
  598. }
  599. //---------------------------------------------------------------------------
  600. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  601. TObject * /*Sender*/)
  602. {
  603. assert(CustomCommandsView->ItemIndex >= 0 &&
  604. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  605. FCustomCommands->Delete(CustomCommandsView->ItemIndex);
  606. UpdateCustomCommandsView();
  607. UpdateControls();
  608. }
  609. //---------------------------------------------------------------------------
  610. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  611. {
  612. if (Source >= 0 && Source < FCustomCommands->Count &&
  613. Dest >= 0 && Dest < FCustomCommands->Count)
  614. {
  615. FCustomCommands->Move(Source, Dest);
  616. // workaround for bug in VCL
  617. CustomCommandsView->ItemIndex = -1;
  618. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  619. CustomCommandsView->ItemIndex = Dest;
  620. UpdateCustomCommandsView();
  621. UpdateControls();
  622. }
  623. }
  624. //---------------------------------------------------------------------------
  625. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  626. {
  627. CustomCommandMove(CustomCommandsView->ItemIndex,
  628. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  629. }
  630. //---------------------------------------------------------------------------
  631. void __fastcall TPreferencesDialog::CustomCommandsViewStartDrag(
  632. TObject * /*Sender*/, TDragObject *& /*DragObject*/)
  633. {
  634. FCustomCommandDragSource = CustomCommandsView->ItemIndex;
  635. FCustomCommandDragDest = -1;
  636. }
  637. //---------------------------------------------------------------------------
  638. bool __fastcall TPreferencesDialog::AllowCustomCommandsDrag(int X, int Y)
  639. {
  640. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  641. FCustomCommandDragDest = Item ? Item->Index : -1;
  642. return (FCustomCommandDragDest >= 0) && (FCustomCommandDragDest != FCustomCommandDragSource);
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  646. TObject * /*Sender*/, TObject * Source, int X, int Y)
  647. {
  648. if (Source == CustomCommandsView)
  649. {
  650. if (AllowCustomCommandsDrag(X, Y))
  651. {
  652. CustomCommandMove(FCustomCommandDragSource, FCustomCommandDragDest);
  653. }
  654. }
  655. }
  656. //---------------------------------------------------------------------------
  657. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  658. TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/,
  659. TDragState /*State*/, bool & Accept)
  660. {
  661. if (Source == CustomCommandsView)
  662. {
  663. // cannot use AllowCustomCommandsDrag(X, Y) because of bug in VCL
  664. // (when dropped on item itself, when it was dragged over another item before,
  665. // that another item remains highlighted forever)
  666. Accept = true;
  667. }
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TPreferencesDialog::CompareByTimeCheckClick(
  671. TObject * /*Sender*/)
  672. {
  673. if (!CompareByTimeCheck->Checked)
  674. {
  675. CompareBySizeCheck->Checked = true;
  676. }
  677. UpdateControls();
  678. }
  679. //---------------------------------------------------------------------------
  680. void __fastcall TPreferencesDialog::CompareBySizeCheckClick(
  681. TObject * /*Sender*/)
  682. {
  683. if (!CompareBySizeCheck->Checked)
  684. {
  685. CompareByTimeCheck->Checked = true;
  686. }
  687. UpdateControls();
  688. }
  689. //---------------------------------------------------------------------------
  690. void __fastcall TPreferencesDialog::NavigationTreeChange(TObject * /*Sender*/,
  691. TTreeNode *Node)
  692. {
  693. if (Node->SelectedIndex)
  694. {
  695. for (Integer Index = 0; Index < PageControl->PageCount; Index++)
  696. {
  697. if (PageControl->Pages[Index]->Tag == (Node->SelectedIndex & 127))
  698. {
  699. PageControl->ActivePage = PageControl->Pages[Index];
  700. return;
  701. }
  702. }
  703. }
  704. assert(false);
  705. }
  706. //---------------------------------------------------------------------------
  707. void __fastcall TPreferencesDialog::PageControlChange(TObject * /*Sender*/)
  708. {
  709. bool Found = false;
  710. if (PageControl->ActivePage->Tag)
  711. {
  712. for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
  713. {
  714. if ((NavigationTree->Items->Item[Index]->SelectedIndex & 127) ==
  715. PageControl->ActivePage->Tag)
  716. {
  717. NavigationTree->Items->Item[Index]->Selected = true;
  718. Found = true;
  719. }
  720. }
  721. }
  722. assert(Found);
  723. if (Found)
  724. {
  725. UpdateControls();
  726. }
  727. }
  728. //---------------------------------------------------------------------------
  729. void __fastcall TPreferencesDialog::CMDialogKey(TWMKeyDown & Message)
  730. {
  731. if (Message.CharCode == VK_TAB)
  732. {
  733. TShiftState Shift = KeyDataToShiftState(Message.KeyData);
  734. if (Shift.Contains(ssCtrl))
  735. {
  736. TTreeNode * Node = NavigationTree->Selected;
  737. if (!Shift.Contains(ssShift))
  738. {
  739. Node = Node->GetNext();
  740. if (!Node) Node = NavigationTree->Items->GetFirstNode();
  741. }
  742. else
  743. {
  744. if (Node->GetPrev()) Node = Node->GetPrev();
  745. else
  746. while (Node->GetNext()) Node = Node->GetNext();
  747. }
  748. Node->Selected = True;
  749. Message.Result = 1;
  750. return;
  751. }
  752. }
  753. TForm::Dispatch(&Message);
  754. }
  755. //---------------------------------------------------------------------------
  756. void __fastcall TPreferencesDialog::Dispatch(void *Message)
  757. {
  758. TMessage * M = reinterpret_cast<TMessage*>(Message);
  759. assert(M);
  760. if (M->Msg == CM_DIALOGKEY)
  761. {
  762. CMDialogKey(*((TWMKeyDown *)Message));
  763. }
  764. else
  765. {
  766. TForm::Dispatch(Message);
  767. }
  768. }
  769. //---------------------------------------------------------------------------
  770. void __fastcall TPreferencesDialog::RegisterAsUrlHandlerButtonClick(
  771. TObject * /*Sender*/)
  772. {
  773. if (MessageDialog(LoadStr(CONFIRM_REGISTER_URL),
  774. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  775. {
  776. RegisterAsUrlHandler();
  777. }
  778. }
  779. //---------------------------------------------------------------------------
  780. void __fastcall TPreferencesDialog::DDExtLabelClick(TObject * Sender)
  781. {
  782. ((Sender == DDExtEnabledLabel) ? DDExtEnabledButton : DDExtDisabledButton)->
  783. Checked = true;
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TPreferencesDialog::PathEditsKeyDown(
  787. TObject * Sender, WORD & Key, TShiftState Shift)
  788. {
  789. PathEditKeyDown(dynamic_cast<TCustomEdit*>(Sender), Key, Shift, false);
  790. }
  791. //---------------------------------------------------------------------------