ScpCommander.cpp 101 KB

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