1
0

NonVisual.cpp 80 KB

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