NonVisual.cpp 88 KB

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