Preferences.cpp 25 KB

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