ScpCommander.cpp 105 KB

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