ScpCommander.cpp 89 KB

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