LocationProfiles.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. }
  196. }
  197. //---------------------------------------------------------------------------
  198. bool __fastcall TLocationProfilesDialog::Execute()
  199. {
  200. bool Result;
  201. AnsiString SessionKey;
  202. if (Terminal)
  203. {
  204. TBookmarkList * BookmarkList;
  205. // cache session key, in case terminal is closed while the window is open
  206. SessionKey = Terminal->SessionData->SessionKey;
  207. BookmarkList = WinConfiguration->Bookmarks[SessionKey];
  208. if (BookmarkList)
  209. {
  210. FBookmarkList->Assign(BookmarkList);
  211. }
  212. else
  213. {
  214. FBookmarkList->Clear();
  215. }
  216. LoadBookmarks();
  217. }
  218. Result = ((Mode != odAddBookmark) || AddAsBookmark()) && (ShowModal() == mrOk);
  219. if (Terminal)
  220. {
  221. WinConfiguration->Bookmarks[SessionKey] = FBookmarkList;
  222. }
  223. return Result;
  224. }
  225. //---------------------------------------------------------------------------
  226. bool __fastcall TLocationProfilesDialog::AddAsBookmark()
  227. {
  228. assert(!LocalDirectory.IsEmpty() || !RemoteDirectory.IsEmpty());
  229. bool Result;
  230. AnsiString BookmarkName;
  231. if ((OperationSide == osLocal && !LocalDirectory.IsEmpty()) ||
  232. RemoteDirectory.IsEmpty())
  233. {
  234. BookmarkName = LocalDirectory;
  235. }
  236. else
  237. {
  238. BookmarkName = RemoteDirectory;
  239. }
  240. Result = InputDialog(LoadStr(ADD_BOOKMARK_CAPTION), LoadStr(ADD_BOOKMARK_PROMPT),
  241. BookmarkName, HELP_LOCATION_PROFILE_ADD);
  242. if (Result)
  243. {
  244. if (BookmarkName.IsEmpty() || (StrToIntDef(BookmarkName, -123) != -123))
  245. {
  246. throw Exception(FMTLOAD(BOOKMARK_INVALID_NAME, (BookmarkName)));
  247. }
  248. TBookmark * Bookmark = new TBookmark();
  249. Bookmark->Name = BookmarkName;
  250. Bookmark->Local = LocalDirectory;
  251. Bookmark->Remote = RemoteDirectory;
  252. TTreeNode * Selected = ProfilesView->Selected;
  253. if (Selected && Selected->Data)
  254. {
  255. TBookmark * SelectedBookmark = (TBookmark *)Selected->Data;
  256. Bookmark->Node = SelectedBookmark->Node;
  257. FBookmarkList->InsertBefore(SelectedBookmark, Bookmark);
  258. Selected = ProfilesView->Items->InsertObject(Selected, Bookmark->Name, Bookmark);
  259. }
  260. else if (Selected && !Selected->Data)
  261. {
  262. // must be a folder
  263. assert(!Selected->Parent); // more than one level of folders is not supported
  264. Bookmark->Node = Selected->Text;
  265. FBookmarkList->Add(Bookmark);
  266. Selected = ProfilesView->Items->AddChildObject(Selected, Bookmark->Name, Bookmark);
  267. }
  268. else
  269. {
  270. FBookmarkList->Add(Bookmark);
  271. Selected = ProfilesView->Items->AddObject(NULL, Bookmark->Name, Bookmark);
  272. }
  273. ProfilesView->Selected = Selected;
  274. }
  275. UpdateControls();
  276. return Result;
  277. }
  278. //---------------------------------------------------------------------------
  279. void __fastcall TLocationProfilesDialog::AddBookmarkButtonClick(TObject */*Sender*/)
  280. {
  281. AddAsBookmark();
  282. }
  283. //---------------------------------------------------------------------------
  284. void __fastcall TLocationProfilesDialog::RemoveBookmarkButtonClick(TObject * /*Sender*/)
  285. {
  286. assert(ProfilesView->Selected);
  287. TTreeNode * Node = ProfilesView->Selected;
  288. if (Node->Data)
  289. {
  290. FBookmarkList->Delete((TBookmark *)Node->Data);
  291. TTreeNode * ParentNode = Node->Parent;
  292. Node->Delete();
  293. if (ParentNode && !ParentNode->Count)
  294. {
  295. assert(FFolders->IndexOfObject(ParentNode) >= 0);
  296. FFolders->Delete(FFolders->IndexOfObject(ParentNode));
  297. ParentNode->Delete();
  298. }
  299. }
  300. else
  301. {
  302. if (MessageDialog(LoadStr(DELETE_BOOKMARK_FOLDER), qtConfirmation,
  303. qaYes | qaNo, HELP_LOCATION_PROFILE_DELETE) == qaYes)
  304. {
  305. assert(Node->Count);
  306. for (int i = 0; i < Node->Count; i++)
  307. {
  308. FBookmarkList->Delete((TBookmark *)Node->Item[i]->Data);
  309. }
  310. assert(FFolders->IndexOfObject(Node) >= 0);
  311. FFolders->Delete(FFolders->IndexOfObject(Node));
  312. Node->Delete();
  313. }
  314. }
  315. UpdateControls();
  316. }
  317. //---------------------------------------------------------------------------
  318. void __fastcall TLocationProfilesDialog::BookmarkMove(
  319. TTreeNode * Source, TTreeNode * Dest)
  320. {
  321. assert(Source && Source->Data);
  322. TBookmark * Bookmark = (TBookmark *)Source->Data;
  323. TTreeNode * PrevFolderNode = Source->Parent;
  324. if (!Dest || !Dest->Data)
  325. {
  326. Bookmark->Node = Dest ? Dest->Text : AnsiString("");
  327. FBookmarkList->MoveTo(FBookmarkList->Bookmarks[FBookmarkList->Count - 1],
  328. Bookmark, false);
  329. ProfilesView->Selected->MoveTo(Dest, naAddChild);
  330. }
  331. else
  332. {
  333. TBookmark * DestBookmark = (TBookmark *)Dest->Data;
  334. Bookmark->Node = DestBookmark->Node;
  335. FBookmarkList->MoveTo(DestBookmark, Bookmark,
  336. Source->AbsoluteIndex > Dest->AbsoluteIndex);
  337. if (Source->AbsoluteIndex > Dest->AbsoluteIndex)
  338. {
  339. Source->MoveTo(Dest, naInsert);
  340. }
  341. else if (Dest->getNextSibling() != NULL)
  342. {
  343. Source->MoveTo(Dest->getNextSibling(), naInsert);
  344. }
  345. else
  346. {
  347. Source->MoveTo(Dest, naAdd);
  348. }
  349. }
  350. if (PrevFolderNode && !PrevFolderNode->Count)
  351. {
  352. assert(FFolders->IndexOfObject(PrevFolderNode) >= 0);
  353. FFolders->Delete(FFolders->IndexOfObject(PrevFolderNode));
  354. PrevFolderNode->Delete();
  355. }
  356. Source->MakeVisible();
  357. UpdateControls();
  358. }
  359. //---------------------------------------------------------------------------
  360. void __fastcall TLocationProfilesDialog::BookmarkButtonClick(TObject *Sender)
  361. {
  362. TTreeNode * Node = ProfilesView->Selected;
  363. assert(Node);
  364. assert(Node->Data);
  365. TTreeNode * TargetNode;
  366. if (Sender == UpBookmarkButton)
  367. {
  368. TargetNode = Node->getPrevSibling();
  369. assert(TargetNode);
  370. }
  371. else
  372. {
  373. TargetNode = Node->getNextSibling();
  374. }
  375. BookmarkMove(Node, TargetNode ? TargetNode : Node->Parent);
  376. }
  377. //---------------------------------------------------------------------------
  378. void __fastcall TLocationProfilesDialog::ProfilesViewStartDrag(
  379. TObject * /*Sender*/ , TDragObject *& /*DragObject*/)
  380. {
  381. if (!ProfilesView->Selected->Data)
  382. {
  383. Abort();
  384. }
  385. FBookmarkDragSource = ProfilesView->Selected;
  386. }
  387. //---------------------------------------------------------------------------
  388. void __fastcall TLocationProfilesDialog::ProfilesViewDragOver(
  389. TObject */*Sender*/, TObject *Source, int /*X*/, int /*Y*/,
  390. TDragState /*State*/, bool &Accept)
  391. {
  392. if (Source == ProfilesView)
  393. {
  394. Accept = (ProfilesView->DropTarget != NULL) &&
  395. (FBookmarkDragSource != ProfilesView->DropTarget);
  396. }
  397. }
  398. //---------------------------------------------------------------------------
  399. void __fastcall TLocationProfilesDialog::ProfilesViewDragDrop(
  400. TObject * /*Sender*/, TObject * Source, int /*X*/, int /*Y*/)
  401. {
  402. if ((Source == ProfilesView) && (ProfilesView->DropTarget != NULL) &&
  403. (FBookmarkDragSource != ProfilesView->DropTarget))
  404. {
  405. assert(FBookmarkDragSource);
  406. TTreeNode * Target = ProfilesView->DropTarget;
  407. BookmarkMove(FBookmarkDragSource, Target);
  408. FBookmarkDragSource = NULL;
  409. }
  410. }
  411. //---------------------------------------------------------------------------
  412. void __fastcall TLocationProfilesDialog::ProfilesViewDblClick(TObject * /*Sender*/)
  413. {
  414. TPoint P = ProfilesView->ScreenToClient(Mouse->CursorPos);
  415. TTreeNode * Node = ProfilesView->GetNodeAt(P.x, P.y);
  416. if (OKBtn->Enabled && Node && Node->Data && Node->Selected)
  417. {
  418. ModalResult = mrOk;
  419. }
  420. }
  421. //---------------------------------------------------------------------------
  422. void __fastcall TLocationProfilesDialog::FormShow(TObject * /*Sender*/)
  423. {
  424. FindProfile();
  425. if (OperationSide == osLocal)
  426. {
  427. LocalDirectoryEdit->SetFocus();
  428. }
  429. else
  430. {
  431. RemoteDirectoryEdit->SetFocus();
  432. }
  433. UpdateControls();
  434. }
  435. //---------------------------------------------------------------------------
  436. void __fastcall TLocationProfilesDialog::ProfilesViewKeyDown(TObject * /*Sender*/,
  437. WORD &Key, TShiftState /*Shift*/)
  438. {
  439. if (RemoveBookmarkButton->Enabled && (Key == VK_DELETE))
  440. {
  441. RemoveBookmarkButtonClick(NULL);
  442. }
  443. }
  444. //---------------------------------------------------------------------------
  445. void __fastcall TLocationProfilesDialog::DirectoryEditChange(
  446. TObject * /*Sender*/)
  447. {
  448. if (!FChanging)
  449. {
  450. FindProfile();
  451. UpdateControls();
  452. }
  453. }
  454. //---------------------------------------------------------------------------
  455. void __fastcall TLocationProfilesDialog::ProfilesViewChange(
  456. TObject * /*Sender*/, TTreeNode * Node)
  457. {
  458. if (Node && Node->Data)
  459. {
  460. assert(!FChanging);
  461. FChanging = true;
  462. try
  463. {
  464. LocalDirectoryEdit->Text = ((TBookmark *)Node->Data)->Local;
  465. RemoteDirectoryEdit->Text = ((TBookmark *)Node->Data)->Remote;
  466. }
  467. __finally
  468. {
  469. FChanging = false;
  470. }
  471. }
  472. UpdateControls();
  473. }
  474. //---------------------------------------------------------------------------
  475. void __fastcall TLocationProfilesDialog::MoveToButtonClick(TObject * /*Sender*/)
  476. {
  477. assert(ProfilesView->Selected->Data);
  478. TBookmark * Bookmark = (TBookmark *)ProfilesView->Selected->Data;
  479. AnsiString Name = Bookmark->Node;
  480. if (DoComboInputDialog(LoadStr(MOVE_BOOKMARK_CAPTION), LoadStr(MOVE_BOOKMARK_PROMPT),
  481. Name, FFolders, NULL, true, HELP_LOCATION_PROFILE_MOVE) &&
  482. (Name != Bookmark->Node))
  483. {
  484. if (Name.Pos("\\"))
  485. {
  486. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (Name)));
  487. }
  488. TTreeNode * FolderNode;
  489. int I = FFolders->IndexOf(Name);
  490. if (Name.IsEmpty())
  491. {
  492. FolderNode = NULL;
  493. }
  494. else if (I >= 0)
  495. {
  496. FolderNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I]);
  497. assert(FolderNode);
  498. }
  499. else
  500. {
  501. I = FFolders->Add(Name);
  502. TTreeNode * NextNode;
  503. // duplicated in RenameButtonClick()
  504. if (I < FFolders->Count-1)
  505. {
  506. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  507. assert(NextNode);
  508. }
  509. else if (FFolders->Count > 1)
  510. {
  511. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  512. }
  513. else
  514. {
  515. assert(ProfilesView->Items->Count);
  516. NextNode = ProfilesView->Items->Item[0];
  517. }
  518. FolderNode = ProfilesView->Items->Insert(NextNode, Name);
  519. assert(FolderNode);
  520. FFolders->Objects[I] = FolderNode;
  521. }
  522. BookmarkMove(ProfilesView->Selected, FolderNode);
  523. }
  524. }
  525. //---------------------------------------------------------------------------
  526. void __fastcall TLocationProfilesDialog::RenameButtonClick(TObject * /*Sender*/)
  527. {
  528. assert(ProfilesView->Selected);
  529. TTreeNode * Node = ProfilesView->Selected;
  530. AnsiString Name = Node->Text;
  531. if (InputDialog(LoadStr(RENAME_BOOKMARK_CAPTION), LoadStr(RENAME_BOOKMARK_PROMPT),
  532. Name, HELP_LOCATION_PROFILE_RENAME) && (Name != Node->Text))
  533. {
  534. if (Node->Data)
  535. {
  536. if (Name.IsEmpty() || (StrToIntDef(Name, -123) != -123))
  537. {
  538. throw Exception(FMTLOAD(BOOKMARK_INVALID_NAME, (Name)));
  539. }
  540. // raises exception in case of duplicate name??
  541. ((TBookmark *)Node->Data)->Name = Name;
  542. Node->Text = Name;
  543. }
  544. else
  545. {
  546. if (Name.IsEmpty() || Name.Pos("\\"))
  547. {
  548. throw Exception(FMTLOAD(BOOKMARK_FOLDER_INVALID_NAME, (Name)));
  549. }
  550. if ((FFolders->IndexOf(Name) >= 0) && AnsiCompareText(Name, Node->Text))
  551. {
  552. throw Exception(FMTLOAD(DUPLICATE_BOOKMARK_FOLDER, (Name)));
  553. }
  554. assert(Node->Count);
  555. FFolders->Delete(FFolders->IndexOf(Node->Text));
  556. int I = FFolders->AddObject(Name, Node);
  557. TTreeNode * NextNode;
  558. // duplicated in MoveToButtonClick()
  559. if (I < FFolders->Count-1)
  560. {
  561. NextNode = dynamic_cast<TTreeNode *>(FFolders->Objects[I+1]);
  562. assert(NextNode);
  563. }
  564. else if (FFolders->Count > 1)
  565. {
  566. NextNode = (dynamic_cast<TTreeNode *>(FFolders->Objects[I-1]))->getNextSibling();
  567. }
  568. else
  569. {
  570. assert(ProfilesView->Items->Count);
  571. NextNode = ProfilesView->Items->Item[0];
  572. }
  573. if (NextNode != Node)
  574. {
  575. Node->MoveTo(NextNode, NextNode ? naInsert : naAddChild);
  576. }
  577. Node->Text = Name;
  578. for (int i = 0; i < Node->Count; i++)
  579. {
  580. ((TBookmark *)Node->Item[i]->Data)->Node = Name;
  581. }
  582. Node->MakeVisible();
  583. }
  584. }
  585. UpdateControls();
  586. }
  587. //---------------------------------------------------------------------------
  588. void __fastcall TLocationProfilesDialog::ProfilesViewGetImageIndex(
  589. TObject * /*Sender*/, TTreeNode * Node)
  590. {
  591. Node->ImageIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  592. }
  593. //---------------------------------------------------------------------------
  594. void __fastcall TLocationProfilesDialog::ProfilesViewGetSelectedIndex(
  595. TObject * /*Sender*/, TTreeNode * Node)
  596. {
  597. Node->SelectedIndex = Node->Data ? 0 : (Node->Expanded ? 1 : 2);
  598. }
  599. //---------------------------------------------------------------------------
  600. void __fastcall TLocationProfilesDialog::LocalDirectoryBrowseButtonClick(
  601. TObject * /*Sender*/)
  602. {
  603. AnsiString Directory = LocalDirectoryEdit->Text;
  604. if (SelectDirectory(Directory, LoadStr(SELECT_LOCAL_DIRECTORY), true))
  605. {
  606. LocalDirectoryEdit->Text = Directory;
  607. DirectoryEditChange(LocalDirectoryEdit);
  608. }
  609. }
  610. //---------------------------------------------------------------------------
  611. void __fastcall TLocationProfilesDialog::SwitchButtonClick(TObject * /*Sender*/)
  612. {
  613. WinConfiguration->UseLocationProfiles = false;
  614. }
  615. //---------------------------------------------------------------------------
  616. void __fastcall TLocationProfilesDialog::HelpButtonClick(TObject * /*Sender*/)
  617. {
  618. FormHelp(this);
  619. }
  620. //---------------------------------------------------------------------------