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