ScpCommander.cpp 106 KB

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