Symlink.cpp 4.3 KB

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