NonVisual.cpp 87 KB

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