OpenDirectory.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <CoreMain.h>
  5. #include <Configuration.h>
  6. #include <RemoteFiles.h>
  7. #include <VCLCommon.h>
  8. #include <TextsWin.h>
  9. #include <Common.h>
  10. #include <Math.hpp>
  11. #include <GUITools.h>
  12. #include "OpenDirectory.h"
  13. #include "WinConfiguration.h"
  14. //---------------------------------------------------------------------
  15. #pragma link "HistoryComboBox"
  16. #pragma resource "*.dfm"
  17. //---------------------------------------------------------------------
  18. bool __fastcall DoOpenDirectoryDialog(TOpenDirectoryMode Mode, TOperationSide Side,
  19. UnicodeString & Directory, TStrings * Directories, TTerminal * Terminal,
  20. bool AllowSwitch)
  21. {
  22. bool Result;
  23. TOpenDirectoryDialog * Dialog = new TOpenDirectoryDialog(Application);
  24. try
  25. {
  26. Dialog->Mode = Mode;
  27. Dialog->OperationSide = Side;
  28. Dialog->Directory = Directory;
  29. Dialog->Directories = Directories;
  30. Dialog->Terminal = Terminal;
  31. Dialog->AllowSwitch = AllowSwitch;
  32. Result = Dialog->Execute();
  33. if (Result)
  34. {
  35. Directory = Dialog->Directory;
  36. }
  37. }
  38. __finally
  39. {
  40. delete Dialog;
  41. }
  42. return Result;
  43. }
  44. //---------------------------------------------------------------------
  45. __fastcall TOpenDirectoryDialog::TOpenDirectoryDialog(TComponent * AOwner):
  46. TForm(AOwner)
  47. {
  48. UseSystemSettings(this);
  49. FOperationSide = osCurrent;
  50. OperationSide = osLocal;
  51. FBookmarkDragDest = -1;
  52. FTerminal = NULL;
  53. FSessionBookmarkList = new TBookmarkList();
  54. FSharedBookmarkList = new TBookmarkList();
  55. FSessionScrollOnDragOver = new TListBoxScrollOnDragOver(SessionBookmarksList, true);
  56. FSharedScrollOnDragOver = new TListBoxScrollOnDragOver(SharedBookmarksList, true);
  57. FixComboBoxResizeBug(LocalDirectoryEdit);
  58. FixComboBoxResizeBug(RemoteDirectoryEdit);
  59. LoadDialogImage(Image, L"Open folder");
  60. }
  61. //---------------------------------------------------------------------
  62. __fastcall TOpenDirectoryDialog::~TOpenDirectoryDialog()
  63. {
  64. SAFE_DESTROY(FSessionScrollOnDragOver);
  65. SAFE_DESTROY(FSharedScrollOnDragOver);
  66. SAFE_DESTROY(FSessionBookmarkList);
  67. SAFE_DESTROY(FSharedBookmarkList);
  68. }
  69. //---------------------------------------------------------------------
  70. void __fastcall TOpenDirectoryDialog::SetOperationSide(TOperationSide value)
  71. {
  72. if (OperationSide != value)
  73. {
  74. UnicodeString ADirectory = Directory;
  75. FOperationSide = value;
  76. Directory = ADirectory;
  77. RemoteDirectoryEdit->Visible = False;
  78. LocalDirectoryEdit->Visible = False;
  79. CurrentEdit->Visible = True;
  80. EditLabel->FocusControl = CurrentEdit;
  81. UpdateControls();
  82. }
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TOpenDirectoryDialog::SetDirectory(UnicodeString value)
  86. {
  87. if (OperationSide == osRemote)
  88. {
  89. RemoteDirectoryEdit->Text = value;
  90. }
  91. else
  92. {
  93. LocalDirectoryEdit->Text = value;
  94. }
  95. DirectoryEditChange(NULL);
  96. }
  97. //---------------------------------------------------------------------------
  98. UnicodeString __fastcall TOpenDirectoryDialog::GetDirectory()
  99. {
  100. if (OperationSide == osRemote)
  101. return UnixExcludeTrailingBackslash(RemoteDirectoryEdit->Text);
  102. else
  103. return ExcludeTrailingBackslash(LocalDirectoryEdit->Text);
  104. }
  105. //---------------------------------------------------------------------------
  106. TWinControl * __fastcall TOpenDirectoryDialog::GetCurrentEdit()
  107. {
  108. if (OperationSide == osRemote) return RemoteDirectoryEdit;
  109. else return LocalDirectoryEdit;
  110. }
  111. //---------------------------------------------------------------------------
  112. void __fastcall TOpenDirectoryDialog::ControlChange(TObject * /*Sender*/)
  113. {
  114. UpdateControls();
  115. }
  116. //---------------------------------------------------------------------------
  117. void __fastcall TOpenDirectoryDialog::UpdateBookmarkControls(
  118. TButton * AddBookmarkButton, TButton * RemoveBookmarkButton,
  119. TButton * ShortCutBookmarkButton,
  120. TButton * UpBookmarkButton, TButton * DownBookmarkButton,
  121. TListBox * BookmarksList, bool ListBoxUpdate)
  122. {
  123. EnableControl(AddBookmarkButton,
  124. !Directory.IsEmpty() && (FindBookmark(BookmarksList, Directory) < 0));
  125. EnableControl(RemoveBookmarkButton, BookmarksList->ItemIndex >= 0);
  126. if (ShortCutBookmarkButton != NULL)
  127. {
  128. EnableControl(ShortCutBookmarkButton, BookmarksList->ItemIndex >= 0);
  129. }
  130. EnableControl(UpBookmarkButton, BookmarksList->ItemIndex > 0);
  131. EnableControl(DownBookmarkButton, BookmarksList->ItemIndex >= 0 &&
  132. BookmarksList->ItemIndex < BookmarksList->Items->Count-1);
  133. if (ListBoxUpdate)
  134. {
  135. int MaxWidth = 0;
  136. for (int i = 0; i < BookmarksList->Items->Count; i++)
  137. {
  138. int Width = BookmarksList->Canvas->TextExtent(BookmarksList->Items->Strings[i]).cx;
  139. if (Width > MaxWidth)
  140. {
  141. MaxWidth = Width;
  142. }
  143. }
  144. BookmarksList->ScrollWidth = MaxWidth;
  145. MaxWidth += ScaleByTextHeight(this, 6);
  146. if (BookmarksList->Items->Count > BookmarksList->ClientHeight / BookmarksList->ItemHeight)
  147. {
  148. MaxWidth += GetSystemMetricsForControl(this, SM_CXVSCROLL);
  149. }
  150. if (MaxWidth > BookmarksList->Width)
  151. {
  152. int CWidth = ClientWidth + (MaxWidth - BookmarksList->Width);
  153. ClientWidth = Min(CWidth, ScaleByTextHeight(this, 700));
  154. }
  155. }
  156. }
  157. //---------------------------------------------------------------------------
  158. void __fastcall TOpenDirectoryDialog::UpdateControls(bool ListBoxUpdate)
  159. {
  160. EnableControl(OKBtn, !Directory.IsEmpty());
  161. LocalDirectoryBrowseButton->Visible = (OperationSide == osLocal);
  162. SwitchButton->Visible = AllowSwitch;
  163. SessionBookmarksSheet->TabVisible = (Terminal != NULL);
  164. UpdateBookmarkControls(AddSessionBookmarkButton, RemoveSessionBookmarkButton,
  165. NULL, UpSessionBookmarkButton, DownSessionBookmarkButton,
  166. SessionBookmarksList, ListBoxUpdate);
  167. UpdateBookmarkControls(AddSharedBookmarkButton, RemoveSharedBookmarkButton,
  168. ShortCutSharedBookmarkButton, UpSharedBookmarkButton, DownSharedBookmarkButton,
  169. SharedBookmarksList, ListBoxUpdate);
  170. }
  171. //---------------------------------------------------------------------------
  172. void __fastcall TOpenDirectoryDialog::SetDirectories(TStrings * value)
  173. {
  174. dynamic_cast<TCustomComboBox*>(CurrentEdit)->Items = value;
  175. }
  176. //---------------------------------------------------------------------------
  177. TStrings * __fastcall TOpenDirectoryDialog::GetDirectories()
  178. {
  179. return RemoteDirectoryEdit->Items;
  180. }
  181. //---------------------------------------------------------------------------
  182. UnicodeString __fastcall TOpenDirectoryDialog::BookmarkDirectory(TBookmark * Bookmark)
  183. {
  184. return Bookmark->GetSideDirectory(OperationSide);
  185. }
  186. //---------------------------------------------------------------------------
  187. UnicodeString __fastcall TOpenDirectoryDialog::BookmarkText(TBookmark * Bookmark)
  188. {
  189. UnicodeString Result = BookmarkDirectory(Bookmark);
  190. if (!Result.IsEmpty() && (Bookmark->ShortCut != 0))
  191. {
  192. Result = FORMAT(L"%s (%s)", (Result, ShortCutToText(Bookmark->ShortCut)));
  193. }
  194. return Result;
  195. }
  196. //---------------------------------------------------------------------------
  197. TBookmark * __fastcall TOpenDirectoryDialog::GetBookmark(TListBox * BookmarksList, int Index)
  198. {
  199. return dynamic_cast<TBookmark *>(BookmarksList->Items->Objects[Index]);
  200. }
  201. //---------------------------------------------------------------------------
  202. void __fastcall TOpenDirectoryDialog::LoadBookmarks(TListBox * ListBox,
  203. TBookmarkList * BookmarkList, TBookmarkList * Source)
  204. {
  205. if (Source != NULL)
  206. {
  207. BookmarkList->Assign(Source);
  208. }
  209. else
  210. {
  211. BookmarkList->Clear();
  212. }
  213. Configuration->Usage->SetMax(L"MaxBookmarks", BookmarkList->Count);
  214. ListBox->Items->Clear();
  215. for (int i = 0; i < BookmarkList->Count; i++)
  216. {
  217. TBookmark * Bookmark = BookmarkList->Bookmarks[i];
  218. UnicodeString Directory = BookmarkDirectory(Bookmark);
  219. if (!Directory.IsEmpty() && (FindBookmark(ListBox, Directory) < 0))
  220. {
  221. UnicodeString Text = BookmarkText(Bookmark);
  222. ListBox->Items->AddObject(Text, Bookmark);
  223. }
  224. }
  225. }
  226. //---------------------------------------------------------------------------
  227. bool __fastcall TOpenDirectoryDialog::Execute()
  228. {
  229. bool Result;
  230. UnicodeString SessionKey;
  231. if (Terminal)
  232. {
  233. // cache session key, in case terminal is closed while the window is open
  234. SessionKey = Terminal->SessionData->SessionKey;
  235. LoadBookmarks(SessionBookmarksList, FSessionBookmarkList, WinConfiguration->Bookmarks[SessionKey]);
  236. }
  237. LoadBookmarks(SharedBookmarksList, FSharedBookmarkList, WinConfiguration->SharedBookmarks);
  238. TTabSheet * Page =
  239. (Terminal == NULL) || WinConfiguration->UseSharedBookmarks ? SharedBookmarksSheet : SessionBookmarksSheet;
  240. PageControl->ActivePage = Page;
  241. DirectoryEditChange(NULL);
  242. if (Mode == odAddBookmark)
  243. {
  244. AddAsBookmark(PageControl->ActivePage);
  245. }
  246. FBookmarkSelected = false;
  247. Result = (ShowModal() == DefaultResult(this));
  248. WinConfiguration->SharedBookmarks = FSharedBookmarkList;
  249. if (Terminal != NULL)
  250. {
  251. WinConfiguration->Bookmarks[SessionKey] = FSessionBookmarkList;
  252. // Do not remember that shared page was selected,
  253. // if it was selected implicitly because there's no site page.
  254. WinConfiguration->UseSharedBookmarks = (PageControl->ActivePage == SharedBookmarksSheet);
  255. }
  256. if (Result)
  257. {
  258. if (FBookmarkSelected)
  259. {
  260. Configuration->Usage->Inc(L"OpenedBookmark");
  261. }
  262. else
  263. {
  264. Configuration->Usage->Inc(L"OpenedPath");
  265. }
  266. }
  267. return Result;
  268. }
  269. //---------------------------------------------------------------------------
  270. template<class T>
  271. typename T * GetBookmarkObject(TObject * Sender, T * SessionObject, T * SharedObject)
  272. {
  273. TControl * Control = dynamic_cast<TControl *>(Sender);
  274. DebugAssert(Control != NULL);
  275. switch (abs(Control->Tag))
  276. {
  277. case 1: return SessionObject;
  278. case 2: return SharedObject;
  279. default: DebugFail(); return NULL;
  280. }
  281. }
  282. //---------------------------------------------------------------------------
  283. TBookmarkList * TOpenDirectoryDialog::GetBookmarkList(TObject * Sender)
  284. {
  285. return GetBookmarkObject(Sender, FSessionBookmarkList, FSharedBookmarkList);
  286. }
  287. //---------------------------------------------------------------------------
  288. TListBox * TOpenDirectoryDialog::GetBookmarksList(TObject * Sender)
  289. {
  290. return GetBookmarkObject(Sender, SessionBookmarksList, SharedBookmarksList);
  291. }
  292. //---------------------------------------------------------------------------
  293. TListBoxScrollOnDragOver * TOpenDirectoryDialog::GetScrollOnDragOver(TObject * Sender)
  294. {
  295. return GetBookmarkObject(Sender, FSessionScrollOnDragOver, FSharedScrollOnDragOver);
  296. }
  297. //---------------------------------------------------------------------------
  298. void __fastcall TOpenDirectoryDialog::AddAsBookmark(TObject * Sender)
  299. {
  300. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  301. TListBox * BookmarksList = GetBookmarksList(Sender);
  302. if (Directory.IsEmpty() || (FindBookmark(BookmarksList, Directory) >= 0))
  303. {
  304. return;
  305. }
  306. TBookmark * Bookmark = new TBookmark;
  307. if (OperationSide == osRemote)
  308. {
  309. RemoteDirectoryEdit->SelectAll();
  310. Bookmark->Remote = Directory;
  311. }
  312. else
  313. {
  314. LocalDirectoryEdit->SelectAll();
  315. Bookmark->Local = Directory;
  316. }
  317. Bookmark->Name = Directory;
  318. // would always be equal to Directory atm,
  319. // as only difference can be a shorcut, which is not set
  320. UnicodeString Text = BookmarkText(Bookmark);
  321. if (BookmarksList->ItemIndex >= 0)
  322. {
  323. int PrevItemIndex = BookmarksList->ItemIndex;
  324. BookmarkList->InsertBefore(
  325. GetBookmark(BookmarksList, BookmarksList->ItemIndex), Bookmark);
  326. BookmarksList->Items->InsertObject(BookmarksList->ItemIndex, Text, Bookmark);
  327. BookmarksList->ItemIndex = PrevItemIndex;
  328. }
  329. else
  330. {
  331. BookmarkList->Add(Bookmark);
  332. BookmarksList->Items->AddObject(Text, Bookmark);
  333. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  334. }
  335. UpdateControls(true);
  336. }
  337. //---------------------------------------------------------------------------
  338. void __fastcall TOpenDirectoryDialog::AddBookmarkButtonClick(TObject * Sender)
  339. {
  340. AddAsBookmark(Sender);
  341. }
  342. //---------------------------------------------------------------------------
  343. void __fastcall TOpenDirectoryDialog::RemoveBookmark(TObject * Sender)
  344. {
  345. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  346. TListBox * BookmarksList = GetBookmarksList(Sender);
  347. int PrevItemIndex = BookmarksList->ItemIndex;
  348. TBookmark * Bookmark = GetBookmark(BookmarksList, PrevItemIndex);
  349. DebugAssert(Bookmark != NULL);
  350. BookmarkList->Delete(Bookmark);
  351. BookmarksList->Items->Delete(PrevItemIndex);
  352. if (PrevItemIndex < BookmarksList->Items->Count)
  353. {
  354. BookmarksList->ItemIndex = PrevItemIndex;
  355. }
  356. else
  357. {
  358. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  359. }
  360. UpdateControls(true);
  361. BookmarkSelected(Sender);
  362. }
  363. //---------------------------------------------------------------------------
  364. void __fastcall TOpenDirectoryDialog::RemoveBookmarkButtonClick(TObject * Sender)
  365. {
  366. RemoveBookmark(Sender);
  367. }
  368. //---------------------------------------------------------------------------
  369. Integer __fastcall TOpenDirectoryDialog::FindBookmark(TListBox * BookmarksList, const UnicodeString Bookmark)
  370. {
  371. if (OperationSide == osRemote)
  372. {
  373. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  374. {
  375. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  376. if (AnsiCompareStr(BookmarkDirectory(ABookmark), Bookmark) == 0)
  377. {
  378. return Index;
  379. }
  380. }
  381. }
  382. else
  383. {
  384. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  385. {
  386. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  387. if (AnsiCompareText(BookmarkDirectory(ABookmark), Bookmark) == 0)
  388. {
  389. return Index;
  390. }
  391. }
  392. }
  393. return -1;
  394. }
  395. //---------------------------------------------------------------------------
  396. void __fastcall TOpenDirectoryDialog::BookmarkSelected(TObject * Sender)
  397. {
  398. TListBox * BookmarksList = GetBookmarksList(Sender);
  399. if (BookmarksList->ItemIndex >= 0)
  400. {
  401. Directory = BookmarkDirectory(GetBookmark(BookmarksList, BookmarksList->ItemIndex));
  402. }
  403. UpdateControls();
  404. FBookmarkSelected = true;
  405. }
  406. //---------------------------------------------------------------------------
  407. void __fastcall TOpenDirectoryDialog::BookmarksListClick(TObject * Sender)
  408. {
  409. BookmarkSelected(Sender);
  410. }
  411. //---------------------------------------------------------------------------
  412. void __fastcall TOpenDirectoryDialog::BookmarkMove(TObject * Sender,
  413. int Source, int Dest)
  414. {
  415. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  416. TListBox * BookmarksList = GetBookmarksList(Sender);
  417. if (Source >= 0 && Source < BookmarksList->Items->Count &&
  418. Dest >= 0 && Dest < BookmarksList->Items->Count)
  419. {
  420. BookmarkList->MoveTo(
  421. GetBookmark(BookmarksList, Dest),
  422. GetBookmark(BookmarksList, Source),
  423. Source > Dest);
  424. BookmarksList->Items->Move(Source, Dest);
  425. BookmarksList->ItemIndex = Dest;
  426. BookmarksList->SetFocus();
  427. UpdateControls();
  428. }
  429. }
  430. //---------------------------------------------------------------------------
  431. void __fastcall TOpenDirectoryDialog::BookmarkButtonClick(TObject * Sender)
  432. {
  433. TControl * Control = dynamic_cast<TControl *>(Sender);
  434. BookmarkMove(Sender,
  435. GetBookmarksList(Sender)->ItemIndex,
  436. GetBookmarksList(Sender)->ItemIndex + (Control->Tag / abs(Control->Tag)));
  437. UpdateControls();
  438. }
  439. //---------------------------------------------------------------------------
  440. bool __fastcall TOpenDirectoryDialog::AllowBookmarkDrag(TObject * Sender, int X, int Y)
  441. {
  442. FBookmarkDragDest = GetBookmarksList(Sender)->ItemAtPos(TPoint(X, Y), true);
  443. return (FBookmarkDragDest >= 0) && (FBookmarkDragDest != FBookmarkDragSource);
  444. }
  445. //---------------------------------------------------------------------------
  446. void __fastcall TOpenDirectoryDialog::BookmarksListStartDrag(
  447. TObject * Sender , TDragObject *& /*DragObject*/)
  448. {
  449. FBookmarkDragSource = GetBookmarksList(Sender)->ItemIndex;
  450. FBookmarkDragDest = -1;
  451. GetScrollOnDragOver(Sender)->StartDrag();
  452. }
  453. //---------------------------------------------------------------------------
  454. void __fastcall TOpenDirectoryDialog::BookmarksListDragOver(
  455. TObject * Sender, TObject *Source, int X, int Y, TDragState /*State*/,
  456. bool &Accept)
  457. {
  458. if (Source == GetBookmarksList(Sender))
  459. {
  460. Accept = AllowBookmarkDrag(Sender, X, Y);
  461. GetScrollOnDragOver(Sender)->DragOver(TPoint(X, Y));
  462. }
  463. }
  464. //---------------------------------------------------------------------------
  465. void __fastcall TOpenDirectoryDialog::BookmarksListDragDrop(
  466. TObject * Sender, TObject *Source, int X, int Y)
  467. {
  468. if (Source == GetBookmarksList(Sender))
  469. {
  470. if (AllowBookmarkDrag(Sender, X, Y))
  471. {
  472. BookmarkMove(Sender, FBookmarkDragSource, FBookmarkDragDest);
  473. }
  474. }
  475. }
  476. //---------------------------------------------------------------------------
  477. void __fastcall TOpenDirectoryDialog::SelectBookmark(TListBox * BookmarksList)
  478. {
  479. int ItemIndex = FindBookmark(BookmarksList, Directory);
  480. if (ItemIndex >= 0)
  481. {
  482. BookmarksList->ItemIndex = ItemIndex;
  483. }
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TOpenDirectoryDialog::DirectoryEditChange(TObject * /*Sender*/)
  487. {
  488. SelectBookmark(SessionBookmarksList);
  489. SelectBookmark(SharedBookmarksList);
  490. UpdateControls();
  491. FBookmarkSelected = false;
  492. }
  493. //---------------------------------------------------------------------------
  494. void __fastcall TOpenDirectoryDialog::BookmarksListDblClick(TObject * Sender)
  495. {
  496. if (GetBookmarksList(Sender)->ItemIndex >= 0)
  497. {
  498. ModalResult = DefaultResult(this);
  499. }
  500. }
  501. //---------------------------------------------------------------------------
  502. void __fastcall TOpenDirectoryDialog::SetMode(TOpenDirectoryMode value)
  503. {
  504. FMode = value;
  505. Caption = LoadStr(Mode == odBrowse ?
  506. OPEN_DIRECTORY_BROWSE_CAPTION : OPEN_DIRECTORY_ADD_BOOMARK_ACTION );
  507. }
  508. //---------------------------------------------------------------------------
  509. void __fastcall TOpenDirectoryDialog::FormShow(TObject * /*Sender*/)
  510. {
  511. InstallPathWordBreakProc(LocalDirectoryEdit);
  512. InstallPathWordBreakProc(RemoteDirectoryEdit);
  513. UpdateControls(true);
  514. if (Mode == odBrowse)
  515. {
  516. ActiveControl = CurrentEdit;
  517. }
  518. else
  519. {
  520. ActiveControl = GetBookmarksList(PageControl->ActivePage);
  521. }
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TOpenDirectoryDialog::BookmarksListKeyDown(TObject * Sender,
  525. WORD & Key, TShiftState /*Shift*/)
  526. {
  527. if ((GetBookmarksList(Sender)->ItemIndex >= 0) && (Key == VK_DELETE))
  528. {
  529. RemoveBookmark(Sender);
  530. }
  531. }
  532. //---------------------------------------------------------------------------
  533. void __fastcall TOpenDirectoryDialog::LocalDirectoryBrowseButtonClick(
  534. TObject * /*Sender*/)
  535. {
  536. SelectDirectoryForEdit(LocalDirectoryEdit);
  537. }
  538. //---------------------------------------------------------------------------
  539. void __fastcall TOpenDirectoryDialog::SwitchButtonClick(TObject * /*Sender*/)
  540. {
  541. WinConfiguration->UseLocationProfiles = true;
  542. }
  543. //---------------------------------------------------------------------------
  544. void __fastcall TOpenDirectoryDialog::HelpButtonClick(TObject * /*Sender*/)
  545. {
  546. FormHelp(this);
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TOpenDirectoryDialog::BookmarksListEndDrag(TObject * Sender,
  550. TObject * /*Target*/, int /*X*/, int /*Y*/)
  551. {
  552. GetScrollOnDragOver(Sender)->EndDrag();
  553. }
  554. //---------------------------------------------------------------------------
  555. void __fastcall TOpenDirectoryDialog::ShortCutBookmarkButtonClick(
  556. TObject * Sender)
  557. {
  558. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  559. TListBox * BookmarksList = GetBookmarksList(Sender);
  560. int Index = BookmarksList->ItemIndex;
  561. TBookmark * Bookmark = GetBookmark(BookmarksList, Index);
  562. DebugAssert(Bookmark != NULL);
  563. TShortCuts ShortCuts;
  564. WinConfiguration->CustomCommandShortCuts(ShortCuts);
  565. BookmarkList->ShortCuts(ShortCuts);
  566. TShortCut ShortCut = Bookmark->ShortCut;
  567. if (DoShortCutDialog(ShortCut, ShortCuts, HelpKeyword))
  568. {
  569. Bookmark->ShortCut = ShortCut;
  570. BookmarksList->Items->Strings[Index] = BookmarkText(Bookmark);
  571. UpdateControls(true);
  572. }
  573. }
  574. //---------------------------------------------------------------------------
  575. void __fastcall TOpenDirectoryDialog::PageControlChange(TObject * /*Sender*/)
  576. {
  577. BookmarkSelected(GetBookmarksList(PageControl->ActivePage));
  578. }
  579. //---------------------------------------------------------------------------