NonVisual.cpp 84 KB

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