Symlink.cpp 4.3 KB

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