Symlink.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //---------------------------------------------------------------------------
  2. #include <FormsPCH.h>
  3. #pragma hdrstop
  4. #include "Symlink.h"
  5. //---------------------------------------------------------------------------
  6. #pragma resource "*.dfm"
  7. //---------------------------------------------------------------------------
  8. bool __fastcall DoSymlinkDialog(UnicodeString & FileName, UnicodeString & PointTo,
  9. TOperationSide Side, bool & SymbolicLink, bool Edit, bool AllowHardLink)
  10. {
  11. bool Result;
  12. TSymlinkDialog * Dialog = new TSymlinkDialog(Application);
  13. try
  14. {
  15. Dialog->FileName = FileName;
  16. Dialog->PointTo = PointTo;
  17. Dialog->Side = Side;
  18. Dialog->SymbolicLink = SymbolicLink;
  19. Dialog->Edit = Edit;
  20. Dialog->AllowHardLink = AllowHardLink;
  21. Result = Dialog->Execute();
  22. if (Result)
  23. {
  24. FileName = Dialog->FileName;
  25. PointTo = Dialog->PointTo;
  26. SymbolicLink = Dialog->SymbolicLink;
  27. }
  28. }
  29. __finally
  30. {
  31. delete Dialog;
  32. }
  33. return Result;
  34. }
  35. //---------------------------------------------------------------------------
  36. __fastcall TSymlinkDialog::TSymlinkDialog(TComponent* Owner)
  37. : TForm(Owner)
  38. {
  39. UseSystemSettings(this);
  40. FSide = osLocal;
  41. }
  42. //---------------------------------------------------------------------------
  43. void __fastcall TSymlinkDialog::UpdateControls()
  44. {
  45. DebugAssert(Side == osLocal || Side == osRemote);
  46. FileNameEdit->Color = !Edit ? clWindow : clBtnFace;
  47. FileNameEdit->ReadOnly = Edit;
  48. FileNameEdit->TabStop = !Edit;
  49. EnableControl(HardLinkCheck, (Side == osRemote) && !Edit && AllowHardLink);
  50. EnableControl(OkButton, !FileName.IsEmpty() && !PointTo.IsEmpty());
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TSymlinkDialog::SetFileName(UnicodeString value)
  54. {
  55. FileNameEdit->Text = value;
  56. }
  57. //---------------------------------------------------------------------------
  58. UnicodeString __fastcall TSymlinkDialog::GetFileName()
  59. {
  60. return FileNameEdit->Text;
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TSymlinkDialog::SetPointTo(UnicodeString value)
  64. {
  65. PointToEdit->Text = value;
  66. }
  67. //---------------------------------------------------------------------------
  68. UnicodeString __fastcall TSymlinkDialog::GetPointTo()
  69. {
  70. return PointToEdit->Text;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TSymlinkDialog::SetSymbolicLink(bool value)
  74. {
  75. HardLinkCheck->Checked = !value;
  76. }
  77. //---------------------------------------------------------------------------
  78. bool __fastcall TSymlinkDialog::GetSymbolicLink()
  79. {
  80. return !HardLinkCheck->Checked;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TSymlinkDialog::SetSide(TOperationSide value)
  84. {
  85. FSide = value;
  86. UpdateControls();
  87. }
  88. //---------------------------------------------------------------------------
  89. void __fastcall TSymlinkDialog::SetEdit(bool value)
  90. {
  91. FEdit = value;
  92. UpdateControls();
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TSymlinkDialog::ControlChange(TObject * /*Sender*/)
  96. {
  97. UpdateControls();
  98. }
  99. //---------------------------------------------------------------------------
  100. void __fastcall TSymlinkDialog::SetAllowHardLink(bool value)
  101. {
  102. FAllowHardLink = value;
  103. UpdateControls();
  104. }
  105. //---------------------------------------------------------------------------
  106. bool __fastcall TSymlinkDialog::Execute()
  107. {
  108. return (ShowModal() == DefaultResult(this));
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TSymlinkDialog::FormShow(TObject * /*Sender*/)
  112. {
  113. InstallPathWordBreakProc(PointToEdit);
  114. InstallPathWordBreakProc(FileNameEdit);
  115. Caption = LoadStr(Edit ? LINK_EDIT_CAPTION : LINK_ADD_CAPTION);
  116. UpdateControls();
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TSymlinkDialog::HelpButtonClick(TObject * /*Sender*/)
  120. {
  121. FormHelp(this);
  122. }
  123. //---------------------------------------------------------------------------