NonVisual.cpp 60 KB

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