ScpCommander.cpp 107 KB

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