NonVisual.cpp 79 KB

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