NonVisual.cpp 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227
  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 <Log.h>
  11. #include <Interface.h>
  12. #include "WinConfiguration.h"
  13. #include "TerminalManager.h"
  14. #include "TBX.hpp"
  15. #include "VCLCommon.h"
  16. //---------------------------------------------------------------------------
  17. #pragma package(smart_init)
  18. #pragma link "TB2Item"
  19. #pragma link "TBX"
  20. #pragma resource "*.dfm"
  21. TNonVisualDataModule *NonVisualDataModule;
  22. //---------------------------------------------------------------------------
  23. #define SCPCOMMANDER ((TScpCommanderForm *)ScpExplorer)
  24. #define UPDEX(HandleAction, Condition, OtherEnabled, OtherDisabled) if (Action == HandleAction) { \
  25. ((TCustomAction *)Action)->Enabled = (Condition); \
  26. if (((TCustomAction *)Action)->Enabled) { OtherEnabled; } else { OtherDisabled; }; \
  27. Handled = true; } else
  28. #define UPD(HandleAction, Condition) if (Action == HandleAction) { \
  29. ((TCustomAction *)Action)->Enabled = (Condition); Handled = true; } else
  30. #define UPDFUNC(HandleAction, Function) if (Action == HandleAction) { Function; Handled = true; } else
  31. #define EXE(HandleAction, Command) if (Action == HandleAction) { \
  32. Command; Handled = true; } else
  33. #define UPDACT(HandleAction, Command) \
  34. EXE(HandleAction, ((TCustomAction *)Action)->Enabled = true; Command)
  35. #define UPDCOMP(COMP) if (Action == COMP ## Action) { COMP ## Action->Enabled = true; \
  36. COMP ## Action->Checked = ScpExplorer->ComponentVisible[fc ## COMP]; Handled = true; } else
  37. #define EXECOMP(COMP) EXE(COMP ## Action, \
  38. ScpExplorer->ComponentVisible[fc ## COMP] = !ScpExplorer->ComponentVisible[fc ## COMP] )
  39. #define COLPROPS(SIDE) \
  40. ((TCustomDirViewColProperties*)ScpExplorer->DirView(os ## SIDE)->ColProperties)
  41. #define UPDSORT(SIDE, PREFIX, COL) if (Action == SIDE ## SortBy ## COL ## Action) { \
  42. SIDE ## SortBy ## COL ## Action->Enabled = true; Handled = true; \
  43. SIDE ## SortBy ## COL ## Action->Checked = (COLPROPS(SIDE)->SortColumn == PREFIX ## COL); } else
  44. #define EXESORT(SIDE, PREFIX, COL) EXE(SIDE ## SortBy ## COL ## Action, \
  45. if (COLPROPS(SIDE)->SortColumn == PREFIX ## COL) \
  46. COLPROPS(SIDE)->SortAscending = !COLPROPS(SIDE)->SortAscending; \
  47. else COLPROPS(SIDE)->SortColumn = PREFIX ## COL )
  48. #define UPDSORTA(SIDE) if (Action == SIDE ## SortAscendingAction) { \
  49. SIDE ## SortAscendingAction->Enabled = true; Handled = true; \
  50. SIDE ## SortAscendingAction->Checked = COLPROPS(SIDE)->SortAscending; } else
  51. #define EXESORTA(SIDE) EXE(SIDE ## SortAscendingAction, \
  52. COLPROPS(SIDE)->SortAscending = !COLPROPS(SIDE)->SortAscending; )
  53. #define UPDSORTC(LPREFIX, LCOL, RPREFIX, RCOL) if (Action == CurrentSortBy ## RCOL ## Action) { \
  54. CurrentSortBy ## RCOL ## Action->Enabled = ScpExplorer->AllowedAction((TAction *)Action, aaShortCut); \
  55. if (CurrentSortBy ## RCOL ## Action->Enabled) { \
  56. if (ScpExplorer->DirView(osCurrent) == ScpExplorer->DirView(osRemote)) \
  57. CurrentSortBy ## RCOL ## Action->Checked = (COLPROPS(Current)->SortColumn == RPREFIX ## RCOL); \
  58. else CurrentSortBy ## RCOL ## Action->Checked = (COLPROPS(Current)->SortColumn == LPREFIX ## LCOL); \
  59. } else CurrentSortBy ## RCOL ## Action->Checked = false; Handled = true; } else
  60. #define EXESORTC(COL, LCOL, RCOL) \
  61. EXE(CurrentSortBy ## COL ## Action, \
  62. Integer NewSortCol = \
  63. ((ScpExplorer->DirView(osCurrent) == ScpExplorer->DirView(osRemote)) ? RCOL : LCOL); \
  64. if (COLPROPS(Current)->SortColumn == NewSortCol) \
  65. COLPROPS(Current)->SortAscending = !COLPROPS(Current)->SortAscending; \
  66. else COLPROPS(Current)->SortColumn = NewSortCol \
  67. )
  68. #define UPDSHCOL(SIDE, PREFIX, COL) \
  69. EXE(ShowHide ## SIDE ## COL ## ColumnAction, \
  70. ShowHide ## SIDE ## COL ## ColumnAction->Checked = COLPROPS(SIDE)->Visible[PREFIX ## COL])
  71. #define EXESHCOL(SIDE, PREFIX, COL) \
  72. EXE(ShowHide ## SIDE ## COL ## ColumnAction, \
  73. COLPROPS(SIDE)->Visible[PREFIX ## COL] = !COLPROPS(SIDE)->Visible[PREFIX ## COL])
  74. //---------------------------------------------------------------------------
  75. __fastcall TNonVisualDataModule::TNonVisualDataModule(TComponent* Owner)
  76. : TDataModule(Owner)
  77. {
  78. InitSystemSettings(this);
  79. FListColumn = NULL;
  80. FSessionIdleTimerExecuting = false;
  81. FIdle = 0;
  82. }
  83. //---------------------------------------------------------------------------
  84. __fastcall TNonVisualDataModule::~TNonVisualDataModule()
  85. {
  86. }
  87. //---------------------------------------------------------------------------
  88. void __fastcall TNonVisualDataModule::LogActionsUpdate(
  89. TBasicAction *Action, bool &Handled)
  90. {
  91. TLogMemo * LogMemo = TTerminalManager::Instance()->LogMemo;
  92. bool ValidLogMemo = LogMemo && LogMemo->Parent;
  93. UPD(LogClearAction, ValidLogMemo && LogMemo->Lines->Count)
  94. // removed potentially CPU intensive check for "all selected already"
  95. UPD(LogSelectAllAction, ValidLogMemo && LogMemo->Lines->Count)
  96. UPD(LogCopyAction, ValidLogMemo && LogMemo->SelLength)
  97. UPD(LogCloseAction, Configuration->Logging && (WinConfiguration->LogView == lvWindow))
  98. UPD(LogPreferencesAction, true)
  99. ;
  100. }
  101. //---------------------------------------------------------------------------
  102. void __fastcall TNonVisualDataModule::LogActionsExecute(
  103. TBasicAction *Action, bool &Handled)
  104. {
  105. FIdle--;
  106. try
  107. {
  108. TLogMemo * LogMemo = TTerminalManager::Instance()->LogMemo;
  109. assert(LogMemo && LogMemo->Parent);
  110. EXE(LogClearAction, LogMemo->SessionLog->Clear())
  111. EXE(LogSelectAllAction, LogMemo->SelectAll())
  112. EXE(LogCopyAction, LogMemo->CopyToClipboard())
  113. EXE(LogCloseAction, WinConfiguration->LogView = lvNone)
  114. EXE(LogPreferencesAction, PreferencesDialog(pmLogging));
  115. ;
  116. }
  117. __finally
  118. {
  119. assert(FIdle < 0);
  120. FIdle++;
  121. }
  122. DoIdle();
  123. }
  124. //---------------------------------------------------------------------------
  125. void __fastcall TNonVisualDataModule::ExplorerActionsUpdate(
  126. TBasicAction *Action, bool &Handled)
  127. {
  128. if (!ScpExplorer || !ScpExplorer->AllowedAction((TAction *)Action, aaUpdate))
  129. {
  130. ((TAction *)Action)->Enabled = false;
  131. Handled = true;
  132. return;
  133. }
  134. // CURRENT DIRVIEW
  135. bool EnableSelectedOperation = ScpExplorer->EnableSelectedOperation[osCurrent];
  136. bool EnableFocusedOperation = ScpExplorer->EnableFocusedOperation[osCurrent];
  137. bool EnableSelectedFileOperation = ScpExplorer->EnableSelectedFileOperation[osCurrent];
  138. bool EnableFocusedFileOperation = ScpExplorer->EnableFocusedFileOperation[osCurrent];
  139. // focused operation
  140. UPD(CurrentCopyFocusedAction, EnableFocusedOperation)
  141. UPD(CurrentMoveFocusedAction, EnableFocusedOperation)
  142. UPD(CurrentDeleteFocusedAction, EnableFocusedOperation)
  143. UPD(CurrentPropertiesFocusedAction, EnableFocusedOperation)
  144. UPD(RemoteMoveToFocusedAction, EnableFocusedOperation &&
  145. (DirView(osRemote) == DirView(osCurrent)) &&
  146. ScpExplorer->Terminal->IsCapable[fcRemoteMove])
  147. UPD(RemoteCopyToFocusedAction, EnableFocusedOperation &&
  148. (DirView(osRemote) == DirView(osCurrent) &&
  149. (ScpExplorer->Terminal->IsCapable[fcRemoteCopy] ||
  150. ScpExplorer->Terminal->IsCapable[fcSecondaryShell])))
  151. UPD(CurrentEditFocusedAction, EnableFocusedFileOperation &&
  152. !WinConfiguration->DisableOpenEdit)
  153. // file operation
  154. UPD(CurrentRenameAction, EnableFocusedOperation &&
  155. ((ScpExplorer->HasDirView[osLocal] && DirView(osLocal) == DirView(osCurrent)) ||
  156. ScpExplorer->Terminal->IsCapable[fcRename]))
  157. UPD(CurrentEditAction, EnableSelectedFileOperation &&
  158. !WinConfiguration->DisableOpenEdit)
  159. UPD(CurrentEditAlternativeAction, EnableSelectedFileOperation &&
  160. !WinConfiguration->DisableOpenEdit)
  161. UPD(CurrentOpenAction, EnableFocusedOperation &&
  162. !WinConfiguration->DisableOpenEdit &&
  163. !DirView(osCurrent)->ItemIsDirectory(DirView(osCurrent)->ItemFocused))
  164. UPD(AddEditLinkAction, ScpExplorer->Terminal &&
  165. (DirView(osCurrent) != DirView(osRemote) ||
  166. (ScpExplorer->Terminal->ResolvingSymlinks &&
  167. ScpExplorer->Terminal->IsCapable[fcSymbolicLink])))
  168. UPD(NewLinkAction, ScpExplorer->Terminal &&
  169. (DirView(osCurrent) != DirView(osRemote) ||
  170. (ScpExplorer->Terminal->ResolvingSymlinks &&
  171. ScpExplorer->Terminal->IsCapable[fcSymbolicLink])))
  172. // selected operaton
  173. UPD(CurrentCopyAction, EnableSelectedOperation)
  174. UPD(RemoteCopyAction, ScpExplorer->EnableSelectedOperation[osRemote])
  175. UPD(LocalCopyAction, ScpExplorer->HasDirView[osLocal] && ScpExplorer->EnableSelectedOperation[osLocal])
  176. UPD(CurrentMoveAction, EnableSelectedOperation)
  177. UPD(CurrentDeleteAction, EnableSelectedOperation)
  178. UPD(CurrentPropertiesAction, EnableSelectedOperation)
  179. UPD(RemoteMoveToAction, EnableSelectedOperation &&
  180. (DirView(osRemote) == DirView(osCurrent)) &&
  181. ScpExplorer->Terminal->IsCapable[fcRemoteMove])
  182. UPD(RemoteCopyToAction, EnableSelectedOperation &&
  183. (DirView(osRemote) == DirView(osCurrent) &&
  184. (ScpExplorer->Terminal->IsCapable[fcRemoteCopy] ||
  185. ScpExplorer->Terminal->IsCapable[fcSecondaryShell])))
  186. UPD(FileListToCommandLineAction, EnableSelectedOperation)
  187. UPD(FileListToClipboardAction, EnableSelectedOperation)
  188. UPD(FullFileListToClipboardAction, EnableSelectedOperation)
  189. UPD(UrlToClipboardAction, EnableSelectedOperation && (DirView(osRemote) == DirView(osCurrent)))
  190. UPD(FileListFromClipboardAction, IsFormatInClipboard(CF_TEXT));
  191. // directory
  192. UPD(CurrentCreateDirAction, true)
  193. UPD(NewDirAction, true)
  194. // selection
  195. UPD(SelectOneAction, DirView(osCurrent)->FilesCount)
  196. UPD(SelectAction, DirView(osCurrent)->FilesCount)
  197. UPD(UnselectAction, DirView(osCurrent)->SelCount)
  198. UPD(SelectAllAction, DirView(osCurrent)->FilesCount)
  199. UPD(InvertSelectionAction, DirView(osCurrent)->FilesCount)
  200. UPD(ClearSelectionAction, DirView(osCurrent)->SelCount)
  201. UPD(RestoreSelectionAction, DirView(osCurrent)->SelectedNamesSaved)
  202. UPD(PasteAction, ScpExplorer->CanPasteFromClipBoard())
  203. //style
  204. UPDACT(CurrentCycleStyleAction,
  205. CurrentCycleStyleAction->ImageIndex = 8 + (DirView(osCurrent)->ViewStyle + 1) % 4)
  206. #define STYLEACTION(Style) UPDACT(Current ## Style ## Action, \
  207. Current ## Style ## Action->Checked = (DirView(osCurrent)->ViewStyle == vs ## Style))
  208. STYLEACTION(Icon)
  209. STYLEACTION(SmallIcon)
  210. STYLEACTION(List)
  211. STYLEACTION(Report)
  212. #undef STYLEACTION
  213. // REMOTE+LOCAL
  214. // back/forward
  215. #define HISTORYACTION(SIDE, DIRECTION, HINTFMT, DELTA) \
  216. UPDEX(SIDE ## DIRECTION ## Action, (DirView(os ## SIDE)->DIRECTION ## Count > 0), \
  217. SIDE ## DIRECTION ## Action->Hint = FMTLOAD(HINTFMT, (DirView(os ## SIDE)->HistoryPath[DELTA])), \
  218. SIDE ## DIRECTION ## Action->Hint = "")
  219. HISTORYACTION(Local, Back, EXPLORER_BACK_HINT, -1)
  220. HISTORYACTION(Local, Forward, EXPLORER_FORWARD_HINT, 1)
  221. HISTORYACTION(Remote, Back, EXPLORER_BACK_HINT, -1)
  222. HISTORYACTION(Remote, Forward, EXPLORER_FORWARD_HINT, 1)
  223. #undef HISTORYACTION
  224. #define PANEL_ACTIONS(SIDE) \
  225. UPD(SIDE ## ParentDirAction, !DirView(os ## SIDE)->IsRoot) \
  226. UPD(SIDE ## RootDirAction, !DirView(os ## SIDE)->IsRoot) \
  227. UPD(SIDE ## HomeDirAction, true) \
  228. UPD(SIDE ## RefreshAction, DirView(os ## SIDE)->DirOK) \
  229. UPD(SIDE ## OpenDirAction, true) \
  230. UPD(SIDE ## ChangePathAction, true) \
  231. UPD(SIDE ## AddBookmarkAction, true) \
  232. UPD(SIDE ## PathToClipboardAction, true)
  233. PANEL_ACTIONS(Local)
  234. PANEL_ACTIONS(Remote)
  235. #undef PANEL_ACTIONS
  236. UPD(LocalExploreDirectoryAction, true)
  237. // HELP
  238. UPD(AboutAction, true)
  239. UPD(HomepageAction, true)
  240. UPD(HistoryPageAction, true)
  241. UPD(TableOfContentsAction, true)
  242. UPD(ForumPageAction, true)
  243. UPD(CheckForUpdatesAction, true)
  244. UPDACT(ShowUpdatesAction, ShowUpdatesUpdate())
  245. UPD(UpdatesPreferencesAction, true)
  246. UPD(DonatePageAction, true)
  247. UPD(DownloadPageAction, true)
  248. // VIEW
  249. UPDCOMP(StatusBar)
  250. UPDCOMP(ToolBar)
  251. UPDCOMP(LocalStatusBar)
  252. UPDCOMP(RemoteStatusBar)
  253. UPDCOMP(CommandLinePanel)
  254. UPDCOMP(RemoteTree)
  255. UPDCOMP(LocalTree)
  256. UPDCOMP(ExplorerMenuBand)
  257. UPDCOMP(ExplorerAddressBand)
  258. UPDCOMP(ExplorerToolbarBand)
  259. UPDCOMP(ExplorerSelectionBand)
  260. UPDCOMP(ExplorerSessionBand)
  261. UPDCOMP(ExplorerPreferencesBand)
  262. UPDCOMP(ExplorerSortBand)
  263. UPDCOMP(ExplorerUpdatesBand)
  264. UPDCOMP(ExplorerTransferBand)
  265. UPDCOMP(ExplorerCustomCommandsBand)
  266. UPDCOMP(CommanderMenuBand)
  267. UPDCOMP(CommanderSessionBand)
  268. UPDCOMP(CommanderPreferencesBand)
  269. UPDCOMP(CommanderSelectionBand)
  270. UPDCOMP(CommanderToolbarBand)
  271. UPDCOMP(CommanderSortBand)
  272. UPDCOMP(CommanderCommandsBand)
  273. UPDCOMP(CommanderUpdatesBand)
  274. UPDCOMP(CommanderTransferBand)
  275. UPDCOMP(CommanderUploadDownloadBand)
  276. UPDCOMP(CommanderCustomCommandsBand)
  277. UPDCOMP(CommanderLocalHistoryBand)
  278. UPDCOMP(CommanderLocalNavigationBand)
  279. UPDCOMP(CommanderRemoteHistoryBand)
  280. UPDCOMP(CommanderRemoteNavigationBand)
  281. UPD(GoToCommandLineAction, true)
  282. UPD(GoToTreeAction, true)
  283. UPDEX(ViewLogAction, Configuration->Logging,
  284. ViewLogAction->Checked = (WinConfiguration->LogView == lvWindow),
  285. ViewLogAction->Checked = false )
  286. UPDEX(ShowHiddenFilesAction, true,
  287. ShowHiddenFilesAction->Checked = WinConfiguration->ShowHiddenFiles, )
  288. UPDEX(AutoReadDirectoryAfterOpAction, true,
  289. AutoReadDirectoryAfterOpAction->Checked = Configuration->AutoReadDirectoryAfterOp, )
  290. UPD(PreferencesAction, true)
  291. UPD(PresetsPreferencesAction, true)
  292. UPDEX(LockToolbarsAction, true,
  293. LockToolbarsAction->Checked = WinConfiguration->LockToolbars, )
  294. UPDCOMP(CustomCommandsBand)
  295. UPD(ColorMenuAction, true)
  296. UPDACT(ColorDefaultAction,
  297. ColorDefaultAction->Checked = (ScpExplorer->SessionColor == 0));
  298. UPD(ColorPickAction, true);
  299. // SORT
  300. UPDSORTA(Local)
  301. UPDSORT(Local, dv, Name)
  302. UPDSORT(Local, dv, Ext)
  303. UPDSORT(Local, dv, Size)
  304. UPDSORT(Local, dv, Type)
  305. UPDSORT(Local, dv, Changed)
  306. UPDSORT(Local, dv, Attr)
  307. UPDSORTA(Remote)
  308. UPDSORT(Remote, uv, Name)
  309. UPDSORT(Remote, uv, Ext)
  310. UPDSORT(Remote, uv, Size)
  311. UPDSORT(Remote, uv, Changed)
  312. UPDSORT(Remote, uv, Rights)
  313. UPDSORT(Remote, uv, Owner)
  314. UPDSORT(Remote, uv, Group)
  315. UPDSORT(Remote, uv, Type)
  316. UPDSORTA(Current)
  317. UPDSORTC(dv, Name, uv, Name)
  318. UPDSORTC(dv, Ext, uv, Ext)
  319. UPDSORTC(dv, Size, uv, Size)
  320. UPDSORTC(dv, Type, uv, Type)
  321. UPDSORTC(dv, Changed, uv, Changed)
  322. UPDSORTC(dv, Attr, uv, Rights)
  323. UPDSORTC(dv, Name, uv, Owner)
  324. UPDSORTC(dv, Name, uv, Group)
  325. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  326. UPDEX(SortColumnAscendingAction, (ListColumn != NULL), SortColumnAscendingAction->Checked =
  327. (COLVIEWPROPS->SortColumn == ListColumn->Index) && COLVIEWPROPS->SortAscending, /*assert(false)*/ )
  328. UPDEX(SortColumnDescendingAction, (ListColumn != NULL), SortColumnDescendingAction->Checked =
  329. (COLVIEWPROPS->SortColumn == ListColumn->Index) && !COLVIEWPROPS->SortAscending, /*assert(false)*/ )
  330. #undef COLVIEWPROPS
  331. // SHOW/HIDE COLUMN
  332. UPDSHCOL(Local, dv, Name)
  333. UPDSHCOL(Local, dv, Ext)
  334. UPDSHCOL(Local, dv, Size)
  335. UPDSHCOL(Local, dv, Type)
  336. UPDSHCOL(Local, dv, Changed)
  337. UPDSHCOL(Local, dv, Attr)
  338. UPDSHCOL(Remote, uv, Name)
  339. UPDSHCOL(Remote, uv, Ext)
  340. UPDSHCOL(Remote, uv, Size)
  341. UPDSHCOL(Remote, uv, Changed)
  342. UPDSHCOL(Remote, uv, Rights)
  343. UPDSHCOL(Remote, uv, Owner)
  344. UPDSHCOL(Remote, uv, Group)
  345. UPDSHCOL(Remote, uv, LinkTarget)
  346. UPDSHCOL(Remote, uv, Type)
  347. UPD(HideColumnAction, (ListColumn != NULL))
  348. UPD(BestFitColumnAction, (ListColumn != NULL))
  349. // SESSION
  350. UPD(NewSessionAction, true)
  351. UPD(DuplicateSessionAction, true)
  352. UPD(CloseSessionAction, true)
  353. UPD(SavedSessionsAction, (StoredSessions->Count > 0))
  354. UPD(OpenedSessionsAction, true)
  355. UPD(SaveCurrentSessionAction, true)
  356. // COMMAND
  357. UPD(CompareDirectoriesAction, true)
  358. UPD(SynchronizeAction, true)
  359. UPD(FullSynchronizeAction, true)
  360. UPD(ConsoleAction, true)
  361. UPD(PuttyAction, TTerminalManager::Instance()->CanOpenInPutty())
  362. UPD(SynchronizeBrowsingAction, true)
  363. UPD(CloseApplicationAction, true)
  364. UPD(FileSystemInfoAction, true)
  365. UPD(ClearCachesAction, (ScpExplorer->Terminal != NULL) && !ScpExplorer->Terminal->AreCachesEmpty)
  366. UPD(NewFileAction, !WinConfiguration->DisableOpenEdit)
  367. UPD(EditorListCustomizeAction, true)
  368. // CUSTOM COMMANDS
  369. UPD(CustomCommandsAction, true)
  370. UPD(CustomCommandsEnterAction, true)
  371. UPD(CustomCommandsEnterFocusedAction, true)
  372. UPDFUNC(CustomCommandsLastAction, CustomCommandsLastUpdate(CustomCommandsLastAction))
  373. UPDFUNC(CustomCommandsLastFocusedAction, CustomCommandsLastUpdate(CustomCommandsLastFocusedAction))
  374. UPD(CustomCommandsCustomizeAction, true)
  375. // QUEUE
  376. #define UPDQUEUE(OPERATION) UPD(Queue ## OPERATION ## Action, \
  377. ScpExplorer->AllowQueueOperation(qo ## OPERATION))
  378. UPDQUEUE(GoTo)
  379. UPDQUEUE(Preferences)
  380. UPDEX(QueueItemQueryAction, ScpExplorer->AllowQueueOperation(qoItemQuery),
  381. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible = false)
  382. UPDEX(QueueItemErrorAction, ScpExplorer->AllowQueueOperation(qoItemError),
  383. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible = false)
  384. UPDEX(QueueItemPromptAction, ScpExplorer->AllowQueueOperation(qoItemPrompt),
  385. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible = false)
  386. UPDQUEUE(ItemDelete)
  387. UPDEX(QueueItemExecuteAction, ScpExplorer->AllowQueueOperation(qoItemExecute),
  388. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible =
  389. !ScpExplorer->AllowQueueOperation(qoItemPause) &&
  390. !ScpExplorer->AllowQueueOperation(qoItemResume))
  391. UPDEX(QueueItemPauseAction, ScpExplorer->AllowQueueOperation(qoItemPause),
  392. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible = false)
  393. UPDEX(QueueItemResumeAction, ScpExplorer->AllowQueueOperation(qoItemResume),
  394. ((TAction *)Action)->Visible = true, ((TAction *)Action)->Visible = false)
  395. UPDQUEUE(ItemUp)
  396. UPDQUEUE(ItemDown)
  397. UPDQUEUE(PauseAll)
  398. UPDQUEUE(ResumeAll)
  399. #undef UPDQUEUE
  400. UPDACT(QueueToggleShowAction,
  401. ((TAction *)Action)->Checked = ScpExplorer->ComponentVisible[fcQueueView])
  402. #define QUEUEACTION(SHOW) UPDACT(Queue ## SHOW ## Action, \
  403. ((TAction *)Action)->Checked = WinConfiguration->QueueView.Show == qv ## SHOW)
  404. QUEUEACTION(Show)
  405. QUEUEACTION(HideWhenEmpty)
  406. QUEUEACTION(Hide)
  407. #undef QUEUEACTION
  408. UPD(QueueDisconnectOnceEmptyAction, ScpExplorer->AllowQueueOperation(qoDisconnectOnceEmpty))
  409. UPDCOMP(CommanderPreferencesBand)
  410. UPDACT(QueueToolbarAction,
  411. ((TAction *)Action)->Enabled = ScpExplorer->ComponentVisible[fcQueueView];
  412. ((TAction *)Action)->Checked = ScpExplorer->ComponentVisible[fcQueueToolbar]);
  413. ;
  414. }
  415. //---------------------------------------------------------------------------
  416. void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
  417. TBasicAction *Action, bool &Handled)
  418. {
  419. assert(ScpExplorer);
  420. if (!ScpExplorer->AllowedAction((TAction *)Action, aaExecute))
  421. {
  422. Handled = true;
  423. return;
  424. }
  425. ScpExplorer->BeforeAction();
  426. FIdle--;
  427. try
  428. {
  429. // focused operation
  430. EXE(CurrentCopyFocusedAction, ScpExplorer->ExecuteFileOperation(foCopy, osCurrent, true))
  431. EXE(CurrentMoveFocusedAction, ScpExplorer->ExecuteFileOperation(foMove, osCurrent, true))
  432. EXE(CurrentDeleteFocusedAction, ScpExplorer->ExecuteFileOperation(foDelete, osCurrent, true))
  433. EXE(CurrentPropertiesFocusedAction, ScpExplorer->ExecuteFileOperation(foSetProperties, osCurrent, true))
  434. EXE(RemoteMoveToFocusedAction, ScpExplorer->ExecuteFileOperation(foRemoteMove, osCurrent, true))
  435. EXE(RemoteCopyToFocusedAction, ScpExplorer->ExecuteFileOperation(foRemoteCopy, osCurrent, true))
  436. EXE(CurrentEditFocusedAction, ScpExplorer->ExecuteFile(osCurrent, efDefaultEditor, NULL, true, true))
  437. // operation
  438. EXE(CurrentCopyAction, ScpExplorer->ExecuteFileOperation(foCopy, osCurrent, false))
  439. EXE(RemoteCopyAction, ScpExplorer->ExecuteFileOperation(foCopy, osRemote, false))
  440. EXE(LocalCopyAction, ScpExplorer->ExecuteFileOperation(foCopy, osLocal, false))
  441. EXE(CurrentMoveAction, ScpExplorer->ExecuteFileOperation(foMove, osCurrent, false))
  442. EXE(CurrentEditAction, ScpExplorer->ExecuteFile(osCurrent, efDefaultEditor, NULL, true, false))
  443. EXE(CurrentEditAlternativeAction, CreateEditorListMenu(CurrentEditAlternativeAction))
  444. EXE(CurrentOpenAction, ScpExplorer->ExecuteCurrentFile())
  445. EXE(AddEditLinkAction, ScpExplorer->AddEditLink(false))
  446. EXE(NewLinkAction, ScpExplorer->AddEditLink(true))
  447. EXE(CurrentRenameAction, ScpExplorer->ExecuteFileOperation(foRename, osCurrent, false))
  448. EXE(CurrentDeleteAction, ScpExplorer->ExecuteFileOperation(foDelete, osCurrent, false))
  449. EXE(CurrentPropertiesAction, ScpExplorer->ExecuteFileOperation(foSetProperties, osCurrent, false))
  450. EXE(RemoteMoveToAction, ScpExplorer->ExecuteFileOperation(foRemoteMove, osCurrent, false))
  451. EXE(RemoteCopyToAction, ScpExplorer->ExecuteFileOperation(foRemoteCopy, osCurrent, false))
  452. EXE(FileListToCommandLineAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedCommandLine))
  453. EXE(FileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFileList, pedClipboard))
  454. EXE(FullFileListToClipboardAction, ScpExplorer->PanelExport(osCurrent, peFullFileList, pedClipboard))
  455. EXE(UrlToClipboardAction, ScpExplorer->PanelExport(osCurrent, peUrl, pedClipboard))
  456. EXE(FileListFromClipboardAction, ScpExplorer->FileListFromClipboard())
  457. // directory
  458. EXE(CurrentCreateDirAction, ScpExplorer->CreateDirectory(osCurrent))
  459. EXE(NewDirAction, ScpExplorer->CreateDirectory(osCurrent))
  460. //selection
  461. EXE(SelectOneAction, DirView(osCurrent)->SelectCurrentItem(DirView(osCurrent)->NortonLike))
  462. EXE(SelectAction, DirView(osCurrent)->DoSelectByMask(true))
  463. EXE(UnselectAction, DirView(osCurrent)->DoSelectByMask(false))
  464. EXE(SelectAllAction, DirView(osCurrent)->SelectAll(smAll))
  465. EXE(InvertSelectionAction, DirView(osCurrent)->SelectAll(smInvert))
  466. EXE(ClearSelectionAction, DirView(osCurrent)->SelectAll(smNone))
  467. EXE(RestoreSelectionAction, DirView(osCurrent)->RestoreSelectedNames())
  468. EXE(PasteAction, ScpExplorer->PasteFromClipBoard())
  469. // style
  470. EXE(CurrentCycleStyleAction,
  471. if (DirView(osCurrent)->ViewStyle == vsReport) DirView(osCurrent)->ViewStyle = vsIcon;
  472. else DirView(osCurrent)->ViewStyle = (TViewStyle)(DirView(osCurrent)->ViewStyle + 1);
  473. )
  474. #define STYLEACTION(Style) EXE(Current ## Style ## Action, \
  475. DirView(osCurrent)->ViewStyle = vs ## Style)
  476. STYLEACTION(Icon)
  477. STYLEACTION(SmallIcon)
  478. STYLEACTION(List)
  479. STYLEACTION(Report)
  480. #undef STYLEACTION
  481. #define PANEL_ACTIONS(SIDE) \
  482. EXE(SIDE ## BackAction, DirView(os ## SIDE)->HistoryGo(-1)) \
  483. EXE(SIDE ## ForwardAction, DirView(os ## SIDE)->HistoryGo(1)) \
  484. EXE(SIDE ## ParentDirAction, DirView(os ## SIDE)->ExecuteParentDirectory()) \
  485. EXE(SIDE ## RootDirAction, DirView(os ## SIDE)->ExecuteRootDirectory()) \
  486. EXE(SIDE ## HomeDirAction, DirView(os ## SIDE)->ExecuteHomeDirectory()) \
  487. EXE(SIDE ## RefreshAction, DirView(os ## SIDE)->ReloadDirectory()) \
  488. EXE(SIDE ## OpenDirAction, ScpExplorer->OpenDirectory(os ## SIDE)) \
  489. EXE(SIDE ## ChangePathAction, ScpExplorer->ChangePath(os ## SIDE)) \
  490. EXE(SIDE ## AddBookmarkAction, ScpExplorer->AddBookmark(os ## SIDE)) \
  491. EXE(SIDE ## PathToClipboardAction, ScpExplorer->PanelExport(os ## SIDE, pePath, pedClipboard))
  492. PANEL_ACTIONS(Local)
  493. PANEL_ACTIONS(Remote)
  494. #undef PANEL_ACTIONS
  495. EXE(LocalExploreDirectoryAction, ScpExplorer->ExploreLocalDirectory())
  496. //HELP
  497. EXE(AboutAction, DoAboutDialog(Configuration))
  498. EXE(HomepageAction, OpenBrowser(LoadStr(HOMEPAGE_URL)))
  499. EXE(HistoryPageAction, OpenBrowser(LoadStr(HISTORY_URL)))
  500. EXE(TableOfContentsAction, Application->HelpSystem->ShowTableOfContents())
  501. EXE(ForumPageAction, OpenBrowser(LoadStr(FORUM_URL)))
  502. EXE(CheckForUpdatesAction, CheckForUpdates(false))
  503. EXE(ShowUpdatesAction, CheckForUpdates(true))
  504. EXE(UpdatesPreferencesAction, PreferencesDialog(pmUpdates))
  505. EXE(DonatePageAction, OpenBrowser(LoadStr(DONATE_URL)))
  506. EXE(DownloadPageAction, OpenBrowser(LoadStr(DOWNLOAD_URL)))
  507. // VIEW
  508. EXECOMP(StatusBar)
  509. EXECOMP(ToolBar)
  510. EXECOMP(LocalStatusBar)
  511. EXECOMP(RemoteStatusBar)
  512. EXECOMP(ExplorerMenuBand)
  513. EXECOMP(ExplorerAddressBand)
  514. EXECOMP(ExplorerToolbarBand)
  515. EXECOMP(ExplorerSelectionBand)
  516. EXECOMP(ExplorerSessionBand)
  517. EXECOMP(ExplorerPreferencesBand)
  518. EXECOMP(ExplorerSortBand)
  519. EXECOMP(ExplorerUpdatesBand)
  520. EXECOMP(ExplorerTransferBand)
  521. EXECOMP(ExplorerCustomCommandsBand)
  522. EXECOMP(CommanderMenuBand)
  523. EXECOMP(CommanderSessionBand)
  524. EXECOMP(CommanderPreferencesBand)
  525. EXECOMP(CommanderSelectionBand)
  526. EXECOMP(CommanderToolbarBand)
  527. EXECOMP(CommanderSortBand)
  528. EXECOMP(CommanderCommandsBand)
  529. EXECOMP(CommanderUpdatesBand)
  530. EXECOMP(CommanderTransferBand)
  531. EXECOMP(CommanderUploadDownloadBand)
  532. EXECOMP(CommanderCustomCommandsBand)
  533. EXECOMP(CommanderLocalHistoryBand)
  534. EXECOMP(CommanderLocalNavigationBand)
  535. EXECOMP(CommanderRemoteHistoryBand)
  536. EXECOMP(CommanderRemoteNavigationBand)
  537. EXECOMP(CommandLinePanel)
  538. EXECOMP(RemoteTree)
  539. EXECOMP(LocalTree)
  540. EXE(GoToCommandLineAction, ScpExplorer->GoToCommandLine())
  541. EXE(GoToTreeAction, ScpExplorer->GoToTree())
  542. EXE(ViewLogAction, WinConfiguration->LogView =
  543. (WinConfiguration->LogView == lvNone ? lvWindow : lvNone) )
  544. EXE(ShowHiddenFilesAction, ScpExplorer->ToggleShowHiddenFiles())
  545. EXE(AutoReadDirectoryAfterOpAction, ScpExplorer->ToggleAutoReadDirectoryAfterOp())
  546. EXE(PreferencesAction, PreferencesDialog(pmDefault) )
  547. EXE(PresetsPreferencesAction, PreferencesDialog(pmPresets) )
  548. EXE(LockToolbarsAction, WinConfiguration->LockToolbars = !WinConfiguration->LockToolbars)
  549. EXECOMP(CustomCommandsBand)
  550. EXE(ColorMenuAction, );
  551. EXE(ColorDefaultAction, ScpExplorer->SessionColor = (TColor)0);
  552. EXE(ColorPickAction, ScpExplorer->SessionColorPick());
  553. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  554. // SORT
  555. EXESORTA(Local)
  556. EXESORT(Local, dv, Name)
  557. EXESORT(Local, dv, Ext)
  558. EXESORT(Local, dv, Size)
  559. EXESORT(Local, dv, Type)
  560. EXESORT(Local, dv, Changed)
  561. EXESORT(Local, dv, Attr)
  562. EXESORTA(Remote)
  563. EXESORT(Remote, uv, Name)
  564. EXESORT(Remote, uv, Ext)
  565. EXESORT(Remote, uv, Size)
  566. EXESORT(Remote, uv, Changed)
  567. EXESORT(Remote, uv, Rights)
  568. EXESORT(Remote, uv, Owner)
  569. EXESORT(Remote, uv, Group)
  570. EXESORT(Remote, uv, Type)
  571. EXESORTA(Current)
  572. EXESORTC(Name, dvName, uvName)
  573. EXESORTC(Ext, dvExt, uvExt)
  574. EXESORTC(Size, dvSize, uvSize)
  575. EXESORTC(Type, dvType, uvType)
  576. EXESORTC(Changed, dvChanged, uvChanged)
  577. EXESORTC(Rights, dvAttr, uvRights)
  578. EXESORTC(Owner, dvName, uvOwner)
  579. EXESORTC(Group, dvName, uvGroup)
  580. EXE(SortColumnAscendingAction, assert(ListColumn);
  581. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = true; ListColumn = NULL )
  582. EXE(SortColumnDescendingAction, assert(ListColumn);
  583. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = false; ListColumn = NULL )
  584. // SHOW/HIDE COLUMN
  585. EXESHCOL(Local, dv, Name)
  586. EXESHCOL(Local, dv, Ext)
  587. EXESHCOL(Local, dv, Size)
  588. EXESHCOL(Local, dv, Type)
  589. EXESHCOL(Local, dv, Changed)
  590. EXESHCOL(Local, dv, Attr)
  591. EXESHCOL(Remote, uv, Name)
  592. EXESHCOL(Remote, uv, Ext)
  593. EXESHCOL(Remote, uv, Size)
  594. EXESHCOL(Remote, uv, Changed)
  595. EXESHCOL(Remote, uv, Rights)
  596. EXESHCOL(Remote, uv, Owner)
  597. EXESHCOL(Remote, uv, Group)
  598. EXESHCOL(Remote, uv, LinkTarget)
  599. EXESHCOL(Remote, uv, Type)
  600. EXE(HideColumnAction, assert(ListColumn);
  601. COLVIEWPROPS->Visible[ListColumn->Index] = false; ListColumn = NULL )
  602. EXE(BestFitColumnAction, assert(ListColumn); ListColumn = NULL ) // TODO
  603. #undef COLVIEWPROPS
  604. // SESSION
  605. EXE(NewSessionAction, ScpExplorer->NewSession())
  606. EXE(DuplicateSessionAction, ScpExplorer->DuplicateSession())
  607. EXE(CloseSessionAction, ScpExplorer->CloseSession())
  608. EXE(SavedSessionsAction, CreateSessionListMenu(SavedSessionsAction))
  609. EXE(OpenedSessionsAction, CreateOpenedSessionListMenu(OpenedSessionsAction))
  610. EXE(SaveCurrentSessionAction, ScpExplorer->SaveCurrentSession())
  611. // COMMAND
  612. EXE(CompareDirectoriesAction, ScpExplorer->CompareDirectories())
  613. EXE(SynchronizeAction, ScpExplorer->SynchronizeDirectories())
  614. EXE(FullSynchronizeAction, ScpExplorer->FullSynchronizeDirectories())
  615. EXE(ConsoleAction, ScpExplorer->OpenConsole())
  616. EXE(PuttyAction, TTerminalManager::Instance()->OpenInPutty())
  617. EXE(SynchronizeBrowsingAction, ScpExplorer->SynchronizeBrowsingChanged())
  618. EXE(CloseApplicationAction, ScpExplorer->Close())
  619. EXE(FileSystemInfoAction, ScpExplorer->FileSystemInfo())
  620. EXE(ClearCachesAction, ScpExplorer->Terminal->ClearCaches())
  621. EXE(NewFileAction, ScpExplorer->EditNew(osCurrent))
  622. EXE(EditorListCustomizeAction, PreferencesDialog(pmEditor))
  623. // CUSTOM COMMANDS
  624. EXE(CustomCommandsAction, CreateCustomCommandsMenu(CustomCommandsAction))
  625. EXE(CustomCommandsEnterAction, ScpExplorer->AdHocCustomCommand(false))
  626. EXE(CustomCommandsEnterFocusedAction, ScpExplorer->AdHocCustomCommand(true))
  627. EXE(CustomCommandsLastAction, ScpExplorer->LastCustomCommand(false))
  628. EXE(CustomCommandsLastFocusedAction, ScpExplorer->LastCustomCommand(true))
  629. EXE(CustomCommandsCustomizeAction, PreferencesDialog(pmCustomCommands))
  630. // QUEUE
  631. #define EXEQUEUE(OPERATION) EXE(Queue ## OPERATION ## Action, \
  632. ScpExplorer->ExecuteQueueOperation(qo ## OPERATION))
  633. EXEQUEUE(GoTo)
  634. EXEQUEUE(Preferences)
  635. EXEQUEUE(ItemQuery)
  636. EXEQUEUE(ItemError)
  637. EXEQUEUE(ItemPrompt)
  638. EXEQUEUE(ItemDelete)
  639. EXEQUEUE(ItemExecute)
  640. EXEQUEUE(ItemPause)
  641. EXEQUEUE(ItemResume)
  642. EXEQUEUE(ItemUp)
  643. EXEQUEUE(ItemDown)
  644. EXEQUEUE(PauseAll)
  645. EXEQUEUE(ResumeAll)
  646. #undef EXEQUEUE
  647. EXE(QueueToggleShowAction, ScpExplorer->ToggleQueueVisibility())
  648. #define QUEUEACTION(SHOW) EXE(Queue ## SHOW ## Action, \
  649. TQueueViewConfiguration Config = WinConfiguration->QueueView; \
  650. if (Config.Show != qvShow) Config.LastHideShow = Config.Show; \
  651. Config.Show = qv ## SHOW; \
  652. WinConfiguration->QueueView = Config)
  653. QUEUEACTION(Show)
  654. QUEUEACTION(HideWhenEmpty)
  655. QUEUEACTION(Hide)
  656. #undef QUEUEACTION
  657. EXE(QueueDisconnectOnceEmptyAction, )
  658. EXECOMP(QueueToolbar);
  659. ;
  660. }
  661. __finally
  662. {
  663. assert(FIdle < 0);
  664. FIdle++;
  665. }
  666. DoIdle();
  667. }
  668. //---------------------------------------------------------------------------
  669. void __fastcall TNonVisualDataModule::UpdateNonVisibleActions()
  670. {
  671. // following actions needs to be updated even when all clients
  672. // are invisible, so the queue list toolbar button can be shown
  673. NonVisualDataModule->QueueItemQueryAction->Update();
  674. NonVisualDataModule->QueueItemErrorAction->Update();
  675. NonVisualDataModule->QueueItemPromptAction->Update();
  676. }
  677. //---------------------------------------------------------------------------
  678. #define CTRL TShiftState() << ssCtrl
  679. #define ALT TShiftState() << ssAlt
  680. #define SHIFT TShiftState() << ssShift
  681. #define CTRLSHIFT TShiftState() << ssCtrl << ssShift
  682. #define CTRLALT TShiftState() << ssCtrl << ssAlt
  683. #define NONE TShiftState()
  684. void __fastcall TNonVisualDataModule::ExplorerShortcuts()
  685. {
  686. // Directory
  687. CurrentCreateDirAction->ShortCut = ShortCut('D', CTRL);
  688. NewDirAction->ShortCut = CurrentCreateDirAction->ShortCut;
  689. // File operation
  690. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  691. CurrentEditAction->ShortCut = ShortCut('E', CTRL);
  692. AddEditLinkAction->ShortCut = ShortCut('L', CTRLALT);
  693. // Focused operation
  694. CurrentCopyFocusedAction->ShortCut = ShortCut('C', CTRL);
  695. CurrentMoveFocusedAction->ShortCut = ShortCut('M', CTRL);
  696. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_DELETE, NONE);
  697. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_RETURN, ALT);
  698. RemoteMoveToFocusedAction->ShortCut = ShortCut('M', CTRLALT);
  699. // remote directory
  700. RemoteOpenDirAction->ShortCut = ShortCut('O', CTRL);
  701. RemoteRefreshAction->ShortCut = ShortCut(VK_F5, NONE);
  702. RemoteHomeDirAction->ShortCut = ShortCut('H', CTRL);
  703. RemotePathToClipboardAction->ShortCut = ShortCut('P', CTRLSHIFT);
  704. // selected operation
  705. CurrentCopyAction->ShortCut = CurrentCopyFocusedAction->ShortCut;
  706. CurrentMoveAction->ShortCut = CurrentMoveFocusedAction->ShortCut;
  707. CurrentDeleteAction->ShortCut = CurrentDeleteFocusedAction->ShortCut;
  708. CurrentPropertiesAction->ShortCut = CurrentPropertiesFocusedAction->ShortCut;
  709. RemoteMoveToAction->ShortCut = ShortCut('M', CTRLALT);
  710. // selection
  711. SelectAction->ShortCut = ShortCut(VK_ADD, NONE);
  712. UnselectAction->ShortCut = ShortCut(VK_SUBTRACT, NONE);
  713. SelectAllAction->ShortCut = ShortCut('A', CTRL);
  714. InvertSelectionAction->ShortCut = ShortCut(VK_MULTIPLY, NONE);
  715. ClearSelectionAction->ShortCut = ShortCut('L', CTRL);
  716. RestoreSelectionAction->ShortCut = ShortCut('R', CTRLALT);
  717. // commands
  718. NewFileAction->ShortCut = ShortCut('E', CTRLSHIFT);
  719. CloseApplicationAction->ShortCut = ShortCut(VK_F4, ALT);
  720. }
  721. //---------------------------------------------------------------------------
  722. void __fastcall TNonVisualDataModule::CommanderShortcuts()
  723. {
  724. // Directory
  725. CurrentCreateDirAction->ShortCut = ShortCut(VK_F7, NONE);
  726. NewDirAction->ShortCut = CurrentCreateDirAction->ShortCut;
  727. // File operation
  728. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  729. CurrentEditAction->ShortCut = ShortCut(VK_F4, NONE);
  730. AddEditLinkAction->ShortCut = ShortCut(VK_F6, ALT);
  731. // Focused operation
  732. CurrentCopyFocusedAction->ShortCut = ShortCut(VK_F5, NONE);
  733. CurrentMoveFocusedAction->ShortCut = ShortCut(VK_F6, NONE);
  734. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_F8, NONE);
  735. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_F9, NONE);
  736. RemoteMoveToFocusedAction->ShortCut = ShortCut(VK_F6, SHIFT);
  737. RemoteCopyToFocusedAction->ShortCut = ShortCut(VK_F5, SHIFT);
  738. // remote directory
  739. RemoteOpenDirAction->ShortCut = ShortCut('O', CTRL);
  740. RemoteRefreshAction->ShortCut = ShortCut('R', CTRL);
  741. RemoteHomeDirAction->ShortCut = ShortCut('H', CTRL);
  742. RemotePathToClipboardAction->ShortCut = ShortCut(VK_OEM_6 /* ] */, CTRL);
  743. // local directory
  744. LocalOpenDirAction->ShortCut = RemoteOpenDirAction->ShortCut;
  745. LocalRefreshAction->ShortCut = RemoteRefreshAction->ShortCut;
  746. LocalHomeDirAction->ShortCut = RemoteHomeDirAction->ShortCut;
  747. LocalPathToClipboardAction->ShortCut = ShortCut(VK_OEM_4 /* [ */, CTRL);
  748. // selected operation
  749. CurrentCopyAction->ShortCut = CurrentCopyFocusedAction->ShortCut;
  750. CurrentMoveAction->ShortCut = CurrentMoveFocusedAction->ShortCut;
  751. CurrentDeleteAction->ShortCut = CurrentDeleteFocusedAction->ShortCut;
  752. CurrentDeleteAction->SecondaryShortCuts->Clear();
  753. CurrentDeleteAction->SecondaryShortCuts->Add(ShortCutToText(ShortCut(VK_DELETE, NONE)));
  754. CurrentPropertiesAction->ShortCut = CurrentPropertiesFocusedAction->ShortCut;
  755. RemoteMoveToAction->ShortCut = ShortCut(VK_F6, SHIFT);
  756. RemoteCopyToAction->ShortCut = ShortCut(VK_F5, SHIFT);
  757. // selection
  758. SelectOneAction->ShortCut = VK_INSERT;
  759. SelectAction->ShortCut = ShortCut(VK_ADD, NONE);
  760. UnselectAction->ShortCut = ShortCut(VK_SUBTRACT, NONE);
  761. SelectAllAction->ShortCut = ShortCut('A', CTRL);
  762. InvertSelectionAction->ShortCut = ShortCut(VK_MULTIPLY, NONE);
  763. ClearSelectionAction->ShortCut = ShortCut('L', CTRL);
  764. RestoreSelectionAction->ShortCut = ShortCut('R', CTRLALT);
  765. // commands
  766. NewFileAction->ShortCut = ShortCut(VK_F4, SHIFT);
  767. // legacy shortcut (can be removed when necessary)
  768. NewFileAction->SecondaryShortCuts->Add(ShortCutToText(ShortCut(VK_F4, CTRLSHIFT)));
  769. CloseApplicationAction->ShortCut = ShortCut(VK_F10, NONE);
  770. }
  771. #undef CTRL
  772. #undef ALT
  773. #undef NONE
  774. //---------------------------------------------------------------------------
  775. void __fastcall TNonVisualDataModule::SetScpExplorer(TCustomScpExplorerForm * value)
  776. {
  777. FScpExplorer = value;
  778. SessionIdleTimer->Enabled = (FScpExplorer != NULL);
  779. }
  780. //---------------------------------------------------------------------------
  781. void __fastcall TNonVisualDataModule::SessionIdleTimerTimer(
  782. TObject */*Sender*/)
  783. {
  784. DoIdle();
  785. }
  786. //---------------------------------------------------------------------------
  787. void __fastcall TNonVisualDataModule::DoIdle()
  788. {
  789. if (!FSessionIdleTimerExecuting)
  790. {
  791. FSessionIdleTimerExecuting = true;
  792. try
  793. {
  794. assert(ScpExplorer);
  795. ScpExplorer->Idle(FIdle >= 0);
  796. }
  797. __finally
  798. {
  799. FSessionIdleTimerExecuting = false;
  800. }
  801. }
  802. }
  803. //---------------------------------------------------------------------------
  804. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(
  805. TTBCustomItem * Menu, bool OnFocused, bool Toolbar)
  806. {
  807. for (int Index = 0; Index < WinConfiguration->CustomCommands->Count; Index++)
  808. {
  809. AnsiString Description = WinConfiguration->CustomCommands->Names[Index];
  810. int State = ScpExplorer->CustomCommandState(Description, OnFocused);
  811. if (State >= 0)
  812. {
  813. TTBCustomItem * Item = new TTBXItem(Owner);
  814. Item->Caption = Description;
  815. if (Toolbar)
  816. {
  817. Item->Caption = StripHotkey(Item->Caption);
  818. }
  819. Item->Tag = Index;
  820. Item->Enabled = (State > 0);
  821. if (OnFocused)
  822. {
  823. Item->Tag = Item->Tag | 0x0100;
  824. }
  825. Item->Hint = FMTLOAD(CUSTOM_COMMAND_HINT, (StripHotkey(Description)));
  826. Item->OnClick = CustomCommandClick;
  827. Menu->Add(Item);
  828. }
  829. }
  830. TTBCustomItem * Item;
  831. Item = new TTBXItem(Menu);
  832. Item->Action = OnFocused ? CustomCommandsEnterFocusedAction : CustomCommandsEnterAction;
  833. Menu->Add(Item);
  834. Item = new TTBXItem(Menu);
  835. Item->Action = OnFocused ? CustomCommandsLastFocusedAction : CustomCommandsLastAction;
  836. if (Toolbar)
  837. {
  838. Item->Caption = StripHotkey(LoadStr(CUSTOM_COMMAND_LAST_SHORT));
  839. }
  840. Menu->Add(Item);
  841. AddMenuSeparator(Menu);
  842. if (!Toolbar)
  843. {
  844. Item = new TTBXItem(Menu);
  845. Item->Action = CustomCommandsBandAction;
  846. Menu->Add(Item);
  847. }
  848. Item = new TTBXItem(Menu);
  849. Item->Action = CustomCommandsCustomizeAction;
  850. Menu->Add(Item);
  851. }
  852. //---------------------------------------------------------------------------
  853. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(TAction * Action)
  854. {
  855. assert(Action);
  856. TTBCustomItem * Menu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  857. if (Menu)
  858. {
  859. int PrevCount = Menu->Count;
  860. bool OnFocused = (Menu == RemoteDirViewCustomCommandsMenu);
  861. CreateCustomCommandsMenu(Menu, OnFocused, false);
  862. for (int Index = 0; Index < PrevCount; Index++)
  863. {
  864. Menu->Delete(0);
  865. }
  866. }
  867. }
  868. //---------------------------------------------------------------------------
  869. void __fastcall TNonVisualDataModule::UpdateCustomCommandsToolbar(TTBXToolbar * Toolbar)
  870. {
  871. // can be called while explorer is being created
  872. if (ScpExplorer == NULL)
  873. {
  874. return;
  875. }
  876. int AdditionalCommands = 4;
  877. TCustomCommands * CustomCommands = WinConfiguration->CustomCommands;
  878. bool Changed = (CustomCommands->Count != (Toolbar->Items->Count - AdditionalCommands));
  879. if (!Changed)
  880. {
  881. int Index = 0;
  882. while (!Changed && (Index < CustomCommands->Count))
  883. {
  884. Changed =
  885. (Toolbar->Items->Items[Index]->Caption !=
  886. StripHotkey(CustomCommands->Names[Index]));
  887. Index++;
  888. }
  889. }
  890. if (Changed)
  891. {
  892. Toolbar->BeginUpdate();
  893. try
  894. {
  895. Toolbar->Items->Clear();
  896. CreateCustomCommandsMenu(Toolbar->Items, false, true);
  897. assert(CustomCommands->Count == (Toolbar->Items->Count - AdditionalCommands));
  898. }
  899. __finally
  900. {
  901. Toolbar->EndUpdate();
  902. }
  903. }
  904. else
  905. {
  906. for (int Index = 0; Index < Toolbar->Items->Count - AdditionalCommands; Index++)
  907. {
  908. TTBCustomItem * Item = Toolbar->Items->Items[Index];
  909. int CommandIndex = (Item->Tag & 0x00FF);
  910. assert(CommandIndex == Index);
  911. AnsiString Description = WinConfiguration->CustomCommands->Names[CommandIndex];
  912. int State = ScpExplorer->CustomCommandState(Description, false);
  913. assert(State >= 0);
  914. Item->Enabled = (State > 0);
  915. }
  916. }
  917. }
  918. //---------------------------------------------------------------------------
  919. void __fastcall TNonVisualDataModule::CustomCommandClick(TObject * Sender)
  920. {
  921. TTBCustomItem * Item = dynamic_cast<TTBCustomItem *>(Sender);
  922. assert(Item);
  923. TCustomCommandParam Param;
  924. Param.Name = WinConfiguration->CustomCommands->Names[Item->Tag & 0x00FF];
  925. Param.Command = WinConfiguration->CustomCommands->Values[Param.Name];
  926. Param.Params = WinConfiguration->CustomCommands->Params[Param.Name];
  927. ScpExplorer->ExecuteFileOperation(foCustomCommand, osRemote,
  928. (Item->Tag & 0xFF00) != 0, false, &Param);
  929. }
  930. //---------------------------------------------------------------------------
  931. void __fastcall TNonVisualDataModule::CreateSessionListMenu(TAction * Action)
  932. {
  933. TTBCustomItem * SavedSessionsMenu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  934. int PrevCount = SavedSessionsMenu->Count;
  935. StoredSessions->Load();
  936. for (int Index = 0; Index < StoredSessions->Count; Index++)
  937. {
  938. TSessionData * Data = StoredSessions->Sessions[Index];
  939. TTBCustomItem * Item = new TTBXItem(SavedSessionsMenu);
  940. Item->Caption = Data->Name;
  941. Item->Tag = Index;
  942. Item->Hint = FMTLOAD(SAVEDSESSION_HINT, (Data->Name));
  943. Item->OnClick = SessionItemClick;
  944. SavedSessionsMenu->Add(Item);
  945. }
  946. for (int Index = 0; Index < PrevCount; Index++)
  947. {
  948. SavedSessionsMenu->Delete(0);
  949. }
  950. }
  951. //---------------------------------------------------------------------------
  952. void __fastcall TNonVisualDataModule::SessionItemClick(TObject * Sender)
  953. {
  954. assert(StoredSessions && (((TMenuItem *)Sender)->Tag < StoredSessions->Count));
  955. ScpExplorer->OpenStoredSession(StoredSessions->Sessions[((TMenuItem *)Sender)->Tag]);
  956. }
  957. //---------------------------------------------------------------------------
  958. TShortCut __fastcall TNonVisualDataModule::OpenSessionShortCut(int Index)
  959. {
  960. if (Index >= 0 && Index < 10)
  961. {
  962. return ShortCut((Word)(Index < 9 ? '0' + 1 + Index : '0'),
  963. TShiftState() << ssAlt);
  964. }
  965. else
  966. {
  967. return scNone;
  968. }
  969. }
  970. //---------------------------------------------------------------------------
  971. void __fastcall TNonVisualDataModule::CreateOpenedSessionListMenu(TAction * Action)
  972. {
  973. TTBCustomItem * OpenedSessionsMenu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  974. assert(OpenedSessionsMenu != NULL);
  975. TTerminalManager * Manager = TTerminalManager::Instance();
  976. TStrings * TerminalList = Manager->TerminalList;
  977. int PrevCount = OpenedSessionsMenu->Count;
  978. for (int Index = 0; Index < TerminalList->Count; Index++)
  979. {
  980. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  981. assert(Terminal);
  982. TTBCustomItem * Item = new TTBXItem(OpenedSessionsMenu);
  983. Item->Caption = TerminalList->Strings[Index];
  984. Item->Tag = int(Terminal);
  985. Item->Hint = FMTLOAD(OPENEDSESSION_HINT, (Item->Caption));
  986. Item->Checked = (Manager->ActiveTerminal == Terminal);
  987. Item->ShortCut = OpenSessionShortCut(Index);
  988. Item->OnClick = OpenedSessionItemClick;
  989. Item->RadioItem = true;
  990. OpenedSessionsMenu->Add(Item);
  991. }
  992. for (int Index = 0; Index < PrevCount; Index++)
  993. {
  994. OpenedSessionsMenu->Delete(0);
  995. }
  996. }
  997. //---------------------------------------------------------------------------
  998. void __fastcall TNonVisualDataModule::OpenedSessionItemClick(TObject * Sender)
  999. {
  1000. TTerminalManager::Instance()->ActiveTerminal = (TTerminal*)(((TMenuItem *)Sender)->Tag);
  1001. }
  1002. //---------------------------------------------------------------------------
  1003. void __fastcall TNonVisualDataModule::CreateEditorListMenu(TAction * Action)
  1004. {
  1005. assert(Action != NULL);
  1006. TTBCustomItem * Menu = dynamic_cast<TTBCustomItem *>(Action->ActionComponent);
  1007. if (Menu != NULL)
  1008. {
  1009. int PrevCount = Menu->Count;
  1010. TTBCustomItem * Item = new TTBXItem(Menu);
  1011. Item->Caption = LoadStr(INTERNAL_EDITOR_NAME);
  1012. Item->Tag = -1;
  1013. Item->Hint = LoadStr(INTERNAL_EDITOR_HINT);
  1014. Item->OnClick = EditorItemClick;
  1015. Menu->Add(Item);
  1016. AddMenuSeparator(Menu);
  1017. TStringList * UsedEditors = new TStringList();
  1018. try
  1019. {
  1020. UsedEditors->CaseSensitive = false;
  1021. UsedEditors->Sorted = true;
  1022. bool AnyExternal = false;
  1023. const TEditorList * EditorList = WinConfiguration->EditorList;
  1024. for (int Index = 0; Index < EditorList->Count; Index++)
  1025. {
  1026. const TEditorPreferences * Editor = EditorList->Editors[Index];
  1027. if ((Editor->Data.Editor == edExternal) &&
  1028. (UsedEditors->IndexOf(Editor->Data.ExternalEditor) < 0))
  1029. {
  1030. UsedEditors->Add(Editor->Data.ExternalEditor);
  1031. TTBCustomItem * Item = new TTBXItem(Menu);
  1032. Item->Caption = Editor->Name;
  1033. Item->Tag = Index;
  1034. Item->Hint = FMTLOAD(EXTERNAL_EDITOR_HINT, (Editor->Name));
  1035. Item->OnClick = EditorItemClick;
  1036. Menu->Add(Item);
  1037. AnyExternal = true;
  1038. }
  1039. }
  1040. if (AnyExternal)
  1041. {
  1042. AddMenuSeparator(Menu);
  1043. }
  1044. Item = new TTBXItem(Menu);
  1045. Item->Action = EditorListCustomizeAction;
  1046. Menu->Add(Item);
  1047. for (int Index = 0; Index < PrevCount; Index++)
  1048. {
  1049. Menu->Delete(0);
  1050. }
  1051. }
  1052. __finally
  1053. {
  1054. delete UsedEditors;
  1055. }
  1056. }
  1057. }
  1058. //---------------------------------------------------------------------------
  1059. void __fastcall TNonVisualDataModule::EditorItemClick(TObject * Sender)
  1060. {
  1061. int Tag = dynamic_cast<TTBXItem*>(Sender)->Tag;
  1062. if (Tag < 0)
  1063. {
  1064. ScpExplorer->ExecuteFile(osCurrent, efInternalEditor, NULL, true, false);
  1065. }
  1066. else
  1067. {
  1068. const TEditorList * EditorList = WinConfiguration->EditorList;
  1069. // sanity check
  1070. if (Tag < EditorList->Count)
  1071. {
  1072. ScpExplorer->ExecuteFile(osCurrent, efExternalEditor, EditorList->Editors[Tag],
  1073. true, false);
  1074. }
  1075. }
  1076. }
  1077. //---------------------------------------------------------------------------
  1078. void __fastcall TNonVisualDataModule::QueuePopupPopup(TObject * /*Sender*/)
  1079. {
  1080. TAction * Action = NULL;
  1081. switch (ScpExplorer->DefaultQueueOperation())
  1082. {
  1083. case qoItemQuery:
  1084. Action = QueueItemQueryAction;
  1085. break;
  1086. case qoItemError:
  1087. Action = QueueItemErrorAction;
  1088. break;
  1089. case qoItemPrompt:
  1090. Action = QueueItemPromptAction;
  1091. break;
  1092. case qoItemExecute:
  1093. Action = QueueItemExecuteAction;
  1094. break;
  1095. case qoItemPause:
  1096. Action = QueueItemPauseAction;
  1097. break;
  1098. case qoItemResume:
  1099. Action = QueueItemResumeAction;
  1100. break;
  1101. }
  1102. TTBCustomItem * Item;
  1103. for (int Index = 0; Index < QueuePopup->Items->Count; Index++)
  1104. {
  1105. Item = QueuePopup->Items->Items[Index];
  1106. TTBItemOptions O = Item->Options;
  1107. if ((Action != NULL) && (Item->Action == Action))
  1108. {
  1109. O << tboDefault;
  1110. }
  1111. else
  1112. {
  1113. O >> tboDefault;
  1114. }
  1115. Item->Options = O;
  1116. }
  1117. }
  1118. //---------------------------------------------------------------------------
  1119. void __fastcall TNonVisualDataModule::ShowUpdatesUpdate()
  1120. {
  1121. TUpdatesConfiguration Updates = WinConfiguration->Updates;
  1122. unsigned short H, M, S, MS;
  1123. DecodeTime(Now(), H, M, S, MS);
  1124. int CurrentCompoundVer = CurrentCompoundVersion();
  1125. ShowUpdatesAction->ImageIndex =
  1126. ((Updates.HaveResults && (Updates.Results.ForVersion == CurrentCompoundVer) &&
  1127. !Updates.Results.Disabled &&
  1128. ((Updates.Results.Critical && !Updates.ShownResults && (MS >= 500)) ||
  1129. ((!Updates.Results.Critical || Updates.ShownResults) &&
  1130. ((Updates.Results.Version > CurrentCompoundVer) ||
  1131. !Updates.Results.Message.IsEmpty())))) ? 80 :
  1132. ((int(Updates.Period) <= 0) ? 81 : 63));
  1133. }
  1134. //---------------------------------------------------------------------------
  1135. void __fastcall TNonVisualDataModule::PreferencesDialog(TPreferencesMode APreferencesMode)
  1136. {
  1137. if (ScpExplorer != NULL)
  1138. {
  1139. ScpExplorer->PreferencesDialog(APreferencesMode);
  1140. }
  1141. else
  1142. {
  1143. DoPreferencesDialog(APreferencesMode);
  1144. }
  1145. }
  1146. //---------------------------------------------------------------------------
  1147. void __fastcall TNonVisualDataModule::CustomCommandsLastUpdate(TAction * Action)
  1148. {
  1149. TCustomCommandParam CustomCommand;
  1150. int State;
  1151. bool Defined = ScpExplorer->GetLastCustomCommand(
  1152. (Action == CustomCommandsLastFocusedAction), CustomCommand, State);
  1153. Action->Visible = Defined;
  1154. if (Defined)
  1155. {
  1156. AnsiString TitleCommand = CustomCommand.Command;
  1157. int MaxTitleCommandLen = 20;
  1158. if (TitleCommand.Length() > MaxTitleCommandLen)
  1159. {
  1160. TitleCommand = TitleCommand.SubString(1, MaxTitleCommandLen - 3) + "...";
  1161. }
  1162. Action->Caption = FMTLOAD(CUSTOM_COMMAND_LAST, (TitleCommand));
  1163. Action->Hint = FMTLOAD(CUSTOM_COMMAND_HINT, (CustomCommand.Command));
  1164. Action->Enabled = (State > 0);
  1165. }
  1166. }