ScpCommander.cpp 104 KB

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