ScpCommander.cpp 77 KB

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