ScpCommander.cpp 78 KB

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