ScpCommander.cpp 102 KB

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