Preferences.cpp 26 KB

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