NonVisual.cpp 84 KB

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