ScpCommander.cpp 107 KB

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