NonVisual.cpp 84 KB

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