Properties.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. //---------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "WinInterface.h"
  5. #include "Properties.h"
  6. #include <VCLCommon.h>
  7. #include <Common.h>
  8. #include <Terminal.h>
  9. #include <TextsWin.h>
  10. #include <GUITools.h>
  11. #include <CoreMain.h>
  12. #include <Tools.h>
  13. #include <BaseUtils.hpp>
  14. //---------------------------------------------------------------------
  15. #pragma link "PathLabel"
  16. #pragma link "Rights"
  17. #pragma link "RightsExt"
  18. #ifndef NO_RESOURCES
  19. #pragma resource "*.dfm"
  20. #endif
  21. //---------------------------------------------------------------------
  22. bool __fastcall DoPropertiesDialog(TStrings * FileList,
  23. const UnicodeString Directory, const TRemoteTokenList * GroupList,
  24. const TRemoteTokenList * UserList, TRemoteProperties * Properties,
  25. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  26. TCalculateChecksumEvent OnCalculateChecksum)
  27. {
  28. bool Result;
  29. TPropertiesDialog * PropertiesDialog = new TPropertiesDialog(Application,
  30. FileList, Directory, GroupList, UserList, AllowedChanges, UserGroupByID,
  31. OnCalculateSize, OnCalculateChecksum);
  32. try
  33. {
  34. Result = PropertiesDialog->Execute(*Properties);
  35. }
  36. __finally
  37. {
  38. delete PropertiesDialog;
  39. }
  40. return Result;
  41. }
  42. //---------------------------------------------------------------------
  43. __fastcall TPropertiesDialog::TPropertiesDialog(TComponent* AOwner,
  44. TStrings * FileList, const UnicodeString Directory,
  45. const TRemoteTokenList * GroupList, const TRemoteTokenList * UserList,
  46. int AllowedChanges, bool UserGroupByID, TCalculateSizeEvent OnCalculateSize,
  47. TCalculateChecksumEvent OnCalculateChecksum)
  48. : TForm(AOwner)
  49. {
  50. FOnCalculateSize = OnCalculateSize;
  51. FOnCalculateChecksum = OnCalculateChecksum;
  52. RightsFrame->OnChange = ControlChange;
  53. FShellImageList = SharedSystemImageList(true);
  54. FShellImageList->DrawingStyle = dsTransparent;
  55. FFileList = new TStringList();
  56. FFileList->Assign(FileList);
  57. FAllowedChanges = AllowedChanges;
  58. FUserGroupByID = UserGroupByID;
  59. FAllowCalculateStats = false;
  60. FStatsNotCalculated = false;
  61. FChecksumLoaded = false;
  62. FMultipleChecksum = false;
  63. LocationLabel->Caption = Directory;
  64. FGroupList = GroupList;
  65. FUserList = UserList;
  66. LoadInfo();
  67. UseSystemSettings(this);
  68. }
  69. //---------------------------------------------------------------------------
  70. __fastcall TPropertiesDialog::~TPropertiesDialog()
  71. {
  72. delete FFileList;
  73. FFileList = NULL;
  74. delete FShellImageList;
  75. FShellImageList = NULL;
  76. }
  77. //---------------------------------------------------------------------
  78. bool __fastcall TPropertiesDialog::Execute(TRemoteProperties & Properties)
  79. {
  80. SetFileProperties(Properties);
  81. PageControl->ActivePage = CommonSheet;
  82. if (FAllowedChanges & cpGroup) ActiveControl = GroupComboBox;
  83. else
  84. if (FAllowedChanges & cpOwner) ActiveControl = OwnerComboBox;
  85. else
  86. if (FAllowedChanges & cpMode) ActiveControl = RightsFrame;
  87. else ActiveControl = CancelButton;
  88. ChecksumAlgEdit->Text = GUIConfiguration->ChecksumAlg;
  89. ResetChecksum();
  90. UpdateControls();
  91. bool Result = (ShowModal() == DefaultResult(this));
  92. if (Result)
  93. {
  94. Properties = GetFileProperties();
  95. }
  96. GUIConfiguration->ChecksumAlg = ChecksumAlgEdit->Text;
  97. return Result;
  98. }
  99. //---------------------------------------------------------------------------
  100. UnicodeString __fastcall TPropertiesDialog::LoadRemoteToken(
  101. const TRemoteToken & Token)
  102. {
  103. UnicodeString Result;
  104. if (FUserGroupByID)
  105. {
  106. if (Token.IDValid)
  107. {
  108. if (Token.NameValid)
  109. {
  110. Result = FORMAT(L"%s [%d]", (Token.Name, int(Token.ID)));
  111. }
  112. else
  113. {
  114. Result = FORMAT(L"[%d]", (int(Token.ID)));
  115. }
  116. }
  117. else
  118. {
  119. // be it valid or not
  120. Result = Token.Name;
  121. }
  122. }
  123. else
  124. {
  125. // what if name is not filled in?
  126. Result = Token.Name;
  127. }
  128. return Result;
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TPropertiesDialog::LoadRemoteToken(
  132. TComboBox * ComboBox, bool Valid, const TRemoteToken & Token)
  133. {
  134. if (Valid)
  135. {
  136. ComboBox->Text = LoadRemoteToken(Token);
  137. }
  138. else
  139. {
  140. ComboBox->Text = L"";
  141. }
  142. }
  143. //---------------------------------------------------------------------------
  144. void __fastcall TPropertiesDialog::LoadRemoteTokens(TComboBox * ComboBox,
  145. const TRemoteTokenList * List)
  146. {
  147. TStrings * Items = ComboBox->Items;
  148. Items->BeginUpdate();
  149. try
  150. {
  151. Items->Clear();
  152. if (List != NULL)
  153. {
  154. int Count = List->Count();
  155. for (int Index = 0; Index < Count; Index++)
  156. {
  157. Items->Add(LoadRemoteToken(*List->Token(Index)));
  158. }
  159. }
  160. }
  161. __finally
  162. {
  163. Items->EndUpdate();
  164. }
  165. }
  166. //---------------------------------------------------------------------------
  167. void __fastcall TPropertiesDialog::LoadInfo()
  168. {
  169. assert(FFileList->Count > 0);
  170. FMultiple = FFileList->Count > 1;
  171. FMultipleChecksum = FMultiple;
  172. FAllowCalculateStats = false;
  173. FStatsNotCalculated = false;
  174. __int64 FilesSize = 0;
  175. TCalculateSizeStats Stats;
  176. for (int Index = 0; Index < FFileList->Count; Index++)
  177. {
  178. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[Index]);
  179. if (File->IsDirectory)
  180. {
  181. Stats.Directories++;
  182. if (!File->IsSymLink)
  183. {
  184. FAllowCalculateStats = true;
  185. FStatsNotCalculated = true;
  186. FMultipleChecksum = true;
  187. }
  188. }
  189. else
  190. {
  191. Stats.Files++;
  192. }
  193. if (File->IsSymLink)
  194. {
  195. Stats.SymLinks++;
  196. }
  197. FilesSize += File->Size;
  198. }
  199. LoadRemoteTokens(GroupComboBox, FGroupList);
  200. LoadRemoteTokens(OwnerComboBox, FUserList);
  201. RightsFrame->AllowAddXToDirectories = (Stats.Directories > 0);
  202. RecursiveCheck->Visible = (Stats.Directories > 0);
  203. RecursiveBevel->Visible = (Stats.Directories > 0);
  204. LoadStats(FilesSize, Stats);
  205. FileIconImage->Picture->Bitmap = NULL;
  206. RightsFrame->AllowUndef = FMultiple;
  207. if (!FMultiple)
  208. {
  209. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  210. assert(File && FShellImageList);
  211. // shell image list does not have fixed large icon size
  212. // (it is probably 32x32 min, but can be larged, on xp it is 48x48 if
  213. // large icons are enabled, on vista can be even larger).
  214. // so we stretch (shrink) the icon to 32x32 here to be sure.
  215. Graphics::TBitmap * Bitmap = new Graphics::TBitmap;
  216. try
  217. {
  218. FShellImageList->GetBitmap(File->IconIndex, Bitmap);
  219. FileIconImage->Picture->Bitmap->Width = FileIconImage->Width;
  220. FileIconImage->Picture->Bitmap->Height = FileIconImage->Height;
  221. FileIconImage->Picture->Bitmap->Canvas->StretchDraw(
  222. TRect(0, 0, FileIconImage->Width, FileIconImage->Height),
  223. Bitmap);
  224. }
  225. __finally
  226. {
  227. delete Bitmap;
  228. }
  229. LinksToLabelLabel->Visible = File->IsSymLink;
  230. LinksToLabel->Visible = File->IsSymLink;
  231. if (File->IsSymLink)
  232. {
  233. LinksToLabel->Caption = File->LinkTo;
  234. }
  235. RightsFrame->AllowAddXToDirectories = File->IsDirectory;
  236. Caption = FMTLOAD(PROPERTIES_FILE_CAPTION, (File->FileName));
  237. RecursiveCheck->Visible = File->IsDirectory;
  238. RecursiveBevel->Visible = File->IsDirectory;
  239. }
  240. else
  241. {
  242. Caption = FMTLOAD(PROPERTIES_FILES_CAPTION, (FFileList->Strings[0]));
  243. LinksToLabelLabel->Hide();
  244. LinksToLabel->Hide();
  245. }
  246. FilesIconImage->Visible = FMultiple;
  247. FileIconImage->Visible = !FMultiple;
  248. ChecksumGroup->Visible = !FMultipleChecksum;
  249. ChecksumView->Visible = FMultipleChecksum;
  250. }
  251. //---------------------------------------------------------------------------
  252. void __fastcall TPropertiesDialog::LoadStats(__int64 FilesSize,
  253. const TCalculateSizeStats & Stats)
  254. {
  255. UnicodeString SizeStr;
  256. UnicodeString FilesStr;
  257. if (FStatsNotCalculated)
  258. {
  259. SizeStr = LoadStr(PROPERTIES_UNKNOWN_SIZE);
  260. }
  261. else
  262. {
  263. SizeStr = FormatBytes(FilesSize);
  264. UnicodeString SizeUnorderedStr = FormatBytes(FilesSize, false);
  265. if (SizeStr != SizeUnorderedStr)
  266. {
  267. SizeStr = FORMAT(L"%s (%s)", (SizeStr, SizeUnorderedStr));
  268. }
  269. }
  270. if (((Stats.Files + Stats.Directories) == 0) && !FMultiple)
  271. {
  272. TRemoteFile * File = (TRemoteFile *)(FFileList->Objects[0]);
  273. assert(File != NULL);
  274. FilesStr = File->FileName;
  275. }
  276. else
  277. {
  278. if (Stats.Files > 0)
  279. {
  280. FilesStr = (Stats.Files == 1) ? FMTLOAD(PROPERTIES_FILE, (Stats.Files)) :
  281. FMTLOAD(PROPERTIES_FILES, (Stats.Files));
  282. if (Stats.Directories > 0)
  283. {
  284. FilesStr = FORMAT(L"%s, ", (FilesStr));
  285. }
  286. }
  287. if (Stats.Directories > 0)
  288. {
  289. FilesStr += (Stats.Directories == 1) ? FMTLOAD(PROPERTIES_DIRECTORY, (Stats.Directories)) :
  290. FMTLOAD(PROPERTIES_DIRECTORIES, (Stats.Directories));
  291. }
  292. if (Stats.SymLinks > 0)
  293. {
  294. UnicodeString SymLinksStr;
  295. SymLinksStr = (Stats.SymLinks == 1) ? FMTLOAD(PROPERTIES_SYMLINK, (Stats.SymLinks)) :
  296. FMTLOAD(PROPERTIES_SYMLINKS, (Stats.SymLinks));
  297. FilesStr = FORMAT(L"%s (%s)", (FilesStr, SymLinksStr));
  298. }
  299. }
  300. SizeLabel->Caption = SizeStr;
  301. FileLabel->Caption = FilesStr;
  302. }
  303. //---------------------------------------------------------------------------
  304. void __fastcall TPropertiesDialog::SetFileProperties(const TRemoteProperties & value)
  305. {
  306. TValidProperties Valid;
  307. if (value.Valid.Contains(vpRights) && FAllowedChanges & cpMode) Valid << vpRights;
  308. if (value.Valid.Contains(vpOwner) && FAllowedChanges & cpOwner) Valid << vpOwner;
  309. if (value.Valid.Contains(vpGroup) && FAllowedChanges & cpGroup) Valid << vpGroup;
  310. FOrigProperties = value;
  311. FOrigProperties.Valid = Valid;
  312. FOrigProperties.Recursive = false;
  313. if (value.Valid.Contains(vpRights))
  314. {
  315. RightsFrame->Rights = value.Rights;
  316. RightsFrame->AddXToDirectories = value.AddXToDirectories;
  317. }
  318. else
  319. {
  320. RightsFrame->Rights = TRights();
  321. RightsFrame->AddXToDirectories = false;
  322. }
  323. LoadRemoteToken(GroupComboBox, value.Valid.Contains(vpGroup), value.Group);
  324. LoadRemoteToken(OwnerComboBox, value.Valid.Contains(vpOwner), value.Owner);
  325. RecursiveCheck->Checked = value.Recursive;
  326. UpdateControls();
  327. }
  328. //---------------------------------------------------------------------------
  329. void __fastcall TPropertiesDialog::StoreRemoteToken(unsigned int ID,
  330. const UnicodeString & Text, const TRemoteTokenList * List, TRemoteToken & Result)
  331. {
  332. assert(List != NULL);
  333. const TRemoteToken * Token = List->Find(ID);
  334. if (Token == NULL)
  335. {
  336. Result.ID = ID;
  337. Result.Name = Text;
  338. }
  339. else
  340. {
  341. Result = *Token;
  342. }
  343. }
  344. //---------------------------------------------------------------------------
  345. TRemoteToken __fastcall TPropertiesDialog::StoreRemoteToken(const TRemoteToken & Orig,
  346. UnicodeString Text, int Message, const TRemoteTokenList * List)
  347. {
  348. TRemoteToken Result;
  349. Text = Text.Trim();
  350. if (!Text.IsEmpty())
  351. {
  352. if (FUserGroupByID)
  353. {
  354. assert(List != NULL);
  355. int IDStart = Text.LastDelimiter(L"[");
  356. if (!Text.IsEmpty() && (IDStart >= 0) && (Text[Text.Length()] == L']'))
  357. {
  358. int ID;
  359. UnicodeString IDStr = Text.SubString(IDStart + 1, Text.Length() - IDStart - 1);
  360. if (!TryStrToInt(IDStr, ID))
  361. {
  362. throw Exception(Message);
  363. }
  364. else
  365. {
  366. StoreRemoteToken(ID, Text.SubString(1, IDStart - 1).Trim(), List, Result);
  367. }
  368. }
  369. else
  370. {
  371. const TRemoteToken * Token = List->Find(Text);
  372. if (Token == NULL)
  373. {
  374. int ID;
  375. if (TryStrToInt(Text, ID))
  376. {
  377. StoreRemoteToken(ID, Text, List, Result);
  378. }
  379. else
  380. {
  381. throw Exception(MainInstructions(FMTLOAD(PROPERTIES_UNKNOWN_TOKEN, (Text))));
  382. }
  383. }
  384. else
  385. {
  386. Result = *Token;
  387. }
  388. }
  389. }
  390. else
  391. {
  392. Result.Name = Text;
  393. }
  394. }
  395. if (LoadRemoteToken(Result) == LoadRemoteToken(Orig))
  396. {
  397. Result = Orig;
  398. }
  399. return Result;
  400. }
  401. //---------------------------------------------------------------------------
  402. void __fastcall TPropertiesDialog::StoreRemoteToken(TComboBox * ComboBox,
  403. int ChangeFlag, TValidProperty PropertyFlag, const TRemoteToken & Orig,
  404. TRemoteToken & Token, int Message, const TRemoteTokenList * List,
  405. TRemoteProperties & Properties)
  406. {
  407. UnicodeString Text = ComboBox->Text.Trim();
  408. if (FLAGSET(FAllowedChanges, ChangeFlag))
  409. {
  410. Token = StoreRemoteToken(Orig, Text, Message, List);
  411. if (Token.IsSet)
  412. {
  413. Properties.Valid << PropertyFlag;
  414. }
  415. }
  416. }
  417. //---------------------------------------------------------------------------
  418. TRemoteProperties __fastcall TPropertiesDialog::GetFileProperties()
  419. {
  420. TRemoteProperties Result;
  421. if (FAllowedChanges & cpMode)
  422. {
  423. Result.Valid << vpRights;
  424. Result.Rights = RightsFrame->Rights;
  425. Result.AddXToDirectories = RightsFrame->AddXToDirectories;
  426. }
  427. StoreRemoteToken(GroupComboBox, cpGroup, vpGroup, FOrigProperties.Group,
  428. Result.Group, PROPERTIES_INVALID_GROUP, FGroupList, Result);
  429. StoreRemoteToken(OwnerComboBox, cpOwner, vpOwner, FOrigProperties.Owner,
  430. Result.Owner, PROPERTIES_INVALID_OWNER, FUserList, Result);
  431. Result.Recursive = RecursiveCheck->Checked;
  432. return Result;
  433. }
  434. //---------------------------------------------------------------------------
  435. void __fastcall TPropertiesDialog::ControlChange(TObject * /*Sender*/)
  436. {
  437. if (Visible)
  438. {
  439. UpdateControls();
  440. }
  441. }
  442. //---------------------------------------------------------------------------
  443. void __fastcall TPropertiesDialog::UpdateControls()
  444. {
  445. bool Allow;
  446. try
  447. {
  448. Allow =
  449. !TRemoteProperties::ChangedProperties(FOrigProperties, GetFileProperties()).Valid.Empty() ||
  450. RecursiveCheck->Checked;
  451. }
  452. catch(...)
  453. {
  454. // when properties are invalid allow submitting the form,
  455. // because that reveals the cause to the user, otherwise he/she
  456. // may not be able to tell what is wrong
  457. Allow = true;
  458. }
  459. EnableControl(OkButton, Allow);
  460. EnableControl(GroupComboBox, FAllowedChanges & cpGroup);
  461. EnableControl(OwnerComboBox, FAllowedChanges & cpOwner);
  462. EnableControl(RightsFrame, FAllowedChanges & cpMode);
  463. CalculateSizeButton->Visible = FAllowCalculateStats;
  464. if (!FMultiple)
  465. {
  466. // when setting properties for one file only, allow undef state
  467. // only when the input right explicitly requires it or
  468. // when "recursive" is on (possible for directory only).
  469. bool AllowUndef =
  470. (FOrigProperties.Valid.Contains(vpRights) &&
  471. FOrigProperties.Rights.AllowUndef) ||
  472. (RecursiveCheck->Checked);
  473. if (!AllowUndef)
  474. {
  475. // when disallowing undef state, make sure, all undef are turned into unset
  476. RightsFrame->Rights = TRights(RightsFrame->Rights.NumberSet);
  477. }
  478. RightsFrame->AllowUndef = AllowUndef;
  479. }
  480. EnableControl(ChecksumSheet, ChecksumSupported());
  481. EnableControl(ChecksumButton, ChecksumSheet->Enabled &&
  482. !ChecksumAlgEdit->Text.IsEmpty());
  483. // hide checksum edit at least if it is disabled to get rid of ugly
  484. // visage on XP
  485. ChecksumEdit->Visible = ChecksumEdit->Enabled;
  486. }
  487. //---------------------------------------------------------------------------
  488. void __fastcall TPropertiesDialog::FormCloseQuery(TObject * /*Sender*/,
  489. bool & /*CanClose*/)
  490. {
  491. if (ModalResult == DefaultResult(this))
  492. {
  493. ExitActiveControl(this);
  494. }
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TPropertiesDialog::CalculateSizeButtonClick(
  498. TObject * /*Sender*/)
  499. {
  500. assert(FOnCalculateSize != NULL);
  501. bool DoClose = false;
  502. try
  503. {
  504. __int64 Size;
  505. TCalculateSizeStats Stats;
  506. FOnCalculateSize(FFileList, Size, Stats, DoClose);
  507. FStatsNotCalculated = false;
  508. LoadStats(Size, Stats);
  509. }
  510. __finally
  511. {
  512. if (DoClose)
  513. {
  514. Close();
  515. }
  516. }
  517. }
  518. //---------------------------------------------------------------------------
  519. void __fastcall TPropertiesDialog::HelpButtonClick(TObject * /*Sender*/)
  520. {
  521. FormHelp(this);
  522. }
  523. //---------------------------------------------------------------------------
  524. void __fastcall TPropertiesDialog::ResetChecksum()
  525. {
  526. ChecksumView->Items->Clear();
  527. ChecksumEdit->Text = LoadStr(PROPERTIES_CHECKSUM_UNKNOWN);
  528. }
  529. //---------------------------------------------------------------------------
  530. void __fastcall TPropertiesDialog::CalculateChecksum()
  531. {
  532. assert(FOnCalculateChecksum != NULL);
  533. ResetChecksum();
  534. FChecksumLoaded = true;
  535. bool DoClose = false;
  536. try
  537. {
  538. FOnCalculateChecksum(ChecksumAlgEdit->Text, FFileList, CalculatedChecksum, DoClose);
  539. }
  540. __finally
  541. {
  542. if (DoClose)
  543. {
  544. Close();
  545. }
  546. }
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TPropertiesDialog::CalculatedChecksum(
  550. const UnicodeString & FileName, const UnicodeString & /*Alg*/,
  551. const UnicodeString & Hash)
  552. {
  553. if (FMultipleChecksum)
  554. {
  555. TListItem * Item = ChecksumView->Items->Add();
  556. Item->Caption = FileName;
  557. Item->SubItems->Add(Hash);
  558. }
  559. else
  560. {
  561. ChecksumEdit->Text = Hash;
  562. }
  563. }
  564. //---------------------------------------------------------------------------
  565. void __fastcall TPropertiesDialog::NeedChecksum()
  566. {
  567. if (!FChecksumLoaded && ChecksumSupported())
  568. {
  569. CalculateChecksum();
  570. }
  571. }
  572. //---------------------------------------------------------------------------
  573. bool __fastcall TPropertiesDialog::ChecksumSupported()
  574. {
  575. return (FOnCalculateChecksum != NULL);
  576. }
  577. //---------------------------------------------------------------------------
  578. void __fastcall TPropertiesDialog::ChecksumButtonClick(TObject * /*Sender*/)
  579. {
  580. CalculateChecksum();
  581. }
  582. //---------------------------------------------------------------------------
  583. void __fastcall TPropertiesDialog::PageControlChange(TObject * /*Sender*/)
  584. {
  585. if (PageControl->ActivePage == ChecksumSheet)
  586. {
  587. NeedChecksum();
  588. }
  589. }
  590. //---------------------------------------------------------------------------
  591. void __fastcall TPropertiesDialog::ChecksumAlgEditChange(TObject * /*Sender*/)
  592. {
  593. ResetChecksum();
  594. UpdateControls();
  595. }
  596. //---------------------------------------------------------------------------
  597. void __fastcall TPropertiesDialog::CopyClick(TObject * /*Sender*/)
  598. {
  599. TInstantOperationVisualizer Visualizer;
  600. TListView * ListView = dynamic_cast<TListView *>(ListViewMenu->PopupComponent);
  601. assert(ListView != NULL);
  602. int Count = 0;
  603. UnicodeString SingleText;
  604. UnicodeString Text;
  605. TListItem * Item = ListView->GetNextItem(NULL, sdAll, TItemStates() << isSelected);
  606. while (Item != NULL)
  607. {
  608. assert(Item->Selected);
  609. SingleText = Item->SubItems->Strings[0];
  610. Text += FORMAT(L"%s = %s\r\n", (Item->Caption, Item->SubItems->Strings[0]));
  611. Count++;
  612. Item = ListView->GetNextItem(Item, sdAll, TItemStates() << isSelected);
  613. }
  614. CopyToClipboard(Count == 1 ? SingleText : Text);
  615. }
  616. //---------------------------------------------------------------------------
  617. void __fastcall TPropertiesDialog::ChecksumViewContextPopup(
  618. TObject * Sender, TPoint & MousePos, bool & Handled)
  619. {
  620. MenuPopup(Sender, MousePos, Handled);
  621. }
  622. //---------------------------------------------------------------------------
  623. void __fastcall TPropertiesDialog::ResolveRemoteToken(
  624. const TRemoteToken & Orig, int Message, TComboBox * ComboBox,
  625. const TRemoteTokenList * List)
  626. {
  627. try
  628. {
  629. ComboBox->Text =
  630. LoadRemoteToken(StoreRemoteToken(Orig, ComboBox->Text, Message, List));
  631. }
  632. catch(...)
  633. {
  634. ComboBox->SetFocus();
  635. throw;
  636. }
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TPropertiesDialog::GroupComboBoxExit(TObject * Sender)
  640. {
  641. ResolveRemoteToken(FOrigProperties.Group, PROPERTIES_INVALID_GROUP,
  642. dynamic_cast<TComboBox *>(Sender), FGroupList);
  643. }
  644. //---------------------------------------------------------------------------
  645. void __fastcall TPropertiesDialog::OwnerComboBoxExit(TObject * Sender)
  646. {
  647. ResolveRemoteToken(FOrigProperties.Owner, PROPERTIES_INVALID_OWNER,
  648. dynamic_cast<TComboBox *>(Sender), FUserList);
  649. }
  650. //---------------------------------------------------------------------------
  651. void __fastcall TPropertiesDialog::FormShow(TObject * /*Sender*/)
  652. {
  653. UpdateControls();
  654. }
  655. //---------------------------------------------------------------------------