LocationProfiles.cpp 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746
  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 <HelpWin.h>
  10. #include <Common.h>
  11. #include "LocationProfiles.h"
  12. #include "WinConfiguration.h"
  13. //---------------------------------------------------------------------
  14. #pragma link "IEComboBox"
  15. #pragma resource "*.dfm"
  16. //---------------------------------------------------------------------
  17. bool __fastcall LocationProfilesDialog(TOpenDirectoryMode Mode,
  18. TOperationSide Side, AnsiString & LocalDirectory, AnsiString & RemoteDirectory,
  19. TStrings * LocalDirectories, TStrings * RemoteDirectories, TTerminal * Terminal)
  20. {
  21. bool Result;
  22. TLocationProfilesDialog * Dialog = new TLocationProfilesDialog(Application);
  23. try
  24. {
  25. Dialog->LocalDirectory = LocalDirectory;
  26. Dialog->RemoteDirectory = RemoteDirectory;
  27. Dialog->OperationSide = Side;
  28. Dialog->Terminal = Terminal;
  29. Dialog->RemoteDirectories = RemoteDirectories;
  30. Dialog->LocalDirectories = LocalDirectories;
  31. Dialog->Mode = Mode;
  32. Result = Dialog->Execute();
  33. if (Result)
  34. {
  35. LocalDirectory = Dialog->LocalDirectory;
  36. RemoteDirectory = Dialog->RemoteDirectory;
  37. }
  38. }
  39. __finally
  40. {
  41. delete Dialog;
  42. }
  43. return Result;
  44. }
  45. //---------------------------------------------------------------------
  46. __fastcall TLocationProfilesDialog::TLocationProfilesDialog(TComponent * AOwner):
  47. TForm(AOwner)
  48. {
  49. FOperationSide = osLocal;
  50. FBookmarkDragSource = NULL;
  51. FTerminal = NULL;
  52. FBookmarkList = new TBookmarkList();
  53. FChanging = false;
  54. FFolders = new TStringList;
  55. FFolders->CaseSensitive = false;
  56. FFolders->Sorted = true;
  57. FFolders->Duplicates = dupIgnore;
  58. UseSystemSettings(this);
  59. InstallPathWordBreakProc(LocalDirectoryEdit);
  60. InstallPathWordBreakProc(RemoteDirectoryEdit);
  61. }
  62. //---------------------------------------------------------------------
  63. __fastcall TLocationProfilesDialog::~TLocationProfilesDialog()
  64. {
  65. SAFE_DESTROY(FBookmarkList);
  66. SAFE_DESTROY(FFolders);
  67. }
  68. //---------------------------------------------------------------------------
  69. void __fastcall TLocationProfilesDialog::SetLocalDirectory(AnsiString value)
  70. {
  71. if (LocalDirectory != value)
  72. {
  73. LocalDirectoryEdit->Text = value;
  74. FindProfile();
  75. UpdateControls();
  76. }
  77. }
  78. //---------------------------------------------------------------------------
  79. AnsiString __fastcall TLocationProfilesDialog::GetLocalDirectory()
  80. {
  81. return ExcludeTrailingBackslash(LocalDirectoryEdit->Text);
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TLocationProfilesDialog::SetRemoteDirectory(AnsiString value)
  85. {
  86. if (RemoteDirectory != value)
  87. {
  88. RemoteDirectoryEdit->Text = value;
  89. FindProfile();
  90. UpdateControls();
  91. }
  92. }
  93. //---------------------------------------------------------------------------
  94. AnsiString __fastcall TLocationProfilesDialog::GetRemoteDirectory()
  95. {
  96. return UnixExcludeTrailingBackslash(RemoteDirectoryEdit->Text);
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TLocationProfilesDialog::SetRemoteDirectories(TStrings * value)
  100. {
  101. RemoteDirectoryEdit->Items = value;
  102. }
  103. //---------------------------------------------------------------------------
  104. TStrings * __fastcall TLocationProfilesDialog::GetRemoteDirectories()
  105. {
  106. return RemoteDirectoryEdit->Items;
  107. }
  108. //---------------------------------------------------------------------------
  109. void __fastcall TLocationProfilesDialog::SetLocalDirectories(TStrings * value)
  110. {
  111. LocalDirectoryEdit->Items = value;
  112. }
  113. //---------------------------------------------------------------------------
  114. TStrings * __fastcall TLocationProfilesDialog::GetLocalDirectories()
  115. {
  116. return LocalDirectoryEdit->Items;
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TLocationProfilesDialog::FindProfile()
  120. {
  121. TTreeNode * Match = NULL;
  122. for (int Index = 0; Index < ProfilesView->Items->Count; Index++)
  123. {
  124. TTreeNode * Node = ProfilesView->Items->Item[Index];
  125. if (Node->Data)
  126. {
  127. TBookmark * Bookmark = (TBookmark *)Node->Data;
  128. if (Bookmark->Local == LocalDirectory &&
  129. Bookmark->Remote == RemoteDirectory)
  130. {
  131. Match = Node;
  132. break;
  133. }
  134. }
  135. }
  136. if (Match)
  137. {
  138. ProfilesView->Selected = Match;
  139. Match->MakeVisible();
  140. }
  141. else
  142. {
  143. ProfilesView->Selected = NULL;
  144. }
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TLocationProfilesDialog::ControlChange(TObject * /*Sender*/)
  148. {
  149. UpdateControls();
  150. }
  151. //---------------------------------------------------------------------------
  152. void __fastcall TLocationProfilesDialog::UpdateControls()
  153. {
  154. EnableControl(OKBtn, !LocalDirectory.IsEmpty() || !RemoteDirectory.IsEmpty());
  155. EnableControl(AddBookmarkButton,
  156. !LocalDirectory.IsEmpty() || !RemoteDirectory.IsEmpty());
  157. EnableControl(RemoveBookmarkButton, ProfilesView->Selected);
  158. EnableControl(RenameButton, ProfilesView->Selected);
  159. EnableControl(MoveToButton, ProfilesView->Selected && ProfilesView->Selected->Data);
  160. EnableControl(UpBookmarkButton, ProfilesView->Selected &&
  161. ProfilesView->Selected->Data && ProfilesView->Selected->getPrevSibling() &&
  162. ProfilesView->Selected->getPrevSibling()->Data);
  163. EnableControl(DownBookmarkButton, ProfilesView->Selected &&
  164. ProfilesView->Selected->Data && ProfilesView->Selected->getNextSibling() &&
  165. ProfilesView->Selected->getNextSibling()->Data);
  166. }
  167. //---------------------------------------------------------------------------
  168. void __fastcall TLocationProfilesDialog::LoadBookmarks()
  169. {
  170. assert(FBookmarkList);
  171. FFolders->Clear();
  172. for (int Index = 0; Index < FBookmarkList->Count; Index++)
  173. {
  174. TBookmark * Bookmark = FBookmarkList->Bookmarks[Index];
  175. if (!Bookmark->Node.IsEmpty())
  176. {
  177. FFolders->Add(Bookmark->Node);
  178. }
  179. }
  180. ProfilesView->Items->Clear();
  181. for (int Index = 0; Index < FFolders->Count; Index++)
  182. {
  183. FFolders->Objects[Index] = ProfilesView->Items->Add(NULL, FFolders->Strings[Index]);
  184. }
  185. for (int Index = 0; Index < FBookmarkList->Count; Index++)
  186. {
  187. TBookmark * Bookmark = FBookmarkList->Bookmarks[Index];
  188. TTreeNode * Parent = NULL;
  189. if (!Bookmark->Node.IsEmpty())
  190. {
  191. assert(FFolders->IndexOf(Bookmark->Node) >= 0);
  192. Parent = dynamic_cast<TTreeNode *>(FFolders->Objects[FFolders->IndexOf(Bookmark->Node)]);
  193. }
  194. ProfilesView->Items->AddChildObject(Parent, Bookmark->Name, Bookmark);
  195. if ((Parent != NULL) && (Parent->Count == 1))
  196. {
  197. // only now, when folder node has its first child, we can eventually expand it
  198. Parent->Expanded = FBookmarkList->NodeOpened[Parent->Text];
  199. }
  200. }
  201. }
  202. //---------------------------------------------------------------------------
  203. bool __fastcall TLocationProfilesDialog::Execute()
  204. {
  205. bool Result;
  206. AnsiString SessionKey;
  207. if (Terminal)
  208. {
  209. TBookmarkList * BookmarkList;
  210. // cache session key, in case terminal is closed while the window is open
  211. SessionKey = Terminal->SessionData->SessionKey;
  212. BookmarkList = WinConfiguration->Bookmarks[SessionKey];
  213. if (BookmarkList)
  214. {
  215. FBookmarkList->Assign(BookmarkList);
  216. }
  217. else
  218. {
  219. FBookmarkList->Clear();
  220. }
  221. LoadBookmarks();
  222. }
  223. Result = ((Mode != odAddBookmark) || AddAsBookmark()) && (ShowModal() == mrOk);
  224. if (Terminal)
  225. {
  226. WinConfiguration->Bookmarks[SessionKey] = FBookmarkList;
  227. }
  228. return Result;
  229. }
  230. //---------------------------------------------------------------------------
  231. bool __fastcall TLocationProfilesDialog::AddAsBookmark()
  232. {
  233. assert(!LocalDirectory.IsEmpty() || !RemoteDirectory.IsEmpty());
  234. bool Result;
  235. AnsiString BookmarkName;
  236. if ((OperationSide == osLocal && !LocalDirectory.IsEmpty()) ||
  237. RemoteDirectory.IsEmpty())
  238. {
  239. BookmarkName = LocalDirectory;
  240. }
  241. else
  242. {
  243. BookmarkName = RemoteDirectory;
  244. }
  245. TTreeNode * Selected = ProfilesView->Selected;
  246. TBookmark * SelectedBookmark = NULL;
  247. AnsiString SelectedNode;
  248. if (Selected != NULL)
  249. {
  250. SelectedBookmark = (TBookmark *)Selected->Data;
  251. if (SelectedBookmark != NULL)
  252. {
  253. SelectedNode = SelectedBookmark->Node;
  254. }
  255. else
  256. {
  257. SelectedNode = Selected->Text;
  258. }
  259. }
  260. TStrings * PeerBookmarks = new TStringList();
  261. try
  262. {
  263. for (int Index = 0; Index < FBookmarkList->Count; Index++)
  264. {
  265. TBookmark * Bookmark = FBookmarkList->Bookmarks[Index];
  266. if (Bookmark->Node == SelectedNode)
  267. {
  268. PeerBookmarks->Add(Bookmark->Name);
  269. }
  270. }
  271. Result = DoComboInputDialog(LoadStr(ADD_BOOKMARK_CAPTION), LoadStr(ADD_BOOKMARK_PROMPT),
  272. BookmarkName, PeerBookmarks, false, HELP_LOCATION_PROFILE_ADD);
  273. if (Result)
  274. {
  275. if (BookmarkName.IsEmpty() || (StrToIntDef(BookmarkName, -123) != -123))
  276. {
  277. throw Exception(FMTLOAD(BOOKMARK_INVALID_NAME, (BookmarkName)));
  278. }
  279. TBookmark * Bookmark = FBookmarkList->FindByName(SelectedNode, BookmarkName);
  280. if (Bookmark != NULL)
  281. {
  282. Bookmark->Local = LocalDirectory;
  283. Bookmark->Remote = RemoteDirectory;
  284. for (int Index = 0; Index < ProfilesView->Items->Count; Index++)
  285. {
  286. TTreeNode * Node = ProfilesView->Items->Item[Index];
  287. if (Node->Data == Bookmark)
  288. {
  289. Selected = Node;
  290. break;
  291. }
  292. }
  293. }
  294. else
  295. {
  296. Bookmark = new TBookmark();
  297. Bookmark->Name = BookmarkName;
  298. Bookmark->Local = LocalDirectory;
  299. Bookmark->Remote = RemoteDirectory;
  300. if (SelectedBookmark != NULL)
  301. {
  302. Bookmark->Node = SelectedBookmark->Node;
  303. FBookmarkList->InsertBefore(SelectedBookmark, Bookmark);
  304. Selected = ProfilesView->Items->InsertObject(Selected, Bookmark->Name, Bookmark);
  305. }
  306. else if ((Selected != NULL) && (SelectedBookmark == NULL))
  307. {
  308. // must be a folder
  309. assert(!Selected->Parent); // more than one level of folders is not supported
  310. Bookmark->Node = Selected->Text;
  311. FBookmarkList->Add(Bookmark);
  312. Selected = ProfilesView->Items->AddChildObject(Selected, Bookmark->Name, Bookmark);
  313. }
  314. else
  315. {
  316. FBookmarkList->Add(Bookmark);
  317. Selected = ProfilesView->Items->AddObject(NULL, Bookmark->Name, Bookmark);
  318. }
  319. }
  320. ProfilesView->Selected = Selected;
  321. }
  322. }
  323. __finally
  324. {
  325. delete PeerBookmarks;
  326. }
  327. UpdateControls();
  328. return Result;
  329. }
  330. //---------------------------------------------------------------------------
  331. void __fastcall TLocationProfilesDialog::AddBookmarkButtonClick(TObject */*Sender*/)
  332. {
  333. AddAsBookmark();
  334. }
  335. //---------------------------------------------------------------------------
  336. void __fastcall TLocationProfilesDialog::RemoveBookmarkButtonClick(TObject * /*Sender*/)
  337. {
  338. assert(ProfilesView->Selected);
  339. TTreeNode * Node = ProfilesView->Selected;
  340. if (Node->Data)
  341. {
  342. FBookmarkList->Delete((TBookmark *)Node->Data);
  343. TTreeNode * ParentNode = Node->Parent;
  344. Node->Delete();
  345. if (ParentNode && !ParentNode->Count)
  346. {
  347. assert(FFolders->IndexOfObject(ParentNode) >= 0);
  348. FFolders->Delete(FFolders->IndexOfObject(ParentNode));
  349. ParentNode->Delete();
  350. }
  351. }
  352. else
  353. {
  354. if (MessageDialog(LoadStr(DELETE_BOOKMARK_FOLDER), qtConfirmation,
  355. qaYes | qaNo, HELP_LOCATION_PROFILE_DELETE) == qaYes)
  356. {
  357. assert(Node->Count);
  358. for (int i = 0; i < Node->Count; i++)
  359. {
  360. FBookmarkList->Delete((TBookmark *)Node->Item[i]->Data);
  361. }
  362. assert(FFolders->IndexOfObject(Node) >= 0);
  363. FFolders->Delete(FFolders->IndexOfObject(Node));
  364. Node->Delete();
  365. }
  366. }
  367. UpdateControls();
  368. }
  369. //---------------------------------------------------------------------------
  370. void __fastcall TLocationProfilesDialog::BookmarkMove(
  371. TTreeNode * Source, TTreeNode * Dest)
  372. {
  373. assert(Source && Source->Data);
  374. TBookmark * Bookmark = (TBookmark *)Source->Data;
  375. TTreeNode * PrevFolderNode = Source->Parent;
  376. if (!Dest || !Dest->Data)
  377. {
  378. Bookmark->Node = Dest ? Dest->Text : AnsiString("");
  379. FBookmarkList->MoveTo(FBookmarkList->Bookmarks[FBookmarkList->Count - 1],
  380. Bookmark, false);
  381. ProfilesView->Selected->MoveTo(Dest, naAddChild);
  382. }
  383. else
  384. {
  385. TBookmark * DestBookmark = (TBookmark *)Dest->Data;
  386. Bookmark->Node = DestBookmark->Node;
  387. FBookmarkList->MoveTo(DestBookmark, Bookmark,
  388. Source->AbsoluteIndex > Dest->AbsoluteIndex);
  389. if (Source->AbsoluteIndex > Dest->AbsoluteIndex)
  390. {
  391. Source->MoveTo(Dest, naInsert);
  392. }
  393. else if (Dest->getNextSibling() != NULL)
  394. {
  395. Source->MoveTo(Dest->getNextSibling(), naInsert);
  396. }
  397. else
  398. {
  399. Source->MoveTo(Dest, naAdd);
  400. }
  401. }
  402. if (PrevFolderNode && !PrevFolderNode->Count)
  403. {
  404. assert(FFolders->IndexOfObject(PrevFolderNode) >= 0);
  405. FFolders->Delete(FFolders->IndexOfObject(PrevFolderNode));
  406. PrevFolderNode->Delete();
  407. }
  408. Source->MakeVisible();
  409. UpdateControls();
  410. }
  411. //---------------------------------------------------------------------------
  412. void __fastcall TLocationProfilesDialog::BookmarkButtonClick(TObject *Sender)
  413. {
  414. TTreeNode * Node = ProfilesView->Selected;
  415. assert(Node);
  416. assert(Node->Data);
  417. TTreeNode * TargetNode;
  418. if (Sender == UpBookmarkButton)
  419. {
  420. TargetNode = Node->getPrevSibling();
  421. assert(TargetNode);
  422. }
  423. else
  424. {
  425. TargetNode = Node->getNextSibling();
  426. }
  427. BookmarkMove(Node, TargetNode ? TargetNode : Node->Parent);
  428. }
  429. //---------------------------------------------------------------------------
  430. void __fastcall TLocationProfilesDialog::ProfilesViewStartDrag(
  431. TObject * /*Sender*/ , TDragObject *& /*DragObject*/)
  432. {
  433. if (!ProfilesView->Selected->Data)
  434. {
  435. Abort();
  436. }
  437. FBookmarkDragSource = ProfilesView->Selected;
  438. }
  439. //---------------------------------------------------------------------------
  440. void __fastcall TLocationProfilesDialog::ProfilesViewDragOver(
  441. TObject */*Sender*/, TObject *Source, int /*X*/, int /*Y*/,
  442. TDragState /*State*/, bool &Accept)
  443. {
  444. if (Source == ProfilesView)
  445. {
  446. Accept = (ProfilesView->DropTarget != NULL) &&
  447. (FBookmarkDragSource != ProfilesView->DropTarget);
  448. }
  449. }
  450. //---------------------------------------------------------------------------
  451. void __fastcall TLocationProfilesDialog::ProfilesViewDragDrop(
  452. TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/)
  453. {
  454. if ((Source == ProfilesView) && (ProfilesView->DropTarget != NULL) &&
  455. (FBookmarkDragSource != ProfilesView->DropTarget))
  456. {
  457. assert(FBookmarkDragSource);
  458. TTreeNode * Target = ProfilesView->DropTarget;
  459. BookmarkMove(FBookmarkDragSource, Target);
  460. FBookmarkDragSource = NULL;
  461. }
  462. }
  463. //---------------------------------------------------------------------------
  464. void __fastcall TLocationProfilesDialog::ProfilesViewDblClick(TObject * /*Sender*/)
  465. {
  466. TPoint P = ProfilesView->ScreenToClient(Mouse->CursorPos);
  467. TTreeNode * Node = ProfilesView->GetNodeAt(P.x, P.y);
  468. if (OKBtn->Enabled && Node && Node->Data && Node->Selected)
  469. {
  470. ModalResult = mrOk;
  471. }
  472. }
  473. //---------------------------------------------------------------------------
  474. void __fastcall TLocationProfilesDialog::FormShow(TObject * /*Sender*/)
  475. {
  476. FindProfile();
  477. if (OperationSide == osLocal)
  478. {
  479. ActiveControl = LocalDirectoryEdit;
  480. }
  481. else
  482. {
  483. ActiveControl = RemoteDirectoryEdit;
  484. }
  485. UpdateControls();
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TLocationProfilesDialog::ProfilesViewKeyDown(TObject * /*Sender*/,
  489. WORD & Key, TShiftState /*Shift*/)
  490. {
  491. if (!ProfilesView->IsEditing())
  492. {
  493. if (RemoveBookmarkButton->Enabled && (Key == VK_DELETE))
  494. {
  495. RemoveBookmarkButtonClick(NULL);
  496. Key = 0;
  497. }
  498. else if (RenameButton->Enabled && (Key == VK_F2))
  499. {
  500. RenameButtonClick(NULL);
  501. Key = 0;
  502. }
  503. }
  504. }
  505. //---------------------------------------------------------------------------
  506. void __fastcall TLocationProfilesDialog::DirectoryEditChange(
  507. TObject * /*Sender*/)
  508. {
  509. if (!FChanging)
  510. {
  511. FindProfile();
  512. UpdateControls();
  513. }
  514. }
  515. //---------------------------------------------------------------------------
  516. void __fastcall TLocationProfilesDialog::ProfilesViewChange(
  517. TObject * /*Sender*/, TTreeNode * Node)
  518. {
  519. if (Node && Node->Data)
  520. {
  521. assert(!FChanging);
  522. FChanging = true;
  523. try
  524. {
  525. LocalDirectoryEdit->Text = ((TBookmark *)Node->Data)->Local;
  526. RemoteDirectoryEdit->Text = ((TBookmark *)Node->Data)->Remote;
  527. }
  528. __finally
  529. {
  530. FChanging = false;
  531. }
  532. }
  533. UpdateControls();
  534. }
  535. //---------------------------------------------------------------------------
  536. void __fastcall TLocationProfilesDialog::MoveToButtonClick(TObject * /*Sender*/)
  537. {
  538. assert(ProfilesView->Selected->Data);
  539. TBookmark * Bookmark = (TBookmark *)ProfilesView->Selected->Data;
  540. AnsiString Name = Bookmark->Node;
  541. if (DoComboInputDialog(LoadStr(MOVE_BOOKMARK_CAPTION), LoadStr(MOVE_BOOKMARK_PROMPT),
  542. Name, FFolders, true, HELP_LOCATION_PROFILE_MOVE) &&
  543. (Name != Bookmark->Node))
  544. {
  545. if (Name.Pos("\\"))
  546. {
  547. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (Name)));
  548. }
  549. TTreeNode * FolderNode;
  550. int I = FFolders->IndexOf(Name);
  551. if (Name.IsEmpty())
  552. {
  553. FolderNode = NULL;
  554. }
  555. else if (I >= 0)
  556. {
  557. FolderNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I]);
  558. assert(FolderNode);
  559. }
  560. else
  561. {
  562. I = FFolders->Add(Name);
  563. TTreeNode * NextNode;
  564. // duplicated in RenameButtonClick()
  565. if (I < FFolders->Count-1)
  566. {
  567. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  568. assert(NextNode);
  569. }
  570. else if (FFolders->Count > 1)
  571. {
  572. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  573. }
  574. else
  575. {
  576. assert(ProfilesView->Items->Count);
  577. NextNode = ProfilesView->Items->Item[0];
  578. }
  579. FolderNode = ProfilesView->Items->Insert(NextNode, Name);
  580. assert(FolderNode);
  581. FFolders->Objects[I] = FolderNode;
  582. }
  583. BookmarkMove(ProfilesView->Selected, FolderNode);
  584. }
  585. }
  586. //---------------------------------------------------------------------------
  587. void __fastcall TLocationProfilesDialog::RenameButtonClick(TObject * /*Sender*/)
  588. {
  589. assert(ProfilesView->Selected != NULL);
  590. if (ProfilesView->Selected != NULL)
  591. {
  592. ProfilesView->SetFocus();
  593. ProfilesView->Selected->EditText();
  594. }
  595. }
  596. //---------------------------------------------------------------------------
  597. void __fastcall TLocationProfilesDialog::ProfilesViewGetImageIndex(
  598. TObject * /*Sender*/, TTreeNode * Node)
  599. {
  600. Node->ImageIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  601. }
  602. //---------------------------------------------------------------------------
  603. void __fastcall TLocationProfilesDialog::ProfilesViewGetSelectedIndex(
  604. TObject * /*Sender*/, TTreeNode * Node)
  605. {
  606. Node->SelectedIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  607. }
  608. //---------------------------------------------------------------------------
  609. void __fastcall TLocationProfilesDialog::LocalDirectoryBrowseButtonClick(
  610. TObject * /*Sender*/)
  611. {
  612. AnsiString Directory = LocalDirectoryEdit->Text;
  613. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
  614. {
  615. LocalDirectoryEdit->Text = Directory;
  616. DirectoryEditChange(LocalDirectoryEdit);
  617. }
  618. }
  619. //---------------------------------------------------------------------------
  620. void __fastcall TLocationProfilesDialog::SwitchButtonClick(TObject * /*Sender*/)
  621. {
  622. WinConfiguration->UseLocationProfiles = false;
  623. }
  624. //---------------------------------------------------------------------------
  625. void __fastcall TLocationProfilesDialog::HelpButtonClick(TObject * /*Sender*/)
  626. {
  627. FormHelp(this);
  628. }
  629. //---------------------------------------------------------------------------
  630. void __fastcall TLocationProfilesDialog::ProfilesViewCollapsed(
  631. TObject * /*Sender*/, TTreeNode * Node)
  632. {
  633. assert(Node != NULL);
  634. assert(Node->Data == NULL);
  635. FBookmarkList->NodeOpened[Node->Text] = false;
  636. }
  637. //---------------------------------------------------------------------------
  638. void __fastcall TLocationProfilesDialog::ProfilesViewExpanded(
  639. TObject * /*Sender*/, TTreeNode * Node)
  640. {
  641. assert(Node != NULL);
  642. assert(Node->Data == NULL);
  643. FBookmarkList->NodeOpened[Node->Text] = true;
  644. }
  645. //---------------------------------------------------------------------------
  646. void __fastcall TLocationProfilesDialog::ProfilesViewEdited(
  647. TObject * /*Sender*/, TTreeNode * Node, AnsiString & S)
  648. {
  649. if (Node->Data != NULL)
  650. {
  651. if (S.IsEmpty() || (StrToIntDef(S, -123) != -123))
  652. {
  653. throw Exception(FMTLOAD(BOOKMARK_INVALID_NAME, (S)));
  654. }
  655. // raises exception in case of duplicate name??
  656. ((TBookmark *)Node->Data)->Name = S;
  657. }
  658. else
  659. {
  660. if (S.IsEmpty() || S.Pos("\\"))
  661. {
  662. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (S)));
  663. }
  664. if ((FFolders->IndexOf(S) >= 0) && AnsiCompareText(S, Node->Text))
  665. {
  666. throw Exception(FMTLOAD(DUPLICATE_BOOKMARK_FOLDER, (S)));
  667. }
  668. assert(Node->Count);
  669. FFolders->Delete(FFolders->IndexOf(Node->Text));
  670. int I = FFolders->AddObject(S, Node);
  671. TTreeNode * NextNode;
  672. // duplicated in MoveToButtonClick()
  673. if (I < FFolders->Count-1)
  674. {
  675. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  676. assert(NextNode);
  677. }
  678. else if (FFolders->Count > 1)
  679. {
  680. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  681. }
  682. else
  683. {
  684. assert(ProfilesView->Items->Count);
  685. NextNode = ProfilesView->Items->Item[0];
  686. }
  687. if (NextNode != Node)
  688. {
  689. Node->MoveTo(NextNode, NextNode ? naInsert : naAddChild);
  690. }
  691. for (int i = 0; i < Node->Count; i++)
  692. {
  693. ((TBookmark *)Node->Item[i]->Data)->Node = S;
  694. }
  695. Node->MakeVisible();
  696. }
  697. }
  698. //---------------------------------------------------------------------------
  699. void __fastcall TLocationProfilesDialog::ProfilesViewEditing(
  700. TObject * /*Sender*/, TTreeNode * /*Node*/, bool & /*AllowEdit*/)
  701. {
  702. OKBtn->Default = false;
  703. CancelBtn->Cancel = false;
  704. }
  705. //---------------------------------------------------------------------------
  706. void __fastcall TLocationProfilesDialog::UpdateActions()
  707. {
  708. TForm::UpdateActions();
  709. if ((!OKBtn->Default || !CancelBtn->Cancel) && !ProfilesView->IsEditing())
  710. {
  711. OKBtn->Default = true;
  712. CancelBtn->Cancel = true;
  713. }
  714. }
  715. //---------------------------------------------------------------------------