NonVisual.cpp 87 KB

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