ScpCommander.cpp 93 KB

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