Symlink.cpp 4.2 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(AnsiString & FileName, AnsiString & PointTo,
  15. TOperationSide Side, bool & SymbolicLink, bool Edit, bool AllowSymbolic)
  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->AllowSymbolic = AllowSymbolic;
  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. InstallPathWordBreakProc(PointToEdit);
  48. InstallPathWordBreakProc(FileNameEdit);
  49. }
  50. //---------------------------------------------------------------------------
  51. void __fastcall TSymlinkDialog::UpdateControls()
  52. {
  53. assert(Side == osLocal || Side == osRemote);
  54. FileNameEdit->Color = !Edit ? clWindow : clBtnFace;
  55. FileNameEdit->ReadOnly = Edit;
  56. FileNameEdit->TabStop = !Edit;
  57. EnableControl(SymbolicCheck, Side == osRemote && !Edit && AllowSymbolic);
  58. EnableControl(OkButton, !FileName.IsEmpty() && !PointTo.IsEmpty());
  59. }
  60. //---------------------------------------------------------------------------
  61. void __fastcall TSymlinkDialog::SetFileName(AnsiString value)
  62. {
  63. FileNameEdit->Text = value;
  64. }
  65. //---------------------------------------------------------------------------
  66. AnsiString __fastcall TSymlinkDialog::GetFileName()
  67. {
  68. return FileNameEdit->Text;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TSymlinkDialog::SetPointTo(AnsiString value)
  72. {
  73. PointToEdit->Text = value;
  74. }
  75. //---------------------------------------------------------------------------
  76. AnsiString __fastcall TSymlinkDialog::GetPointTo()
  77. {
  78. return PointToEdit->Text;
  79. }
  80. //---------------------------------------------------------------------------
  81. void __fastcall TSymlinkDialog::SetSymbolicLink(bool value)
  82. {
  83. SymbolicCheck->Checked = value;
  84. }
  85. //---------------------------------------------------------------------------
  86. bool __fastcall TSymlinkDialog::GetSymbolicLink()
  87. {
  88. return SymbolicCheck->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::SetAllowSymbolic(bool value)
  109. {
  110. FAllowSymbolic = value;
  111. UpdateControls();
  112. }
  113. //---------------------------------------------------------------------------
  114. bool __fastcall TSymlinkDialog::Execute()
  115. {
  116. return ShowModal() == mrOk;
  117. }
  118. //---------------------------------------------------------------------------
  119. void __fastcall TSymlinkDialog::FormShow(TObject * /*Sender*/)
  120. {
  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. //---------------------------------------------------------------------------