OpenDirectory.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  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. PageControl->ActivePage =
  239. (Terminal == NULL) || WinConfiguration->UseSharedBookmarks ? SharedBookmarksSheet : SessionBookmarksSheet;
  240. DirectoryEditChange(NULL);
  241. if (Mode == odAddBookmark)
  242. {
  243. AddAsBookmark(PageControl->ActivePage);
  244. }
  245. FBookmarkSelected = false;
  246. Result = (ShowModal() == DefaultResult(this));
  247. WinConfiguration->SharedBookmarks = FSharedBookmarkList;
  248. if (Terminal != NULL)
  249. {
  250. WinConfiguration->Bookmarks[SessionKey] = FSessionBookmarkList;
  251. // Do not remember that shared page was selected,
  252. // if it was selected implicitly because there's no site page.
  253. WinConfiguration->UseSharedBookmarks = (PageControl->ActivePage == SharedBookmarksSheet);
  254. }
  255. if (Result)
  256. {
  257. if (FBookmarkSelected)
  258. {
  259. Configuration->Usage->Inc(L"OpenedBookmark");
  260. }
  261. else
  262. {
  263. Configuration->Usage->Inc(L"OpenedPath");
  264. }
  265. }
  266. return Result;
  267. }
  268. //---------------------------------------------------------------------------
  269. template<class T>
  270. typename T * GetBookmarkObject(TObject * Sender, T * SessionObject, T * SharedObject)
  271. {
  272. TControl * Control = dynamic_cast<TControl *>(Sender);
  273. DebugAssert(Control != NULL);
  274. switch (abs(Control->Tag))
  275. {
  276. case 1: return SessionObject;
  277. case 2: return SharedObject;
  278. default: DebugFail(); return NULL;
  279. }
  280. }
  281. //---------------------------------------------------------------------------
  282. TBookmarkList * TOpenDirectoryDialog::GetBookmarkList(TObject * Sender)
  283. {
  284. return GetBookmarkObject(Sender, FSessionBookmarkList, FSharedBookmarkList);
  285. }
  286. //---------------------------------------------------------------------------
  287. TListBox * TOpenDirectoryDialog::GetBookmarksList(TObject * Sender)
  288. {
  289. return GetBookmarkObject(Sender, SessionBookmarksList, SharedBookmarksList);
  290. }
  291. //---------------------------------------------------------------------------
  292. TListBoxScrollOnDragOver * TOpenDirectoryDialog::GetScrollOnDragOver(TObject * Sender)
  293. {
  294. return GetBookmarkObject(Sender, FSessionScrollOnDragOver, FSharedScrollOnDragOver);
  295. }
  296. //---------------------------------------------------------------------------
  297. void __fastcall TOpenDirectoryDialog::AddAsBookmark(TObject * Sender)
  298. {
  299. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  300. TListBox * BookmarksList = GetBookmarksList(Sender);
  301. if (Directory.IsEmpty() || (FindBookmark(BookmarksList, Directory) >= 0))
  302. {
  303. return;
  304. }
  305. TBookmark * Bookmark = new TBookmark;
  306. if (OperationSide == osRemote)
  307. {
  308. RemoteDirectoryEdit->SelectAll();
  309. Bookmark->Remote = Directory;
  310. }
  311. else
  312. {
  313. LocalDirectoryEdit->SelectAll();
  314. Bookmark->Local = Directory;
  315. }
  316. Bookmark->Name = Directory;
  317. // would alway be equal to Directory atm,
  318. // as only difference can be a shorcut, which is not set
  319. UnicodeString Text = BookmarkText(Bookmark);
  320. if (BookmarksList->ItemIndex >= 0)
  321. {
  322. int PrevItemIndex = BookmarksList->ItemIndex;
  323. BookmarkList->InsertBefore(
  324. GetBookmark(BookmarksList, BookmarksList->ItemIndex), Bookmark);
  325. BookmarksList->Items->InsertObject(BookmarksList->ItemIndex, Text, Bookmark);
  326. BookmarksList->ItemIndex = PrevItemIndex;
  327. }
  328. else
  329. {
  330. BookmarkList->Add(Bookmark);
  331. BookmarksList->Items->AddObject(Text, Bookmark);
  332. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  333. }
  334. UpdateControls(true);
  335. }
  336. //---------------------------------------------------------------------------
  337. void __fastcall TOpenDirectoryDialog::AddBookmarkButtonClick(TObject * Sender)
  338. {
  339. AddAsBookmark(Sender);
  340. }
  341. //---------------------------------------------------------------------------
  342. void __fastcall TOpenDirectoryDialog::RemoveBookmark(TObject * Sender)
  343. {
  344. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  345. TListBox * BookmarksList = GetBookmarksList(Sender);
  346. int PrevItemIndex = BookmarksList->ItemIndex;
  347. TBookmark * Bookmark = GetBookmark(BookmarksList, PrevItemIndex);
  348. DebugAssert(Bookmark != NULL);
  349. BookmarkList->Delete(Bookmark);
  350. BookmarksList->Items->Delete(PrevItemIndex);
  351. if (PrevItemIndex < BookmarksList->Items->Count)
  352. {
  353. BookmarksList->ItemIndex = PrevItemIndex;
  354. }
  355. else
  356. {
  357. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  358. }
  359. UpdateControls(true);
  360. BookmarkSelected(Sender);
  361. }
  362. //---------------------------------------------------------------------------
  363. void __fastcall TOpenDirectoryDialog::RemoveBookmarkButtonClick(TObject * Sender)
  364. {
  365. RemoveBookmark(Sender);
  366. }
  367. //---------------------------------------------------------------------------
  368. Integer __fastcall TOpenDirectoryDialog::FindBookmark(TListBox * BookmarksList, const UnicodeString Bookmark)
  369. {
  370. if (OperationSide == osRemote)
  371. {
  372. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  373. {
  374. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  375. if (AnsiCompareStr(BookmarkDirectory(ABookmark), Bookmark) == 0)
  376. {
  377. return Index;
  378. }
  379. }
  380. }
  381. else
  382. {
  383. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  384. {
  385. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  386. if (AnsiCompareText(BookmarkDirectory(ABookmark), Bookmark) == 0)
  387. {
  388. return Index;
  389. }
  390. }
  391. }
  392. return -1;
  393. }
  394. //---------------------------------------------------------------------------
  395. void __fastcall TOpenDirectoryDialog::BookmarkSelected(TObject * Sender)
  396. {
  397. TListBox * BookmarksList = GetBookmarksList(Sender);
  398. if (BookmarksList->ItemIndex >= 0)
  399. {
  400. Directory = BookmarkDirectory(GetBookmark(BookmarksList, BookmarksList->ItemIndex));
  401. }
  402. UpdateControls();
  403. FBookmarkSelected = true;
  404. }
  405. //---------------------------------------------------------------------------
  406. void __fastcall TOpenDirectoryDialog::BookmarksListClick(TObject * Sender)
  407. {
  408. BookmarkSelected(Sender);
  409. }
  410. //---------------------------------------------------------------------------
  411. void __fastcall TOpenDirectoryDialog::BookmarkMove(TObject * Sender,
  412. int Source, int Dest)
  413. {
  414. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  415. TListBox * BookmarksList = GetBookmarksList(Sender);
  416. if (Source >= 0 && Source < BookmarksList->Items->Count &&
  417. Dest >= 0 && Dest < BookmarksList->Items->Count)
  418. {
  419. BookmarkList->MoveTo(
  420. GetBookmark(BookmarksList, Dest),
  421. GetBookmark(BookmarksList, Source),
  422. Source > Dest);
  423. BookmarksList->Items->Move(Source, Dest);
  424. BookmarksList->ItemIndex = Dest;
  425. BookmarksList->SetFocus();
  426. UpdateControls();
  427. }
  428. }
  429. //---------------------------------------------------------------------------
  430. void __fastcall TOpenDirectoryDialog::BookmarkButtonClick(TObject * Sender)
  431. {
  432. TControl * Control = dynamic_cast<TControl *>(Sender);
  433. BookmarkMove(Sender,
  434. GetBookmarksList(Sender)->ItemIndex,
  435. GetBookmarksList(Sender)->ItemIndex + (Control->Tag / abs(Control->Tag)));
  436. UpdateControls();
  437. }
  438. //---------------------------------------------------------------------------
  439. bool __fastcall TOpenDirectoryDialog::AllowBookmarkDrag(TObject * Sender, int X, int Y)
  440. {
  441. FBookmarkDragDest = GetBookmarksList(Sender)->ItemAtPos(TPoint(X, Y), true);
  442. return (FBookmarkDragDest >= 0) && (FBookmarkDragDest != FBookmarkDragSource);
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TOpenDirectoryDialog::BookmarksListStartDrag(
  446. TObject * Sender , TDragObject *& /*DragObject*/)
  447. {
  448. FBookmarkDragSource = GetBookmarksList(Sender)->ItemIndex;
  449. FBookmarkDragDest = -1;
  450. GetScrollOnDragOver(Sender)->StartDrag();
  451. }
  452. //---------------------------------------------------------------------------
  453. void __fastcall TOpenDirectoryDialog::BookmarksListDragOver(
  454. TObject * Sender, TObject *Source, int X, int Y, TDragState /*State*/,
  455. bool &Accept)
  456. {
  457. if (Source == GetBookmarksList(Sender))
  458. {
  459. Accept = AllowBookmarkDrag(Sender, X, Y);
  460. GetScrollOnDragOver(Sender)->DragOver(TPoint(X, Y));
  461. }
  462. }
  463. //---------------------------------------------------------------------------
  464. void __fastcall TOpenDirectoryDialog::BookmarksListDragDrop(
  465. TObject * Sender, TObject *Source, int X, int Y)
  466. {
  467. if (Source == GetBookmarksList(Sender))
  468. {
  469. if (AllowBookmarkDrag(Sender, X, Y))
  470. {
  471. BookmarkMove(Sender, FBookmarkDragSource, FBookmarkDragDest);
  472. }
  473. }
  474. }
  475. //---------------------------------------------------------------------------
  476. void __fastcall TOpenDirectoryDialog::SelectBookmark(TListBox * BookmarksList)
  477. {
  478. int ItemIndex = FindBookmark(BookmarksList, Directory);
  479. if (ItemIndex >= 0)
  480. {
  481. BookmarksList->ItemIndex = ItemIndex;
  482. }
  483. }
  484. //---------------------------------------------------------------------------
  485. void __fastcall TOpenDirectoryDialog::DirectoryEditChange(TObject * /*Sender*/)
  486. {
  487. SelectBookmark(SessionBookmarksList);
  488. SelectBookmark(SharedBookmarksList);
  489. UpdateControls();
  490. FBookmarkSelected = false;
  491. }
  492. //---------------------------------------------------------------------------
  493. void __fastcall TOpenDirectoryDialog::BookmarksListDblClick(TObject * Sender)
  494. {
  495. if (GetBookmarksList(Sender)->ItemIndex >= 0)
  496. {
  497. ModalResult = DefaultResult(this);
  498. }
  499. }
  500. //---------------------------------------------------------------------------
  501. void __fastcall TOpenDirectoryDialog::SetMode(TOpenDirectoryMode value)
  502. {
  503. FMode = value;
  504. Caption = LoadStr(Mode == odBrowse ?
  505. OPEN_DIRECTORY_BROWSE_CAPTION : OPEN_DIRECTORY_ADD_BOOMARK_ACTION );
  506. }
  507. //---------------------------------------------------------------------------
  508. void __fastcall TOpenDirectoryDialog::FormShow(TObject * /*Sender*/)
  509. {
  510. InstallPathWordBreakProc(LocalDirectoryEdit);
  511. InstallPathWordBreakProc(RemoteDirectoryEdit);
  512. UpdateControls(true);
  513. if (Mode == odBrowse)
  514. {
  515. ActiveControl = CurrentEdit;
  516. }
  517. else
  518. {
  519. ActiveControl = GetBookmarksList(PageControl->ActivePage);
  520. }
  521. }
  522. //---------------------------------------------------------------------------
  523. void __fastcall TOpenDirectoryDialog::BookmarksListKeyDown(TObject * Sender,
  524. WORD & Key, TShiftState /*Shift*/)
  525. {
  526. if ((GetBookmarksList(Sender)->ItemIndex >= 0) && (Key == VK_DELETE))
  527. {
  528. RemoveBookmark(Sender);
  529. }
  530. }
  531. //---------------------------------------------------------------------------
  532. void __fastcall TOpenDirectoryDialog::LocalDirectoryBrowseButtonClick(
  533. TObject * /*Sender*/)
  534. {
  535. UnicodeString Directory = LocalDirectoryEdit->Text;
  536. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
  537. {
  538. LocalDirectoryEdit->Text = Directory;
  539. DirectoryEditChange(NULL);
  540. }
  541. }
  542. //---------------------------------------------------------------------------
  543. void __fastcall TOpenDirectoryDialog::SwitchButtonClick(TObject * /*Sender*/)
  544. {
  545. WinConfiguration->UseLocationProfiles = true;
  546. }
  547. //---------------------------------------------------------------------------
  548. void __fastcall TOpenDirectoryDialog::HelpButtonClick(TObject * /*Sender*/)
  549. {
  550. FormHelp(this);
  551. }
  552. //---------------------------------------------------------------------------
  553. void __fastcall TOpenDirectoryDialog::BookmarksListEndDrag(TObject * Sender,
  554. TObject * /*Target*/, int /*X*/, int /*Y*/)
  555. {
  556. GetScrollOnDragOver(Sender)->EndDrag();
  557. }
  558. //---------------------------------------------------------------------------
  559. void __fastcall TOpenDirectoryDialog::ShortCutBookmarkButtonClick(
  560. TObject * Sender)
  561. {
  562. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  563. TListBox * BookmarksList = GetBookmarksList(Sender);
  564. int Index = BookmarksList->ItemIndex;
  565. TBookmark * Bookmark = GetBookmark(BookmarksList, Index);
  566. DebugAssert(Bookmark != NULL);
  567. TShortCuts ShortCuts;
  568. WinConfiguration->CustomCommandShortCuts(ShortCuts);
  569. BookmarkList->ShortCuts(ShortCuts);
  570. TShortCut ShortCut = Bookmark->ShortCut;
  571. if (DoShortCutDialog(ShortCut, ShortCuts, HelpKeyword))
  572. {
  573. Bookmark->ShortCut = ShortCut;
  574. BookmarksList->Items->Strings[Index] = BookmarkText(Bookmark);
  575. UpdateControls(true);
  576. }
  577. }
  578. //---------------------------------------------------------------------------
  579. void __fastcall TOpenDirectoryDialog::PageControlChange(TObject * /*Sender*/)
  580. {
  581. BookmarkSelected(GetBookmarksList(PageControl->ActivePage));
  582. }
  583. //---------------------------------------------------------------------------