NonVisual.cpp 87 KB

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