LocationProfiles.cpp 23 KB

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