ScpCommander.cpp 107 KB

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