OpenDirectory.cpp 21 KB

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