1
0

ScpCommander.cpp 79 KB

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