ScpCommander.cpp 80 KB

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