Preferences.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Preferences.h"
  5. #include <Common.h>
  6. #include <ScpMain.h>
  7. #include "VCLCommon.h"
  8. #include "Tools.h"
  9. #include "TextsWin.h"
  10. #include "UserInterface.h"
  11. #include "WinConfiguration.h"
  12. //---------------------------------------------------------------------
  13. #pragma link "GeneralSettings"
  14. #pragma link "LogSettings"
  15. #pragma link "XPGroupBox"
  16. #pragma link "CopyParams"
  17. #pragma link "UpDownEdit"
  18. #pragma link "IEComboBox"
  19. #pragma resource "*.dfm"
  20. //---------------------------------------------------------------------
  21. bool __fastcall DoPreferencesDialog(TPreferencesMode APreferencesMode)
  22. {
  23. bool Result;
  24. TPreferencesDialog * PreferencesDialog = new TPreferencesDialog(Application);
  25. try
  26. {
  27. PreferencesDialog->PreferencesMode = APreferencesMode;
  28. Result = PreferencesDialog->Execute();
  29. }
  30. __finally
  31. {
  32. delete PreferencesDialog;
  33. }
  34. return Result;
  35. }
  36. //---------------------------------------------------------------------
  37. __fastcall TPreferencesDialog::TPreferencesDialog(TComponent* AOwner)
  38. : TForm(AOwner)
  39. {
  40. FPreferencesMode = pmDefault;
  41. LoggingFrame->OnGetDefaultLogFileName = LoggingGetDefaultLogFileName;
  42. CopyParamsFrame->Direction = pdAll;
  43. FEditorFont = new TFont();
  44. FAfterExternalEditorDialog = false;
  45. FCustomCommands = new TStringList();
  46. FCustomCommandChanging = false;
  47. FCustomCommandDragDest = -1;
  48. UseSystemFont(this);
  49. }
  50. //---------------------------------------------------------------------------
  51. __fastcall TPreferencesDialog::~TPreferencesDialog()
  52. {
  53. LoggingFrame->OnGetDefaultLogFileName = NULL;
  54. delete FEditorFont;
  55. delete FCustomCommands;
  56. }
  57. //---------------------------------------------------------------------
  58. bool __fastcall TPreferencesDialog::Execute()
  59. {
  60. LoadConfiguration();
  61. bool Result = (ShowModal() == mrOk);
  62. if (Result) SaveConfiguration();
  63. return Result;
  64. }
  65. //---------------------------------------------------------------------------
  66. void __fastcall TPreferencesDialog::LoggingGetDefaultLogFileName(
  67. TObject * /*Sender*/, AnsiString & DefaultLogFileName)
  68. {
  69. DefaultLogFileName = "";
  70. }
  71. //---------------------------------------------------------------------------
  72. void __fastcall TPreferencesDialog::LoadConfiguration()
  73. {
  74. if (FPreferencesMode != pmLogin)
  75. {
  76. LoggingFrame->LoadConfiguration();
  77. GeneralSettingsFrame->LoadConfiguration();
  78. }
  79. #define BOOLPROP(PROP) PROP ## Check->Checked = WinConfiguration->PROP;
  80. BOOLPROP(DefaultDirIsHome);
  81. BOOLPROP(DeleteToRecycleBin);
  82. BOOLPROP(DDAllowMove);
  83. BOOLPROP(DDTransferConfirmation);
  84. BOOLPROP(DDWarnLackOfTempSpace);
  85. BOOLPROP(ShowHiddenFiles);
  86. BOOLPROP(ShowInaccesibleDirectories);
  87. BOOLPROP(CopyOnDoubleClick);
  88. BOOLPROP(CopyOnDoubleClickConfirmation);
  89. BOOLPROP(ConfirmOverwriting);
  90. BOOLPROP(ConfirmDeleting);
  91. BOOLPROP(ConfirmClosingSession);
  92. BOOLPROP(UseLocationProfiles);
  93. BOOLPROP(ContinueOnError);
  94. #undef BOOLPROP
  95. if (WinConfiguration->DDTemporaryDirectory.IsEmpty())
  96. {
  97. DDSystemTemporaryDirectoryButton->Checked = true;
  98. DDTemporaryDirectoryEdit->Text = SystemTemporaryDirectory();
  99. }
  100. else
  101. {
  102. DDCustomTemporaryDirectoryButton->Checked = true;
  103. DDTemporaryDirectoryEdit->Text = WinConfiguration->DDTemporaryDirectory;
  104. }
  105. ExplorerStyleSelectionCheck->Checked =
  106. WinConfiguration->ScpCommander.ExplorerStyleSelection;
  107. PreserveLocalDirectoryCheck->Checked =
  108. WinConfiguration->ScpCommander.PreserveLocalDirectory;
  109. ShowFullAddressCheck->Checked =
  110. WinConfiguration->ScpExplorer.ShowFullAddress;
  111. RegistryStorageButton->Checked = (Configuration->Storage == stRegistry);
  112. IniFileStorageButton->Checked = (Configuration->Storage == stIniFile);
  113. RandomSeedFileEdit->Text = Configuration->RandomSeedFile;
  114. // editor
  115. EditorInternalButton->Checked = WinConfiguration->Editor.Editor == edInternal;
  116. EditorExternalButton->Checked = WinConfiguration->Editor.Editor == edExternal;
  117. AnsiString ExternalEditor = WinConfiguration->Editor.ExternalEditor;
  118. if (!ExternalEditor.IsEmpty())
  119. {
  120. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  121. }
  122. ExternalEditorEdit->Text = ExternalEditor;
  123. EditorWordWrapCheck->Checked = WinConfiguration->Editor.WordWrap;
  124. FEditorFont->Name = WinConfiguration->Editor.FontName;
  125. FEditorFont->Height = WinConfiguration->Editor.FontHeight;
  126. FEditorFont->Charset = (TFontCharset)WinConfiguration->Editor.FontCharset;
  127. FEditorFont->Style = IntToFontStyles(WinConfiguration->Editor.FontStyle);
  128. CopyParamsFrame->Params = Configuration->CopyParam;
  129. ResumeOnButton->Checked = Configuration->CopyParam.ResumeSupport == rsOn;
  130. ResumeSmartButton->Checked = Configuration->CopyParam.ResumeSupport == rsSmart;
  131. ResumeOffButton->Checked = Configuration->CopyParam.ResumeSupport == rsOff;
  132. ResumeThresholdEdit->Value = Configuration->CopyParam.ResumeThreshold / 1024;
  133. TransferSheet->TabVisible = WinConfiguration->ExpertMode;
  134. GeneralSheet->TabVisible = (PreferencesMode != pmLogin) && WinConfiguration->ExpertMode;
  135. ExplorerSheet->TabVisible = WinConfiguration->ExpertMode;
  136. CommanderSheet->TabVisible = WinConfiguration->ExpertMode;
  137. GeneralSheet->TabVisible = (PreferencesMode != pmLogin);
  138. EditorSheet->TabVisible = WinConfiguration->ExpertMode && !WinConfiguration->DisableOpenEdit;
  139. StorageGroup->Visible = WinConfiguration->ExpertMode;
  140. RandomSeedFileLabel->Visible = WinConfiguration->ExpertMode;
  141. RandomSeedFileEdit->Visible = WinConfiguration->ExpertMode;
  142. FCustomCommands->Assign(WinConfiguration->CustomCommands);
  143. CustomCommandDescEdit->Text = "";
  144. CustomCommandEdit->Text = "";
  145. UpdateCustomCommandsView();
  146. PuttyPathEdit->FileName = WinConfiguration->PuttyPath;
  147. UpdateControls();
  148. }
  149. //---------------------------------------------------------------------------
  150. void __fastcall TPreferencesDialog::SaveConfiguration()
  151. {
  152. Configuration->BeginUpdate();
  153. try
  154. {
  155. if (FPreferencesMode != pmLogin)
  156. {
  157. LoggingFrame->SaveConfiguration();
  158. GeneralSettingsFrame->SaveConfiguration();
  159. }
  160. #define BOOLPROP(PROP) WinConfiguration->PROP = PROP ## Check->Checked
  161. BOOLPROP(DefaultDirIsHome);
  162. BOOLPROP(DeleteToRecycleBin);
  163. BOOLPROP(DDAllowMove);
  164. BOOLPROP(DDTransferConfirmation);
  165. BOOLPROP(DDWarnLackOfTempSpace);
  166. BOOLPROP(ShowHiddenFiles);
  167. BOOLPROP(ShowInaccesibleDirectories);
  168. BOOLPROP(CopyOnDoubleClick);
  169. BOOLPROP(CopyOnDoubleClickConfirmation);
  170. BOOLPROP(ConfirmOverwriting);
  171. BOOLPROP(ConfirmDeleting);
  172. BOOLPROP(ConfirmClosingSession);
  173. BOOLPROP(UseLocationProfiles);
  174. BOOLPROP(ContinueOnError);
  175. #undef BOOLPROP
  176. if (DDSystemTemporaryDirectoryButton->Checked)
  177. {
  178. WinConfiguration->DDTemporaryDirectory = "";
  179. }
  180. else
  181. {
  182. WinConfiguration->DDTemporaryDirectory = DDTemporaryDirectoryEdit->Text;
  183. }
  184. Configuration->Storage = RegistryStorageButton->Checked ? stRegistry : stIniFile;
  185. TScpCommanderConfiguration ScpCommander = WinConfiguration->ScpCommander;
  186. ScpCommander.ExplorerStyleSelection = ExplorerStyleSelectionCheck->Checked;
  187. ScpCommander.PreserveLocalDirectory = PreserveLocalDirectoryCheck->Checked;
  188. WinConfiguration->ScpCommander = ScpCommander;
  189. TScpExplorerConfiguration ScpExplorer = WinConfiguration->ScpExplorer;
  190. ScpExplorer.ShowFullAddress = ShowFullAddressCheck->Checked;
  191. WinConfiguration->ScpExplorer = ScpExplorer;
  192. Configuration->RandomSeedFile = RandomSeedFileEdit->Text;
  193. // editor
  194. WinConfiguration->Editor.Editor =
  195. (EditorInternalButton->Checked || ExternalEditorEdit->Text.IsEmpty()) ?
  196. edInternal : edExternal;
  197. WinConfiguration->Editor.ExternalEditor = ExternalEditorEdit->Text;
  198. WinConfiguration->Editor.WordWrap = EditorWordWrapCheck->Checked;
  199. WinConfiguration->Editor.FontName = FEditorFont->Name;
  200. WinConfiguration->Editor.FontHeight = FEditorFont->Height;
  201. WinConfiguration->Editor.FontCharset = FEditorFont->Charset;
  202. WinConfiguration->Editor.FontStyle = FontStylesToInt(FEditorFont->Style);
  203. TCopyParamType CopyParam = CopyParamsFrame->Params;
  204. if (ResumeOnButton->Checked) CopyParam.ResumeSupport = rsOn;
  205. if (ResumeSmartButton->Checked) CopyParam.ResumeSupport = rsSmart;
  206. if (ResumeOffButton->Checked) CopyParam.ResumeSupport = rsOff;
  207. CopyParam.ResumeThreshold = ResumeThresholdEdit->Value * 1024;
  208. Configuration->CopyParam = CopyParam;
  209. WinConfiguration->CustomCommands = FCustomCommands;
  210. WinConfiguration->PuttyPath = PuttyPathEdit->FileName;
  211. }
  212. __finally
  213. {
  214. Configuration->EndUpdate();
  215. }
  216. }
  217. //---------------------------------------------------------------------------
  218. void __fastcall TPreferencesDialog::SetPreferencesMode(TPreferencesMode value)
  219. {
  220. if (PreferencesMode != value)
  221. {
  222. FPreferencesMode = value;
  223. GeneralSheet->TabVisible = (value != pmLogin);
  224. LogSheet->TabVisible = (value != pmLogin);
  225. }
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TPreferencesDialog::FormShow(TObject * /*Sender*/)
  229. {
  230. switch (PreferencesMode) {
  231. case pmEditor: PageControl->ActivePage = EditorSheet; break;
  232. case pmCustomCommands: PageControl->ActivePage = CustomCommandsSheet; break;
  233. default: PageControl->ActivePage = PreferencesSheet; break;
  234. }
  235. }
  236. //---------------------------------------------------------------------------
  237. void __fastcall TPreferencesDialog::ControlChange(TObject * /*Sender*/)
  238. {
  239. UpdateControls();
  240. }
  241. //---------------------------------------------------------------------------
  242. void __fastcall TPreferencesDialog::UpdateControls()
  243. {
  244. EnableControl(CopyOnDoubleClickConfirmationCheck, CopyOnDoubleClickCheck->Checked);
  245. EnableControl(DDTemporaryDirectoryEdit, DDCustomTemporaryDirectoryButton->Checked);
  246. EnableControl(ResumeThresholdEdit, ResumeSmartButton->Checked);
  247. EditorFontLabel->Caption = FORMAT("%s, %d pt",
  248. (FEditorFont->Name, FEditorFont->Size));
  249. bool CommandComplete = !CustomCommandDescEdit->Text.IsEmpty() &&
  250. !CustomCommandEdit->Text.IsEmpty();
  251. EnableControl(AddCommandButton, CommandComplete);
  252. EnableControl(SaveCommandButton, CommandComplete &&
  253. CustomCommandsView->Selected &&
  254. (CustomCommandDescEdit->Text != FCustomCommands->Names[CustomCommandsView->ItemIndex] ||
  255. CustomCommandEdit->Text != FCustomCommands->Values[
  256. FCustomCommands->Names[CustomCommandsView->ItemIndex]]));
  257. EnableControl(RemoveCommandButton, CustomCommandsView->Selected);
  258. EnableControl(UpCommandButton, CustomCommandsView->ItemIndex > 0);
  259. EnableControl(DownCommandButton, CustomCommandsView->ItemIndex >= 0 &&
  260. CustomCommandsView->ItemIndex < CustomCommandsView->Items->Count - 1);
  261. }
  262. //---------------------------------------------------------------------------
  263. void __fastcall TPreferencesDialog::EditorFontButtonClick(TObject * /*Sender*/)
  264. {
  265. TFontDialog * Dialog = new TFontDialog(Application);
  266. try
  267. {
  268. Dialog->Device = fdScreen;
  269. Dialog->Options = TFontDialogOptions() << fdForceFontExist;
  270. Dialog->Font = FEditorFont;
  271. if (Dialog->Execute())
  272. {
  273. FEditorFont->Assign(Dialog->Font);
  274. UpdateControls();
  275. }
  276. }
  277. __finally
  278. {
  279. delete Dialog;
  280. }
  281. }
  282. //---------------------------------------------------------------------------
  283. void __fastcall TPreferencesDialog::ExternalEditorEditExit(TObject * /*Sender*/)
  284. {
  285. try
  286. {
  287. AnsiString ExternalEditor = ExternalEditorEdit->Text;
  288. if (!ExternalEditor.IsEmpty())
  289. {
  290. TWinConfiguration::ReformatFileNameCommand(ExternalEditor);
  291. ExternalEditorEdit->Text = ExternalEditor;
  292. }
  293. }
  294. catch(...)
  295. {
  296. ExternalEditorEdit->SelectAll();
  297. ExternalEditorEdit->SetFocus();
  298. throw;
  299. }
  300. }
  301. //---------------------------------------------------------------------------
  302. void __fastcall TPreferencesDialog::ExternalEditorEditAfterDialog(
  303. TObject * /*Sender*/, AnsiString & /*Name*/, bool & Action)
  304. {
  305. if (Action)
  306. {
  307. FAfterExternalEditorDialog = true;
  308. }
  309. }
  310. //---------------------------------------------------------------------------
  311. void __fastcall TPreferencesDialog::ExternalEditorEditChange(
  312. TObject *Sender)
  313. {
  314. if (FAfterExternalEditorDialog)
  315. {
  316. FAfterExternalEditorDialog = false;
  317. ExternalEditorEditExit(Sender);
  318. }
  319. }
  320. //---------------------------------------------------------------------------
  321. void __fastcall TPreferencesDialog::FormCloseQuery(TObject * /*Sender*/,
  322. bool & /*CanClose*/)
  323. {
  324. if (ModalResult != mrCancel && ExternalEditorEdit->Focused())
  325. {
  326. ExternalEditorEditExit(NULL);
  327. }
  328. }
  329. //---------------------------------------------------------------------------
  330. void __fastcall TPreferencesDialog::IconButtonClick(TObject *Sender)
  331. {
  332. if (MessageDialog(LoadStr(CONFIRM_CREATE_ICON),
  333. qtConfirmation, qaYes | qaNo, 0) == qaYes)
  334. {
  335. AnsiString IconName, Params;
  336. int SpecialFolder;
  337. if (Sender == SendToHookButton)
  338. {
  339. IconName = FMTLOAD(SENDTO_HOOK_NAME, (AppNameVersion));
  340. SpecialFolder = CSIDL_SENDTO;
  341. Params = "/upload";
  342. }
  343. else if (Sender == QuickLaunchIconButton)
  344. {
  345. IconName = "Microsoft\\Internet Explorer\\Quick Launch\\" +
  346. AppNameVersion;
  347. SpecialFolder = CSIDL_APPDATA;
  348. }
  349. else
  350. {
  351. IconName = AppNameVersion;
  352. SpecialFolder = Sender == DesktopIconButton ?
  353. CSIDL_DESKTOPDIRECTORY :CSIDL_COMMON_DESKTOPDIRECTORY;
  354. }
  355. CreateDesktopShortCut(IconName,
  356. Application->ExeName, Params, "", SpecialFolder);
  357. }
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TPreferencesDialog::CustomCommandsViewData(TObject * /*Sender*/,
  361. TListItem * Item)
  362. {
  363. assert(FCustomCommands);
  364. int Index = Item->Index;
  365. assert(Index >= 0 && Index <= FCustomCommands->Count);
  366. Item->Caption = StringReplace(FCustomCommands->Names[Index], "&", "",
  367. TReplaceFlags() << rfReplaceAll);
  368. assert(!Item->SubItems->Count);
  369. Item->SubItems->Add(FCustomCommands->Values[FCustomCommands->Names[Index]]);
  370. }
  371. //---------------------------------------------------------------------------
  372. void __fastcall TPreferencesDialog::CustomCommandsViewSelectItem(
  373. TObject * /*Sender*/, TListItem * Item, bool Selected)
  374. {
  375. if (Item && Selected)
  376. {
  377. assert(Item);
  378. int Index = Item->Index;
  379. assert(Index >= 0 && Index <= FCustomCommands->Count);
  380. CustomCommandDescEdit->Text = FCustomCommands->Names[Index];
  381. CustomCommandEdit->Text = FCustomCommands->Values[FCustomCommands->Names[Index]];
  382. }
  383. UpdateControls();
  384. }
  385. //---------------------------------------------------------------------------
  386. void __fastcall TPreferencesDialog::UpdateCustomCommandsView()
  387. {
  388. CustomCommandsView->Items->Count = FCustomCommands->Count;
  389. AdjustListColumnsWidth(CustomCommandsView);
  390. CustomCommandsView->Invalidate();
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall TPreferencesDialog::CustomCommandsViewKeyDown(
  394. TObject * /*Sender*/, WORD & Key, TShiftState /*Shift*/)
  395. {
  396. if (RemoveCommandButton->Enabled && (Key == VK_DELETE))
  397. {
  398. RemoveCommandButtonClick(NULL);
  399. }
  400. }
  401. //---------------------------------------------------------------------------
  402. AnsiString __fastcall TPreferencesDialog::CustomCommandString(int Index)
  403. {
  404. if (CustomCommandDescEdit->Text.Pos("="))
  405. {
  406. throw Exception(FMTLOAD(CUSTOM_COMMAND_INVALID, ("=")));
  407. }
  408. int I = FCustomCommands->IndexOfName(CustomCommandDescEdit->Text);
  409. if (I >= 0 && (Index < 0 || I != Index))
  410. {
  411. throw Exception(FMTLOAD(CUSTOM_COMMAND_DUPLICATE, (CustomCommandDescEdit->Text)));
  412. }
  413. return FORMAT("%s=%s", (CustomCommandDescEdit->Text, CustomCommandEdit->Text));
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TPreferencesDialog::AddCommandButtonClick(TObject * /*Sender*/)
  417. {
  418. int Index;
  419. if (CustomCommandsView->ItemIndex >= 0)
  420. {
  421. FCustomCommands->Insert(CustomCommandsView->ItemIndex, CustomCommandString());
  422. Index = CustomCommandsView->ItemIndex;
  423. }
  424. else
  425. {
  426. Index = FCustomCommands->Add(CustomCommandString());
  427. }
  428. CustomCommandsView->ItemIndex = Index;
  429. UpdateCustomCommandsView();
  430. UpdateControls();
  431. }
  432. //---------------------------------------------------------------------------
  433. void __fastcall TPreferencesDialog::SaveCommandButtonClick(TObject * /*Sender*/)
  434. {
  435. assert(CustomCommandsView->ItemIndex >= 0 &&
  436. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  437. FCustomCommands->Strings[CustomCommandsView->ItemIndex] =
  438. CustomCommandString(CustomCommandsView->ItemIndex);
  439. UpdateCustomCommandsView();
  440. UpdateControls();
  441. }
  442. //---------------------------------------------------------------------------
  443. void __fastcall TPreferencesDialog::RemoveCommandButtonClick(
  444. TObject * /*Sender*/)
  445. {
  446. assert(CustomCommandsView->ItemIndex >= 0 &&
  447. CustomCommandsView->ItemIndex < FCustomCommands->Count);
  448. FCustomCommands->Delete(CustomCommandsView->ItemIndex);
  449. UpdateCustomCommandsView();
  450. UpdateControls();
  451. }
  452. //---------------------------------------------------------------------------
  453. void __fastcall TPreferencesDialog::CustomCommandMove(int Source, int Dest)
  454. {
  455. if (Source >= 0 && Source < FCustomCommands->Count &&
  456. Dest >= 0 && Dest < FCustomCommands->Count)
  457. {
  458. FCustomCommands->Move(Source, Dest);
  459. // workaround for bug in VCL
  460. CustomCommandsView->ItemIndex = -1;
  461. CustomCommandsView->ItemFocused = CustomCommandsView->Selected;
  462. CustomCommandsView->ItemIndex = Dest;
  463. UpdateCustomCommandsView();
  464. UpdateControls();
  465. }
  466. }
  467. //---------------------------------------------------------------------------
  468. void __fastcall TPreferencesDialog::UpDownCommandButtonClick(TObject * Sender)
  469. {
  470. CustomCommandMove(CustomCommandsView->ItemIndex,
  471. CustomCommandsView->ItemIndex + (Sender == UpCommandButton ? -1 : 1));
  472. }
  473. //---------------------------------------------------------------------------
  474. void __fastcall TPreferencesDialog::CustomCommandsViewStartDrag(
  475. TObject * /*Sender*/, TDragObject *& /*DragObject*/)
  476. {
  477. FCustomCommandDragSource = CustomCommandsView->ItemIndex;
  478. FCustomCommandDragDest = -1;
  479. }
  480. //---------------------------------------------------------------------------
  481. bool __fastcall TPreferencesDialog::AllowCustomCommandsDrag(int X, int Y)
  482. {
  483. TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
  484. FCustomCommandDragDest = Item ? Item->Index : -1;
  485. return (FCustomCommandDragDest >= 0) && (FCustomCommandDragDest != FCustomCommandDragSource);
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TPreferencesDialog::CustomCommandsViewDragDrop(
  489. TObject * /*Sender*/, TObject * Source, int X, int Y)
  490. {
  491. if (Source == CustomCommandsView)
  492. {
  493. if (AllowCustomCommandsDrag(X, Y))
  494. {
  495. CustomCommandMove(FCustomCommandDragSource, FCustomCommandDragDest);
  496. }
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TPreferencesDialog::CustomCommandsViewDragOver(
  501. TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/,
  502. TDragState /*State*/, bool & Accept)
  503. {
  504. if (Source == CustomCommandsView)
  505. {
  506. // cannot use AllowCustomCommandsDrag(X, Y) because of bug in VCL
  507. // (when dropped on item itself, when it was dragged over another item before,
  508. // that another item remains highlighted forever)
  509. Accept = true;
  510. }
  511. }
  512. //---------------------------------------------------------------------------