1
0

ScpCommander.cpp 76 KB

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