ScpCommander.cpp 80 KB

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