ScpCommander.cpp 95 KB

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