1
0

ScpCommander.cpp 107 KB

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