NonVisual.cpp 84 KB

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