NonVisual.cpp 84 KB

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