1
0

NonVisual.cpp 88 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <Common.h>
  5. #include "NonVisual.h"
  6. #include <CoreMain.h>
  7. #include <TextsWin.h>
  8. #include <Tools.h>
  9. #include <Setup.h>
  10. #include <Interface.h>
  11. #include "WinConfiguration.h"
  12. #include "TerminalManager.h"
  13. #include "TBX.hpp"
  14. #include "VCLCommon.h"
  15. #include <HistoryComboBox.hpp>
  16. //---------------------------------------------------------------------------
  17. #pragma package(smart_init)
  18. #pragma link "TB2Item"
  19. #pragma link "TBX"
  20. #pragma link "TB2ExtItems"
  21. #pragma link "TBXExtItems"
  22. #pragma link "TBXToolPals"
  23. #pragma resource "*.dfm"
  24. TNonVisualDataModule *NonVisualDataModule;
  25. //---------------------------------------------------------------------------
  26. #define SCPCOMMANDER ((TScpCommanderForm *)ScpExplorer)
  27. #define UPDEX(HandleAction, Condition, OtherEnabled, OtherDisabled) if (Action == HandleAction) { \
  28. ((TCustomAction *)Action)->Enabled = (Condition); \
  29. if (((TCustomAction *)Action)->Enabled) { OtherEnabled; } else { OtherDisabled; }; \
  30. Handled = true; } else
  31. #define UPDEX1(HandleAction, Condition, Other) UPDEX(HandleAction, Condition, Other, Other)
  32. #define UPD(HandleAction, Condition) if (Action == HandleAction) { \
  33. ((TCustomAction *)Action)->Enabled = (Condition); Handled = true; } else
  34. #define UPDFUNC(HandleAction, Function) if (Action == HandleAction) { Function; Handled = true; } else
  35. #define EXE(HandleAction, Command) if (Action == HandleAction) { \
  36. Command; Handled = true; } else
  37. #define UPDACT(HandleAction, Command) \
  38. EXE(HandleAction, ((TCustomAction *)Action)->Enabled = true; Command)
  39. #define UPDCOMP2(COMP, NUM) if (Action == COMP ## Action ## NUM) { COMP ## Action ## NUM->Enabled = true; \
  40. COMP ## Action ## NUM->Visible = ScpExplorer->IsComponentPossible(fc ## COMP); \
  41. COMP ## Action ## NUM->Checked = ScpExplorer->ComponentVisible[fc ## COMP]; Handled = true; } else
  42. #define UPDCOMP(COMP) UPDCOMP2(COMP, )
  43. #define EXECOMP2(COMP, NUM) EXE(COMP ## Action ## NUM, \
  44. ScpExplorer->ComponentVisible[fc ## COMP] = !ScpExplorer->ComponentVisible[fc ## COMP] )
  45. #define EXECOMP(COMP) EXECOMP2(COMP, )
  46. #define COLPROPS(SIDE) \
  47. ((TCustomDirViewColProperties*)ScpExplorer->DirView(os ## SIDE)->ColProperties)
  48. #define UPDSORT(SIDE, NAME, LCOL, RCOL, NUM) \
  49. UPDEX(SIDE ## SortBy ## NAME ## Action ## NUM, (AuxInt = (ScpExplorer->IsSideLocalBrowser(os ## SIDE) ? LCOL : RCOL)) >= 0, \
  50. Action->Checked = (COLPROPS(SIDE)->SortColumn == AuxInt), \
  51. Action->Checked = false \
  52. )
  53. #define EXESORT(SIDE, NAME, LCOL, RCOL, NUM) \
  54. EXE(SIDE ## SortBy ## NAME ## Action ## NUM, ScpExplorer->DirView(os ## SIDE)->SortBy(ScpExplorer->IsSideLocalBrowser(os ## SIDE) ? LCOL : RCOL))
  55. #define UPDSORTA(SIDE, NUM) if (Action == SIDE ## SortAscendingAction ## NUM) { \
  56. SIDE ## SortAscendingAction ## NUM->Enabled = true; Handled = true; \
  57. SIDE ## SortAscendingAction ## NUM->Checked = COLPROPS(SIDE)->SortAscending; } else
  58. #define EXESORTA(SIDE, NUM) EXE(SIDE ## SortAscendingAction ## NUM, \
  59. COLPROPS(SIDE)->SortAscending = !COLPROPS(SIDE)->SortAscending; )
  60. #define UPDSHCOL(SIDE, NAME, LCOL, RCOL) \
  61. UPDFUNC(ShowHide ## SIDE ## NAME ## ColumnAction2, \
  62. int Col = (ScpExplorer->IsSideLocalBrowser(os ## SIDE) ? LCOL : RCOL); \
  63. Action->Enabled = (Col >= 0); \
  64. Action->Checked = Action->Enabled && COLPROPS(SIDE)->Visible[Col]; \
  65. )
  66. #define EXESHCOL(SIDE, NAME, LCOL, RCOL) \
  67. EXE(ShowHide ## SIDE ## NAME ## ColumnAction2, \
  68. int Col = (ScpExplorer->IsSideLocalBrowser(os ## SIDE) ? LCOL : RCOL); \
  69. COLPROPS(SIDE)->Visible[Col] = !COLPROPS(SIDE)->Visible[Col])
  70. #define BAND_COMPONENTS \
  71. EMIT_BAND_COMPONENT(ExplorerMenuBand) \
  72. EMIT_BAND_COMPONENT(ExplorerAddressBand) \
  73. EMIT_BAND_COMPONENT(ExplorerToolbarBand) \
  74. EMIT_BAND_COMPONENT(ExplorerSelectionBand) \
  75. EMIT_BAND_COMPONENT(ExplorerSessionBand) \
  76. EMIT_BAND_COMPONENT(ExplorerPreferencesBand) \
  77. EMIT_BAND_COMPONENT(ExplorerSortBand) \
  78. EMIT_BAND_COMPONENT(ExplorerUpdatesBand) \
  79. EMIT_BAND_COMPONENT(ExplorerTransferBand) \
  80. EMIT_BAND_COMPONENT(ExplorerCustomCommandsBand) \
  81. EMIT_BAND_COMPONENT(CommanderMenuBand) \
  82. EMIT_BAND_COMPONENT2(CommanderSessionBand, 2) \
  83. EMIT_BAND_COMPONENT(CommanderPreferencesBand) \
  84. EMIT_BAND_COMPONENT(CommanderSortBand) \
  85. EMIT_BAND_COMPONENT(CommanderCommandsBand) \
  86. EMIT_BAND_COMPONENT(CommanderUpdatesBand) \
  87. EMIT_BAND_COMPONENT(CommanderTransferBand) \
  88. EMIT_BAND_COMPONENT(CommanderCustomCommandsBand) \
  89. EMIT_BAND_COMPONENT2(CommanderLocalHistoryBand, 2) \
  90. EMIT_BAND_COMPONENT2(CommanderLocalNavigationBand, 2) \
  91. EMIT_BAND_COMPONENT2(CommanderLocalFileBand, 2) \
  92. EMIT_BAND_COMPONENT2(CommanderLocalSelectionBand, 2) \
  93. EMIT_BAND_COMPONENT2(CommanderRemoteHistoryBand, 2) \
  94. EMIT_BAND_COMPONENT2(CommanderRemoteNavigationBand, 2) \
  95. EMIT_BAND_COMPONENT2(CommanderRemoteFileBand, 2) \
  96. EMIT_BAND_COMPONENT2(CommanderRemoteSelectionBand, 2)
  97. #define EMIT_BAND_COMPONENT(COMP) EMIT_BAND_COMPONENT2(COMP, )
  98. //---------------------------------------------------------------------------
  99. __fastcall TNonVisualDataModule::TNonVisualDataModule(TComponent* Owner)
  100. : TDataModule(Owner)
  101. {
  102. FListColumn = NULL;
  103. FSessionIdleTimerExecuting = false;
  104. FCustomizedToolbar = NULL;
  105. FBusy = 0;
  106. QueueSpeedComboBoxItem(QueuePopupSpeedComboBoxItem);
  107. FRemoteRootDirImageIndex = RemoteRootDirAction->ImageIndex;
  108. }
  109. //---------------------------------------------------------------------------
  110. __fastcall TNonVisualDataModule::~TNonVisualDataModule()
  111. {
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall TNonVisualDataModule::ExplorerActionsUpdate(
  115. TBasicAction * BasicAction, bool & Handled)
  116. {
  117. TAction * Action = DebugNotNull(dynamic_cast<TAction *>(BasicAction));
  118. if (!ScpExplorer || !ScpExplorer->AllowedAction(Action, aaUpdate))
  119. {
  120. Action->Enabled = false;
  121. Handled = true;
  122. return;
  123. }
  124. void * AuxVoidPtr;
  125. int AuxInt;
  126. #define HasManagedSession ScpExplorer->HasManagedSession()
  127. #define HasTerminal ScpExplorer->HasActiveTerminal()
  128. // CURRENT DIRVIEW
  129. #define EnabledSelectedOperation (ScpExplorer->EnableSelectedOperation[osCurrent])
  130. #define EnabledFocusedOperation (ScpExplorer->EnableFocusedOperation[osCurrent])
  131. #define EnabledSelectedFileOperation (ScpExplorer->EnableSelectedFileOperation[osCurrent])
  132. #define EnabledFocusedFileOperation (ScpExplorer->EnableFocusedFileOperation[osCurrent])
  133. #define EnabledLocalSelectedOperation (ScpExplorer->HasDirView[osLocal] && ScpExplorer->EnableSelectedOperation[osLocal])
  134. #define EnabledLocalFocusedOperation (ScpExplorer->HasDirView[osLocal] && ScpExplorer->EnableFocusedOperation[osLocal])
  135. #define EnabledLocalSelectedFileOperation (ScpExplorer->HasDirView[osLocal] && ScpExplorer->EnableSelectedFileOperation[osLocal])
  136. #define EnabledRemoteSelectedOperation (ScpExplorer->EnableSelectedOperation[osRemote] && HasTerminal)
  137. #define EnabledRemoteFocusedOperation (ScpExplorer->EnableFocusedOperation[osRemote] && HasTerminal)
  138. #define EnabledRemoteSelectedFileOperation (ScpExplorer->EnableSelectedFileOperation[osRemote] && HasTerminal)
  139. #define EnabledOtherSelectedOperation ScpExplorer->IsLocalBrowserMode() && ScpExplorer->EnableSelectedOperation[osOther]
  140. #define EnabledOtherSelectedFileOperation ScpExplorer->IsLocalBrowserMode() && ScpExplorer->EnableSelectedFileOperation[osOther]
  141. // focused operation
  142. UPD(CurrentDeleteFocusedAction, EnabledFocusedOperation)
  143. UPD(CurrentPropertiesFocusedAction, EnabledFocusedOperation)
  144. UPD(CurrentEditFocusedAction, EnabledFocusedFileOperation &&
  145. !WinConfiguration->DisableOpenEdit)
  146. UPD(CurrentSystemMenuFocusedAction, EnabledFocusedOperation)
  147. UPD(CurrentEditWithFocusedAction, EnabledFocusedFileOperation &&
  148. !WinConfiguration->DisableOpenEdit)
  149. UPD(CurrentEditInternalFocusedAction, EnabledFocusedFileOperation &&
  150. !WinConfiguration->DisableOpenEdit)
  151. UPD(CurrentCopyToClipboardFocusedAction2, EnabledFocusedOperation)
  152. // file operation
  153. UPD(CurrentRenameAction, EnabledFocusedOperation &&
  154. (ScpExplorer->IsSideLocalBrowser(osCurrent) || ScpExplorer->Terminal->IsCapable[fcRename]))
  155. UPD(CurrentEditAction, EnabledSelectedFileOperation &&
  156. !WinConfiguration->DisableOpenEdit)
  157. UPD(CurrentEditInternalAction, EnabledSelectedFileOperation &&
  158. !WinConfiguration->DisableOpenEdit)
  159. UPD(CurrentEditWithAction, EnabledSelectedFileOperation &&
  160. !WinConfiguration->DisableOpenEdit)
  161. UPD(CurrentOpenAction, EnabledFocusedOperation &&
  162. !WinConfiguration->DisableOpenEdit)
  163. UPDEX1(CurrentAddEditLinkContextAction, ScpExplorer->CanAddEditLink(osCurrent),
  164. Action->Visible = ScpExplorer->LinkFocused())
  165. UPD(NewLinkAction, ScpExplorer->CanAddEditLink(osCurrent))
  166. // selected operation
  167. UPD(CurrentDeleteAction, EnabledSelectedOperation)
  168. UPD(CurrentDeleteAlternativeAction, EnabledSelectedOperation)
  169. UPD(CurrentPropertiesAction, EnabledSelectedOperation)
  170. UPD(CurrentCopyToClipboardAction2, EnabledSelectedOperation)
  171. UPD(RemoteMoveToAction, EnabledSelectedOperation &&
  172. !ScpExplorer->IsSideLocalBrowser(osCurrent) &&
  173. ScpExplorer->Terminal->IsCapable[fcRemoteMove])
  174. UPD(RemoteCopyToAction, EnabledSelectedOperation &&
  175. !ScpExplorer->IsSideLocalBrowser(osCurrent))
  176. UPD(FileListToCommandLineAction, EnabledSelectedOperation)
  177. UPD(FileListToClipboardAction, EnabledSelectedOperation)
  178. UPD(FullFileListToClipboardAction, EnabledSelectedOperation)
  179. UPD(FileGenerateUrlAction2, EnabledSelectedOperation && !ScpExplorer->IsSideLocalBrowser(osCurrent))
  180. UPD(FileListFromClipboardAction, IsFormatInClipboard(CF_TEXT))
  181. UPD(CurrentAddEditLinkAction, ScpExplorer->CanAddEditLink(osCurrent))
  182. UPD(LockAction,
  183. EnabledSelectedOperation && !ScpExplorer->IsSideLocalBrowser(osCurrent) &&
  184. ScpExplorer->Terminal->IsCapable[fcLocking])
  185. UPD(UnlockAction,
  186. EnabledSelectedOperation && !ScpExplorer->IsSideLocalBrowser(osCurrent) &&
  187. ScpExplorer->Terminal->IsCapable[fcLocking])
  188. UPD(CalculateDirectorySizesAction, EnabledSelectedOperation)
  189. // local selected operation
  190. UPD(LocalCopyAction, HasTerminal && EnabledLocalSelectedOperation)
  191. UPDEX1(LocalCopyQueueAction,
  192. HasTerminal && EnabledLocalSelectedOperation && ScpExplorer->Terminal->IsCapable[fcBackgroundTransfers],
  193. Action->Visible = !ScpExplorer->IsLocalBrowserMode())
  194. UPDEX1(LocalCopyNonQueueAction, HasTerminal && EnabledLocalSelectedOperation, Action->Visible = !ScpExplorer->IsLocalBrowserMode())
  195. UPD(LocalRenameAction2, EnabledLocalSelectedOperation)
  196. UPD(LocalEditAction2, EnabledLocalSelectedFileOperation && !WinConfiguration->DisableOpenEdit)
  197. UPD(LocalMoveAction, HasTerminal && EnabledLocalSelectedOperation)
  198. UPD(LocalCreateDirAction3, true)
  199. UPD(LocalDeleteAction2, EnabledLocalSelectedOperation)
  200. UPD(LocalPropertiesAction2, EnabledLocalSelectedOperation)
  201. UPD(LocalAddEditLinkAction3, ScpExplorer->CanAddEditLink(osLocal))
  202. UPD(LocalNewFileAction, !WinConfiguration->DisableOpenEdit)
  203. UPD(LocalLocalCopyAction, ScpExplorer->IsLocalBrowserMode() && EnabledLocalSelectedOperation)
  204. UPD(LocalLocalMoveAction, ScpExplorer->IsLocalBrowserMode() && EnabledLocalSelectedOperation)
  205. UPD(LocalOtherCopyAction, EnabledOtherSelectedOperation)
  206. UPD(LocalOtherMoveAction, EnabledOtherSelectedOperation)
  207. UPD(LocalCalculateDirectorySizesAction, EnabledLocalSelectedOperation)
  208. // local focused operation
  209. UPDEX1(LocalCopyFocusedAction, HasTerminal && EnabledLocalFocusedOperation, Action->Visible = !ScpExplorer->IsLocalBrowserMode())
  210. UPD(LocalCopyFocusedQueueAction, HasTerminal && EnabledLocalFocusedOperation && ScpExplorer->Terminal->IsCapable[fcBackgroundTransfers])
  211. UPD(LocalCopyFocusedNonQueueAction, HasTerminal && EnabledLocalFocusedOperation)
  212. UPD(LocalMoveFocusedAction, HasTerminal && EnabledLocalFocusedOperation)
  213. UPDEX1(LocalLocalCopyFocusedAction, ScpExplorer->IsLocalBrowserMode() && EnabledFocusedOperation, Action->Visible = ScpExplorer->IsLocalBrowserMode())
  214. UPDEX1(LocalLocalMoveFocusedAction, ScpExplorer->IsLocalBrowserMode() && EnabledFocusedOperation, Action->Visible = ScpExplorer->IsLocalBrowserMode())
  215. // remote selected operation
  216. UPD(RemoteCopyAction, EnabledRemoteSelectedOperation)
  217. UPDEX1(RemoteCopyQueueAction,
  218. EnabledRemoteSelectedOperation && ScpExplorer->Terminal->IsCapable[fcBackgroundTransfers],
  219. Action->Visible = !ScpExplorer->IsLocalBrowserMode())
  220. UPDEX1(RemoteCopyNonQueueAction, EnabledRemoteSelectedOperation, Action->Visible = !ScpExplorer->IsLocalBrowserMode())
  221. UPD(RemoteRenameAction2, (EnabledRemoteSelectedOperation && ScpExplorer->Terminal->IsCapable[fcRename]) || EnabledOtherSelectedOperation)
  222. UPD(RemoteEditAction2, (EnabledRemoteSelectedFileOperation || EnabledOtherSelectedFileOperation) && !WinConfiguration->DisableOpenEdit)
  223. UPD(RemoteMoveAction, EnabledRemoteSelectedOperation)
  224. UPD(RemoteCreateDirAction3, DirViewEnabled(osRemote))
  225. UPD(RemoteNewFileAction, DirViewEnabled(osRemote) && !WinConfiguration->DisableOpenEdit)
  226. UPD(RemoteDeleteAction2, EnabledRemoteSelectedOperation || EnabledOtherSelectedOperation)
  227. UPD(RemotePropertiesAction2, EnabledRemoteSelectedOperation || EnabledOtherSelectedOperation)
  228. UPD(RemoteAddEditLinkAction3, ScpExplorer->CanAddEditLink(osRemote))
  229. UPD(RemoteCalculateDirectorySizesAction, EnabledRemoteSelectedOperation || EnabledOtherSelectedOperation)
  230. // remote focused operation
  231. UPD(RemoteCopyFocusedAction, EnabledRemoteFocusedOperation)
  232. UPD(RemoteCopyFocusedQueueAction, EnabledRemoteFocusedOperation && ScpExplorer->Terminal->IsCapable[fcBackgroundTransfers])
  233. UPD(RemoteCopyFocusedNonQueueAction, EnabledRemoteFocusedOperation)
  234. UPD(RemoteMoveFocusedAction, EnabledRemoteFocusedOperation)
  235. UPD(RemoteMoveToFocusedAction, EnabledFocusedOperation &&
  236. !ScpExplorer->IsSideLocalBrowser(osCurrent) &&
  237. ScpExplorer->Terminal->IsCapable[fcRemoteMove])
  238. UPD(RemoteCopyToFocusedAction, EnabledFocusedOperation &&
  239. !ScpExplorer->IsSideLocalBrowser(osCurrent))
  240. // directory
  241. UPD(CurrentCreateDirAction, DirViewEnabled(osCurrent))
  242. UPD(NewDirAction, DirViewEnabled(osCurrent))
  243. UPD(RemoteFindFilesAction2, HasTerminal)
  244. // selection
  245. UPD(SelectOneAction, DirView(osCurrent)->FilesCount)
  246. UPD(SelectAction, DirView(osCurrent)->FilesCount)
  247. UPD(UnselectAction, DirView(osCurrent)->SelCount)
  248. UPD(SelectAllAction, DirView(osCurrent)->FilesCount)
  249. UPD(InvertSelectionAction, DirView(osCurrent)->FilesCount)
  250. UPD(ClearSelectionAction, DirView(osCurrent)->SelCount)
  251. UPD(RestoreSelectionAction, DirView(osCurrent)->SelectedNamesSaved)
  252. UPD(SelectSameExtAction, EnabledFocusedFileOperation)
  253. UPD(UnselectSameExtAction, EnabledFocusedFileOperation)
  254. UPD(PasteAction3, ScpExplorer->CanPasteFromClipBoard())
  255. UPD(LocalSelectAction2, ScpExplorer->HasDirView[osLocal] && DirView(osLocal)->FilesCount)
  256. UPD(LocalUnselectAction2, ScpExplorer->HasDirView[osLocal] && DirView(osLocal)->SelCount)
  257. UPD(LocalSelectAllAction2, ScpExplorer->HasDirView[osLocal] && DirView(osLocal)->FilesCount)
  258. UPD(RemoteSelectAction2, DirView(osRemote)->FilesCount)
  259. UPD(RemoteUnselectAction2, DirView(osRemote)->SelCount)
  260. UPD(RemoteSelectAllAction2, DirView(osRemote)->FilesCount)
  261. //style
  262. UPDACT(CurrentCycleStyleAction,
  263. CurrentCycleStyleAction->ImageIndex = 8 + (DirView(osCurrent)->ViewStyle + 1) % 4)
  264. #define STYLEACTION(Style) UPDACT(Current ## Style ## Action, \
  265. Current ## Style ## Action->Checked = (DirView(osCurrent)->ViewStyle == vs ## Style))
  266. STYLEACTION(Icon)
  267. STYLEACTION(SmallIcon)
  268. STYLEACTION(List)
  269. STYLEACTION(Report)
  270. #undef STYLEACTION
  271. // REMOTE+LOCAL
  272. // back/forward
  273. #define HISTORYACTION(SIDE, DIRECTION, HINTFMT, DELTA) \
  274. UPDEX(SIDE ## DIRECTION ## Action, DirViewEnabled(os ## SIDE) && (DirView(os ## SIDE)->DIRECTION ## Count > 0), \
  275. SIDE ## DIRECTION ## Action->Hint = FMTLOAD(HINTFMT, (DirView(os ## SIDE)->HistoryPath[DELTA])), \
  276. SIDE ## DIRECTION ## Action->Hint = L"")
  277. HISTORYACTION(Local, Back, EXPLORER_BACK_HINT, -1)
  278. HISTORYACTION(Local, Forward, EXPLORER_FORWARD_HINT, 1)
  279. HISTORYACTION(Remote, Back, EXPLORER_BACK_HINT, -1)
  280. HISTORYACTION(Remote, Forward, EXPLORER_FORWARD_HINT, 1)
  281. #undef HISTORYACTION
  282. #define PANEL_ACTIONS(SIDE) \
  283. UPD(SIDE ## ParentDirAction, DirViewEnabled(os ## SIDE) && !DirView(os ## SIDE)->IsRoot) \
  284. UPDEX1(SIDE ## RootDirAction, DirViewEnabled(os ## SIDE) && !DirView(os ## SIDE)->IsRoot, Action->ImageIndex = (ScpExplorer->IsSideLocalBrowser(os ## SIDE) ? LocalRootDirAction->ImageIndex : FRemoteRootDirImageIndex)) \
  285. UPD(SIDE ## HomeDirAction, DirViewEnabled(os ## SIDE)) \
  286. UPD(SIDE ## RefreshAction, DirViewEnabled(os ## SIDE) && DirView(os ## SIDE)->DirOK) \
  287. UPD(SIDE ## OpenDirAction, DirViewEnabled(os ## SIDE)) \
  288. UPD(SIDE ## ChangePathAction2, DirViewEnabled(os ## SIDE)) \
  289. UPD(SIDE ## AddBookmarkAction2, DirViewEnabled(os ## SIDE)) \
  290. UPD(SIDE ## PathToClipboardAction2, DirViewEnabled(os ## SIDE)) \
  291. UPDEX1(SIDE ## FilterAction, DirViewEnabled(os ## SIDE), Action->Checked = !DirView(os ## SIDE)->Mask.IsEmpty()) \
  292. UPD(SIDE ## ExploreDirectoryAction, ScpExplorer->IsSideLocalBrowser(os ## SIDE))
  293. PANEL_ACTIONS(Local)
  294. PANEL_ACTIONS(Remote)
  295. #undef PANEL_ACTIONS
  296. // HELP
  297. UPD(AboutAction, true)
  298. UPD(HomepageAction, true)
  299. UPD(HistoryPageAction, true)
  300. UPD(TableOfContentsAction, true)
  301. UPD(ForumPageAction, true)
  302. UPDACT(CheckForUpdatesAction, ShowUpdatesUpdate())
  303. UPD(UpdatesPreferencesAction, true)
  304. UPDEX1(DonatePageAction, true, DonatePageAction->Visible = !IsUWP())
  305. UPD(DownloadPageAction, true)
  306. UPDEX1(TipsAction, true, TipsAction->Visible = AnyTips())
  307. // VIEW
  308. UPDCOMP2(SessionsTabs, 2)
  309. UPDCOMP(StatusBar)
  310. UPDCOMP(ToolBar2)
  311. UPDCOMP2(LocalStatusBar, 2)
  312. UPDCOMP2(RemoteStatusBar, 2)
  313. UPDCOMP(CommandLinePanel)
  314. UPDCOMP(RemoteTree)
  315. UPDCOMP(LocalTree)
  316. #define EMIT_BAND_COMPONENT2(COMP, NUM) UPDCOMP2(COMP, NUM)
  317. BAND_COMPONENTS
  318. #undef EMIT_BAND_COMPONENT2
  319. UPD(CommanderLocalPanelAction, true)
  320. UPD(CommanderRemotePanelAction, true)
  321. UPD(GoToCommandLineAction, true)
  322. UPD(GoToTreeAction, true)
  323. UPDEX(ShowHiddenFilesAction, true,
  324. ShowHiddenFilesAction->Checked = WinConfiguration->ShowHiddenFiles, )
  325. UPDEX(FormatSizeBytesNoneAction, true,
  326. FormatSizeBytesNoneAction->Checked = (WinConfiguration->FormatSizeBytes == fbNone), )
  327. UPDEX(FormatSizeBytesKilobytesAction, true,
  328. FormatSizeBytesKilobytesAction->Checked = (WinConfiguration->FormatSizeBytes == fbKilobytes), )
  329. UPDEX(FormatSizeBytesShortAction, true,
  330. FormatSizeBytesShortAction->Checked = (WinConfiguration->FormatSizeBytes == fbShort), )
  331. UPDEX(AutoReadDirectoryAfterOpAction, true,
  332. AutoReadDirectoryAfterOpAction->Checked = Configuration->AutoReadDirectoryAfterOp, )
  333. UPD(PreferencesAction, true)
  334. UPD(PresetsPreferencesAction, true)
  335. UPD(FileColorsPreferencesAction, true)
  336. UPDEX(LockToolbarsAction, true,
  337. LockToolbarsAction->Checked = WinConfiguration->LockToolbars, )
  338. UPDEX(SelectiveToolbarTextAction, true,
  339. SelectiveToolbarTextAction->Checked = WinConfiguration->SelectiveToolbarText, )
  340. UPDCOMP(CustomCommandsBand)
  341. UPD(ColorMenuAction2, HasTerminal)
  342. UPD(GoToAddressAction, true)
  343. UPD(CustomizeToolbarAction, IsToolbarCustomizable())
  344. // SORT
  345. UPDSORTA(Local, 2)
  346. #define UPDSORTL(NAME, COL) UPDSORT(Local, NAME, COL, -1, 2)
  347. UPDSORTL(Name, dvName)
  348. UPDSORTL(Ext, dvExt)
  349. UPDSORTL(Size, dvSize)
  350. UPDSORTL(Type, dvType)
  351. UPDSORTL(Changed, dvChanged)
  352. UPDSORTL(Attr, dvAttr)
  353. #undef UPDSORTL
  354. UPDSORTA(Remote, 2)
  355. UPDSORT(Remote, Name, dvName, uvName, 2)
  356. UPDSORT(Remote, Ext, dvExt, uvExt, 2)
  357. UPDSORT(Remote, Size, dvSize, uvSize, 2)
  358. UPDSORT(Remote, Changed, dvChanged, uvChanged, 2)
  359. UPDSORT(Remote, Rights, dvAttr, uvRights, 2)
  360. UPDSORT(Remote, Owner, -1, uvOwner, 2)
  361. UPDSORT(Remote, Group, -1, uvGroup, 2)
  362. UPDSORT(Remote, Type, dvType, uvType, 2)
  363. UPDSORTA(Current, )
  364. UPDSORT(Current, Name, dvName, uvName, )
  365. UPDSORT(Current, Ext, dvExt, uvExt, )
  366. UPDSORT(Current, Size, dvSize, uvSize, )
  367. UPDSORT(Current, Type, dvType, uvType, 2)
  368. UPDSORT(Current, Changed, dvChanged, uvChanged, )
  369. UPDSORT(Current, Rights, dvAttr, uvRights, )
  370. UPDSORT(Current, Owner, -1, uvOwner, )
  371. UPDSORT(Current, Group, -1, uvGroup, )
  372. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  373. UPDEX(SortColumnAscendingAction, (ListColumn != NULL), SortColumnAscendingAction->Checked =
  374. (COLVIEWPROPS->SortColumn == ListColumn->Index) && COLVIEWPROPS->SortAscending, )
  375. UPDEX(SortColumnDescendingAction, (ListColumn != NULL), SortColumnDescendingAction->Checked =
  376. (COLVIEWPROPS->SortColumn == ListColumn->Index) && !COLVIEWPROPS->SortAscending, )
  377. #undef COLVIEWPROPS
  378. // SHOW/HIDE COLUMN
  379. #define UPDSHCOLL(NAME) UPDSHCOL(Local, NAME, dv ## NAME, -1)
  380. UPDSHCOLL(Name)
  381. UPDSHCOLL(Ext)
  382. UPDSHCOLL(Size)
  383. UPDSHCOLL(Type)
  384. UPDSHCOLL(Changed)
  385. UPDSHCOLL(Attr)
  386. #undef UPDSHCOLL
  387. UPDSHCOL(Remote, Name, dvName, uvName)
  388. UPDSHCOL(Remote, Ext, dvExt, uvExt)
  389. UPDSHCOL(Remote, Size, dvSize, uvSize)
  390. UPDSHCOL(Remote, Changed, dvChanged, uvChanged)
  391. UPDSHCOL(Remote, Rights, dvAttr, uvRights)
  392. UPDSHCOL(Remote, Owner, -1, uvOwner)
  393. UPDSHCOL(Remote, Group, -1, uvGroup)
  394. UPDSHCOL(Remote, LinkTarget, -1, uvLinkTarget)
  395. UPDSHCOL(Remote, Type, dvType, uvType)
  396. UPD(HideColumnAction, (ListColumn != NULL))
  397. UPD(BestFitColumnAction, (ListColumn != NULL))
  398. // SESSION
  399. UPD(NewSessionAction, true)
  400. UPDACT(NewTabAction, Action->ImageIndex = ScpExplorer->GetNewTabActionImageIndex())
  401. UPD(NewRemoteTabAction, true)
  402. UPD(NewLocalTabAction, true)
  403. UPDACT(DefaultToNewRemoteTabAction, Action->Checked = WinConfiguration->DefaultToNewRemoteTab)
  404. UPD(SiteManagerAction, true)
  405. UPD(DuplicateTabAction, HasManagedSession)
  406. UPD(RenameTabAction, HasManagedSession)
  407. UPD(CloseTabAction, HasManagedSession && ScpExplorer->CanCloseSession(ScpExplorer->ManagedSession))
  408. UPDEX1(DisconnectSessionAction, HasTerminal, DisconnectSessionAction->Visible = (ScpExplorer->Terminal == NULL) || !ScpExplorer->Terminal->Disconnected)
  409. UPDEX1(ReconnectSessionAction, (ScpExplorer->Terminal != NULL) && ScpExplorer->Terminal->Disconnected, ReconnectSessionAction->Visible = ReconnectSessionAction->Enabled)
  410. UPD(SavedSessionsAction2, true)
  411. UPD(WorkspacesAction, StoredSessions->HasAnyWorkspace())
  412. UPD(OpenedTabsAction, HasManagedSession)
  413. UPD(SaveCurrentSessionAction2, HasTerminal)
  414. UPD(SaveWorkspaceAction, HasTerminal)
  415. // COMMAND
  416. UPD(CompareDirectoriesAction2, HasTerminal)
  417. UPD(SynchronizeAction, HasTerminal)
  418. UPD(FullSynchronizeAction, HasTerminal)
  419. UPD(ConsoleAction, ScpExplorer->CanConsole())
  420. UPD(PuttyAction, HasTerminal && TTerminalManager::Instance()->CanOpenInPutty())
  421. UPD(SynchronizeBrowsingAction2, HasTerminal)
  422. UPD(CloseApplicationAction2, true)
  423. UPD(FileSystemInfoAction, HasTerminal)
  424. UPD(SessionGenerateUrlAction2, HasTerminal)
  425. UPD(ClearCachesAction, HasTerminal && !ScpExplorer->Terminal->AreCachesEmpty)
  426. UPD(NewFileAction, DirViewEnabled(osCurrent) && !WinConfiguration->DisableOpenEdit)
  427. UPD(EditorListCustomizeAction, true)
  428. UPD(ChangePasswordAction, ScpExplorer->CanChangePassword())
  429. UPD(PrivateKeyUploadAction, ScpExplorer->CanPrivateKeyUpload())
  430. // CUSTOM COMMANDS
  431. UPD(CustomCommandsFileAction, true)
  432. UPD(CustomCommandsNonFileAction, true)
  433. UPD(CustomCommandsEnterAction, true)
  434. UPD(CustomCommandsEnterFocusedAction, true)
  435. UPDFUNC(CustomCommandsLastAction, CustomCommandsLastUpdate(CustomCommandsLastAction))
  436. UPDFUNC(CustomCommandsLastFocusedAction, CustomCommandsLastUpdate(CustomCommandsLastFocusedAction))
  437. UPD(CustomCommandsCustomizeAction, true)
  438. // QUEUE
  439. UPDEX(QueueEnableAction, HasTerminal, Action->Checked = ScpExplorer->GetQueueEnabled(), )
  440. #define UPDQUEUE(OPERATION) UPD(Queue ## OPERATION ## Action, \
  441. ScpExplorer->AllowQueueOperation(qo ## OPERATION))
  442. UPDQUEUE(GoTo)
  443. UPDQUEUE(Preferences)
  444. UPDEX(QueueItemQueryAction, ScpExplorer->AllowQueueOperation(qoItemQuery),
  445. Action->Visible = true, Action->Visible = false)
  446. UPDEX(QueueItemErrorAction, ScpExplorer->AllowQueueOperation(qoItemError),
  447. Action->Visible = true, Action->Visible = false)
  448. UPDEX(QueueItemPromptAction, ScpExplorer->AllowQueueOperation(qoItemPrompt),
  449. Action->Visible = true, Action->Visible = false)
  450. UPDQUEUE(ItemDelete)
  451. UPDEX(QueueItemExecuteAction, ScpExplorer->AllowQueueOperation(qoItemExecute),
  452. Action->Visible = true, Action->Visible =
  453. !ScpExplorer->AllowQueueOperation(qoItemPause) &&
  454. !ScpExplorer->AllowQueueOperation(qoItemResume))
  455. UPDEX(QueueItemPauseAction, ScpExplorer->AllowQueueOperation(qoItemPause),
  456. Action->Visible = true, Action->Visible = false)
  457. UPDEX(QueueItemResumeAction, ScpExplorer->AllowQueueOperation(qoItemResume),
  458. Action->Visible = true, Action->Visible = false)
  459. UPDQUEUE(ItemUp)
  460. UPDQUEUE(ItemDown)
  461. UPDQUEUE(PauseAll)
  462. UPDQUEUE(ResumeAll)
  463. UPDQUEUE(DeleteAll)
  464. UPDQUEUE(DeleteAllDone)
  465. #undef UPDQUEUE
  466. UPDEX(QueueItemSpeedAction, ScpExplorer->AllowQueueOperation(qoItemSpeed, &AuxVoidPtr),
  467. QueueItemSpeedAction->Text = SetSpeedLimit(reinterpret_cast<unsigned long>(AuxVoidPtr)),
  468. QueueItemSpeedAction->Text = L"")
  469. UPDEX1(QueueToggleShowAction, !ScpExplorer->IsLocalBrowserMode(), Action->Checked = ScpExplorer->ComponentVisible[fcQueueView])
  470. #define QUEUEACTION(SHOW) \
  471. UPDEX1(Queue ## SHOW ## Action, !ScpExplorer->IsLocalBrowserMode(), Action->Checked = WinConfiguration->QueueView.Show == qv ## SHOW)
  472. QUEUEACTION(Show)
  473. QUEUEACTION(HideWhenEmpty)
  474. QUEUEACTION(Hide)
  475. #undef QUEUEACTION
  476. UPDEX1(QueueCycleOnceEmptyAction, ScpExplorer->AllowQueueOperation(qoOnceEmpty),
  477. QueueCycleOnceEmptyAction->ImageIndex = CurrentQueueOnceEmptyAction()->ImageIndex;
  478. QueueCycleOnceEmptyAction->Checked = !QueueIdleOnceEmptyAction->Checked)
  479. UPD(QueueIdleOnceEmptyAction, ScpExplorer->AllowQueueOperation(qoOnceEmpty))
  480. UPD(QueueDisconnectOnceEmptyAction2, ScpExplorer->AllowQueueOperation(qoOnceEmpty))
  481. UPD(QueueSuspendOnceEmptyAction2, ScpExplorer->AllowQueueOperation(qoOnceEmpty))
  482. UPD(QueueShutDownOnceEmptyAction2, ScpExplorer->AllowQueueOperation(qoOnceEmpty))
  483. UPDCOMP(CommanderPreferencesBand)
  484. UPDACT(QueueToolbarAction,
  485. Action->Enabled = ScpExplorer->ComponentVisible[fcQueueView];
  486. Action->Checked = ScpExplorer->ComponentVisible[fcQueueToolbar])
  487. UPDACT(QueueFileListAction,
  488. Action->Enabled = ScpExplorer->ComponentVisible[fcQueueView];
  489. Action->Checked = ScpExplorer->ComponentVisible[fcQueueFileList])
  490. ;
  491. }
  492. //---------------------------------------------------------------------------
  493. void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
  494. TBasicAction * BasicAction, bool & Handled)
  495. {
  496. DebugAssert(ScpExplorer);
  497. TAction * Action = DebugNotNull(dynamic_cast<TAction *>(BasicAction));
  498. if (!ScpExplorer->AllowedAction(Action, aaExecute))
  499. {
  500. Handled = true;
  501. return;
  502. }
  503. ScpExplorer->BeforeAction();
  504. unsigned int ShortCutFlag = FLAGMASK((Action->ActionComponent == NULL), cocShortCutHint);
  505. {
  506. TAutoNestingCounter Counter(FBusy);
  507. // focused operation
  508. EXE(CurrentDeleteFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foDelete, osCurrent, true))
  509. EXE(CurrentPropertiesFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foSetProperties, osCurrent, true))
  510. EXE(CurrentEditFocusedAction, ScpExplorer->ExecuteFile(osCurrent, efDefaultEditor, NULL, true, true))
  511. EXE(CurrentSystemMenuFocusedAction, ScpExplorer->DisplaySystemContextMenu())
  512. EXE(CurrentEditWithFocusedAction, ScpExplorer->ExecuteCurrentFileWith(true))
  513. EXE(CurrentEditInternalFocusedAction, ScpExplorer->ExecuteFile(osCurrent, efInternalEditor, NULL, true, true))
  514. EXE(CurrentCopyToClipboardFocusedAction2, ScpExplorer->CopyFilesToClipboard(osCurrent, true))
  515. // operation
  516. EXE(CurrentEditAction, ScpExplorer->ExecuteFile(osCurrent, efDefaultEditor, NULL, true, false))
  517. EXE(CurrentEditInternalAction, ScpExplorer->ExecuteFile(osCurrent, efInternalEditor, NULL, true, false))
  518. EXE(CurrentEditWithAction, ScpExplorer->ExecuteCurrentFileWith(false))
  519. EXE(CurrentOpenAction, ScpExplorer->ExecuteCurrentFile())
  520. EXE(CurrentAddEditLinkAction, ScpExplorer->AddEditLink(osCurrent, false))
  521. EXE(CurrentAddEditLinkContextAction, ScpExplorer->AddEditLink(osCurrent, false))
  522. EXE(NewLinkAction, ScpExplorer->AddEditLink(osCurrent, true))
  523. EXE(CurrentRenameAction, ScpExplorer->ExecuteFileOperationCommand(foRename, osCurrent, false))
  524. EXE(CurrentDeleteAction, ScpExplorer->ExecuteFileOperationCommand(foDelete, osCurrent, false))
  525. EXE(CurrentDeleteAlternativeAction, ScpExplorer->ExecuteFileOperationCommand(foDelete, osCurrent, false, false, (void*)true))
  526. EXE(CurrentPropertiesAction, ScpExplorer->ExecuteFileOperationCommand(foSetProperties, osCurrent, false))
  527. EXE(CurrentCopyToClipboardAction2, ScpExplorer->CopyFilesToClipboard(osCurrent, false))
  528. EXE(FileListToCommandLineAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedCommandLine))
  529. EXE(FileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedClipboard))
  530. EXE(FullFileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFullFileList, pedClipboard))
  531. EXE(FileGenerateUrlAction2, ScpExplorer->FileGenerateUrl())
  532. EXE(FileListFromClipboardAction, ScpExplorer->FileListFromClipboard())
  533. EXE(LockAction, ScpExplorer->ExecuteFileOperationCommand(foLock, osCurrent, false))
  534. EXE(UnlockAction, ScpExplorer->ExecuteFileOperationCommand(foUnlock, osCurrent, false))
  535. EXE(CalculateDirectorySizesAction, ScpExplorer->CalculateDirectorySizes(osCurrent))
  536. // local selected operation
  537. EXE(LocalCopyAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, false, ShortCutFlag))
  538. EXE(LocalCopyQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, false, cocQueue))
  539. EXE(LocalCopyNonQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, false, cocNonQueue))
  540. EXE(LocalRenameAction2, ScpExplorer->ExecuteFileOperationCommand(foRename, osLocal, false))
  541. EXE(LocalEditAction2, ScpExplorer->ExecuteFile(osLocal, efDefaultEditor, NULL, true, false))
  542. EXE(LocalMoveAction, ScpExplorer->ExecuteFileOperationCommand(foMove, osLocal, false))
  543. EXE(LocalCreateDirAction3, ScpExplorer->CreateDirectory(osLocal))
  544. EXE(LocalDeleteAction2, ScpExplorer->ExecuteFileOperationCommand(foDelete, osLocal, false))
  545. EXE(LocalPropertiesAction2, ScpExplorer->ExecuteFileOperationCommand(foSetProperties, osLocal, false))
  546. EXE(LocalAddEditLinkAction3, ScpExplorer->AddEditLink(osLocal, false))
  547. EXE(LocalNewFileAction, ScpExplorer->EditNew(osLocal))
  548. EXE(LocalLocalCopyAction, ScpExplorer->LocalLocalCopyCommand(foCopy, osLocal, false, ShortCutFlag))
  549. EXE(LocalLocalMoveAction, ScpExplorer->LocalLocalCopyCommand(foMove, osLocal, false, ShortCutFlag))
  550. EXE(LocalOtherCopyAction, ScpExplorer->LocalLocalCopyCommand(foCopy, osOther, false, ShortCutFlag))
  551. EXE(LocalOtherMoveAction, ScpExplorer->LocalLocalCopyCommand(foMove, osOther, false, ShortCutFlag))
  552. EXE(LocalCalculateDirectorySizesAction, ScpExplorer->CalculateDirectorySizes(osLocal))
  553. // local focused operation
  554. EXE(LocalCopyFocusedAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, true, ShortCutFlag))
  555. EXE(LocalCopyFocusedQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, true, cocQueue))
  556. EXE(LocalCopyFocusedNonQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osLocal, true, cocNonQueue))
  557. EXE(LocalMoveFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foMove, osLocal, true))
  558. EXE(LocalLocalCopyFocusedAction, ScpExplorer->LocalLocalCopyCommand(foCopy, osCurrent, true, ShortCutFlag))
  559. EXE(LocalLocalMoveFocusedAction, ScpExplorer->LocalLocalCopyCommand(foMove, osCurrent, true, ShortCutFlag))
  560. // remote selected operation
  561. EXE(RemoteCopyAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, false, ShortCutFlag))
  562. EXE(RemoteCopyQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, false, cocQueue))
  563. EXE(RemoteCopyNonQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, false, cocNonQueue))
  564. EXE(RemoteRenameAction2, ScpExplorer->ExecuteFileOperationCommand(foRename, osRemote, false))
  565. EXE(RemoteEditAction2, ScpExplorer->ExecuteFile(osRemote, efDefaultEditor, NULL, true, false))
  566. EXE(RemoteMoveAction, ScpExplorer->ExecuteFileOperationCommand(foMove, osRemote, false))
  567. EXE(RemoteCreateDirAction3, ScpExplorer->CreateDirectory(osRemote))
  568. EXE(RemoteNewFileAction, ScpExplorer->EditNew(osRemote))
  569. EXE(RemoteDeleteAction2, ScpExplorer->ExecuteFileOperationCommand(foDelete, osRemote, false))
  570. EXE(RemotePropertiesAction2, ScpExplorer->ExecuteFileOperationCommand(foSetProperties, osRemote, false))
  571. EXE(RemoteMoveToAction, ScpExplorer->ExecuteFileOperationCommand(foRemoteMove, osCurrent, false))
  572. EXE(RemoteCopyToAction, ScpExplorer->ExecuteFileOperationCommand(foRemoteCopy, osCurrent, false))
  573. EXE(RemoteAddEditLinkAction3, ScpExplorer->AddEditLink(osRemote, false))
  574. EXE(RemoteCalculateDirectorySizesAction, ScpExplorer->CalculateDirectorySizes(osRemote))
  575. // remote focused operation
  576. EXE(RemoteCopyFocusedAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, true, ShortCutFlag))
  577. EXE(RemoteCopyFocusedQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, true, cocQueue))
  578. EXE(RemoteCopyFocusedNonQueueAction, ScpExplorer->ExecuteCopyOperationCommand(osRemote, true, cocNonQueue))
  579. EXE(RemoteMoveFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foMove, osRemote, true))
  580. EXE(RemoteMoveToFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foRemoteMove, osCurrent, true))
  581. EXE(RemoteCopyToFocusedAction, ScpExplorer->ExecuteFileOperationCommand(foRemoteCopy, osCurrent, true))
  582. // directory
  583. EXE(CurrentCreateDirAction, ScpExplorer->CreateDirectory(osCurrent))
  584. EXE(NewDirAction, ScpExplorer->CreateDirectory(osCurrent))
  585. EXE(RemoteFindFilesAction2, ScpExplorer->RemoteFindFiles())
  586. //selection
  587. EXE(SelectOneAction, DirView(osCurrent)->SelectCurrentItem(DirView(osCurrent)->NortonLike))
  588. EXE(SelectAction, ScpExplorer->SelectByMask(osCurrent, true))
  589. EXE(UnselectAction, ScpExplorer->SelectByMask(osCurrent, false))
  590. EXE(SelectAllAction, ScpExplorer->SelectAll(osCurrent, smAll))
  591. EXE(InvertSelectionAction, ScpExplorer->SelectAll(osCurrent, smInvert))
  592. EXE(ClearSelectionAction, ScpExplorer->SelectAll(osCurrent, smNone))
  593. EXE(RestoreSelectionAction, ScpExplorer->RestoreSelectedNames(osCurrent))
  594. EXE(SelectSameExtAction, ScpExplorer->SelectSameExt(true))
  595. EXE(UnselectSameExtAction, ScpExplorer->SelectSameExt(false))
  596. EXE(LocalSelectAction2, ScpExplorer->SelectByMask(osLocal, true))
  597. EXE(LocalUnselectAction2, ScpExplorer->SelectByMask(osLocal, false))
  598. EXE(LocalSelectAllAction2, ScpExplorer->SelectAll(osLocal, smAll))
  599. EXE(RemoteSelectAction2, ScpExplorer->SelectByMask(osRemote, true))
  600. EXE(RemoteUnselectAction2, ScpExplorer->SelectByMask(osRemote, false))
  601. EXE(RemoteSelectAllAction2, ScpExplorer->SelectAll(osRemote, smAll))
  602. EXE(PasteAction3, ScpExplorer->PasteFromClipBoard())
  603. // style
  604. EXE(CurrentCycleStyleAction,
  605. if (DirView(osCurrent)->ViewStyle == vsReport) DirView(osCurrent)->ViewStyle = vsIcon;
  606. else DirView(osCurrent)->ViewStyle = (TViewStyle)(DirView(osCurrent)->ViewStyle + 1);
  607. )
  608. #define STYLEACTION(Style) EXE(Current ## Style ## Action, \
  609. DirView(osCurrent)->ViewStyle = vs ## Style)
  610. STYLEACTION(Icon)
  611. STYLEACTION(SmallIcon)
  612. STYLEACTION(List)
  613. STYLEACTION(Report)
  614. #undef STYLEACTION
  615. #define PANEL_ACTIONS(SIDE) \
  616. EXE(SIDE ## BackAction, ScpExplorer->HistoryGo(os ## SIDE, -1)) \
  617. EXE(SIDE ## ForwardAction, ScpExplorer->HistoryGo(os ## SIDE, 1)) \
  618. EXE(SIDE ## ParentDirAction, DirView(os ## SIDE)->ExecuteParentDirectory()) \
  619. EXE(SIDE ## RootDirAction, DirView(os ## SIDE)->ExecuteRootDirectory()) \
  620. EXE(SIDE ## HomeDirAction, ScpExplorer->HomeDirectory(os ## SIDE)) \
  621. EXE(SIDE ## RefreshAction, ScpExplorer->ReloadDirectory(os ## SIDE)) \
  622. EXE(SIDE ## OpenDirAction, ScpExplorer->OpenDirectory(os ## SIDE)) \
  623. EXE(SIDE ## ChangePathAction2, ScpExplorer->ChangePath(os ## SIDE)) \
  624. EXE(SIDE ## AddBookmarkAction2, ScpExplorer->AddBookmark(os ## SIDE)) \
  625. EXE(SIDE ## PathToClipboardAction2, ScpExplorer->PanelExport(os ## SIDE, pePath, pedClipboard)) \
  626. EXE(SIDE ## FilterAction, ScpExplorer->Filter(os ## SIDE)) \
  627. EXE(SIDE ## ExploreDirectoryAction, ScpExplorer->ExploreLocalDirectory(os ## SIDE))
  628. PANEL_ACTIONS(Local)
  629. PANEL_ACTIONS(Remote)
  630. #undef PANEL_ACTIONS
  631. //HELP
  632. EXE(AboutAction, DoAboutDialog(Configuration))
  633. EXE(HomepageAction, OpenBrowser(LoadStr(HOMEPAGE_URL)))
  634. EXE(HistoryPageAction, OpenBrowser(LoadStr(HISTORY_URL)))
  635. EXE(TableOfContentsAction, Application->HelpSystem->ShowTableOfContents())
  636. EXE(ForumPageAction, OpenBrowser(LoadStr(FORUM_URL)))
  637. EXE(CheckForUpdatesAction, CheckForUpdates(false))
  638. EXE(UpdatesPreferencesAction, PreferencesDialog(pmUpdates))
  639. EXE(DonatePageAction, OpenBrowser(LoadStr(DONATE_URL)))
  640. EXE(DownloadPageAction, OpenBrowser(LoadStr(DOWNLOAD_URL)))
  641. EXE(TipsAction, ShowTips())
  642. // VIEW
  643. EXECOMP2(SessionsTabs, 2)
  644. EXECOMP(StatusBar)
  645. EXECOMP(ToolBar2)
  646. EXECOMP2(LocalStatusBar, 2)
  647. EXECOMP2(RemoteStatusBar, 2)
  648. #define EMIT_BAND_COMPONENT2(COMP, NUM) EXECOMP2(COMP, NUM)
  649. BAND_COMPONENTS
  650. #undef EMIT_BAND_COMPONENT2
  651. EXECOMP(CommandLinePanel)
  652. EXECOMP(RemoteTree)
  653. EXECOMP(LocalTree)
  654. EXE(CommanderLocalPanelAction, )
  655. EXE(CommanderRemotePanelAction, )
  656. EXE(GoToCommandLineAction, ScpExplorer->GoToCommandLine())
  657. EXE(GoToTreeAction, ScpExplorer->GoToTree())
  658. EXE(ShowHiddenFilesAction, ScpExplorer->ToggleShowHiddenFiles())
  659. EXE(FormatSizeBytesNoneAction, ScpExplorer->SetFormatSizeBytes(fbNone))
  660. EXE(FormatSizeBytesKilobytesAction, ScpExplorer->SetFormatSizeBytes(fbKilobytes))
  661. EXE(FormatSizeBytesShortAction, ScpExplorer->SetFormatSizeBytes(fbShort))
  662. EXE(AutoReadDirectoryAfterOpAction, ScpExplorer->ToggleAutoReadDirectoryAfterOp())
  663. EXE(PreferencesAction, PreferencesDialog(::pmDefault) )
  664. EXE(PresetsPreferencesAction, PreferencesDialog(pmPresets) )
  665. EXE(FileColorsPreferencesAction, PreferencesDialog(pmFileColors) )
  666. EXE(LockToolbarsAction, WinConfiguration->LockToolbars = !WinConfiguration->LockToolbars)
  667. EXE(SelectiveToolbarTextAction, WinConfiguration->SelectiveToolbarText = !WinConfiguration->SelectiveToolbarText)
  668. EXECOMP(CustomCommandsBand)
  669. EXE(ColorMenuAction2, CreateSessionColorMenu(ColorMenuAction2))
  670. EXE(GoToAddressAction, ScpExplorer->GoToAddress())
  671. EXE(CustomizeToolbarAction, CreateToolbarButtonsList())
  672. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  673. // SORT
  674. EXESORTA(Local, 2)
  675. #define EXESORTL(NAME, COL) EXESORT(Local, NAME, COL, COL, 2)
  676. EXESORTL(Name, dvName)
  677. EXESORTL(Ext, dvExt)
  678. EXESORTL(Size, dvSize)
  679. EXESORTL(Type, dvType)
  680. EXESORTL(Changed, dvChanged)
  681. EXESORTL(Attr, dvAttr)
  682. #undef EXESORTL
  683. EXESORTA(Remote, 2)
  684. EXESORT(Remote, Name, dvName, uvName, 2)
  685. EXESORT(Remote, Ext, dvExt, uvExt, 2)
  686. EXESORT(Remote, Size, dvSize, uvSize, 2)
  687. EXESORT(Remote, Changed, dvChanged, uvChanged, 2)
  688. EXESORT(Remote, Rights, dvAttr, uvRights, 2)
  689. EXESORT(Remote, Owner, -1, uvOwner, 2)
  690. EXESORT(Remote, Group, -1, uvGroup, 2)
  691. EXESORT(Remote, Type, dvType, uvType, 2)
  692. EXESORTA(Current, )
  693. EXESORT(Current, Name, dvName, uvName, )
  694. EXESORT(Current, Ext, dvExt, uvExt, )
  695. EXESORT(Current, Size, dvSize, uvSize, )
  696. EXESORT(Current, Type, dvType, uvType, 2)
  697. EXESORT(Current, Changed, dvChanged, uvChanged, )
  698. EXESORT(Current, Rights, dvAttr, uvRights, )
  699. EXESORT(Current, Owner, -1, uvOwner, )
  700. EXESORT(Current, Group, -1, uvGroup, )
  701. EXE(SortColumnAscendingAction, DebugAssert(ListColumn);
  702. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = true; ListColumn = NULL )
  703. EXE(SortColumnDescendingAction, DebugAssert(ListColumn);
  704. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = false; ListColumn = NULL )
  705. // SHOW/HIDE COLUMN
  706. #define EXESHCOLL(NAME) EXESHCOL(Local, NAME, dv ## NAME, -1)
  707. EXESHCOLL(Name)
  708. EXESHCOLL(Ext)
  709. EXESHCOLL(Size)
  710. EXESHCOLL(Type)
  711. EXESHCOLL(Changed)
  712. EXESHCOLL(Attr)
  713. #undef EXESHCOLL
  714. EXESHCOL(Remote, Name, dvName, uvName)
  715. EXESHCOL(Remote, Ext, dvExt, uvExt)
  716. EXESHCOL(Remote, Size, dvSize, uvSize)
  717. EXESHCOL(Remote, Changed, dvChanged, uvChanged)
  718. EXESHCOL(Remote, Rights, dvAttr, uvRights)
  719. EXESHCOL(Remote, Owner, -1, uvOwner)
  720. EXESHCOL(Remote, Group, -1, uvGroup)
  721. EXESHCOL(Remote, LinkTarget, -1, uvLinkTarget)
  722. EXESHCOL(Remote, Type, dvType, uvType)
  723. EXE(HideColumnAction, DebugAssert(ListColumn);
  724. COLVIEWPROPS->Visible[ListColumn->Index] = false; ListColumn = NULL )
  725. EXE(BestFitColumnAction, DebugAssert(ListColumn); ListColumn = NULL ) // TODO
  726. #undef COLVIEWPROPS
  727. // SESSION
  728. EXE(NewSessionAction, ScpExplorer->NewSession())
  729. EXE(NewTabAction, ScpExplorer->NewTab())
  730. EXE(NewRemoteTabAction, ScpExplorer->NewTab(osRemote))
  731. EXE(NewLocalTabAction, ScpExplorer->NewTab(osLocal))
  732. EXE(DefaultToNewRemoteTabAction, WinConfiguration->DefaultToNewRemoteTab = !WinConfiguration->DefaultToNewRemoteTab)
  733. EXE(SiteManagerAction, ScpExplorer->NewSession())
  734. EXE(DuplicateTabAction, ScpExplorer->DuplicateSession())
  735. EXE(RenameTabAction, ScpExplorer->RenameSession())
  736. EXE(CloseTabAction, ScpExplorer->CloseSession())
  737. EXE(DisconnectSessionAction, ScpExplorer->DisconnectSession())
  738. EXE(ReconnectSessionAction, ScpExplorer->ReconnectSession())
  739. EXE(SavedSessionsAction2, CreateSessionListMenu(SavedSessionsAction2))
  740. EXE(WorkspacesAction, CreateWorkspacesMenu(WorkspacesAction))
  741. EXE(OpenedTabsAction, CreateOpenedSessionListMenu(OpenedTabsAction))
  742. EXE(SaveCurrentSessionAction2, ScpExplorer->SaveCurrentSession())
  743. EXE(SaveWorkspaceAction, ScpExplorer->SaveWorkspace(false))
  744. // COMMAND
  745. EXE(CompareDirectoriesAction2, ScpExplorer->CompareDirectories())
  746. EXE(SynchronizeAction, ScpExplorer->SynchronizeDirectories())
  747. EXE(FullSynchronizeAction, ScpExplorer->FullSynchronizeDirectories())
  748. EXE(ConsoleAction, ScpExplorer->OpenConsole())
  749. EXE(PuttyAction, TTerminalManager::Instance()->OpenInPutty())
  750. EXE(SynchronizeBrowsingAction2, ScpExplorer->SynchronizeBrowsingChanged())
  751. EXE(CloseApplicationAction2, ScpExplorer->CloseApp())
  752. EXE(FileSystemInfoAction, ScpExplorer->FileSystemInfo())
  753. EXE(SessionGenerateUrlAction2, ScpExplorer->SessionGenerateUrl())
  754. EXE(ClearCachesAction, ScpExplorer->Terminal->ClearCaches())
  755. EXE(NewFileAction, ScpExplorer->EditNew(osCurrent))
  756. EXE(EditorListCustomizeAction, PreferencesDialog(pmEditor))
  757. EXE(ChangePasswordAction, ScpExplorer->ChangePassword())
  758. EXE(PrivateKeyUploadAction, ScpExplorer->PrivateKeyUpload())
  759. // CUSTOM COMMANDS
  760. EXE(CustomCommandsFileAction, CreateCustomCommandsMenu(CustomCommandsFileAction, ccltFile))
  761. EXE(CustomCommandsNonFileAction, CreateCustomCommandsMenu(CustomCommandsNonFileAction, ccltNonFile))
  762. EXE(CustomCommandsEnterAction, ScpExplorer->AdHocCustomCommand(false))
  763. EXE(CustomCommandsEnterFocusedAction, ScpExplorer->AdHocCustomCommand(true))
  764. EXE(CustomCommandsLastAction, ScpExplorer->LastCustomCommand(false))
  765. EXE(CustomCommandsLastFocusedAction, ScpExplorer->LastCustomCommand(true))
  766. EXE(CustomCommandsCustomizeAction, CustomCommandsCustomize(NULL))
  767. // QUEUE
  768. EXE(QueueEnableAction, ScpExplorer->ToggleQueueEnabled())
  769. #define EXEQUEUE(OPERATION) EXE(Queue ## OPERATION ## Action, \
  770. ScpExplorer->ExecuteQueueOperation(qo ## OPERATION))
  771. EXEQUEUE(GoTo)
  772. EXEQUEUE(Preferences)
  773. EXEQUEUE(ItemQuery)
  774. EXEQUEUE(ItemError)
  775. EXEQUEUE(ItemPrompt)
  776. EXEQUEUE(ItemDelete)
  777. EXEQUEUE(ItemExecute)
  778. EXEQUEUE(ItemPause)
  779. EXEQUEUE(ItemResume)
  780. EXEQUEUE(ItemUp)
  781. EXEQUEUE(ItemDown)
  782. EXEQUEUE(PauseAll)
  783. EXEQUEUE(ResumeAll)
  784. EXEQUEUE(DeleteAll)
  785. EXEQUEUE(DeleteAllDone)
  786. #undef EXEQUEUE
  787. EXE(QueueToggleShowAction, ScpExplorer->ToggleQueueVisibility())
  788. #define QUEUEACTION(SHOW) EXE(Queue ## SHOW ## Action, \
  789. TQueueViewConfiguration Config = WinConfiguration->QueueView; \
  790. if (Config.Show != qvShow) Config.LastHideShow = Config.Show; \
  791. Config.Show = qv ## SHOW; \
  792. WinConfiguration->QueueView = Config)
  793. QUEUEACTION(Show)
  794. QUEUEACTION(HideWhenEmpty)
  795. QUEUEACTION(Hide)
  796. #undef QUEUEACTION
  797. EXE(QueueCycleOnceEmptyAction, CycleQueueOnceEmptyAction())
  798. EXE(QueueIdleOnceEmptyAction, SetQueueOnceEmptyAction(QueueIdleOnceEmptyAction))
  799. EXE(QueueDisconnectOnceEmptyAction2, SetQueueOnceEmptyAction(QueueDisconnectOnceEmptyAction2))
  800. EXE(QueueSuspendOnceEmptyAction2, SetQueueOnceEmptyAction(QueueSuspendOnceEmptyAction2))
  801. EXE(QueueShutDownOnceEmptyAction2, SetQueueOnceEmptyAction(QueueShutDownOnceEmptyAction2))
  802. EXECOMP(QueueToolbar)
  803. EXECOMP(QueueFileList)
  804. EXE(QueueItemSpeedAction, )
  805. ;
  806. }
  807. DoIdle();
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TNonVisualDataModule::UpdateNonVisibleActions()
  811. {
  812. // following actions needs to be updated even when all clients
  813. // are invisible, so the queue list toolbar button can be shown
  814. NonVisualDataModule->QueueItemQueryAction->Update();
  815. NonVisualDataModule->QueueItemErrorAction->Update();
  816. NonVisualDataModule->QueueItemPromptAction->Update();
  817. }
  818. //---------------------------------------------------------------------------
  819. #define CTRL TShiftState() << ssCtrl
  820. #define ALT TShiftState() << ssAlt
  821. #define SHIFT TShiftState() << ssShift
  822. #define CTRLSHIFT TShiftState() << ssCtrl << ssShift
  823. #define CTRLALT TShiftState() << ssCtrl << ssAlt
  824. #define NONE TShiftState()
  825. void __fastcall TNonVisualDataModule::ExplorerShortcuts()
  826. {
  827. // Directory
  828. CurrentCreateDirAction->ShortCut = ShortCut(L'D', CTRL);
  829. // File operation
  830. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  831. CurrentEditAction->ShortCut = ShortCut(L'E', CTRL);
  832. CurrentAddEditLinkAction->ShortCut = ShortCut(L'L', CTRLALT);
  833. CurrentEditInternalAction->ShortCut = 0;
  834. CurrentEditInternalFocusedAction->ShortCut = 0;
  835. // Focused operation
  836. RemoteCopyAction->ShortCut = ShortCut(L'T', CTRL);
  837. RemoteMoveAction->ShortCut = ShortCut(L'M', CTRL);
  838. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_DELETE, NONE);
  839. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_RETURN, ALT);
  840. RemoteMoveToFocusedAction->ShortCut = ShortCut(L'M', CTRLALT);
  841. // remote directory
  842. RemoteOpenDirAction->ShortCut = ShortCut(L'O', CTRL);
  843. RemoteRefreshAction->ShortCut = ShortCut(VK_F5, NONE);
  844. RemoteHomeDirAction->ShortCut = ShortCut(L'H', CTRL);
  845. RemotePathToClipboardAction2->ShortCut = ShortCut(L'P', CTRLSHIFT);
  846. // selected operation
  847. CurrentDeleteAlternativeAction->ShortCut = ShortCut(VK_DELETE, SHIFT);
  848. RemoteMoveToAction->ShortCut = ShortCut(L'M', CTRLALT);
  849. // commands
  850. NewFileAction->ShortCut = ShortCut(L'E', CTRLSHIFT);
  851. RemoteFindFilesAction2->ShortCut = ShortCut(VK_F3, NONE);
  852. CloseApplicationAction2->ShortCut = ShortCut(VK_F4, ALT);
  853. CloneShortcuts();
  854. SessionsNewTabItem->DropdownCombo = false;
  855. SetSubmenu(SessionsNewTabItem, false);
  856. }
  857. //---------------------------------------------------------------------------
  858. void __fastcall TNonVisualDataModule::CommanderShortcuts()
  859. {
  860. bool ExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  861. // Directory
  862. CurrentCreateDirAction->ShortCut = ShortCut(VK_F7, NONE);
  863. // File operation
  864. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  865. CurrentEditAction->ShortCut = ShortCut(VK_F4, NONE);
  866. CurrentAddEditLinkAction->ShortCut = ShortCut(VK_F6, ALT);
  867. CurrentEditInternalAction->ShortCut = ShortCut(VK_F4, CTRLALT);
  868. CurrentEditInternalFocusedAction->ShortCut = ShortCut(VK_F4, CTRLALT);
  869. // Focused operation
  870. RemoteCopyAction->ShortCut =
  871. ExplorerKeyboardShortcuts ? ShortCut(L'K', CTRL) : ShortCut(VK_F5, NONE);
  872. RemoteMoveAction->ShortCut = ShortCut(VK_F6, NONE);
  873. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_F8, NONE);
  874. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_F9, NONE);
  875. RemoteMoveToFocusedAction->ShortCut = ShortCut(VK_F6, SHIFT);
  876. RemoteCopyToFocusedAction->ShortCut = ShortCut(VK_F5, SHIFT);
  877. // remote directory
  878. RemoteOpenDirAction->ShortCut = ShortCut(L'O', CTRL);
  879. RemoteRefreshAction->ShortCut =
  880. ExplorerKeyboardShortcuts ? ShortCut(VK_F5, NONE) : ShortCut(L'R', CTRL);
  881. RemoteHomeDirAction->ShortCut = ShortCut(L'H', CTRL);
  882. RemotePathToClipboardAction2->ShortCut = ShortCut(VK_OEM_6 /* ] */, CTRL);
  883. // local directory
  884. LocalPathToClipboardAction2->ShortCut = ShortCut(VK_OEM_4 /* [ */, CTRL);
  885. // selected operation
  886. CurrentDeleteAction->SecondaryShortCuts->Clear();
  887. CurrentDeleteAction->SecondaryShortCuts->Add(ShortCutToText(ShortCut(VK_DELETE, NONE)));
  888. CurrentDeleteAlternativeAction->ShortCut = ShortCut(VK_F8, SHIFT);
  889. CurrentDeleteAlternativeAction->SecondaryShortCuts->Clear();
  890. CurrentDeleteAlternativeAction->SecondaryShortCuts->Add(ShortCutToText(ShortCut(VK_DELETE, SHIFT)));
  891. RemoteMoveToAction->ShortCut = ShortCut(VK_F6, SHIFT);
  892. RemoteCopyToAction->ShortCut = ShortCut(VK_F5, SHIFT);
  893. // selection
  894. SelectOneAction->ShortCut = VK_INSERT;
  895. // commands
  896. NewFileAction->ShortCut = ShortCut(VK_F4, SHIFT);
  897. RemoteFindFilesAction2->ShortCut =
  898. ExplorerKeyboardShortcuts ? ShortCut(VK_F3, NONE) : ShortCut(VK_F7, ALT);
  899. NewTabAction->ShortCut = ShortCut(L'T', CTRL);
  900. // legacy shortcut (can be removed when necessary)
  901. NewFileAction->SecondaryShortCuts->Clear();
  902. NewFileAction->SecondaryShortCuts->Add(ShortCutToText(ShortCut(VK_F4, CTRLSHIFT)));
  903. CloseApplicationAction2->ShortCut = ShortCut(VK_F10, NONE);
  904. TShortCut CtrlF4 = ShortCut(VK_F4, CTRL);
  905. LocalSortByExtAction2->ShortCut = ExplorerKeyboardShortcuts ? TShortCut(0) : CtrlF4;
  906. RemoteSortByExtAction2->ShortCut = LocalSortByExtAction2->ShortCut;
  907. CurrentSortByExtAction->ShortCut = LocalSortByExtAction2->ShortCut;
  908. int Index = CloseTabAction->SecondaryShortCuts->IndexOfShortCut(CtrlF4);
  909. if (ExplorerKeyboardShortcuts && (Index < 0))
  910. {
  911. CloseTabAction->SecondaryShortCuts->Add(ShortCutToText(CtrlF4));
  912. }
  913. else if (!ExplorerKeyboardShortcuts && (Index >= 0))
  914. {
  915. CloseTabAction->SecondaryShortCuts->Delete(Index);
  916. }
  917. CloneShortcuts();
  918. }
  919. #undef CTRL
  920. #undef ALT
  921. #undef NONE
  922. //---------------------------------------------------------------------------
  923. void __fastcall TNonVisualDataModule::CloneShortcuts()
  924. {
  925. // Commands
  926. NewDirAction->ShortCut = CurrentCreateDirAction->ShortCut;
  927. // File operation
  928. CurrentAddEditLinkContextAction->ShortCut = CurrentAddEditLinkAction->ShortCut;
  929. LocalAddEditLinkAction3->ShortCut = CurrentAddEditLinkAction->ShortCut;
  930. RemoteAddEditLinkAction3->ShortCut = CurrentAddEditLinkAction->ShortCut;
  931. RemoteNewFileAction->ShortCut = NewFileAction->ShortCut;
  932. LocalNewFileAction->ShortCut = NewFileAction->ShortCut;
  933. // local directory
  934. LocalOpenDirAction->ShortCut = RemoteOpenDirAction->ShortCut;
  935. LocalRefreshAction->ShortCut = RemoteRefreshAction->ShortCut;
  936. LocalHomeDirAction->ShortCut = RemoteHomeDirAction->ShortCut;
  937. // selected operation
  938. CurrentDeleteAction->ShortCut = CurrentDeleteFocusedAction->ShortCut;
  939. CurrentPropertiesAction->ShortCut = CurrentPropertiesFocusedAction->ShortCut;
  940. // local selected operation
  941. LocalCopyAction->ShortCut = RemoteCopyAction->ShortCut;
  942. LocalLocalCopyAction->ShortCut = RemoteCopyAction->ShortCut;
  943. LocalOtherCopyAction->ShortCut = RemoteCopyAction->ShortCut;
  944. LocalRenameAction2->ShortCut = CurrentRenameAction->ShortCut;
  945. LocalEditAction2->ShortCut = CurrentEditAction->ShortCut;
  946. LocalMoveAction->ShortCut = RemoteMoveAction->ShortCut;
  947. LocalLocalMoveAction->ShortCut = LocalMoveAction->ShortCut;
  948. LocalOtherMoveAction->ShortCut = LocalMoveAction->ShortCut;
  949. LocalCreateDirAction3->ShortCut = CurrentCreateDirAction->ShortCut;
  950. LocalDeleteAction2->ShortCut = CurrentDeleteAction->ShortCut;
  951. LocalPropertiesAction2->ShortCut = CurrentPropertiesAction->ShortCut;
  952. // local focused operation
  953. LocalCopyFocusedAction->ShortCut = LocalCopyAction->ShortCut;
  954. LocalMoveFocusedAction->ShortCut = LocalMoveAction->ShortCut;
  955. LocalLocalCopyFocusedAction->ShortCut = LocalCopyAction->ShortCut;
  956. LocalLocalMoveFocusedAction->ShortCut = LocalMoveAction->ShortCut;
  957. // remote selected operation
  958. RemoteRenameAction2->ShortCut = CurrentRenameAction->ShortCut;
  959. RemoteEditAction2->ShortCut = CurrentEditAction->ShortCut;
  960. RemoteCreateDirAction3->ShortCut = CurrentCreateDirAction->ShortCut;
  961. RemoteDeleteAction2->ShortCut = CurrentDeleteAction->ShortCut;
  962. RemotePropertiesAction2->ShortCut = CurrentPropertiesAction->ShortCut;
  963. // remote focused operation
  964. RemoteCopyFocusedAction->ShortCut = RemoteCopyAction->ShortCut;
  965. RemoteMoveFocusedAction->ShortCut = RemoteMoveAction->ShortCut;
  966. // selection
  967. LocalSelectAction2->ShortCut = SelectAction->ShortCut;
  968. LocalUnselectAction2->ShortCut = UnselectAction->ShortCut;
  969. LocalSelectAllAction2->ShortCut = SelectAllAction->ShortCut;
  970. RemoteSelectAction2->ShortCut = SelectAction->ShortCut;
  971. RemoteUnselectAction2->ShortCut = UnselectAction->ShortCut;
  972. RemoteSelectAllAction2->ShortCut = SelectAllAction->ShortCut;
  973. }
  974. //---------------------------------------------------------------------------
  975. void __fastcall TNonVisualDataModule::SetScpExplorer(TCustomScpExplorerForm * value)
  976. {
  977. FScpExplorer = value;
  978. SessionIdleTimer->Enabled = (FScpExplorer != NULL);
  979. }
  980. //---------------------------------------------------------------------------
  981. void __fastcall TNonVisualDataModule::SessionIdleTimerTimer(
  982. TObject */*Sender*/)
  983. {
  984. DoIdle();
  985. }
  986. //---------------------------------------------------------------------------
  987. void __fastcall TNonVisualDataModule::DoIdle()
  988. {
  989. if (!FSessionIdleTimerExecuting)
  990. {
  991. FSessionIdleTimerExecuting = true;
  992. try
  993. {
  994. DebugAssert(ScpExplorer);
  995. ScpExplorer->Idle();
  996. }
  997. __finally
  998. {
  999. FSessionIdleTimerExecuting = false;
  1000. }
  1001. }
  1002. }
  1003. //---------------------------------------------------------------------------
  1004. UnicodeString __fastcall TNonVisualDataModule::CustomCommandCaption(const TCustomCommandType * Command, bool Toolbar)
  1005. {
  1006. UnicodeString Result = Command->Name;
  1007. if (Toolbar)
  1008. {
  1009. Result = StripHotkey(Result);
  1010. Result = EscapeHotkey(Result);
  1011. }
  1012. return Result;
  1013. }
  1014. //---------------------------------------------------------------------------
  1015. UnicodeString __fastcall TNonVisualDataModule::CustomCommandHint(const TCustomCommandType * Command)
  1016. {
  1017. UnicodeString Name = StripHotkey(Command->Name);
  1018. UnicodeString LongHint =
  1019. !Command->Description.IsEmpty() ? Command->Description : FMTLOAD(CUSTOM_COMMAND_HINT_LONG, (Name, Command->Command));
  1020. UnicodeString Result = FORMAT(L"%s|%s", (Name, LongHint));
  1021. return Result;
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. const int CustomCommandOnFocused = 0x0100;
  1025. const int CustomCommandBoth = 0x0200;
  1026. const int CustomCommandExtension = 0x0400;
  1027. const int CustomCommandIndexMask = 0x00FF;
  1028. //---------------------------------------------------------------------------
  1029. // See IsValidIdent
  1030. static UnicodeString MakeIdent(const UnicodeString & S)
  1031. {
  1032. UnicodeString Result;
  1033. for (int Index = 1; Index <= S.Length(); Index++)
  1034. {
  1035. wchar_t C = S[Index];
  1036. if (IsLetter(C) ||
  1037. (!Result.IsEmpty() && IsDigit(C)))
  1038. {
  1039. Result += C;
  1040. }
  1041. }
  1042. return Result;
  1043. }
  1044. //---------------------------------------------------------------------------
  1045. int __fastcall TNonVisualDataModule::CreateCustomCommandsListMenu(
  1046. TCustomCommandList * List, TTBCustomItem * Menu, bool OnFocused, bool Toolbar, TCustomCommandListType ListType,
  1047. int Tag, TStrings * HiddenCommands)
  1048. {
  1049. int Result = 0;
  1050. for (int Index = 0; Index < List->Count; Index++)
  1051. {
  1052. const TCustomCommandType * Command = List->Commands[Index];
  1053. int State = ScpExplorer->CustomCommandState(*Command, OnFocused, ListType);
  1054. if (State >= 0)
  1055. {
  1056. TTBCustomItem * Item = new TTBXItem(Owner);
  1057. Item->Caption = CustomCommandCaption(Command, Toolbar);
  1058. Item->Tag = Index | Tag;
  1059. Item->Enabled = (State > 0);
  1060. if (Toolbar)
  1061. {
  1062. UnicodeString Name = ExtractFileName(Command->Id);
  1063. if (Name.IsEmpty())
  1064. {
  1065. Name = Command->Name;
  1066. }
  1067. Name = MakeIdent(Name);
  1068. Name += L"CustomCommand";
  1069. // This is only the last resort to avoid run-time errors.
  1070. // If there are duplicates, button hidding won't be deterministic.
  1071. int X = 0;
  1072. UnicodeString UniqueName = Name;
  1073. while (Owner->FindComponent(UniqueName) != NULL)
  1074. {
  1075. X++;
  1076. UniqueName = FORMAT(L"%s%d", (Name, X));
  1077. }
  1078. Item->Name = UniqueName;
  1079. Item->Visible = (HiddenCommands->IndexOf(Item->Name) < 0);
  1080. }
  1081. if (OnFocused)
  1082. {
  1083. Item->Tag = Item->Tag | CustomCommandOnFocused;
  1084. }
  1085. if (ListType == ccltBoth)
  1086. {
  1087. Item->Tag = Item->Tag | CustomCommandBoth;
  1088. }
  1089. Item->Hint = CustomCommandHint(Command);
  1090. Item->ShortCut = Command->ShortCut;
  1091. Item->OnClick = CustomCommandClick;
  1092. Menu->Add(Item);
  1093. Result++;
  1094. }
  1095. }
  1096. return Result;
  1097. }
  1098. //---------------------------------------------------------------------------
  1099. void __fastcall TNonVisualDataModule::CustomCommandsCustomize(TObject *)
  1100. {
  1101. PreferencesDialog(pmCustomCommands);
  1102. }
  1103. //---------------------------------------------------------------------------
  1104. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(
  1105. TTBCustomItem * Menu, bool OnFocused, bool Toolbar, TCustomCommandListType ListType, TStrings * HiddenCommands)
  1106. {
  1107. CreateCustomCommandsListMenu(WinConfiguration->CustomCommandList, Menu, OnFocused, Toolbar, ListType, 0, HiddenCommands);
  1108. TTBCustomItem * Item;
  1109. if ((ListType == ccltAll) || (ListType == ccltFile) || (ListType == ccltNonFile))
  1110. {
  1111. Item = new TTBXItem(Menu);
  1112. Item->Action = OnFocused ? CustomCommandsEnterFocusedAction : CustomCommandsEnterAction;
  1113. Menu->Add(Item);
  1114. GiveTBItemPriority(Item);
  1115. Item = new TTBXItem(Menu);
  1116. Item->Action = OnFocused ? CustomCommandsLastFocusedAction : CustomCommandsLastAction;
  1117. if (Toolbar)
  1118. {
  1119. Item->Caption = EscapeHotkey(StripHotkey(LoadStr(CUSTOM_COMMAND_LAST_SHORT)));
  1120. }
  1121. Menu->Add(Item);
  1122. GiveTBItemPriority(Item);
  1123. }
  1124. TTBXSeparatorItem * Separator = AddMenuSeparator(Menu);
  1125. int ExtensionItems =
  1126. CreateCustomCommandsListMenu(WinConfiguration->ExtensionList, Menu, OnFocused, Toolbar, ListType, CustomCommandExtension, HiddenCommands);
  1127. Separator->Visible = (ExtensionItems > 0);
  1128. AddMenuSeparator(Menu);
  1129. if (((ListType == ccltFile) || ((ListType == ccltNonFile) && !OnFocused)) && DebugAlwaysTrue(!Toolbar))
  1130. {
  1131. Item = new TTBXSubmenuItem(Menu);
  1132. // copy the texts from the action, but do not use is as a handler, because it will duplicate the auxiliary commands in the submenu
  1133. Item->Action = (ListType == ccltFile) ? CustomCommandsNonFileAction : CustomCommandsFileAction;
  1134. Item->Action = NULL;
  1135. TCustomCommandListType SubListType = (ListType == ccltFile) ? ccltNonFile : ccltFile;
  1136. int CustomCommandItems = CreateCustomCommandsListMenu(WinConfiguration->CustomCommandList, Item, OnFocused, Toolbar, SubListType, 0, HiddenCommands);
  1137. TTBXSeparatorItem * Separator = AddMenuSeparator(Item);
  1138. int ExtensionItems = CreateCustomCommandsListMenu(WinConfiguration->ExtensionList, Item, OnFocused, Toolbar, SubListType, CustomCommandExtension, HiddenCommands);
  1139. Separator->Visible = (ExtensionItems > 0);
  1140. Item->Enabled = (CustomCommandItems + ExtensionItems > 0);
  1141. Menu->Add(Item);
  1142. }
  1143. if (!Toolbar && (ListType != ccltBoth))
  1144. {
  1145. Item = new TTBXItem(Menu);
  1146. Item->Action = CustomCommandsBandAction;
  1147. Menu->Add(Item);
  1148. GiveTBItemPriority(Item);
  1149. }
  1150. Item = new TTBXItem(Menu);
  1151. Item->Action = CustomCommandsCustomizeAction;
  1152. if (ListType == ccltBoth)
  1153. {
  1154. // Hack. Bypass the Busy test in ExplorerActionsExecute.
  1155. Item->OnClick = CustomCommandsCustomize;
  1156. }
  1157. Menu->Add(Item);
  1158. GiveTBItemPriority(Item);
  1159. }
  1160. //---------------------------------------------------------------------------
  1161. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(
  1162. TAction * Action, bool OnFocused, TCustomCommandListType ListType)
  1163. {
  1164. DebugAssert(Action);
  1165. TTBCustomItem * Menu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  1166. if (Menu)
  1167. {
  1168. int PrevCount = Menu->Count;
  1169. CreateCustomCommandsMenu(Menu, OnFocused, false, ListType, NULL);
  1170. for (int Index = 0; Index < PrevCount; Index++)
  1171. {
  1172. Menu->Delete(0);
  1173. }
  1174. }
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(TAction * Action, TCustomCommandListType ListType)
  1178. {
  1179. TTBCustomItem * Menu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  1180. if (DebugAlwaysTrue(Menu != NULL))
  1181. {
  1182. bool OnFocused =
  1183. (Menu == RemoteDirViewPopupCustomCommandsMenu) || (Menu == LocalFilePopupCustomCommandsMenu) || (Menu == RemoteFilePopupCustomCommandsMenu);
  1184. CreateCustomCommandsMenu(Action, OnFocused, ListType);
  1185. }
  1186. }
  1187. //---------------------------------------------------------------------------
  1188. bool __fastcall TNonVisualDataModule::CheckCustomCommandsToolbarList(TTBXToolbar * Toolbar, TCustomCommandList * List, int & Index)
  1189. {
  1190. bool Changed = false;
  1191. int CommandIndex = 0;
  1192. while (!Changed && (CommandIndex < List->Count))
  1193. {
  1194. TTBCustomItem * Item = Toolbar->Items->Items[Index];
  1195. const TCustomCommandType * Command = List->Commands[CommandIndex];
  1196. UnicodeString Caption = CustomCommandCaption(Command, true);
  1197. UnicodeString Hint = CustomCommandHint(Command);
  1198. Changed =
  1199. (Item->Caption != Caption) ||
  1200. (Item->Hint != Hint);
  1201. Index++;
  1202. CommandIndex++;
  1203. }
  1204. return Changed;
  1205. }
  1206. //---------------------------------------------------------------------------
  1207. void __fastcall TNonVisualDataModule::UpdateCustomCommandsToolbarList(TTBXToolbar * Toolbar, TCustomCommandList * List, int & Index)
  1208. {
  1209. for (int CommandIndex = 0; CommandIndex < List->Count; CommandIndex++, Index++)
  1210. {
  1211. TTBCustomItem * Item = Toolbar->Items->Items[Index];
  1212. DebugAssert((Item->Tag & CustomCommandIndexMask) == CommandIndex);
  1213. int State = ScpExplorer->CustomCommandState(*List->Commands[CommandIndex], false, ccltAll);
  1214. DebugAssert(State >= 0);
  1215. Item->Enabled = (State > 0);
  1216. }
  1217. }
  1218. //---------------------------------------------------------------------------
  1219. void __fastcall TNonVisualDataModule::UpdateCustomCommandsToolbar(TTBXToolbar * Toolbar)
  1220. {
  1221. TCustomCommandList * CustomCommandList = WinConfiguration->CustomCommandList;
  1222. TCustomCommandList * ExtensionList = WinConfiguration->ExtensionList;
  1223. int AfterCustomCommandsCommandCount = 2; // ad hoc, last
  1224. int AdditionalCommands = AfterCustomCommandsCommandCount + 3; // custom/ext separator + separator, customize
  1225. int CommandCount = CustomCommandList->Count + ExtensionList->Count;
  1226. bool Changed = (CommandCount + AdditionalCommands != Toolbar->Items->Count);
  1227. if (!Changed)
  1228. {
  1229. int Index = 0;
  1230. Changed = CheckCustomCommandsToolbarList(Toolbar, CustomCommandList, Index);
  1231. if (!Changed)
  1232. {
  1233. Index += AfterCustomCommandsCommandCount;
  1234. Changed = (dynamic_cast<TTBXSeparatorItem *>(Toolbar->Items->Items[Index]) == NULL);
  1235. Index++;
  1236. if (!Changed)
  1237. {
  1238. Changed = CheckCustomCommandsToolbarList(Toolbar, ExtensionList, Index);
  1239. }
  1240. }
  1241. }
  1242. if (Changed)
  1243. {
  1244. Toolbar->BeginUpdate();
  1245. try
  1246. {
  1247. std::unique_ptr<TStrings> HiddenCommands(CreateSortedStringList());
  1248. for (int Index = 0; Index < Toolbar->Items->Count; Index++)
  1249. {
  1250. TTBCustomItem * Item = Toolbar->Items->Items[Index];
  1251. if (IsCustomizableToolbarItem(Item) && !Item->Visible)
  1252. {
  1253. HiddenCommands->Add(Item->Name);
  1254. }
  1255. }
  1256. Toolbar->Items->Clear();
  1257. CreateCustomCommandsMenu(Toolbar->Items, false, true, ccltAll, HiddenCommands.get());
  1258. DebugAssert(CommandCount + AdditionalCommands == Toolbar->Items->Count);
  1259. }
  1260. __finally
  1261. {
  1262. Toolbar->EndUpdate();
  1263. }
  1264. }
  1265. else
  1266. {
  1267. int Index = 0;
  1268. UpdateCustomCommandsToolbarList(Toolbar, CustomCommandList, Index);
  1269. Index += AfterCustomCommandsCommandCount + 1;
  1270. UpdateCustomCommandsToolbarList(Toolbar, ExtensionList, Index);
  1271. }
  1272. }
  1273. //---------------------------------------------------------------------------
  1274. void __fastcall TNonVisualDataModule::CustomCommandClick(TObject * Sender)
  1275. {
  1276. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1277. DebugAssert(Item);
  1278. const TCustomCommandList * List = FLAGSET(Item->Tag, CustomCommandExtension) ? WinConfiguration->ExtensionList : WinConfiguration->CustomCommandList;
  1279. const TCustomCommandType * Command = List->Commands[Item->Tag & CustomCommandIndexMask];
  1280. if (FLAGCLEAR(Item->Tag, CustomCommandBoth))
  1281. {
  1282. ScpExplorer->ExecuteFileOperationCommand(foCustomCommand, osRemote,
  1283. FLAGSET(Item->Tag, CustomCommandOnFocused), false, const_cast<TCustomCommandType *>(Command));
  1284. }
  1285. else
  1286. {
  1287. ScpExplorer->BothCustomCommand(*Command);
  1288. }
  1289. }
  1290. //---------------------------------------------------------------------------
  1291. void __fastcall TNonVisualDataModule::CreateSessionColorMenu(TAction * Action)
  1292. {
  1293. if (DebugAlwaysTrue(Action->ActionComponent != NULL))
  1294. {
  1295. ::CreateSessionColorMenu(Action->ActionComponent, ScpExplorer->SessionColor,
  1296. SessionColorChange);
  1297. }
  1298. }
  1299. //---------------------------------------------------------------------------
  1300. void __fastcall TNonVisualDataModule::SessionColorChange(TColor Color)
  1301. {
  1302. ScpExplorer->SessionColor = Color;
  1303. }
  1304. //---------------------------------------------------------------------------
  1305. void __fastcall TNonVisualDataModule::CreateSessionListMenu(TAction * Action)
  1306. {
  1307. StoredSessions->Reload();
  1308. CreateSessionListMenuLevel(
  1309. dynamic_cast<TTBCustomItem *>(Action->ActionComponent), 0, 0);
  1310. }
  1311. //---------------------------------------------------------------------------
  1312. UnicodeString __fastcall TNonVisualDataModule::GetSessionFolderRoot(
  1313. TSessionData * Data, int Level)
  1314. {
  1315. UnicodeString Path = Data->Name;
  1316. UnicodeString Root;
  1317. for (int ALevel = 0; ALevel < Level; ALevel++)
  1318. {
  1319. Root.Insert(CutToChar(Path, L'/', false) + L'/', Root.Length() + 1);
  1320. }
  1321. return Root;
  1322. }
  1323. //---------------------------------------------------------------------------
  1324. void __fastcall TNonVisualDataModule::CreateSessionListMenuLevel(
  1325. TTBCustomItem * Menu, int Index, int Level)
  1326. {
  1327. Menu->Clear();
  1328. TTBCustomItem * Item = new TTBXItem(Menu);
  1329. UnicodeString Root;
  1330. if (Level == 0)
  1331. {
  1332. Item->Action = SiteManagerAction;
  1333. Root = L"";
  1334. }
  1335. else
  1336. {
  1337. DebugAssert(Index < StoredSessions->Count);
  1338. TSessionData * Data = StoredSessions->Sessions[Index];
  1339. Root = GetSessionFolderRoot(Data, Level);
  1340. Item->Caption = LoadStr(SAVEDSESSIONFOLDER_THIS_OPEN);
  1341. Item->Tag = MAKELONG(Index, Level);
  1342. UnicodeString FolderName = Root;
  1343. if (DebugAlwaysTrue(!FolderName.IsEmpty() && FolderName[FolderName.Length()] == L'/'))
  1344. {
  1345. FolderName.Delete(FolderName.Length(), 1);
  1346. }
  1347. Item->Hint = FMTLOAD(SAVEDSESSIONFOLDER_THIS_HINT, (FolderName));
  1348. Item->OnClick = SessionFolderThisItemClick;
  1349. }
  1350. Menu->Insert(Menu->Count, Item);
  1351. AddMenuSeparator(Menu);
  1352. int FirstSession = Menu->Count;
  1353. UnicodeString PrevName;
  1354. while (Index < StoredSessions->Count)
  1355. {
  1356. TSessionData * Data = StoredSessions->Sessions[Index];
  1357. if (!AnsiSameText(Data->Name.SubString(1, Root.Length()), Root))
  1358. {
  1359. // Sessions are sorted, so no chance further sessions may match
  1360. break;
  1361. }
  1362. else if (!Data->IsWorkspace)
  1363. {
  1364. UnicodeString Name = Data->Name.SubString(Root.Length() + 1, Data->Name.Length() - Root.Length());
  1365. int P = Name.Pos(L'/');
  1366. if (P > 0)
  1367. {
  1368. Name.SetLength(P - 1);
  1369. }
  1370. if (Name != PrevName)
  1371. {
  1372. if (P > 0)
  1373. {
  1374. TTBCustomItem * Item = new TTBXSubmenuItem(Menu);
  1375. Item->Caption = Name;
  1376. Item->Tag = ((Level + 1) << 16) | Index; // MAKELONG
  1377. Item->ImageIndex = SavedSessionsAction2->ImageIndex;
  1378. Item->OnClick = SessionFolderItemClick;
  1379. Menu->Insert(FirstSession, Item);
  1380. FirstSession++;
  1381. }
  1382. else
  1383. {
  1384. TTBCustomItem * Item = new TTBXItem(Menu);
  1385. Item->Caption = Name;
  1386. Item->Tag = Index;
  1387. Item->Hint = FMTLOAD(SAVEDSESSION_HINT, (Data->Name));
  1388. Item->OnClick = SessionItemClick;
  1389. Menu->Insert(Menu->Count, Item);
  1390. }
  1391. PrevName = Name;
  1392. }
  1393. }
  1394. Index++;
  1395. }
  1396. }
  1397. //---------------------------------------------------------------------------
  1398. void __fastcall TNonVisualDataModule::SessionFolderItemClick(TObject * Sender)
  1399. {
  1400. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  1401. DebugAssert(Item != NULL);
  1402. CreateSessionListMenuLevel(Item, LOWORD(Item->Tag), HIWORD(Item->Tag));
  1403. }
  1404. //---------------------------------------------------------------------------
  1405. void __fastcall TNonVisualDataModule::SessionFolderThisItemClick(TObject * Sender)
  1406. {
  1407. TTBCustomItem * Item = DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender));
  1408. int Index = LOWORD(Item->Tag);
  1409. int Level = HIWORD(Item->Tag);
  1410. UnicodeString Folder = GetSessionFolderRoot(StoredSessions->Sessions[Index], Level);
  1411. ScpExplorer->OpenFolderOrWorkspace(Folder);
  1412. }
  1413. //---------------------------------------------------------------------------
  1414. void __fastcall TNonVisualDataModule::SessionItemClick(TObject * Sender)
  1415. {
  1416. DebugAssert(StoredSessions && (((TTBCustomItem *)Sender)->Tag < StoredSessions->Count));
  1417. ScpExplorer->OpenStoredSession(StoredSessions->Sessions[((TTBCustomItem *)Sender)->Tag]);
  1418. }
  1419. //---------------------------------------------------------------------------
  1420. void __fastcall TNonVisualDataModule::CreateWorkspacesMenu(TAction * Action)
  1421. {
  1422. StoredSessions->Reload();
  1423. if (!StoredSessions->HasAnyWorkspace())
  1424. {
  1425. Abort();
  1426. }
  1427. else
  1428. {
  1429. TTBCustomItem * Menu =
  1430. DebugNotNull(dynamic_cast<TTBCustomItem *>(Action->ActionComponent));
  1431. Menu->Clear();
  1432. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  1433. for (int Index = 0; Index < Workspaces->Count; Index++)
  1434. {
  1435. TTBCustomItem * Item = new TTBXItem(Menu);
  1436. Item->Caption = Workspaces->Strings[Index];
  1437. Item->Tag = Index;
  1438. Item->Hint = FMTLOAD(WORKSPACE_HINT, (Workspaces->Strings[Index]));
  1439. Item->OnClick = WorkspaceItemClick;
  1440. Menu->Insert(Menu->Count, Item);
  1441. }
  1442. }
  1443. }
  1444. //---------------------------------------------------------------------------
  1445. void __fastcall TNonVisualDataModule::WorkspaceItemClick(TObject * Sender)
  1446. {
  1447. std::unique_ptr<TStrings> Workspaces(StoredSessions->GetWorkspaces());
  1448. ScpExplorer->OpenFolderOrWorkspace(
  1449. Workspaces->Strings[DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender))->Tag]);
  1450. }
  1451. //---------------------------------------------------------------------------
  1452. TShortCut __fastcall TNonVisualDataModule::OpenSessionShortCut(int Index)
  1453. {
  1454. if (Index >= 0 && Index < 10)
  1455. {
  1456. return ShortCut((Word)(Index < 9 ? L'0' + 1 + Index : L'0'),
  1457. TShiftState() << ssAlt);
  1458. }
  1459. else
  1460. {
  1461. return scNone;
  1462. }
  1463. }
  1464. //---------------------------------------------------------------------------
  1465. void __fastcall TNonVisualDataModule::CreateOpenedSessionListMenu(TAction * Action)
  1466. {
  1467. TTBCustomItem * OpenedSessionsMenu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  1468. DebugAssert(OpenedSessionsMenu != NULL);
  1469. TTerminalManager * Manager = TTerminalManager::Instance();
  1470. TStrings * SessionList = Manager->SessionList;
  1471. int PrevCount = OpenedSessionsMenu->Count;
  1472. for (int Index = 0; Index < SessionList->Count; Index++)
  1473. {
  1474. TManagedTerminal * Session = dynamic_cast<TManagedTerminal *>(SessionList->Objects[Index]);
  1475. DebugAssert(Session != NULL);
  1476. TTBCustomItem * Item = new TTBXItem(OpenedSessionsMenu);
  1477. Item->Caption = SessionList->Strings[Index];
  1478. Item->Tag = int(Session);
  1479. Item->Hint = FMTLOAD(OPENED_TAB_HINT, (Item->Caption));
  1480. Item->Checked = (Manager->ActiveSession == Session);
  1481. Item->ShortCut = OpenSessionShortCut(Index);
  1482. Item->OnClick = OpenedSessionItemClick;
  1483. Item->RadioItem = true;
  1484. OpenedSessionsMenu->Add(Item);
  1485. }
  1486. for (int Index = 0; Index < PrevCount; Index++)
  1487. {
  1488. OpenedSessionsMenu->Delete(0);
  1489. }
  1490. }
  1491. //---------------------------------------------------------------------------
  1492. void __fastcall TNonVisualDataModule::OpenedSessionItemClick(TObject * Sender)
  1493. {
  1494. TTerminalManager::Instance()->ActiveSession = (TManagedTerminal*)(((TMenuItem *)Sender)->Tag);
  1495. }
  1496. //---------------------------------------------------------------------------
  1497. void __fastcall TNonVisualDataModule::CreateEditorListMenu(TTBCustomItem * Menu, bool OnFocused)
  1498. {
  1499. DebugAssert(Menu != NULL);
  1500. int PrevCount = Menu->Count;
  1501. TTBCustomItem * Item;
  1502. Item = new TTBXItem(Menu);
  1503. Item->Action = OnFocused ? CurrentEditFocusedAction : CurrentEditAction;
  1504. Menu->Add(Item);
  1505. AddMenuSeparator(Menu);
  1506. Item = new TTBXItem(Menu);
  1507. Item->Action = OnFocused ? CurrentEditInternalFocusedAction : CurrentEditInternalAction;
  1508. Menu->Add(Item);
  1509. AddMenuSeparator(Menu);
  1510. TStringList * UsedEditors = CreateSortedStringList();
  1511. try
  1512. {
  1513. const TEditorList * EditorList = WinConfiguration->EditorList;
  1514. for (int Index = 0; Index < EditorList->Count; Index++)
  1515. {
  1516. const TEditorPreferences * Editor = EditorList->Editors[Index];
  1517. if ((Editor->Data->Editor == edExternal) &&
  1518. (UsedEditors->IndexOf(Editor->Data->ExternalEditor) < 0))
  1519. {
  1520. UsedEditors->Add(Editor->Data->ExternalEditor);
  1521. TTBCustomItem * Item = new TTBXItem(Menu);
  1522. Item->Caption = Editor->Name;
  1523. Item->Tag = Index;
  1524. Item->Hint = FMTLOAD(EXTERNAL_EDITOR_HINT, (Editor->Name));
  1525. if (OnFocused)
  1526. {
  1527. Item->OnClick = EditorItemClickFocused;
  1528. }
  1529. else
  1530. {
  1531. Item->OnClick = EditorItemClick;
  1532. }
  1533. Menu->Add(Item);
  1534. }
  1535. }
  1536. Item = new TTBXItem(Menu);
  1537. Item->Action = OnFocused ? CurrentEditWithFocusedAction : CurrentEditWithAction;
  1538. Menu->Add(Item);
  1539. AddMenuSeparator(Menu);
  1540. Item = new TTBXItem(Menu);
  1541. Item->Action = EditorListCustomizeAction;
  1542. Menu->Add(Item);
  1543. for (int Index = 0; Index < PrevCount; Index++)
  1544. {
  1545. Menu->Delete(0);
  1546. }
  1547. }
  1548. __finally
  1549. {
  1550. delete UsedEditors;
  1551. }
  1552. }
  1553. //---------------------------------------------------------------------------
  1554. void __fastcall TNonVisualDataModule::DoEditorItemClick(TObject * Sender, bool OnFocused)
  1555. {
  1556. int Tag = dynamic_cast<TTBXItem*>(Sender)->Tag;
  1557. const TEditorList * EditorList = WinConfiguration->EditorList;
  1558. // sanity check
  1559. if (Tag < EditorList->Count)
  1560. {
  1561. ScpExplorer->ExecuteFile(osCurrent, efExternalEditor, EditorList->Editors[Tag]->Data,
  1562. true, OnFocused);
  1563. }
  1564. }
  1565. //---------------------------------------------------------------------------
  1566. void __fastcall TNonVisualDataModule::EditorItemClick(TObject * Sender)
  1567. {
  1568. DoEditorItemClick(Sender, false);
  1569. }
  1570. //---------------------------------------------------------------------------
  1571. void __fastcall TNonVisualDataModule::EditorItemClickFocused(TObject * Sender)
  1572. {
  1573. DoEditorItemClick(Sender, true);
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. void __fastcall TNonVisualDataModule::QueuePopupPopup(TObject * /*Sender*/)
  1577. {
  1578. TAction * Action = NULL;
  1579. switch (ScpExplorer->DefaultQueueOperation())
  1580. {
  1581. case qoItemQuery:
  1582. Action = QueueItemQueryAction;
  1583. break;
  1584. case qoItemError:
  1585. Action = QueueItemErrorAction;
  1586. break;
  1587. case qoItemPrompt:
  1588. Action = QueueItemPromptAction;
  1589. break;
  1590. case qoItemExecute:
  1591. Action = QueueItemExecuteAction;
  1592. break;
  1593. case qoItemPause:
  1594. Action = QueueItemPauseAction;
  1595. break;
  1596. case qoItemResume:
  1597. Action = QueueItemResumeAction;
  1598. break;
  1599. }
  1600. TTBCustomItem * Item;
  1601. for (int Index = 0; Index < QueuePopup->Items->Count; Index++)
  1602. {
  1603. Item = QueuePopup->Items->Items[Index];
  1604. TTBItemOptions O = Item->Options;
  1605. if ((Action != NULL) && (Item->Action == Action))
  1606. {
  1607. O << tboDefault;
  1608. }
  1609. else
  1610. {
  1611. O >> tboDefault;
  1612. }
  1613. Item->Options = O;
  1614. }
  1615. QueueSpeedComboBoxItemUpdate(QueuePopupSpeedComboBoxItem);
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. void __fastcall TNonVisualDataModule::ShowUpdatesUpdate()
  1619. {
  1620. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  1621. unsigned short H, M, S, MS;
  1622. DecodeTime(Now(), H, M, S, MS);
  1623. int CurrentCompoundVer = Configuration->CompoundVersion;
  1624. CheckForUpdatesAction->ImageIndex =
  1625. ((Updates.HaveResults && (Updates.Results.ForVersion == CurrentCompoundVer) &&
  1626. !Updates.Results.Disabled &&
  1627. ((Updates.Results.Critical && !Updates.ShownResults && (MS >= 500)) ||
  1628. ((!Updates.Results.Critical || Updates.ShownResults) &&
  1629. ((Updates.Results.Version > CurrentCompoundVer) ||
  1630. !Updates.Results.Message.IsEmpty())))) ? 80 :
  1631. ((int(Updates.Period) <= 0) ? 81 : 63));
  1632. CheckForUpdatesAction->Visible = !IsUWP();
  1633. }
  1634. //---------------------------------------------------------------------------
  1635. void __fastcall TNonVisualDataModule::PreferencesDialog(TPreferencesMode APreferencesMode)
  1636. {
  1637. if (ScpExplorer != NULL)
  1638. {
  1639. ScpExplorer->PreferencesDialog(APreferencesMode);
  1640. }
  1641. else
  1642. {
  1643. DoPreferencesDialog(APreferencesMode);
  1644. }
  1645. }
  1646. //---------------------------------------------------------------------------
  1647. void __fastcall TNonVisualDataModule::CustomCommandsLastUpdate(TAction * Action)
  1648. {
  1649. TCustomCommandType Command;
  1650. int State;
  1651. bool Defined = ScpExplorer->GetLastCustomCommand(
  1652. (Action == CustomCommandsLastFocusedAction), Command, State);
  1653. Action->Visible = Defined;
  1654. if (Defined)
  1655. {
  1656. UnicodeString TitleCommand = Command.Command;
  1657. int MaxTitleCommandLen = 20;
  1658. if (TitleCommand.Length() > MaxTitleCommandLen)
  1659. {
  1660. TitleCommand = TitleCommand.SubString(1, MaxTitleCommandLen - 3) + Ellipsis;
  1661. }
  1662. Action->Caption = FMTLOAD(CUSTOM_COMMAND_LAST, (EscapeHotkey(TitleCommand)));
  1663. Action->Hint = Command.Command;
  1664. Action->Enabled = (State > 0);
  1665. }
  1666. }
  1667. //---------------------------------------------------------------------------
  1668. UnicodeString __fastcall TNonVisualDataModule::QueueItemSpeed(const UnicodeString & Text,
  1669. TTBXComboBoxItem * Item)
  1670. {
  1671. // Keep in sync with TProgressForm::ItemSpeed
  1672. unsigned long Speed = GetSpeedLimit(Text);
  1673. ScpExplorer->ExecuteQueueOperation(qoItemSpeed, reinterpret_cast<void*>(Speed));
  1674. UnicodeString Result = SetSpeedLimit(Speed);
  1675. SaveToHistory(Item->Strings, Result);
  1676. CustomWinConfiguration->History[L"SpeedLimit"] = Item->Strings;
  1677. return Result;
  1678. }
  1679. //---------------------------------------------------------------------------
  1680. void __fastcall TNonVisualDataModule::QueuePopupSpeedComboBoxItemItemClick(
  1681. TObject * Sender)
  1682. {
  1683. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  1684. QueueItemSpeedAction->Text = QueueItemSpeed(Item->Text, Item);
  1685. }
  1686. //---------------------------------------------------------------------------
  1687. void __fastcall TNonVisualDataModule::QueueSpeedComboBoxItemAcceptText(
  1688. TObject * Sender, UnicodeString & NewText, bool & /*Accept*/)
  1689. {
  1690. TTBXComboBoxItem * Item = dynamic_cast<TTBXComboBoxItem *>(Sender);
  1691. NewText = QueueItemSpeed(NewText, Item);
  1692. QueueItemSpeedAction->Text = NewText;
  1693. }
  1694. //---------------------------------------------------------------------------
  1695. void __fastcall TNonVisualDataModule::QueueSpeedComboBoxItem(TTBXComboBoxItem * Item)
  1696. {
  1697. // IDE often looses this link
  1698. Item->OnAcceptText = QueueSpeedComboBoxItemAcceptText;
  1699. Item->OnItemClick = QueuePopupSpeedComboBoxItemItemClick;
  1700. }
  1701. //---------------------------------------------------------------------------
  1702. void __fastcall TNonVisualDataModule::QueueSpeedComboBoxItemUpdate(TTBXComboBoxItem * Item)
  1703. {
  1704. CopySpeedLimits(CustomWinConfiguration->History[L"SpeedLimit"], Item->Strings);
  1705. }
  1706. //---------------------------------------------------------------------------
  1707. void __fastcall TNonVisualDataModule::SetQueueOnceEmptyAction(TAction * Action)
  1708. {
  1709. TAction * Current = CurrentQueueOnceEmptyAction();
  1710. if (Current != Action)
  1711. {
  1712. Current->Checked = false;
  1713. Action->Checked = true;
  1714. }
  1715. }
  1716. //---------------------------------------------------------------------------
  1717. void __fastcall TNonVisualDataModule::CycleQueueOnceEmptyAction()
  1718. {
  1719. TAction * Current = CurrentQueueOnceEmptyAction();
  1720. Current->Checked = false;
  1721. if (Current == QueueIdleOnceEmptyAction)
  1722. {
  1723. QueueDisconnectOnceEmptyAction2->Checked = true;
  1724. }
  1725. else if (Current == QueueDisconnectOnceEmptyAction2)
  1726. {
  1727. QueueSuspendOnceEmptyAction2->Checked = true;
  1728. }
  1729. else if (Current == QueueSuspendOnceEmptyAction2)
  1730. {
  1731. QueueShutDownOnceEmptyAction2->Checked = true;
  1732. }
  1733. else if (Current == QueueShutDownOnceEmptyAction2)
  1734. {
  1735. QueueIdleOnceEmptyAction->Checked = true;
  1736. }
  1737. else
  1738. {
  1739. DebugFail();
  1740. }
  1741. }
  1742. //---------------------------------------------------------------------------
  1743. TAction * __fastcall TNonVisualDataModule::CurrentQueueOnceEmptyAction()
  1744. {
  1745. TAction * Result;
  1746. if (QueueIdleOnceEmptyAction->Checked)
  1747. {
  1748. Result = QueueIdleOnceEmptyAction;
  1749. }
  1750. else if (QueueDisconnectOnceEmptyAction2->Checked)
  1751. {
  1752. Result = QueueDisconnectOnceEmptyAction2;
  1753. }
  1754. else if (QueueSuspendOnceEmptyAction2->Checked)
  1755. {
  1756. Result = QueueSuspendOnceEmptyAction2;
  1757. }
  1758. else if (QueueShutDownOnceEmptyAction2->Checked)
  1759. {
  1760. Result = QueueShutDownOnceEmptyAction2;
  1761. }
  1762. else
  1763. {
  1764. DebugFail();
  1765. }
  1766. return Result;
  1767. }
  1768. //---------------------------------------------------------------------------
  1769. TOnceDoneOperation __fastcall TNonVisualDataModule::CurrentQueueOnceEmptyOperation()
  1770. {
  1771. TOnceDoneOperation Result;
  1772. TBasicAction * Current = CurrentQueueOnceEmptyAction();
  1773. if (Current == QueueIdleOnceEmptyAction)
  1774. {
  1775. Result = odoIdle;
  1776. }
  1777. else if (Current == QueueDisconnectOnceEmptyAction2)
  1778. {
  1779. Result = odoDisconnect;
  1780. }
  1781. else if (Current == QueueSuspendOnceEmptyAction2)
  1782. {
  1783. Result = odoSuspend;
  1784. }
  1785. else if (Current == QueueShutDownOnceEmptyAction2)
  1786. {
  1787. Result = odoShutDown;
  1788. }
  1789. else
  1790. {
  1791. DebugFail();
  1792. }
  1793. return Result;
  1794. }
  1795. //---------------------------------------------------------------------------
  1796. void __fastcall TNonVisualDataModule::ResetQueueOnceEmptyOperation()
  1797. {
  1798. SetQueueOnceEmptyAction(QueueIdleOnceEmptyAction);
  1799. }
  1800. //---------------------------------------------------------------------------
  1801. void __fastcall TNonVisualDataModule::StartBusy()
  1802. {
  1803. FBusy++;
  1804. }
  1805. //---------------------------------------------------------------------------
  1806. void __fastcall TNonVisualDataModule::EndBusy()
  1807. {
  1808. FBusy--;
  1809. }
  1810. //---------------------------------------------------------------------------
  1811. bool __fastcall TNonVisualDataModule::GetBusy()
  1812. {
  1813. return
  1814. (FBusy > 0) ||
  1815. ((ScpExplorer != NULL) && ScpExplorer->IsBusy());
  1816. }
  1817. //---------------------------------------------------------------------------
  1818. void __fastcall TNonVisualDataModule::FocusedEditMenuItemPopup(TTBCustomItem * Sender,
  1819. bool /*FromLink*/)
  1820. {
  1821. CreateEditorListMenu(Sender, true);
  1822. }
  1823. //---------------------------------------------------------------------------
  1824. void __fastcall TNonVisualDataModule::EditMenuItemPopup(TTBCustomItem * Sender,
  1825. bool /*FromLink*/)
  1826. {
  1827. CreateEditorListMenu(Sender, false);
  1828. }
  1829. //---------------------------------------------------------------------------
  1830. void __fastcall TNonVisualDataModule::QueuePopupSpeedComboBoxItemAdjustImageIndex(
  1831. TTBXComboBoxItem * Sender, const UnicodeString /*AText*/, int /*AIndex*/, int & ImageIndex)
  1832. {
  1833. // Use fixed image (do not change image by item index)
  1834. ImageIndex = Sender->ImageIndex;
  1835. }
  1836. //---------------------------------------------------------------------------
  1837. void __fastcall TNonVisualDataModule::ToolbarButtonItemClick(TObject * Sender)
  1838. {
  1839. TTBCustomItem * Item = DebugNotNull(dynamic_cast<TTBCustomItem *>(Sender));
  1840. TTBCustomItem * ButtonItem = reinterpret_cast<TTBCustomItem *>(Item->Tag);
  1841. ButtonItem->Visible = !ButtonItem->Visible;
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. bool __fastcall TNonVisualDataModule::IsCustomizableToolbarItem(TTBCustomItem * Item)
  1845. {
  1846. return
  1847. ((dynamic_cast<TTBXItem *>(Item) != NULL) ||
  1848. (dynamic_cast<TTBXSubmenuItem *>(Item) != NULL)) &&
  1849. (Item->Action != CustomCommandsLastAction) &&
  1850. DebugAlwaysTrue(Item->Action != CustomCommandsLastFocusedAction);
  1851. }
  1852. //---------------------------------------------------------------------------
  1853. bool __fastcall TNonVisualDataModule::IsToolbarCustomizable()
  1854. {
  1855. bool Result = false;
  1856. if (FCustomizedToolbar != NULL)
  1857. {
  1858. for (int Index = 0; Index < FCustomizedToolbar->Items->Count; Index++)
  1859. {
  1860. if (IsCustomizableToolbarItem(FCustomizedToolbar->Items->Items[Index]))
  1861. {
  1862. Result = true;
  1863. break;
  1864. }
  1865. }
  1866. }
  1867. return Result;
  1868. }
  1869. //---------------------------------------------------------------------------
  1870. void __fastcall TNonVisualDataModule::CreateToolbarButtonsList()
  1871. {
  1872. if (FCustomizedToolbar != NULL)
  1873. {
  1874. TTBCustomItem * CustomizeItem = DebugNotNull(dynamic_cast<TTBCustomItem *>(CustomizeToolbarAction->ActionComponent));
  1875. CustomizeItem->Clear();
  1876. for (int Index = 0; Index < FCustomizedToolbar->Items->Count; Index++)
  1877. {
  1878. TTBCustomItem * ButtonItem = FCustomizedToolbar->Items->Items[Index];
  1879. TTBCustomItem * Item = NULL;
  1880. if (dynamic_cast<TTBSeparatorItem *>(ButtonItem) != NULL)
  1881. {
  1882. Item = new TTBSeparatorItem(CustomizeItem);
  1883. }
  1884. else if (IsCustomizableToolbarItem(ButtonItem))
  1885. {
  1886. Item = new TTBXItem(CustomizeItem);
  1887. Item->Caption = StripEllipsis(ButtonItem->Caption);
  1888. Item->ImageIndex = ButtonItem->ImageIndex;
  1889. Item->Tag = reinterpret_cast<int>(ButtonItem);
  1890. Item->OnClick = ToolbarButtonItemClick;
  1891. Item->Checked = ButtonItem->Visible;
  1892. }
  1893. if (Item != NULL)
  1894. {
  1895. CustomizeItem->Insert(CustomizeItem->Count, Item);
  1896. }
  1897. }
  1898. }
  1899. }
  1900. //---------------------------------------------------------------------------
  1901. void __fastcall TNonVisualDataModule::ControlContextPopup(TObject * Sender, const TPoint & MousePos)
  1902. {
  1903. TTBDock * Dock = dynamic_cast<TTBDock *>(Sender);
  1904. if (Dock != NULL)
  1905. {
  1906. // While we can identify toolbar for which context menu is popping up in OnExecute,
  1907. // we cannot in OnUpdate, so we have to remember it here.
  1908. FCustomizedToolbar = dynamic_cast<TTBCustomToolbar *>(Dock->ControlAtPos(MousePos, true, true, false));
  1909. }
  1910. else
  1911. {
  1912. FCustomizedToolbar = NULL;
  1913. }
  1914. }