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 AllowSymbolic)
  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->AllowSymbolic = AllowSymbolic;
  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. InstallPathWordBreakProc(PointToEdit);
  50. InstallPathWordBreakProc(FileNameEdit);
  51. }
  52. //---------------------------------------------------------------------------
  53. void __fastcall TSymlinkDialog::UpdateControls()
  54. {
  55. assert(Side == osLocal || Side == osRemote);
  56. FileNameEdit->Color = !Edit ? clWindow : clBtnFace;
  57. FileNameEdit->ReadOnly = Edit;
  58. FileNameEdit->TabStop = !Edit;
  59. EnableControl(SymbolicCheck, Side == osRemote && !Edit && AllowSymbolic);
  60. EnableControl(OkButton, !FileName.IsEmpty() && !PointTo.IsEmpty());
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TSymlinkDialog::SetFileName(UnicodeString value)
  64. {
  65. FileNameEdit->Text = value;
  66. }
  67. //---------------------------------------------------------------------------
  68. UnicodeString __fastcall TSymlinkDialog::GetFileName()
  69. {
  70. return FileNameEdit->Text;
  71. }
  72. //---------------------------------------------------------------------------
  73. void __fastcall TSymlinkDialog::SetPointTo(UnicodeString value)
  74. {
  75. PointToEdit->Text = value;
  76. }
  77. //---------------------------------------------------------------------------
  78. UnicodeString __fastcall TSymlinkDialog::GetPointTo()
  79. {
  80. return PointToEdit->Text;
  81. }
  82. //---------------------------------------------------------------------------
  83. void __fastcall TSymlinkDialog::SetSymbolicLink(bool value)
  84. {
  85. SymbolicCheck->Checked = value;
  86. }
  87. //---------------------------------------------------------------------------
  88. bool __fastcall TSymlinkDialog::GetSymbolicLink()
  89. {
  90. return SymbolicCheck->Checked;
  91. }
  92. //---------------------------------------------------------------------------
  93. void __fastcall TSymlinkDialog::SetSide(TOperationSide value)
  94. {
  95. FSide = value;
  96. UpdateControls();
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TSymlinkDialog::SetEdit(bool value)
  100. {
  101. FEdit = value;
  102. UpdateControls();
  103. }
  104. //---------------------------------------------------------------------------
  105. void __fastcall TSymlinkDialog::ControlChange(TObject * /*Sender*/)
  106. {
  107. UpdateControls();
  108. }
  109. //---------------------------------------------------------------------------
  110. void __fastcall TSymlinkDialog::SetAllowSymbolic(bool value)
  111. {
  112. FAllowSymbolic = value;
  113. UpdateControls();
  114. }
  115. //---------------------------------------------------------------------------
  116. bool __fastcall TSymlinkDialog::Execute()
  117. {
  118. return ShowModal() == mrOk;
  119. }
  120. //---------------------------------------------------------------------------
  121. void __fastcall TSymlinkDialog::FormShow(TObject * /*Sender*/)
  122. {
  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. //---------------------------------------------------------------------------