NonVisual.cpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "NonVisual.h"
  5. #include <Common.h>
  6. #include <ScpMain.h>
  7. #include <TextsWin.h>
  8. #include <Log.h>
  9. #include <Interface.h>
  10. #include "WinConfiguration.h"
  11. #include "TerminalManager.h"
  12. //---------------------------------------------------------------------------
  13. #pragma package(smart_init)
  14. #pragma resource "*.dfm"
  15. TNonVisualDataModule *NonVisualDataModule;
  16. //---------------------------------------------------------------------------
  17. #define SCPCOMMANDER ((TScpCommanderForm *)ScpExplorer)
  18. #define UPDEX(HandleAction, Condition, OtherEnabled, OtherDisabled) if (Action == HandleAction) { \
  19. ((TCustomAction *)Action)->Enabled = (Condition); \
  20. if (((TCustomAction *)Action)->Enabled) { OtherEnabled; } else { OtherDisabled; }; \
  21. Handled = true; } else
  22. #define UPD(HandleAction, Condition) if (Action == HandleAction) { \
  23. ((TCustomAction *)Action)->Enabled = (Condition); Handled = true; } else
  24. #define EXE(HandleAction, Command) if (Action == HandleAction) { \
  25. Command; Handled = true; } else
  26. #define UPDACT(HandleAction, Command) EXE(HandleAction, Command)
  27. #define UPDCOMP(COMP) if (Action == COMP ## Action) { COMP ## Action->Enabled = true; \
  28. COMP ## Action->Checked = ScpExplorer->ComponentVisible[fc ## COMP]; Handled = true; } else
  29. #define EXECOMP(COMP) EXE(COMP ## Action, \
  30. ScpExplorer->ComponentVisible[fc ## COMP] = !ScpExplorer->ComponentVisible[fc ## COMP] )
  31. #define COLPROPS(SIDE) \
  32. ((TCustomDirViewColProperties*)ScpExplorer->DirView(os ## SIDE)->ColProperties)
  33. #define UPDSORT(SIDE, PREFIX, COL) if (Action == SIDE ## SortBy ## COL ## Action) { \
  34. SIDE ## SortBy ## COL ## Action->Enabled = true; Handled = true; \
  35. SIDE ## SortBy ## COL ## Action->Checked = (COLPROPS(SIDE)->SortColumn == PREFIX ## COL); } else
  36. #define EXESORT(SIDE, PREFIX, COL) EXE(SIDE ## SortBy ## COL ## Action, \
  37. if (COLPROPS(SIDE)->SortColumn == PREFIX ## COL) \
  38. COLPROPS(SIDE)->SortAscending = !COLPROPS(SIDE)->SortAscending; \
  39. else COLPROPS(SIDE)->SortColumn = PREFIX ## COL )
  40. #define UPDSORTA(SIDE) if (Action == SIDE ## SortAscendingAction) { \
  41. SIDE ## SortAscendingAction->Enabled = true; Handled = true; \
  42. SIDE ## SortAscendingAction->Checked = COLPROPS(SIDE)->SortAscending; } else
  43. #define EXESORTA(SIDE) EXE(SIDE ## SortAscendingAction, \
  44. COLPROPS(SIDE)->SortAscending = !COLPROPS(SIDE)->SortAscending; )
  45. #define UPDSORTC(LPREFIX, LCOL, RPREFIX, RCOL) if (Action == CurrentSortBy ## RCOL ## Action) { \
  46. CurrentSortBy ## RCOL ## Action->Enabled = ScpExplorer->AllowedAction((TAction *)Action, aaShortCut); \
  47. if (CurrentSortBy ## RCOL ## Action->Enabled) { \
  48. if (ScpExplorer->DirView(osCurrent) == ScpExplorer->DirView(osRemote)) \
  49. CurrentSortBy ## RCOL ## Action->Checked = (COLPROPS(Current)->SortColumn == RPREFIX ## RCOL); \
  50. else CurrentSortBy ## RCOL ## Action->Checked = (COLPROPS(Current)->SortColumn == LPREFIX ## LCOL); \
  51. } else CurrentSortBy ## RCOL ## Action->Checked = false; Handled = true; } else
  52. #define EXESORTC(COL, LCOL, RCOL) \
  53. EXE(CurrentSortBy ## COL ## Action, \
  54. Integer NewSortCol = \
  55. ((ScpExplorer->DirView(osCurrent) == ScpExplorer->DirView(osRemote)) ? RCOL : LCOL); \
  56. if (COLPROPS(Current)->SortColumn == NewSortCol) \
  57. COLPROPS(Current)->SortAscending = !COLPROPS(Current)->SortAscending; \
  58. else COLPROPS(Current)->SortColumn = NewSortCol \
  59. )
  60. #define UPDSHCOL(SIDE, PREFIX, COL) \
  61. EXE(ShowHide ## SIDE ## COL ## ColumnAction, \
  62. ShowHide ## SIDE ## COL ## ColumnAction->Checked = COLPROPS(SIDE)->Visible[PREFIX ## COL])
  63. #define EXESHCOL(SIDE, PREFIX, COL) \
  64. EXE(ShowHide ## SIDE ## COL ## ColumnAction, \
  65. COLPROPS(SIDE)->Visible[PREFIX ## COL] = !COLPROPS(SIDE)->Visible[PREFIX ## COL])
  66. //---------------------------------------------------------------------------
  67. __fastcall TNonVisualDataModule::TNonVisualDataModule(TComponent* Owner)
  68. : TDataModule(Owner)
  69. {
  70. FListColumn = NULL;
  71. FSessionIdleTimerExecuting = false;
  72. }
  73. //---------------------------------------------------------------------------
  74. void __fastcall TNonVisualDataModule::LogActionsUpdate(
  75. TBasicAction *Action, bool &Handled)
  76. {
  77. TLogMemo * LogMemo = TTerminalManager::Instance()->LogMemo;
  78. bool ValidLogMemo = LogMemo && LogMemo->Parent;
  79. UPD(LogClearAction, ValidLogMemo && LogMemo->Lines->Count)
  80. UPD(LogSelectAllAction, ValidLogMemo && LogMemo->Lines->Count &&
  81. LogMemo->SelLength != LogMemo->Lines->Text.Length())
  82. UPD(LogCopyAction, ValidLogMemo && LogMemo->SelLength)
  83. UPD(LogCloseAction, Configuration->Logging && (WinConfiguration->LogView == lvWindow))
  84. ;
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TNonVisualDataModule::LogActionsExecute(
  88. TBasicAction *Action, bool &Handled)
  89. {
  90. TLogMemo * LogMemo = TTerminalManager::Instance()->LogMemo;
  91. assert(LogMemo && LogMemo->Parent);
  92. EXE(LogClearAction, LogMemo->SessionLog->Clear())
  93. EXE(LogSelectAllAction, LogMemo->SelectAll())
  94. EXE(LogCopyAction, LogMemo->CopyToClipboard())
  95. EXE(LogCloseAction, WinConfiguration->LogView = lvNone)
  96. ;
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TNonVisualDataModule::ExplorerActionsUpdate(
  100. TBasicAction *Action, bool &Handled)
  101. {
  102. if (!ScpExplorer || !ScpExplorer->AllowedAction((TAction *)Action, aaUpdate))
  103. {
  104. ((TAction *)Action)->Enabled = false;
  105. Handled = true;
  106. return;
  107. }
  108. // CURRENT DIRVIEW
  109. bool EnableSelectedOperation = ScpExplorer->EnableSelectedOperation[osCurrent];
  110. bool EnableFocusedOperation = ScpExplorer->EnableFocusedOperation[osCurrent];
  111. // focused operation
  112. UPD(CurrentCopyFocusedAction, EnableFocusedOperation)
  113. UPD(CurrentMoveFocusedAction, EnableFocusedOperation)
  114. UPD(CurrentDeleteFocusedAction, EnableFocusedOperation)
  115. UPD(CurrentPropertiesFocusedAction, EnableFocusedOperation)
  116. // file operation
  117. UPD(CurrentRenameAction, EnableFocusedOperation &&
  118. ((ScpExplorer->HasDirView[osLocal] && DirView(osLocal) == DirView(osCurrent)) ||
  119. ScpExplorer->Terminal->IsCapable[fcRename]))
  120. UPD(CurrentEditAction, EnableFocusedOperation &&
  121. !WinConfiguration->DisableOpenEdit &&
  122. !DirView(osCurrent)->ItemIsDirectory(DirView(osCurrent)->ItemFocused))
  123. UPD(CurrentEditAlternativeAction, EnableFocusedOperation &&
  124. !WinConfiguration->DisableOpenEdit &&
  125. !DirView(osCurrent)->ItemIsDirectory(DirView(osCurrent)->ItemFocused) &&
  126. (WinConfiguration->Editor.Editor == edExternal || !WinConfiguration->Editor.ExternalEditor.IsEmpty()))
  127. UPD(CurrentOpenAction, EnableFocusedOperation &&
  128. !WinConfiguration->DisableOpenEdit &&
  129. !DirView(osCurrent)->ItemIsDirectory(DirView(osCurrent)->ItemFocused))
  130. UPD(AddEditLinkAction, ScpExplorer->Terminal &&
  131. (DirView(osCurrent) != DirView(osRemote) ||
  132. (ScpExplorer->Terminal->IsCapable[fcResolveSymlink] &&
  133. ScpExplorer->Terminal->IsCapable[fcSymbolicLink])))
  134. // selected operaton
  135. UPD(CurrentCopyAction, EnableSelectedOperation)
  136. UPD(CurrentMoveAction, EnableSelectedOperation)
  137. UPD(CurrentDeleteAction, EnableSelectedOperation)
  138. UPD(CurrentPropertiesAction, EnableSelectedOperation)
  139. // directory
  140. UPD(CurrentCreateDirAction, true)
  141. // selection
  142. UPD(SelectAction, DirView(osCurrent)->FilesCount)
  143. UPD(UnselectAction, DirView(osCurrent)->SelCount)
  144. UPD(SelectAllAction, DirView(osCurrent)->FilesCount)
  145. UPD(InvertSelectionAction, DirView(osCurrent)->FilesCount)
  146. UPD(ClearSelectionAction, DirView(osCurrent)->SelCount)
  147. //style
  148. UPDACT(CurrentCycleStyleAction,
  149. CurrentCycleStyleAction->ImageIndex = 8 + (DirView(osCurrent)->ViewStyle + 1) % 4)
  150. #define STYLEACTION(Style) UPDACT(Current ## Style ## Action, \
  151. Current ## Style ## Action->Checked = (DirView(osCurrent)->ViewStyle == vs ## Style))
  152. STYLEACTION(Icon)
  153. STYLEACTION(SmallIcon)
  154. STYLEACTION(List)
  155. STYLEACTION(Report)
  156. #undef STYLEACTION
  157. // REMOTE+LOCAL
  158. // back/forward
  159. #define HISTORYACTION(SIDE, DIRECTION, HINTFMT, DELTA) \
  160. UPDEX(SIDE ## DIRECTION ## Action, (DirView(os ## SIDE)->DIRECTION ## Count > 0), \
  161. SIDE ## DIRECTION ## Action->Hint = FMTLOAD(HINTFMT, (DirView(os ## SIDE)->HistoryPath[DELTA])), \
  162. SIDE ## DIRECTION ## Action->Hint = "")
  163. HISTORYACTION(Local, Back, EXPLORER_BACK_HINT, -1)
  164. HISTORYACTION(Local, Forward, EXPLORER_FORWARD_HINT, 1)
  165. HISTORYACTION(Remote, Back, EXPLORER_BACK_HINT, -1)
  166. HISTORYACTION(Remote, Forward, EXPLORER_FORWARD_HINT, 1)
  167. #undef HISTORYACTION
  168. #define PANEL_ACTIONS(SIDE) \
  169. UPD(SIDE ## ParentDirAction, !DirView(os ## SIDE)->IsRoot) \
  170. UPD(SIDE ## RootDirAction, !DirView(os ## SIDE)->IsRoot) \
  171. UPD(SIDE ## HomeDirAction, true) \
  172. UPD(SIDE ## RefreshAction, DirView(os ## SIDE)->DirOK) \
  173. UPD(SIDE ## OpenDirAction, true) \
  174. UPD(SIDE ## ChangePathAction, true) \
  175. EXE(SIDE ## AddBookmarkAction, true)
  176. PANEL_ACTIONS(Local)
  177. PANEL_ACTIONS(Remote)
  178. #undef PANEL_ACTIONS
  179. UPD(LocalExploreDirectoryAction, true)
  180. // HELP
  181. UPD(AboutAction, true)
  182. UPD(HomepageAction, true)
  183. UPD(HistoryPageAction, true)
  184. UPD(RequirementsPageAction, true)
  185. UPD(ForumPageAction, true)
  186. UPD(CheckForUpdatesAction, true)
  187. UPD(DonatePageAction, true)
  188. // VIEW
  189. UPDCOMP(StatusBar)
  190. UPDCOMP(ToolBar)
  191. UPDCOMP(LocalStatusBar)
  192. UPDCOMP(RemoteStatusBar)
  193. UPDCOMP(ExplorerMenuBand)
  194. UPDCOMP(ExplorerAddressBand)
  195. UPDCOMP(ExplorerToolbarBand)
  196. UPDCOMP(ExplorerSelectionBand)
  197. UPDCOMP(ExplorerSessionBand)
  198. UPDCOMP(ExplorerPreferencesBand)
  199. UPDCOMP(ExplorerSortBand)
  200. UPDCOMP(CommanderMenuBand)
  201. UPDCOMP(CommanderSessionBand)
  202. UPDCOMP(CommanderPreferencesBand)
  203. UPDCOMP(CommanderSelectionBand)
  204. UPDCOMP(CommanderToolbarBand)
  205. UPDCOMP(CommanderSortBand)
  206. UPDCOMP(CommanderCommandsBand)
  207. UPDCOMP(CommanderLocalHistoryBand)
  208. UPDCOMP(CommanderLocalNavigationBand)
  209. UPDCOMP(CommanderRemoteHistoryBand)
  210. UPDCOMP(CommanderRemoteNavigationBand)
  211. UPDEX(ViewLogAction, Configuration->Logging,
  212. ViewLogAction->Checked = (WinConfiguration->LogView == lvWindow),
  213. ViewLogAction->Checked = false )
  214. UPD(PreferencesAction, true)
  215. // SORT
  216. UPDSORTA(Local)
  217. UPDSORT(Local, dv, Name)
  218. UPDSORT(Local, dv, Ext)
  219. UPDSORT(Local, dv, Size)
  220. UPDSORT(Local, dv, Type)
  221. UPDSORT(Local, dv, Changed)
  222. UPDSORT(Local, dv, Attr)
  223. UPDSORTA(Remote)
  224. UPDSORT(Remote, uv, Name)
  225. UPDSORT(Remote, uv, Ext)
  226. UPDSORT(Remote, uv, Size)
  227. UPDSORT(Remote, uv, Changed)
  228. UPDSORT(Remote, uv, Rights)
  229. UPDSORT(Remote, uv, Owner)
  230. UPDSORT(Remote, uv, Group)
  231. UPDSORTA(Current)
  232. UPDSORTC(dv, Name, uv, Name)
  233. UPDSORTC(dv, Ext, uv, Ext)
  234. UPDSORTC(dv, Size, uv, Size)
  235. #define uvType uvName /* no type columns on remote panel */
  236. UPDSORTC(dv, Type, uv, Type)
  237. #undef uvType
  238. UPDSORTC(dv, Changed, uv, Changed)
  239. UPDSORTC(dv, Attr, uv, Rights)
  240. UPDSORTC(dv, Name, uv, Owner)
  241. UPDSORTC(dv, Name, uv, Group)
  242. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  243. UPDEX(SortColumnAscendingAction, (ListColumn != NULL), SortColumnAscendingAction->Checked =
  244. (COLVIEWPROPS->SortColumn == ListColumn->Index) && COLVIEWPROPS->SortAscending, /*assert(false)*/ )
  245. UPDEX(SortColumnDescendingAction, (ListColumn != NULL), SortColumnDescendingAction->Checked =
  246. (COLVIEWPROPS->SortColumn == ListColumn->Index) && !COLVIEWPROPS->SortAscending, /*assert(false)*/ )
  247. #undef COLVIEWPROPS
  248. // SHOW/HIDE COLUMN
  249. UPDSHCOL(Local, dv, Name)
  250. UPDSHCOL(Local, dv, Ext)
  251. UPDSHCOL(Local, dv, Size)
  252. UPDSHCOL(Local, dv, Type)
  253. UPDSHCOL(Local, dv, Changed)
  254. UPDSHCOL(Local, dv, Attr)
  255. UPDSHCOL(Remote, uv, Name)
  256. UPDSHCOL(Remote, uv, Ext)
  257. UPDSHCOL(Remote, uv, Size)
  258. UPDSHCOL(Remote, uv, Changed)
  259. UPDSHCOL(Remote, uv, Rights)
  260. UPDSHCOL(Remote, uv, Owner)
  261. UPDSHCOL(Remote, uv, Group)
  262. UPD(HideColumnAction, (ListColumn != NULL))
  263. // SESSION
  264. UPD(NewSessionAction, true)
  265. UPD(CloseSessionAction, true)
  266. UPD(SavedSessionsAction, (StoredSessions->Count > 0))
  267. UPD(OpenedSessionsAction, true)
  268. UPD(SaveCurrentSessionAction, true)
  269. // COMMAND
  270. UPD(CompareDirectoriesAction, true)
  271. UPD(SynchronizeAction, true)
  272. UPD(FullSynchronizeAction, true)
  273. UPD(ConsoleAction, ScpExplorer->Terminal && ScpExplorer->Terminal->IsCapable[fcAnyCommand])
  274. UPD(PuttyAction, true)
  275. UPD(SynchorizeBrowsingAction, true)
  276. UPD(CloseApplicationAction, true)
  277. UPD(FileSystemInfoAction, true)
  278. UPD(ClearCachesAction, (ScpExplorer->Terminal != NULL) && !ScpExplorer->Terminal->AreCachesEmpty)
  279. // CUSTOM COMMANDS
  280. UPD(CustomCommandsAction,
  281. (ScpExplorer->DirView(osCurrent) == ScpExplorer->DirView(osRemote)) &&
  282. ScpExplorer->Terminal && ScpExplorer->Terminal->IsCapable[fcAnyCommand])
  283. UPD(CustomCommandsCustomizeAction, true)
  284. ;
  285. }
  286. //---------------------------------------------------------------------------
  287. void __fastcall TNonVisualDataModule::ExplorerActionsExecute(
  288. TBasicAction *Action, bool &Handled)
  289. {
  290. assert(ScpExplorer);
  291. if (!ScpExplorer->AllowedAction((TAction *)Action, aaExecute))
  292. {
  293. Handled = true;
  294. return;
  295. }
  296. // focused operation
  297. EXE(CurrentCopyFocusedAction, ScpExplorer->ExecuteFileOperation(foCopy, osCurrent, true))
  298. EXE(CurrentMoveFocusedAction, ScpExplorer->ExecuteFileOperation(foMove, osCurrent, true))
  299. EXE(CurrentDeleteFocusedAction, ScpExplorer->ExecuteFileOperation(foDelete, osCurrent, true))
  300. EXE(CurrentPropertiesFocusedAction, ScpExplorer->ExecuteFileOperation(foSetProperties, osCurrent, true))
  301. // operation
  302. EXE(CurrentCopyAction, ScpExplorer->ExecuteFileOperation(foCopy, osCurrent, false))
  303. EXE(CurrentMoveAction, ScpExplorer->ExecuteFileOperation(foMove, osCurrent, false))
  304. EXE(CurrentEditAction, ScpExplorer->ExecuteFile(osCurrent, efEditor))
  305. EXE(CurrentEditAlternativeAction, ScpExplorer->ExecuteFile(osCurrent, efAlternativeEditor))
  306. EXE(CurrentOpenAction, ScpExplorer->ExecuteCurrentFile())
  307. EXE(AddEditLinkAction, ScpExplorer->AddEditLink())
  308. EXE(CurrentRenameAction, ScpExplorer->ExecuteFileOperation(foRename, osCurrent, false))
  309. EXE(CurrentDeleteAction, ScpExplorer->ExecuteFileOperation(foDelete, osCurrent, false))
  310. EXE(CurrentPropertiesAction, ScpExplorer->ExecuteFileOperation(foSetProperties, osCurrent, false))
  311. // directory
  312. EXE(CurrentCreateDirAction, ScpExplorer->CreateDirectory(osCurrent))
  313. //selection
  314. EXE(SelectAction, DirView(osCurrent)->DoSelectByMask(true))
  315. EXE(UnselectAction, DirView(osCurrent)->DoSelectByMask(false))
  316. EXE(SelectAllAction, DirView(osCurrent)->SelectAll(smAll))
  317. EXE(InvertSelectionAction, DirView(osCurrent)->SelectAll(smInvert))
  318. EXE(ClearSelectionAction, DirView(osCurrent)->SelectAll(smNone))
  319. // style
  320. EXE(CurrentCycleStyleAction,
  321. if (DirView(osCurrent)->ViewStyle == vsReport) DirView(osCurrent)->ViewStyle = vsIcon;
  322. else DirView(osCurrent)->ViewStyle = (TViewStyle)(DirView(osCurrent)->ViewStyle + 1);
  323. )
  324. #define STYLEACTION(Style) EXE(Current ## Style ## Action, \
  325. DirView(osCurrent)->ViewStyle = vs ## Style)
  326. STYLEACTION(Icon)
  327. STYLEACTION(SmallIcon)
  328. STYLEACTION(List)
  329. STYLEACTION(Report)
  330. #undef STYLEACTION
  331. #define PANEL_ACTIONS(SIDE) \
  332. EXE(SIDE ## BackAction, DirView(os ## SIDE)->HistoryGo(-1)) \
  333. EXE(SIDE ## ForwardAction, DirView(os ## SIDE)->HistoryGo(1)) \
  334. EXE(SIDE ## ParentDirAction, DirView(os ## SIDE)->ExecuteParentDirectory()) \
  335. EXE(SIDE ## RootDirAction, DirView(os ## SIDE)->ExecuteRootDirectory()) \
  336. EXE(SIDE ## HomeDirAction, DirView(os ## SIDE)->ExecuteHomeDirectory()) \
  337. EXE(SIDE ## RefreshAction, DirView(os ## SIDE)->ReloadDirectory()) \
  338. EXE(SIDE ## OpenDirAction, ScpExplorer->OpenDirectory(os ## SIDE)) \
  339. EXE(SIDE ## ChangePathAction, ScpExplorer->ChangePath(os ## SIDE)) \
  340. EXE(SIDE ## AddBookmarkAction, ScpExplorer->AddBookmark(os ## SIDE))
  341. PANEL_ACTIONS(Local)
  342. PANEL_ACTIONS(Remote)
  343. #undef PANEL_ACTIONS
  344. EXE(LocalExploreDirectoryAction, ScpExplorer->ExploreLocalDirectory())
  345. //HELP
  346. EXE(AboutAction, DoAboutDialog(Configuration))
  347. EXE(HomepageAction, OpenBrowser(LoadStr(HOMEPAGE_URL)))
  348. EXE(HistoryPageAction, OpenBrowser(LoadStr(HISTORY_URL)))
  349. EXE(RequirementsPageAction, OpenBrowser(LoadStr(REQUIREMENTS_URL)))
  350. EXE(ForumPageAction, OpenBrowser(LoadStr(FORUM_URL)))
  351. EXE(CheckForUpdatesAction, CheckForUpdates())
  352. EXE(DonatePageAction, OpenBrowser(LoadStr(DONATE_URL)))
  353. // VIEW
  354. EXECOMP(StatusBar)
  355. EXECOMP(ToolBar)
  356. EXECOMP(LocalStatusBar)
  357. EXECOMP(RemoteStatusBar)
  358. EXECOMP(ExplorerMenuBand)
  359. EXECOMP(ExplorerAddressBand)
  360. EXECOMP(ExplorerToolbarBand)
  361. EXECOMP(ExplorerSelectionBand)
  362. EXECOMP(ExplorerSessionBand)
  363. EXECOMP(ExplorerPreferencesBand)
  364. EXECOMP(ExplorerSortBand)
  365. EXECOMP(CommanderMenuBand)
  366. EXECOMP(CommanderSessionBand)
  367. EXECOMP(CommanderPreferencesBand)
  368. EXECOMP(CommanderSelectionBand)
  369. EXECOMP(CommanderToolbarBand)
  370. EXECOMP(CommanderSortBand)
  371. EXECOMP(CommanderCommandsBand)
  372. EXECOMP(CommanderLocalHistoryBand)
  373. EXECOMP(CommanderLocalNavigationBand)
  374. EXECOMP(CommanderRemoteHistoryBand)
  375. EXECOMP(CommanderRemoteNavigationBand)
  376. EXE(ViewLogAction, WinConfiguration->LogView =
  377. (WinConfiguration->LogView == lvNone ? lvWindow : lvNone) )
  378. EXE(PreferencesAction, DoPreferencesDialog(pmDefault) )
  379. #define COLVIEWPROPS ((TCustomDirViewColProperties*)(((TCustomDirView*)(((TListColumns*)(ListColumn->Collection))->Owner()))->ColProperties))
  380. // SORT
  381. EXESORTA(Local)
  382. EXESORT(Local, dv, Name)
  383. EXESORT(Local, dv, Ext)
  384. EXESORT(Local, dv, Size)
  385. EXESORT(Local, dv, Type)
  386. EXESORT(Local, dv, Changed)
  387. EXESORT(Local, dv, Attr)
  388. EXESORTA(Remote)
  389. EXESORT(Remote, uv, Name)
  390. EXESORT(Remote, uv, Ext)
  391. EXESORT(Remote, uv, Size)
  392. EXESORT(Remote, uv, Changed)
  393. EXESORT(Remote, uv, Rights)
  394. EXESORT(Remote, uv, Owner)
  395. EXESORT(Remote, uv, Group)
  396. EXESORTA(Current)
  397. EXESORTC(Name, dvName, uvName)
  398. EXESORTC(Ext, dvExt, uvExt)
  399. EXESORTC(Size, dvSize, uvSize)
  400. EXESORTC(Type, dvType, uvName)
  401. EXESORTC(Changed, dvChanged, uvChanged)
  402. EXESORTC(Rights, dvAttr, uvRights)
  403. EXESORTC(Owner, dvName, uvOwner)
  404. EXESORTC(Group, dvName, uvGroup)
  405. EXE(SortColumnAscendingAction, assert(ListColumn);
  406. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = true; ListColumn = NULL )
  407. EXE(SortColumnDescendingAction, assert(ListColumn);
  408. COLVIEWPROPS->SortColumn = ListColumn->Index; COLVIEWPROPS->SortAscending = false; ListColumn = NULL )
  409. // SHOW/HIDE COLUMN
  410. EXESHCOL(Local, dv, Name)
  411. EXESHCOL(Local, dv, Ext)
  412. EXESHCOL(Local, dv, Size)
  413. EXESHCOL(Local, dv, Type)
  414. EXESHCOL(Local, dv, Changed)
  415. EXESHCOL(Local, dv, Attr)
  416. EXESHCOL(Remote, uv, Name)
  417. EXESHCOL(Remote, uv, Ext)
  418. EXESHCOL(Remote, uv, Size)
  419. EXESHCOL(Remote, uv, Changed)
  420. EXESHCOL(Remote, uv, Rights)
  421. EXESHCOL(Remote, uv, Owner)
  422. EXESHCOL(Remote, uv, Group)
  423. EXE(HideColumnAction, assert(ListColumn);
  424. COLVIEWPROPS->Visible[ListColumn->Index] = false; ListColumn = NULL )
  425. #undef COLVIEWPROPS
  426. // SESSION
  427. EXE(NewSessionAction, ScpExplorer->NewSession())
  428. EXE(CloseSessionAction, ScpExplorer->CloseSession())
  429. EXE(SavedSessionsAction, CreateSessionListMenu())
  430. EXE(OpenedSessionsAction, )
  431. EXE(SaveCurrentSessionAction, ScpExplorer->SaveCurrentSession())
  432. // COMMAND
  433. EXE(CompareDirectoriesAction, ScpExplorer->CompareDirectories())
  434. EXE(SynchronizeAction, ScpExplorer->SynchronizeDirectories())
  435. EXE(FullSynchronizeAction, ScpExplorer->FullSynchronizeDirectories())
  436. EXE(ConsoleAction, ScpExplorer->OpenConsole())
  437. EXE(PuttyAction, ScpExplorer->OpenInPutty())
  438. EXE(SynchorizeBrowsingAction, )
  439. EXE(CloseApplicationAction, ScpExplorer->Close())
  440. EXE(FileSystemInfoAction, DoFileSystemInfoDialog(ScpExplorer->Terminal))
  441. EXE(ClearCachesAction, ScpExplorer->Terminal->ClearCaches())
  442. // CUSTOM COMMANDS
  443. EXE(CustomCommandsAction, CreateCustomCommandsMenu(CustomCommandsAction))
  444. EXE(CustomCommandsCustomizeAction, DoPreferencesDialog(pmCustomCommands))
  445. ;
  446. }
  447. //---------------------------------------------------------------------------
  448. #define CTRL TShiftState() << ssCtrl
  449. #define ALT TShiftState() << ssAlt
  450. #define SHIFT TShiftState() << ssShift
  451. #define CTRLSHIFT TShiftState() << ssCtrl << ssShift
  452. #define CTRLALT TShiftState() << ssCtrl << ssAlt
  453. #define NONE TShiftState()
  454. void __fastcall TNonVisualDataModule::ExplorerShortcuts()
  455. {
  456. // Directory
  457. CurrentCreateDirAction->ShortCut = ShortCut('D', CTRL);
  458. // File operation
  459. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  460. CurrentEditAction->ShortCut = ShortCut('E', CTRL);
  461. CurrentEditAlternativeAction->ShortCut = ShortCut('E', CTRLSHIFT);
  462. AddEditLinkAction->ShortCut = ShortCut('L', CTRLALT);
  463. // Focused operation
  464. CurrentCopyFocusedAction->ShortCut = ShortCut('C', CTRL);
  465. CurrentMoveFocusedAction->ShortCut = ShortCut('M', CTRL);
  466. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_DELETE, NONE);
  467. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_RETURN, ALT);
  468. // remote directory
  469. RemoteOpenDirAction->ShortCut = ShortCut('O', CTRL);
  470. RemoteRefreshAction->ShortCut = ShortCut(VK_F5, NONE);
  471. RemoteHomeDirAction->ShortCut = ShortCut('H', CTRL);
  472. // selected operation
  473. CurrentCopyAction->ShortCut = CurrentCopyFocusedAction->ShortCut;
  474. CurrentMoveAction->ShortCut = CurrentMoveFocusedAction->ShortCut;
  475. CurrentDeleteAction->ShortCut = CurrentDeleteFocusedAction->ShortCut;
  476. CurrentPropertiesAction->ShortCut = CurrentPropertiesFocusedAction->ShortCut;
  477. // selection
  478. SelectAction->ShortCut = ShortCut(VK_ADD, NONE);
  479. UnselectAction->ShortCut = ShortCut(VK_SUBTRACT, NONE);
  480. SelectAllAction->ShortCut = ShortCut('A', CTRL);
  481. InvertSelectionAction->ShortCut = ShortCut(VK_MULTIPLY, NONE);
  482. ClearSelectionAction->ShortCut = ShortCut('L', CTRL);
  483. CloseApplicationAction->ShortCut = ShortCut(VK_F4, ALT);
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TNonVisualDataModule::CommanderShortcuts()
  487. {
  488. // Directory
  489. CurrentCreateDirAction->ShortCut = ShortCut(VK_F7, NONE);
  490. // File operation
  491. CurrentRenameAction->ShortCut = ShortCut(VK_F2, NONE);
  492. CurrentEditAction->ShortCut = ShortCut(VK_F4, NONE);
  493. CurrentEditAlternativeAction->ShortCut = ShortCut(VK_F4, SHIFT);
  494. AddEditLinkAction->ShortCut = ShortCut(VK_F6, ALT);
  495. // Focused operation
  496. CurrentCopyFocusedAction->ShortCut = ShortCut(VK_F5, NONE);
  497. CurrentMoveFocusedAction->ShortCut = ShortCut(VK_F6, NONE);
  498. CurrentDeleteFocusedAction->ShortCut = ShortCut(VK_F8, NONE);
  499. CurrentPropertiesFocusedAction->ShortCut = ShortCut(VK_F9, NONE);
  500. // remote directory
  501. RemoteOpenDirAction->ShortCut = ShortCut('O', CTRL);
  502. RemoteRefreshAction->ShortCut = ShortCut('R', CTRL);
  503. RemoteHomeDirAction->ShortCut = ShortCut('H', CTRL);
  504. // local directory
  505. LocalOpenDirAction->ShortCut = RemoteOpenDirAction->ShortCut;
  506. LocalRefreshAction->ShortCut = RemoteRefreshAction->ShortCut;
  507. LocalHomeDirAction->ShortCut = RemoteHomeDirAction->ShortCut;
  508. // selected operation
  509. CurrentCopyAction->ShortCut = CurrentCopyFocusedAction->ShortCut;
  510. CurrentMoveAction->ShortCut = CurrentMoveFocusedAction->ShortCut;
  511. CurrentDeleteAction->ShortCut = CurrentDeleteFocusedAction->ShortCut;
  512. CurrentPropertiesAction->ShortCut = CurrentPropertiesFocusedAction->ShortCut;
  513. // selection
  514. SelectAction->ShortCut = ShortCut(VK_ADD, NONE);
  515. UnselectAction->ShortCut = ShortCut(VK_SUBTRACT, NONE);
  516. SelectAllAction->ShortCut = ShortCut('A', CTRL);
  517. InvertSelectionAction->ShortCut = ShortCut(VK_MULTIPLY, NONE);
  518. ClearSelectionAction->ShortCut = ShortCut('L', CTRL);
  519. CloseApplicationAction->ShortCut = ShortCut(VK_F10, NONE);
  520. }
  521. #undef CTRL
  522. #undef ALT
  523. #undef NONE
  524. //---------------------------------------------------------------------------
  525. void __fastcall TNonVisualDataModule::SetScpExplorer(TCustomScpExplorerForm * value)
  526. {
  527. FScpExplorer = value;
  528. SessionIdleTimer->Enabled = (FScpExplorer != NULL);
  529. }
  530. //---------------------------------------------------------------------------
  531. void __fastcall TNonVisualDataModule::SessionIdleTimerTimer(
  532. TObject */*Sender*/)
  533. {
  534. if (!FSessionIdleTimerExecuting)
  535. {
  536. FSessionIdleTimerExecuting = true;
  537. try
  538. {
  539. assert(ScpExplorer);
  540. ScpExplorer->SessionIdle();
  541. }
  542. __finally
  543. {
  544. FSessionIdleTimerExecuting = false;
  545. }
  546. }
  547. }
  548. //---------------------------------------------------------------------------
  549. void __fastcall TNonVisualDataModule::CreateCustomCommandsMenu(TAction * Action)
  550. {
  551. assert(Action);
  552. TMenuItem * Menu = dynamic_cast<TMenuItem *>(Action->ActionComponent);
  553. if (Menu)
  554. {
  555. int PrevCount = Menu->Count;
  556. for (int Index = 0; Index < WinConfiguration->CustomCommands->Count; Index++)
  557. {
  558. AnsiString Description = WinConfiguration->CustomCommands->Names[Index];
  559. AnsiString Command = WinConfiguration->CustomCommands->Values[Description];
  560. TMenuItem * Item = new TMenuItem(Menu);
  561. Item->Caption = Description;
  562. Item->Tag = Index;
  563. if (Menu == RemoteDirViewCustomCommandsMenu)
  564. {
  565. Item->Tag = Item->Tag | 0x0100;
  566. }
  567. Item->Hint = FMTLOAD(CUSTOM_COMMAND_HINT,
  568. (StringReplace(Description, "&", "", TReplaceFlags() << rfReplaceAll)));
  569. Item->OnClick = CustomCommandClick;
  570. Menu->Add(Item);
  571. }
  572. TMenuItem * Item;
  573. if (WinConfiguration->CustomCommands->Count)
  574. {
  575. Item = new TMenuItem(Menu);
  576. Item->Caption = "-";
  577. Item->Hint = "E";
  578. Menu->Add(Item);
  579. }
  580. Item = new TMenuItem(Menu);
  581. Item->Action = CustomCommandsCustomizeAction;
  582. Menu->Add(Item);
  583. for (int Index = 0; Index < PrevCount; Index++)
  584. {
  585. Menu->Delete(0);
  586. }
  587. }
  588. }
  589. //---------------------------------------------------------------------------
  590. void __fastcall TNonVisualDataModule::CustomCommandClick(TObject * Sender)
  591. {
  592. TMenuItem * Item = dynamic_cast<TMenuItem *>(Sender);
  593. assert(Item);
  594. AnsiString CommandName;
  595. CommandName = WinConfiguration->CustomCommands->Names[Item->Tag & 0x00FF];
  596. ScpExplorer->ExecuteFileOperation(foCustomCommand, osRemote,
  597. (Item->Tag & 0xFF00) != 0, false, &CommandName);
  598. }
  599. //---------------------------------------------------------------------------
  600. void __fastcall TNonVisualDataModule::CreateSessionListMenu()
  601. {
  602. int PrevCount = SavedSessionsMenu->Count;
  603. StoredSessions->Load();
  604. for (int Index = 0; Index < StoredSessions->Count; Index++)
  605. {
  606. TSessionData * Data = StoredSessions->Sessions[Index];
  607. TMenuItem * Item = new TMenuItem(SavedSessionsMenu);
  608. Item->Caption = Data->Name;
  609. Item->Tag = Index;
  610. Item->Hint = FMTLOAD(SAVEDSESSION_HINT, (Data->Name));
  611. Item->OnClick = SessionItemClick;
  612. SavedSessionsMenu->Add(Item);
  613. }
  614. for (int Index = 0; Index < PrevCount; Index++)
  615. {
  616. SavedSessionsMenu->Delete(0);
  617. }
  618. }
  619. //---------------------------------------------------------------------------
  620. void __fastcall TNonVisualDataModule::SessionItemClick(TObject * Sender)
  621. {
  622. assert(StoredSessions && (((TMenuItem *)Sender)->Tag < StoredSessions->Count));
  623. ScpExplorer->OpenStoredSession(StoredSessions->Sessions[((TMenuItem *)Sender)->Tag]);
  624. }
  625. //---------------------------------------------------------------------------
  626. TShortCut __fastcall TNonVisualDataModule::OpenSessionShortCut(int Index)
  627. {
  628. if (Index >= 0 && Index < 10)
  629. {
  630. return ShortCut((Word)(Index < 9 ? '0' + 1 + Index : '0'),
  631. TShiftState() << ssAlt);
  632. }
  633. else
  634. {
  635. return scNone;
  636. }
  637. }
  638. //---------------------------------------------------------------------------
  639. void __fastcall TNonVisualDataModule::CreateOpenedSessionListMenu()
  640. {
  641. TTerminalManager * Manager = TTerminalManager::Instance();
  642. TStrings * TerminalList = Manager->TerminalList;
  643. int PrevCount = OpenedSessionsMenu->Count;
  644. for (int Index = 0; Index < TerminalList->Count; Index++)
  645. {
  646. TTerminal * Terminal = dynamic_cast<TTerminal *>(TerminalList->Objects[Index]);
  647. assert(Terminal);
  648. TMenuItem * Item = new TMenuItem(this);
  649. Item->Caption = TerminalList->Strings[Index];
  650. Item->Tag = int(Terminal);
  651. Item->Hint = FMTLOAD(OPENEDSESSION_HINT, (Item->Caption));
  652. Item->Checked = (Manager->ActiveTerminal == Terminal);
  653. Item->ShortCut = OpenSessionShortCut(Index);
  654. Item->OnClick = OpenedSessionItemClick;
  655. OpenedSessionsMenu->Add(Item);
  656. }
  657. for (int Index = 0; Index < PrevCount; Index++)
  658. {
  659. OpenedSessionsMenu->Delete(0);
  660. }
  661. }
  662. //---------------------------------------------------------------------------
  663. void __fastcall TNonVisualDataModule::OpenedSessionItemClick(TObject * Sender)
  664. {
  665. TTerminalManager::Instance()->ActiveTerminal = (TTerminal*)(((TMenuItem *)Sender)->Tag);
  666. }
  667. //---------------------------------------------------------------------------
  668. void __fastcall TNonVisualDataModule::OpenBrowser(AnsiString URL)
  669. {
  670. ShellExecute(Application->Handle, "open", URL.c_str(), NULL, NULL, SW_SHOWNORMAL);
  671. }
  672. //---------------------------------------------------------------------------