ScpCommander.cpp 77 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "ScpCommander.h"
  5. #include <Common.h>
  6. #include <CoreMain.h>
  7. #include <Interface.h>
  8. #include <TextsCore.h>
  9. #include <TextsWin.h>
  10. #include <HelpWin.h>
  11. #include <VCLCommon.h>
  12. #include <GUITools.h>
  13. #include <DragDrop.hpp>
  14. #include <StrUtils.hpp>
  15. #include "Glyphs.h"
  16. #include "NonVisual.h"
  17. #include "Tools.h"
  18. #include "WinConfiguration.h"
  19. #include "TerminalManager.h"
  20. #include "Bookmarks.h"
  21. //---------------------------------------------------------------------------
  22. #pragma package(smart_init)
  23. #pragma link "CustomDirView"
  24. #pragma link "CustomScpExplorer"
  25. #pragma link "CustomUnixDirView"
  26. #pragma link "IEListView"
  27. #pragma link "NortonLikeListView"
  28. #pragma link "UnixDirView"
  29. #pragma link "DirView"
  30. #pragma link "PathLabel"
  31. #pragma link "HistoryComboBox"
  32. #pragma link "CustomDriveView"
  33. #pragma link "DriveView"
  34. #pragma link "UnixDriveView"
  35. #pragma link "TB2Dock"
  36. #pragma link "TB2Item"
  37. #pragma link "TB2Toolbar"
  38. #pragma link "TBX"
  39. #pragma link "TB2ExtItems"
  40. #pragma link "TBXExtItems"
  41. #pragma link "TBXLists"
  42. #pragma link "TBXStatusBars"
  43. #pragma link "TBXToolPals"
  44. #pragma link "ThemePageControl"
  45. #ifndef NO_RESOURCES
  46. #pragma resource "*.dfm"
  47. #endif
  48. //---------------------------------------------------------------------------
  49. class TSynchronizedBrowsingGuard
  50. {
  51. public:
  52. TSynchronizedBrowsingGuard()
  53. {
  54. FWasSynchronisingBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  55. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  56. }
  57. ~TSynchronizedBrowsingGuard()
  58. {
  59. NonVisualDataModule->SynchronizeBrowsingAction->Checked = FWasSynchronisingBrowsing;
  60. }
  61. private:
  62. bool FWasSynchronisingBrowsing;
  63. };
  64. //---------------------------------------------------------------------------
  65. __fastcall TScpCommanderForm::TScpCommanderForm(TComponent* Owner)
  66. : TCustomScpExplorerForm(Owner)
  67. {
  68. FConstructed = true;
  69. FCurrentSide = osLocal;
  70. FLastLeftPanelWidth = LeftPanelWidth;
  71. FNormalPanelsWidth = -1;
  72. FSynchronisingBrowse = false;
  73. FFirstTerminal = true;
  74. FInternalDDDownloadList = new TStringList();
  75. FLocalPathComboBoxPaths = new TStringList();
  76. LocalPathComboUpdateDrives();
  77. LocalBackButton->LinkSubitems = HistoryMenu(osLocal, true)->Items;
  78. LocalForwardButton->LinkSubitems = HistoryMenu(osLocal, false)->Items;
  79. RemoteBackButton->LinkSubitems = HistoryMenu(osRemote, true)->Items;
  80. RemoteForwardButton->LinkSubitems = HistoryMenu(osRemote, false)->Items;
  81. TopDock->PopupMenu = NonVisualDataModule->CommanderBarPopup;
  82. CopyPopup(StatusBar, TopDock);
  83. CopyPopup(QueueDock, TopDock);
  84. CopyPopup(QueueLabel, TopDock);
  85. CopyPopup(BottomDock, TopDock);
  86. CopyPopup(QueueSeparatorPanel, TopDock);
  87. LocalTopDock->PopupMenu = NonVisualDataModule->LocalPanelPopup;
  88. CopyPopup(LocalPathLabel, LocalTopDock);
  89. CopyPopup(LocalStatusBar, LocalTopDock);
  90. CopyPopup(LocalDriveView, LocalTopDock);
  91. CopyPopup(LocalBottomDock, LocalTopDock);
  92. RemoteTopDock->PopupMenu = NonVisualDataModule->RemotePanelPopup;
  93. CopyPopup(RemotePathLabel, RemoteTopDock);
  94. CopyPopup(RemoteStatusBar, RemoteTopDock);
  95. CopyPopup(RemoteDriveView, RemoteTopDock);
  96. CopyPopup(RemoteBottomDock, RemoteTopDock);
  97. SetShortcuts();
  98. Splitter->ShowHint = True;
  99. LocalPanelSplitter->ShowHint = true;
  100. reinterpret_cast<TLabel*>(Splitter)->OnDblClick = SplitterDblClick;
  101. reinterpret_cast<TLabel*>(LocalPanelSplitter)->OnDblClick = PanelSplitterDblClick;
  102. reinterpret_cast<TLabel*>(RemotePanelSplitter)->OnDblClick = PanelSplitterDblClick;
  103. CommandLineCombo->Text = L"";
  104. FCommandLineComboPopulated = false;
  105. for (int i = 0; i < Toolbar2Toolbar->Items->Count; i++)
  106. {
  107. UpdateToolbar2ItemCaption(Toolbar2Toolbar->Items->Items[i]);
  108. }
  109. UseDesktopFont(LocalDirView);
  110. UseDesktopFont(LocalDriveView);
  111. UseDesktopFont(LocalPathLabel);
  112. UseDesktopFont(RemotePathLabel);
  113. UseDesktopFont(LocalStatusBar);
  114. UseDesktopFont(StatusBar);
  115. NonVisualDataModule->QueueSpeedComboBoxItem(QueueSpeedComboBoxItem);
  116. // particularly to reorder panels on right-to-left bidi mode
  117. ConfigurationChanged();
  118. }
  119. //---------------------------------------------------------------------------
  120. __fastcall TScpCommanderForm::~TScpCommanderForm()
  121. {
  122. delete FInternalDDDownloadList;
  123. SAFE_DESTROY(FLocalPathComboBoxPaths);
  124. }
  125. //---------------------------------------------------------------------------
  126. void __fastcall TScpCommanderForm::UpdateToolbar2ItemCaption(TTBCustomItem * Item)
  127. {
  128. Item->Caption =
  129. ShortCutToText(Item->ShortCut) + L" " +
  130. StripEllipsis(StripHotkey(Item->Caption));
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall TScpCommanderForm::RestoreFormParams()
  134. {
  135. DebugAssert(WinConfiguration);
  136. TCustomScpExplorerForm::RestoreFormParams();
  137. RestoreForm(WinConfiguration->ScpCommander.WindowParams, this);
  138. }
  139. //---------------------------------------------------------------------------
  140. void __fastcall TScpCommanderForm::RestoreParams()
  141. {
  142. DebugAssert(Configuration);
  143. TCustomScpExplorerForm::RestoreParams();
  144. LeftPanelWidth = WinConfiguration->ScpCommander.LocalPanelWidth;
  145. LoadToolbarsLayoutStr(WinConfiguration->ScpCommander.ToolbarsLayout, WinConfiguration->ScpCommander.ToolbarsButtons);
  146. if (IsUWP())
  147. {
  148. UpdatesToolbar->Visible = false;
  149. }
  150. SessionsPageControl->Visible = WinConfiguration->ScpCommander.SessionsTabs;
  151. StatusBar->Visible = WinConfiguration->ScpCommander.StatusBar;
  152. #define RESTORE_PANEL_PARAMS(PANEL) \
  153. PANEL ## DirView->ColProperties->ParamsStr = WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams; \
  154. PANEL ## StatusBar->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar; \
  155. PANEL ## DriveView->Visible = WinConfiguration->ScpCommander.PANEL ## Panel.DriveView; \
  156. if (PANEL ## DriveView->Align == alTop) \
  157. PANEL ## DriveView->Height = LoadDimension(WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight, WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeightPixelsPerInch, this); \
  158. else \
  159. PANEL ## DriveView->Width = LoadDimension(WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth, WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidthPixelsPerInch, this)
  160. RESTORE_PANEL_PARAMS(Local);
  161. RESTORE_PANEL_PARAMS(Remote);
  162. #undef RESTORE_PANEL_PARAMS
  163. FPanelsRestored = true;
  164. // just to make sure
  165. LocalDirView->DirColProperties->ExtVisible = false;
  166. RemoteDirView->UnixColProperties->ExtVisible = false;
  167. }
  168. //---------------------------------------------------------------------------
  169. void __fastcall TScpCommanderForm::StoreParams()
  170. {
  171. DebugAssert(WinConfiguration);
  172. WinConfiguration->BeginUpdate();
  173. try
  174. {
  175. WinConfiguration->ScpCommander.ToolbarsLayout = GetToolbarsLayoutStr();
  176. WinConfiguration->ScpCommander.ToolbarsButtons = GetToolbarsButtonsStr();
  177. WinConfiguration->ScpCommander.LocalPanelWidth = LeftPanelWidth;
  178. WinConfiguration->ScpCommander.SessionsTabs = SessionsPageControl->Visible;
  179. WinConfiguration->ScpCommander.StatusBar = StatusBar->Visible;
  180. SaveCommandLine();
  181. WinConfiguration->ScpCommander.CurrentPanel = FCurrentSide;
  182. #define STORE_PANEL_PARAMS(PANEL) \
  183. WinConfiguration->ScpCommander.PANEL ## Panel.DirViewParams = PANEL ## DirView->ColProperties->ParamsStr; \
  184. WinConfiguration->ScpCommander.PANEL ## Panel.StatusBar = PANEL ## StatusBar->Visible; \
  185. WinConfiguration->ScpCommander.PANEL ## Panel.DriveView = PANEL ## DriveView->Visible; \
  186. if (PANEL ## DriveView->Align == alTop) \
  187. { \
  188. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeight = PANEL ## DriveView->Height; \
  189. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewHeightPixelsPerInch = GetControlPixelsPerInch(this); \
  190. } \
  191. else \
  192. { \
  193. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidth = PANEL ## DriveView->Width; \
  194. WinConfiguration->ScpCommander.PANEL ## Panel.DriveViewWidthPixelsPerInch = GetControlPixelsPerInch(this); \
  195. }
  196. STORE_PANEL_PARAMS(Local);
  197. STORE_PANEL_PARAMS(Remote);
  198. #undef RESTORE_PANEL_PARAMS
  199. WinConfiguration->ScpCommander.WindowParams = StoreForm(this);
  200. TCustomScpExplorerForm::StoreParams();
  201. }
  202. __finally
  203. {
  204. WinConfiguration->EndUpdate();
  205. }
  206. }
  207. //---------------------------------------------------------------------------
  208. void __fastcall TScpCommanderForm::UpdateTerminal(TTerminal * Terminal)
  209. {
  210. TCustomScpExplorerForm::UpdateTerminal(Terminal);
  211. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  212. DebugAssert(ManagedTerminal != NULL);
  213. DebugAssert(LocalDirView != NULL);
  214. SAFE_DESTROY(ManagedTerminal->LocalExplorerState);
  215. if (WinConfiguration->PreservePanelState)
  216. {
  217. ManagedTerminal->LocalExplorerState = LocalDirView->SaveState();
  218. }
  219. }
  220. //---------------------------------------------------------------------------
  221. void __fastcall TScpCommanderForm::UpdateSessionData(TSessionData * Data)
  222. {
  223. // Keep in sync with TSessionData::CopyStateData
  224. TCustomScpExplorerForm::UpdateSessionData(Data);
  225. DebugAssert(LocalDirView);
  226. Data->LocalDirectory = LocalDirView->PathName;
  227. Data->SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  228. }
  229. //---------------------------------------------------------------------------
  230. bool __fastcall TScpCommanderForm::InternalDDDownload(UnicodeString & TargetDirectory)
  231. {
  232. DebugAssert(IsFileControl(FDDTargetControl, osLocal));
  233. bool Result = false;
  234. if (FDDTargetControl == LocalDirView)
  235. {
  236. if (LocalDirView->DropTarget)
  237. {
  238. // when drop target is not directory, it is probably file type, which have
  239. // associated drop handler (such as ZIP file in WinXP). in this case we
  240. // must leave drop handling to destination application.
  241. // ! this check is duplicated in LocalDirViewDDTargetHasDropHandler()
  242. // for shellex downloads
  243. if (LocalDirView->ItemIsDirectory(LocalDirView->DropTarget))
  244. {
  245. TargetDirectory = LocalDirView->ItemFullFileName(LocalDirView->DropTarget);
  246. Result = true;
  247. }
  248. }
  249. else
  250. {
  251. TargetDirectory = DefaultDownloadTargetDirectory();
  252. Result = true;
  253. }
  254. }
  255. else if (FDDTargetControl == LocalDriveView)
  256. {
  257. DebugAssert(LocalDriveView->DropTarget != NULL);
  258. TargetDirectory = LocalDriveView->NodePathName(LocalDriveView->DropTarget);
  259. Result = true;
  260. }
  261. else
  262. {
  263. DebugFail();
  264. Abort();
  265. }
  266. return Result;
  267. }
  268. //---------------------------------------------------------------------------
  269. UnicodeString __fastcall TScpCommanderForm::DefaultDownloadTargetDirectory()
  270. {
  271. return IncludeTrailingBackslash(LocalDirView->Path);
  272. }
  273. //---------------------------------------------------------------------------
  274. bool __fastcall TScpCommanderForm::CopyParamDialog(TTransferDirection Direction,
  275. TTransferType Type, bool Temp, TStrings * FileList, UnicodeString & TargetDirectory,
  276. TGUICopyParamType & CopyParam, bool Confirm, bool DragDrop, int Options)
  277. {
  278. bool Result = false;
  279. // Temp means d&d here so far, may change in future!
  280. if (Temp && (Direction == tdToLocal) &&
  281. IsFileControl(FDDTargetControl, osLocal))
  282. {
  283. Result = InternalDDDownload(TargetDirectory);
  284. if (Result)
  285. {
  286. DebugAssert(FileList->Count > 0);
  287. FInternalDDDownloadList->Assign(FileList);
  288. }
  289. }
  290. else if (!Temp && TargetDirectory.IsEmpty())
  291. {
  292. if (Direction == tdToLocal)
  293. {
  294. TargetDirectory = DefaultDownloadTargetDirectory();
  295. }
  296. else
  297. {
  298. TargetDirectory = UnixIncludeTrailingBackslash(RemoteDirView->Path);
  299. }
  300. }
  301. if (!Result)
  302. {
  303. Result = TCustomScpExplorerForm::CopyParamDialog(Direction, Type, Temp,
  304. FileList, TargetDirectory, CopyParam, Confirm, DragDrop, Options);
  305. }
  306. return Result;
  307. }
  308. //---------------------------------------------------------------------------
  309. void __fastcall TScpCommanderForm::DoShow()
  310. {
  311. // Make sure the RemoteDirView is disabled (if not connected yet)
  312. // before the focusing below,
  313. // otherwise we disable the view while setting it focused
  314. // (UpdateControls gets calling within the SetFocus),
  315. // leading to VCL focus inconsistency wih Windows,
  316. // and the view [anothing actually] not getting focused after the session
  317. // is finally connected
  318. UpdateControls();
  319. // If we do not call SetFocus on any control before DoShow,
  320. // no control will get focused on Login dialog
  321. // (HACK seems like a bug in VCL)
  322. if (WinConfiguration->ScpCommander.CurrentPanel == osLocal)
  323. {
  324. LocalDirView->SetFocus();
  325. FRemoteDirViewWasFocused = false;
  326. }
  327. else
  328. {
  329. if (RemoteDirView->Enabled)
  330. {
  331. RemoteDirView->SetFocus();
  332. }
  333. else
  334. {
  335. LocalDirView->SetFocus();
  336. }
  337. FRemoteDirViewWasFocused = true;
  338. }
  339. TCustomScpExplorerForm::DoShow();
  340. }
  341. //---------------------------------------------------------------------------
  342. Boolean __fastcall TScpCommanderForm::AllowedAction(TAction * Action, TActionAllowed Allowed)
  343. {
  344. #define FLAG ((TActionFlag)(Action->Tag))
  345. return
  346. TCustomScpExplorerForm::AllowedAction(Action, Allowed) &&
  347. // always require Commander flag
  348. (FLAG & afCommander) &&
  349. // if action is execution or update, we don't require any other flag
  350. // if we check for shortcut, we require proper dirview to be selected
  351. ((Allowed != aaShortCut) ||
  352. ((FLAG & afLocal) && (FCurrentSide == osLocal)) ||
  353. ((FLAG & afRemote) && (FCurrentSide == osRemote))
  354. );
  355. #undef FLAG
  356. }
  357. //---------------------------------------------------------------------------
  358. TCustomDirView * __fastcall TScpCommanderForm::DirView(TOperationSide Side)
  359. {
  360. Side = GetSide(Side);
  361. if (Side == osLocal)
  362. {
  363. return LocalDirView;
  364. }
  365. else
  366. {
  367. return TCustomScpExplorerForm::DirView(Side);
  368. }
  369. }
  370. //---------------------------------------------------------------------------
  371. bool __fastcall TScpCommanderForm::DirViewEnabled(TOperationSide Side)
  372. {
  373. Side = GetSide(Side);
  374. if (Side == osLocal)
  375. {
  376. return true;
  377. }
  378. else
  379. {
  380. return TCustomScpExplorerForm::DirViewEnabled(Side);
  381. }
  382. }
  383. //---------------------------------------------------------------------------
  384. bool __fastcall TScpCommanderForm::IsFileControl(TObject * Control,
  385. TOperationSide Side)
  386. {
  387. return
  388. ((Side == osLocal) &&
  389. ((Control == LocalDirView) || (Control == LocalDriveView))) ||
  390. TCustomScpExplorerForm::IsFileControl(Control, Side);
  391. }
  392. //---------------------------------------------------------------------------
  393. void __fastcall TScpCommanderForm::ReloadLocalDirectory(const UnicodeString Directory)
  394. {
  395. if (Directory.IsEmpty() || SamePaths(Directory, LocalDirView->Path))
  396. {
  397. LocalDirView->ReloadDirectory();
  398. LocalDriveView->ValidateDirectory(LocalDriveView->Selected);
  399. }
  400. TCustomScpExplorerForm::ReloadLocalDirectory();
  401. }
  402. //---------------------------------------------------------------------------
  403. void __fastcall TScpCommanderForm::BatchStart(void *& Storage)
  404. {
  405. Storage = new bool;
  406. *static_cast<bool*>(Storage) = LocalDirView->WatchForChanges;
  407. LocalDirView->WatchForChanges = false;
  408. LocalDriveView->WatchDirectory = false;
  409. TCustomScpExplorerForm::BatchStart(Storage);
  410. }
  411. //---------------------------------------------------------------------------
  412. void __fastcall TScpCommanderForm::BatchEnd(void * Storage)
  413. {
  414. TCustomScpExplorerForm::BatchEnd(Storage);
  415. DebugAssert(Storage != NULL);
  416. LocalDirView->WatchForChanges = *static_cast<bool*>(Storage);
  417. LocalDriveView->WatchDirectory = LocalDirView->WatchForChanges;
  418. delete Storage;
  419. }
  420. //---------------------------------------------------------------------------
  421. void __fastcall TScpCommanderForm::StartingDisconnected()
  422. {
  423. TCustomScpExplorerForm::StartingDisconnected();
  424. LocalDefaultDirectory();
  425. }
  426. //---------------------------------------------------------------------------
  427. void __fastcall TScpCommanderForm::TerminalChanged()
  428. {
  429. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  430. TCustomScpExplorerForm::TerminalChanged();
  431. if (Terminal)
  432. {
  433. // we will load completelly different directory, so particularly
  434. // do not attempt to select previously selected directory
  435. LocalDirView->ContinueSession(false);
  436. TManagedTerminal * ManagedTerminal = dynamic_cast<TManagedTerminal *>(Terminal);
  437. DebugAssert(ManagedTerminal != NULL);
  438. // reset home directory
  439. LocalDirView->HomeDirectory = L"";
  440. if (FFirstTerminal || !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  441. {
  442. UnicodeString LocalDirectory = ManagedTerminal->StateData->LocalDirectory;
  443. bool DocumentsDir = LocalDirectory.IsEmpty();
  444. if (!DocumentsDir)
  445. {
  446. try
  447. {
  448. LocalDirView->Path = LocalDirectory;
  449. }
  450. catch(Exception & E)
  451. {
  452. DocumentsDir = true;
  453. if (!Terminal->SessionData->UpdateDirectories)
  454. {
  455. Terminal->ShowExtendedException(&E);
  456. }
  457. }
  458. }
  459. if (DocumentsDir)
  460. {
  461. LocalDefaultDirectory();
  462. }
  463. }
  464. FFirstTerminal = false;
  465. if (WinConfiguration->DefaultDirIsHome &&
  466. !Terminal->SessionData->UpdateDirectories)
  467. {
  468. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  469. }
  470. if (WinConfiguration->PreservePanelState &&
  471. !WinConfiguration->ScpCommander.PreserveLocalDirectory)
  472. {
  473. if (ManagedTerminal->LocalExplorerState != NULL)
  474. {
  475. LocalDirView->RestoreState(ManagedTerminal->LocalExplorerState);
  476. }
  477. else
  478. {
  479. LocalDirView->ClearState();
  480. }
  481. NonVisualDataModule->SynchronizeBrowsingAction->Checked = ManagedTerminal->StateData->SynchronizeBrowsing;
  482. }
  483. }
  484. }
  485. //---------------------------------------------------------------------------
  486. void __fastcall TScpCommanderForm::LocalDefaultDirectory()
  487. {
  488. try
  489. {
  490. LocalDirView->HomeDirectory = L"";
  491. LocalDirView->ExecuteHomeDirectory();
  492. }
  493. catch(Exception & E)
  494. {
  495. ShowExtendedException(NULL, &E);
  496. LocalDirView->Path = ExtractFilePath(Application->ExeName);
  497. }
  498. }
  499. //---------------------------------------------------------------------------
  500. void __fastcall TScpCommanderForm::ConfigurationChanged()
  501. {
  502. TCustomScpExplorerForm::ConfigurationChanged();
  503. if (WinConfiguration->DefaultDirIsHome && Terminal &&
  504. !Terminal->SessionData->UpdateDirectories)
  505. {
  506. LocalDirView->HomeDirectory = ExpandFileName(Terminal->SessionData->LocalDirectory);
  507. }
  508. else
  509. {
  510. LocalDirView->HomeDirectory = L"";
  511. }
  512. LocalDirView->DimmHiddenFiles = WinConfiguration->DimmHiddenFiles;
  513. LocalDriveView->DimmHiddenDirs = WinConfiguration->DimmHiddenFiles;
  514. LocalDirView->ShowHiddenFiles = WinConfiguration->ShowHiddenFiles;
  515. LocalDirView->FormatSizeBytes = WinConfiguration->FormatSizeBytes;
  516. LocalDriveView->ShowHiddenDirs = WinConfiguration->ShowHiddenFiles;
  517. LocalDirView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  518. LocalDriveView->ConfirmOverwrite = WinConfiguration->ConfirmOverwriting;
  519. LocalDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  520. RemoteDirView->NortonLike = WinConfiguration->ScpCommander.NortonLikeMode;
  521. LocalDirView->NaturalOrderNumericalSorting = WinConfiguration->NaturalOrderNumericalSorting;
  522. if (LocalDirView->RowSelect != WinConfiguration->FullRowSelect)
  523. {
  524. LocalDirView->RowSelect = WinConfiguration->FullRowSelect;
  525. // selection is not redrawn automatically when RowSelect changes
  526. LocalDirView->Invalidate();
  527. }
  528. // See also LocalDirViewDDTargetHasDropHandler
  529. LocalDirView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  530. LocalDriveView->DragDropFilesEx->ShellExtensions->DropHandler = !WinConfiguration->DDFakeFile;
  531. if (Panel(true)->Left > Panel(false)->Left)
  532. {
  533. DisableAlign();
  534. try
  535. {
  536. int AWidth = ClientWidth;
  537. Panel(false)->Align = alClient;
  538. // In bidi mode it gets swapped to alRight, what does not work with the rest of this logic
  539. Splitter->Align = alLeft;
  540. Panel(true)->Align = alLeft;
  541. TControl * ControlsOrder[] =
  542. { Panel(true), Splitter, Panel(false) };
  543. SetHorizontalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  544. Panel(true)->TabOrder = 0;
  545. Panel(false)->TabOrder = 1;
  546. ClientWidth = AWidth;
  547. LeftPanelWidth = FLastLeftPanelWidth;
  548. }
  549. __finally
  550. {
  551. EnableAlign();
  552. }
  553. int LocalIndex = MenuToolbar->Items->IndexOf(LocalMenuButton);
  554. int RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  555. MenuToolbar->Items->Move(LocalIndex, RemoteIndex);
  556. RemoteIndex = MenuToolbar->Items->IndexOf(RemoteMenuButton);
  557. MenuToolbar->Items->Move(RemoteIndex, LocalIndex);
  558. SWAP(TShortCut, NonVisualDataModule->LocalChangePathAction->ShortCut,
  559. NonVisualDataModule->RemoteChangePathAction->ShortCut);
  560. }
  561. if ((RemoteDriveView->Align == alLeft) != WinConfiguration->ScpCommander.TreeOnLeft)
  562. {
  563. TScpCommanderPanelConfiguration LocalPanel = WinConfiguration->ScpCommander.LocalPanel;
  564. TScpCommanderPanelConfiguration RemotePanel = WinConfiguration->ScpCommander.RemotePanel;
  565. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  566. // save value only is it was set yet
  567. if (FPanelsRestored)
  568. {
  569. if (TreeOnLeft)
  570. {
  571. // want to be on left, so it is on top, saving height
  572. LocalPanel.DriveViewHeight = LocalDriveView->Height;
  573. RemotePanel.DriveViewHeight = RemoteDriveView->Height;
  574. }
  575. else
  576. {
  577. LocalPanel.DriveViewWidth = LocalDriveView->Width;
  578. RemotePanel.DriveViewWidth = RemoteDriveView->Width;
  579. }
  580. }
  581. TAlign NonClientAlign = (TreeOnLeft ? alLeft : alTop);
  582. // VCL adjusts cursors only between crVSplit and crHSplit,
  583. // See TSplitter.RequestAlign
  584. TCursor SplitterCursor = (TreeOnLeft ? crSizeWE : crSizeNS);
  585. LocalDriveView->Align = NonClientAlign;
  586. LocalPanelSplitter->Align = NonClientAlign;
  587. LocalPanelSplitter->Cursor = SplitterCursor;
  588. RemoteDriveView->Align = NonClientAlign;
  589. RemotePanelSplitter->Align = NonClientAlign;
  590. RemotePanelSplitter->Cursor = SplitterCursor;
  591. FixControlsPlacement();
  592. if (TreeOnLeft)
  593. {
  594. LocalDriveView->Width = LocalPanel.DriveViewWidth;
  595. RemoteDriveView->Width = RemotePanel.DriveViewWidth;
  596. }
  597. else
  598. {
  599. LocalDriveView->Height = LocalPanel.DriveViewHeight;
  600. RemoteDriveView->Height = RemotePanel.DriveViewHeight;
  601. }
  602. // in case it trigges config-changed event (does not),
  603. // make sure it does only after we apply the TreeOnLeft change to avoid endless recursion
  604. WinConfiguration->ScpCommander.LocalPanel = LocalPanel;
  605. WinConfiguration->ScpCommander.RemotePanel = RemotePanel;
  606. }
  607. if (FExplorerKeyboardShortcuts != WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts)
  608. {
  609. SetShortcuts();
  610. }
  611. }
  612. //---------------------------------------------------------------------------
  613. void __fastcall TScpCommanderForm::SetShortcuts()
  614. {
  615. // set common norton shorcuts to our actions
  616. NonVisualDataModule->CommanderShortcuts();
  617. FExplorerKeyboardShortcuts = WinConfiguration->ScpCommander.ExplorerKeyboardShortcuts;
  618. }
  619. //---------------------------------------------------------------------------
  620. TPanel * __fastcall TScpCommanderForm::Panel(bool Left)
  621. {
  622. bool SwappedPanels = WinConfiguration->ScpCommander.SwappedPanels;
  623. if (IsRightToLeft())
  624. {
  625. SwappedPanels = !SwappedPanels;
  626. }
  627. return (SwappedPanels == Left ? RemotePanel : LocalPanel);
  628. }
  629. //---------------------------------------------------------------------------
  630. TPanel * __fastcall TScpCommanderForm::CurrentPanel()
  631. {
  632. return (FCurrentSide == osLocal ? LocalPanel : RemotePanel);
  633. }
  634. //---------------------------------------------------------------------------
  635. void __fastcall TScpCommanderForm::SetLeftPanelWidth(double value)
  636. {
  637. double Total = LocalPanel->Width + RemotePanel->Width;
  638. FLeftPanelWidth = value;
  639. if (value * Total != Panel(true)->Width)
  640. {
  641. Panel(true)->Width = static_cast<int>(value * Total);
  642. UpdateControls();
  643. }
  644. }
  645. //---------------------------------------------------------------------------
  646. double __fastcall TScpCommanderForm::GetLeftPanelWidth()
  647. {
  648. return FLeftPanelWidth;
  649. }
  650. //---------------------------------------------------------------------------
  651. void __fastcall TScpCommanderForm::SplitterMoved(TObject * /*Sender*/)
  652. {
  653. double Left = Panel(true)->Width;
  654. double Total = LocalPanel->Width + RemotePanel->Width;
  655. FLeftPanelWidth = Left / Total;
  656. FLastLeftPanelWidth = LeftPanelWidth;
  657. UpdateControls();
  658. }
  659. //---------------------------------------------------------------------------
  660. void __fastcall TScpCommanderForm::SplitterCanResize(TObject * /*Sender*/,
  661. int &NewSize, bool & /*Accept*/)
  662. {
  663. // When splitter is drag so far to right, that width contraint of remote panel would
  664. // be violated, it doesn't stop, but extend form width.
  665. // Following prevents this behavior.
  666. if (ClientWidth - NewSize - Splitter->Width < Panel(false)->Constraints->MinWidth)
  667. NewSize = (ClientWidth - Panel(false)->Constraints->MinWidth - Splitter->Width);
  668. }
  669. //---------------------------------------------------------------------------
  670. void __fastcall TScpCommanderForm::SplitterDblClick(TObject * /*Sender*/)
  671. {
  672. LeftPanelWidth = 0.5;
  673. }
  674. //---------------------------------------------------------------------------
  675. void __fastcall TScpCommanderForm::PanelSplitterDblClick(TObject * Sender)
  676. {
  677. TSplitter * Splitter = dynamic_cast<TSplitter *>(Sender);
  678. DebugAssert(Splitter != NULL);
  679. TCustomDriveView * DriveView;
  680. TCustomDriveView * OtherDriveView;
  681. if (Splitter == LocalPanelSplitter)
  682. {
  683. DriveView = LocalDriveView;
  684. OtherDriveView = RemoteDriveView;
  685. }
  686. else
  687. {
  688. DriveView = RemoteDriveView;
  689. OtherDriveView = LocalDriveView;
  690. }
  691. bool TreeOnLeft = WinConfiguration->ScpCommander.TreeOnLeft;
  692. DebugAssert(DriveView->Visible);
  693. if (OtherDriveView->Visible)
  694. {
  695. if (TreeOnLeft)
  696. {
  697. DriveView->Width = OtherDriveView->Width;
  698. }
  699. else
  700. {
  701. DriveView->Height = OtherDriveView->Height;
  702. }
  703. }
  704. else
  705. {
  706. if (TreeOnLeft)
  707. {
  708. OtherDriveView->Width = DriveView->Width;
  709. }
  710. else
  711. {
  712. OtherDriveView->Height = DriveView->Height;
  713. }
  714. OtherDriveView->Visible = true;
  715. }
  716. FixControlsPlacement();
  717. }
  718. //---------------------------------------------------------------------------
  719. void __fastcall TScpCommanderForm::UpdateControls()
  720. {
  721. TCustomScpExplorerForm::UpdateControls();
  722. UnicodeString SplitterLongHint = Splitter->Hint;
  723. int P = SplitterLongHint.Pos(L"|");
  724. if (P == 0)
  725. {
  726. P = SplitterLongHint.Pos(L"\n");
  727. }
  728. SplitterLongHint.Delete(1, P);
  729. Splitter->Hint = FORMAT(L"%0.0f%%\n%s", (LeftPanelWidth*100, SplitterLongHint));
  730. UnicodeString ACommandLinePromptLabel = LoadStr(COMMAND_LINE_LABEL) + " " +
  731. ((FCurrentSide == osRemote) ? L"$" : L">");
  732. if (CommandLinePromptLabel->Caption != ACommandLinePromptLabel)
  733. {
  734. CommandLinePromptLabel->Caption = ACommandLinePromptLabel;
  735. // command line combo width needs to be updated as caption width has probably changed
  736. ToolBarResize(CommandLineToolbar);
  737. }
  738. LocalDirView->Color = (SessionColor != 0 ? SessionColor : clWindow);
  739. LocalDriveView->Color = LocalDirView->Color;
  740. bool LocalSide = (FCurrentSide == osLocal);
  741. TAction * CurrentCopyAction = LocalSide ? NonVisualDataModule->LocalCopyAction : NonVisualDataModule->RemoteCopyAction;
  742. if (CurrentCopyItem->Action != CurrentCopyAction)
  743. {
  744. CurrentCopyItem->Action = CurrentCopyAction;
  745. CurrentCopyToolbar2Item->Action = CurrentCopyAction;
  746. UpdateToolbar2ItemCaption(CurrentCopyToolbar2Item);
  747. CurrentCopyNonQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyNonQueueAction : NonVisualDataModule->RemoteCopyNonQueueAction;
  748. CurrentCopyQueueItem->Action = LocalSide ? NonVisualDataModule->LocalCopyQueueAction : NonVisualDataModule->RemoteCopyQueueAction;
  749. TAction * CurrentMoveAction = LocalSide ? NonVisualDataModule->LocalMoveAction : NonVisualDataModule->RemoteMoveAction;
  750. CurrentMoveItem->Action = CurrentMoveAction;
  751. CurrentMoveToolbar2Item->Action = CurrentMoveAction;
  752. UpdateToolbar2ItemCaption(CurrentMoveToolbar2Item);
  753. }
  754. CommandLineCombo->Enabled = (FCurrentSide == osLocal) || CanConsole();
  755. CommandLinePromptLabel->Enabled = CommandLineCombo->Enabled;
  756. }
  757. //---------------------------------------------------------------------------
  758. void __fastcall TScpCommanderForm::ChangePath(TOperationSide Side)
  759. {
  760. DebugAssert((Side == osLocal) || (Side == osRemote));
  761. TTBXComboBoxItem * PathComboBox;
  762. if (Side == osLocal)
  763. {
  764. PathComboBox = LocalPathComboBox;
  765. }
  766. else
  767. {
  768. PathComboBox = RemotePathComboBox;
  769. }
  770. ClickToolbarItem(PathComboBox, false);
  771. }
  772. //---------------------------------------------------------------------------
  773. TControl * __fastcall TScpCommanderForm::GetComponent(Byte Component)
  774. {
  775. switch (Component) {
  776. case fcToolBar2: return Toolbar2Toolbar; // name changed to enforce change of default visibility
  777. case fcStatusBar: return StatusBar;
  778. case fcLocalStatusBar: return LocalStatusBar;
  779. case fcRemoteStatusBar: return RemoteStatusBar;
  780. case fcCommandLinePanel: return CommandLineToolbar;
  781. case fcLocalTree: return LocalDriveView;
  782. case fcSessionToolbar: return SessionToolbar;
  783. case fcCustomCommandsBand: return CustomCommandsToolbar;
  784. case fcColorMenu: return reinterpret_cast<TControl*>(ColorMenuItem);
  785. case fcTransferDropDown: return reinterpret_cast<TControl*>(TransferDropDown);
  786. case fcTransferList: return reinterpret_cast<TControl*>(TransferList);
  787. case fcTransferLabel: return reinterpret_cast<TControl*>(TransferLabel);
  788. case fcLocalPopup: return reinterpret_cast<TControl *>(NonVisualDataModule->LocalFilePopup);
  789. case fcRemotePathComboBox: return reinterpret_cast<TControl*>(RemotePathComboBox);
  790. case fcCommanderMenuBand: return MenuToolbar;
  791. case fcCommanderSessionBand: return SessionToolbar;
  792. case fcCommanderPreferencesBand: return PreferencesToolbar;
  793. case fcCommanderSortBand: return SortToolbar;
  794. case fcCommanderCommandsBand: return CommandsToolbar;
  795. case fcCommanderUpdatesBand: return UpdatesToolbar;
  796. case fcCommanderTransferBand: return TransferToolbar;
  797. case fcCommanderCustomCommandsBand: return CustomCommandsToolbar;
  798. case fcCommanderLocalHistoryBand: return LocalHistoryToolbar;
  799. case fcCommanderLocalNavigationBand: return LocalNavigationToolbar;
  800. case fcCommanderLocalFileBand: return LocalFileToolbar;
  801. case fcCommanderLocalSelectionBand: return LocalSelectionToolbar;
  802. case fcCommanderRemoteHistoryBand: return RemoteHistoryToolbar;
  803. case fcCommanderRemoteNavigationBand: return RemoteNavigationToolbar;
  804. case fcCommanderRemoteFileBand: return RemoteFileToolbar;
  805. case fcCommanderRemoteSelectionBand: return RemoteSelectionToolbar;
  806. default: return TCustomScpExplorerForm::GetComponent(Component);
  807. }
  808. }
  809. //---------------------------------------------------------------------------
  810. void __fastcall TScpCommanderForm::FixControlsPlacement()
  811. {
  812. TCustomScpExplorerForm::FixControlsPlacement();
  813. QueueSeparatorPanel->Visible = QueuePanel->Visible;
  814. LocalPanelSplitter->Visible = LocalDriveView->Visible;
  815. TControl * ControlsOrder[] =
  816. { BottomDock, QueueSeparatorPanel, QueueSplitter, QueuePanel, StatusBar };
  817. SetVerticalControlsOrder(ControlsOrder, LENOF(ControlsOrder));
  818. TControl * LocalControlsOrder[] =
  819. { LocalTopDock, LocalPathLabel, LocalDriveView, LocalPanelSplitter,
  820. LocalDirView, LocalBottomDock, LocalStatusBar };
  821. SetVerticalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  822. SetHorizontalControlsOrder(LocalControlsOrder, LENOF(LocalControlsOrder));
  823. TControl * RemoteControlsOrder[] =
  824. { RemoteTopDock, RemotePathLabel, RemoteDriveView, RemotePanelSplitter,
  825. RemoteDirView, RemoteBottomDock, RemoteStatusBar };
  826. SetVerticalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  827. SetHorizontalControlsOrder(RemoteControlsOrder, LENOF(RemoteControlsOrder));
  828. if (LocalDirView->ItemFocused != NULL)
  829. {
  830. LocalDirView->ItemFocused->MakeVisible(false);
  831. }
  832. }
  833. //---------------------------------------------------------------------------
  834. bool __fastcall TScpCommanderForm::GetHasDirView(TOperationSide Side)
  835. {
  836. return TCustomScpExplorerForm::GetHasDirView(Side) || (Side == osLocal);
  837. }
  838. //---------------------------------------------------------------------------
  839. void __fastcall TScpCommanderForm::CompareDirectories()
  840. {
  841. LocalDirView->CompareFiles(RemoteDirView, false,
  842. WinConfiguration->ScpCommander.CompareCriterias());
  843. RemoteDirView->CompareFiles(LocalDirView, false,
  844. WinConfiguration->ScpCommander.CompareCriterias());
  845. if (LocalDirView->SelCount + RemoteDirView->SelCount == 0)
  846. {
  847. MessageDialog(LoadStr(COMPARE_NO_DIFFERENCES), qtInformation, qaOK,
  848. HELP_COMPARE_NO_DIFFERENCES);
  849. }
  850. }
  851. //---------------------------------------------------------------------------
  852. void __fastcall TScpCommanderForm::SynchronizeDirectories()
  853. {
  854. UnicodeString LocalDirectory = LocalDirView->PathName;
  855. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  856. DoSynchronizeDirectories(LocalDirectory, RemoteDirectory, false);
  857. }
  858. //---------------------------------------------------------------------------
  859. void __fastcall TScpCommanderForm::FullSynchronizeDirectories()
  860. {
  861. UnicodeString LocalDirectory = LocalDirView->PathName;
  862. UnicodeString RemoteDirectory = RemoteDirView->PathName;
  863. bool SaveMode = !(GUIConfiguration->SynchronizeModeAuto < 0);
  864. TSynchronizeMode Mode =
  865. (SaveMode ? (TSynchronizeMode)GUIConfiguration->SynchronizeModeAuto :
  866. ((FCurrentSide == osLocal) ? smRemote : smLocal));
  867. if (DoFullSynchronizeDirectories(LocalDirectory, RemoteDirectory, Mode, SaveMode, false) >= 0)
  868. {
  869. if (SaveMode)
  870. {
  871. GUIConfiguration->SynchronizeModeAuto = Mode;
  872. }
  873. }
  874. }
  875. //---------------------------------------------------------------------------
  876. void __fastcall TScpCommanderForm::ExploreLocalDirectory()
  877. {
  878. OpenFolderInExplorer(LocalDirView->Path);
  879. }
  880. //---------------------------------------------------------------------------
  881. void __fastcall TScpCommanderForm::LocalDirViewExecFile(TObject *Sender,
  882. TListItem *Item, bool &AllowExec)
  883. {
  884. DebugAssert(Item);
  885. if ((UpperCase(PFileRec(Item->Data)->FileExt) == L"LNK") &&
  886. DirectoryExists(ApiPath(ResolveFileShortCut(LocalDirView->ItemFullFileName(Item), true))))
  887. {
  888. AllowExec = true;
  889. }
  890. else
  891. {
  892. DoDirViewExecFile(Sender, Item, AllowExec);
  893. }
  894. }
  895. //---------------------------------------------------------------------------
  896. void __fastcall TScpCommanderForm::LocalFileControlDDDragEnter(TObject *Sender,
  897. IDataObject *DataObj, int grfKeyState, TPoint &Point, int &dwEffect,
  898. bool &Accept)
  899. {
  900. // LocalDirViewDDDragEnter is duplication of
  901. // TCustomScpExplorerForm::DirViewDDDragEnter, but it differs in
  902. // literal type of 'DataObj' parameter.Actual type is however same
  903. FileControlDDDragEnter(Sender, DataObj, grfKeyState, Point, dwEffect, Accept);
  904. }
  905. //---------------------------------------------------------------------------
  906. bool __fastcall TScpCommanderForm::PanelOperation(TOperationSide Side,
  907. bool DragDrop)
  908. {
  909. return TCustomScpExplorerForm::PanelOperation(Side, DragDrop) ||
  910. (DropSourceControl == LocalDirView);
  911. }
  912. //---------------------------------------------------------------------------
  913. void __fastcall TScpCommanderForm::FileOperationProgress(
  914. TFileOperationProgressType & ProgressData)
  915. {
  916. // Heuristic: When operation finishes and DD targed is local dir view,
  917. // we suppose that drag&drop download finished, so local dir view should be
  918. // reloaded
  919. if (!ProgressData.InProgress && FProgressForm &&
  920. IsFileControl(FDDTargetControl, osLocal) &&
  921. ((ProgressData.Operation == ::foCopy) || (ProgressData.Operation == ::foMove)))
  922. {
  923. ReloadLocalDirectory();
  924. }
  925. TCustomScpExplorerForm::FileOperationProgress(ProgressData);
  926. }
  927. //---------------------------------------------------------------------------
  928. UnicodeString __fastcall TScpCommanderForm::ChangeFilePath(UnicodeString Path, TOperationSide Side)
  929. {
  930. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  931. UnicodeString Result;
  932. while (!Path.IsEmpty())
  933. {
  934. int P = Path.Pos(Side == osLocal ? L'\\' : L'/');
  935. if (P > 0)
  936. {
  937. Result += Terminal->ChangeFileName(&CopyParams, Path.SubString(1, P - 1), Side, false) +
  938. (Side == osLocal ? L'/' : L'\\');
  939. Path.Delete(1, P);
  940. }
  941. else
  942. {
  943. Result += Terminal->ChangeFileName(&CopyParams, Path, osLocal, false);
  944. Path = L"";
  945. }
  946. }
  947. return Result;
  948. }
  949. //---------------------------------------------------------------------------
  950. void __fastcall TScpCommanderForm::CreateRemoteDirectory(const UnicodeString & Path)
  951. {
  952. UnicodeString Dir = UnixExtractFileDir(Path);
  953. if (!IsUnixRootPath(Dir) && !Terminal->FileExists(Dir))
  954. {
  955. CreateRemoteDirectory(Dir);
  956. }
  957. TRemoteProperties Properties = GUIConfiguration->NewDirectoryProperties;
  958. TCustomScpExplorerForm::CreateRemoteDirectory(Path, Properties);
  959. }
  960. //---------------------------------------------------------------------------
  961. void __fastcall TScpCommanderForm::SynchronizeBrowsingLocal(
  962. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  963. {
  964. Terminal->ExceptionOnFail = true;
  965. TStrings * Paths = new TStringList();
  966. try
  967. {
  968. Paths->Add(IncludeTrailingBackslash(PrevPath));
  969. Paths->Add(IncludeTrailingBackslash(LocalDirView->Path));
  970. UnicodeString CommonPath;
  971. if (ExtractCommonPath(Paths, CommonPath))
  972. {
  973. PrevPath = IncludeTrailingBackslash(PrevPath);
  974. CommonPath = IncludeTrailingBackslash(CommonPath);
  975. NewPath = RemoteDirView->Path;
  976. while (!SamePaths(PrevPath, CommonPath))
  977. {
  978. if (NewPath == UnixExcludeTrailingBackslash(NewPath))
  979. {
  980. Abort();
  981. }
  982. NewPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(NewPath));
  983. PrevPath = ExtractFilePath(ExcludeTrailingBackslash(PrevPath));
  984. }
  985. NewPath = UnixIncludeTrailingBackslash(NewPath) +
  986. ToUnixPath(LocalDirView->Path.SubString(PrevPath.Length() + 1,
  987. LocalDirView->Path.Length() - PrevPath.Length()));
  988. }
  989. else
  990. {
  991. Abort();
  992. }
  993. if (Create)
  994. {
  995. CreateRemoteDirectory(UnixExcludeTrailingBackslash(NewPath));
  996. }
  997. RemoteDirView->Path = NewPath;
  998. }
  999. __finally
  1000. {
  1001. Terminal->ExceptionOnFail = false;
  1002. delete Paths;
  1003. }
  1004. }
  1005. //---------------------------------------------------------------------------
  1006. void __fastcall TScpCommanderForm::CreateLocalDirectory(const UnicodeString & Path)
  1007. {
  1008. UnicodeString Dir = ExtractFileDir(Path);
  1009. if (!Dir.IsEmpty() && !DirectoryExists(Dir))
  1010. {
  1011. CreateLocalDirectory(Dir);
  1012. }
  1013. LocalDirView->CreateDirectory(Path);
  1014. }
  1015. //---------------------------------------------------------------------------
  1016. void __fastcall TScpCommanderForm::SynchronizeBrowsingRemote(
  1017. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1018. {
  1019. TStrings * Paths = new TStringList();
  1020. try
  1021. {
  1022. Paths->Add(UnixIncludeTrailingBackslash(PrevPath));
  1023. Paths->Add(UnixIncludeTrailingBackslash(RemoteDirView->Path));
  1024. UnicodeString CommonPath;
  1025. if (UnixExtractCommonPath(Paths, CommonPath))
  1026. {
  1027. PrevPath = UnixIncludeTrailingBackslash(PrevPath);
  1028. CommonPath = UnixIncludeTrailingBackslash(CommonPath);
  1029. UnicodeString NewLocalPath;
  1030. NewPath = ExcludeTrailingBackslash(LocalDirView->Path);
  1031. while (!UnixSamePath(PrevPath, CommonPath))
  1032. {
  1033. NewLocalPath = ExcludeTrailingBackslash(ExtractFileDir(NewPath));
  1034. if (NewLocalPath == NewPath)
  1035. {
  1036. Abort();
  1037. }
  1038. NewPath = NewLocalPath;
  1039. PrevPath = UnixExtractFilePath(UnixExcludeTrailingBackslash(PrevPath));
  1040. }
  1041. NewPath = IncludeTrailingBackslash(NewPath) +
  1042. ChangeFilePath(
  1043. RemoteDirView->Path.SubString(PrevPath.Length() + 1,
  1044. RemoteDirView->Path.Length() - PrevPath.Length()),
  1045. osRemote);
  1046. }
  1047. else
  1048. {
  1049. Abort();
  1050. }
  1051. }
  1052. __finally
  1053. {
  1054. delete Paths;
  1055. }
  1056. if (Create)
  1057. {
  1058. CreateLocalDirectory(ExcludeTrailingBackslash(NewPath));
  1059. }
  1060. LocalDirView->Path = NewPath;
  1061. }
  1062. //---------------------------------------------------------------------------
  1063. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView,
  1064. UnicodeString PrevPath, UnicodeString & NewPath, bool Create)
  1065. {
  1066. if (ADirView == LocalDirView)
  1067. {
  1068. SynchronizeBrowsingLocal(PrevPath, NewPath, Create);
  1069. }
  1070. else
  1071. {
  1072. SynchronizeBrowsingRemote(PrevPath, NewPath, Create);
  1073. }
  1074. }
  1075. //---------------------------------------------------------------------------
  1076. void __fastcall TScpCommanderForm::SynchronizeBrowsing(TCustomDirView * ADirView)
  1077. {
  1078. UnicodeString PrevPath;
  1079. // cannot assign to UnicodeString before the class is constructed,
  1080. // if we do, the value get lost when UnicodeString constructor gets finally called,
  1081. // what results in memory leak in the best case
  1082. if (FConstructed)
  1083. {
  1084. PrevPath = FPrevPath[ADirView == LocalDirView];
  1085. FPrevPath[ADirView == LocalDirView] = ADirView->Path;
  1086. }
  1087. if (!FSynchronisingBrowse && NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1088. !PrevPath.IsEmpty() && PrevPath != ADirView->Path)
  1089. {
  1090. TValueRestorer<bool> AllowTransferPresetAutoSelectRestorer(FAllowTransferPresetAutoSelect);
  1091. FAllowTransferPresetAutoSelect = false;
  1092. TValueRestorer<bool> SynchronisingBrowseRestorer(FSynchronisingBrowse);
  1093. FSynchronisingBrowse = true;
  1094. try
  1095. {
  1096. UnicodeString NewPath;
  1097. bool Error = false;
  1098. std::unique_ptr<TStrings> ErrorMoreMessages;
  1099. UnicodeString ErrorHelpKeyword;
  1100. try
  1101. {
  1102. SynchronizeBrowsing(ADirView, PrevPath, NewPath, false);
  1103. }
  1104. // EAbort means that we do not know how to synchronize browsing
  1105. // there's no fallback scenario for that
  1106. catch(EAbort &)
  1107. {
  1108. throw;
  1109. }
  1110. catch(Exception & E)
  1111. {
  1112. // what does this say?
  1113. if (Application->Terminated)
  1114. {
  1115. throw;
  1116. }
  1117. else
  1118. {
  1119. Error = true;
  1120. ErrorMoreMessages.reset(ExceptionToMoreMessages(&E));
  1121. ErrorHelpKeyword =
  1122. MergeHelpKeyword(HELP_SYNC_DIR_BROWSE_ERROR, GetExceptionHelpKeyword(&E));
  1123. }
  1124. }
  1125. // this was moved here out of the above catch clause,
  1126. // to avoid deep nesting, what seems to cause some stray access violations
  1127. if (Error)
  1128. {
  1129. if (MoreMessageDialog(FMTLOAD(SYNC_DIR_BROWSE_CREATE2, (NewPath)),
  1130. ErrorMoreMessages.get(), qtConfirmation, qaYes | qaNo,
  1131. ErrorHelpKeyword) == qaYes)
  1132. {
  1133. try
  1134. {
  1135. SynchronizeBrowsing(ADirView, PrevPath, NewPath, true);
  1136. }
  1137. catch(Exception & E)
  1138. {
  1139. if (!Application->Terminated)
  1140. {
  1141. Terminal->ShowExtendedException(&E);
  1142. }
  1143. throw;
  1144. }
  1145. }
  1146. else
  1147. {
  1148. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1149. }
  1150. }
  1151. }
  1152. catch(Exception & E)
  1153. {
  1154. NonVisualDataModule->SynchronizeBrowsingAction->Checked = false;
  1155. // what does this say?
  1156. if (Application->Terminated)
  1157. {
  1158. throw;
  1159. }
  1160. else
  1161. {
  1162. MessageDialog(LoadStr(SYNC_DIR_BROWSE_ERROR), qtInformation, qaOK,
  1163. HELP_SYNC_DIR_BROWSE_ERROR);
  1164. }
  1165. }
  1166. // note the value restorers at the beginning of this block
  1167. }
  1168. }
  1169. //---------------------------------------------------------------------------
  1170. void __fastcall TScpCommanderForm::DoDirViewLoaded(TCustomDirView * ADirView)
  1171. {
  1172. TCustomScpExplorerForm::DoDirViewLoaded(ADirView);
  1173. UpdateControls();
  1174. SynchronizeBrowsing(ADirView);
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. void __fastcall TScpCommanderForm::AddEditLink(TOperationSide Side, bool Add)
  1178. {
  1179. if (GetSide(Side) == osLocal)
  1180. {
  1181. bool Edit = false;
  1182. UnicodeString FileName;
  1183. UnicodeString PointTo;
  1184. bool SymbolicLink = true;
  1185. if (LocalDirView->ItemFocused)
  1186. {
  1187. DebugAssert(LocalDirView->ItemFocused->Data);
  1188. PFileRec FileRec = (PFileRec)LocalDirView->ItemFocused->Data;
  1189. Edit = !Add && (UpperCase(FileRec->FileExt) == L"LNK");
  1190. if (Edit)
  1191. {
  1192. UnicodeString FullName = LocalDirView->ItemFullFileName(LocalDirView->ItemFocused);
  1193. FileName = FullName;
  1194. PointTo = ResolveFileShortCut(FullName, false);
  1195. if (PointTo.IsEmpty())
  1196. {
  1197. throw Exception(FMTLOAD(RESOLVE_SHORTCUT_ERROR, (FullName)));
  1198. }
  1199. }
  1200. else
  1201. {
  1202. PointTo = FileRec->FileName;
  1203. }
  1204. }
  1205. if (DoSymlinkDialog(FileName, PointTo, osLocal, SymbolicLink, Edit, false))
  1206. {
  1207. Configuration->Usage->Inc(L"LocalShortcutsCreated");
  1208. DebugAssert(SymbolicLink);
  1209. DebugAssert(!FileName.IsEmpty());
  1210. DebugAssert(!PointTo.IsEmpty());
  1211. if (ExtractFileDrive(FileName) == L"" && FileName[1] != L'\\')
  1212. {
  1213. FileName = IncludeTrailingBackslash(LocalDirView->PathName) + FileName;
  1214. }
  1215. if (ExtractFileDrive(PointTo) == L"" && PointTo[1] != L'\\')
  1216. {
  1217. PointTo = IncludeTrailingBackslash(LocalDirView->PathName) + PointTo;
  1218. }
  1219. if (ExtractFileExt(FileName) == L"")
  1220. {
  1221. FileName = FileName + L".lnk";
  1222. }
  1223. if (Edit)
  1224. {
  1225. DeleteFileChecked(FileName);
  1226. }
  1227. if (!CreateFileShortCut(PointTo, FileName, L""))
  1228. {
  1229. throw Exception(CREATE_SHORTCUT_ERROR);
  1230. }
  1231. }
  1232. }
  1233. else
  1234. {
  1235. TCustomScpExplorerForm::AddEditLink(Side, Add);
  1236. }
  1237. }
  1238. //---------------------------------------------------------------------------
  1239. void __fastcall TScpCommanderForm::DoOpenDirectoryDialog(TOpenDirectoryMode Mode,
  1240. TOperationSide Side)
  1241. {
  1242. bool UseLocationProfiles;
  1243. do
  1244. {
  1245. UseLocationProfiles = WinConfiguration->UseLocationProfiles;
  1246. // Location profiles dialog is not ready to be run without terminal
  1247. if (UseLocationProfiles && (Terminal != NULL))
  1248. {
  1249. TStrings * LocalDirectories = NULL;
  1250. TStrings * RemoteDirectories = NULL;
  1251. try
  1252. {
  1253. LocalDirectories = CreateVisitedDirectories(osLocal);
  1254. RemoteDirectories = CreateVisitedDirectories(osRemote);
  1255. UnicodeString Local = LocalDirView->PathName;
  1256. UnicodeString Remote = RemoteDirView->PathName;
  1257. if (LocationProfilesDialog(Mode, Side, Local, Remote, LocalDirectories,
  1258. RemoteDirectories, Terminal))
  1259. {
  1260. DoOpenBookmark(Local, Remote);
  1261. }
  1262. }
  1263. __finally
  1264. {
  1265. delete LocalDirectories;
  1266. delete RemoteDirectories;
  1267. }
  1268. }
  1269. else
  1270. {
  1271. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1272. TCustomScpExplorerForm::DoOpenDirectoryDialog(Mode, Side);
  1273. }
  1274. // for second and further rounds, always do browse only
  1275. Mode = odBrowse;
  1276. }
  1277. while (UseLocationProfiles != WinConfiguration->UseLocationProfiles);
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. void __fastcall TScpCommanderForm::DoOpenBookmark(UnicodeString Local, UnicodeString Remote)
  1281. {
  1282. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1283. // make sure that whatever path is valid it is opened first and only
  1284. // after that an eventual error is reported
  1285. try
  1286. {
  1287. if (!Local.IsEmpty())
  1288. {
  1289. LocalDirView->Path = Local;
  1290. }
  1291. }
  1292. __finally
  1293. {
  1294. if (!Remote.IsEmpty())
  1295. {
  1296. // While we might get here when the session is closed (from location profiles),
  1297. // it's not a problem as the Path setter is noop then
  1298. RemoteDirView->Path = Remote;
  1299. }
  1300. }
  1301. }
  1302. //---------------------------------------------------------------------------
  1303. bool __fastcall TScpCommanderForm::OpenBookmark(TOperationSide Side, TBookmark * Bookmark)
  1304. {
  1305. bool Result;
  1306. if (WinConfiguration->UseLocationProfiles)
  1307. {
  1308. DoOpenBookmark(Bookmark->Local, Bookmark->Remote);
  1309. Result = true;
  1310. }
  1311. else
  1312. {
  1313. Result = TCustomScpExplorerForm::OpenBookmark(Side, Bookmark);
  1314. }
  1315. return Result;
  1316. }
  1317. //---------------------------------------------------------------------------
  1318. void __fastcall TScpCommanderForm::LocalDirViewDDTargetHasDropHandler(
  1319. TObject * /*Sender*/, TListItem * Item, int & /*Effect*/, bool & DropHandler)
  1320. {
  1321. // When drop target is not directory, it is probably file type, which have
  1322. // associated drop handler (such as EXE file). In this case we
  1323. // cannot allow drop when when using shellex,
  1324. // as drop handlers are disabled, so drop would error
  1325. // (see TShellExtension.DropHandler assignment in ConfigurationChanged),
  1326. if (WinConfiguration->DDFakeFile &&
  1327. !LocalDirView->ItemIsDirectory(Item))
  1328. {
  1329. DropHandler = false;
  1330. }
  1331. }
  1332. //---------------------------------------------------------------------------
  1333. void __fastcall TScpCommanderForm::LocalFileControlDDDragOver(TObject * /*Sender*/,
  1334. int grfKeyState, TPoint & /*Point*/, int & dwEffect)
  1335. {
  1336. if (IsFileControl(DropSourceControl, osRemote))
  1337. {
  1338. if (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == 0) ||
  1339. (((grfKeyState & (MK_CONTROL | MK_SHIFT)) == MK_SHIFT) &&
  1340. !WinConfiguration->DDAllowMoveInit))
  1341. {
  1342. dwEffect = DROPEFFECT_Copy;
  1343. }
  1344. }
  1345. }
  1346. //---------------------------------------------------------------------------
  1347. bool __fastcall TScpCommanderForm::DDGetTarget(
  1348. UnicodeString & Directory, bool & ForceQueue, UnicodeString & CounterName)
  1349. {
  1350. bool Result;
  1351. if (!FDDFakeFileTarget.IsEmpty())
  1352. {
  1353. Directory = FDDFakeFileTarget;
  1354. FDDFakeFileTarget = L"";
  1355. Result = true;
  1356. CounterName = L"DownloadsDragDropInternal";
  1357. ForceQueue = false;
  1358. }
  1359. else
  1360. {
  1361. Result = TCustomScpExplorerForm::DDGetTarget(Directory, ForceQueue, CounterName);
  1362. }
  1363. return Result;
  1364. }
  1365. //---------------------------------------------------------------------------
  1366. void __fastcall TScpCommanderForm::DDFakeFileInitDrag(TFileList * FileList,
  1367. bool & Created)
  1368. {
  1369. FDDFakeFileTarget = L"";
  1370. TCustomScpExplorerForm::DDFakeFileInitDrag(FileList, Created);
  1371. }
  1372. //---------------------------------------------------------------------------
  1373. void __fastcall TScpCommanderForm::LocalFileControlDDFileOperation(
  1374. TObject * /*Sender*/, int dwEffect, UnicodeString SourcePath,
  1375. UnicodeString TargetPath, bool & DoOperation)
  1376. {
  1377. if (IsFileControl(DropSourceControl, osRemote))
  1378. {
  1379. UnicodeString TargetDirectory;
  1380. if (InternalDDDownload(TargetDirectory))
  1381. {
  1382. // See TCustomScpExplorerForm::QueueDDProcessDropped
  1383. if (FDDExtMapFile != NULL)
  1384. {
  1385. FDDFakeFileTarget = TargetDirectory;
  1386. }
  1387. else
  1388. {
  1389. DebugAssert(FInternalDDDownloadList->Count > 0);
  1390. DebugAssert(dwEffect == DROPEFFECT_Copy || dwEffect == DROPEFFECT_Move);
  1391. TGUICopyParamType CopyParams = GUIConfiguration->CurrentCopyParam;
  1392. TTransferType TransferType = dwEffect == DROPEFFECT_Copy ? ttCopy : ttMove;
  1393. if (FDDMoveSlipped)
  1394. {
  1395. TransferType = ttMove;
  1396. }
  1397. int Options =
  1398. FLAGMASK(DraggingAllFilesFromDirView(osRemote, FInternalDDDownloadList), coAllFiles);
  1399. if (CopyParamDialog(tdToLocal, TransferType,
  1400. false, FInternalDDDownloadList, TargetDirectory, CopyParams,
  1401. (WinConfiguration->DDTransferConfirmation != asOff), true, Options))
  1402. {
  1403. int Params =
  1404. (TransferType == ttMove ? cpDelete : 0);
  1405. DDDownload(FInternalDDDownloadList, TargetDirectory,
  1406. &CopyParams, Params);
  1407. Configuration->Usage->Inc(L"DownloadsDragDropInternal");
  1408. FInternalDDDownloadList->Clear();
  1409. }
  1410. }
  1411. DoOperation = false;
  1412. }
  1413. }
  1414. }
  1415. //---------------------------------------------------------------------------
  1416. void __fastcall TScpCommanderForm::RemoteFileControlDDFileOperationExecuted(
  1417. TObject * /*Sender*/, int dwEffect, UnicodeString /*SourcePath*/,
  1418. UnicodeString /*TargetPath*/)
  1419. {
  1420. if ((dwEffect == DROPEFFECT_Move) &&
  1421. IsFileControl(DropSourceControl, osLocal))
  1422. {
  1423. ReloadLocalDirectory();
  1424. }
  1425. }
  1426. //---------------------------------------------------------------------------
  1427. void __fastcall TScpCommanderForm::LocalDirViewEnter(TObject * /*Sender*/)
  1428. {
  1429. SideEnter(osLocal);
  1430. }
  1431. //---------------------------------------------------------------------------
  1432. void __fastcall TScpCommanderForm::LocalDriveViewEnter(TObject * /*Sender*/)
  1433. {
  1434. MakeNextInTabOrder(LocalDirView, LocalDriveView);
  1435. SideEnter(osLocal);
  1436. }
  1437. //---------------------------------------------------------------------------
  1438. void __fastcall TScpCommanderForm::SideEnter(TOperationSide Side)
  1439. {
  1440. if (Visible && (FCurrentSide != Side))
  1441. {
  1442. // this may get called yet before controls are initialized
  1443. CommandLineCombo->Strings->Clear();
  1444. FCommandLineComboPopulated = false;
  1445. }
  1446. TCustomScpExplorerForm::SideEnter(Side);
  1447. if (Visible)
  1448. {
  1449. UpdateControls();
  1450. UpdatePanelsPathLabelsStatus();
  1451. }
  1452. }
  1453. //---------------------------------------------------------------------------
  1454. void __fastcall TScpCommanderForm::UpdatePanelsPathLabelsStatus()
  1455. {
  1456. LocalPathLabel->UpdateStatus();
  1457. RemotePathLabel->UpdateStatus();
  1458. }
  1459. //---------------------------------------------------------------------------
  1460. void __fastcall TScpCommanderForm::OpenConsole(UnicodeString Command)
  1461. {
  1462. SaveCommandLine();
  1463. try
  1464. {
  1465. TCustomScpExplorerForm::OpenConsole(Command);
  1466. }
  1467. __finally
  1468. {
  1469. FCommandLineComboPopulated = false;
  1470. }
  1471. }
  1472. //---------------------------------------------------------------------------
  1473. void __fastcall TScpCommanderForm::SaveCommandLine()
  1474. {
  1475. if (FCommandLineComboPopulated)
  1476. {
  1477. CustomWinConfiguration->History[
  1478. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"] =
  1479. CommandLineCombo->Strings;
  1480. }
  1481. }
  1482. //---------------------------------------------------------------------------
  1483. bool __fastcall TScpCommanderForm::ExecuteCommandLine()
  1484. {
  1485. UnicodeString Command = CommandLineCombo->Text;
  1486. bool Result =
  1487. !NonVisualDataModule->Busy &&
  1488. !Command.IsEmpty() &&
  1489. ((FCurrentSide != osRemote) ||
  1490. (Terminal->AllowedAnyCommand(Command) &&
  1491. EnsureCommandSessionFallback(fcAnyCommand)));
  1492. if (Result)
  1493. {
  1494. CommandLinePopulate();
  1495. SaveToHistory(CommandLineCombo->Strings, Command);
  1496. CommandLineCombo->Text = L"";
  1497. if (FCurrentSide == osRemote)
  1498. {
  1499. OpenConsole(Command);
  1500. }
  1501. else
  1502. {
  1503. ExecuteShellChecked(Command);
  1504. }
  1505. }
  1506. return Result;
  1507. }
  1508. //---------------------------------------------------------------------------
  1509. void __fastcall TScpCommanderForm::CommandLinePopulate()
  1510. {
  1511. if (!FCommandLineComboPopulated)
  1512. {
  1513. TStrings * CommandsHistory;
  1514. CommandsHistory = CustomWinConfiguration->History[
  1515. FCurrentSide == osRemote ? L"Commands" : L"LocalCommands"];
  1516. if ((CommandsHistory != NULL) && (CommandsHistory->Count > 0))
  1517. {
  1518. CommandLineCombo->Strings = CommandsHistory;
  1519. }
  1520. else
  1521. {
  1522. CommandLineCombo->Strings->Clear();
  1523. }
  1524. FCommandLineComboPopulated = true;
  1525. }
  1526. }
  1527. //---------------------------------------------------------------------------
  1528. void __fastcall TScpCommanderForm::GoToCommandLine()
  1529. {
  1530. ComponentVisible[fcCommandLinePanel] = true;
  1531. if (CommandLineCombo->Enabled)
  1532. {
  1533. ClickToolbarItem(CommandLineCombo, true);
  1534. }
  1535. }
  1536. //---------------------------------------------------------------------------
  1537. void __fastcall TScpCommanderForm::GoToTree()
  1538. {
  1539. if (FCurrentSide == osLocal)
  1540. {
  1541. ComponentVisible[fcLocalTree] = true;
  1542. LocalDriveView->SetFocus();
  1543. }
  1544. else
  1545. {
  1546. TCustomScpExplorerForm::GoToTree();
  1547. }
  1548. }
  1549. //---------------------------------------------------------------------------
  1550. void __fastcall TScpCommanderForm::PanelExportStore(TOperationSide Side,
  1551. TPanelExport Export, TPanelExportDestination Destination,
  1552. TStrings * ExportData)
  1553. {
  1554. if (Destination == pedCommandLine)
  1555. {
  1556. ComponentVisible[fcCommandLinePanel] = true;
  1557. UnicodeString Buf;
  1558. for (int Index = 0; Index < ExportData->Count; Index++)
  1559. {
  1560. Buf += ExportData->Strings[Index] + L" ";
  1561. }
  1562. CommandLineCombo->Text = CommandLineCombo->Text + Buf;
  1563. }
  1564. else
  1565. {
  1566. TCustomScpExplorerForm::PanelExportStore(Side, Export, Destination, ExportData);
  1567. }
  1568. }
  1569. //---------------------------------------------------------------------------
  1570. int __fastcall TScpCommanderForm::GetStaticComponentsHeight()
  1571. {
  1572. return TCustomScpExplorerForm::GetStaticComponentsHeight() +
  1573. (BottomDock->Visible ? BottomDock->Height : 0) +
  1574. (QueueSeparatorPanel->Visible ? QueueSeparatorPanel->Height : 0) +
  1575. (StatusBar->Visible ? StatusBar->Height : 0);
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. void __fastcall TScpCommanderForm::SysResizing(unsigned int Cmd)
  1579. {
  1580. TCustomScpExplorerForm::SysResizing(Cmd);
  1581. if ((Cmd == SC_MAXIMIZE) ||
  1582. ((Cmd == SC_DEFAULT) && (WindowState != wsMaximized)))
  1583. {
  1584. FNormalPanelsWidth = LocalPanel->Width + RemotePanel->Width;
  1585. }
  1586. else if ((Cmd == SC_RESTORE) ||
  1587. ((Cmd == SC_DEFAULT) && (WindowState == wsMaximized)))
  1588. {
  1589. if (FNormalPanelsWidth >= 0)
  1590. {
  1591. Panel(true)->Width = static_cast<int>(FLeftPanelWidth * FNormalPanelsWidth);
  1592. FNormalPanelsWidth = -1;
  1593. }
  1594. }
  1595. }
  1596. //---------------------------------------------------------------------------
  1597. void __fastcall TScpCommanderForm::Resize()
  1598. {
  1599. TCustomScpExplorerForm::Resize();
  1600. LeftPanelWidth = FLastLeftPanelWidth;
  1601. UpdateControls();
  1602. }
  1603. //---------------------------------------------------------------------------
  1604. void __fastcall TScpCommanderForm::LocalFileControlDDMenuPopup(TObject * /*Sender*/,
  1605. HMENU AMenu, IDataObject * /*DataObj*/, int /*AMinCustCmd*/, int /*grfKeyState*/,
  1606. TPoint & /*pt*/)
  1607. {
  1608. if (IsFileControl(DropSourceControl, osRemote) &&
  1609. !WinConfiguration->DDAllowMoveInit)
  1610. {
  1611. // index of copy item
  1612. int Index = GetMenuDefaultItem(AMenu, TRUE, 0);
  1613. DebugAssert(Index >= 0);
  1614. UnicodeString Caption = Dragdrop_MIMoveStr;
  1615. MENUITEMINFO MI;
  1616. memset(&MI, 0, sizeof(MI));
  1617. MI.cbSize = sizeof(MI);
  1618. MI.fMask = MIIM_TYPE | MIIM_ID | MIIM_STATE;
  1619. MI.fType = MFT_STRING;
  1620. MI.wID = 1 /*DragDrop::CmdMove*/;
  1621. MI.dwTypeData = Caption.c_str();
  1622. MI.cch = Caption.Length();
  1623. MI.fState = MFS_ENABLED;
  1624. InsertMenuItem(AMenu, Index, TRUE, &MI);
  1625. if (FDDMoveSlipped)
  1626. {
  1627. SetMenuDefaultItem(AMenu, Index, TRUE);
  1628. }
  1629. FDDMoveSlipped = false;
  1630. }
  1631. }
  1632. //---------------------------------------------------------------------------
  1633. void __fastcall TScpCommanderForm::PathLabelDblClick(TObject * Sender)
  1634. {
  1635. OpenDirectory(Sender == LocalPathLabel ? osLocal : osRemote);
  1636. }
  1637. //---------------------------------------------------------------------------
  1638. void __fastcall TScpCommanderForm::LocalPathLabelGetStatus(
  1639. TCustomPathLabel * /*Sender*/, bool & Active)
  1640. {
  1641. // WORKAROUND this strange form is here to make borland compiler work :-)
  1642. Active = Active || LocalDriveView->Focused();
  1643. }
  1644. //---------------------------------------------------------------------------
  1645. void __fastcall TScpCommanderForm::RemotePathLabelGetStatus(
  1646. TCustomPathLabel * /*Sender*/, bool & Active)
  1647. {
  1648. // WORKAROUND this strange form is here to make borland compiler work :-)
  1649. Active = Active || RemoteDriveView->Focused();
  1650. }
  1651. //---------------------------------------------------------------------------
  1652. void __fastcall TScpCommanderForm::LocalPathLabelPathClick(
  1653. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1654. {
  1655. if (SamePaths(Path, LocalDirView->Path))
  1656. {
  1657. OpenDirectory(osLocal);
  1658. }
  1659. else
  1660. {
  1661. LocalDirView->Path = Path;
  1662. }
  1663. }
  1664. //---------------------------------------------------------------------------
  1665. void __fastcall TScpCommanderForm::RemotePathLabelPathClick(
  1666. TCustomPathLabel * /*Sender*/, UnicodeString Path)
  1667. {
  1668. if (UnixSamePath(Path, RemoteDirView->Path))
  1669. {
  1670. OpenDirectory(osRemote);
  1671. }
  1672. else
  1673. {
  1674. RemoteDirView->Path = Path;
  1675. }
  1676. }
  1677. //---------------------------------------------------------------------------
  1678. void __fastcall TScpCommanderForm::LocalDirViewFileIconForName(
  1679. TObject * /*Sender*/, TListItem * /*Item*/, UnicodeString & FileName)
  1680. {
  1681. UnicodeString PartialExt = Configuration->PartialExt;
  1682. if (AnsiSameText(ExtractFileExt(FileName), PartialExt))
  1683. {
  1684. FileName.SetLength(FileName.Length() - PartialExt.Length());
  1685. }
  1686. if (WinConfiguration->LocalIconsByExt)
  1687. {
  1688. FileName = ExtractFileName(FileName);
  1689. }
  1690. }
  1691. //---------------------------------------------------------------------------
  1692. void __fastcall TScpCommanderForm::LocalDirViewUpdateStatusBar(
  1693. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1694. {
  1695. UpdateFileStatusBar(LocalStatusBar, FileInfo, osLocal);
  1696. }
  1697. //---------------------------------------------------------------------------
  1698. void __fastcall TScpCommanderForm::RemoteDirViewUpdateStatusBar(
  1699. TObject * /*Sender*/, const TStatusFileInfo & FileInfo)
  1700. {
  1701. UpdateFileStatusBar(RemoteStatusBar, FileInfo, osRemote);
  1702. }
  1703. //---------------------------------------------------------------------------
  1704. void __fastcall TScpCommanderForm::LocalStatusBarClick(TObject * /*Sender*/)
  1705. {
  1706. LocalDirView->SetFocus();
  1707. }
  1708. //---------------------------------------------------------------------------
  1709. UnicodeString __fastcall TScpCommanderForm::PathForCaption()
  1710. {
  1711. UnicodeString Result;
  1712. if (FCurrentSide == osLocal)
  1713. {
  1714. // for consistency do not show even local path when there is no terminal
  1715. if (Terminal != NULL)
  1716. {
  1717. switch (WinConfiguration->PathInCaption)
  1718. {
  1719. case picShort:
  1720. {
  1721. Result = ExtractFileName(LocalDirView->PathName);
  1722. if (Result.IsEmpty())
  1723. {
  1724. Result = LocalDirView->PathName;
  1725. }
  1726. }
  1727. break;
  1728. case picFull:
  1729. Result = LocalDirView->PathName;
  1730. break;
  1731. }
  1732. }
  1733. }
  1734. else
  1735. {
  1736. Result = TCustomScpExplorerForm::PathForCaption();
  1737. }
  1738. return Result;
  1739. }
  1740. //---------------------------------------------------------------------------
  1741. void __fastcall TScpCommanderForm::GetTransferPresetAutoSelectData(
  1742. TCopyParamRuleData & Data)
  1743. {
  1744. TCustomScpExplorerForm::GetTransferPresetAutoSelectData(Data);
  1745. Data.LocalDirectory = LocalDirView->PathName;
  1746. }
  1747. //---------------------------------------------------------------------------
  1748. void __fastcall TScpCommanderForm::BeforeAction()
  1749. {
  1750. TCustomScpExplorerForm::BeforeAction();
  1751. if (LocalDirView->ItemFocused != NULL)
  1752. {
  1753. LocalDirView->ItemFocused->CancelEdit();
  1754. }
  1755. }
  1756. //---------------------------------------------------------------------------
  1757. void __fastcall TScpCommanderForm::RemoteDirViewPathChange(TCustomDirView * /*Sender*/)
  1758. {
  1759. UpdateRemotePathComboBox(false);
  1760. }
  1761. //---------------------------------------------------------------------------
  1762. void __fastcall TScpCommanderForm::UpdateImages()
  1763. {
  1764. TCustomScpExplorerForm::UpdateImages();
  1765. TImageList * ImageList = ShellImageListForControl(this, ilsSmall);
  1766. RemotePathComboBox->Images = ImageList;
  1767. RemotePathComboBox->SubMenuImages = ImageList;
  1768. LocalPathComboBox->Images = ImageList;
  1769. LocalPathComboBox->SubMenuImages = ImageList;
  1770. }
  1771. //---------------------------------------------------------------------------
  1772. void __fastcall TScpCommanderForm::LocalPathComboUpdateDrives()
  1773. {
  1774. FLocalSpecialPaths = 0;
  1775. TStrings* Strings = LocalPathComboBox->Strings;
  1776. Strings->BeginUpdate();
  1777. try
  1778. {
  1779. Strings->Clear();
  1780. FLocalPathComboBoxPaths->Clear();
  1781. Strings->Add(LoadStr(SPECIAL_FOLDER_MY_DOCUMENTS));
  1782. FLocalPathComboBoxPaths->AddObject(GetPersonalFolder(),
  1783. (TObject *)DriveInfo->SpecialFolder[CSIDL_PERSONAL]->ImageIndex);
  1784. FLocalSpecialPaths++;
  1785. Strings->Add(LoadStr(SPECIAL_FOLDER_DESKTOP));
  1786. FLocalPathComboBoxPaths->AddObject(GetDesktopFolder(),
  1787. (TObject *)DriveInfo->SpecialFolder[CSIDL_DESKTOP]->ImageIndex);
  1788. FLocalSpecialPaths++;
  1789. std::unique_ptr<TStrings> Drives(LocalDriveView->GetDrives());
  1790. for (int Index = 0; Index < Drives->Count; Index++)
  1791. {
  1792. UnicodeString Drive = Drives->Strings[Index];
  1793. if (DriveInfo->Get(Drive)->Valid)
  1794. {
  1795. UnicodeString Caption = DriveInfo->GetPrettyName(Drive);
  1796. if (DriveInfo->IsRealDrive(Drive))
  1797. {
  1798. Caption.Insert(L"&", 0);
  1799. }
  1800. Strings->Add(Caption);
  1801. UnicodeString RootPath = DriveInfo->GetDriveRoot(Drive);
  1802. int ImageIndex = DriveInfo->GetImageIndex(Drive);
  1803. FLocalPathComboBoxPaths->AddObject(RootPath, reinterpret_cast<TObject *>(ImageIndex));
  1804. }
  1805. }
  1806. }
  1807. __finally
  1808. {
  1809. Strings->EndUpdate();
  1810. }
  1811. }
  1812. //---------------------------------------------------------------------------
  1813. void __fastcall TScpCommanderForm::LocalPathComboUpdate()
  1814. {
  1815. // this may get called even after destructor finishes
  1816. // (e.g. from SetDockAllowDrag invoked [indirectly] from StoreParams)
  1817. if (FLocalPathComboBoxPaths != NULL)
  1818. {
  1819. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1820. int Index = 0;
  1821. while ((Index < FLocalPathComboBoxPaths->Count) &&
  1822. !SamePaths(FLocalPathComboBoxPaths->Strings[Index],
  1823. LocalDirView->Path.SubString(1, FLocalPathComboBoxPaths->Strings[Index].Length())))
  1824. {
  1825. Index++;
  1826. }
  1827. // what to do if not?
  1828. if (Index < FLocalPathComboBoxPaths->Count)
  1829. {
  1830. LocalPathComboBox->ItemIndex = Index;
  1831. }
  1832. }
  1833. }
  1834. //---------------------------------------------------------------------------
  1835. void __fastcall TScpCommanderForm::LocalDirViewPathChange(TCustomDirView * /*Sender*/)
  1836. {
  1837. LocalPathComboUpdate();
  1838. if (IsUncPath(LocalDirView->Path))
  1839. {
  1840. Configuration->Usage->Inc(L"BrowsedUncPath");
  1841. }
  1842. }
  1843. //---------------------------------------------------------------------------
  1844. void __fastcall TScpCommanderForm::LocalPathComboBoxCancel(TObject * /*Sender*/)
  1845. {
  1846. LocalPathComboUpdate();
  1847. }
  1848. //---------------------------------------------------------------------------
  1849. void __fastcall TScpCommanderForm::LocalPathComboBoxAdjustImageIndex(
  1850. TTBXComboBoxItem * /*Sender*/, const UnicodeString AText, int AIndex,
  1851. int & ImageIndex)
  1852. {
  1853. // this may get called even before constructor starts
  1854. // (e.g. from FixControlsPlacement)
  1855. if (FLocalPathComboBoxPaths != NULL)
  1856. {
  1857. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1858. DebugAssert(AIndex < FLocalPathComboBoxPaths->Count);
  1859. if (AIndex < 0)
  1860. {
  1861. AIndex = LocalPathComboBox->ItemIndex;
  1862. }
  1863. if (AIndex >= 0)
  1864. {
  1865. ImageIndex = int(FLocalPathComboBoxPaths->Objects[AIndex]);
  1866. }
  1867. }
  1868. }
  1869. //---------------------------------------------------------------------------
  1870. void __fastcall TScpCommanderForm::LocalPathComboBoxItemClick(TObject * /*Sender*/)
  1871. {
  1872. DebugAssert(FLocalPathComboBoxPaths->Count == LocalPathComboBox->Strings->Count);
  1873. DebugAssert((LocalPathComboBox->ItemIndex >= 0) && (LocalPathComboBox->ItemIndex < FLocalPathComboBoxPaths->Count));
  1874. UnicodeString Path = FLocalPathComboBoxPaths->Strings[LocalPathComboBox->ItemIndex];
  1875. if (LocalPathComboBox->ItemIndex >= FLocalSpecialPaths)
  1876. {
  1877. LocalDirView->ExecuteDrive(DriveInfo->GetDriveKey(Path));
  1878. }
  1879. else
  1880. {
  1881. LocalDirView->Path = Path;
  1882. }
  1883. }
  1884. //---------------------------------------------------------------------------
  1885. void __fastcall TScpCommanderForm::ToolbarItemResize(TTBXCustomDropDownItem * Item, int Width)
  1886. {
  1887. TCustomScpExplorerForm::ToolbarItemResize(Item, Width);
  1888. if ((Item == LocalPathComboBox) ||
  1889. (Item == RemotePathComboBox) ||
  1890. (Item == CommandLineCombo))
  1891. {
  1892. dynamic_cast<TTBXComboBoxItem *>(Item)->MinListWidth = Width - 4;
  1893. }
  1894. }
  1895. //---------------------------------------------------------------------------
  1896. void __fastcall TScpCommanderForm::CommandLineComboPopup(
  1897. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1898. {
  1899. CommandLinePopulate();
  1900. }
  1901. //---------------------------------------------------------------------------
  1902. void __fastcall TScpCommanderForm::CommandLineComboBeginEdit(
  1903. TTBEditItem * /*Sender*/, TTBEditItemViewer * /*Viewer*/, TEdit *EditControl)
  1904. {
  1905. InstallPathWordBreakProc(EditControl);
  1906. FCommandLineComboEdit = EditControl;
  1907. FToolbarEditOldWndProc = EditControl->WindowProc;
  1908. EditControl->WindowProc = CommandLineComboEditWndProc;
  1909. }
  1910. //---------------------------------------------------------------------------
  1911. void __fastcall TScpCommanderForm::ExitToolbar()
  1912. {
  1913. CurrentPanel()->SetFocus();
  1914. }
  1915. //---------------------------------------------------------------------------
  1916. void __fastcall TScpCommanderForm::CommandLineComboEditWndProc(TMessage & Message)
  1917. {
  1918. bool Handled = false;
  1919. if (Message.Msg == WM_CHAR)
  1920. {
  1921. switch (reinterpret_cast<TWMChar &>(Message).CharCode)
  1922. {
  1923. case VK_ESCAPE:
  1924. CommandLineCombo->Text = L"";
  1925. ExitToolbar();
  1926. Handled = true;
  1927. break;
  1928. case VK_TAB:
  1929. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1930. ExitToolbar();
  1931. Handled = true;
  1932. break;
  1933. case VK_RETURN:
  1934. CommandLineCombo->Text = FCommandLineComboEdit->Text;
  1935. ExitToolbar();
  1936. if (!ExecuteCommandLine())
  1937. {
  1938. // re-enter command line
  1939. // (most probably exited by now as message dialog was shown)
  1940. GoToCommandLine();
  1941. }
  1942. Handled = true;
  1943. break;
  1944. }
  1945. }
  1946. if (!Handled)
  1947. {
  1948. FToolbarEditOldWndProc(Message);
  1949. }
  1950. }
  1951. //---------------------------------------------------------------------------
  1952. void __fastcall TScpCommanderForm::LocalDriveViewRefreshDrives(TObject * /*Sender*/)
  1953. {
  1954. LocalPathComboUpdateDrives();
  1955. LocalPathComboUpdate();
  1956. }
  1957. //---------------------------------------------------------------------------
  1958. void __fastcall TScpCommanderForm::HomeDirectory(TOperationSide Side)
  1959. {
  1960. bool SynchronizeBrowsing = NonVisualDataModule->SynchronizeBrowsingAction->Checked;
  1961. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1962. TCustomScpExplorerForm::HomeDirectory(Side);
  1963. if (SynchronizeBrowsing)
  1964. {
  1965. TCustomScpExplorerForm::HomeDirectory(GetOtherSize(Side));
  1966. }
  1967. }
  1968. //---------------------------------------------------------------------------
  1969. void __fastcall TScpCommanderForm::QueueSubmenuItemPopup(
  1970. TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  1971. {
  1972. NonVisualDataModule->QueueSpeedComboBoxItemUpdate(QueueSpeedComboBoxItem);
  1973. }
  1974. //---------------------------------------------------------------------------
  1975. void __fastcall TScpCommanderForm::DoFocusRemotePath(TTerminal * Terminal, const UnicodeString & Path)
  1976. {
  1977. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1978. TCustomScpExplorerForm::DoFocusRemotePath(Terminal, Path);
  1979. }
  1980. //---------------------------------------------------------------------------
  1981. TOperationSide __fastcall TScpCommanderForm::GetOtherSize(TOperationSide Side)
  1982. {
  1983. Side = GetSide(Side);
  1984. return ReverseOperationSide(Side);
  1985. }
  1986. //---------------------------------------------------------------------------
  1987. void __fastcall TScpCommanderForm::HistoryGo(TOperationSide Side, int Index)
  1988. {
  1989. TOperationSide OtherSide = GetOtherSize(Side);
  1990. if (NonVisualDataModule->SynchronizeBrowsingAction->Checked &&
  1991. ((Index < 0) ? (-Index < DirView(OtherSide)->BackCount) : (Index < DirView(OtherSide)->ForwardCount)))
  1992. {
  1993. TSynchronizedBrowsingGuard SynchronizedBrowsingGuard;
  1994. TCustomScpExplorerForm::HistoryGo(Side, Index);
  1995. TCustomScpExplorerForm::HistoryGo(OtherSide, Index);
  1996. }
  1997. else
  1998. {
  1999. TCustomScpExplorerForm::HistoryGo(Side, Index);
  2000. }
  2001. }
  2002. //---------------------------------------------------------------------------
  2003. void __fastcall TScpCommanderForm::DirViewHistoryGo(
  2004. TCustomDirView * Sender, int Index, bool & Cancel)
  2005. {
  2006. TOperationSide Side = (Sender == DirView(osRemote) ? osRemote : osLocal);
  2007. HistoryGo(Side, Index);
  2008. Cancel = true;
  2009. }
  2010. //---------------------------------------------------------------------------
  2011. bool __fastcall TScpCommanderForm::EligibleForImageDisplayMode(TTBCustomItem * Item)
  2012. {
  2013. return
  2014. TCustomScpExplorerForm::EligibleForImageDisplayMode(Item) &&
  2015. ((Item->Parent == NULL) || (Item->Parent->ParentComponent != Toolbar2Toolbar));
  2016. }
  2017. //---------------------------------------------------------------------------
  2018. bool __fastcall TScpCommanderForm::UpdateToolbarDisplayMode()
  2019. {
  2020. bool Result = TCustomScpExplorerForm::UpdateToolbarDisplayMode();
  2021. if (Result)
  2022. {
  2023. // command line combo width needs to be updated as caption visibility has changed
  2024. ToolBarResize(CommandLineToolbar);
  2025. }
  2026. return Result;
  2027. }
  2028. //---------------------------------------------------------------------------
  2029. void __fastcall TScpCommanderForm::QueueLabelUpdateStatus()
  2030. {
  2031. TCustomScpExplorerForm::QueueLabelUpdateStatus();
  2032. // this is here to deactivate panels path labels when moving focus from
  2033. // directory tree to queue
  2034. UpdatePanelsPathLabelsStatus();
  2035. }
  2036. //---------------------------------------------------------------------------
  2037. void __fastcall TScpCommanderForm::LocalDirViewContextPopup(TObject * /*Sender*/,
  2038. TPoint & MousePos, bool & Handled)
  2039. {
  2040. if (!WinConfiguration->ScpCommander.SystemContextMenu && !FForceSystemContextMenu)
  2041. {
  2042. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalOpenMenuItem, dcaOpen);
  2043. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalEditMenuItem, dcaEdit);
  2044. DirViewContextPopupDefaultItem(osLocal, NonVisualDataModule->LocalCopyMenuItem, dcaCopy);
  2045. DirViewContextPopup(osLocal, fcLocalPopup, MousePos);
  2046. Handled = true;
  2047. }
  2048. }
  2049. //---------------------------------------------------------------------------
  2050. void __fastcall TScpCommanderForm::DisplaySystemContextMenu()
  2051. {
  2052. TAutoFlag Flag(FForceSystemContextMenu);
  2053. if ((FLastContextPopupScreenPoint.x >= 0) && (FLastContextPopupScreenPoint.Y >= 0))
  2054. {
  2055. LocalDirView->DisplayContextMenu(FLastContextPopupScreenPoint);
  2056. }
  2057. else
  2058. {
  2059. LocalDirView->DisplayContextMenuInSitu();
  2060. }
  2061. }
  2062. //---------------------------------------------------------------------------
  2063. void __fastcall TScpCommanderForm::LocalStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2064. TTBXStatusPanel * Panel)
  2065. {
  2066. FileStatusBarPanelClick(Panel, osLocal);
  2067. }
  2068. //---------------------------------------------------------------------------
  2069. void __fastcall TScpCommanderForm::RemoteStatusBarPanelClick(TTBXCustomStatusBar * /*Sender*/,
  2070. TTBXStatusPanel *Panel)
  2071. {
  2072. FileStatusBarPanelClick(Panel, osRemote);
  2073. }
  2074. //---------------------------------------------------------------------------
  2075. void __fastcall TScpCommanderForm::GoToAddress()
  2076. {
  2077. OpenDirectory(GetSide(osCurrent));
  2078. }
  2079. //---------------------------------------------------------------------------
  2080. void __fastcall TScpCommanderForm::RemotePathLabelMaskClick(TObject * /*Sender*/)
  2081. {
  2082. Filter(osRemote);
  2083. }
  2084. //---------------------------------------------------------------------------
  2085. void __fastcall TScpCommanderForm::LocalPathLabelMaskClick(TObject * /*Sender*/)
  2086. {
  2087. Filter(osLocal);
  2088. }
  2089. //---------------------------------------------------------------------------
  2090. void __fastcall TScpCommanderForm::LocalOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2091. {
  2092. CreateOpenDirMenu(LocalOpenDirButton, osLocal);
  2093. }
  2094. //---------------------------------------------------------------------------
  2095. void __fastcall TScpCommanderForm::RemoteOpenDirButtonPopup(TTBCustomItem * /*Sender*/, bool /*FromLink*/)
  2096. {
  2097. CreateOpenDirMenu(RemoteOpenDirButton, osRemote);
  2098. }
  2099. //---------------------------------------------------------------------------
  2100. void __fastcall TScpCommanderForm::CopyFilesToClipboard(TOperationSide Side)
  2101. {
  2102. if (GetSide(Side) == osLocal)
  2103. {
  2104. TInstantOperationVisualizer Visualizer;
  2105. LocalDirView->CopyToClipBoard();
  2106. }
  2107. else
  2108. {
  2109. TCustomScpExplorerForm::CopyFilesToClipboard(Side);
  2110. }
  2111. }
  2112. //---------------------------------------------------------------------------
  2113. void __fastcall TScpCommanderForm::PasteFromClipBoard()
  2114. {
  2115. if (DoesClipboardContainOurFiles() && (GetSide(osCurrent) == osLocal))
  2116. {
  2117. if (DebugAlwaysTrue(CanPasteToDirViewFromClipBoard()))
  2118. {
  2119. ClipboardDownload(LocalDirView->Path, !WinConfiguration->ConfirmTransferring, false);
  2120. }
  2121. }
  2122. else
  2123. {
  2124. TCustomScpExplorerForm::PasteFromClipBoard();
  2125. }
  2126. }
  2127. //---------------------------------------------------------------------------