1
0

ScpCommander.cpp 100 KB

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