ScpCommander.cpp 79 KB

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