ScpCommander.cpp 106 KB

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