Preferences.cpp 26 KB

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