LocationProfiles.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <ScpMain.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 "XPThemes"
  15. #pragma link "IEComboBox"
  16. #pragma resource "*.dfm"
  17. //---------------------------------------------------------------------
  18. bool __fastcall LocationProfilesDialog(TOpenDirectoryMode Mode,
  19. TOperationSide Side, AnsiString & LocalDirectory, AnsiString & RemoteDirectory,
  20. TStrings * LocalDirectories, TStrings * RemoteDirectories, TTerminal * Terminal)
  21. {
  22. bool Result;
  23. TLocationProfilesDialog * Dialog = new TLocationProfilesDialog(Application);
  24. try
  25. {
  26. Dialog->LocalDirectory = LocalDirectory;
  27. Dialog->RemoteDirectory = RemoteDirectory;
  28. Dialog->OperationSide = Side;
  29. Dialog->Terminal = Terminal;
  30. Dialog->RemoteDirectories = RemoteDirectories;
  31. Dialog->LocalDirectories = LocalDirectories;
  32. Dialog->Mode = Mode;
  33. Result = Dialog->Execute();
  34. if (Result)
  35. {
  36. LocalDirectory = Dialog->LocalDirectory;
  37. RemoteDirectory = Dialog->RemoteDirectory;
  38. }
  39. }
  40. __finally
  41. {
  42. delete Dialog;
  43. }
  44. return Result;
  45. }
  46. //---------------------------------------------------------------------
  47. __fastcall TLocationProfilesDialog::TLocationProfilesDialog(TComponent * AOwner):
  48. TForm(AOwner)
  49. {
  50. FOperationSide = osLocal;
  51. FBookmarkDragSource = NULL;
  52. FTerminal = NULL;
  53. FBookmarkList = new TBookmarkList();
  54. FChanging = false;
  55. FFolders = new TStringList;
  56. FFolders->CaseSensitive = false;
  57. FFolders->Sorted = true;
  58. FFolders->Duplicates = dupIgnore;
  59. UseSystemSettings(this);
  60. InstallPathWordBreakProc(LocalDirectoryEdit);
  61. InstallPathWordBreakProc(RemoteDirectoryEdit);
  62. }
  63. //---------------------------------------------------------------------
  64. __fastcall TLocationProfilesDialog::~TLocationProfilesDialog()
  65. {
  66. SAFE_DESTROY(FBookmarkList);
  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, NULL, 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. LocalDirectoryEdit->SetFocus();
  480. }
  481. else
  482. {
  483. RemoteDirectoryEdit->SetFocus();
  484. }
  485. UpdateControls();
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TLocationProfilesDialog::ProfilesViewKeyDown(TObject * /*Sender*/,
  489. WORD &Key, TShiftState /*Shift*/)
  490. {
  491. if (RemoveBookmarkButton->Enabled && (Key == VK_DELETE))
  492. {
  493. RemoveBookmarkButtonClick(NULL);
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TLocationProfilesDialog::DirectoryEditChange(
  498. TObject * /*Sender*/)
  499. {
  500. if (!FChanging)
  501. {
  502. FindProfile();
  503. UpdateControls();
  504. }
  505. }
  506. //---------------------------------------------------------------------------
  507. void __fastcall TLocationProfilesDialog::ProfilesViewChange(
  508. TObject * /*Sender*/, TTreeNode * Node)
  509. {
  510. if (Node && Node->Data)
  511. {
  512. assert(!FChanging);
  513. FChanging = true;
  514. try
  515. {
  516. LocalDirectoryEdit->Text = ((TBookmark *)Node->Data)->Local;
  517. RemoteDirectoryEdit->Text = ((TBookmark *)Node->Data)->Remote;
  518. }
  519. __finally
  520. {
  521. FChanging = false;
  522. }
  523. }
  524. UpdateControls();
  525. }
  526. //---------------------------------------------------------------------------
  527. void __fastcall TLocationProfilesDialog::MoveToButtonClick(TObject * /*Sender*/)
  528. {
  529. assert(ProfilesView->Selected->Data);
  530. TBookmark * Bookmark = (TBookmark *)ProfilesView->Selected->Data;
  531. AnsiString Name = Bookmark->Node;
  532. if (DoComboInputDialog(LoadStr(MOVE_BOOKMARK_CAPTION), LoadStr(MOVE_BOOKMARK_PROMPT),
  533. Name, FFolders, NULL, true, HELP_LOCATION_PROFILE_MOVE) &&
  534. (Name != Bookmark->Node))
  535. {
  536. if (Name.Pos("\\"))
  537. {
  538. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (Name)));
  539. }
  540. TTreeNode * FolderNode;
  541. int I = FFolders->IndexOf(Name);
  542. if (Name.IsEmpty())
  543. {
  544. FolderNode = NULL;
  545. }
  546. else if (I >= 0)
  547. {
  548. FolderNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I]);
  549. assert(FolderNode);
  550. }
  551. else
  552. {
  553. I = FFolders->Add(Name);
  554. TTreeNode * NextNode;
  555. // duplicated in RenameButtonClick()
  556. if (I < FFolders->Count-1)
  557. {
  558. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  559. assert(NextNode);
  560. }
  561. else if (FFolders->Count > 1)
  562. {
  563. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  564. }
  565. else
  566. {
  567. assert(ProfilesView->Items->Count);
  568. NextNode = ProfilesView->Items->Item[0];
  569. }
  570. FolderNode = ProfilesView->Items->Insert(NextNode, Name);
  571. assert(FolderNode);
  572. FFolders->Objects[I] = FolderNode;
  573. }
  574. BookmarkMove(ProfilesView->Selected, FolderNode);
  575. }
  576. }
  577. //---------------------------------------------------------------------------
  578. void __fastcall TLocationProfilesDialog::RenameButtonClick(TObject * /*Sender*/)
  579. {
  580. assert(ProfilesView->Selected);
  581. TTreeNode * Node = ProfilesView->Selected;
  582. AnsiString Name = Node->Text;
  583. if (InputDialog(LoadStr(RENAME_BOOKMARK_CAPTION), LoadStr(RENAME_BOOKMARK_PROMPT),
  584. Name, HELP_LOCATION_PROFILE_RENAME) && (Name != Node->Text))
  585. {
  586. if (Node->Data)
  587. {
  588. if (Name.IsEmpty() || (StrToIntDef(Name, -123) != -123))
  589. {
  590. throw Exception(FMTLOAD(BOOKMARK_INVALID_NAME, (Name)));
  591. }
  592. // raises exception in case of duplicate name??
  593. ((TBookmark *)Node->Data)->Name = Name;
  594. Node->Text = Name;
  595. }
  596. else
  597. {
  598. if (Name.IsEmpty() || Name.Pos("\\"))
  599. {
  600. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (Name)));
  601. }
  602. if ((FFolders->IndexOf(Name) >= 0) && AnsiCompareText(Name, Node->Text))
  603. {
  604. throw Exception(FMTLOAD(DUPLICATE_BOOKMARK_FOLDER, (Name)));
  605. }
  606. assert(Node->Count);
  607. FFolders->Delete(FFolders->IndexOf(Node->Text));
  608. int I = FFolders->AddObject(Name, Node);
  609. TTreeNode * NextNode;
  610. // duplicated in MoveToButtonClick()
  611. if (I < FFolders->Count-1)
  612. {
  613. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  614. assert(NextNode);
  615. }
  616. else if (FFolders->Count > 1)
  617. {
  618. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  619. }
  620. else
  621. {
  622. assert(ProfilesView->Items->Count);
  623. NextNode = ProfilesView->Items->Item[0];
  624. }
  625. if (NextNode != Node)
  626. {
  627. Node->MoveTo(NextNode, NextNode ? naInsert : naAddChild);
  628. }
  629. Node->Text = Name;
  630. for (int i = 0; i < Node->Count; i++)
  631. {
  632. ((TBookmark *)Node->Item[i]->Data)->Node = Name;
  633. }
  634. Node->MakeVisible();
  635. }
  636. }
  637. UpdateControls();
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TLocationProfilesDialog::ProfilesViewGetImageIndex(
  641. TObject * /*Sender*/, TTreeNode * Node)
  642. {
  643. Node->ImageIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  644. }
  645. //---------------------------------------------------------------------------
  646. void __fastcall TLocationProfilesDialog::ProfilesViewGetSelectedIndex(
  647. TObject * /*Sender*/, TTreeNode * Node)
  648. {
  649. Node->SelectedIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  650. }
  651. //---------------------------------------------------------------------------
  652. void __fastcall TLocationProfilesDialog::LocalDirectoryBrowseButtonClick(
  653. TObject * /*Sender*/)
  654. {
  655. AnsiString Directory = LocalDirectoryEdit->Text;
  656. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
  657. {
  658. LocalDirectoryEdit->Text = Directory;
  659. DirectoryEditChange(LocalDirectoryEdit);
  660. }
  661. }
  662. //---------------------------------------------------------------------------
  663. void __fastcall TLocationProfilesDialog::SwitchButtonClick(TObject * /*Sender*/)
  664. {
  665. WinConfiguration->UseLocationProfiles = false;
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TLocationProfilesDialog::HelpButtonClick(TObject * /*Sender*/)
  669. {
  670. FormHelp(this);
  671. }
  672. //---------------------------------------------------------------------------
  673. void __fastcall TLocationProfilesDialog::ProfilesViewCollapsed(
  674. TObject * /*Sender*/, TTreeNode * Node)
  675. {
  676. assert(Node != NULL);
  677. assert(Node->Data == NULL);
  678. FBookmarkList->NodeOpened[Node->Text] = false;
  679. }
  680. //---------------------------------------------------------------------------
  681. void __fastcall TLocationProfilesDialog::ProfilesViewExpanded(
  682. TObject * /*Sender*/, TTreeNode * Node)
  683. {
  684. assert(Node != NULL);
  685. assert(Node->Data == NULL);
  686. FBookmarkList->NodeOpened[Node->Text] = true;
  687. }
  688. //---------------------------------------------------------------------------