ScpCommander.cpp 80 KB

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