NonVisual.cpp 31 KB

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