Properties.cpp 21 KB

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