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