OpenDirectory.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599
  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 "OpenDirectory.h"
  12. #include "WinConfiguration.h"
  13. //---------------------------------------------------------------------
  14. #pragma link "IEComboBox"
  15. #ifndef NO_RESOURCES
  16. #pragma resource "*.dfm"
  17. #endif
  18. //---------------------------------------------------------------------
  19. bool __fastcall DoOpenDirectoryDialog(TOpenDirectoryMode Mode, TOperationSide Side,
  20. UnicodeString & Directory, TStrings * Directories, TTerminal * Terminal,
  21. bool AllowSwitch)
  22. {
  23. bool Result;
  24. TOpenDirectoryDialog * Dialog = new TOpenDirectoryDialog(Application);
  25. try
  26. {
  27. Dialog->Mode = Mode;
  28. Dialog->OperationSide = Side;
  29. Dialog->Directory = Directory;
  30. Dialog->Directories = Directories;
  31. Dialog->Terminal = Terminal;
  32. Dialog->AllowSwitch = AllowSwitch;
  33. Result = Dialog->Execute();
  34. if (Result)
  35. {
  36. Directory = Dialog->Directory;
  37. }
  38. }
  39. __finally
  40. {
  41. delete Dialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TOpenDirectoryDialog::TOpenDirectoryDialog(TComponent * AOwner):
  47. TForm(AOwner)
  48. {
  49. UseSystemSettings(this);
  50. FOperationSide = osCurrent;
  51. OperationSide = osLocal;
  52. FBookmarkDragDest = -1;
  53. FTerminal = NULL;
  54. FSessionBookmarkList = new TBookmarkList();
  55. FSharedBookmarkList = new TBookmarkList();
  56. FSessionScrollOnDragOver = new TListBoxScrollOnDragOver(SessionBookmarksList, true);
  57. FSharedScrollOnDragOver = new TListBoxScrollOnDragOver(SharedBookmarksList, true);
  58. FixComboBoxResizeBug(LocalDirectoryEdit);
  59. FixComboBoxResizeBug(RemoteDirectoryEdit);
  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 += GetSystemMetrics(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. UpdateBookmarkControls(AddSessionBookmarkButton, RemoveSessionBookmarkButton,
  164. NULL, UpSessionBookmarkButton, DownSessionBookmarkButton,
  165. SessionBookmarksList, ListBoxUpdate);
  166. UpdateBookmarkControls(AddSharedBookmarkButton, RemoveSharedBookmarkButton,
  167. ShortCutSharedBookmarkButton, UpSharedBookmarkButton, DownSharedBookmarkButton,
  168. SharedBookmarksList, ListBoxUpdate);
  169. }
  170. //---------------------------------------------------------------------------
  171. void __fastcall TOpenDirectoryDialog::SetDirectories(TStrings * value)
  172. {
  173. dynamic_cast<TCustomComboBox*>(CurrentEdit)->Items = value;
  174. }
  175. //---------------------------------------------------------------------------
  176. TStrings * __fastcall TOpenDirectoryDialog::GetDirectories()
  177. {
  178. return RemoteDirectoryEdit->Items;
  179. }
  180. //---------------------------------------------------------------------------
  181. UnicodeString __fastcall TOpenDirectoryDialog::BookmarkDirectory(TBookmark * Bookmark)
  182. {
  183. return OperationSide == osLocal ? Bookmark->Local : Bookmark->Remote;
  184. }
  185. //---------------------------------------------------------------------------
  186. UnicodeString __fastcall TOpenDirectoryDialog::BookmarkText(TBookmark * Bookmark)
  187. {
  188. UnicodeString Result = BookmarkDirectory(Bookmark);
  189. if (!Result.IsEmpty() && (Bookmark->ShortCut != 0))
  190. {
  191. Result = FORMAT(L"%s (%s)", (Result, ShortCutToText(Bookmark->ShortCut)));
  192. }
  193. return Result;
  194. }
  195. //---------------------------------------------------------------------------
  196. TBookmark * __fastcall TOpenDirectoryDialog::GetBookmark(TListBox * BookmarksList, int Index)
  197. {
  198. return dynamic_cast<TBookmark *>(BookmarksList->Items->Objects[Index]);
  199. }
  200. //---------------------------------------------------------------------------
  201. void __fastcall TOpenDirectoryDialog::LoadBookmarks(TListBox * ListBox,
  202. TBookmarkList * BookmarkList, TBookmarkList * Source)
  203. {
  204. if (Source != NULL)
  205. {
  206. BookmarkList->Assign(Source);
  207. }
  208. else
  209. {
  210. BookmarkList->Clear();
  211. }
  212. Configuration->Usage->SetMax(L"MaxBookmarks", BookmarkList->Count);
  213. ListBox->Items->Clear();
  214. for (int i = 0; i < BookmarkList->Count; i++)
  215. {
  216. TBookmark * Bookmark = BookmarkList->Bookmarks[i];
  217. UnicodeString Directory = BookmarkDirectory(Bookmark);
  218. if (!Directory.IsEmpty() && (FindBookmark(ListBox, Directory) < 0))
  219. {
  220. UnicodeString Text = BookmarkText(Bookmark);
  221. ListBox->Items->AddObject(Text, Bookmark);
  222. }
  223. }
  224. }
  225. //---------------------------------------------------------------------------
  226. bool __fastcall TOpenDirectoryDialog::Execute()
  227. {
  228. bool Result;
  229. UnicodeString SessionKey;
  230. if (Terminal)
  231. {
  232. // cache session key, in case terminal is closed while the window is open
  233. SessionKey = Terminal->SessionData->SessionKey;
  234. LoadBookmarks(SessionBookmarksList, FSessionBookmarkList, WinConfiguration->Bookmarks[SessionKey]);
  235. LoadBookmarks(SharedBookmarksList, FSharedBookmarkList, WinConfiguration->SharedBookmarks);
  236. PageControl->ActivePage =
  237. WinConfiguration->UseSharedBookmarks ? SharedBookmarksSheet : SessionBookmarksSheet;
  238. DirectoryEditChange(NULL);
  239. if (Mode == odAddBookmark)
  240. {
  241. AddAsBookmark(PageControl->ActivePage);
  242. }
  243. }
  244. FBookmarkSelected = false;
  245. Result = (ShowModal() == DefaultResult(this));
  246. if (Terminal)
  247. {
  248. WinConfiguration->Bookmarks[SessionKey] = FSessionBookmarkList;
  249. WinConfiguration->SharedBookmarks = FSharedBookmarkList;
  250. WinConfiguration->UseSharedBookmarks = (PageControl->ActivePage == SharedBookmarksSheet);
  251. }
  252. if (Result)
  253. {
  254. if (FBookmarkSelected)
  255. {
  256. Configuration->Usage->Inc(L"OpenedBookmark");
  257. }
  258. else
  259. {
  260. Configuration->Usage->Inc(L"OpenedPath");
  261. }
  262. }
  263. return Result;
  264. }
  265. //---------------------------------------------------------------------------
  266. template<class T>
  267. typename T * GetBookmarkObject(TObject * Sender, T * SessionObject, T * SharedObject)
  268. {
  269. TControl * Control = dynamic_cast<TControl *>(Sender);
  270. assert(Control != NULL);
  271. switch (abs(Control->Tag))
  272. {
  273. case 1: return SessionObject;
  274. case 2: return SharedObject;
  275. default: FAIL; return NULL;
  276. }
  277. }
  278. //---------------------------------------------------------------------------
  279. TBookmarkList * TOpenDirectoryDialog::GetBookmarkList(TObject * Sender)
  280. {
  281. return GetBookmarkObject(Sender, FSessionBookmarkList, FSharedBookmarkList);
  282. }
  283. //---------------------------------------------------------------------------
  284. TListBox * TOpenDirectoryDialog::GetBookmarksList(TObject * Sender)
  285. {
  286. return GetBookmarkObject(Sender, SessionBookmarksList, SharedBookmarksList);
  287. }
  288. //---------------------------------------------------------------------------
  289. TListBoxScrollOnDragOver * TOpenDirectoryDialog::GetScrollOnDragOver(TObject * Sender)
  290. {
  291. return GetBookmarkObject(Sender, FSessionScrollOnDragOver, FSharedScrollOnDragOver);
  292. }
  293. //---------------------------------------------------------------------------
  294. void __fastcall TOpenDirectoryDialog::AddAsBookmark(TObject * Sender)
  295. {
  296. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  297. TListBox * BookmarksList = GetBookmarksList(Sender);
  298. if (Directory.IsEmpty() || (FindBookmark(BookmarksList, Directory) >= 0))
  299. {
  300. return;
  301. }
  302. TBookmark * Bookmark = new TBookmark;
  303. if (OperationSide == osRemote)
  304. {
  305. RemoteDirectoryEdit->SelectAll();
  306. Bookmark->Remote = Directory;
  307. }
  308. else
  309. {
  310. LocalDirectoryEdit->SelectAll();
  311. Bookmark->Local = Directory;
  312. }
  313. Bookmark->Name = Directory;
  314. // would alway be equal to Directory atm,
  315. // as only difference can be a shorcut, which is not set
  316. UnicodeString Text = BookmarkText(Bookmark);
  317. if (BookmarksList->ItemIndex >= 0)
  318. {
  319. int PrevItemIndex = BookmarksList->ItemIndex;
  320. BookmarkList->InsertBefore(
  321. GetBookmark(BookmarksList, BookmarksList->ItemIndex), Bookmark);
  322. BookmarksList->Items->InsertObject(BookmarksList->ItemIndex, Text, Bookmark);
  323. BookmarksList->ItemIndex = PrevItemIndex;
  324. }
  325. else
  326. {
  327. BookmarkList->Add(Bookmark);
  328. BookmarksList->Items->AddObject(Text, Bookmark);
  329. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  330. }
  331. UpdateControls(true);
  332. }
  333. //---------------------------------------------------------------------------
  334. void __fastcall TOpenDirectoryDialog::AddBookmarkButtonClick(TObject * Sender)
  335. {
  336. AddAsBookmark(Sender);
  337. }
  338. //---------------------------------------------------------------------------
  339. void __fastcall TOpenDirectoryDialog::RemoveBookmark(TObject * Sender)
  340. {
  341. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  342. TListBox * BookmarksList = GetBookmarksList(Sender);
  343. int PrevItemIndex = BookmarksList->ItemIndex;
  344. TBookmark * Bookmark = GetBookmark(BookmarksList, PrevItemIndex);
  345. assert(Bookmark != NULL);
  346. BookmarkList->Delete(Bookmark);
  347. BookmarksList->Items->Delete(PrevItemIndex);
  348. if (PrevItemIndex < BookmarksList->Items->Count)
  349. {
  350. BookmarksList->ItemIndex = PrevItemIndex;
  351. }
  352. else
  353. {
  354. BookmarksList->ItemIndex = BookmarksList->Items->Count-1;
  355. }
  356. UpdateControls(true);
  357. BookmarkSelected(Sender);
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TOpenDirectoryDialog::RemoveBookmarkButtonClick(TObject * Sender)
  361. {
  362. RemoveBookmark(Sender);
  363. }
  364. //---------------------------------------------------------------------------
  365. Integer __fastcall TOpenDirectoryDialog::FindBookmark(TListBox * BookmarksList, const UnicodeString Bookmark)
  366. {
  367. if (OperationSide == osRemote)
  368. {
  369. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  370. {
  371. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  372. if (AnsiCompareStr(BookmarkDirectory(ABookmark), Bookmark) == 0)
  373. {
  374. return Index;
  375. }
  376. }
  377. }
  378. else
  379. {
  380. for (int Index = 0; Index < BookmarksList->Items->Count; Index++)
  381. {
  382. TBookmark * ABookmark = GetBookmark(BookmarksList, Index);
  383. if (AnsiCompareText(BookmarkDirectory(ABookmark), Bookmark) == 0)
  384. {
  385. return Index;
  386. }
  387. }
  388. }
  389. return -1;
  390. }
  391. //---------------------------------------------------------------------------
  392. void __fastcall TOpenDirectoryDialog::BookmarkSelected(TObject * Sender)
  393. {
  394. TListBox * BookmarksList = GetBookmarksList(Sender);
  395. if (BookmarksList->ItemIndex >= 0)
  396. {
  397. Directory = BookmarkDirectory(GetBookmark(BookmarksList, BookmarksList->ItemIndex));
  398. }
  399. UpdateControls();
  400. FBookmarkSelected = true;
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TOpenDirectoryDialog::BookmarksListClick(TObject * Sender)
  404. {
  405. BookmarkSelected(Sender);
  406. }
  407. //---------------------------------------------------------------------------
  408. void __fastcall TOpenDirectoryDialog::BookmarkMove(TObject * Sender,
  409. int Source, int Dest)
  410. {
  411. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  412. TListBox * BookmarksList = GetBookmarksList(Sender);
  413. if (Source >= 0 && Source < BookmarksList->Items->Count &&
  414. Dest >= 0 && Dest < BookmarksList->Items->Count)
  415. {
  416. BookmarkList->MoveTo(
  417. GetBookmark(BookmarksList, Dest),
  418. GetBookmark(BookmarksList, Source),
  419. Source > Dest);
  420. BookmarksList->Items->Move(Source, Dest);
  421. BookmarksList->ItemIndex = Dest;
  422. BookmarksList->SetFocus();
  423. UpdateControls();
  424. }
  425. }
  426. //---------------------------------------------------------------------------
  427. void __fastcall TOpenDirectoryDialog::BookmarkButtonClick(TObject * Sender)
  428. {
  429. TControl * Control = dynamic_cast<TControl *>(Sender);
  430. BookmarkMove(Sender,
  431. GetBookmarksList(Sender)->ItemIndex,
  432. GetBookmarksList(Sender)->ItemIndex + (Control->Tag / abs(Control->Tag)));
  433. UpdateControls();
  434. }
  435. //---------------------------------------------------------------------------
  436. bool __fastcall TOpenDirectoryDialog::AllowBookmarkDrag(TObject * Sender, int X, int Y)
  437. {
  438. FBookmarkDragDest = GetBookmarksList(Sender)->ItemAtPos(TPoint(X, Y), true);
  439. return (FBookmarkDragDest >= 0) && (FBookmarkDragDest != FBookmarkDragSource);
  440. }
  441. //---------------------------------------------------------------------------
  442. void __fastcall TOpenDirectoryDialog::BookmarksListStartDrag(
  443. TObject * Sender , TDragObject *& /*DragObject*/)
  444. {
  445. FBookmarkDragSource = GetBookmarksList(Sender)->ItemIndex;
  446. FBookmarkDragDest = -1;
  447. GetScrollOnDragOver(Sender)->StartDrag();
  448. }
  449. //---------------------------------------------------------------------------
  450. void __fastcall TOpenDirectoryDialog::BookmarksListDragOver(
  451. TObject * Sender, TObject *Source, int X, int Y, TDragState /*State*/,
  452. bool &Accept)
  453. {
  454. if (Source == GetBookmarksList(Sender))
  455. {
  456. Accept = AllowBookmarkDrag(Sender, X, Y);
  457. GetScrollOnDragOver(Sender)->DragOver(TPoint(X, Y));
  458. }
  459. }
  460. //---------------------------------------------------------------------------
  461. void __fastcall TOpenDirectoryDialog::BookmarksListDragDrop(
  462. TObject * Sender, TObject *Source, int X, int Y)
  463. {
  464. if (Source == GetBookmarksList(Sender))
  465. {
  466. if (AllowBookmarkDrag(Sender, X, Y))
  467. {
  468. BookmarkMove(Sender, FBookmarkDragSource, FBookmarkDragDest);
  469. }
  470. }
  471. }
  472. //---------------------------------------------------------------------------
  473. void __fastcall TOpenDirectoryDialog::SelectBookmark(TListBox * BookmarksList)
  474. {
  475. int ItemIndex = FindBookmark(BookmarksList, Directory);
  476. if (ItemIndex >= 0)
  477. {
  478. BookmarksList->ItemIndex = ItemIndex;
  479. }
  480. }
  481. //---------------------------------------------------------------------------
  482. void __fastcall TOpenDirectoryDialog::DirectoryEditChange(TObject * /*Sender*/)
  483. {
  484. SelectBookmark(SessionBookmarksList);
  485. SelectBookmark(SharedBookmarksList);
  486. UpdateControls();
  487. FBookmarkSelected = false;
  488. }
  489. //---------------------------------------------------------------------------
  490. void __fastcall TOpenDirectoryDialog::BookmarksListDblClick(TObject * Sender)
  491. {
  492. if (GetBookmarksList(Sender)->ItemIndex >= 0)
  493. {
  494. ModalResult = DefaultResult(this);
  495. }
  496. }
  497. //---------------------------------------------------------------------------
  498. void __fastcall TOpenDirectoryDialog::SetMode(TOpenDirectoryMode value)
  499. {
  500. FMode = value;
  501. Caption = LoadStr(Mode == odBrowse ?
  502. OPEN_DIRECTORY_BROWSE_CAPTION : OPEN_DIRECTORY_ADD_BOOMARK_ACTION );
  503. }
  504. //---------------------------------------------------------------------------
  505. void __fastcall TOpenDirectoryDialog::FormShow(TObject * /*Sender*/)
  506. {
  507. InstallPathWordBreakProc(LocalDirectoryEdit);
  508. InstallPathWordBreakProc(RemoteDirectoryEdit);
  509. UpdateControls(true);
  510. if (Mode == odBrowse)
  511. {
  512. ActiveControl = CurrentEdit;
  513. }
  514. else
  515. {
  516. ActiveControl = GetBookmarksList(PageControl->ActivePage);
  517. }
  518. }
  519. //---------------------------------------------------------------------------
  520. void __fastcall TOpenDirectoryDialog::BookmarksListKeyDown(TObject * Sender,
  521. WORD & Key, TShiftState /*Shift*/)
  522. {
  523. if ((GetBookmarksList(Sender)->ItemIndex >= 0) && (Key == VK_DELETE))
  524. {
  525. RemoveBookmark(Sender);
  526. }
  527. }
  528. //---------------------------------------------------------------------------
  529. void __fastcall TOpenDirectoryDialog::LocalDirectoryBrowseButtonClick(
  530. TObject * /*Sender*/)
  531. {
  532. UnicodeString Directory = LocalDirectoryEdit->Text;
  533. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
  534. {
  535. LocalDirectoryEdit->Text = Directory;
  536. DirectoryEditChange(NULL);
  537. }
  538. }
  539. //---------------------------------------------------------------------------
  540. void __fastcall TOpenDirectoryDialog::SwitchButtonClick(TObject * /*Sender*/)
  541. {
  542. WinConfiguration->UseLocationProfiles = true;
  543. }
  544. //---------------------------------------------------------------------------
  545. void __fastcall TOpenDirectoryDialog::HelpButtonClick(TObject * /*Sender*/)
  546. {
  547. FormHelp(this);
  548. }
  549. //---------------------------------------------------------------------------
  550. void __fastcall TOpenDirectoryDialog::BookmarksListEndDrag(TObject * Sender,
  551. TObject * /*Target*/, int /*X*/, int /*Y*/)
  552. {
  553. GetScrollOnDragOver(Sender)->EndDrag();
  554. }
  555. //---------------------------------------------------------------------------
  556. void __fastcall TOpenDirectoryDialog::ShortCutBookmarkButtonClick(
  557. TObject * Sender)
  558. {
  559. TBookmarkList * BookmarkList = GetBookmarkList(Sender);
  560. TListBox * BookmarksList = GetBookmarksList(Sender);
  561. int Index = BookmarksList->ItemIndex;
  562. TBookmark * Bookmark = GetBookmark(BookmarksList, Index);
  563. assert(Bookmark != NULL);
  564. TShortCuts ShortCuts;
  565. WinConfiguration->CustomCommandList->ShortCuts(ShortCuts);
  566. BookmarkList->ShortCuts(ShortCuts);
  567. TShortCut ShortCut = Bookmark->ShortCut;
  568. if (DoShortCutDialog(ShortCut, ShortCuts, HelpKeyword))
  569. {
  570. Bookmark->ShortCut = ShortCut;
  571. BookmarksList->Items->Strings[Index] = BookmarkText(Bookmark);
  572. UpdateControls(true);
  573. }
  574. }
  575. //---------------------------------------------------------------------------
  576. void __fastcall TOpenDirectoryDialog::PageControlChange(TObject * /*Sender*/)
  577. {
  578. BookmarkSelected(GetBookmarksList(PageControl->ActivePage));
  579. }
  580. //---------------------------------------------------------------------------