UnixPathComboBox.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "UnixPathComboBox.h"
  5. #ifndef DESIGN_ONLY
  6. #include <RemoteFiles.h>
  7. #endif
  8. #include <Common.h>
  9. #include <CustomUnixDirView.hpp>
  10. #pragma package(smart_init)
  11. //---------------------------------------------------------------------------
  12. // ValidCtrCheck is used to assure that the components created do not have
  13. // any pure virtual functions.
  14. static inline void ValidCtrCheck(TUnixPathComboBox *)
  15. {
  16. new TUnixPathComboBox(NULL);
  17. }
  18. //---------------------------------------------------------------------------
  19. namespace Unixpathcombobox
  20. {
  21. void __fastcall PACKAGE Register()
  22. {
  23. TComponentClass classes[1] = {__classid(TUnixPathComboBox)};
  24. RegisterComponents("Scp", classes, 0);
  25. }
  26. }
  27. //---------------------------------------------------------------------------
  28. // TUnixPathComboBox
  29. //---------------------------------------------------------------------------
  30. __fastcall TUnixPathComboBox::TUnixPathComboBox(TComponent* Owner)
  31. : TCustomPathComboBox(Owner)
  32. {
  33. UseSystemImageList = True;
  34. FRootName = Customunixdirview_SUnixDefaultRootName;
  35. FPath = '/';
  36. ResetItemHeight();
  37. }
  38. //---------------------------------------------------------------------------
  39. Integer __fastcall TUnixPathComboBox::GetItemImage(Integer Index)
  40. {
  41. return (Index < Items->Count-1 ? StdDirIcon : StdDirSelIcon);
  42. }
  43. //---------------------------------------------------------------------------
  44. Integer __fastcall TUnixPathComboBox::GetItemIndent(Integer Index)
  45. {
  46. return (10 * Index);
  47. }
  48. //---------------------------------------------------------------------------
  49. void __fastcall TUnixPathComboBox::SetRootName(AnsiString value)
  50. {
  51. if (FRootName != value)
  52. {
  53. FRootName = value;
  54. ResetItems();
  55. }
  56. }
  57. //---------------------------------------------------------------------------
  58. Boolean __fastcall TUnixPathComboBox::IsRootNameStored()
  59. {
  60. return (FRootName != Customunixdirview_SUnixDefaultRootName);
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TUnixPathComboBox::ResetItems()
  64. {
  65. #ifndef DESIGN_ONLY
  66. Items->BeginUpdate();
  67. try {
  68. Items->Clear();
  69. AnsiString APath = UnixExcludeTrailingBackslash(Path);
  70. while (!IsUnixRootPath(APath))
  71. {
  72. Integer P = APath.LastDelimiter('/');
  73. assert(P >= 0);
  74. Items->Insert(0, APath.SubString(P + 1, APath.Length() - P));
  75. APath.SetLength(P - 1);
  76. }
  77. Items->Insert(0, RootName);
  78. } __finally {
  79. ItemIndex = Items->Count - 1;
  80. Items->EndUpdate();
  81. }
  82. #endif
  83. }
  84. //---------------------------------------------------------------------------
  85. void __fastcall TUnixPathComboBox::CreateWnd()
  86. {
  87. TCustomPathComboBox::CreateWnd();
  88. ResetItems();
  89. }
  90. //---------------------------------------------------------------------------
  91. void __fastcall TUnixPathComboBox::SetPath(AnsiString Value)
  92. {
  93. #ifndef DESIGN_ONLY
  94. if (!Value.IsEmpty())
  95. {
  96. Value = UnixIncludeTrailingBackslash(Value);
  97. if (Value != FPath)
  98. {
  99. FPath = Value;
  100. ResetItems();
  101. }
  102. }
  103. #endif
  104. }
  105. //---------------------------------------------------------------------------
  106. void __fastcall TUnixPathComboBox::PathChanged()
  107. {
  108. #ifndef DESIGN_ONLY
  109. AnsiString APath = UnixExcludeTrailingBackslash(Path);
  110. for (int Index = ItemIndex; Index < Items->Count - 1; Index++)
  111. {
  112. APath = UnixExtractFileDir(APath);
  113. }
  114. // VanDyke style paths
  115. if (APath.IsEmpty())
  116. {
  117. assert(ItemIndex == 0);
  118. APath = ROOTDIRECTORY;
  119. }
  120. Path = APath;
  121. TCustomPathComboBox::PathChanged();
  122. // in case that path was not changed (e.g. inaccessible directory)
  123. Path = ((TCustomDirView*)DirView)->Path;
  124. #endif
  125. }