NonVisual.cpp 30 KB

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