ScpCommander.cpp 78 KB

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