ScpCommander.cpp 79 KB

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