OpenDirectory.cpp 21 KB

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