ScpCommander.cpp 80 KB

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