NonVisual.cpp 81 KB

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