NonVisual.cpp 88 KB

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