ScpCommander.cpp 106 KB

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