ScpCommander.cpp 98 KB

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