NonVisual.cpp 87 KB

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